Jump to content

Recommended Posts

Posted (edited)

 SciTE_OverlayTab

Highlighting the active & unsaved tab item in SciTE

Inspired from  211131-highlighting-the-active-tab-item-in-scite/    (Thanks to BugFix 🏆

While the original was excellent, I found that I needed  to change some things.
Since I made these adjustments, I decided to share the revised code.

What's New

  • New "Significant" Tab Marking:

    • Introduced a new visual layer to mark important tabs.

    • Significant tabs are now highlighted with a 3px Purple top bar for quick identification.

    • Added Ctrl+Shift+6 shortcut to instantly toggle the "Significant" status on the currently focused tab.

 

 

; https://www.autoitscript.com/forum/topic/213330-scite_overlaytab/
;--------------------------------------------------------------------------------------------------------------------------------
; Title...........: SciTE_OverlayTab.au3
; Description.....: Highlighting the active & unsaved tab item in SciTE
; AutoIt Version..: 3.3.18.0   Author: ioa747           Script Version: 0.8
; Note............: Testet in Windows 11 Pro 24H2       Date:22/03/2026
;                   New Layer added (Significant)  toggled with Ctrl+Shift+6
;--------------------------------------------------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <GuiTab.au3>
#include <Misc.au3>
#include <WinAPISysWin.au3>
#include <WindowsStylesConstants.au3>

Opt('TrayIconHide', 1)
_Singleton(@ScriptName)

Global Const $g_hActiveColor = 0x0026FF      ; Blue for active
Global Const $g_hUnSavedColor = 0xFF6A00     ; Orange for not stored
Global Const $g_hSignificantColor = 0x800080 ; Purple for Significant
Global Const $g_iOpacity = 50                ; Background transparency
Global Const $g_iTopBarHeight = 3            ; Significant line thickness

Global $g_aOverlayHwnd[0]
Global $g_aSigOverlayHwnd[0]
Global $g_mSignificant[]
Global $g_SciTE_Handle = WinGetHandle('[CLASS:SciTEWindow]')

If Not $g_SciTE_Handle Then Exit

HotKeySet("^+6", "_ToggleSignificant") ; <<--( toggled Significant with Ctrl+Shift+6 )--<<
OnAutoItExitRegister(_Exit)

While WinExists($g_SciTE_Handle)
    ; Update only if SciTE is visible/active
    _SciTEState()
    Sleep(200)
WEnd

;---------------------------------------------------------------------------------------
Func _SciTEState()
    ; Retrieve the state of the SciTEWindow.
    Local $iState = WinGetState($g_SciTE_Handle)
    Switch $iState
        Case 15, 47 ; exists+visible+enabled+active +maximized
            _UpdateTabOverlays()
        Case Else
            Sleep(250)
    EndSwitch
EndFunc
;---------------------------------------------------------------------------------------
Func _UpdateTabOverlays()
    Local $hTab = _GetHwnd_SciTeTabCtrl()
    If @error Then Return

    Local $iCount = _GUICtrlTab_GetItemCount($hTab)
    Local $iActive = _GUICtrlTab_GetCurFocus($hTab)

    ; Synchronize tables if the number of Tabs changes
    If $iCount <> UBound($g_aOverlayHwnd) Then
        _CleanupOverlays()
        ReDim $g_aOverlayHwnd[$iCount]
        ReDim $g_aSigOverlayHwnd[$iCount]
    EndIf

    For $i = 0 To $iCount - 1
        Local $sRawText = _GUICtrlTab_GetItemText($hTab, $i)
        Local $sCleanID = _GetCleanTabID($sRawText)
        Local $tRect = _GUICtrlTab_GetItemRectEx($hTab, $i)

        ; Active/Unsaved Overlay
        Local $iBgColor = 0
        If $i = $iActive Then
            $iBgColor = $g_hActiveColor
        ElseIf StringRight($sRawText, 1) = '*' Then
            $iBgColor = $g_hUnSavedColor
        EndIf

        $g_aOverlayHwnd[$i] = _ManageOverlay($hTab, $tRect, $iBgColor, $g_aOverlayHwnd[$i], False)

        ; Significant Overlay
        If MapExists($g_mSignificant, $sCleanID) Then
            $g_aSigOverlayHwnd[$i] = _ManageOverlay($hTab, $tRect, $g_hSignificantColor, $g_aSigOverlayHwnd[$i], True)
        Else
            If IsHWnd($g_aSigOverlayHwnd[$i]) Then _DeleteHandle($g_aSigOverlayHwnd[$i])
        EndIf
    Next
EndFunc
;---------------------------------------------------------------------------------------
Func _GetCleanTabID($sText)
    If StringLeft($sText, 1) = "&" Then $sText = StringTrimLeft($sText, 3)
    If StringRight($sText, 1) = "*" Then $sText = StringTrimRight($sText, 2)
    Return $sText
EndFunc

;---------------------------------------------------------------------------------------
Func _ToggleSignificant()
    Local $hTab = _GetHwnd_SciTeTabCtrl()
    If @error Then Return
    Local $sID = _GetCleanTabID(_GUICtrlTab_GetItemText($hTab, _GUICtrlTab_GetCurFocus($hTab)))

    If MapExists($g_mSignificant, $sID) Then
        MapRemove($g_mSignificant, $sID)
    Else
        $g_mSignificant[$sID] = True
    EndIf
EndFunc
;---------------------------------------------------------------------------------------
Func _ManageOverlay($hTab, $tRect, $iColor, $hExisting, $bIsTopBar)
    If $iColor == 0 Then
        If IsHWnd($hExisting) Then _DeleteHandle($hExisting)
        Return 0
    EndIf

    Local $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $tRect.Left)
    DllStructSetData($tPoint, "Y", $tRect.Top)
    _WinAPI_ClientToScreen($hTab, $tPoint)

    Local $iX = DllStructGetData($tPoint, "X")
    Local $iY = DllStructGetData($tPoint, "Y")
    Local $iW = $tRect.Right - $tRect.Left
    Local $iH = ($bIsTopBar ? $g_iTopBarHeight : ($tRect.Bottom - $tRect.Top))

    Local $hOverlay = $hExisting
    If Not IsHWnd($hOverlay) Then
        $hOverlay = GUICreate("", $iW, $iH, $iX, $iY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE, $WS_EX_TRANSPARENT), $hTab)
        GUISetBkColor($iColor)
        WinSetTrans($hOverlay, "", ($bIsTopBar ? 150 : $g_iOpacity))
        GUISetState(@SW_SHOWNOACTIVATE, $hOverlay)
    Else
        WinMove($hOverlay, "", $iX, $iY, $iW, $iH)
        GUISetBkColor($iColor, $hOverlay)
    EndIf
    Return $hOverlay
