Ich habe das Script geändert, damit es auch mit mehreren SciTE-Instanzen funktioniert.
If StringRegExp($__sTitle, 'SciTE( \[\d+ of \d+\])?$') Then
So wird bei dem RegEx auch eine eingedeutschte Version berücksichtigt:
If StringRegExp($sTitle, 'SciTE( \[\d+ (of|von) \d+\])?$') Then
Mir ist auch aufgefallen, dass SciTE den Save-Button selbst nicht mehr aktiviert. Wenn SciTE_EnDisable_SaveBtn.au3 also beendet wird, muss der Save-Button in allen Instanzen wieder aktiviert werden, da er sonst nicht mehr nutzbar ist. Dafür kann man die von mir geänderte Version dann einfach mit dem Parameter /Exit aufrufen.
Python
;-- TIME_STAMP 2019-07-24 14:12:24
; setzt Status des Toolbar-Button <SAVE> abhängig von Erfordernis zu speichern oder nicht auf ENABLE/DISABLE
; Skript kompilieren
#NoTrayIcon
#include <Misc.au3>
#include <WinAPISys.au3>
#include <GuiToolbar.au3>
Opt('MustDeclareVars', 1)
If Not @Compiled Then Exit 1
Global $g_hUSER32 = DllOpen('user32.dll')
; Index des gewünschten Button ermitteln
; Die Trennstriche zählen mit! Gezählt wird bei 0 beginnend.
; Bsp. Button "Save": Davor liegt "Trenner", "NEW", "OPEN" --> "SAVE" ist das 4.te Element - somit Index "3"
Global Const $g_iIndexSave = 3
If $CMDLINE[0] And $CMDLINE[1] = '/Exit' Then _SciTE_EnDisable_SaveBtn_Exit()
_Singleton('SciTE_EnDisable_SaveBtn') ; Enforce a design paradigm where only one instance of the script may be running
While Sleep(500)
_CheckAndSetState()
WEnd
Exit
Func _CheckAndSetState()
Local $hScite, $sTitle, $iBtnState, $iNewState, $hWndToolbar, $idCmd, $aResult
$hScite = WinGetHandle('[ACTIVE]')
$aResult = DllCall($g_hUSER32, "int", "GetClassNameW", "hwnd", $hScite, "wstr", "", "int", 4096)
If Not @error And $aResult[2] = 'SciTEWindow' Then
$hWndToolbar = ControlGetHandle($hScite, '', '[CLASS:ToolbarWindow32; INSTANCE:1]')
$aResult = DllCall($g_hUSER32, "bool", "IsWindowVisible", "hwnd", $hWndToolbar)
If Not @error And $aResult[0] Then
$idCmd = _GUICtrlToolbar_IndexToCommand($hWndToolbar, $g_iIndexSave)
$sTitle = WinGetTitle($hScite)
If StringRegExp($sTitle, 'SciTE( \[\d+ (of|von) \d+\])?$') Then
$iBtnState = _GUICtrlToolbar_GetButtonState($hWndToolbar, $idCmd)
If Not StringInStr($sTitle, '*') And BitAND($iBtnState, $TBSTATE_ENABLED) Then
$iNewState = BitXOR($iBtnState, $TBSTATE_ENABLED)
ElseIf StringInStr($sTitle, '*') And Not BitAND($iBtnState, $TBSTATE_ENABLED) Then
$iNewState = BitOR($iBtnState, $TBSTATE_ENABLED)
Else
Return
EndIf
_GUICtrlToolbar_SetButtonState($hWndToolbar, $idCmd, $iNewState)
EndIf
EndIf
EndIf
EndFunc
Func _SciTE_EnDisable_SaveBtn_Exit()
Local $aWinList = WinList('[CLASS:SciTEWindow]'), $hWndToolbar, $idCmd, $iBtnState, $iNewState, $aProcessList = ProcessList(@ScriptName)
For $i = 1 To $aProcessList[0][0] Step 1
If $aProcessList[$i][1] <> @AutoItPID Then ProcessClose($aProcessList[$i][1])
Next
DllClose($g_hUSER32)
For $i = 1 To $aWinList[0][0] Step 1
$hWndToolbar = ControlGetHandle($aWinList[$i][1], '', '[CLASS:ToolbarWindow32; INSTANCE:1]')
$idCmd = _GUICtrlToolbar_IndexToCommand($hWndToolbar, $g_iIndexSave)
$iBtnState = _GUICtrlToolbar_GetButtonState($hWndToolbar, $idCmd)
$iNewState = BitOR($iBtnState, $TBSTATE_ENABLED)
If $iNewState <> $iBtnState Then _GUICtrlToolbar_SetButtonState($hWndToolbar, $idCmd, $iNewState)
Next
Exit
EndFunc
Alles anzeigen