ToolBox.au3

 
ToolBox for SciTE PlusBar


I had included it in SciTE_PlusBar_1.0.0.25 as a tool, albeit incomplete.
I changed the management logic, for easier adding and editing commands directly from SciTE. 

As a shortcut menu, useful for entering additional commands, without taking up extra space on the PlusBar

 

; https://www.autoitscript.com/forum/topic/208404-scite-plusbar/page/2/#comment-1517956
;------------------------------------------------------------------------------
; Title...........: ToolBox.au3
; Description.....: ToolBox for SciTE PlusBar
;------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon
#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <ListBoxConstants.au3>
#include <GuiListBox.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
;~ #include <Debug.au3>

Global $AutoItHome = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)
Global $MyIni = StringTrimRight(@ScriptFullPath, 4) & ".ini"
Global $MyName = StringSplit($MyIni, "\", 1)
$MyName = $MyName[$MyName[0]]
$MyName = StringTrimRight($MyName, 4)

Global $mPos = MouseGetPos()
Global $hGui = GUICreate("Fav_gui", 32, 32, $mPos[0], $mPos[1], $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))
GUISetBkColor("0x000000")
WinSetTrans($hGui, "", 2)

;Add FileChangeDir to set the workdir to the scriptdir
FileChangeDir(@ScriptDir)

Global $Scite_Hwnd = WinGetHandle("[CLASS:SciTEWindow]")
Global $aBox = BoxLoad()

#Region === ContextMenu ===
Global $hMenu = GUICtrlCreateContextMenu()

Global $Menu_Add = GUICtrlCreateMenuItem("+  Add To " & $MyName, $hMenu)
Global $Menu_Remove = GUICtrlCreateMenuItem("-  Remove From " & $MyName, $hMenu)
GUICtrlCreateMenuItem("", $hMenu)     ; separator   -------------------------------------
Global $Menu_Edit = GUICtrlCreateMenuItem(">  Edit " & $MyName, $hMenu)
GUICtrlCreateMenuItem("", $hMenu)     ; separator   -------------------------------------

For $i = 1 To $aBox[0][0]
    GUICtrlCreateMenuItem($aBox[$i][0], $hMenu)
Next

GUICtrlCreateMenuItem("", $hMenu)     ; separator   -------------------------------------
Global $Menu_Cancel = GUICtrlCreateMenuItem("Cancel", $hMenu)
#EndRegion === ContextMenu ===
GUISetState(@SW_SHOW)

;HotKeySet("{END}", "DisplayBox")

; Perform a mouse right click
MouseClick("right")

Global $ID, $TmpSciteFile, $NeedSave = False
; Loop until the user exits.
;********************************************************************
While 1
    $ID = GUIGetMsg()
    Switch $ID
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Menu_Add
            $TmpSciteFile = SciTE_CurrentFile()
            If $TmpSciteFile Then AddToBox($TmpSciteFile)
            ExitLoop
        Case $Menu_Remove
            $TmpSciteFile = SciTE_CurrentFile()
            If $TmpSciteFile Then RemoveFromBox($TmpSciteFile)
            ExitLoop
        Case $Menu_Edit
            $TmpSciteFile = SciTE_CurrentFile()
            If $TmpSciteFile Then BoxEdit($TmpSciteFile)
            ExitLoop
        Case $Menu_Cancel
            ExitLoop
        Case 8 To $aBox[0][0] + 9
            ;ShellExecute($aBox[$ID - 8][1])
            RunFromBox($aBox[$ID - 8][1])
            ExitLoop
    EndSwitch

    If Not WinActive($hGui) Then
        ExitLoop
    EndIf

    Sleep(10)

WEnd
;********************************************************************
;~ Sleep(100) ;
ConsoleWrite("$NeedSave=" & $NeedSave & @CRLF)

If $NeedSave = True Then BoxSave()

GoToExit()
;----------------------------------------------------------------------------------------
Func GoToExit() ; exit
    Exit
