- Hervorheben des aktiven Tab-Item in SciTE
- Individuell:
- Rahmenfarbe
- Textfarbe
- Hintergrundfarbe
- Textfarbe bei nicht gespeichert
- [NEU] Markierung inaktiver Tabitem mit ungespeicherten Dateien
- Farben als Scheme über INI ladbar
Das Skript z.B. über Autostart laden.
AutoIt
;-- TIME_STAMP 2023-03-21 10:20:01 v 0.3
#cs
v 0.3 [added] Gesonderte Markierung (Farbige Linie Top) für inaktive Tab mit ungespeicherten Dateien
v 0.2 [added] Gesonderte Markierung (Textfarbe) für ungespeicherte Dateien.
[added] Laden der Farben aus einer INI (Farbschemata) möglich
#ce
#include <FontConstants.au3>
#include <GuiTab.au3>
#include <Misc.au3>
#include <WinAPIGdi.au3>
#include <WinAPISys.au3>
#include <WinAPIMisc.au3>
#include <WindowsConstants.au3>
Opt('TrayIconHide', 1)
If _Singleton(@ScriptName, 1) = 0 Then
MsgBox($MB_SYSTEMMODAL, "Warning", 'An occurrence of "' & @ScriptName & '" is already running!')
Exit
EndIf
;~ HotKeySet("!{F8}", _End) ; <Alt><F8> Beenden
OnAutoItExitRegister(_End)
Global $sINI = StringFormat("%s\%s.ini", @ScriptDir, StringTrimRight(@ScriptName, 4))
Global $gm_SciTE[]
$gm_SciTE.ExistsLast = 0
$gm_SciTE.ExistsCurr = 0
#cs
Farben können in einer INI definiert werden. Falls INI nicht vorhanden, werden Standardfarben geladen.
INI-Name = Name_der_Exe.ini
[scheme]
current=default
[default]
rect=0xCC483F
text=0x800020
bg=0xFFFFFF
unsaved=0x3030FF
idle=0x3030FF
[blue_invers]
rect=0xCC483F
text=0xFFF0F0
bg=0x800020
unsaved=0xA9A5F7
idle=0xA9A5F7
[green_invers]
rect=0x005F00
text=0xEDFFED
bg=0x409340
unsaved=0x1DE6B5
idle=0x1DE6B5
#ce
; scheme: default (blau):
$gm_SciTE.RectColor = _IniOrDefault($sINI, 'rect' , 0xCC483F) ; BGR
$gm_SciTE.TextColor = _IniOrDefault($sINI, 'text' , 0x800020) ; BGR
$gm_SciTE.BGColor = _IniOrDefault($sINI, 'bg' , 0xFFFFFF) ; BGR
$gm_SciTE.TextColorUnsaved = _IniOrDefault($sINI, 'unsaved', 0x3030FF) ; BGR
$gm_SciTE.IdleUnsaved = _IniOrDefault($sINI, 'idle' , 0x3030FF) ; BGR 0x00C0FF
_CheckSciTE() ; the effect takes place immediately
AdlibRegister(_CheckSciTE, 2000)
While True
Sleep(5000)
WEnd
Func _End()
AdlibUnRegister(_CheckSciTE)
;~ MsgBox(0, 'SciTE TabItem', 'Beendet!')
Exit
EndFunc
Func _CheckSciTE()
If ProcessExists("SciTE.exe") Then
$gm_SciTE.ExistsCurr = 1
If $gm_SciTE.ExistsLast = 0 Then
$gm_SciTE.ExistsLast = 1
_DrawTabItem()
AdlibRegister(_MouseHoversTab, 150)
EndIf
_MarkUnsavedIdleTab()
Else
$gm_SciTE.ExistsCurr = 0
If $gm_SciTE.ExistsLast = 1 Then
$gm_SciTE.ExistsLast = 0
AdlibUnRegister(_MouseHoversTab)
EndIf
EndIf
EndFunc
Func _MouseHoversTab()
Local Static $iHoverLast = 1 ; bei Programmstart muss Verlassen des Item simuliert werden
Local $mTab = _SciTE_GetActiveTabInfo()
If @error Then Return
Local $tPoint = _WinAPI_GetMousePos(True, $mTab.hTab)
Local $tRect = $mTab.RectItem
Local $isHover = _WinAPI_PtInRect($tRect, $tPoint)
If $isHover = 1 And $iHoverLast = 0 Then
$iHoverLast = 1
ElseIf $isHover = 0 And $iHoverLast = 1 Then
$iHoverLast = 1
Return _DrawTabItem()
EndIf
EndFunc
Func _MarkUnsavedIdleTab()
Local $hTab = __GetHwnd_SciTeTabCtrl()
If @error Then Return SetError(1)
Local $iActive = _GUICtrlTab_GetCurFocus($hTab)
For $i = 0 To _GUICtrlTab_GetItemCount($hTab) -1
If $i = $iActive Then ContinueLoop
If StringRight(_GUICtrlTab_GetItemText($hTab, $i), 1) = '*' Then
_DrawMarkerUnsaved($hTab, $i)
EndIf
Next
EndFunc
Func _DrawMarkerUnsaved($_hTab, $_iItem)
Local $tRect = _GUICtrlTab_GetItemRectEx($_hTab, $_iItem)
Local $tRectDraw = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct")
$tRectDraw.Left = $tRect.Left
$tRectDraw.Top = $tRect.Top -2
$tRectDraw.Right = $tRect.Right
$tRectDraw.Bottom = $tRect.Top
Local $hDC = _WinAPI_GetDC($_hTab)
Local $hPen = _WinAPI_CreatePen($PS_SOLID, 2, $gm_SciTE.IdleUnsaved)
Local $hOldPen = _WinAPI_SelectObject($hDC, $hPen)
_WinAPI_Rectangle($hDC, $tRectDraw)
_WinAPI_SelectObject($hDC, $hOldPen)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc
Func _DrawTabItem()
Local $mTab = _SciTE_GetActiveTabInfo()
If @error Then Return
Local $hDC = _WinAPI_GetDC($mTab.hTab)
Local $hFont = _WinAPI_CreateFont(14.5, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Lucida Sans Unicode Standard')
Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)
Local $tRect = $mTab.RectItem ; in Variable extrahieren - sonst kein ByRef-Zugriff möglich
_WinAPI_InflateRect($tRect, 2, 2) ; Rect in jede Richtung um 1px vergrößern
_WinAPI_OffsetRect($tRect, 0, 1) ; Rect für Rahmen 1px nach unten verschieben
; Rect zeichnen und füllen
Local $hPen = _WinAPI_CreatePen($PS_SOLID, 2, $gm_SciTE.RectColor)
Local $hBrush = _WinAPI_CreateSolidBrush($gm_SciTE.BGColor)
Local $hOldPen = _WinAPI_SelectObject($hDC, $hPen)
Local $hOldBrush = _WinAPI_SelectObject($hDC, $hBrush)
_WinAPI_Rectangle($hDC, $tRECT)
; Text zeichnen
If StringRight($mTab.Item, 1) = '*' Then
_WinAPI_SetTextColor($hDC, $gm_SciTE.TextColorUnsaved)
Else
_WinAPI_SetTextColor($hDC, $gm_SciTE.TextColor)
EndIf
_WinAPI_SetBkColor($hDC, $gm_SciTE.BGColor)
; den Text noch etwas nach unten verschieben
_WinAPI_OffsetRect($tRect, 0, 3)
_WinAPI_DrawText($hDC, $mTab.Item, $tRect, BitOR($DT_BOTTOM,$DT_CENTER))
; clear Ressources
_WinAPI_SelectObject($hDC, $hOldFont)
_WinAPI_DeleteObject($hFont)
_WinAPI_SelectObject($hDC, $hOldPen)
_WinAPI_DeleteObject($hPen)
_WinAPI_SelectObject($hDC, $hOldBrush)
_WinAPI_DeleteObject($hBrush)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc
Func _SciTE_GetActiveTabInfo()
Local $mResult[], $hTab = __GetHwnd_SciTeTabCtrl()
If @error Then Return SetError(1)
$mResult.hTab = $hTab
$mResult.Index = _GUICtrlTab_GetCurFocus($hTab)
$mResult.Item = _GUICtrlTab_GetItemText($hTab, $mResult.Index)
$mResult.RectItem = _GUICtrlTab_GetItemRectEx($hTab, $mResult.Index)
Return $mResult
EndFunc
Func __GetHwnd_SciTE()
Local $hScite = WinGetHandle('[ACTIVE]')
If _WinAPI_GetClassName($hScite) = 'SciTEWindow' Then
Return $hScite
Else
Return SetError(1, 0, Null)
EndIf
EndFunc
Func __GetHwnd_SciTeTabCtrl()
Local $hScite = __GetHwnd_SciTE()
If @error Then Return SetError(1, 0, Null)
Local $aChild, $hWndTab = Null
$aChild = _WinAPI_EnumChildWindows($hScite) ; only visible
If Not @error Then
For $i = 1 To $aChild[0][0]
If $aChild[$i][1] = "SciTeTabCtrl" Then
$hWndTab = $aChild[$i][0]
ExitLoop
EndIf
Next
EndIf
Return SetError(($hWndTab = Null ? 1 : 0), 0, $hWndTab)
EndFunc
; read from INI if exists
Func _IniOrDefault($_sINI, $_sKey, $_sDefault)
Local $sVal = $_sDefault, $sSec
If FileExists($_sINI) Then
$sSec = IniRead($_sINI, 'scheme', 'current', 'default')
$sVal = IniRead($_sINI, $sSec, $_sKey, $_sDefault)
EndIf
Return $sVal
EndFunc
Alles anzeigen
DL bisher: 10