From a1fb4de805dcddd24883f95acff555d01228300d Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:23:07 +0000 Subject: [PATCH 1/8] Gui rename --- AboutGui.ahk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AboutGui.ahk b/AboutGui.ahk index f0631e2..cb14b9a 100644 --- a/AboutGui.ahk +++ b/AboutGui.ahk @@ -17,7 +17,7 @@ DestroyAboutGui() Gui, About:Destroy } -ShowAbout() +ShowAboutGui() { Global AppName, AppTitle, AppDescription, AppNotes, AppURL, AppVersion From 0f1af1dbceab4c50daefc456b39e584977ec695f Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:24:20 +0000 Subject: [PATCH 2/8] New library functions and refactor to support event structure --- Lib/ArrayUtils.ahk | 13 +++++ Lib/DesktopIcons.ahk | 24 +++++++-- Lib/Logging.ahk | 51 +++++++++++------- Lib/MathUtils.ahk | 5 ++ Lib/MenuFunctions.ahk | 57 ++++++++++++++++++++ Lib/UserConfig.ahk | 16 ++++-- Lib/UserDataUtils.ahk | 24 ++++++--- Lib/WindowPositions.ahk | 17 ++++-- WindowExtensionsUserConfig.ahk | 99 +++++++++++++++++++++++++++++++++- 9 files changed, 271 insertions(+), 35 deletions(-) create mode 100644 Lib/MenuFunctions.ahk diff --git a/Lib/ArrayUtils.ahk b/Lib/ArrayUtils.ahk index 5b9bf46..80151db 100644 --- a/Lib/ArrayUtils.ahk +++ b/Lib/ArrayUtils.ahk @@ -12,3 +12,16 @@ AutoSort(Arr) return Arr } + +;-------------------------------------------------------------------------------- +; IndexOf - Find the index of an array item +IndexOf(array, item) +{ + for index, param in array + { + if (param = item) + return index + } + + return 0 +} diff --git a/Lib/DesktopIcons.ahk b/Lib/DesktopIcons.ahk index 80c9fb2..05bddfb 100644 --- a/Lib/DesktopIcons.ahk +++ b/Lib/DesktopIcons.ahk @@ -15,15 +15,33 @@ global PAGE_READWRITE := 0x04 global LVM_GETITEMCOUNT := 0x00001004, LVM_GETITEMPOSITION := 0x00001010, LVM_SETITEMPOSITION := 0x0000100F, WM_SETREDRAW := 0x000B ;-------------------------------------------------------------------------------- -; Configuration -DesktopIconsBaseFileName := "DesktopIcons" +; Globals +DesktopIconsBaseFileName := "" + +;-------------------------------------------------------------------------------- +; Initialisation +DesktopIcons_OnInit() +{ + global MEM_COMMIT + global PAGE_READWRITE + global LVM_GETITEMCOUNT + global DesktopIconsBaseFileName + + MEM_COMMIT := 0x1000, MEM_RESERVE := 0x2000, MEM_RELEASE := 0x8000 + PAGE_READWRITE := 0x04 + LVM_GETITEMCOUNT := 0x00001004, LVM_GETITEMPOSITION := 0x00001010, LVM_SETITEMPOSITION := 0x0000100F, WM_SETREDRAW := 0x000B + + DesktopIconsBaseFileName := "DesktopIcons" +} ;-------------------------------------------------------------------------------- HasSavedDesktopIconsFile(desktopSize) { fileName := GetDesktopIconsDataFileName(desktopSize) - return FileExist(fileName) + exists := FileExist(fileName) + + return (exists && exists != "X") } ;-------------------------------------------------------------------------------- diff --git a/Lib/Logging.ahk b/Lib/Logging.ahk index f38088f..4b8d033 100644 --- a/Lib/Logging.ahk +++ b/Lib/Logging.ahk @@ -1,16 +1,25 @@ -LogFile := A_Temp +LogFile := -SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt - -; Initialise Log -LogFileSuffix := "" -IfNotEqual, A_IsCompiled, 1 +;-------------------------------------------------------------------------------- +; LogInit - Initialise logging (explicit call, rather than relying on include) +LogInit() { - LogFileSuffix := ".Debug" -} + global LogFile + + LogFile := A_Temp -LogFile := A_Temp . "\" . ScriptFileNameNoExt . LogFileSuffix . ".log" -LogStart() + SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt + + ; Initialise Log + LogFileSuffix := "" + IfNotEqual, A_IsCompiled, 1 + { + LogFileSuffix := ".Debug" + } + + LogFile := A_Temp . "\" . ScriptFileNameNoExt . LogFileSuffix . ".log" + LogStart() +} ;-------------------------------------------------------------------------------- ; LogText - Debug Text to a file @@ -18,23 +27,29 @@ LogText(text) { global LogFile - FormatTime now,, yyy-MM-dd HH:mm.ss - FileAppend %now% %text%`r`n, %LogFile% + if (LogFile) + { + FormatTime now,, yyy-MM-dd HH:mm.ss + FileAppend %now% %text%`r`n, %LogFile% + } } ;-------------------------------------------------------------------------------- -; LogText - Debug Text to a file +; LogStart - Begin a logging session LogStart() { global LogFile - IfNotEqual, A_IsCompiled, 1 + if (LogFile) { - FileDelete, LogFile - file := FileOpen(LogFile, "w") - if IsObject(file) + IfNotEqual, A_IsCompiled, 1 { - file.Close() + FileDelete, LogFile + file := FileOpen(LogFile, "w") + if IsObject(file) + { + file.Close() + } } } diff --git a/Lib/MathUtils.ahk b/Lib/MathUtils.ahk index 4b48e90..1c46bc1 100644 --- a/Lib/MathUtils.ahk +++ b/Lib/MathUtils.ahk @@ -22,3 +22,8 @@ MaxOf(a, b) return b } } + +ContainsFlag(value, bitwiseFlag) +{ + return (bitwiseFlag > 0) && (value & bitwiseFlag) > 0 +} diff --git a/Lib/MenuFunctions.ahk b/Lib/MenuFunctions.ahk new file mode 100644 index 0000000..859ca85 --- /dev/null +++ b/Lib/MenuFunctions.ahk @@ -0,0 +1,57 @@ +#Include Lib\Logging.ahk + +;-------------------------------------------------------------------------------- +; ResetMenu - Remove all items from a Menu +ResetMenu(menuName) +{ + try Menu, %menuName%, DeleteAll +} + +;-------------------------------------------------------------------------------- +; AddMenuItem - Add a Menu Item to a Menu +AddMenuItem(menuName, text, handler, menuIndex := 0) +{ + If (text = "") + { + LogText("Adding Menu Separator: " . menuName) + Menu, %menuName%, Add + } + else + { + LogText("Adding Menu: " . menuName . " - " . text . " = " . handler) + Menu, %menuName%, Add, %text%, %handler% + } + + return menuIndex + 1 +} + +;-------------------------------------------------------------------------------- +; AddMenuItem - Add a Menu Item to a Menu, and set its Icon +AddMenuItemWithIcon(menuName, text, handler, iconFileName, iconIndex, menuIndex := 0) +{ + menuIndex := AddMenuItem(menuName, text, handler, menuIndex) + + if (iconIndex > 0) + { + try Menu, %menuName%, Icon, %text%, %iconFileName%, %iconIndex% + } + + return menuIndex + 1 +} + +;-------------------------------------------------------------------------------- +; AddMenuItemSeparator - Add a Menu Item separator to a Menu +AddMenuItemSeparator(menuName, menuIndex) +{ + AddMenuItem(menuName, "", "", menuIndex) +} + +;-------------------------------------------------------------------------------- +; EnableMenuItem - Enable / Disable a menu item +EnableMenuItem(menuName, menuTitle, enabled) +{ + state := enabled ? "Enable" : "Disable" + LogText("Enabling: " . menuName . " - " . menuTitle . ", with " . enabled . " = " . state) + + Menu, %menuName%, %state%, %menuTitle% +} diff --git a/Lib/UserConfig.ahk b/Lib/UserConfig.ahk index b857a1d..9e221f1 100644 --- a/Lib/UserConfig.ahk +++ b/Lib/UserConfig.ahk @@ -1,6 +1,16 @@ #Include Lib\UserDataUtils.ahk #Include Lib\Logging.ahk +#Include Lib\WindowPositions.ahk +;-------------------------------------------------------------------------------- +; Initialisation +UserConfig_OnInit() +{ + UserDataUtils_OnInit() +} + +;-------------------------------------------------------------------------------- +; UserConfig base class class UserConfig { Properties := [] @@ -16,14 +26,13 @@ class UserConfig { dataFileName := this.DataFileName - LogText("Getting Value: [" . section . "]." . key . ", default:" . defaultValue) + LogText("Getting Value: [" . section . "]." . key . ", default: " . defaultValue) IniRead, readValue, %dataFileName%, %section%, %key%, %defaultValue% LogText("Got Value: " . readValue) if (type <> "") { - ; TODO - Support other types if (type = "integer") { if readValue is not integer @@ -35,6 +44,7 @@ class UserConfig { readValue := (readValue) ? true : false } + ; TODO - Support other types as necessary } return readValue @@ -44,7 +54,7 @@ class UserConfig { dataFileName := this.DataFileName - LogText("Setting Value: [" . section . "]." . key . ", value:" . value) + LogText("Setting Value: [" . section . "]." . key . ", value: " . value) IniWrite, %value%, %dataFileName%, %section%, %key% } diff --git a/Lib/UserDataUtils.ahk b/Lib/UserDataUtils.ahk index cbf91e7..47f51f1 100644 --- a/Lib/UserDataUtils.ahk +++ b/Lib/UserDataUtils.ahk @@ -2,18 +2,30 @@ #Include Lib\StringUtils.ahk #Include Lib\PathUtils.ahk +;-------------------------------------------------------------------------------- +; Globals +UserDataPath := "" + ;-------------------------------------------------------------------------------- ; Initialisation -SplitPath A_ScriptFullPath, , , , AppName +UserDataUtils_OnInit() +{ + global AppName + global UserDataPath + + SplitPath A_ScriptFullPath, , , , AppName -UserDataPath := CombinePaths(A_AppData, AppName) + UserDataPath := CombinePaths(A_AppData, AppName) -If !DirectoryExists(UserDataPath) -{ - LogText("Creating UserDataPath: " . UserDataPath) - FileCreateDir, %UserDataPath% + If (!DirectoryExists(UserDataPath)) + { + LogText("Creating UserDataPath: " . UserDataPath) + FileCreateDir, %UserDataPath% + } } +;-------------------------------------------------------------------------------- +; GetUserDataFileName : Build an appropriate file name for the specified User data GetUserDataFileName(dataFileName) { global UserDataPath diff --git a/Lib/WindowPositions.ahk b/Lib/WindowPositions.ahk index 19c9554..9e53c6c 100644 --- a/Lib/WindowPositions.ahk +++ b/Lib/WindowPositions.ahk @@ -8,15 +8,26 @@ #Include Lib\PleasantNotify.ahk ;-------------------------------------------------------------------------------- -; Configuration -WindowPositionsBaseFileName := "WindowPositions" +; Globals +WindowPositionsBaseFileName := "" + +;-------------------------------------------------------------------------------- +; Initialisation +WindowPositions_OnInit() +{ + global WindowPositionsBaseFileName + + WindowPositionsBaseFileName := "WindowPositions" +} ;-------------------------------------------------------------------------------- HasSavedWindowPositionFile(desktopSize) { fileName := GetWindowPositionsDataFileName(desktopSize) - return FileExist(fileName) + exists := FileExist(fileName) + + return (exists && exists != "X") } ;-------------------------------------------------------------------------------- diff --git a/WindowExtensionsUserConfig.ahk b/WindowExtensionsUserConfig.ahk index 3d421de..4861b43 100644 --- a/WindowExtensionsUserConfig.ahk +++ b/WindowExtensionsUserConfig.ahk @@ -1,5 +1,62 @@ #Include Lib\UserConfig.ahk +MenuLocationNone := 0 +MenuLocationWindowMenu := 1 +MenuLocationTrayMenu := 2 +MenuLocationAll := MenuLocationWindowMenu | MenuLocationTrayMenu + +MenuLocationItems := [] + +MenuLocationValues := [] + +;-------------------------------------------------------------------------------- +; Initialisation +WindowExtensionsUserConfig_OnInit() +{ + global MenuLocationNone + global MenuLocationWindowMenu + global MenuLocationTrayMenu + global MenuLocationAll + + global MenuLocationItems + global MenuLocationValues + + MenuLocationNone := 0 + MenuLocationWindowMenu := 1 + MenuLocationTrayMenu := 2 + MenuLocationAll := MenuLocationWindowMenu | MenuLocationTrayMenu + + MenuLocationItems := [] + MenuLocationItems.push("None") + MenuLocationItems.push("Window Menu") + MenuLocationItems.push("Tray Menu") + MenuLocationItems.push("Both") + + MenuLocationValues := [] + MenuLocationValues.push(MenuLocationNone) + MenuLocationValues.push(MenuLocationWindowMenu) + MenuLocationValues.push(MenuLocationTrayMenu) + MenuLocationValues.push(MenuLocationAll) + + UserConfig_OnInit() +} + +;-------------------------------------------------------------------------------- +; OnStartup +WindowExtensionsUserConfig_OnStartup() +{ + global G_UserConfig + + if (G_UserConfig.RestoreDesktopIconsOnStartup) + { + RestoreDesktopIcons() + } + if (G_UserConfig.RestoreWindowPositionsOnStartup) + { + RestoreWindowPositions() + } +} + class WindowExtensionsUserConfig extends UserConfig { DefaultCascadeGutterSize := 30 @@ -7,12 +64,24 @@ DefaultColumnGutterSize := 5 DefaultGridGutterSize := 5 DefaultSpanMonitorGutterSize := 5 DefaultRestoreDesktopIconsOnStartup := false -DefaultWindowPositionsOnStartup := false +DefaultRestoreWindowPositionsOnStartup := false +DefaultWindowPositionsMenuLocation := 0 +DefaultDesktopIconsMenuLocation := 0 + + InitDefaults() + { + global MenuLocationTrayMenu + + this.DefaultWindowPositionsMenuLocation := MenuLocationTrayMenu + this.DefaultDesktopIconsMenuLocation := MenuLocationTrayMenu + } __New() { global AppName + this.InitDefaults() + fileName := GetUserDataFileName(AppName . ".dat") base.__New(fileName) @@ -23,6 +92,8 @@ DefaultWindowPositionsOnStartup := false this.Properties.push("SpanMonitorGutterSize") this.Properties.push("RestoreDesktopIconsOnStartup") this.Properties.push("RestoreWindowPositionsOnStartup") + this.Properties.push("WindowPositionsMenuLocation") + this.Properties.push("DesktopIconsMenuLocation") } CascadeGutterSize @@ -89,7 +160,31 @@ DefaultWindowPositionsOnStartup := false { get { - return base.GetValue("General", base.GetPropertyNameFromFunc(A_ThisFunc), this.DefaultWindowPositionsOnStartup, "boolean") + return base.GetValue("General", base.GetPropertyNameFromFunc(A_ThisFunc), this.DefaultRestoreWindowPositionsOnStartup, "boolean") + } + set + { + base.SetValue("General", base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + WindowPositionsMenuLocation + { + get + { + return base.GetValue("General", base.GetPropertyNameFromFunc(A_ThisFunc), this.DefaultWindowPositionsMenuLocation, "integer") + } + set + { + base.SetValue("General", base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + DesktopIconsMenuLocation + { + get + { + return base.GetValue("General", base.GetPropertyNameFromFunc(A_ThisFunc), this.DefaultDesktopIconsMenuLocation, "integer") } set { From 69895b35db87af8856cf83be7340436769e6a9d6 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:24:36 +0000 Subject: [PATCH 3/8] TrayMenu separated into a module --- TrayMenu.ahk | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 TrayMenu.ahk diff --git a/TrayMenu.ahk b/TrayMenu.ahk new file mode 100644 index 0000000..dfb71b2 --- /dev/null +++ b/TrayMenu.ahk @@ -0,0 +1,95 @@ +#Include Lib\Logging.ahk +#Include Lib\MenuFunctions.ahk + +;-------------------------------------------------------------------------------- +; Globals +TrayMenuName := + +;-------------------------------------------------------------------------------- +; Initialisation +TrayMenu_OnInit() +{ + global TrayMenuName + + TrayMenuName := "Tray" +} + +;-------------------------------------------------------------------------------- +; OnStartup +TrayMenu_OnStartup() +{ + BuildTrayMenu() +} + +;-------------------------------------------------------------------------------- +; Setup Tray Menu +BuildTrayMenu() +{ + global AppTitle + global G_UserConfig + global MenuLocationTrayMenu + global TrayMenuName + global IconLibraryFileName + + desktopSize := GetDesktopSize() + + menuIndex := 0 + + ResetMenu(TrayMenuName) + + Menu, %TrayMenuName%, NoStandard + Menu, %TrayMenuName%, Tip, %AppTitle% + + menuIndex := AddMenuItemWithIcon(TrayMenuName, "Con&figure...", "TrayConfigureHandler", A_ScriptFullPath, 0, menuIndex) + + ; Window Positions + if (ContainsFlag(G_UserConfig.WindowPositionsMenuLocation, MenuLocationTrayMenu)) + { + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + + saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(TrayMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex) + + restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) + + restoreEnabled := HasSavedWindowPositionFile(desktopSize) + EnableMenuItem(TrayMenuName, restoreTitle, restoreEnabled) + } + + ; Desktop Icons + if (ContainsFlag(G_UserConfig.DesktopIconsMenuLocation, MenuLocationTrayMenu)) + { + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + + saveTitle := "Save &Desktop Icons (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(TrayMenuName, saveTitle, "SaveDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_SAVE"), menuIndex) + + restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) + + restoreEnabled := HasSavedDesktopIconsFile(desktopSize) + EnableMenuItem(TrayMenuName, restoreTitle, restoreEnabled) + } + + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + menuIndex := AddMenuItem(TrayMenuName, "&About...", "TrayAboutHandler", menuIndex) + + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + menuIndex := AddMenuItem(TrayMenuName, "Exit", "TrayExitHandler", menuIndex) +} + +;-------------------------------------------------------------------------------- +TrayConfigureHandler: +ShowUserConfigGui() +return + +;-------------------------------------------------------------------------------- +TrayAboutHandler: +ShowAboutGui() +return + +;-------------------------------------------------------------------------------- +TrayExitHandler: +ExitApp +return From 83e30ef6e3a3bc8ab83904e264ecd56b91f42355 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:25:00 +0000 Subject: [PATCH 4/8] WindowMenu consolidated to just a menu module --- WindowMenu.ahk | 430 ++++++++++++++++++++----------------------------- 1 file changed, 175 insertions(+), 255 deletions(-) diff --git a/WindowMenu.ahk b/WindowMenu.ahk index 66ec23f..3fd065a 100644 --- a/WindowMenu.ahk +++ b/WindowMenu.ahk @@ -2,178 +2,198 @@ #Include Lib\WindowObjects.ahk #Include Lib\StringUtils.ahk #Include Lib\ArrayUtils.ahk +#Include Lib\MathUtils.ahk +#Include Lib\MenuFunctions.ahk #Include Lib\WindowFunctions.ahk #Include Lib\WindowPositions.ahk #Include Lib\DesktopIcons.ahk +#Include WindowExtensionsUserConfig.ahk ;-------------------------------------------------------------------------------- -; System Information -SysGet, G_CaptionHeight, 4 ; SM_CYCAPTION -SysGet, G_BorderHeight, 5 ; SM_CXBORDER -SysGet, G_MenuDropAlignment, 40 ; SM_MENUDROPALIGNMENT -SysGet, G_MonitorCount, MonitorCount -SysGet, G_PrimaryMonitorIndex, MonitorPrimary - -G_CaptionHitHeight := G_CaptionHeight + (G_BorderHeight * 2) -G_LeftAlignedMenus := (G_MenuDropAlignment = 0) - -LogText("G_CaptionHeight: " G_CaptionHeight) -LogText("G_BorderHeight: " G_BorderHeight) -LogText("G_MonitorCount: " G_MonitorCount) -LogText("G_PrimaryMonitorIndex: " G_PrimaryMonitorIndex) -LogText("G_CaptionHitHeight: " G_CaptionHitHeight) -LogText("G_LeftAlignedMenus: " G_LeftAlignedMenus) +; Globals +IconLibrary := [] +WindowMenuName := ;-------------------------------------------------------------------------------- ; Initialisation -G_ActiveWindow := -G_CurrentMouse := -G_MenuTitle := AppTitle -G_SaveWindowPositionsMenuTitle := "" -G_RestoreWindowPositionsMenuTitle := "" -G_SaveDesktopIconsMenuTitle := "" -G_RestoreDesktopIconsMenuTitle := "" - -SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt -IconLibraryFileName := ScriptFilePath . "\" . ScriptFileNameNoExt . ".icl" - -IconIndexes := [] -IconIndexes.push("MONITOR_FIT") -IconIndexes.push("MOVESIZE_COLUMN_CENTRE") -IconIndexes.push("MOVESIZE_COLUMN_LEFT") -IconIndexes.push("MOVESIZE_COLUMN_RIGHT") -IconIndexes.push("MOVESIZE_COMMON_MEDIUM") -IconIndexes.push("MOVESIZE_COMMON_OPTIMUM") -IconIndexes.push("MOVESIZE_COMMON_SMALL") -IconIndexes.push("MOVESIZE_COMMON_SUBOPTIMUM") -IconIndexes.push("MOVESIZE_COMMON_TINY") -IconIndexes.push("MOVE_CENTRE") -IconIndexes.push("MOVE_CORNER_BOTTOMLEFT") -IconIndexes.push("MOVE_CORNER_BOTTOMRIGHT") -IconIndexes.push("MOVE_CORNER_TOPLEFT") -IconIndexes.push("MOVE_CORNER_TOPRIGHT") -IconIndexes.push("POSITION_TRANSPARENCY0") -IconIndexes.push("POSITION_TRANSPARENCY25") -IconIndexes.push("POSITION_TRANSPARENCY50") -IconIndexes.push("POSITION_TRANSPARENCY75") -IconIndexes.push("POSITION_ZORDER_SENDTOBACK") -IconIndexes.push("POSITION_ZORDER_TOPMOSTOFF") -IconIndexes.push("POSITION_ZORDER_TOPMOSTON") -IconIndexes.push("POSITION_ZORDER_TOPMOSTTOGGLE") -IconIndexes.push("SIZE_COMMON_ROLLUP") -IconIndexes.push("MONITOR_SPAN_ALL") -IconIndexes.push("MONITOR_SPAN_HEIGHT") -IconIndexes.push("MONITOR_SPAN_WIDTH") -IconIndexes.push("POSITION_RESTORE") -IconIndexes.push("POSITION_SAVE") -IconIndexes.push("DESKTOPICONS_RESTORE") -IconIndexes.push("DESKTOPICONS_SAVE") +WindowMenu_OnInit() +{ + global WindowMenuName + + WindowMenuName := "WindowMenu" + BuildIconLibrary() +} ;-------------------------------------------------------------------------------- -; Build Menu -menuIndex := 0 - -Menu, WindowMenu, Add, %G_MenuTitle%, NullHandler -menuIndex += 1 -Menu, WindowMenu, Icon, %G_MenuTitle%, Shell32.dll, 20 -menuIndex += 1 - -; Standard Window Sizes -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("&Optimum Size", "OptimumSizeHandler", "MOVESIZE_COMMON_OPTIMUM", menuIndex) -menuIndex := AddWindowMenuItem("Su&b-Optimum Size", "SubOptimumSizeHandler", "MOVESIZE_COMMON_SUBOPTIMUM", menuIndex) -menuIndex := AddWindowMenuItem("M&edium Size", "MediumSizeHandler", "MOVESIZE_COMMON_MEDIUM", menuIndex) -menuIndex := AddWindowMenuItem("Sma&ll Size", "SmallSizeHandler", "MOVESIZE_COMMON_SMALL", menuIndex) -menuIndex := AddWindowMenuItem("T&iny Size", "TinySizeHandler", "MOVESIZE_COMMON_TINY", menuIndex) - -; Move to known columns of the Screen -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("&Left Column", "MoveColumnLeftHandler", "MOVESIZE_COLUMN_LEFT", menuIndex) -menuIndex := AddWindowMenuItem("Ce&ntre Column", "MoveColumnCentreHandler", "MOVESIZE_COLUMN_CENTRE", menuIndex) -menuIndex := AddWindowMenuItem("&Right Column", "MoveColumnRightHandler", "MOVESIZE_COLUMN_RIGHT", menuIndex) - -; Multi-Monitor spanning -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("&Fit Current Monitor", "SpanCurrentMonitorHandler", "MONITOR_FIT", menuIndex) -if (G_MonitorCount > 1) +; OnStartup +WindowMenu_OnStartup() { - menuIndex := AddWindowMenuItem("Span &Monitor Width", "SpanMonitorWidthHandler", "MONITOR_SPAN_WIDTH", menuIndex) - menuIndex := AddWindowMenuItem("Span &Monitor Height", "SpanMonitorHeightHandler", "MONITOR_SPAN_HEIGHT", menuIndex) - menuIndex := AddWindowMenuItem("Span &All Monitors", "SpanAllMonitorsHandler", "MONITOR_SPAN_ALL", menuIndex) + BuildWindowMenu() } -; Window Positions -menuIndex := AddWindowMenuItem("", "", "", menuIndex) - -G_SaveWindowPositionsMenuTitle := "Save Window &Positions" -menuIndex := AddWindowMenuItem(G_SaveWindowPositionsMenuTitle, "SaveWindowPositionsHandler", "POSITION_SAVE", menuIndex) +;-------------------------------------------------------------------------------- +; OnExit +WindowMenu_OnExit() +{ + RestoreRollupWindows() ; This line will unroll any rolled up windows if the script exits for any reason: +} -G_RestoreWindowPositionsMenuTitle := "Restore Window &Positions" -menuIndex := AddWindowMenuItem(G_RestoreWindowPositionsMenuTitle, "RestoreWindowPositionsHandler", "POSITION_RESTORE", menuIndex) +;-------------------------------------------------------------------------------- +; Build Menu +BuildWindowMenu() +{ + global G_UserConfig + global G_MonitorCount + global G_MenuTitle + global IconLibraryFileName + global MenuLocationWindowMenu + global WindowMenuName + + menuIndex := 0 + + desktopSize := GetDesktopSize() -; Move to Corners -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("Move &Centre", "CentreHandler", "MOVE_CENTRE", menuIndex) -menuIndex := AddWindowMenuItem("Move &Top Left", "MoveTopLeftHandler", "MOVE_CORNER_TOPLEFT", menuIndex) -menuIndex := AddWindowMenuItem("Move &Top Right", "MoveTopRightHandler", "MOVE_CORNER_TOPRIGHT", menuIndex) -menuIndex := AddWindowMenuItem("Move &Bottom Left", "MoveBottomLeftHandler", "MOVE_CORNER_BOTTOMLEFT", menuIndex) -menuIndex := AddWindowMenuItem("Move &Bottom Right", "MoveBottomRightHandler", "MOVE_CORNER_BOTTOMRIGHT", menuIndex) + try Menu, %WindowMenuName%, DeleteAll + + menuIndex := AddMenuItem(WindowMenuName, G_MenuTitle, "NullHandler", menuIndex) + Menu, %WindowMenuName%, Icon, %G_MenuTitle%, Shell32.dll, 20 + + ; Standard Window Sizes + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Optimum Size", "OptimumSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_OPTIMUM"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Su&b-Optimum Size", "SubOptimumSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_SUBOPTIMUM"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "M&edium Size", "MediumSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_MEDIUM"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Sma&ll Size", "SmallSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_SMALL"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "T&iny Size", "TinySizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_TINY"), menuIndex) + + ; Move to known columns of the Screen + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Left Column", "MoveColumnLeftHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COLUMN_LEFT"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Ce&ntre Column", "MoveColumnCentreHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COLUMN_CENTRE"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Right Column", "MoveColumnRightHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COLUMN_RIGHT"), menuIndex) + + ; Multi-Monitor spanning + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Fit Current Monitor", "SpanCurrentMonitorHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_FIT"), menuIndex) + if (G_MonitorCount > 1) + { + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Span &Monitor Width", "SpanMonitorWidthHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_SPAN_WIDTH"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Span &Monitor Height", "SpanMonitorHeightHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_SPAN_HEIGHT"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Span &All Monitors", "SpanAllMonitorsHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_SPAN_ALL"), menuIndex) + } -; Rollup -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("Roll&up", "RollupHandler", "SIZE_COMMON_ROLLUP", menuIndex) + ; Window Positions + if (ContainsFlag(G_UserConfig.WindowPositionsMenuLocation, MenuLocationWindowMenu)) + { + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) -; Topmost handling -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("Set Top&Most On", "TopmostSetHandler", "POSITION_ZORDER_TOPMOSTON", menuIndex) -menuIndex := AddWindowMenuItem("Set Top&Most Off", "TopmostUnsetHandler", "POSITION_ZORDER_TOPMOSTOFF", menuIndex) -menuIndex := AddWindowMenuItem("&Toggle TopMost", "TopmostToggleHandler", "POSITION_ZORDER_TOPMOSTTOGGLE", menuIndex) + saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex) -; Transparency -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("Set Transparency &75%", "TransparencySet75Handler", "POSITION_TRANSPARENCY75", menuIndex) -menuIndex := AddWindowMenuItem("Set Transparency &50%", "TransparencySet50Handler", "POSITION_TRANSPARENCY50", menuIndex) -menuIndex := AddWindowMenuItem("Set Transparency &25%", "TransparencySet25Handler", "POSITION_TRANSPARENCY25", menuIndex) -menuIndex := AddWindowMenuItem("Set Transparency &0%", "TransparencySet0Handler", "POSITION_TRANSPARENCY0", menuIndex) + restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) -; Send to back -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("Send to Bac&k", "SendToBackHandler", "POSITION_ZORDER_SENDTOBACK", menuIndex) + restoreEnabled := HasSavedWindowPositionFile(desktopSize) + EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled) + } -; Window Positions -menuIndex := AddWindowMenuItem("", "", "", menuIndex) + ; Move to Corners + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Centre", "CentreHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CENTRE"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Top Left", "MoveTopLeftHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_TOPLEFT"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Top Right", "MoveTopRightHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_TOPRIGHT"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Bottom Left", "MoveBottomLeftHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_BOTTOMLEFT"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Bottom Right", "MoveBottomRightHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_BOTTOMRIGHT"), menuIndex) + + ; Rollup + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Roll&up", "RollupHandler", IconLibraryFileName, GetIconLibraryIndex("SIZE_COMMON_ROLLUP"), menuIndex) + + ; Topmost handling + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Top&Most On", "TopmostSetHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_TOPMOSTON"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Top&Most Off", "TopmostUnsetHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_TOPMOSTOFF"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Toggle TopMost", "TopmostToggleHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_TOPMOSTTOGGLE"), menuIndex) + + ; Transparency + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &75%", "TransparencySet75Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY75"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &50%", "TransparencySet50Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY50"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &25%", "TransparencySet25Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY25"), menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &0%", "TransparencySet0Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY0"), menuIndex) + + ; Send to back + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItemWithIcon(WindowMenuName, "Send to Bac&k", "SendToBackHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_SENDTOBACK"), menuIndex) + + ; Desktop Icons + if (ContainsFlag(G_UserConfig.DesktopIconsMenuLocation, MenuLocationWindowMenu)) + { + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) -G_SaveDesktopIconsMenuTitle := "Save &Desktop Icons" -menuIndex := AddWindowMenuItem(G_SaveDesktopIconsMenuTitle, "SaveDesktopIconsHandler", "DESKTOPICONS_SAVE", menuIndex) + saveTitle := "Save &Desktop Icons (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_SAVE"), menuIndex) -G_RestoreDesktopIconsMenuTitle := "Restore &Desktop Icons" -menuIndex := AddWindowMenuItem(G_RestoreDesktopIconsMenuTitle, "RestoreDesktopIconsHandler", "DESKTOPICONS_RESTORE", menuIndex) + restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) -; Cancel menu -menuIndex := AddWindowMenuItem("", "", "", menuIndex) -menuIndex := AddWindowMenuItem("&Cancel", "NullHandler", "", menuIndex) + restoreEnabled := HasSavedDesktopIconsFile(desktopSize) + EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled) + } -; This line will unroll any rolled up windows if the script exits -; for any reason: -OnExit, ExitSub + ; Cancel menu + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItem(WindowMenuName, "&Cancel", "NullHandler", menuIndex) +} ;-------------------------------------------------------------------------------- -; Apply Startup options ? -if (G_UserConfig.RestoreDesktopIconsOnStartup) +; Build Icon Library +BuildIconLibrary() { - RestoreDesktopIcons() + global IconLibrary + + IconLibrary := [] + IconLibrary.push("MONITOR_FIT") + IconLibrary.push("MOVESIZE_COLUMN_CENTRE") + IconLibrary.push("MOVESIZE_COLUMN_LEFT") + IconLibrary.push("MOVESIZE_COLUMN_RIGHT") + IconLibrary.push("MOVESIZE_COMMON_MEDIUM") + IconLibrary.push("MOVESIZE_COMMON_OPTIMUM") + IconLibrary.push("MOVESIZE_COMMON_SMALL") + IconLibrary.push("MOVESIZE_COMMON_SUBOPTIMUM") + IconLibrary.push("MOVESIZE_COMMON_TINY") + IconLibrary.push("MOVE_CENTRE") + IconLibrary.push("MOVE_CORNER_BOTTOMLEFT") + IconLibrary.push("MOVE_CORNER_BOTTOMRIGHT") + IconLibrary.push("MOVE_CORNER_TOPLEFT") + IconLibrary.push("MOVE_CORNER_TOPRIGHT") + IconLibrary.push("POSITION_TRANSPARENCY0") + IconLibrary.push("POSITION_TRANSPARENCY25") + IconLibrary.push("POSITION_TRANSPARENCY50") + IconLibrary.push("POSITION_TRANSPARENCY75") + IconLibrary.push("POSITION_ZORDER_SENDTOBACK") + IconLibrary.push("POSITION_ZORDER_TOPMOSTOFF") + IconLibrary.push("POSITION_ZORDER_TOPMOSTON") + IconLibrary.push("POSITION_ZORDER_TOPMOSTTOGGLE") + IconLibrary.push("SIZE_COMMON_ROLLUP") + IconLibrary.push("MONITOR_SPAN_ALL") + IconLibrary.push("MONITOR_SPAN_HEIGHT") + IconLibrary.push("MONITOR_SPAN_WIDTH") + IconLibrary.push("POSITION_RESTORE") + IconLibrary.push("POSITION_SAVE") + IconLibrary.push("DESKTOPICONS_RESTORE") + IconLibrary.push("DESKTOPICONS_SAVE") } -if (G_UserConfig.RestoreWindowPositionsOnStartup) + +;-------------------------------------------------------------------------------- +; GetIconIndex - Find the array index of a named icon +GetIconLibraryIndex(iconName) { - RestoreWindowPositions() + global IconLibrary + + return IndexOf(IconLibrary, iconName) } -return ; End of script's auto-execute section. - -ExitSub: -RestoreRollupWindows() -ExitApp ; Must do this for the OnExit subroutine to actually Exit the script. - ;-------------------------------------------------------------------------------- ; Menu Handlers @@ -319,139 +339,38 @@ return NullHandler: return -;-------------------------------------------------------------------------------- -; AddWindowMenuItem - Add a Menu Item to the main Window Menu -AddWindowMenuItem(text, handler, iconName, menuIndex := 0) -{ - global WindowMenu - global IconLibraryFileName - - If (text = "") - { - Menu, WindowMenu, Add - } - else - { - Menu, WindowMenu, Add, %text%, %handler% - - iconIndex := GetIconIndex(iconName) - if (iconIndex > 0) - { - Menu, WindowMenu, Icon, %text%, %IconLibraryFileName%, %iconIndex% - } - } - - return menuIndex + 1 -} - -;-------------------------------------------------------------------------------- -; GetIconIndex - Find the array index of a named icon -GetIconIndex(iconName) -{ - global IconIndexes - - for index, element in IconIndexes - { - If (element = iconName) - { - return index - } - } - - return 0 -} - ;-------------------------------------------------------------------------------- ; ShowMenu - Show the Window Control Menu ShowMenu(theWindow) { global G_MenuTitle - global G_SaveWindowPositionsMenuTitle - global G_RestoreWindowPositionsMenuTitle - global G_SaveDesktopIconsMenuTitle - global G_RestoreDesktopIconsMenuTitle + global WindowMenuName + + BuildWindowMenu() ; Build Window Details newMenuTitle := theWindow.Title . " (" . theWindow.ProcessName . ") [" . theWindow.Left . ", " . theWindow.Top . ", " . theWindow.Width . ", " . theWindow.Height . "]" - processPath := theWindow.ProcessPath - ; Change Menu MainTitle if (newMenuTitle <> G_MenuTitle) { G_MenuTitle := newMenuTitle - Menu, WindowMenu, Rename, 1&, %G_MenuTitle% - } - - ; Configure Window Positions Menu - desktopSize := GetDesktopSize() - - title := "Save Window &Positions (" . desktopSize.DimensionsText . ")" - if (title <> G_SaveWindowPositionsMenuTitle) - { - Menu, WindowMenu, Rename, %G_SaveWindowPositionsMenuTitle%, %title% - G_SaveWindowPositionsMenuTitle := title - LogText("G_SaveWindowPositionsMenuTitle: " . G_SaveWindowPositionsMenuTitle) - } - - title := "Restore Window &Positions (" . desktopSize.DimensionsText . ")" - if (title <> G_RestoreWindowPositionsMenuTitle) - { - Menu, WindowMenu, Rename, %G_RestoreWindowPositionsMenuTitle%, %title% - G_RestoreWindowPositionsMenuTitle := title - LogText("G_RestoreWindowPositionsMenuTitle: " . G_RestoreWindowPositionsMenuTitle) - } - - title := "Save &Desktop Icons (" . desktopSize.DimensionsText . ")" - if (title <> G_SaveDesktopIconsMenuTitle) - { - Menu, WindowMenu, Rename, %G_SaveDesktopIconsMenuTitle%, %title% - G_SaveDesktopIconsMenuTitle := title - LogText("G_SaveDesktopIconsMenuTitle: " . G_SaveDesktopIconsMenuTitle) + Menu, %WindowMenuName%, Rename, 1&, %G_MenuTitle% } - title := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")" - if (title <> G_RestoreDesktopIconsMenuTitle) - { - Menu, WindowMenu, Rename, %G_RestoreDesktopIconsMenuTitle%, %title% - G_RestoreDesktopIconsMenuTitle := title - LogText("G_RestoreDesktopIconsMenuTitle: " . G_RestoreDesktopIconsMenuTitle) - } - - If (HasSavedWindowPositionFile(desktopSize)) - { - Menu, WindowMenu, Enable, %G_RestoreWindowPositionsMenuTitle% - } - else - { - Menu, WindowMenu, Disable, %G_RestoreWindowPositionsMenuTitle% - } - - If (HasSavedDesktopIconsFile(desktopSize)) - { - Menu, WindowMenu, Enable, %G_RestoreDesktopIconsMenuTitle% - } - else - { - Menu, WindowMenu, Disable, %G_RestoreDesktopIconsMenuTitle% - } - - try Menu, WindowMenu, Icon, 1&, %processPath%, 0 + processPath := theWindow.ProcessPath + + try Menu, %WindowMenuName%, Icon, 1&, %processPath%, 0 ; Enable / Disable as appropriate - if (IsWindowTopMost(theWindow.WindowHandle)) - { - Menu, WindowMenu, Disable, Set Top&Most On - Menu, WindowMenu, Enable, Set Top&Most Off - } - else - { - Menu, WindowMenu, Enable, Set Top&Most On - Menu, WindowMenu, Disable, Set Top&Most Off - } + enableTopMostOff := IsWindowTopMost(theWindow.WindowHandle) + enableTopMostOn := !enableTopMostOff + EnableMenuItem(WindowMenuName, "Set Top&Most On", enableTopMostOn) + EnableMenuItem(WindowMenuName, "Set Top&Most Off", enableTopMostOff) + ; Show Popup Menu - Menu, WindowMenu, Show + Menu, %WindowMenuName%, Show } ;-------------------------------------------------------------------------------- @@ -465,6 +384,7 @@ ShowMenu(theWindow) G_CurrentMouse := New Coordinate(mouseX, mouseY) ShowMenu(G_ActiveWindow) + return ;-------------------------------------------------------------------------------- From 95965c6e5d61674889334acc58c344eccbb8c8bd Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:25:10 +0000 Subject: [PATCH 5/8] Support new config settings --- WindowExtensionsUserConfigGui.ahk | 41 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/WindowExtensionsUserConfigGui.ahk b/WindowExtensionsUserConfigGui.ahk index b6b4d70..b12211e 100644 --- a/WindowExtensionsUserConfigGui.ahk +++ b/WindowExtensionsUserConfigGui.ahk @@ -1,3 +1,5 @@ +#Include Lib/StringUtils.ahk +#Include Lib/ArrayUtils.ahk #Include WindowExtensionsUserConfig.ahk cascadeGutterSize := 0 @@ -13,6 +15,11 @@ BuildUserConfigGui(windowExtensionsUserConfig) global spanMonitorGutterSize global restoreDesktopIconsOnStartup global restoreWindowPositionsOnStartup + global desktopIconsMenuLocation + global windowPositionsMenuLocation + + global MenuLocationValues + global MenuLocationItems cascadeGutterSize := windowExtensionsUserConfig.CascadeGutterSize columnGutterSize := windowExtensionsUserConfig.ColumnGutterSize @@ -20,6 +27,13 @@ BuildUserConfigGui(windowExtensionsUserConfig) spanMonitorGutterSize := windowExtensionsUserConfig.SpanMonitorGutterSize restoreDesktopIconsOnStartup := windowExtensionsUserConfig.RestoreDesktopIconsOnStartup ? 1 : 0 restoreWindowPositionsOnStartup := windowExtensionsUserConfig.RestoreWindowPositionsOnStartup ? 1 : 0 + desktopIconsMenuLocation := windowExtensionsUserConfig.DesktopIconsMenuLocation + windowPositionsMenuLocation := windowExtensionsUserConfig.WindowPositionsMenuLocation + + desktopIconsMenuLocationChoice := IndexOf(MenuLocationValues, desktopIconsMenuLocation) + windowPositionsMenuLocationChoice := IndexOf(MenuLocationValues, windowPositionsMenuLocation) + + menuLocationItemsText := JoinItems("|", MenuLocationItems) Gui, Config:New, -SysMenu Gui, Config:Add, Text,, Cascade Gutter Size: @@ -28,6 +42,8 @@ BuildUserConfigGui(windowExtensionsUserConfig) Gui, Config:Add, Text,, Span Monitor Gutter Size: Gui, Config:Add, Text,, Restore Desktop Icons on Startup: Gui, Config:Add, Text,, Restore Window Positions on Startup: + Gui, Config:Add, Text,, Save / Restore Window Positions Menu Location: + Gui, Config:Add, Text,, Save / Restore Desktop Icons Menu Location: Gui, Config:Add, Edit, ym w80 Gui, Config:Add, UpDown, vcascadeGutterSize Range0-100, %cascadeGutterSize% Gui, Config:Add, Edit, w80 @@ -38,16 +54,18 @@ BuildUserConfigGui(windowExtensionsUserConfig) Gui, Config:Add, UpDown, vspanMonitorGutterSize Range0-100, %spanMonitorGutterSize% Gui, Config:Add, Checkbox, vrestoreDesktopIconsOnStartup Checked%restoreDesktopIconsOnStartup%, Gui, Config:Add, Checkbox, vrestoreWindowPositionsOnStartup Checked%restoreWindowPositionsOnStartup%, `n - Gui, Config:Add, Button, default x50 y180 w80, OK ; The label ButtonOK (if it exists) will be run when the button is pressed. - Gui, Config:Add, Button, x140 y180 w80, Cancel ; The label ButtonCancel (if it exists) will be run when the button is pressed. + Gui, Config:Add, DropDownList, vwindowPositionsMenuLocation AltSubmit Choose%windowPositionsMenuLocationChoice%, %menuLocationItemsText% + Gui, Config:Add, DropDownList, vdesktopIconsMenuLocation AltSubmit Choose%desktopIconsMenuLocationChoice%, %menuLocationItemsText% + Gui, Config:Add, Button, default x240 y230 w80, OK ; The label ButtonOK (if it exists) will be run when the button is pressed. + Gui, Config:Add, Button, x330 y230 w80, Cancel ; The label ButtonCancel (if it exists) will be run when the button is pressed. } -DestroyConfigGui() +DestroyUserConfigGui() { Gui, Config:Destroy } -ShowUserConfig() +ShowUserConfigGui() { global G_UserConfig @@ -58,19 +76,19 @@ ShowUserConfig() ConfigGuiEscape: { - DestroyConfigGui() + DestroyUserConfigGui() return } ConfigGuiClose: { - DestroyConfigGui() + DestroyUserConfigGui() return } ConfigButtonCancel: { - DestroyConfigGui() + DestroyUserConfigGui() return } @@ -80,6 +98,8 @@ ConfigButtonOK: global columnGutterSize global gridGutterSize global spanMonitorGutterSize + + global MenuLocationValues Gui, Config:Submit @@ -89,9 +109,12 @@ ConfigButtonOK: G_UserConfig.SpanMonitorGutterSize := spanMonitorGutterSize G_UserConfig.RestoreDesktopIconsOnStartup := restoreDesktopIconsOnStartup G_UserConfig.RestoreWindowPositionsOnStartup := restoreWindowPositionsOnStartup + G_UserConfig.DesktopIconsMenuLocation := MenuLocationValues[desktopIconsMenuLocation] + G_UserConfig.WindowPositionsMenuLocation := MenuLocationValues[windowPositionsMenuLocation] G_UserConfig.Save() - DestroyConfigGui() + OnUserConfigUpdated() + + DestroyUserConfigGui() return } - From 55475f005339550c6c601b54a57c7f42b1d503cc Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:25:48 +0000 Subject: [PATCH 6/8] Refactor primary module to event design --- WindowExtensions.ahk | 117 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 25 deletions(-) diff --git a/WindowExtensions.ahk b/WindowExtensions.ahk index 3912b88..40bc9df 100644 --- a/WindowExtensions.ahk +++ b/WindowExtensions.ahk @@ -8,54 +8,121 @@ SetBatchLines, 10ms SetTitleMatchMode, 2 ;-------------------------------------------------------------------------------- -; Initialisation +; Application Details AppName := "WindowExtensions" AppTitle := "Window Extensions" AppDescription := "Window Extensions Menu and HotKeys" AppNotes := "Concise and consistent control over Window Positions. Right-click right half of Window Caption bar to invoke, or hit WinKey-W" AppURL := "https://github.com/martinsmith1968/WindowExtensions" -AppVersion := "1.5.0.0" +AppVersion := "1.6.0.0" ;-------------------------------------------------------------------------------- -; Setup Tray Menu -Menu, Tray, NoStandard -Menu, Tray, Tip, %AppTitle% +; Includes +#Include Lib\Logging.ahk +LogInit() + +;-------------------------------------------------------------------------------- +; System Information +SysGet, G_CaptionHeight, 4 ; SM_CYCAPTION +SysGet, G_BorderHeight, 5 ; SM_CXBORDER +SysGet, G_MenuDropAlignment, 40 ; SM_MENUDROPALIGNMENT +SysGet, G_MonitorCount, MonitorCount +SysGet, G_PrimaryMonitorIndex, MonitorPrimary + +SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt +IconLibraryFileName := ScriptFilePath . "\" . ScriptFileNameNoExt . ".icl" + +G_CaptionHitHeight := G_CaptionHeight + (G_BorderHeight * 2) +G_LeftAlignedMenus := (G_MenuDropAlignment = 0) -Menu, Tray, Add, Con&figure..., TrayConfigureHandler -try Menu, Tray, Icon, Con&figure..., %A_ScriptFullPath%, 0 -Menu, Tray, Add -Menu, Tray, Add, &About..., TrayAboutHandler -Menu, Tray, Add -Menu, Tray, Add, Exit, TrayExitHandler +LogText("G_CaptionHeight: " G_CaptionHeight) +LogText("G_BorderHeight: " G_BorderHeight) +LogText("G_MonitorCount: " G_MonitorCount) +LogText("G_PrimaryMonitorIndex: " G_PrimaryMonitorIndex) +LogText("G_CaptionHitHeight: " G_CaptionHitHeight) +LogText("G_LeftAlignedMenus: " G_LeftAlignedMenus) ;-------------------------------------------------------------------------------- -; Includes -#Include Lib\Logging.ahk -#Include WindowExtensionsUserConfig.ahk +; Globals Declarations +G_UserConfig := +G_ActiveWindow := +G_CurrentMouse := +G_MenuTitle := AppTitle +G_SaveWindowPositionsMenuTitle := "" +G_RestoreWindowPositionsMenuTitle := "" +G_SaveDesktopIconsMenuTitle := "" +G_RestoreDesktopIconsMenuTitle := "" + +OnExit, ExitHandler + +;-------------------------------------------------------------------------------- +; Auto-Execute section +OnInit() ; Perform module initialisation - not reliant on other modules +InitGlobals() ; +OnStartup() ; Perform module startup - may rely on other modules Init + +return ; End of script's auto-execute section. + ;-------------------------------------------------------------------------------- -; Globals -G_UserConfig := new WindowExtensionsUserConfig() +; Exit Handler +ExitHandler: +OnExit() +; Must do this for the OnExit subroutine to actually Exit the script. +ExitApp + +;-------------------------------------------------------------------------------- +;-------------------------------------------------------------------------------- +;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; Modules +#Include TrayMenu.ahk #include WindowMenu.ahk #Include WindowHotKeys.ahk #Include WindowExtensionsUserConfigGui.ahk #Include AboutGui.ahk -return +;-------------------------------------------------------------------------------- +; Initialise global variables once everything else initialised +InitGlobals() +{ + global G_UserConfig + + G_UserConfig := new WindowExtensionsUserConfig() +} ;-------------------------------------------------------------------------------- -TrayExitHandler: -ExitApp +; Module initialisation +OnInit() +{ + WindowExtensionsUserConfig_OnInit() + WindowPositions_OnInit() + DesktopIcons_OnInit() + WindowMenu_OnInit() + TrayMenu_OnInit() +} + +;-------------------------------------------------------------------------------- +; OnStartup event +OnStartup() +{ + WindowExtensionsUserConfig_OnStartup() + WindowMenu_OnStartup() + TrayMenu_OnStartup() +} ;-------------------------------------------------------------------------------- -TrayAboutHandler: -ShowAbout() -return +; OnExit event +OnExit() +{ + WindowMenu_OnExit() +} ;-------------------------------------------------------------------------------- -TrayConfigureHandler: -ShowUserConfig() -return +; OnUserConfigUpdated event +OnUserConfigUpdated() +{ + BuildWindowMenu() + BuildTrayMenu() +} From c3721986a3e41b54c124a01fb2943f1c4c549628 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:26:05 +0000 Subject: [PATCH 7/8] Doc updates for new version --- Docs/releasenotes.md | 5 +++++ Docs/todo.md | 3 --- README.md | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Docs/releasenotes.md b/Docs/releasenotes.md index a24213b..3f1b797 100644 --- a/Docs/releasenotes.md +++ b/Docs/releasenotes.md @@ -1,5 +1,10 @@ # Release Notes +## v1.6.0 - 2020-01-04 + +- Restructured code radically to better organise modules and avoid multi module hell of inline startup code +- Implemented options to control which menus the Save / Restore Window Positions and Desktop Icons appear in + ## v1.5.0 - 2020-01-01 - Added options for Restore Window Positions on Startup and Restore Desktop Icons on Startup diff --git a/Docs/todo.md b/Docs/todo.md index cbbc8e0..3518a21 100644 --- a/Docs/todo.md +++ b/Docs/todo.md @@ -1,8 +1,5 @@ # To Do -- Move Window Positions Menu to Context Menu (Option?) -- Move Saved Desktop Icon Positions Menu to Context Menu (Option?) - History list of Saved Window Positions - History list of Saved Desktop Icon Positions - Add icons to other context menu items -- Support other config value types as required diff --git a/README.md b/README.md index 776b8f1..a12e9bf 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Window Extensions has the ability to save window positions and restore them on d This was originally intended as a remedy to the widely known Multi-Monitor bug in Windows that doesn't restore window positions when unlocking or activating / deactivating monitors. -Window positions are saved to a file in the Users data folder (E.g. %APPDATA%\Roaming\WindowExtensions) +Window positions are saved to a file in the Users data folder (E.g. %APPDATA%\WindowExtensions) ### Desktop Icons @@ -53,6 +53,6 @@ Window Extensions has the ability to save desktop icon positions and restore the There are other tools available which are dedicated to this task, with perhaps more functionality. This feature was added to Window Extensions due to restrictions in being able to use these tools on some sites that I visit. -Desktop Icon positions are saved to a file in the Users data folder (E.g. %APPDATA%\Roaming\WindowExtensions) +Desktop Icon positions are saved to a file in the Users data folder (E.g. %APPDATA%\WindowExtensions) ## [To Do](Docs/todo.md) From 36b7254227537f6c3d58b164559020c111e500be Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Fri, 3 Jan 2020 10:28:18 +0000 Subject: [PATCH 8/8] Version bump for setup --- Setup/WindowMenu_Setup.iss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/WindowMenu_Setup.iss b/Setup/WindowMenu_Setup.iss index 5b6b4b7..869fa67 100644 --- a/Setup/WindowMenu_Setup.iss +++ b/Setup/WindowMenu_Setup.iss @@ -1,6 +1,6 @@ #define AppName "WindowExtensions" #define AppTitle "Window Extensions" -#define AppVersion "1.5.0" +#define AppVersion "1.6.0" [Setup] AppName={#AppName}