EndFunc
;---------------------------------------------------------------------------------------
Func _DeleteHandle(ByRef $hWnd)
    GUIDelete($hWnd)
    $hWnd = 0
EndFunc
;---------------------------------------------------------------------------------------
Func _CleanupOverlays()
    For $i = 0 To UBound($g_aOverlayHwnd) - 1
        _DeleteHandle($g_aOverlayHwnd[$i])
        _DeleteHandle($g_aSigOverlayHwnd[$i])
    Next
EndFunc
;---------------------------------------------------------------------------------------
Func _GetHwnd_SciTeTabCtrl()
    Local $aChild = _WinAPI_EnumChildWindows($g_SciTE_Handle)
    If Not @error Then
        For $i = 1 To $aChild[0][0]
            If $aChild[$i][1] = "SciTeTabCtrl" Then Return $aChild[$i][0]
        Next
    EndIf
    Return SetError(1, 0, Null)
EndFunc
;---------------------------------------------------------------------------------------
Func _Exit()
    _CleanupOverlays()
    Exit
EndFunc
;---------------------------------------------------------------------------------------

 

Please, every comment is appreciated!
leave your comments and experiences here!
Thank you very much  :)

 

Edited by ioa747
Version: 0.8

I know that I know nothing

Posted (edited)


What's New in Version 0.7

  • New "Significant" Tab Marking:

    • Introduced a new visual layer to mark important tabs.

    • Significant tabs are now highlighted with a 3px Purple top bar for quick identification.

    • Added Ctrl+Shift+6 shortcut to instantly toggle the "Significant" status on the currently focused tab.

 

Update to Version 0.8

I added an extra layer to the site's activity control to reduce processor activity.

Edited by ioa747

I know that I know nothing

Posted (edited)

I'm getting a crash 

AutoIt3 ended. rc:-1073740940

when starting it as x64 execution. x86 runs properly.

I must add a Sleep(10) to the _ManageOverlay() function. I don't know why but the Tab blue rectangle was topmost painted althouth SciTE was in the background.

Just wondering why SciTE doesn't have this feature already onboard...

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

I prefer to run it on x86, and I didn't encounter any problems.
But I also tried it on x64, without Sleep(10), and I didn't encounter any problems here either.
(not even with the blue rectangle)

Can I ask what version of SciTE you're running?

My combination
AutoIt Version..: 3.3.18.0
SciTE, 32-bit, Version 4.4.6, Mar 12 2022 10:14:43
Windows 11 Pro, Version    25H2

 

Edited by ioa747

I know that I know nothing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...