EndFunc   ;==>GoToExit
;----------------------------------------------------------------------------------------
Func SciTE_CurrentFile($FullPath = 1) ; Return the Current Scite [0=ScriptName; 1=ScriptFullPath]

    Local $ClipBack = ClipGet() ; backup clip data

    WinMenuSelectItem("[CLASS:SciTEWindow]", "", "&File", "Copy Pat&h")

    Local $ScriptName, $ScriptFullPath = ClipGet()
    ConsoleWrite("$ScriptFullPath=" & $ScriptFullPath & @CRLF)

    If Not FileExists($ScriptFullPath) Then
        Return SetError(1, 0, "")
    EndIf

    If $FullPath = 0 Then
        Local $sSplit = StringSplit($ScriptFullPath, "\")
        $ScriptName = $sSplit[$sSplit[0]]
    Else
        $ScriptName = $ScriptFullPath
    EndIf

    ClipPut($ClipBack) ; Restore clip data

    Return $ScriptName

EndFunc   ;==>SciTE_CurrentFile
;----------------------------------------------------------------------------------------
Func BoxLoad() ; Ini Read
    Local $iniFileExists = FileExists($MyIni)
    Local $index = 0
    Local $aArray[1][2]
    $aArray[0][0] = $index
    $aArray[0][1] = "Path"

    ;Checks if FavoriteMenu.ini not exists then make one.
    If Not $iniFileExists Then
        ;Open the file for writing (append to the end of a file) and store the handle to a variable.
        Local $hFileOpen = FileOpen($MyIni, $FO_APPEND)
        If $hFileOpen = -1 Then
            MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the " & $MyName & ".ini")
            GoToExit()
        EndIf

        ;Write data to the file using the handle returned by FileOpen.
        FileWrite($hFileOpen, "[Box_1]" & @CRLF)
        FileWrite($hFileOpen, "Name=" & @ScriptName & "  * <-  Test Run 'another ...Box'" & @CRLF)
        FileWrite($hFileOpen, "Path=" & @ScriptFullPath & @CRLF)
        FileWrite($hFileOpen, "[Box_2]" & @CRLF)
        FileWrite($hFileOpen, "Name=" & "StringRegExpGUI.au3" & @CRLF)
        FileWrite($hFileOpen, "Path=" & $AutoItHome & "\Examples\Helpfile\StringRegExpGUI.au3" & @CRLF)
        FileWrite($hFileOpen, "[Box_3]" & @CRLF)
        FileWrite($hFileOpen, "Name=" & "_WinAPI_EnumWindows.au3" & @CRLF)
        FileWrite($hFileOpen, "Path=" & $AutoItHome & "\Examples\Helpfile\_WinAPI_EnumWindows.au3" & @CRLF)

        ;Close the handle returned by FileOpen.
        FileClose($hFileOpen)
        Sleep(100)
    EndIf

    ;Read the INI section names. This will return a 1 dimensional array.
    Local $aSections = IniReadSectionNames($MyIni)
    ;Check if an error occurred.
    If Not @error Then
        ;Enumerate through the array displaying the section names.
        For $i = 1 To $aSections[0]
            ReDim $aArray[UBound($aArray) + 1][2]
            $index += 1
            $aArray[0][0] = $index ; cnt
            $aArray[$index][0] = IniRead($MyIni, $aSections[$i], "Name", "default") ;Name
            $aArray[$index][1] = IniRead($MyIni, $aSections[$i], "Path", "default") ;Path
        Next
    EndIf

    Return $aArray

EndFunc   ;==>BoxLoad
;----------------------------------------------------------------------------------------
Func BoxSave() ; Save or Make new Ini file
    ;Read the INI section names. This will return a 1 dimensional array.
    Local $aSections = IniReadSectionNames($MyIni)
    ;Check if an error occurred.
    If Not @error Then
        ;Enumerate through the array displaying the section names.
        For $i = 1 To $aSections[0]
            ;Delete the sections
            IniDelete($MyIni, $aSections[$i])
        Next
    EndIf

    ;Write to the .ini
    If Not @error Then
        For $i = 1 To $aBox[0][0]
            IniWrite($MyIni, "Box_" & $i, "Name", $aBox[$i][0])
            IniWrite($MyIni, "Box_" & $i, "Path", $aBox[$i][1])
            ;ConsoleWrite($i & ") " & $aBox[$i][0] & @CRLF)
        Next
    EndIf
EndFunc   ;==>BoxSave
;----------------------------------------------------------------------------------------
Func AddToBox($sFilePath) ; Add to Box
    ; Search if $sFilePath exist (looking in col 2)
    Local $iIndex = _ArraySearch($aBox, $sFilePath, 0, 0, 0, 0, 1, 2)

    If $iIndex > 1 Then Return  ; if all redy exist then return
    Local $mName = StringSplit($sFilePath, "\")
    Local $sFill = $mName[$mName[0]] & "|" & $sFilePath

    _ArrayAdd($aBox, $sFill)

    $aBox[0][0] += 1
    $NeedSave = True
EndFunc   ;==>AddToBox
;----------------------------------------------------------------------------------------
Func RemoveFromBox($sFilePath) ; Remove from Box
    ; Search if $sFilePath exist (looking in col 2)
    Local $iIndex = _ArraySearch($aBox, $sFilePath, 0, 0, 0, 0, 1, 2)
    If $iIndex Then
        _ArrayDelete($aBox, $iIndex)
        $aBox[0][0] -= 1
        $NeedSave = True
    EndIf
EndFunc   ;==>RemoveFromBox
;----------------------------------------------------------------------------------------
Func BoxEdit($sCurrentSciteFile) ; Box Edit
    #Region === Create GUI ===
    Local $hGuiEdit = GUICreate("Edit " & $MyName, 550, 420, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_ACCEPTFILES))
    Local $idListBox = GUICtrlCreateList("", 5, 0, 540, 330, BitOR($WS_VSCROLL, $WS_BORDER, $LBS_NOTIFY))
    GUICtrlSetFont(-1, 9)
    GUICtrlCreateLabel("Name:", 5, 330, 30, 10)
    GUICtrlSetFont(-1, 8)
    Local $Input_Name = GUICtrlCreateInput("Name", 5, 345, 460, 21)
    GUICtrlSetFont(-1, 9)
    GUICtrlCreateLabel("Path:", 5, 375, 30, 10)
    GUICtrlSetFont(-1, 8)
    Local $Input_Path = GUICtrlCreateInput("Path", 5, 390, 540, 21)
    GUICtrlSetFont(-1, 7)
    GUICtrlSetState($Input_Path, $GUI_DROPACCEPTED)
    Local $Button_Add = GUICtrlCreateButton("Add", 478, 323, 32, 32, $BS_ICON)
    GUICtrlSetImage(-1, "..\ICO\GUI\BTN_ADD.ico") ;  "mmcndmgr.dll", 30503)
    GUICtrlSetTip(-1, "Add Item")
    Local $Button_Remove = GUICtrlCreateButton("Remove", 478, 356, 32, 32, $BS_ICON)
    GUICtrlSetImage(-1, "..\ICO\GUI\BTN_SUB.ico") ;  "mmcndmgr.dll", 30536)
    GUICtrlSetTip(-1, "Remove Item")
    Local $Button_Up = GUICtrlCreateButton("Up", 513, 323, 32, 32, $BS_ICON)
    GUICtrlSetImage(-1, "..\ICO\GUI\BTN_UP2.ico") ; "mmcndmgr.dll", 30554)
    GUICtrlSetTip(-1, "Move UP")
    Local $Button_Down = GUICtrlCreateButton("Down", 513, 356, 32, 32, $BS_ICON)
    GUICtrlSetImage(-1, "..\ICO\GUI\BTN_DOWN2.ico") ; "mmcndmgr.dll", 30545)
    GUICtrlSetTip(-1, "Move DOWN")
    Local $Button_FileDlg = GUICtrlCreateButton("File", 415, 368, 51, 20)
    GUISetState(@SW_SHOWNORMAL)
    #EndRegion === Create GUI ===
    #Region === ContextMenu ===
    Local $hBoxMenu = GUICtrlCreateContextMenu($idListBox)

    Local $Menu_Add = GUICtrlCreateMenuItem("Add Item ", $hBoxMenu)
    Local $Menu_Remove = GUICtrlCreateMenuItem("Remove Item ", $hBoxMenu)
    GUICtrlCreateMenuItem("", $hBoxMenu) ; separator    -------------------------------------
    Local $Menu_Up = GUICtrlCreateMenuItem("Move UP" & @TAB & "Shift ▲", $hBoxMenu)
    Local $Menu_Down = GUICtrlCreateMenuItem("Move DOWN" & @TAB & "Shift ▼", $hBoxMenu)
    GUICtrlCreateMenuItem("", $hBoxMenu) ; separator    -------------------------------------
    Local $Menu_Edit = GUICtrlCreateMenuItem("Edit ", $hBoxMenu)

    Local $GUI_AccelTable[2][2] = [["+{UP}", $Menu_Up], ["+{DOWN}", $Menu_Down]]
    GUISetAccelerators($GUI_AccelTable, $hGuiEdit)
    #EndRegion === ContextMenu ===

    Local $CurPos, $TmpPos, $AddNew, $mName

    ; Add strings
    _GUICtrlListBox_BeginUpdate($idListBox)
    For $i = 1 To $aBox[0][0]
        _GUICtrlListBox_AddString($idListBox, $aBox[$i][0])
    Next
    _GUICtrlListBox_EndUpdate($idListBox)

    ;ConsoleWrite("$aBox[0][0]=" & $aBox[0][0] & @CRLF)

    ; Search if $sCurrentSciteFile exist (looking in col 2)
    Local $iIndex = _ArraySearch($aBox, $sCurrentSciteFile, 0, 0, 0, 0, 1, 2)
    ;ConsoleWrite("$iIndex=" & $iIndex & @CRLF)
    If $iIndex > 0 Then
        _GUICtrlListBox_SetCurSel($idListBox, $iIndex - 1)
    Else
        _GUICtrlListBox_SetCurSel($idListBox, $aBox[0][0] - 1)
    EndIf

    $CurPos = _GUICtrlListBox_GetCurSel($idListBox)
    ;ConsoleWrite("StartPos=" & $CurPos & @CRLF)

    ; Get currently selected item
    GUICtrlSetData($Input_Name, $aBox[_GUICtrlListBox_GetCurSel($idListBox) + 1][0])
    GUICtrlSetData($Input_Path, $aBox[_GUICtrlListBox_GetCurSel($idListBox) + 1][1])
    GUICtrlSetTip($Input_Path, $aBox[$CurPos + 1][1])

    ; Loop until the user exits.
    While 1
        If $CurPos <> $TmpPos Then
            $TmpPos = $CurPos
            ;ConsoleWrite("$CurPos=" & $CurPos & @CRLF)
        EndIf

        $ID = GUIGetMsg()
        Switch $ID
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idListBox
                ;ConsoleWrite("-- $idListBox" & @CRLF)
                ; Get currently selected item
                $CurPos = _GUICtrlListBox_GetCurSel($idListBox)
                GUICtrlSetData($Input_Name, $aBox[$CurPos + 1][0])
                GUICtrlSetData($Input_Path, $aBox[$CurPos + 1][1])
                GUICtrlSetTip($Input_Path, $aBox[$CurPos + 1][1])
                If $AddNew = True Then
                    $AddNew = False
                    GUICtrlSetState($Input_Name, $GUI_FOCUS)
                    GUICtrlSetTip($Input_Path, "Select or Drop file or folder")
                    Send("^a")
                EndIf
            Case $Input_Name
                ;ConsoleWrite("-- $Input_Name" & @CRLF)
                $aBox[$CurPos + 1][0] = GUICtrlRead($Input_Name)
                _GUICtrlListBox_ReplaceString($idListBox, $CurPos, $aBox[$CurPos + 1][0])
                $NeedSave = True
            Case $Input_Path
                ;ConsoleWrite("-- $Input_Path" & @CRLF)
                $aBox[$CurPos + 1][1] = GUICtrlRead($Input_Path)
                $NeedSave = True
            Case $Button_FileDlg
                ;ConsoleWrite("-- $Button_FileDlg" & @CRLF)
                GUISetState(@SW_HIDE, $hGuiEdit)
                Local $sFileOpenDialog = FileOpenDialog("Select to add in " & $MyName, @ScriptDir & "\", "AutoIT (*.au3)", BitOR($FD_FILEMUSTEXIST, $FD_PATHMUSTEXIST))
                If @error Then
                    MsgBox(4096, "Error", "No file was selected.")
                Else
                    GUICtrlSetData($Input_Path, $sFileOpenDialog)
                    GUICtrlSetTip($Input_Path, $sFileOpenDialog)
                    $aBox[$CurPos + 1][1] = $sFileOpenDialog
                    $mName = StringSplit($sFileOpenDialog, "\")
                    GUICtrlSetData($Input_Name, $mName[$mName[0]])
                    $aBox[$CurPos + 1][0] = $mName[$mName[0]]
                    _GUICtrlListBox_ReplaceString($idListBox, $CurPos, $mName[$mName[0]])
                    $NeedSave = True
                EndIf
                GUISetState(@SW_SHOW, $hGuiEdit)
                $NeedSave = True
            Case $Button_Add, $Menu_Add
                ;ConsoleWrite("-- $Button_Add" & @CRLF)
                Local $sFill = "<Name>|<Path>"
                If $CurPos < $aBox[0][0] - 1 Then
                    ; Insert item delimited string - inserted as 1 row - other rows filled with ""
                    _ArrayInsert($aBox, $CurPos + 1, $sFill)
                    _GUICtrlListBox_InsertString($idListBox, "<Name>", $CurPos)
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos, "left")
                Else
                    _ArrayAdd($aBox, $sFill)
                    _GUICtrlListBox_AddString($idListBox, "<Name>")
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos + 1, "left")
                EndIf
                $aBox[0][0] += 1
                $AddNew = True
                $NeedSave = True
            Case $Button_Remove, $Menu_Remove
                ;ConsoleWrite("-- $Button_Remove" & @CRLF)
                _GUICtrlListBox_DeleteString($idListBox, $CurPos)
                _ArrayDelete($aBox, $CurPos + 1)
                $aBox[0][0] -= 1
                If $CurPos = $aBox[0][0] - 1 Then $CurPos -= 1
                If $CurPos > 0 Then
                    _GUICtrlListBox_ClickItem($idListBox, $CurPos - 1, "left")
                Else
                    _GUICtrlListBox_ClickItem($idListBox, 0, "left")
                EndIf
                $NeedSave = True
            Case $Button_Up, $Menu_Up
                ;ConsoleWrite("-- $Button_Up" & @CRLF)
                If $CurPos > 0 Then
                    ;ConsoleWrite("$aBox[" & $CurPos + 1 & "][0]=" & $aBox[$CurPos + 1][0] & @CRLF)
                    _ArraySwap($aBox, $CurPos + 1, $CurPos)
                    _GUICtrlListBox_SwapString($idListBox, $CurPos, $CurPos - 1)
                    $CurPos -= 1
                    _GUICtrlListBox_SetCurSel($idListBox, $CurPos)
                    $NeedSave = True
                EndIf
            Case $Button_Down, $Menu_Down
                ;ConsoleWrite("-- $Button_Down" & @CRLF)
                If $CurPos < $aBox[0][0] - 1 Then
                    ;ConsoleWrite("$aBox[" & $CurPos + 1 & "][0]=" & $aBox[$CurPos + 1][0] & @CRLF)
                    _ArraySwap($aBox, $CurPos + 1, $CurPos + 2)
                    _GUICtrlListBox_SwapString($idListBox, $CurPos, $CurPos + 1)
                    $CurPos += 1
                    _GUICtrlListBox_SetCurSel($idListBox, $CurPos)
                    $NeedSave = True
                EndIf
            Case $GUI_EVENT_DROPPED
                If @GUI_DropId = $Input_Path Then
                    ; SetImage ico file to $ICON_Drop label
                    GUICtrlSetData($Input_Path, @GUI_DragFile)
                    GUICtrlSetTip($Input_Path, @GUI_DragFile)
                    $aBox[$CurPos + 1][1] = @GUI_DragFile
                    $mName = StringSplit(@GUI_DragFile, "\")
                    GUICtrlSetData($Input_Name, $mName[$mName[0]])
                    $aBox[$CurPos + 1][0] = $mName[$mName[0]]
                    _GUICtrlListBox_ReplaceString($idListBox, $CurPos, $mName[$mName[0]])
                    $NeedSave = True
                EndIf

            Case $Menu_Edit
                ShellExecute($aBox[$CurPos + 1][1])
                ExitLoop

        EndSwitch
        Sleep(10)
    WEnd
    GUIDelete()
EndFunc   ;==>BoxEdit
;----------------------------------------------------------------------------------------
Func DisplayBox() ; _DebugArrayDisplay
    _ArrayDisplay($aBox)
EndFunc   ;==>DisplayBox
;----------------------------------------------------------------------------------------
Func RunFromBox($FilePath) ; Run From Box
    ConsoleWrite($FilePath & @CRLF)
    Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & FileGetShortName($FilePath) & '"')
EndFunc   ;==>RunFromBox
;----------------------------------------------------------------------------------------


Comments

Popular posts from this blog

ControlGetHandle ($hWnd, "", "[REGEXPCLASS:<>; INSTANCE:<>]")

Simple Calculator