From 4620408b07d16d7891c9f67bb5d6ac3dbd15cc98 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Thu, 30 Jan 2020 23:19:25 +0000 Subject: [PATCH 1/5] Untabified --- AboutGui.ahk | 44 +- Lib/ArrayUtils.ahk | 28 +- Lib/IOClasses.ahk | 4 +- Lib/IOUtils.ahk | 8 +- Lib/ListViewSelector.ahk | 174 +++---- Lib/Logging.ahk | 72 +-- Lib/MathUtils.ahk | 34 +- Lib/MenuFunctions.ahk | 52 +- Lib/PleasantNotify.ahk | 208 ++++---- Lib/StringUtils.ahk | 94 ++-- Lib/UserConfig.ahk | 192 ++++---- Lib/UserDataUtils.ahk | 52 +- Lib/WindowExtensionsClasses.ahk | 4 +- Lib/WindowFunctions.ahk | 382 +++++++-------- Lib/WindowObjects.ahk | 758 +++++++++++++++--------------- TrayMenu.ahk | 140 +++--- WindowExtensions.ahk | 42 +- WindowExtensionsUserConfig.ahk | 696 +++++++++++++-------------- WindowExtensionsUserConfigGui.ahk | 470 +++++++++--------- WindowHotKeys.ahk | 14 +- WindowMenu.ahk | 438 ++++++++--------- 21 files changed, 1953 insertions(+), 1953 deletions(-) diff --git a/AboutGui.ahk b/AboutGui.ahk index cb14b9a..bcbda05 100644 --- a/AboutGui.ahk +++ b/AboutGui.ahk @@ -1,45 +1,45 @@ BuildAboutGui() { - Global AppName, AppTitle, AppDescription, AppNotes, AppURL, AppVersion - - Gui, About:New, -SysMenu +OwnDialogs - Gui, About:Add, Picture, x10 y10, %A_ScriptFullPath% - Gui, About:Add, Text, x52 y10, %AppTitle% v%AppVersion% - Gui, About:Add, Text, x52 y30, %AppDescription% - Gui, About:Add, Text, x52 y50 h60 w280, %AppNotes% - Gui, About:Add, Link, x52 y120, %AppURL% - Gui, About:Add, Button, default x135 y150 w80, OK + Global AppName, AppTitle, AppDescription, AppNotes, AppURL, AppVersion + + Gui, About:New, -SysMenu +OwnDialogs + Gui, About:Add, Picture, x10 y10, %A_ScriptFullPath% + Gui, About:Add, Text, x52 y10, %AppTitle% v%AppVersion% + Gui, About:Add, Text, x52 y30, %AppDescription% + Gui, About:Add, Text, x52 y50 h60 w280, %AppNotes% + Gui, About:Add, Link, x52 y120, %AppURL% + Gui, About:Add, Button, default x135 y150 w80, OK } DestroyAboutGui() { - Gui, About:Destroy + Gui, About:Destroy } ShowAboutGui() { - Global AppName, AppTitle, AppDescription, AppNotes, AppURL, AppVersion - - BuildAboutGui() - - Gui, About:Show, w350 h180, About... %AppTitle% + Global AppName, AppTitle, AppDescription, AppNotes, AppURL, AppVersion + + BuildAboutGui() + + Gui, About:Show, w350 h180, About... %AppTitle% } AboutGuiEscape: { - DestroyAboutGui() - return + DestroyAboutGui() + return } AboutGuiClose: { - DestroyAboutGui() - return + DestroyAboutGui() + return } AboutButtonOK: { - DestroyAboutGui() - return -} + DestroyAboutGui() + return +} diff --git a/Lib/ArrayUtils.ahk b/Lib/ArrayUtils.ahk index dce171e..ea201a3 100644 --- a/Lib/ArrayUtils.ahk +++ b/Lib/ArrayUtils.ahk @@ -3,24 +3,24 @@ SortArray(Arr) { t:=Object() - + for k, v in Arr t[RegExReplace(v,"\s")] := v - + for k, v in t Arr[A_Index] := v - + return Arr } ReverseArray(arr) { - newArr := [] - - for k, v in arr - newArr.Insert(1, v) - - return newArr + newArr := [] + + for k, v in arr + newArr.Insert(1, v) + + return newArr } ;-------------------------------------------------------------------------------- @@ -28,10 +28,10 @@ ReverseArray(arr) IndexOf(array, item) { for index, param in array - { - if (param = item) - return index - } - + { + if (param = item) + return index + } + return 0 } diff --git a/Lib/IOClasses.ahk b/Lib/IOClasses.ahk index 3d62f58..747dab6 100644 --- a/Lib/IOClasses.ahk +++ b/Lib/IOClasses.ahk @@ -83,8 +83,8 @@ _FullFileName := ; DataFile - Class to represent a data file with a well formed name class DataFile extends FileNameParser { - __New(fullFileName) - { + __New(fullFileName) + { base.__New(fullFileName) } diff --git a/Lib/IOUtils.ahk b/Lib/IOUtils.ahk index 8e03f8e..78cb69e 100644 --- a/Lib/IOUtils.ahk +++ b/Lib/IOUtils.ahk @@ -49,8 +49,8 @@ FileExists(fileName) fileAttribute := FileExist(fileName) exists := (fileAttribute && fileAttribute != "X") - - return exists + + return exists } ;-------------------------------------------------------------------------------- @@ -60,8 +60,8 @@ FolderExists(folderName) folderAttribute := FileExist(folderName) exists := (folderAttribute && InStr(folderAttribute, "D")) - - return exists + + return exists } ;-------------------------------------------------------------------------------- diff --git a/Lib/ListViewSelector.ahk b/Lib/ListViewSelector.ahk index d13ae28..56e0123 100644 --- a/Lib/ListViewSelector.ahk +++ b/Lib/ListViewSelector.ahk @@ -16,117 +16,117 @@ MaxRowCountSize := 20 ListViewWidth := 400 OnSuccess := "" - __New() - { - this.Title := "Select..." - this.ColumnNames := [] - this.ColumnOptions := [] - this.Items := [] - this.SelectedIndex := 0 - this.MinRowCountSize := 5 - this.MaxRowCountSize := 20 - this.ListViewWidth := 400 - this.OnSuccess := "" - } - - ShowDialog() - { - global G_CurrentListViewSelector - - G_CurrentListViewSelector := this - - this.BuildGui() + __New() + { + this.Title := "Select..." + this.ColumnNames := [] + this.ColumnOptions := [] + this.Items := [] + this.SelectedIndex := 0 + this.MinRowCountSize := 5 + this.MaxRowCountSize := 20 + this.ListViewWidth := 400 + this.OnSuccess := "" + } + + ShowDialog() + { + global G_CurrentListViewSelector + + G_CurrentListViewSelector := this + + this.BuildGui() - if (this.SelectedIndex) - { - LV_Modify(this.SelectedIndex, "Select") - } - - this.PopulateItems() + if (this.SelectedIndex) + { + LV_Modify(this.SelectedIndex, "Select") + } + + this.PopulateItems() - this.SetupColumns() + this.SetupColumns() - Gui, LvwSelector:Show - } + Gui, LvwSelector:Show + } - BuildGui() - { - title := this.Title - columnNameText := JoinItems("|", this.ColumnNames) - rowCount := MinOf(MaxOf(this.Items.length(), this.MinRowCountSize), this.MaxRowCountSize) - - buttonWidth := 80 - buttonLeft := this.ListViewWidth - (buttonWidth * 2) - - listViewWidth := this.ListViewWidth - - Gui, LvwSelector:New, -SysMenu, %title% - Gui, LvwSelector:Add, ListView, r%rowCount% w%listViewWidth% gLvwSelectorListView, %columnNameText% - - Gui, LvwSelector:Add, Button, Section default x%buttonLeft% w80 gLvwSelectorGuiButtonOK, OK - Gui, LvwSelector:Add, Button, ys x+10 w80, Cancel - } - - PopulateItems() - { - LV_Delete() - - for index, item in this.Items - { - LV_Add("", item*) - } - } - - SetupColumns() - { - for index, item in this.ColumnOptions - { - LV_ModifyCol(index, item) - } - } + BuildGui() + { + title := this.Title + columnNameText := JoinItems("|", this.ColumnNames) + rowCount := MinOf(MaxOf(this.Items.length(), this.MinRowCountSize), this.MaxRowCountSize) + + buttonWidth := 80 + buttonLeft := this.ListViewWidth - (buttonWidth * 2) + + listViewWidth := this.ListViewWidth + + Gui, LvwSelector:New, -SysMenu, %title% + Gui, LvwSelector:Add, ListView, r%rowCount% w%listViewWidth% gLvwSelectorListView, %columnNameText% + + Gui, LvwSelector:Add, Button, Section default x%buttonLeft% w80 gLvwSelectorGuiButtonOK, OK + Gui, LvwSelector:Add, Button, ys x+10 w80, Cancel + } + + PopulateItems() + { + LV_Delete() + + for index, item in this.Items + { + LV_Add("", item*) + } + } + + SetupColumns() + { + for index, item in this.ColumnOptions + { + LV_ModifyCol(index, item) + } + } } ;-------------------------------------------------------------------------------- ; DestroyConfigGui - Destroy the Config Gui DestroyLvwSelectorGui() { - Gui, LvwSelector:Destroy + Gui, LvwSelector:Destroy } LvwSelectorListView() { - if (A_GuiEvent = "DoubleClick") - { - LV_Modify(A_EventInfo, "Select") - LvwSelectorGuiButtonOK() - } + if (A_GuiEvent = "DoubleClick") + { + LV_Modify(A_EventInfo, "Select") + LvwSelectorGuiButtonOK() + } } LvwSelectorButtonCancel() { - DestroyLvwSelectorGui() + DestroyLvwSelectorGui() } LvwSelectorGuiEscape() { - LvwSelectorButtonCancel() + LvwSelectorButtonCancel() } LvwSelectorGuiButtonOK() { - global G_CurrentListViewSelector - - G_CurrentListViewSelector.SelectedIndex := LV_GetNext() - if (!(G_CurrentListViewSelector.SelectedIndex)) - return - - Gui, LvwSelector:Submit - - DestroyLvwSelectorGui() - - funcName := G_CurrentListViewSelector.OnSuccess - if (funcName) - { - %funcName%(G_CurrentListViewSelector) - } + global G_CurrentListViewSelector + + G_CurrentListViewSelector.SelectedIndex := LV_GetNext() + if (!(G_CurrentListViewSelector.SelectedIndex)) + return + + Gui, LvwSelector:Submit + + DestroyLvwSelectorGui() + + funcName := G_CurrentListViewSelector.OnSuccess + if (funcName) + { + %funcName%(G_CurrentListViewSelector) + } } diff --git a/Lib/Logging.ahk b/Lib/Logging.ahk index 4b8d033..37b0e57 100644 --- a/Lib/Logging.ahk +++ b/Lib/Logging.ahk @@ -4,55 +4,55 @@ LogFile := ; LogInit - Initialise logging (explicit call, rather than relying on include) LogInit() { - global LogFile - - LogFile := A_Temp + global LogFile + + LogFile := A_Temp - SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt + SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt - ; Initialise Log - LogFileSuffix := "" - IfNotEqual, A_IsCompiled, 1 - { - LogFileSuffix := ".Debug" - } + ; Initialise Log + LogFileSuffix := "" + IfNotEqual, A_IsCompiled, 1 + { + LogFileSuffix := ".Debug" + } - LogFile := A_Temp . "\" . ScriptFileNameNoExt . LogFileSuffix . ".log" - LogStart() + LogFile := A_Temp . "\" . ScriptFileNameNoExt . LogFileSuffix . ".log" + LogStart() } ;-------------------------------------------------------------------------------- ; LogText - Debug Text to a file LogText(text) { - global LogFile - - if (LogFile) - { - FormatTime now,, yyy-MM-dd HH:mm.ss - FileAppend %now% %text%`r`n, %LogFile% - } + global LogFile + + if (LogFile) + { + FormatTime now,, yyy-MM-dd HH:mm.ss + FileAppend %now% %text%`r`n, %LogFile% + } } ;-------------------------------------------------------------------------------- ; LogStart - Begin a logging session LogStart() { - global LogFile - - if (LogFile) - { - IfNotEqual, A_IsCompiled, 1 - { - FileDelete, LogFile - file := FileOpen(LogFile, "w") - if IsObject(file) - { - file.Close() - } - } - } - - LogText("------------------------------------------------------------------------------------------------------------------------") - LogText("Starting...") + global LogFile + + if (LogFile) + { + IfNotEqual, A_IsCompiled, 1 + { + FileDelete, LogFile + file := FileOpen(LogFile, "w") + if IsObject(file) + { + file.Close() + } + } + } + + LogText("------------------------------------------------------------------------------------------------------------------------") + LogText("Starting...") } diff --git a/Lib/MathUtils.ahk b/Lib/MathUtils.ahk index 1763658..0fe3e96 100644 --- a/Lib/MathUtils.ahk +++ b/Lib/MathUtils.ahk @@ -2,33 +2,33 @@ ; MinOf - Find the lower of 2 numbers MinOf(a, b) { - if (a < b) - { - return a - } - else - { - return b - } + if (a < b) + { + return a + } + else + { + return b + } } ;-------------------------------------------------------------------------------- ; MaxOf - Find the higher of 2 numbers MaxOf(a, b) { - if (a > b) - { - return a - } - else - { - return b - } + if (a > b) + { + return a + } + else + { + return b + } } ;-------------------------------------------------------------------------------- ; ContainsFlag - Does a value contain a bitwise value ContainsFlag(value, bitwiseFlag) { - return (bitwiseFlag > 0) && (value & bitwiseFlag) > 0 + return (bitwiseFlag > 0) && (value & bitwiseFlag) > 0 } diff --git a/Lib/MenuFunctions.ahk b/Lib/MenuFunctions.ahk index 859ca85..344bc14 100644 --- a/Lib/MenuFunctions.ahk +++ b/Lib/MenuFunctions.ahk @@ -4,54 +4,54 @@ ; ResetMenu - Remove all items from a Menu ResetMenu(menuName) { - try Menu, %menuName%, DeleteAll + 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 + 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 + 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) + 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% + state := enabled ? "Enable" : "Disable" + LogText("Enabling: " . menuName . " - " . menuTitle . ", with " . enabled . " = " . state) + + Menu, %menuName%, %state%, %menuTitle% } diff --git a/Lib/PleasantNotify.ahk b/Lib/PleasantNotify.ahk index 3d61731..43b29e3 100644 --- a/Lib/PleasantNotify.ahk +++ b/Lib/PleasantNotify.ahk @@ -21,121 +21,121 @@ return */ Class PleasantNotify { - __New(title - ,message - ,pnW=700 - ,pnH=300 - ,position="b r" - ,time=5 - ,backgroundColor="0xC0C0C0" - ,titleFontName="Segoe UI" - ,titleFontDetails="cBlue s16 wBold" - ,textFontName="Segoe UI" - ,textFontDetails="cBlack s12 wRegular") { - Critical - lastfound := WinExist() - - Gui, New, % "HwndPN_hwnd" - this.PN_hwnd := PN_hwnd - Gui, % PN_hwnd ": Default" - Gui, % PN_hwnd ": +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound" - ;WinSet, ExStyle, +0x20 - WinSet, Transparent, 0 - Gui, % PN_hwnd ": Color", % backgroundColor - Gui, % PN_hwnd ": Font", % titleFontDetails, % titleFontName - Gui, % PN_hwnd ": Add", Text, % " x" 20 " y" 12 " w" pnW-20 " hwndTitleHwnd", % title - this.TitleHwnd := TitleHwnd - Gui, % PN_hwnd ": Font", % textFontDetails, % textFontName - Gui, % PN_hwnd ": Add", Text, % " x" 20 " y" 56 " w" pnW-20 " h" pnH-56 " hwndMessageHwnd", % message - if (time = "P"){ - Gui, % PN_hwnd ": Add", Button, % " x" pnW - 80 " y" pnH - 50 " w50 h25 ", OK - ; When OK is clicked, call this instance of the class - fn := bind("_NotifyOK", this) - GuiControl +g, OK, %fn% - } - this.MessageHwnd := MessageHwnd - RealW := pnW + 50 - RealH := pnH + 20 - Gui, % PN_hwnd ": Show", W%RealW% H%RealH% NoActivate - this.WinMove(PN_hwnd, position) - ;Gui, % PN_Hwnd ": +Parent" A_ScriptHwnd - if A_ScreenDPI = 96 - WinSet, Region,0-0 w%pnW% h%pnH% R40-40,%A_ScriptName% - /* For Screen text size 125% - if A_ScreenDPI = 120 - WinSet, Region, 0-0 w800 h230 R40-40, %A_ScriptName% - */ - Critical Off - this.winfade("ahk_id " PN_hwnd,210,5) - if (time != "P") - { - ; Bind this class to the timer. - fn := bind("_NotifyTimer", this) - SetTimer %fn%, % time * -1000 - } - - if (WinExist(lastfound)){ - Gui, % lastfound ":Default" - } - } - - __Delete(){ - this.Destroy() - } - - TimerExpired(){ - this.winfade("ahk_id " this.PN_hwnd,0,5) - Gui, % this.PN_hwnd ": Destroy" - } - - OKClicked(){ - this.Destroy() - } - - Destroy(){ - this.winfade("ahk_id " PN_hwnd,0,5) - try - { - Gui, % this.PN_hwnd ": Destroy" - } - catch e - { - } - } + __New(title + ,message + ,pnW=700 + ,pnH=300 + ,position="b r" + ,time=5 + ,backgroundColor="0xC0C0C0" + ,titleFontName="Segoe UI" + ,titleFontDetails="cBlue s16 wBold" + ,textFontName="Segoe UI" + ,textFontDetails="cBlack s12 wRegular") { + Critical + lastfound := WinExist() + + Gui, New, % "HwndPN_hwnd" + this.PN_hwnd := PN_hwnd + Gui, % PN_hwnd ": Default" + Gui, % PN_hwnd ": +AlwaysOnTop +ToolWindow -SysMenu -Caption +LastFound" + ;WinSet, ExStyle, +0x20 + WinSet, Transparent, 0 + Gui, % PN_hwnd ": Color", % backgroundColor + Gui, % PN_hwnd ": Font", % titleFontDetails, % titleFontName + Gui, % PN_hwnd ": Add", Text, % " x" 20 " y" 12 " w" pnW-20 " hwndTitleHwnd", % title + this.TitleHwnd := TitleHwnd + Gui, % PN_hwnd ": Font", % textFontDetails, % textFontName + Gui, % PN_hwnd ": Add", Text, % " x" 20 " y" 56 " w" pnW-20 " h" pnH-56 " hwndMessageHwnd", % message + if (time = "P"){ + Gui, % PN_hwnd ": Add", Button, % " x" pnW - 80 " y" pnH - 50 " w50 h25 ", OK + ; When OK is clicked, call this instance of the class + fn := bind("_NotifyOK", this) + GuiControl +g, OK, %fn% + } + this.MessageHwnd := MessageHwnd + RealW := pnW + 50 + RealH := pnH + 20 + Gui, % PN_hwnd ": Show", W%RealW% H%RealH% NoActivate + this.WinMove(PN_hwnd, position) + ;Gui, % PN_Hwnd ": +Parent" A_ScriptHwnd + if A_ScreenDPI = 96 + WinSet, Region,0-0 w%pnW% h%pnH% R40-40,%A_ScriptName% + /* For Screen text size 125% + if A_ScreenDPI = 120 + WinSet, Region, 0-0 w800 h230 R40-40, %A_ScriptName% + */ + Critical Off + this.winfade("ahk_id " PN_hwnd,210,5) + if (time != "P") + { + ; Bind this class to the timer. + fn := bind("_NotifyTimer", this) + SetTimer %fn%, % time * -1000 + } + + if (WinExist(lastfound)){ + Gui, % lastfound ":Default" + } + } + + __Delete(){ + this.Destroy() + } + + TimerExpired(){ + this.winfade("ahk_id " this.PN_hwnd,0,5) + Gui, % this.PN_hwnd ": Destroy" + } + + OKClicked(){ + this.Destroy() + } + + Destroy(){ + this.winfade("ahk_id " PN_hwnd,0,5) + try + { + Gui, % this.PN_hwnd ": Destroy" + } + catch e + { + } + } - WinMove(hwnd,position) { - SysGet, Mon, MonitorWorkArea - WinGetPos,ix,iy,w,h, ahk_id %hwnd% - x := InStr(position,"l") ? MonLeft : InStr(position,"hc") ? (MonRight-w)/2 : InStr(position,"r") ? MonRight - w : ix - y := InStr(position,"t") ? MonTop : InStr(position,"vc") ? (MonBottom-h)/2 : InStr(position,"b") ? MonBottom - h : iy - WinMove, ahk_id %hwnd%,,x,y - } + WinMove(hwnd,position) { + SysGet, Mon, MonitorWorkArea + WinGetPos,ix,iy,w,h, ahk_id %hwnd% + x := InStr(position,"l") ? MonLeft : InStr(position,"hc") ? (MonRight-w)/2 : InStr(position,"r") ? MonRight - w : ix + y := InStr(position,"t") ? MonTop : InStr(position,"vc") ? (MonBottom-h)/2 : InStr(position,"b") ? MonBottom - h : iy + WinMove, ahk_id %hwnd%,,x,y + } - winfade(w:="",t:=128,i:=1,d:=10) { - w:=(w="")?("ahk_id " WinActive("A")):w - t:=(t>255)?255:(t<0)?0:t - WinGet,s,Transparent,%w% - s:=(s="")?255:s ;prevent trans unset bug - WinSet,Transparent,%s%,%w% - i:=(st):(s255)?255:(t<0)?0:t + WinGet,s,Transparent,%w% + s:=(s="")?255:s ;prevent trans unset bug + WinSet,Transparent,%s%,%w% + i:=(st):(s 0) - { - If (SubStr(text, 1, prefixLength) != prefix) - text := prefix . text - } - - return text + prefixLength := StrLen(prefix) + + if (prefixLength > 0) + { + If (SubStr(text, 1, prefixLength) != prefix) + text := prefix . text + } + + return text } EnsureEndsWith(text, suffix) { - suffixLength := StrLen(suffix) - - if (suffixLength > 0) - { - If (SubStr(text, 1 - suffixLength) != suffix) - text := text . suffix - } - - return text + suffixLength := StrLen(suffix) + + if (suffixLength > 0) + { + If (SubStr(text, 1 - suffixLength) != suffix) + text := text . suffix + } + + return text } RemoveStartsWith(text, prefix) { - prefixLength := StrLen(prefix) - - if (prefixLength > 0) - { - while(SubStr(text, 1, prefixLength) = prefix) - text := SubStr(text, prefixLength + 1) - } - - return text + prefixLength := StrLen(prefix) + + if (prefixLength > 0) + { + while(SubStr(text, 1, prefixLength) = prefix) + text := SubStr(text, prefixLength + 1) + } + + return text } RemoveEndsWith(text, suffix) { - suffixLength := StrLen(suffix) - - if (suffixLength > 0) - { - while(SubStr(text, 1 - suffixLength) = suffix) - text := SubStr(text, 1, StrLen(text) - suffixLength) - } - - return text + suffixLength := StrLen(suffix) + + if (suffixLength > 0) + { + while(SubStr(text, 1 - suffixLength) = suffix) + text := SubStr(text, 1, StrLen(text) - suffixLength) + } + + return text } ToUpper(text) { - StringUpper, result, text - - return result + StringUpper, result, text + + return result } ToLower(text) { - StringLower, result, text - - return result + StringLower, result, text + + return result } JoinText(sep, params*) { for index, param in params str .= param . sep - + return SubStr(str, 1, -StrLen(sep)) } @@ -84,7 +84,7 @@ JoinItems(sep, array) { for index, param in array str .= param . sep - + return SubStr(str, 1, -StrLen(sep)) } diff --git a/Lib/UserConfig.ahk b/Lib/UserConfig.ahk index 0f9a8e7..c4a0660 100644 --- a/Lib/UserConfig.ahk +++ b/Lib/UserConfig.ahk @@ -6,107 +6,107 @@ ; Initialisation UserConfig_OnInit() { - UserDataUtils_OnInit() + UserDataUtils_OnInit() } ;-------------------------------------------------------------------------------- ; UserConfig base class class UserConfig { - DataFileName := - Properties := [] - ObsoleteProperties := [] + DataFileName := + Properties := [] + ObsoleteProperties := [] - __New(fileName) - { - LogText("Setting DataFileName: " . fileName) - this.DataFileName := fileName - } - - GetValue(section, key, defaultValue, type="") - { - dataFileName := this.DataFileName - - LogText("Getting Value: [" . section . "]." . key . ", default: " . defaultValue) - IniRead, readValue, %dataFileName%, %section%, %key%, %defaultValue% - - LogText("Got Value: " . readValue) - - if (type <> "") - { - if (type = "integer") - { - if readValue is not integer - { - readValue := defaultValue - } - } - else if (type == "boolean") - { - readValue := (readValue) ? true : false - } - ; TODO - Support other types as necessary - } - - return readValue - } - - SetValue(section, key, value) - { - dataFileName := this.DataFileName - - LogText("Setting Value: [" . section . "]." . key . ", value: " . value) - IniWrite, %value%, %dataFileName%, %section%, %key% - } - - GetSectionNameFromFunc(func, defaultName := "General") - { - sectionName := Instr(func, ".") ? StrSplit(func, ".")[2] : func - - if (sectionName =) - sectionName := func - - nameParts := StrSplit(sectionName, "_") - if (nameParts.length() > 1) - sectionName := nameParts[1] - else - sectionName := defaultName - - return sectionName - } - - GetPropertyNameFromFunc(func) - { - propertyName := Instr(func, ".") ? StrSplit(func, ".")[2] : func - - if (propertyName =) - propertyName := func - - nameParts := StrSplit(propertyName, "_") - if (nameParts.length() > 1) - propertyName := nameParts[2] - - return propertyName - } - - RemoveProperty(section, propertyName) - { - dataFileName := this.DataFileName - - LogText("Removing: [" . section . "]." . propertyName) - IniDelete, %dataFileName%, %section%, %propertyName% - } - - Save() - { - for index, propertyName in this.Properties - { - value := this[propertyName] - this[propertyName] := value - } - for index, propertyName in this.ObsoleteProperties - { - this.RemoveProperty(this.GetSectionNameFromFunc(propertyName), this.GetPropertyNameFromFunc(propertyName)) - } - } + __New(fileName) + { + LogText("Setting DataFileName: " . fileName) + this.DataFileName := fileName + } + + GetValue(section, key, defaultValue, type="") + { + dataFileName := this.DataFileName + + LogText("Getting Value: [" . section . "]." . key . ", default: " . defaultValue) + IniRead, readValue, %dataFileName%, %section%, %key%, %defaultValue% + + LogText("Got Value: " . readValue) + + if (type <> "") + { + if (type = "integer") + { + if readValue is not integer + { + readValue := defaultValue + } + } + else if (type == "boolean") + { + readValue := (readValue) ? true : false + } + ; TODO - Support other types as necessary + } + + return readValue + } + + SetValue(section, key, value) + { + dataFileName := this.DataFileName + + LogText("Setting Value: [" . section . "]." . key . ", value: " . value) + IniWrite, %value%, %dataFileName%, %section%, %key% + } + + GetSectionNameFromFunc(func, defaultName := "General") + { + sectionName := Instr(func, ".") ? StrSplit(func, ".")[2] : func + + if (sectionName =) + sectionName := func + + nameParts := StrSplit(sectionName, "_") + if (nameParts.length() > 1) + sectionName := nameParts[1] + else + sectionName := defaultName + + return sectionName + } + + GetPropertyNameFromFunc(func) + { + propertyName := Instr(func, ".") ? StrSplit(func, ".")[2] : func + + if (propertyName =) + propertyName := func + + nameParts := StrSplit(propertyName, "_") + if (nameParts.length() > 1) + propertyName := nameParts[2] + + return propertyName + } + + RemoveProperty(section, propertyName) + { + dataFileName := this.DataFileName + + LogText("Removing: [" . section . "]." . propertyName) + IniDelete, %dataFileName%, %section%, %propertyName% + } + + Save() + { + for index, propertyName in this.Properties + { + value := this[propertyName] + this[propertyName] := value + } + for index, propertyName in this.ObsoleteProperties + { + this.RemoveProperty(this.GetSectionNameFromFunc(propertyName), this.GetPropertyNameFromFunc(propertyName)) + } + } } diff --git a/Lib/UserDataUtils.ahk b/Lib/UserDataUtils.ahk index 090540f..2af37df 100644 --- a/Lib/UserDataUtils.ahk +++ b/Lib/UserDataUtils.ahk @@ -11,39 +11,39 @@ UserDataPath := "" ; Initialisation UserDataUtils_OnInit() { - global AppName - global UserDataPath - - SplitPath A_ScriptFullPath, , , , AppName + global AppName + global UserDataPath + + SplitPath A_ScriptFullPath, , , , AppName - UserDataPath := CombinePaths(A_AppData, AppName) + UserDataPath := CombinePaths(A_AppData, AppName) - If (!FolderExists(UserDataPath)) - { - LogText("Creating UserDataPath: " . UserDataPath) - FileCreateDir, %UserDataPath% - } + If (!FolderExists(UserDataPath)) + { + LogText("Creating UserDataPath: " . UserDataPath) + FileCreateDir, %UserDataPath% + } } ;-------------------------------------------------------------------------------- ; GetUserDataFileName : Build an appropriate file name for the specified User data GetUserDataFileName(dataFileName) { - global UserDataPath - + global UserDataPath + fileName := CombinePaths(UserDataPath, dataFileName) - - return fileName + + return fileName } ;-------------------------------------------------------------------------------- ; GetUserDataFileNames : Get a list of appropriate file names for the specified User Data GetUserDataFileNames(dataFilePattern, sortOrder := 0) { - global UserDataPath - + global UserDataPath + filePattern := CombinePaths(UserDataPath, dataFilePattern) - + files := [] Loop, Files, %filePattern% @@ -51,15 +51,15 @@ GetUserDataFileNames(dataFilePattern, sortOrder := 0) files.push(A_LoopFileFullPath) } - if (sortOrder != 0) - { - files := SortArray(files) - - if (sortOrder < 0) - { - files := ReverseArray(files) - } - } + if (sortOrder != 0) + { + files := SortArray(files) + + if (sortOrder < 0) + { + files := ReverseArray(files) + } + } return files } diff --git a/Lib/WindowExtensionsClasses.ahk b/Lib/WindowExtensionsClasses.ahk index 544bd8e..134bd0f 100644 --- a/Lib/WindowExtensionsClasses.ahk +++ b/Lib/WindowExtensionsClasses.ahk @@ -4,8 +4,8 @@ ; WindowExtensionsDataFile - class WindowExtensionsDataFile extends DataFile { - __New(fullFileName) - { + __New(fullFileName) + { base.__New(fullFileName) } diff --git a/Lib/WindowFunctions.ahk b/Lib/WindowFunctions.ahk index e733ab8..2fe3d50 100644 --- a/Lib/WindowFunctions.ahk +++ b/Lib/WindowFunctions.ahk @@ -7,12 +7,12 @@ G_RollupList := Object() ; MoveAndSizeWindow - Set the Window position and size MoveAndSizeWindow(theWindow, winLeft, winTop, winWidth, winHeight) { - windowHandle := theWindow.WindowHandle - + windowHandle := theWindow.WindowHandle + LogText("Window: " . theWindow.ProcessName . " (" . windowHandle . ") Left: " . winLeft . ", Top: " . winTop . ", Width: " . winWidth . ", Height: " . winHeight) - WinMove , ahk_id %windowHandle%, , winLeft, winTop, winWidth, winHeight - WinActivate, ahk_id %windowHandle% + WinMove , ahk_id %windowHandle%, , winLeft, winTop, winWidth, winHeight + WinActivate, ahk_id %windowHandle% WinShow, ahk_id %windowHandle% } @@ -20,229 +20,229 @@ MoveAndSizeWindow(theWindow, winLeft, winTop, winWidth, winHeight) ; MoveAndSizeWindow - Set the Window position MoveWindow(theWindow, winLeft, winTop) { - windowHandle := theWindow.WindowHandle - - WinGet, theProcess, ProcessName, ahk_id %theWindow% + windowHandle := theWindow.WindowHandle + + WinGet, theProcess, ProcessName, ahk_id %theWindow% LogText("Window: " . theWindow.ProcessName . " (" . windowHandle . ") Left: " . winLeft . ", Top: " . winTop) - WinMove , ahk_id %windowHandle%, , winLeft, winTop - WinActivate, ahk_id %windowHandle% - WinShow, ahk_id %windowHandle% + WinMove , ahk_id %windowHandle%, , winLeft, winTop + WinActivate, ahk_id %windowHandle% + WinShow, ahk_id %windowHandle% } ;-------------------------------------------------------------------------------- ; SetWindowStatus - Set the Window Minimized / Maximized status SetWindowStatus(theWindow, status) { - windowHandle := theWindow.WindowHandle - - LogText("Window: " . theWindow.ProcessName . " (" . windowHandle . ") Status: " . status) - If (status = 1) - { - WinMaximize, ahk_id %windowHandle% - } - else if (status = -1) - { - WinMinimize, ahk_id %windowHandle% - } - else - { - WinRestore , ahk_id %windowHandle% - } + windowHandle := theWindow.WindowHandle + + LogText("Window: " . theWindow.ProcessName . " (" . windowHandle . ") Status: " . status) + If (status = 1) + { + WinMaximize, ahk_id %windowHandle% + } + else if (status = -1) + { + WinMinimize, ahk_id %windowHandle% + } + else + { + WinRestore , ahk_id %windowHandle% + } } ;-------------------------------------------------------------------------------- ; SetWindowToCentre - Centre the window on its Monitor SetWindowToCentre(theWindow) { - monitor := new Monitor(theWindow.MonitorIndex) - monitorWorkArea := monitor.WorkArea - - winLeft := monitorWorkArea.Left + (monitorWorkArea.Width - theWindow.Width) / 2 - winTop := monitorWorkArea.Top + (monitorWorkArea.Height- theWindow.Height) / 2 + monitor := new Monitor(theWindow.MonitorIndex) + monitorWorkArea := monitor.WorkArea + + winLeft := monitorWorkArea.Left + (monitorWorkArea.Width - theWindow.Width) / 2 + winTop := monitorWorkArea.Top + (monitorWorkArea.Height- theWindow.Height) / 2 - MoveWindow(theWindow, winLeft, winTop) + MoveWindow(theWindow, winLeft, winTop) } ;-------------------------------------------------------------------------------- ; SetWindowTop - Set the Window TopMost setting SetWindowTop(theWindow, top) { - windowHandle := theWindow.WindowHandle - - if (top = 1) - WinSet, AlwaysOnTop, On, ahk_id %windowHandle% - else if (top = 0) - WinSet, AlwaysOnTop, Off, ahk_id %windowHandle% - else - WinSet, AlwaysOnTop, Toggle, ahk_id %windowHandle% + windowHandle := theWindow.WindowHandle + + if (top = 1) + WinSet, AlwaysOnTop, On, ahk_id %windowHandle% + else if (top = 0) + WinSet, AlwaysOnTop, Off, ahk_id %windowHandle% + else + WinSet, AlwaysOnTop, Toggle, ahk_id %windowHandle% } ;-------------------------------------------------------------------------------- ; SetWindowTransparency - Set the Window Transparency setting SetWindowTransparency(theWindow, transparency) { - windowHandle := theWindow.WindowHandle - - WinSet, Transparent, transparency, ahk_id %windowHandle% + windowHandle := theWindow.WindowHandle + + WinSet, Transparent, transparency, ahk_id %windowHandle% } ;-------------------------------------------------------------------------------- ; SetWindowByGutter - Set the Window position including a gutter SetWindowByGutter(theWindow, gutterSize) { - LogText("gutterSize: " . gutterSize) - - monitor := new Monitor(theWindow.MonitorIndex) - monitorWorkArea := monitor.WorkArea - - winLeft := monitorWorkArea.Left + gutterSize - winTop := monitorWorkArea.Top + gutterSize - winWidth := monitorWorkArea.Width - (gutterSize * 2) - winHeight := monitorWorkArea.Height - (gutterSize * 2) - - MoveAndSizeWindow(theWindow, winLeft, winTop, winWidth, winHeight) + LogText("gutterSize: " . gutterSize) + + monitor := new Monitor(theWindow.MonitorIndex) + monitorWorkArea := monitor.WorkArea + + winLeft := monitorWorkArea.Left + gutterSize + winTop := monitorWorkArea.Top + gutterSize + winWidth := monitorWorkArea.Width - (gutterSize * 2) + winHeight := monitorWorkArea.Height - (gutterSize * 2) + + MoveAndSizeWindow(theWindow, winLeft, winTop, winWidth, winHeight) } ;-------------------------------------------------------------------------------- ; SetWindowByColumn - Set the Window position by column, including a gutter SetWindowByColumn(theWindow, column, maxColumns, gutterSize := 0) { - SetWindowByGrid(theWindow, 1, column, 1, maxColumns, gutterSize) + SetWindowByGrid(theWindow, 1, column, 1, maxColumns, gutterSize) } ;-------------------------------------------------------------------------------- ; SetWindowByRow - Set the Window position by row, including a gutter SetWindowByRow(theWindow, row, maxRows, gutterSize := 0) { - SetWindowByGrid(theWindow, row, 1, maxRows, 1, gutterSize) + SetWindowByGrid(theWindow, row, 1, maxRows, 1, gutterSize) } ;-------------------------------------------------------------------------------- ; SetWindowByGutter - Set the Window position by column, including a gutter SetWindowByGrid(theWindow, row, column, maxRows, maxColumns, gutterSize := 0) { - LogText("Row: " . row . " / " . maxRows . ", Column: " . column . " / " . maxColumns . ", gutterSize: " . gutterSize) - - monitor := new Monitor(theWindow.MonitorIndex) - monitorWorkArea := monitor.WorkArea + LogText("Row: " . row . " / " . maxRows . ", Column: " . column . " / " . maxColumns . ", gutterSize: " . gutterSize) + + monitor := new Monitor(theWindow.MonitorIndex) + monitorWorkArea := monitor.WorkArea - columnWidth := (monitorWorkArea.Width - (gutterSize * 2)) / maxColumns - columnLeft := monitorWorkArea.Left + (columnWidth * (column - 1)) + gutterSize + columnWidth := (monitorWorkArea.Width - (gutterSize * 2)) / maxColumns + columnLeft := monitorWorkArea.Left + (columnWidth * (column - 1)) + gutterSize - rowHeight := (monitorWorkArea.Height - (gutterSize * 2)) / maxRows - rowTop := monitorWorkArea.Top + (rowHeight * (row - 1)) + gutterSize + rowHeight := (monitorWorkArea.Height - (gutterSize * 2)) / maxRows + rowTop := monitorWorkArea.Top + (rowHeight * (row - 1)) + gutterSize - MoveAndSizeWindow(theWindow, columnLeft, rowTop, columnWidth, rowHeight) + MoveAndSizeWindow(theWindow, columnLeft, rowTop, columnWidth, rowHeight) } ;-------------------------------------------------------------------------------- ; SetWindowByGutter - Set the Window position by column, including a gutter SetWindowSpanMonitors(theWindow, alignLeft, alignTop, alignRight, alignBottom, gutterSize := 0) { - windowSpan := new Rectangle2(alignLeft, alignTop, alignRight, alignBottom) - - SysGet, monitorCount, MonitorCount - - Loop, %monitorCount% - { - ; Get Monitor Details - monitor := new Monitor(A_Index) - monitorWorkArea := monitor.WorkArea - - if alignLeft = - { - if (windowSpan.Left = "" || monitorWorkArea.Left < windowSpan.Left) - { - windowSpan.Left := monitorWorkArea.Left - } - } - - if alignRight = - { - if (windowSpan.Right = "" || monitorWorkArea.Right > windowSpan.Right) - { - windowSpan.Right := monitorWorkArea.Right - } - } - - if alignTop = - { - if (windowSpan.Top = "" || monitorWorkArea.Top < windowSpan.Top) - { - windowSpan.Top := monitorWorkArea.Top - } - } - - if alignBottom = - { - if (windowSpan.Bottom = "" || monitorWorkArea.Bottom > windowSpan.Bottom) - { - windowSpan.Bottom := monitorWorkArea.Bottom - } - } - - LogText("Span: " . windowSpan.Description) - } - - MoveAndSizeWindow(theWindow, windowSpan.Left, windowSpan.Top, windowSpan.Width, windowSpan.Height) + windowSpan := new Rectangle2(alignLeft, alignTop, alignRight, alignBottom) + + SysGet, monitorCount, MonitorCount + + Loop, %monitorCount% + { + ; Get Monitor Details + monitor := new Monitor(A_Index) + monitorWorkArea := monitor.WorkArea + + if alignLeft = + { + if (windowSpan.Left = "" || monitorWorkArea.Left < windowSpan.Left) + { + windowSpan.Left := monitorWorkArea.Left + } + } + + if alignRight = + { + if (windowSpan.Right = "" || monitorWorkArea.Right > windowSpan.Right) + { + windowSpan.Right := monitorWorkArea.Right + } + } + + if alignTop = + { + if (windowSpan.Top = "" || monitorWorkArea.Top < windowSpan.Top) + { + windowSpan.Top := monitorWorkArea.Top + } + } + + if alignBottom = + { + if (windowSpan.Bottom = "" || monitorWorkArea.Bottom > windowSpan.Bottom) + { + windowSpan.Bottom := monitorWorkArea.Bottom + } + } + + LogText("Span: " . windowSpan.Description) + } + + MoveAndSizeWindow(theWindow, windowSpan.Left, windowSpan.Top, windowSpan.Width, windowSpan.Height) } ;-------------------------------------------------------------------------------- ; IsWindowTopMost - Detect if a window is set on top IsWindowTopMost(windowHandle) { - WinGet, winStyle, ExStyle, ahk_id %windowHandle% - if (winStyle & 0x8) ; 0x8 is WS_EX_TOPMOST. - { - return true - } - - return false + WinGet, winStyle, ExStyle, ahk_id %windowHandle% + if (winStyle & 0x8) ; 0x8 is WS_EX_TOPMOST. + { + return true + } + + return false } ;-------------------------------------------------------------------------------- ; IsWindowVisible - Detect if a window is visible IsWindowVisible(windowHandle) { - WinGet, Style, Style, ahk_id %windowHandle% - Transform, result, BitAnd, %Style%, 0x10000000 ; 0x10000000 is WS_VISIBLE. - - return result <> 0 + WinGet, Style, Style, ahk_id %windowHandle% + Transform, result, BitAnd, %Style%, 0x10000000 ; 0x10000000 is WS_VISIBLE. + + return result <> 0 } ;-------------------------------------------------------------------------------- ; IsWindowOnScreen - Detect if a window handle is showing on any monitor IsWindowOnScreen(windowHandle) { - WinGetPos, left, top, width, height, ahk_id %windowHandle% - - rect := new Rectangle(left, top, width, height) - - return IsRectOnScreen(rect) + WinGetPos, left, top, width, height, ahk_id %windowHandle% + + rect := new Rectangle(left, top, width, height) + + return IsRectOnScreen(rect) } ;-------------------------------------------------------------------------------- ; IsRectOnScreen - Detect if a rectangle is within any monitor IsRectOnScreen(rect) { - monitorIndex := GetMonitorIndexAt(rect.Left, rect.Top) - if (monitorIndex >= 0) - return true - - monitorIndex := GetMonitorIndexAt(rect.Left, rect.Bottom) - if (monitorIndex >= 0) - return true - - monitorIndex := GetMonitorIndexAt(rect.Right, rect.Top) - if (monitorIndex >= 0) - return true - - monitorIndex := GetMonitorIndexAt(rect.Right, rect.Bottom) - if (monitorIndex >= 0) - return true - - return false + monitorIndex := GetMonitorIndexAt(rect.Left, rect.Top) + if (monitorIndex >= 0) + return true + + monitorIndex := GetMonitorIndexAt(rect.Left, rect.Bottom) + if (monitorIndex >= 0) + return true + + monitorIndex := GetMonitorIndexAt(rect.Right, rect.Top) + if (monitorIndex >= 0) + return true + + monitorIndex := GetMonitorIndexAt(rect.Right, rect.Bottom) + if (monitorIndex >= 0) + return true + + return false } ;-------------------------------------------------------------------------------- @@ -251,15 +251,15 @@ GetWindowNormalPosition(windowHandle) { VarSetCapacity(wp, 44), NumPut(44, wp) DllCall("GetWindowPlacement", "uint", windowHandle, "uint", &wp) - + x := NumGet(wp, 28, "int") y := NumGet(wp, 32, "int") w := NumGet(wp, 36, "int") - x h := NumGet(wp, 40, "int") - y - - rect := new Rectangle(x, y, w, h) - - return rect + + rect := new Rectangle(x, y, w, h) + + return rect } ;-------------------------------------------------------------------------------- @@ -267,15 +267,15 @@ GetWindowNormalPosition(windowHandle) GetDesktopSize() { SysGet, monitorCount, MonitorCount - + desktopSize := new Rectangle2(0, 0) desktopSize.Right := 0 desktopSize.Bottom := 0 - Loop, %monitorCount% - { - ; Get Monitor Details - monitor := new Monitor(A_Index) + Loop, %monitorCount% + { + ; Get Monitor Details + monitor := new Monitor(A_Index) desktopSize.Left := MinOf(monitor.Left, desktopSize.Left) desktopSize.Right := MaxOf(monitor.Right, desktopSize.Right) @@ -290,66 +290,66 @@ GetDesktopSize() ; RollupToggleWindow - Roll up a window to just its title bar RollupToggleWindow(theWindow, rollupHeight) { - global G_RollupList - - windowHandle := theWindow.WindowHandle - - for ruWindowId, ruHeight in G_RollupList - { - IfEqual, ruWindowId, %windowHandle% - { - WinMove, ahk_id %windowHandle%,,,,, %ruHeight% - G_RollupList.Delete(windowHandle) - return - } - } - - WinGetPos,,,, wsHeight, ahk_id %windowHandle% - G_RollupList[windowHandle] := wsHeight - - WinMove, ahk_id %windowHandle%,,,,, %rollupHeight% + global G_RollupList + + windowHandle := theWindow.WindowHandle + + for ruWindowId, ruHeight in G_RollupList + { + IfEqual, ruWindowId, %windowHandle% + { + WinMove, ahk_id %windowHandle%,,,,, %ruHeight% + G_RollupList.Delete(windowHandle) + return + } + } + + WinGetPos,,,, wsHeight, ahk_id %windowHandle% + G_RollupList[windowHandle] := wsHeight + + WinMove, ahk_id %windowHandle%,,,,, %rollupHeight% } ;-------------------------------------------------------------------------------- ; RollupWindow - Roll up a window to just its title bar RestoreRollupWindows() { - global G_RollupList - - Loop, Parse, G_RollupList, | - { - if A_LoopField = ; First field in list is normally blank. - continue ; So skip it. - StringTrimRight, ws_Height, ws_Window%A_LoopField%, 0 - WinMove, ahk_id %A_LoopField%,,,,, %ws_Height% - } + global G_RollupList + + Loop, Parse, G_RollupList, | + { + if A_LoopField = ; First field in list is normally blank. + continue ; So skip it. + StringTrimRight, ws_Height, ws_Window%A_LoopField%, 0 + WinMove, ahk_id %A_LoopField%,,,,, %ws_Height% + } } ;-------------------------------------------------------------------------------- ; SendWindowToBack - Send a Window to the back of the zorder SendWindowToBack(theWindow) { - windowHandle := theWindow.WindowHandle - WinSet, Bottom, , ahk_id %windowHandle%` + windowHandle := theWindow.WindowHandle + WinSet, Bottom, , ahk_id %windowHandle%` } ;-------------------------------------------------------------------------------- ; GetMonitorIndexAt - Get the index of the monitor containing the specified x and y co-ordinates. GetMonitorIndexAt(x, y, defaultMonitor := -1) { - coordinate := new Coordinate(x, y) - ;LogText("GetMonitorIndexAt: " . coordinate.Description) - + coordinate := new Coordinate(x, y) + ;LogText("GetMonitorIndexAt: " . coordinate.Description) + SysGet, monitorCount, MonitorCount - + ; Iterate through all monitors. Loop, %monitorCount% { - ; Get Monitor details - monitor := new Monitor(A_Index) - ;LogText("Monitor: " . monitor.Description) - - ; Check if the coordinates are on this monitor. + ; Get Monitor details + monitor := new Monitor(A_Index) + ;LogText("Monitor: " . monitor.Description) + + ; Check if the coordinates are on this monitor. if (coordinate.IsInRectangle(monitor)) return A_Index } diff --git a/Lib/WindowObjects.ahk b/Lib/WindowObjects.ahk index 365f7da..5131d7e 100644 --- a/Lib/WindowObjects.ahk +++ b/Lib/WindowObjects.ahk @@ -2,412 +2,412 @@ Class Coordinate { - X := 0 - Y := 0 - - __New(x, y) - { - this.X := x - this.Y := y - } - - Left - { - get - { - return this.X - } - set - { - this.X := value - } - } - - Top - { - get - { - return this.Y - } - set - { - this.Y := value - } - } - - Description - { - get - { - return "Left: " . this.Left . ", Top: " . this.Top . ", MonitorIndex: " . this.MonitorIndex - } - } - - IsInRectangle(rect) - { - if (this.X < rect.Left) - return false - if (this.X > rect.Right) - return false - if (this.Y < rect.Top) - return false - if (this.Y > rect.Bottom) - return false - - return true - } - - MonitorIndex - { - get - { - SysGet, primaryMonitorIndex, MonitorPrimary + X := 0 + Y := 0 + + __New(x, y) + { + this.X := x + this.Y := y + } + + Left + { + get + { + return this.X + } + set + { + this.X := value + } + } + + Top + { + get + { + return this.Y + } + set + { + this.Y := value + } + } + + Description + { + get + { + return "Left: " . this.Left . ", Top: " . this.Top . ", MonitorIndex: " . this.MonitorIndex + } + } + + IsInRectangle(rect) + { + if (this.X < rect.Left) + return false + if (this.X > rect.Right) + return false + if (this.Y < rect.Top) + return false + if (this.Y > rect.Bottom) + return false + + return true + } + + MonitorIndex + { + get + { + SysGet, primaryMonitorIndex, MonitorPrimary - index := GetMonitorIndexAt(this.X, this.Y, primaryMonitorIndex) - - return index - } - } + index := GetMonitorIndexAt(this.X, this.Y, primaryMonitorIndex) + + return index + } + } } Class Rectangle extends Coordinate { - Width := 0 - Height := 0 - - __New(x, y, width, height) - { - base.__New(x, y) - - this.Width := width - this.Height := height - } - - Right - { - get - { - return this.X + this.Width - } - } - - Bottom - { - get - { - return this.Y + this.Height - } - } - - IsValid - { - get - { - return this.Width > 0 && this.Height > 0 - } - } + Width := 0 + Height := 0 + + __New(x, y, width, height) + { + base.__New(x, y) + + this.Width := width + this.Height := height + } + + Right + { + get + { + return this.X + this.Width + } + } + + Bottom + { + get + { + return this.Y + this.Height + } + } + + IsValid + { + get + { + return this.Width > 0 && this.Height > 0 + } + } - DimensionsText - { - get - { - return this.Width . "x" . this.Height - } - } - - Description - { - get - { - return "Left: " . this.Left . ", Top: " . this.Top . ", Width: " . this.Width . ", Height: " . this.Height . ", Right: " . this.Right . ", Bottom: " . this.Bottom - } - } + DimensionsText + { + get + { + return this.Width . "x" . this.Height + } + } + + Description + { + get + { + return "Left: " . this.Left . ", Top: " . this.Top . ", Width: " . this.Width . ", Height: " . this.Height . ", Right: " . this.Right . ", Bottom: " . this.Bottom + } + } } Class Rectangle2 extends Coordinate { - Right := 0 - Bottom := 0 - - __New(x, y, right, bottom) - { - base.__New(x, y) - - this.Right := right - this.Bottom := bottom - } - - Width - { - get - { - return this.Right - this.X - } - } - - Height - { - get - { - return this.Bottom - this.Y - } - } - - IsValid - { - get - { - return this.Width > 0 && this.Height > 0 - } - } - - DimensionsText - { - get - { - return this.Width . "x" . this.Height - } - } - - Description - { - get - { - return "Left: " . this.Left . ", Top: " . this.Top . ", Right: " . this.Right . ", Bottom: " . this.Bottom . ", Width: " . this.Width . ", Height: " . this.Height - } - } + Right := 0 + Bottom := 0 + + __New(x, y, right, bottom) + { + base.__New(x, y) + + this.Right := right + this.Bottom := bottom + } + + Width + { + get + { + return this.Right - this.X + } + } + + Height + { + get + { + return this.Bottom - this.Y + } + } + + IsValid + { + get + { + return this.Width > 0 && this.Height > 0 + } + } + + DimensionsText + { + get + { + return this.Width . "x" . this.Height + } + } + + Description + { + get + { + return "Left: " . this.Left . ", Top: " . this.Top . ", Right: " . this.Right . ", Bottom: " . this.Bottom . ", Width: " . this.Width . ", Height: " . this.Height + } + } } Class Window extends Rectangle { - WindowHandle := - WindowStatus := - ProcessName := - ProcessPath := - - __New(windowHandle) - { - WinGetPos, left, top, width, height, ahk_id %windowHandle% - WinGet, status, MinMax, ahk_id %windowHandle% - WinGet, processName, ProcessName, ahk_id %windowHandle% - WinGet, processPath, ProcessPath, ahk_id %windowHandle% - - base.__New(left, top, width, height) + WindowHandle := + WindowStatus := + ProcessName := + ProcessPath := + + __New(windowHandle) + { + WinGetPos, left, top, width, height, ahk_id %windowHandle% + WinGet, status, MinMax, ahk_id %windowHandle% + WinGet, processName, ProcessName, ahk_id %windowHandle% + WinGet, processPath, ProcessPath, ahk_id %windowHandle% + + base.__New(left, top, width, height) - this.WindowHandle := windowHandle - this.WindowStatus := status - this.ProcessName := processName - this.ProcessPath := processPath - } - - IsValid - { - get - { - if (!this.WindowHandle) - return false - - return WinExist("ahk_id " . this.WindowHandle) - } - } - - Title - { - get - { - windowHandle := this.WindowHandle - WinGetTitle, title, ahk_id %windowHandle% - - return title - } - } - - ProcessId - { - get - { - handle := this.WindowHandle - - WinGet, processId, PID, ahk_id %handle% - - return processId - } - } - - IsTopmost - { - get - { - return IsWindowTopmost(this.WindowHandle) - } - } - - IsVisible - { - get - { - return IsWindowVisible(this.WindowHandle) - } - } - - IsOnScreen - { - get - { - return IsWindowOnScreen(this.WindowHandle) - } - } - - MonitorIndex - { - get - { - monitorIndex := GetMonitorIndexAt(this.Left, this.Top) - if (monitorIndex < 0) - { - midX := theWindowLeft + (theWindowWidth / 2) - midY := theWindowTop + (theWindowHeight / 2) - - monitorIndex := GetMonitorIndexAt(midX, midY) - if (monitorIndex < 0) - { - monitorIndex := GetMonitorIndexAt(theWindowRight, theWindowTop) - if (monitorIndex < 0) - { - monitorIndex = GetMonitorIndexAt(theWindowRight, theWindowBottom) - if (monitorIndex < 0) - { - SysGet, monitorIndex, MonitorPrimary - } - } - } - } - - return monitorIndex - } - } - - GetHitArea(hitHeight) - { - area := new Rectangle(this.Left + (this.Width / 2), this.Top, (this.Width / 2), hitHeight) - - return area - } - - Description - { - get - { - return "Handle: " . this.WindowHandle . ", Left: " . this.Left . ", Top: " . this.Top . ", Width: " . this.Width . ", Height: " . this.Height . ", Right: " . this.Right . ", Bottom: " . this.Bottom . ", ProcessName: " . this.ProcessName . ", Title: " . this.Title - } - } + this.WindowHandle := windowHandle + this.WindowStatus := status + this.ProcessName := processName + this.ProcessPath := processPath + } + + IsValid + { + get + { + if (!this.WindowHandle) + return false + + return WinExist("ahk_id " . this.WindowHandle) + } + } + + Title + { + get + { + windowHandle := this.WindowHandle + WinGetTitle, title, ahk_id %windowHandle% + + return title + } + } + + ProcessId + { + get + { + handle := this.WindowHandle + + WinGet, processId, PID, ahk_id %handle% + + return processId + } + } + + IsTopmost + { + get + { + return IsWindowTopmost(this.WindowHandle) + } + } + + IsVisible + { + get + { + return IsWindowVisible(this.WindowHandle) + } + } + + IsOnScreen + { + get + { + return IsWindowOnScreen(this.WindowHandle) + } + } + + MonitorIndex + { + get + { + monitorIndex := GetMonitorIndexAt(this.Left, this.Top) + if (monitorIndex < 0) + { + midX := theWindowLeft + (theWindowWidth / 2) + midY := theWindowTop + (theWindowHeight / 2) + + monitorIndex := GetMonitorIndexAt(midX, midY) + if (monitorIndex < 0) + { + monitorIndex := GetMonitorIndexAt(theWindowRight, theWindowTop) + if (monitorIndex < 0) + { + monitorIndex = GetMonitorIndexAt(theWindowRight, theWindowBottom) + if (monitorIndex < 0) + { + SysGet, monitorIndex, MonitorPrimary + } + } + } + } + + return monitorIndex + } + } + + GetHitArea(hitHeight) + { + area := new Rectangle(this.Left + (this.Width / 2), this.Top, (this.Width / 2), hitHeight) + + return area + } + + Description + { + get + { + return "Handle: " . this.WindowHandle . ", Left: " . this.Left . ", Top: " . this.Top . ", Width: " . this.Width . ", Height: " . this.Height . ", Right: " . this.Right . ", Bottom: " . this.Bottom . ", ProcessName: " . this.ProcessName . ", Title: " . this.Title + } + } } Class Monitor extends Rectangle2 { - MonitorIndex := -1 + MonitorIndex := -1 - __New(index) - { - SysGet, mon, Monitor, %index% - - base.__New(monLeft, monTop, monRight, monBottom) - - this.MonitorIndex := index - } - - WorkArea - { - get - { - index := this.MonitorIndex - SysGet, area, MonitorWorkArea, %index% - - rect := new Rectangle2(areaLeft, areaTop, areaRight, areaBottom) - - return rect - } - } - - Description - { - get - { - return "MonitorIndex: " . this.MonitorIndex . ", " . base.Description - } - } + __New(index) + { + SysGet, mon, Monitor, %index% + + base.__New(monLeft, monTop, monRight, monBottom) + + this.MonitorIndex := index + } + + WorkArea + { + get + { + index := this.MonitorIndex + SysGet, area, MonitorWorkArea, %index% + + rect := new Rectangle2(areaLeft, areaTop, areaRight, areaBottom) + + return rect + } + } + + Description + { + get + { + return "MonitorIndex: " . this.MonitorIndex . ", " . base.Description + } + } } class Desktop { - DefViewParentWindow := - DefViewWindow := - SysListView32Window := - - __New() - { - ; Inspired by : https://www.autohotkey.com/boards/viewtopic.php?t=70072&p=302495 - - ;handle := DllCall("User32.dll\GetDesktopWindow", "UPtr") - ;this.DesktopWindow := new Window(handle) - - shellWindowHandle := DllCall("User32.dll\GetShellWindow", "UPtr") - this.DefViewParentWindow := new Window(shellWindowHandle) - this.LocateChildWindows(handle) - - if (!this.IsValid) - { - WinGet, workerWHandles, list, ahk_class WorkerW - Loop, %workerWHandles% - { - workerWHandle := workerWHandles%A_Index% - - this.LocateChildWindows(workerWHandle) - if (this.IsValid) - break - } - } - } - - IsValid - { - get - { - if (!this.DefViewParentWindow || !this.DefViewParentWindow.IsValid) - return false - if (!this.DefViewWindow || !this.DefViewWindow.IsValid) - return false - if (!this.SysListView32Window || !this.SysListView32Window.IsValid) - return false - return true - } - } - - LocateChildWindows(parentHandle) - { - defViewHandle := DllCall("user32\FindWindowEx", "Ptr", parentHandle, "Ptr", 0, "Str","SHELLDLL_DefView", "Ptr", 0, "Ptr") - this.DefViewWindow := new Window(defViewHandle) - - sysListViewHandle := DllCall("user32\FindWindowEx", "Ptr", defViewHandle, "Ptr", 0, "Str", "SysListView32", "Str", "FolderView", "Ptr") - this.SysListView32Window := new Window(sysListViewHandle) - } + DefViewParentWindow := + DefViewWindow := + SysListView32Window := + + __New() + { + ; Inspired by : https://www.autohotkey.com/boards/viewtopic.php?t=70072&p=302495 + + ;handle := DllCall("User32.dll\GetDesktopWindow", "UPtr") + ;this.DesktopWindow := new Window(handle) + + shellWindowHandle := DllCall("User32.dll\GetShellWindow", "UPtr") + this.DefViewParentWindow := new Window(shellWindowHandle) + this.LocateChildWindows(handle) + + if (!this.IsValid) + { + WinGet, workerWHandles, list, ahk_class WorkerW + Loop, %workerWHandles% + { + workerWHandle := workerWHandles%A_Index% + + this.LocateChildWindows(workerWHandle) + if (this.IsValid) + break + } + } + } + + IsValid + { + get + { + if (!this.DefViewParentWindow || !this.DefViewParentWindow.IsValid) + return false + if (!this.DefViewWindow || !this.DefViewWindow.IsValid) + return false + if (!this.SysListView32Window || !this.SysListView32Window.IsValid) + return false + return true + } + } + + LocateChildWindows(parentHandle) + { + defViewHandle := DllCall("user32\FindWindowEx", "Ptr", parentHandle, "Ptr", 0, "Str","SHELLDLL_DefView", "Ptr", 0, "Ptr") + this.DefViewWindow := new Window(defViewHandle) + + sysListViewHandle := DllCall("user32\FindWindowEx", "Ptr", defViewHandle, "Ptr", 0, "Str", "SysListView32", "Str", "FolderView", "Ptr") + this.SysListView32Window := new Window(sysListViewHandle) + } } Class IconPosition extends Coordinate { - Index := -1 - Title := 0 + Index := -1 + Title := 0 - __New(x, y) - { - base.__New(x, y) - } - - Description - { - get - { - return "Icon: " . this.Index . ", Title: " . this.Title . ", " . base.Description - } - } + __New(x, y) + { + base.__New(x, y) + } + + Description + { + get + { + return "Icon: " . this.Index . ", Title: " . this.Title . ", " . base.Description + } + } } diff --git a/TrayMenu.ahk b/TrayMenu.ahk index a6fc6de..c2d3530 100644 --- a/TrayMenu.ahk +++ b/TrayMenu.ahk @@ -9,88 +9,88 @@ TrayMenuName := ; Initialisation TrayMenu_OnInit() { - global TrayMenuName - - TrayMenuName := "Tray" + global TrayMenuName + + TrayMenuName := "Tray" } ;-------------------------------------------------------------------------------- ; OnStartup TrayMenu_OnStartup() { - BuildTrayMenu() + 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.MenuControl_WindowPositionsMenuLocation, MenuLocationTrayMenu)) - { - menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) - - saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")" - menuIndex := AddMenuItemWithIcon(TrayMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex) - - restoreTitle := "Restore Last Window &Positions (" . desktopSize.DimensionsText . ")" - menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) - - restoreEnabled := HasSavedWindowPositionsFile(desktopSize) - EnableMenuItem(TrayMenuName, restoreTitle, restoreEnabled) - - if (HasMultipleSavedWindowPositionsFiles(desktopSize)) - { - restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")..." - - menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreMultipleWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) - } - } - - ; Desktop Icons - if (ContainsFlag(G_UserConfig.MenuControl_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) - - if (HasMultipleSavedDesktopIconsFiles(desktopSize)) - { - restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")..." - - menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreMultipleDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) - } - } - - menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) - menuIndex := AddMenuItem(TrayMenuName, "&About...", "TrayAboutHandler", menuIndex) - - menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) - menuIndex := AddMenuItem(TrayMenuName, "Exit", "TrayExitHandler", menuIndex) + 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.MenuControl_WindowPositionsMenuLocation, MenuLocationTrayMenu)) + { + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + + saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(TrayMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex) + + restoreTitle := "Restore Last Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) + + restoreEnabled := HasSavedWindowPositionsFile(desktopSize) + EnableMenuItem(TrayMenuName, restoreTitle, restoreEnabled) + + if (HasMultipleSavedWindowPositionsFiles(desktopSize)) + { + restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")..." + + menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreMultipleWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) + } + } + + ; Desktop Icons + if (ContainsFlag(G_UserConfig.MenuControl_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) + + if (HasMultipleSavedDesktopIconsFiles(desktopSize)) + { + restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")..." + + menuIndex := AddMenuItemWithIcon(TrayMenuName, restoreTitle, "RestoreMultipleDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) + } + } + + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + menuIndex := AddMenuItem(TrayMenuName, "&About...", "TrayAboutHandler", menuIndex) + + menuIndex := AddMenuItemSeparator(TrayMenuName, menuIndex) + menuIndex := AddMenuItem(TrayMenuName, "Exit", "TrayExitHandler", menuIndex) } ;-------------------------------------------------------------------------------- diff --git a/WindowExtensions.ahk b/WindowExtensions.ahk index ff2fc05..a00622f 100644 --- a/WindowExtensions.ahk +++ b/WindowExtensions.ahk @@ -1,4 +1,4 @@ -#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. +#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. #SingleInstance Force SendMode Input ; Recommended for new scripts due to its superior speed and reliability. @@ -12,10 +12,10 @@ SetTitleMatchMode, 2 AppName := "WindowExtensions" AppTitle := "Window Extensions" AppDescription := "Window Extensions Menu and HotKeys" -AppCopyright := "Copyright © 2020 Martin Smith" +AppCopyright := "Copyright � 2020 Martin Smith" 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.6.6.0" +AppVersion := "1.6.7.0" ;-------------------------------------------------------------------------------- ; Includes @@ -54,9 +54,9 @@ OnExit, ExitHandler ;-------------------------------------------------------------------------------- ; Auto-Execute section -OnInit() ; Perform module initialisation - not reliant on other modules or globals -InitGlobals() ; -OnStartup() ; Perform module startup - may rely on other modules Init +OnInit() ; Perform module initialisation - not reliant on other modules or globals +InitGlobals() ; +OnStartup() ; Perform module startup - may rely on other modules Init return ; End of script's auto-execute section. @@ -86,43 +86,43 @@ ExitApp ; Initialise global variables once everything else initialised InitGlobals() { - global G_UserConfig - - G_UserConfig := new WindowExtensionsUserConfig() + global G_UserConfig + + G_UserConfig := new WindowExtensionsUserConfig() } ;-------------------------------------------------------------------------------- ; Module initialisation OnInit() { - WindowExtensionsUserConfig_OnInit() - WindowPositions_OnInit() - DesktopIcons_OnInit() - WindowMenu_OnInit() - TrayMenu_OnInit() + WindowExtensionsUserConfig_OnInit() + WindowPositions_OnInit() + DesktopIcons_OnInit() + WindowMenu_OnInit() + TrayMenu_OnInit() } ;-------------------------------------------------------------------------------- ; OnStartup event OnStartup() { - WindowExtensionsUserConfig_OnStartup() - WindowMenu_OnStartup() - TrayMenu_OnStartup() + WindowExtensionsUserConfig_OnStartup() + WindowMenu_OnStartup() + TrayMenu_OnStartup() } ;-------------------------------------------------------------------------------- ; OnExit event OnExit() { - WindowMenu_OnExit() + WindowMenu_OnExit() } ;-------------------------------------------------------------------------------- ; OnUserConfigUpdated event OnUserConfigUpdated() { - BuildWindowMenu() - BuildTrayMenu() - WindowExtensionsUserConfig_OnConfigUpdated() + BuildWindowMenu() + BuildTrayMenu() + WindowExtensionsUserConfig_OnConfigUpdated() } diff --git a/WindowExtensionsUserConfig.ahk b/WindowExtensionsUserConfig.ahk index dc3ff34..7b971d8 100644 --- a/WindowExtensionsUserConfig.ahk +++ b/WindowExtensionsUserConfig.ahk @@ -19,153 +19,153 @@ DesktopIcons_TimerIntervalMinutes := 0 ; Initialisation WindowExtensionsUserConfig_OnInit() { - global MenuLocationNone - global MenuLocationWindowMenu - global MenuLocationTrayMenu - global MenuLocationAll - - global MenuLocationItems - global MenuLocationValues + global MenuLocationNone + global MenuLocationWindowMenu + global MenuLocationTrayMenu + global MenuLocationAll + + global MenuLocationItems + global MenuLocationValues - global WindowPositions_TimerEnabled - global WindowPositions_TimerIntervalMinutes - global DesktopIcons_TimerEnabled - global DesktopIcons_TimerIntervalMinutes + global WindowPositions_TimerEnabled + global WindowPositions_TimerIntervalMinutes + global DesktopIcons_TimerEnabled + global DesktopIcons_TimerIntervalMinutes - MenuLocationNone := 0 - MenuLocationWindowMenu := 1 - MenuLocationTrayMenu := 2 - MenuLocationAll := MenuLocationWindowMenu | MenuLocationTrayMenu + MenuLocationNone := 0 + MenuLocationWindowMenu := 1 + MenuLocationTrayMenu := 2 + MenuLocationAll := MenuLocationWindowMenu | MenuLocationTrayMenu - MenuLocationItems := [] - MenuLocationItems.push("None") - MenuLocationItems.push("Window Menu") - MenuLocationItems.push("Tray Menu") - MenuLocationItems.push("Both") + 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) - - WindowPositions_TimerEnabled := false - WindowPositions_TimerIntervalMinutes := 0 - DesktopIcons_TimerEnabled := false - DesktopIcons_TimerIntervalMinutes := 0 - - UserConfig_OnInit() + MenuLocationValues := [] + MenuLocationValues.push(MenuLocationNone) + MenuLocationValues.push(MenuLocationWindowMenu) + MenuLocationValues.push(MenuLocationTrayMenu) + MenuLocationValues.push(MenuLocationAll) + + WindowPositions_TimerEnabled := false + WindowPositions_TimerIntervalMinutes := 0 + DesktopIcons_TimerEnabled := false + DesktopIcons_TimerIntervalMinutes := 0 + + UserConfig_OnInit() } ;-------------------------------------------------------------------------------- ; OnStartup WindowExtensionsUserConfig_OnStartup() { - global G_UserConfig - - desktopSize := GetDesktopSize() - - if (G_UserConfig.Startup_RestoreDesktopIcons) - { - if (HasSavedDesktopIconsFile(desktopSize)) - { - fileName := GetLatestDesktopIconsDataFileName(desktopSize) - - RestoreDesktopIcons(fileName) - } - } - - if (G_UserConfig.Startup_RestoreWindowPositions) - { - if (HasSavedWindowPositionsFile(desktopSize)) - { - fileName := GetLatestWindowPositionsDataFileName(desktopSize) - - RestoreWindowPositions(fileName, G_UserConfig.WindowPositions_IncludeOffScreenWindows) - } - } - - WindowExtensionsUserConfig_OnConfigUpdated() + global G_UserConfig + + desktopSize := GetDesktopSize() + + if (G_UserConfig.Startup_RestoreDesktopIcons) + { + if (HasSavedDesktopIconsFile(desktopSize)) + { + fileName := GetLatestDesktopIconsDataFileName(desktopSize) + + RestoreDesktopIcons(fileName) + } + } + + if (G_UserConfig.Startup_RestoreWindowPositions) + { + if (HasSavedWindowPositionsFile(desktopSize)) + { + fileName := GetLatestWindowPositionsDataFileName(desktopSize) + + RestoreWindowPositions(fileName, G_UserConfig.WindowPositions_IncludeOffScreenWindows) + } + } + + WindowExtensionsUserConfig_OnConfigUpdated() } ;-------------------------------------------------------------------------------- ; OnConfigUpdated WindowExtensionsUserConfig_OnConfigUpdated() { - global G_UserConfig - - WindowPositionsConfigureTimer(G_UserConfig.WindowPositions_AutoSave, G_UserConfig.WindowPositions_AutoSaveIntervalMinutes) - DesktopIconsConfigureTimer(G_UserConfig.DesktopIcons_AutoSave, G_UserConfig.DesktopIcons_AutoSaveIntervalMinutes) + global G_UserConfig + + WindowPositionsConfigureTimer(G_UserConfig.WindowPositions_AutoSave, G_UserConfig.WindowPositions_AutoSaveIntervalMinutes) + DesktopIconsConfigureTimer(G_UserConfig.DesktopIcons_AutoSave, G_UserConfig.DesktopIcons_AutoSaveIntervalMinutes) } ;-------------------------------------------------------------------------------- ; WindowPositionsConfigureTimer - Configure the timer WindowPositionsConfigureTimer(enabled, intervalMinutes) { - global WindowPositions_TimerEnabled - global WindowPositions_TimerIntervalMinutes - - if (enabled = WindowPositions_TimerEnabled && intervalMinutes = WindowPositions_TimerIntervalMinutes) - { - return - } - - LogText("Deleting WindowPositionsAutoSave_OnTimer") - Try SetTimer, WindowPositionsAutoSave_OnTimer, Delete - - if (enabled) - { - milliseconds := (intervalMinutes * 60) * 1000 - - LogText("Setting WindowPositionsAutoSave_OnTimer for : " . milliseconds) - SetTimer, WindowPositionsAutoSave_OnTimer, %milliseconds% - } + global WindowPositions_TimerEnabled + global WindowPositions_TimerIntervalMinutes + + if (enabled = WindowPositions_TimerEnabled && intervalMinutes = WindowPositions_TimerIntervalMinutes) + { + return + } + + LogText("Deleting WindowPositionsAutoSave_OnTimer") + Try SetTimer, WindowPositionsAutoSave_OnTimer, Delete + + if (enabled) + { + milliseconds := (intervalMinutes * 60) * 1000 + + LogText("Setting WindowPositionsAutoSave_OnTimer for : " . milliseconds) + SetTimer, WindowPositionsAutoSave_OnTimer, %milliseconds% + } } ;-------------------------------------------------------------------------------- ; DesktopIconsConfigureTimer - Configure the timer DesktopIconsConfigureTimer(enabled, intervalMinutes) { - global DesktopIcons_TimerEnabled - global DesktopIcons_TimerIntervalMinutes - - if (enabled = DesktopIcons_TimerEnabled && intervalMinutes = DesktopIcons_TimerIntervalMinutes) - { - return - } - - LogText("Deleting DesktopIconsAutoSave_OnTimer") - Try SetTimer, DesktopIconsAutoSave_OnTimer, Delete - - if (enabled) - { - milliseconds := (intervalMinutes * 60) * 1000 - - LogText("Setting DesktopIconsAutoSave_OnTimer for : " . milliseconds) - SetTimer, DesktopIconsAutoSave_OnTimer, %milliseconds% - } + global DesktopIcons_TimerEnabled + global DesktopIcons_TimerIntervalMinutes + + if (enabled = DesktopIcons_TimerEnabled && intervalMinutes = DesktopIcons_TimerIntervalMinutes) + { + return + } + + LogText("Deleting DesktopIconsAutoSave_OnTimer") + Try SetTimer, DesktopIconsAutoSave_OnTimer, Delete + + if (enabled) + { + milliseconds := (intervalMinutes * 60) * 1000 + + LogText("Setting DesktopIconsAutoSave_OnTimer for : " . milliseconds) + SetTimer, DesktopIconsAutoSave_OnTimer, %milliseconds% + } } ;-------------------------------------------------------------------------------- ; WindowPositionsAutoSave_OnTimer - Timer execute WindowPositionsAutoSave_OnTimer() { - global G_UserConfig - - LogText("Executing: " . A_ThisFunc) - - SaveWindowPositions(G_UserConfig.WindowPositions_IncludeOffScreenWindows, G_UserConfig.WindowPositions_AutoSaveNotify) + global G_UserConfig + + LogText("Executing: " . A_ThisFunc) + + SaveWindowPositions(G_UserConfig.WindowPositions_IncludeOffScreenWindows, G_UserConfig.WindowPositions_AutoSaveNotify) } ;-------------------------------------------------------------------------------- ; DesktopIconsAutoSave_OnTimer - Timer execute DesktopIconsAutoSave_OnTimer() { - global G_UserConfig - - LogText("Executing: " . A_ThisFunc) - - SaveDesktopIcons(G_UserConfig.DesktopIcons_AutoSaveNotify) + global G_UserConfig + + LogText("Executing: " . A_ThisFunc) + + SaveDesktopIcons(G_UserConfig.DesktopIcons_AutoSaveNotify) } ;-------------------------------------------------------------------------------- @@ -189,246 +189,246 @@ Default_DesktopIcons_AutoSave := false Default_DesktopIcons_AutoSaveIntervalMinutes := 5 Default_DesktopIcons_AutoSaveNotify := false - InitDefaults() - { - global AppVersion - global MenuLocationTrayMenu - - this.Default_About_Version := AppVersion - this.Default_MenuControl_WindowPositionsMenuLocation := MenuLocationTrayMenu - this.Default_MenuControl_DesktopIconsMenuLocation := MenuLocationTrayMenu - } + InitDefaults() + { + global AppVersion + global MenuLocationTrayMenu + + this.Default_About_Version := AppVersion + this.Default_MenuControl_WindowPositionsMenuLocation := MenuLocationTrayMenu + this.Default_MenuControl_DesktopIconsMenuLocation := MenuLocationTrayMenu + } - __New() - { - global AppName - - this.InitDefaults() - - fileName := GetUserDataFileName(AppName . ".dat") - - base.__New(fileName) - - this.Properties.push("About_Version") - this.Properties.push("General_CascadeGutterSize") - this.Properties.push("General_ColumnGutterSize") - this.Properties.push("General_GridGutterSize") - this.Properties.push("General_SpanMonitorGutterSize") - this.Properties.push("Startup_RestoreDesktopIcons") - this.Properties.push("Startup_RestoreWindowPositions") - this.Properties.push("MenuControl_WindowPositionsMenuLocation") - this.Properties.push("MenuControl_DesktopIconsMenuLocation") - this.Properties.push("WindowPositions_IncludeOffScreenWindows") - this.Properties.push("WindowPositions_AutoSave") - this.Properties.push("WindowPositions_AutoSaveIntervalMinutes") - this.Properties.push("WindowPositions_AutoSaveNotify") - this.Properties.push("DesktopIcons_AutoSave") - this.Properties.push("DesktopIcons_AutoSaveIntervalMinutes") - this.Properties.push("DesktopIcons_AutoSaveNotify") - - this.ObsoleteProperties.push("General_RestoreDesktopIconsOnStartup") - this.ObsoleteProperties.push("General_RestoreWindowPositionsOnStartup") - this.ObsoleteProperties.push("General_DesktopIconsMenuLocation") - this.ObsoleteProperties.push("General_WindowPositionsMenuLocation") - } - - About_Version - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_CascadeGutterSize, "string") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_About_Version) - } - } - - General_CascadeGutterSize - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_CascadeGutterSize, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - General_ColumnGutterSize - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_ColumnGutterSize, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - General_GridGutterSize - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_GridGutterSize, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - General_SpanMonitorGutterSize - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_SpanMonitorGutterSize, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - Startup_RestoreDesktopIcons - { - get - { - oldValue1 := base.GetValue("General", "RestoreDesktopIconsOnStartup", this.Default_Startup_RestoreDesktopIcons, "boolean") - - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - Startup_RestoreWindowPositions - { - get - { - oldValue1 := base.GetValue("General", "RestoreWindowPositionsOnStartup", this.Default_Startup_RestoreWindowPositions, "boolean") - - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - MenuControl_WindowPositionsMenuLocation - { - get - { - oldValue1 := base.GetValue("General", "WindowPositionsMenuLocation", this.Default_MenuControl_WindowPositionsMenuLocation, "integer") - - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - MenuControl_DesktopIconsMenuLocation - { - get - { - oldValue1 := base.GetValue("General", "DesktopIconsMenuLocation", this.Default_MenuControl_WindowPositionsMenuLocation, "integer") - - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - WindowPositions_IncludeOffScreenWindows - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_IncludeOffScreenWindows, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - WindowPositions_AutoSave - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_AutoSave, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - WindowPositions_AutoSaveIntervalMinutes - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_AutoSaveIntervalMinutes, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - WindowPositions_AutoSaveNotify - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_AutoSaveNotify, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - DesktopIcons_AutoSave - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_DesktopIcons_AutoSave, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - DesktopIcons_AutoSaveIntervalMinutes - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_DesktopIcons_AutoSaveIntervalMinutes, "integer") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } - - DesktopIcons_AutoSaveNotify - { - get - { - return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_DesktopIcons_AutoSaveNotify, "boolean") - } - set - { - base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) - } - } + __New() + { + global AppName + + this.InitDefaults() + + fileName := GetUserDataFileName(AppName . ".dat") + + base.__New(fileName) + + this.Properties.push("About_Version") + this.Properties.push("General_CascadeGutterSize") + this.Properties.push("General_ColumnGutterSize") + this.Properties.push("General_GridGutterSize") + this.Properties.push("General_SpanMonitorGutterSize") + this.Properties.push("Startup_RestoreDesktopIcons") + this.Properties.push("Startup_RestoreWindowPositions") + this.Properties.push("MenuControl_WindowPositionsMenuLocation") + this.Properties.push("MenuControl_DesktopIconsMenuLocation") + this.Properties.push("WindowPositions_IncludeOffScreenWindows") + this.Properties.push("WindowPositions_AutoSave") + this.Properties.push("WindowPositions_AutoSaveIntervalMinutes") + this.Properties.push("WindowPositions_AutoSaveNotify") + this.Properties.push("DesktopIcons_AutoSave") + this.Properties.push("DesktopIcons_AutoSaveIntervalMinutes") + this.Properties.push("DesktopIcons_AutoSaveNotify") + + this.ObsoleteProperties.push("General_RestoreDesktopIconsOnStartup") + this.ObsoleteProperties.push("General_RestoreWindowPositionsOnStartup") + this.ObsoleteProperties.push("General_DesktopIconsMenuLocation") + this.ObsoleteProperties.push("General_WindowPositionsMenuLocation") + } + + About_Version + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_CascadeGutterSize, "string") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_About_Version) + } + } + + General_CascadeGutterSize + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_CascadeGutterSize, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + General_ColumnGutterSize + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_ColumnGutterSize, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + General_GridGutterSize + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_GridGutterSize, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + General_SpanMonitorGutterSize + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_General_SpanMonitorGutterSize, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + Startup_RestoreDesktopIcons + { + get + { + oldValue1 := base.GetValue("General", "RestoreDesktopIconsOnStartup", this.Default_Startup_RestoreDesktopIcons, "boolean") + + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + Startup_RestoreWindowPositions + { + get + { + oldValue1 := base.GetValue("General", "RestoreWindowPositionsOnStartup", this.Default_Startup_RestoreWindowPositions, "boolean") + + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + MenuControl_WindowPositionsMenuLocation + { + get + { + oldValue1 := base.GetValue("General", "WindowPositionsMenuLocation", this.Default_MenuControl_WindowPositionsMenuLocation, "integer") + + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + MenuControl_DesktopIconsMenuLocation + { + get + { + oldValue1 := base.GetValue("General", "DesktopIconsMenuLocation", this.Default_MenuControl_WindowPositionsMenuLocation, "integer") + + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), oldValue1, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + WindowPositions_IncludeOffScreenWindows + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_IncludeOffScreenWindows, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + WindowPositions_AutoSave + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_AutoSave, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + WindowPositions_AutoSaveIntervalMinutes + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_AutoSaveIntervalMinutes, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + WindowPositions_AutoSaveNotify + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_WindowPositions_AutoSaveNotify, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + DesktopIcons_AutoSave + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_DesktopIcons_AutoSave, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + DesktopIcons_AutoSaveIntervalMinutes + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_DesktopIcons_AutoSaveIntervalMinutes, "integer") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } + + DesktopIcons_AutoSaveNotify + { + get + { + return base.GetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), this.Default_DesktopIcons_AutoSaveNotify, "boolean") + } + set + { + base.SetValue(base.GetSectionNameFromFunc(A_ThisFunc), base.GetPropertyNameFromFunc(A_ThisFunc), value) + } + } } diff --git a/WindowExtensionsUserConfigGui.ahk b/WindowExtensionsUserConfigGui.ahk index 46e64c8..76952c2 100644 --- a/WindowExtensionsUserConfigGui.ahk +++ b/WindowExtensionsUserConfigGui.ahk @@ -32,302 +32,302 @@ desktopIcons_AutoSaveNotify := false ; LoadConfigGuiValues - Populate gui variables with values from User Config LoadConfigGuiValues(userConfig) { - global general_cascadeGutterSize - global general_columnGutterSize - global general_gridGutterSize - global general_spanMonitorGutterSize - global startup_restoreWindowPositions - global startup_restoreDesktopIcons - global menuControl_windowPositionsMenuLocation - global menuControl_windowPositionsMenuLocationChoice - global menuControl_desktopIconsMenuLocation - global menuControl_desktopIconsMenuLocationChoice - global windowPositions_IncludeOffScreenWindows - global windowPositions_AutoSave - global windowPositions_AutoSaveIntervalLabel - global windowPositions_AutoSaveIntervalEdit - global windowPositions_AutoSaveIntervalMinutes - global windowPositions_AutoSaveNotify - global desktopIcons_AutoSave - global desktopIcons_AutoSaveIntervalLabel - global desktopIcons_AutoSaveIntervalEdit - global desktopIcons_AutoSaveIntervalMinutes - global desktopIcons_AutoSaveNotify - - global MenuLocationValues - global MenuLocationItems + global general_cascadeGutterSize + global general_columnGutterSize + global general_gridGutterSize + global general_spanMonitorGutterSize + global startup_restoreWindowPositions + global startup_restoreDesktopIcons + global menuControl_windowPositionsMenuLocation + global menuControl_windowPositionsMenuLocationChoice + global menuControl_desktopIconsMenuLocation + global menuControl_desktopIconsMenuLocationChoice + global windowPositions_IncludeOffScreenWindows + global windowPositions_AutoSave + global windowPositions_AutoSaveIntervalLabel + global windowPositions_AutoSaveIntervalEdit + global windowPositions_AutoSaveIntervalMinutes + global windowPositions_AutoSaveNotify + global desktopIcons_AutoSave + global desktopIcons_AutoSaveIntervalLabel + global desktopIcons_AutoSaveIntervalEdit + global desktopIcons_AutoSaveIntervalMinutes + global desktopIcons_AutoSaveNotify + + global MenuLocationValues + global MenuLocationItems - if (!userConfig) - return + if (!userConfig) + return - general_cascadeGutterSize := userConfig.General_CascadeGutterSize - general_columnGutterSize := userConfig.General_ColumnGutterSize - general_gridGutterSize := userConfig.General_GridGutterSize - general_spanMonitorGutterSize := userConfig.General_SpanMonitorGutterSize - startup_restoreWindowPositions := userConfig.Startup_RestoreWindowPositions ? 1 : 0 - startup_restoreDesktopIcons := userConfig.Startup_RestoreDesktopIcons ? 1 : 0 - menuControl_windowPositionsMenuLocation := userConfig.MenuControl_WindowPositionsMenuLocation - menuControl_windowPositionsMenuLocationChoice := IndexOf(MenuLocationValues, menuControl_windowPositionsMenuLocation) - menuControl_desktopIconsMenuLocation := userConfig.MenuControl_DesktopIconsMenuLocation - menuControl_desktopIconsMenuLocationChoice := IndexOf(MenuLocationValues, menuControl_desktopIconsMenuLocation) - windowPositions_AutoSave := userConfig.WindowPositions_AutoSave - windowPositions_AutoSaveIntervalMinutes := userConfig.WindowPositions_AutoSaveIntervalMinutes - windowPositions_AutoSaveNotify := userConfig.WindowPositions_AutoSaveNotify - windowPositions_IncludeOffScreenWindows := userConfig.WindowPositions_IncludeOffScreenWindows ? 1 : 0 - desktopIcons_AutoSave := userConfig.DesktopIcons_AutoSave - desktopIcons_AutoSaveIntervalMinutes := userConfig.DesktopIcons_AutoSaveIntervalMinutes - desktopIcons_AutoSaveNotify := userConfig.DesktopIcons_AutoSaveNotify - desktopIcons_IncludeOffScreenWindows := userConfig.DesktopIcons_IncludeOffScreenWindows ? 1 : 0 + general_cascadeGutterSize := userConfig.General_CascadeGutterSize + general_columnGutterSize := userConfig.General_ColumnGutterSize + general_gridGutterSize := userConfig.General_GridGutterSize + general_spanMonitorGutterSize := userConfig.General_SpanMonitorGutterSize + startup_restoreWindowPositions := userConfig.Startup_RestoreWindowPositions ? 1 : 0 + startup_restoreDesktopIcons := userConfig.Startup_RestoreDesktopIcons ? 1 : 0 + menuControl_windowPositionsMenuLocation := userConfig.MenuControl_WindowPositionsMenuLocation + menuControl_windowPositionsMenuLocationChoice := IndexOf(MenuLocationValues, menuControl_windowPositionsMenuLocation) + menuControl_desktopIconsMenuLocation := userConfig.MenuControl_DesktopIconsMenuLocation + menuControl_desktopIconsMenuLocationChoice := IndexOf(MenuLocationValues, menuControl_desktopIconsMenuLocation) + windowPositions_AutoSave := userConfig.WindowPositions_AutoSave + windowPositions_AutoSaveIntervalMinutes := userConfig.WindowPositions_AutoSaveIntervalMinutes + windowPositions_AutoSaveNotify := userConfig.WindowPositions_AutoSaveNotify + windowPositions_IncludeOffScreenWindows := userConfig.WindowPositions_IncludeOffScreenWindows ? 1 : 0 + desktopIcons_AutoSave := userConfig.DesktopIcons_AutoSave + desktopIcons_AutoSaveIntervalMinutes := userConfig.DesktopIcons_AutoSaveIntervalMinutes + desktopIcons_AutoSaveNotify := userConfig.DesktopIcons_AutoSaveNotify + desktopIcons_IncludeOffScreenWindows := userConfig.DesktopIcons_IncludeOffScreenWindows ? 1 : 0 } ;-------------------------------------------------------------------------------- ; SaveConfigGuiValues SaveConfigGuiValues(userConfig) { - global general_cascadeGutterSize - global general_columnGutterSize - global general_gridGutterSize - global general_spanMonitorGutterSize - global startup_restoreWindowPositions - global startup_restoreDesktopIcons - global menuControl_windowPositionsMenuLocation - global menuControl_windowPositionsMenuLocationChoice - global menuControl_desktopIconsMenuLocation - global menuControl_desktopIconsMenuLocationChoice - global windowPositions_IncludeOffScreenWindows - global windowPositions_AutoSave - global windowPositions_AutoSaveIntervalLabel - global windowPositions_AutoSaveIntervalMinutes - global windowPositions_AutoSaveNotify - global desktopIcons_AutoSave - global desktopIcons_AutoSaveIntervalLabel - global desktopIcons_AutoSaveIntervalMinutes - global desktopIcons_AutoSaveNotify - - global MenuLocationValues + global general_cascadeGutterSize + global general_columnGutterSize + global general_gridGutterSize + global general_spanMonitorGutterSize + global startup_restoreWindowPositions + global startup_restoreDesktopIcons + global menuControl_windowPositionsMenuLocation + global menuControl_windowPositionsMenuLocationChoice + global menuControl_desktopIconsMenuLocation + global menuControl_desktopIconsMenuLocationChoice + global windowPositions_IncludeOffScreenWindows + global windowPositions_AutoSave + global windowPositions_AutoSaveIntervalLabel + global windowPositions_AutoSaveIntervalMinutes + global windowPositions_AutoSaveNotify + global desktopIcons_AutoSave + global desktopIcons_AutoSaveIntervalLabel + global desktopIcons_AutoSaveIntervalMinutes + global desktopIcons_AutoSaveNotify + + global MenuLocationValues - if (!userConfig) - return + if (!userConfig) + return - userConfig.General_CascadeGutterSize := general_cascadeGutterSize - userConfig.General_ColumnGutterSize := general_columnGutterSize - userConfig.General_GridGutterSize := general_gridGutterSize - userConfig.General_SpanMonitorGutterSize := general_spanMonitorGutterSize - userConfig.Startup_RestoreWindowPositions := startup_restoreWindowPositions - userConfig.Startup_RestoreDesktopIcons := startup_restoreDesktopIcons - userConfig.MenuControl_WindowPositionsMenuLocation := MenuLocationValues[menuControl_windowPositionsMenuLocation] - userConfig.MenuControl_DesktopIconsMenuLocation := MenuLocationValues[menuControl_desktopIconsMenuLocation] - userConfig.WindowPositions_AutoSave := windowPositions_AutoSave - userConfig.WindowPositions_AutoSaveIntervalMinutes := windowPositions_AutoSaveIntervalMinutes - userConfig.WindowPositions_AutoSaveNotify := windowPositions_AutoSaveNotify - userConfig.WindowPositions_IncludeOffScreenWindows := windowPositions_IncludeOffScreenWindows - userConfig.DesktopIcons_AutoSave := desktopIcons_AutoSave - userConfig.DesktopIcons_AutoSaveIntervalMinutes := desktopIcons_AutoSaveIntervalMinutes - userConfig.DesktopIcons_AutoSaveNotify := desktopIcons_AutoSaveNotify - - userConfig.Save() - - OnUserConfigUpdated() + userConfig.General_CascadeGutterSize := general_cascadeGutterSize + userConfig.General_ColumnGutterSize := general_columnGutterSize + userConfig.General_GridGutterSize := general_gridGutterSize + userConfig.General_SpanMonitorGutterSize := general_spanMonitorGutterSize + userConfig.Startup_RestoreWindowPositions := startup_restoreWindowPositions + userConfig.Startup_RestoreDesktopIcons := startup_restoreDesktopIcons + userConfig.MenuControl_WindowPositionsMenuLocation := MenuLocationValues[menuControl_windowPositionsMenuLocation] + userConfig.MenuControl_DesktopIconsMenuLocation := MenuLocationValues[menuControl_desktopIconsMenuLocation] + userConfig.WindowPositions_AutoSave := windowPositions_AutoSave + userConfig.WindowPositions_AutoSaveIntervalMinutes := windowPositions_AutoSaveIntervalMinutes + userConfig.WindowPositions_AutoSaveNotify := windowPositions_AutoSaveNotify + userConfig.WindowPositions_IncludeOffScreenWindows := windowPositions_IncludeOffScreenWindows + userConfig.DesktopIcons_AutoSave := desktopIcons_AutoSave + userConfig.DesktopIcons_AutoSaveIntervalMinutes := desktopIcons_AutoSaveIntervalMinutes + userConfig.DesktopIcons_AutoSaveNotify := desktopIcons_AutoSaveNotify + + userConfig.Save() + + OnUserConfigUpdated() } ;-------------------------------------------------------------------------------- ; BuildConfigGui - Build the Config Gui BuildConfigGui() { - global AppName - global MenuLocationItems - - global general_cascadeGutterSize - global general_columnGutterSize - global general_gridGutterSize - global general_spanMonitorGutterSize - global startup_restoreWindowPositions - global startup_restoreDesktopIcons - global menuControl_windowPositionsMenuLocation - global menuControl_windowPositionsMenuLocationChoice - global menuControl_desktopIconsMenuLocation - global menuControl_desktopIconsMenuLocationChoice - global windowPositions_IncludeOffScreenWindows - global windowPositions_AutoSave - global windowPositions_AutoSaveIntervalLabel - global windowPositions_AutoSaveIntervalEdit - global windowPositions_AutoSaveIntervalMinutes - global windowPositions_AutoSaveNotify - global desktopIcons_AutoSave - global desktopIcons_AutoSaveIntervalLabel - global desktopIcons_AutoSaveIntervalEdit - global desktopIcons_AutoSaveIntervalMinutes - global desktopIcons_AutoSaveNotify + global AppName + global MenuLocationItems + + global general_cascadeGutterSize + global general_columnGutterSize + global general_gridGutterSize + global general_spanMonitorGutterSize + global startup_restoreWindowPositions + global startup_restoreDesktopIcons + global menuControl_windowPositionsMenuLocation + global menuControl_windowPositionsMenuLocationChoice + global menuControl_desktopIconsMenuLocation + global menuControl_desktopIconsMenuLocationChoice + global windowPositions_IncludeOffScreenWindows + global windowPositions_AutoSave + global windowPositions_AutoSaveIntervalLabel + global windowPositions_AutoSaveIntervalEdit + global windowPositions_AutoSaveIntervalMinutes + global windowPositions_AutoSaveNotify + global desktopIcons_AutoSave + global desktopIcons_AutoSaveIntervalLabel + global desktopIcons_AutoSaveIntervalEdit + global desktopIcons_AutoSaveIntervalMinutes + global desktopIcons_AutoSaveNotify - menuLocationItemsText := JoinItems("|", MenuLocationItems) + menuLocationItemsText := JoinItems("|", MenuLocationItems) - marginSize := 5 - indentSize := 20 - col1 := 20 - col1Indent := col1 + indentSize - col2 := 220 - col2Indent := col2 + indentSize - tabHeight := 40 - rowHeight := 30 - textOffSet := 3 - - row1 := tabHeight + (rowHeight * 0) - row2 := tabHeight + (rowHeight * 1) - row3 := tabHeight + (rowHeight * 2) - row4 := tabHeight + (rowHeight * 3) - - row1t := row1 + textOffset - row2t := row2 + textOffset - row3t := row3 + textOffset - row4t := row4 + textOffset + marginSize := 5 + indentSize := 20 + col1 := 20 + col1Indent := col1 + indentSize + col2 := 220 + col2Indent := col2 + indentSize + tabHeight := 40 + rowHeight := 30 + textOffSet := 3 + + row1 := tabHeight + (rowHeight * 0) + row2 := tabHeight + (rowHeight * 1) + row3 := tabHeight + (rowHeight * 2) + row4 := tabHeight + (rowHeight * 3) + + row1t := row1 + textOffset + row2t := row2 + textOffset + row3t := row3 + textOffset + row4t := row4 + textOffset - ; Start Gui - Gui, Config:New, -SysMenu, %AppName% Configuration - Gui, Config:Margin, %marginSize%, %marginSize% - Gui, Config:Add, Tab3, -Wrap w370 h230, General|Startup|Menu Control|Window Positions|Desktop Icons - - ; Tab 1 - General - Gui, Config:Tab, 1 - ; Row 1 - Gui, Config:Add, Text, x%col1% y%row1t%, C&ascade Gutter Size: - Gui, Config:Add, Edit, x%col2% y%row1% w80 x%col2% - Gui, Config:Add, UpDown, vgeneral_cascadeGutterSize Range0-100, %general_cascadeGutterSize% - ; Row 2 - Gui, Config:Add, Text, x%col1% y%row2t%, C&olumn Gutter Size: - Gui, Config:Add, Edit, w80 x%col2% y%row2% - Gui, Config:Add, UpDown, vgeneral_columnGutterSize Range0-100, %general_columnGutterSize% - ; Row 3 - Gui, Config:Add, Text, x%col1% y%row3t%, &Grid Gutter Size: - Gui, Config:Add, Edit, w80 x%col2% y%row3% - Gui, Config:Add, UpDown, vgeneral_gridGutterSize Range0-100, %general_gridGutterSize% - ; Row 4 - Gui, Config:Add, Text, x%col1% y%row4t%, Span &Monitor Gutter Size: - Gui, Config:Add, Edit, w80 x%col2% y%row4% - Gui, Config:Add, UpDown, vgeneral_spanMonitorGutterSize Range0-100, %general_spanMonitorGutterSize% - - ; Tab 2 - Startup - Gui, Config:Tab, 2 - ; Row 1 - Gui, Config:Add, Checkbox, x%col1% y%row1t% vstartup_restoreWindowPositions Checked%startup_restoreWindowPositions%, Restore Window &Positions on Startup - ; Row 2 - Gui, Config:Add, Checkbox, x%col1% y%row2t% vstartup_restoreDesktopIcons Checked%startup_restoreDesktopIcons%, Restore Desktop &Icons on Startup + ; Start Gui + Gui, Config:New, -SysMenu, %AppName% Configuration + Gui, Config:Margin, %marginSize%, %marginSize% + Gui, Config:Add, Tab3, -Wrap w370 h230, General|Startup|Menu Control|Window Positions|Desktop Icons + + ; Tab 1 - General + Gui, Config:Tab, 1 + ; Row 1 + Gui, Config:Add, Text, x%col1% y%row1t%, C&ascade Gutter Size: + Gui, Config:Add, Edit, x%col2% y%row1% w80 x%col2% + Gui, Config:Add, UpDown, vgeneral_cascadeGutterSize Range0-100, %general_cascadeGutterSize% + ; Row 2 + Gui, Config:Add, Text, x%col1% y%row2t%, C&olumn Gutter Size: + Gui, Config:Add, Edit, w80 x%col2% y%row2% + Gui, Config:Add, UpDown, vgeneral_columnGutterSize Range0-100, %general_columnGutterSize% + ; Row 3 + Gui, Config:Add, Text, x%col1% y%row3t%, &Grid Gutter Size: + Gui, Config:Add, Edit, w80 x%col2% y%row3% + Gui, Config:Add, UpDown, vgeneral_gridGutterSize Range0-100, %general_gridGutterSize% + ; Row 4 + Gui, Config:Add, Text, x%col1% y%row4t%, Span &Monitor Gutter Size: + Gui, Config:Add, Edit, w80 x%col2% y%row4% + Gui, Config:Add, UpDown, vgeneral_spanMonitorGutterSize Range0-100, %general_spanMonitorGutterSize% + + ; Tab 2 - Startup + Gui, Config:Tab, 2 + ; Row 1 + Gui, Config:Add, Checkbox, x%col1% y%row1t% vstartup_restoreWindowPositions Checked%startup_restoreWindowPositions%, Restore Window &Positions on Startup + ; Row 2 + Gui, Config:Add, Checkbox, x%col1% y%row2t% vstartup_restoreDesktopIcons Checked%startup_restoreDesktopIcons%, Restore Desktop &Icons on Startup - ; Tab 3 - Menu Control - Gui, Config:Tab, 3 - ; Row 1 - Gui, Config:Add, Text, x%col1% y%row1t%, Window &Positions Menu Location: - Gui, Config:Add, DropDownList, x%col2% y%row1% vmenuControl_windowPositionsMenuLocation AltSubmit Choose%menuControl_windowPositionsMenuLocationChoice%, %menuLocationItemsText% - ; Row 2 - Gui, Config:Add, Text, x%col1% y%row2t%, Desktop &Icons Menu Location: - Gui, Config:Add, DropDownList, x%col2% y%row2% vmenuControl_desktopIconsMenuLocation AltSubmit Choose%menuControl_desktopIconsMenuLocationChoice%, %menuLocationItemsText% + ; Tab 3 - Menu Control + Gui, Config:Tab, 3 + ; Row 1 + Gui, Config:Add, Text, x%col1% y%row1t%, Window &Positions Menu Location: + Gui, Config:Add, DropDownList, x%col2% y%row1% vmenuControl_windowPositionsMenuLocation AltSubmit Choose%menuControl_windowPositionsMenuLocationChoice%, %menuLocationItemsText% + ; Row 2 + Gui, Config:Add, Text, x%col1% y%row2t%, Desktop &Icons Menu Location: + Gui, Config:Add, DropDownList, x%col2% y%row2% vmenuControl_desktopIconsMenuLocation AltSubmit Choose%menuControl_desktopIconsMenuLocationChoice%, %menuLocationItemsText% - ; Tab 4 - Window Positions - Gui, Config:Tab, 4 - ; Row 1 - Gui, Config:Add, Checkbox, x%col1% y%row1t% vwindowPositions_AutoSave gwindowPositions_AutoSave_Checked Checked%windowPositions_AutoSave%, Auto-Save Window Positions ? - Gui, Config:Add, Text, x%col1Indent% y%row2t% vwindowPositions_AutoSaveIntervalLabel, Auto-Save interval (minutes) - Gui, Config:Add, Edit, w80 x%col2% y%row2% vwindowPositions_AutoSaveIntervalEdit - Gui, Config:Add, UpDown, vwindowPositions_AutoSaveIntervalMinutes Range1-360, %windowPositions_AutoSaveIntervalMinutes% - Gui, Config:Add, Checkbox, x%col1Indent% y%row3% vwindowPositions_AutoSaveNotify Checked%windowPositions_AutoSaveNotify%, Notify when Auto-Saving ? - ; Row 4 - Gui, Config:Add, Checkbox, x%col1% y%row4t% vwindowPositions_IncludeOffScreenWindows Checked%windowPositions_IncludeOffScreenWindows%, Include Off-Screen Windows + ; Tab 4 - Window Positions + Gui, Config:Tab, 4 + ; Row 1 + Gui, Config:Add, Checkbox, x%col1% y%row1t% vwindowPositions_AutoSave gwindowPositions_AutoSave_Checked Checked%windowPositions_AutoSave%, Auto-Save Window Positions ? + Gui, Config:Add, Text, x%col1Indent% y%row2t% vwindowPositions_AutoSaveIntervalLabel, Auto-Save interval (minutes) + Gui, Config:Add, Edit, w80 x%col2% y%row2% vwindowPositions_AutoSaveIntervalEdit + Gui, Config:Add, UpDown, vwindowPositions_AutoSaveIntervalMinutes Range1-360, %windowPositions_AutoSaveIntervalMinutes% + Gui, Config:Add, Checkbox, x%col1Indent% y%row3% vwindowPositions_AutoSaveNotify Checked%windowPositions_AutoSaveNotify%, Notify when Auto-Saving ? + ; Row 4 + Gui, Config:Add, Checkbox, x%col1% y%row4t% vwindowPositions_IncludeOffScreenWindows Checked%windowPositions_IncludeOffScreenWindows%, Include Off-Screen Windows - ; Tab 5 - Desktop Icons - Gui, Config:Tab, 5 - ; Row 1 - Gui, Config:Add, Checkbox, x%col1% y%row1t% vdesktopIcons_AutoSave gdesktopIcons_AutoSave_Checked Checked%desktopIcons_AutoSave%, Auto-Save Desktop Icons ? - Gui, Config:Add, Text, x%col1Indent% y%row2t% vdesktopIcons_AutoSaveIntervalLabel, Auto-Save interval (minutes) - Gui, Config:Add, Edit, w80 x%col2% y%row2% vdesktopIcons_AutoSaveIntervalEdit - Gui, Config:Add, UpDown, vdesktopIcons_AutoSaveIntervalMinutes Range1-360, %desktopIcons_AutoSaveIntervalMinutes% - Gui, Config:Add, Checkbox, x%col1Indent% y%row3% vdesktopIcons_AutoSaveNotify Checked%desktopIcons_AutoSaveNotify%, Notify when Auto-Saving ? - ; Row 4 - ;Gui, Config:Add, Text, x%col1% y%row1t%, Number of saved files to &keep : - ;Gui, Config:Add, Edit, w80 x%col2% y%row1% - ;Gui, Config:Add, UpDown, vdesktopIcons_NumberOfFilesToKeep Range0-100, %desktopIcons_NumberOfFilesToKeep% + ; Tab 5 - Desktop Icons + Gui, Config:Tab, 5 + ; Row 1 + Gui, Config:Add, Checkbox, x%col1% y%row1t% vdesktopIcons_AutoSave gdesktopIcons_AutoSave_Checked Checked%desktopIcons_AutoSave%, Auto-Save Desktop Icons ? + Gui, Config:Add, Text, x%col1Indent% y%row2t% vdesktopIcons_AutoSaveIntervalLabel, Auto-Save interval (minutes) + Gui, Config:Add, Edit, w80 x%col2% y%row2% vdesktopIcons_AutoSaveIntervalEdit + Gui, Config:Add, UpDown, vdesktopIcons_AutoSaveIntervalMinutes Range1-360, %desktopIcons_AutoSaveIntervalMinutes% + Gui, Config:Add, Checkbox, x%col1Indent% y%row3% vdesktopIcons_AutoSaveNotify Checked%desktopIcons_AutoSaveNotify%, Notify when Auto-Saving ? + ; Row 4 + ;Gui, Config:Add, Text, x%col1% y%row1t%, Number of saved files to &keep : + ;Gui, Config:Add, Edit, w80 x%col2% y%row1% + ;Gui, Config:Add, UpDown, vdesktopIcons_NumberOfFilesToKeep Range0-100, %desktopIcons_NumberOfFilesToKeep% - ; Button Bar - Gui, Config:Tab - Gui, Config:Add, Button, default x205 y240 w80, OK ; The label ButtonOK (if it exists) will be run when the button is pressed. - Gui, Config:Add, Button, x295 y240 w80, Cancel ; The label ButtonCancel (if it exists) will be run when the button is pressed. - - ;-------------------------------------------------------------------------------- - ; Fire Events to ensure control consistency - windowPositions_AutoSave_Checked() - desktopIcons_AutoSave_Checked() + ; Button Bar + Gui, Config:Tab + Gui, Config:Add, Button, default x205 y240 w80, OK ; The label ButtonOK (if it exists) will be run when the button is pressed. + Gui, Config:Add, Button, x295 y240 w80, Cancel ; The label ButtonCancel (if it exists) will be run when the button is pressed. + + ;-------------------------------------------------------------------------------- + ; Fire Events to ensure control consistency + windowPositions_AutoSave_Checked() + desktopIcons_AutoSave_Checked() } ;-------------------------------------------------------------------------------- ; windowPositions_AutoSave_Checked - When Auto-Save is checked windowPositions_AutoSave_Checked() { - GuiControlGet, windowPositions_AutoSave - enabled := windowPositions_AutoSave ? 1 : 0 - - GuiControl, Enable%enabled%, windowPositions_AutoSaveIntervalLabel - GuiControl, Enable%enabled%, windowPositions_AutoSaveIntervalEdit - GuiControl, Enable%enabled%, windowPositions_AutoSaveIntervalMinutes - GuiControl, Enable%enabled%, windowPositions_AutoSaveNotify + GuiControlGet, windowPositions_AutoSave + enabled := windowPositions_AutoSave ? 1 : 0 + + GuiControl, Enable%enabled%, windowPositions_AutoSaveIntervalLabel + GuiControl, Enable%enabled%, windowPositions_AutoSaveIntervalEdit + GuiControl, Enable%enabled%, windowPositions_AutoSaveIntervalMinutes + GuiControl, Enable%enabled%, windowPositions_AutoSaveNotify } ;-------------------------------------------------------------------------------- ; desktopIcons_AutoSave_Checked - When Auto-Save is checked desktopIcons_AutoSave_Checked() { - GuiControlGet, desktopIcons_AutoSave - enabled := desktopIcons_AutoSave ? 1 : 0 - - GuiControl, Enable%enabled%, desktopIcons_AutoSaveIntervalLabel - GuiControl, Enable%enabled%, desktopIcons_AutoSaveIntervalEdit - GuiControl, Enable%enabled%, desktopIcons_AutoSaveIntervalMinutes - GuiControl, Enable%enabled%, desktopIcons_AutoSaveNotify + GuiControlGet, desktopIcons_AutoSave + enabled := desktopIcons_AutoSave ? 1 : 0 + + GuiControl, Enable%enabled%, desktopIcons_AutoSaveIntervalLabel + GuiControl, Enable%enabled%, desktopIcons_AutoSaveIntervalEdit + GuiControl, Enable%enabled%, desktopIcons_AutoSaveIntervalMinutes + GuiControl, Enable%enabled%, desktopIcons_AutoSaveNotify } ;-------------------------------------------------------------------------------- ; DestroyConfigGui - Destroy the Config Gui DestroyConfigGui() { - Gui, Config:Destroy + Gui, Config:Destroy } ;-------------------------------------------------------------------------------- ; ShowUserConfigGui - Build, Populate and Show the Config Gui ShowConfigGui() { - global G_UserConfig - - LoadConfigGuiValues(G_UserConfig) - - BuildConfigGui() - - Gui, Config:Show + global G_UserConfig + + LoadConfigGuiValues(G_UserConfig) + + BuildConfigGui() + + Gui, Config:Show } ConfigGuiEscape: { - DestroyConfigGui() - return + DestroyConfigGui() + return } ConfigGuiClose: { - DestroyConfigGui() - return + DestroyConfigGui() + return } ConfigButtonCancel: { - DestroyConfigGui() - return + DestroyConfigGui() + return } ConfigButtonOK: { - global G_UserConfig + global G_UserConfig - Gui, Config:Submit - - SaveConfigGuiValues(G_UserConfig) - - DestroyConfigGui() - return -} + Gui, Config:Submit + + SaveConfigGuiValues(G_UserConfig) + + DestroyConfigGui() + return +} diff --git a/WindowHotKeys.ahk b/WindowHotKeys.ahk index b6209b6..3fefc31 100644 --- a/WindowHotKeys.ahk +++ b/WindowHotKeys.ahk @@ -27,7 +27,7 @@ #If WinActive("ahk_exe firefox.exe") ; F9 - Hide images F9:: - LogText("Executing F9: firefox.exe") + LogText("Executing F9: firefox.exe") Send !t Sleep, 100 Send w w {Enter} i m @@ -39,9 +39,9 @@ #If WinActive("ahk_exe notepad++.exe") ; Ctrl+F4 = Ctrl+W - Close current file ^F4:: - LogText("Executing Ctrl+F4: notepad++.exe") - Send ^w - return + LogText("Executing Ctrl+F4: notepad++.exe") + Send ^w + return #if ;-------------------------------------------------------------------------------- @@ -49,7 +49,7 @@ #If WinActive("ahk_exe opera.exe") ; F12 = Ctrl-Shift-C - Open Debug Inspector F12:: - LogText("Executing F12: opera.exe") - Send ^+I - return + LogText("Executing F12: opera.exe") + Send ^+I + return #if diff --git a/WindowMenu.ahk b/WindowMenu.ahk index 2feb2b8..22cc8d4 100644 --- a/WindowMenu.ahk +++ b/WindowMenu.ahk @@ -21,194 +21,194 @@ G_SelectableDesktopIcons := [] ; Initialisation WindowMenu_OnInit() { - global WindowMenuName - - WindowMenuName := "WindowMenu" - BuildIconLibrary() + global WindowMenuName + + WindowMenuName := "WindowMenu" + BuildIconLibrary() } ;-------------------------------------------------------------------------------- ; OnStartup WindowMenu_OnStartup() { - BuildWindowMenu() + BuildWindowMenu() } ;-------------------------------------------------------------------------------- ; OnExit WindowMenu_OnExit() { - RestoreRollupWindows() ; This line will unroll any rolled up windows if the script exits for any reason: + RestoreRollupWindows() ; This line will unroll any rolled up windows if the script exits for any reason: } ;-------------------------------------------------------------------------------- ; Build Menu BuildWindowMenu() { - global G_UserConfig - global G_MonitorCount - global G_MenuTitle - global IconLibraryFileName - global MenuLocationWindowMenu - global WindowMenuName - - menuIndex := 0 - - desktopSize := GetDesktopSize() - - 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) - } - - ; Window Positions - if (ContainsFlag(G_UserConfig.MenuControl_WindowPositionsMenuLocation, MenuLocationWindowMenu)) - { - menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) - - saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")" - menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex) - - restoreTitle := "Restore Last Window &Positions (" . desktopSize.DimensionsText . ")" - menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) - - restoreEnabled := HasSavedWindowPositionsFile(desktopSize) - EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled) - - if (HasMultipleSavedWindowPositionsFiles(desktopSize)) - { - restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")..." - - menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreMultipleWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), 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.MenuControl_DesktopIconsMenuLocation, MenuLocationWindowMenu)) - { - menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) - - saveTitle := "Save &Desktop Icons (" . desktopSize.DimensionsText . ")" - menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_SAVE"), menuIndex) - - restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")" - menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) - - restoreEnabled := HasSavedDesktopIconsFile(desktopSize) - EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled) - - if (HasMultipleSavedDesktopIconsFiles(desktopSize)) - { - restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")..." - - menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreMultipleDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) - } - } - - ; Cancel menu - menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) - menuIndex := AddMenuItem(WindowMenuName, "&Cancel", "NullHandler", menuIndex) + global G_UserConfig + global G_MonitorCount + global G_MenuTitle + global IconLibraryFileName + global MenuLocationWindowMenu + global WindowMenuName + + menuIndex := 0 + + desktopSize := GetDesktopSize() + + 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) + } + + ; Window Positions + if (ContainsFlag(G_UserConfig.MenuControl_WindowPositionsMenuLocation, MenuLocationWindowMenu)) + { + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + + saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex) + + restoreTitle := "Restore Last Window &Positions (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex) + + restoreEnabled := HasSavedWindowPositionsFile(desktopSize) + EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled) + + if (HasMultipleSavedWindowPositionsFiles(desktopSize)) + { + restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")..." + + menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreMultipleWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), 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.MenuControl_DesktopIconsMenuLocation, MenuLocationWindowMenu)) + { + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + + saveTitle := "Save &Desktop Icons (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_SAVE"), menuIndex) + + restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")" + menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) + + restoreEnabled := HasSavedDesktopIconsFile(desktopSize) + EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled) + + if (HasMultipleSavedDesktopIconsFiles(desktopSize)) + { + restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")..." + + menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreMultipleDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex) + } + } + + ; Cancel menu + menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex) + menuIndex := AddMenuItem(WindowMenuName, "&Cancel", "NullHandler", menuIndex) } ;-------------------------------------------------------------------------------- ; BuildIconLibrary - Build Icon Library BuildIconLibrary() { - 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") + 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") } ;-------------------------------------------------------------------------------- ; GetIconIndex - Find the array index of a named icon GetIconLibraryIndex(iconName) { - global IconLibrary - - return IndexOf(IconLibrary, iconName) + global IconLibrary + + return IndexOf(IconLibrary, iconName) } @@ -368,83 +368,83 @@ return ; ShowMenu - Show the Window Control Menu ShowMenu(theWindow) { - global G_MenuTitle - global WindowMenuName - - BuildWindowMenu() - - ; Build Window Details - newMenuTitle := theWindow.Title . " (" . theWindow.ProcessName . ") [" . theWindow.Left . ", " . theWindow.Top . ", " . theWindow.Width . ", " . theWindow.Height . "]" - - ; Change Menu MainTitle - if (newMenuTitle <> G_MenuTitle) - { - G_MenuTitle := newMenuTitle - Menu, %WindowMenuName%, Rename, 1&, %G_MenuTitle% - } - - processPath := theWindow.ProcessPath - - try Menu, %WindowMenuName%, Icon, 1&, %processPath%, 0 - - ; Enable / Disable as appropriate - enableTopMostOff := IsWindowTopMost(theWindow.WindowHandle) - enableTopMostOn := !enableTopMostOff - - EnableMenuItem(WindowMenuName, "Set Top&Most On", enableTopMostOn) - EnableMenuItem(WindowMenuName, "Set Top&Most Off", enableTopMostOff) - - ; Show Popup Menu - Menu, %WindowMenuName%, Show + global G_MenuTitle + global WindowMenuName + + BuildWindowMenu() + + ; Build Window Details + newMenuTitle := theWindow.Title . " (" . theWindow.ProcessName . ") [" . theWindow.Left . ", " . theWindow.Top . ", " . theWindow.Width . ", " . theWindow.Height . "]" + + ; Change Menu MainTitle + if (newMenuTitle <> G_MenuTitle) + { + G_MenuTitle := newMenuTitle + Menu, %WindowMenuName%, Rename, 1&, %G_MenuTitle% + } + + processPath := theWindow.ProcessPath + + try Menu, %WindowMenuName%, Icon, 1&, %processPath%, 0 + + ; Enable / Disable as appropriate + enableTopMostOff := IsWindowTopMost(theWindow.WindowHandle) + enableTopMostOn := !enableTopMostOff + + EnableMenuItem(WindowMenuName, "Set Top&Most On", enableTopMostOn) + EnableMenuItem(WindowMenuName, "Set Top&Most Off", enableTopMostOff) + + ; Show Popup Menu + Menu, %WindowMenuName%, Show } ;-------------------------------------------------------------------------------- ; WindowsKey+W #w:: - ; Get Active Window - WinGet, theWindow, ID, A - MouseGetPos, mouseX, mouseY + ; Get Active Window + WinGet, theWindow, ID, A + MouseGetPos, mouseX, mouseY - G_ActiveWindow := New Window(theWindow) - G_CurrentMouse := New Coordinate(mouseX, mouseY) + G_ActiveWindow := New Window(theWindow) + G_CurrentMouse := New Coordinate(mouseX, mouseY) - ShowMenu(G_ActiveWindow) - - return + ShowMenu(G_ActiveWindow) + + return ;-------------------------------------------------------------------------------- ; RightMouseButton $~Rbutton:: - ; Get MousePos and Active Window - MouseGetPos, mouseX, mouseY, theWindow + ; Get MousePos and Active Window + MouseGetPos, mouseX, mouseY, theWindow - G_ActiveWindow := New Window(theWindow) - G_CurrentMouse := New Coordinate(mouseX, mouseY) + G_ActiveWindow := New Window(theWindow) + G_CurrentMouse := New Coordinate(mouseX, mouseY) - LogText("G_ActiveWindow: " . G_ActiveWindow.Description) - LogText("G_CurrentMouse: " . G_CurrentMouse.Description) + LogText("G_ActiveWindow: " . G_ActiveWindow.Description) + LogText("G_CurrentMouse: " . G_CurrentMouse.Description) - ; Get Mouse Monitor - currentMouseMonitor := New Monitor(G_CurrentMouse.MonitorIndex) - LogText("currentMouseMonitor: " . currentMouseMonitor.Description) - LogText("currentMouseMonitor.WorkArea: " . currentMouseMonitor.WorkArea.Description) + ; Get Mouse Monitor + currentMouseMonitor := New Monitor(G_CurrentMouse.MonitorIndex) + LogText("currentMouseMonitor: " . currentMouseMonitor.Description) + LogText("currentMouseMonitor.WorkArea: " . currentMouseMonitor.WorkArea.Description) - if (!G_CurrentMouse.IsInRectangle(currentMouseMonitor.WorkArea)) - { - LogText("Outside Monitor Area: " . currentMouseMonitor.WorkArea.Description) - return - } + if (!G_CurrentMouse.IsInRectangle(currentMouseMonitor.WorkArea)) + { + LogText("Outside Monitor Area: " . currentMouseMonitor.WorkArea.Description) + return + } - hitArea := G_ActiveWindow.GetHitArea(G_CaptionHeight) - if (!G_currentMouse.IsInRectangle(hitArea)) - { - LogText("Outside Window Hit Area: " . hitArea.Description) - return - } + hitArea := G_ActiveWindow.GetHitArea(G_CaptionHeight) + if (!G_currentMouse.IsInRectangle(hitArea)) + { + LogText("Outside Window Hit Area: " . hitArea.Description) + return + } - title := G_ActiveWindow.Title - description := G_ActiveWindow.Description + title := G_ActiveWindow.Title + description := G_ActiveWindow.Description - ShowMenu(G_ActiveWindow) + ShowMenu(G_ActiveWindow) - return + return From 2df7f7245e7db03901a86c950629b85fa5a8ae51 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Feb 2020 13:35:44 +0000 Subject: [PATCH 2/5] Untabified --- Lib/DesktopIcons.ahk | 332 ++++++++++++++++++++-------------------- Lib/WindowPositions.ahk | 115 ++++++++------ 2 files changed, 230 insertions(+), 217 deletions(-) diff --git a/Lib/DesktopIcons.ahk b/Lib/DesktopIcons.ahk index 40e61bb..3854473 100644 --- a/Lib/DesktopIcons.ahk +++ b/Lib/DesktopIcons.ahk @@ -24,15 +24,15 @@ DesktopIconsFileExt := "dat" ; Initialisation DesktopIcons_OnInit() { - global MEM_COMMIT - global PAGE_READWRITE - global LVM_GETITEMCOUNT - global DesktopIconsBaseFileName + global MEM_COMMIT + global PAGE_READWRITE + global LVM_GETITEMCOUNT + global DesktopIconsBaseFileName global DesktopIconsFileExt - MEM_COMMIT := 0x1000, MEM_RESERVE := 0x2000, MEM_RELEASE := 0x8000 - PAGE_READWRITE := 0x04 - LVM_GETITEMCOUNT := 0x00001004, LVM_GETITEMPOSITION := 0x00001010, LVM_SETITEMPOSITION := 0x0000100F, WM_SETREDRAW := 0x000B + 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" DesktopIconsFileExt := "dat" @@ -54,8 +54,8 @@ DesktopIcons_OnInit() ; DesktopIconsDataFile - class DesktopIconsDataFile extends WindowExtensionsDataFile { - __New(fullFileName) - { + __New(fullFileName) + { base.__New(fullFileName) } @@ -164,20 +164,20 @@ GetLatestDesktopIconsDataFileName(desktopSize) } ;-------------------------------------------------------------------------------- -; BuildWindowFromDefinition - Build a Desktop Icon Definition from a text string -BuildDesktopIconFromDefinition(text, separator = "|") +; BuildDesktopIconFromDefinition - Build a Desktop Icon Definition from a text string +BuildDesktopIconFromDefinition(text, separator := "|") { parts := StrSplit(text, separator) icon := new IconPosition(parts[1], parts[2]) - icon.Title := parts[3] + icon.Title := parts[3] return icon } ;-------------------------------------------------------------------------------- ; GetIconPositionDefinition - Create a text representation of a Desktop Icon -GetIconPositionDefinition(iconPosition, separator = "|") +GetIconPositionDefinition(iconPosition, separator := "|") { parts := [] parts.Push(iconPosition.Left) @@ -192,58 +192,58 @@ GetIconPositionDefinition(iconPosition, separator = "|") ;-------------------------------------------------------------------------------- GetDesktopIconPositions(desktop) { - icons := [] - - try - { - listViewHandle := desktop.SysListView32Window.WindowHandle - - SendMessage, %LVM_GETITEMCOUNT%, , , , ahk_id %listViewHandle% - iconCount := ErrorLevel - - iconNames := [] - ControlGet, items, list, Col1 - Loop, Parse, items, `n - { - iconNames.push(A_LoopField) - } - - hProcess := DllCall("OpenProcess" , "UInt", 0x438 ; PROCESS-OPERATION|READ|WRITE|QUERY_INFORMATION - , "Int", FALSE ; inherit = false - , "UInt", desktop.SysListView32Window.ProcessId) - - VarSetCapacity(iCoord, 8) - pItemCoord := DllCall("VirtualAllocEx", "UInt", hProcess, "UInt", 0, "UInt", 8, "UInt", MEM_COMMIT | MEM_RESERVE, "UInt", PAGE_READWRITE) - Loop, %iconCount% - { - index := A_Index - 1 - - DllCall("WriteProcessMemory", "UInt", hProcess, "UInt", pItemCoord, "UInt", &iCoord, "UInt", 8, "UIntP", cbReadWritten) - SendMessage, %LVM_GETITEMPOSITION%, %index%, %pItemCoord% - DllCall("ReadProcessMemory", "UInt", hProcess, "UInt", pItemCoord, "UInt", &iCoord, "UInt", 8, "UIntP", cbReadWritten) - - x := (NumGet(iCoord) & 0xFFFF) - y := (NumGet(iCoord, 4, "UInt") & 0xFFFF) - title := iconNames[index + 1] - - iconPosition := new IconPosition(x, y) - iconPosition.Index := index - iconPosition.Title := title - - icons.push(iconPosition) - } - DllCall("VirtualFreeEx", "UInt", hProcess, "UInt", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE) - } - catch e - { - LogText("Exception: " . e.Message . ", What: " . e.What . ", Extra: " . e.Extra) - } - finally - { - DllCall("CloseHandle", "UInt", hProcess) - } - - return icons + icons := [] + + try + { + listViewHandle := desktop.SysListView32Window.WindowHandle + + SendMessage, %LVM_GETITEMCOUNT%, , , , ahk_id %listViewHandle% + iconCount := ErrorLevel + + iconNames := [] + ControlGet, items, list, Col1 + Loop, Parse, items, `n + { + iconNames.push(A_LoopField) + } + + hProcess := DllCall("OpenProcess" , "UInt", 0x438 ; PROCESS-OPERATION|READ|WRITE|QUERY_INFORMATION + , "Int", FALSE ; inherit = false + , "UInt", desktop.SysListView32Window.ProcessId) + + VarSetCapacity(iCoord, 8) + pItemCoord := DllCall("VirtualAllocEx", "UInt", hProcess, "UInt", 0, "UInt", 8, "UInt", MEM_COMMIT | MEM_RESERVE, "UInt", PAGE_READWRITE) + Loop, %iconCount% + { + index := A_Index - 1 + + DllCall("WriteProcessMemory", "UInt", hProcess, "UInt", pItemCoord, "UInt", &iCoord, "UInt", 8, "UIntP", cbReadWritten) + SendMessage, %LVM_GETITEMPOSITION%, %index%, %pItemCoord% + DllCall("ReadProcessMemory", "UInt", hProcess, "UInt", pItemCoord, "UInt", &iCoord, "UInt", 8, "UIntP", cbReadWritten) + + x := (NumGet(iCoord) & 0xFFFF) + y := (NumGet(iCoord, 4, "UInt") & 0xFFFF) + title := iconNames[index + 1] + + iconPosition := new IconPosition(x, y) + iconPosition.Index := index + iconPosition.Title := title + + icons.push(iconPosition) + } + DllCall("VirtualFreeEx", "UInt", hProcess, "UInt", pItemCoord, "UInt", 0, "UInt", MEM_RELEASE) + } + catch e + { + LogText("Exception: " . e.Message . ", What: " . e.What . ", Extra: " . e.Extra) + } + finally + { + DllCall("CloseHandle", "UInt", hProcess) + } + + return icons } ;-------------------------------------------------------------------------------- @@ -261,39 +261,37 @@ HasIconMoved(icon1, icon2) ; SaveDesktopIcons - Save all the current desktop icons to a file SaveDesktopIcons(notify) { - desktop := new Desktop() - if (!desktop.IsValid) - return - - desktopSize := GetDesktopSize() - - fileName := GetUserDataFileName(BuildWindowPositionsDataFileName(desktopSize, true)) - - iconPositions := GetDesktopIconPositions(desktop) - - saveCount := 0 - for i, iconPosition in iconPositions - { - xx := iconPositions[i] - - data := GetIconPositionDefinition(iconPosition) - - FileAppend , % data . "`r`n", %fileName% - saveCount += 1 - } + desktop := new Desktop() + if (!desktop.IsValid) + return + + desktopSize := GetDesktopSize() + + iconPositions := GetDesktopIconPositions(desktop) + + fileName := GetUserDataFileName(BuildDesktopIconsDataFileName(desktopSize, true)) + + saveCount := 0 + for i, iconPosition in iconPositions + { + data := GetIconPositionDefinition(iconPosition) + + FileAppend , % data . "`r`n", %fileName% + saveCount += 1 + } LogText("DesktopIcons: " . saveCount . " icons written to " . fileName) - if (notify) - { - notifyText := "No Desktop Icons saved" - If saveCount > 0 - { - notifyText := saveCount . " Desktop Icons saved" - } - - new PleasantNotify("Desktop Icons", notifyText, 250, 100, "b r") - } + if (notify) + { + notifyText := "No Desktop Icons saved" + If saveCount > 0 + { + notifyText := saveCount . " Desktop Icons saved" + } + + new PleasantNotify("Desktop Icons", notifyText, 250, 100, "b r") + } } ;-------------------------------------------------------------------------------- @@ -307,10 +305,10 @@ RestoreDesktopIcons(fileName) return } - desktop := new Desktop() - if (!desktop.IsValid) - return - + desktop := new Desktop() + if (!desktop.IsValid) + return + desktopSize := GetDesktopSize() ; Read the file into an array @@ -326,98 +324,98 @@ RestoreDesktopIcons(fileName) savedIcons.Push(savedIcon) } } - - currentIcons := GetDesktopIconPositions(desktop) + + currentIcons := GetDesktopIconPositions(desktop) restoreCount := 0 moveCount := 0 - for key, currentIcon in currentIcons - { - foundIcon := - for x, savedIcon in savedIcons - { - if (savedIcon.Title = currentIcon.Title) - { - foundIcon := savedIcon - break - } - } - - if (!foundIcon) - { - LogText("No saved Icon for : " . currentIcon.Title) - continue - } - + for key, currentIcon in currentIcons + { + foundIcon := + for x, savedIcon in savedIcons + { + if (savedIcon.Title = currentIcon.Title) + { + foundIcon := savedIcon + break + } + } + + if (!foundIcon) + { + LogText("No saved Icon for : " . currentIcon.Title) + continue + } + If (HasIconMoved(foundIcon, currentIcon)) { - index := currentIcon.Index - + index := currentIcon.Index + LogText("Moving: " . currentIcon.Description) LogText("To: " . foundIcon.Description) - pItemCoord := (foundIcon.Top << 16) | foundIcon.Left - LogText("pItemCoord: " . pItemCoord) - - SendMessage, %LVM_SETITEMPOSITION%, %index%, %pItemCoord% - + pItemCoord := (foundIcon.Top << 16) | foundIcon.Left + LogText("pItemCoord: " . pItemCoord) + + SendMessage, %LVM_SETITEMPOSITION%, %index%, %pItemCoord% + moveCount += 1 } restoreCount += 1 - } + } - textParts := [] - textParts.push(restoreCount . " icons restored") - textParts.push(moveCount . " icons moved") + textParts := [] + textParts.push(restoreCount . " icons restored") + textParts.push(moveCount . " icons moved") LogText("DesktopIcons: " . JoinItems(", ", textParts)) - - new PleasantNotify("Desktop Icons", JoinItems("`r`n", textParts), 300, 125, "b r") + + new PleasantNotify("Desktop Icons", JoinItems("`r`n", textParts), 300, 125, "b r") } ;-------------------------------------------------------------------------------- ; RestoreDesktopIconsFromFile - Show the dialog to select the file to restore desktop icons from RestoreDesktopIconsFromFile(desktopSize) { - global G_SelectableDesktopIcons - - columns := [ "Desktop Resolution", "Date Created", "Hash", "Icon Count" ] - columnOptions := [ "AutoHdr NoSort", "Auto NoSort", "Auto NoSort Right", "AutoHdr Integer NoSort" ] - - G_SelectableDesktopIcons := GetDesktopIconsDataFiles(desktopSize) - - items := [] - for index, item in G_SelectableDesktopIcons - { - itemTimestamp := item.Timestamp - FormatTime, timestamp, %itemTimestamp%, yyyy-MM-dd HH:mm.ss - row := [ item.DesktopSizeDescription, timestamp, item.Adler32, item.LineCount ] - items.push(row) - } - - selector := new ListViewSelector() - selector.Title := "Restore Window Positions..." - selector.ColumnNames := columns - selector.ColumnOptions := columnOptions - selector.Items := items - selector.ListViewWidth := 400 - selector.MinRowCountSize := 6 - selector.SelectedIndex := 1 - selector.OnSuccess := "OnDesktopIconsSelected" - - selector.ShowDialog() + global G_SelectableDesktopIcons + + columns := [ "Desktop Resolution", "Date Created", "Hash", "Icon Count" ] + columnOptions := [ "AutoHdr NoSort", "Auto NoSort", "Auto NoSort Right", "AutoHdr Integer NoSort" ] + + G_SelectableDesktopIcons := GetDesktopIconsDataFiles(desktopSize) + + items := [] + for index, item in G_SelectableDesktopIcons + { + itemTimestamp := item.Timestamp + FormatTime, timestamp, %itemTimestamp%, yyyy-MM-dd HH:mm.ss + row := [ item.DesktopSizeDescription, timestamp, item.Adler32, item.LineCount ] + items.push(row) + } + + selector := new ListViewSelector() + selector.Title := "Restore Window Positions..." + selector.ColumnNames := columns + selector.ColumnOptions := columnOptions + selector.Items := items + selector.ListViewWidth := 400 + selector.MinRowCountSize := 6 + selector.SelectedIndex := 1 + selector.OnSuccess := "OnDesktopIconsSelected" + + selector.ShowDialog() } ;-------------------------------------------------------------------------------- ; OnDesktopIconsSelected - Restore selected Window Positions OnDesktopIconsSelected(listViewSelector) { - global G_SelectableDesktopIcons - - item := G_SelectableDesktopIcons[listViewSelector.SelectedIndex] - - if (!item) - return - - RestoreDesktopIcons(item.FullFileName) + global G_SelectableDesktopIcons + + item := G_SelectableDesktopIcons[listViewSelector.SelectedIndex] + + if (!item) + return + + RestoreDesktopIcons(item.FullFileName) } diff --git a/Lib/WindowPositions.ahk b/Lib/WindowPositions.ahk index 7b4cb4a..330c223 100644 --- a/Lib/WindowPositions.ahk +++ b/Lib/WindowPositions.ahk @@ -43,8 +43,8 @@ WindowPositions_OnInit() ; WindowPositionsDataFile - class WindowPositionsDataFile extends WindowExtensionsDataFile { - __New(fullFileName) - { + __New(fullFileName) + { base.__New(fullFileName) } @@ -192,14 +192,10 @@ GetWindowDefinition(window, separator := "|") } ;-------------------------------------------------------------------------------- -; SaveWindowPositions - Save all the current window positions to a file -SaveWindowPositions(includeOffScreenWindows, notify) +GetWindowPositions(includeOffScreenWindows) { - desktopSize := GetDesktopSize() + positions := [] - fileName := GetUserDataFileName(BuildWindowPositionsDataFileName(desktopSize, true)) - - saveCount := 0 WinGet windows, List Loop %windows% @@ -242,13 +238,32 @@ SaveWindowPositions(includeOffScreenWindows, notify) if (window.Title && window.IsValid && isVisible) { - saveCount += 1 - data := GetWindowDefinition(window) - LogText("Saving: " . data) - FileAppend , % data . "`r`n", %fileName% + positions.push(window) } } + return positions +} + +;-------------------------------------------------------------------------------- +; SaveWindowPositions - Save all the current window positions to a file +SaveWindowPositions(includeOffScreenWindows, notify) +{ + desktopSize := GetDesktopSize() + + windowPositions := GetWindowPositions(includeOffScreenWindows) + + fileName := GetUserDataFileName(BuildWindowPositionsDataFileName(desktopSize, true)) + + saveCount := 0 + for i, windowPosition in windowPositions + { + data := GetWindowDefinition(windowPosition) + + FileAppend , % data . "`r`n", %fileName% + saveCount += 1 + } + LogText("WindowPositions: " . saveCount . " windows written to " . fileName) if (notify) @@ -329,9 +344,9 @@ RestoreWindowPositions(fileName, includeOffScreenWindows) restoreCount += 1 } - textParts := [] - textParts.push(restoreCount . " windows restored") - textParts.push(moveCount . " windows moved") + textParts := [] + textParts.push(restoreCount . " windows restored") + textParts.push(moveCount . " windows moved") LogText("WindowPositions: " . JoinItems(", ", textParts)) @@ -342,45 +357,45 @@ RestoreWindowPositions(fileName, includeOffScreenWindows) ; RestoreWindowPositionsFromFile - Show the dialog to select the file to restore window positions from RestoreWindowPositionsFromFile(desktopSize) { - global G_SelectableWindowPositions - - columns := [ "Desktop Resolution", "Date Created", "Hash", "Window Count" ] - columnOptions := [ "AutoHdr NoSort", "Auto NoSort", "Auto NoSort Right", "AutoHdr Integer NoSort" ] - - G_SelectableWindowPositions := GetWindowPositionsDataFiles(desktopSize) - - items := [] - for index, item in G_SelectableWindowPositions - { - itemTimestamp := item.Timestamp - FormatTime, timestamp, %itemTimestamp%, yyyy-MM-dd HH:mm.ss - row := [ item.DesktopSizeDescription, timestamp, item.Adler32, item.LineCount ] - items.push(row) - } - - selector := new ListViewSelector() - selector.Title := "Restore Window Positions..." - selector.ColumnNames := columns - selector.ColumnOptions := columnOptions - selector.Items := items - selector.ListViewWidth := 400 - selector.MinRowCountSize := 6 - selector.SelectedIndex := 1 - selector.OnSuccess := "OnWindowPositionsSelected" - - selector.ShowDialog() + global G_SelectableWindowPositions + + columns := [ "Desktop Resolution", "Date Created", "Hash", "Window Count" ] + columnOptions := [ "AutoHdr NoSort", "Auto NoSort", "Auto NoSort Right", "AutoHdr Integer NoSort" ] + + G_SelectableWindowPositions := GetWindowPositionsDataFiles(desktopSize) + + items := [] + for index, item in G_SelectableWindowPositions + { + itemTimestamp := item.Timestamp + FormatTime, timestamp, %itemTimestamp%, yyyy-MM-dd HH:mm.ss + row := [ item.DesktopSizeDescription, timestamp, item.Adler32, item.LineCount ] + items.push(row) + } + + selector := new ListViewSelector() + selector.Title := "Restore Window Positions..." + selector.ColumnNames := columns + selector.ColumnOptions := columnOptions + selector.Items := items + selector.ListViewWidth := 400 + selector.MinRowCountSize := 6 + selector.SelectedIndex := 1 + selector.OnSuccess := "OnWindowPositionsSelected" + + selector.ShowDialog() } ;-------------------------------------------------------------------------------- ; OnWindowPositionSelected - Restore selected Window Positions OnWindowPositionsSelected(listViewSelector) { - global G_SelectableWindowPositions - - item := G_SelectableWindowPositions[listViewSelector.SelectedIndex] - - if (!item) - return - - RestoreWindowPositions(item.FullFileName, G_UserConfig.WindowPositions_IncludeOffScreenWindows) + global G_SelectableWindowPositions + + item := G_SelectableWindowPositions[listViewSelector.SelectedIndex] + + if (!item) + return + + RestoreWindowPositions(item.FullFileName, G_UserConfig.WindowPositions_IncludeOffScreenWindows) } From 47dff8c992ab37da6623e120581159462aeb6120 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Feb 2020 13:55:20 +0000 Subject: [PATCH 3/5] Formatting --- WindowExtensions.ahk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/WindowExtensions.ahk b/WindowExtensions.ahk index a00622f..f7fd2ba 100644 --- a/WindowExtensions.ahk +++ b/WindowExtensions.ahk @@ -12,7 +12,7 @@ SetTitleMatchMode, 2 AppName := "WindowExtensions" AppTitle := "Window Extensions" AppDescription := "Window Extensions Menu and HotKeys" -AppCopyright := "Copyright � 2020 Martin Smith" +AppCopyright := "Copyright © 2020 Martin Smith" 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.6.7.0" @@ -24,8 +24,8 @@ LogInit() ;-------------------------------------------------------------------------------- ; System Information -SysGet, G_CaptionHeight, 4 ; SM_CYCAPTION -SysGet, G_BorderHeight, 5 ; SM_CXBORDER +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 @@ -55,10 +55,10 @@ OnExit, ExitHandler ;-------------------------------------------------------------------------------- ; Auto-Execute section OnInit() ; Perform module initialisation - not reliant on other modules or globals -InitGlobals() ; -OnStartup() ; Perform module startup - may rely on other modules Init +InitGlobals() ; +OnStartup() ; Perform module startup - may rely on other modules Init -return ; End of script's auto-execute section. +return ; End of script's auto-execute section. ;-------------------------------------------------------------------------------- From 1f08b53f3590cda97e419a506a80b6ec47401263 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Feb 2020 18:02:57 +0000 Subject: [PATCH 4/5] Consolidate Data Files for Window Positions and Desktop Icons --- Lib/DesktopIcons.ahk | 17 ++++++++++- Lib/UserDataUtils.ahk | 65 +++++++++++++++++++++++++++++++++++++++++ Lib/WindowPositions.ahk | 19 ++++++++++-- 3 files changed, 98 insertions(+), 3 deletions(-) diff --git a/Lib/DesktopIcons.ahk b/Lib/DesktopIcons.ahk index 3854473..13914d0 100644 --- a/Lib/DesktopIcons.ahk +++ b/Lib/DesktopIcons.ahk @@ -282,15 +282,30 @@ SaveDesktopIcons(notify) LogText("DesktopIcons: " . saveCount . " icons written to " . fileName) + pattern := BuildDesktopIconsDataFileName(desktopSize, false, true) + allDataFiles := GetUserDataFileNames(pattern, -1) + + consolidatedCount := ConsolidateUserDataFilesByCRC32(allDataFiles) + + LogText("DesktopIcons: Consolidated - " . consolidatedCount . " files removed") + if (notify) { + notifyHeight := 100 notifyText := "No Desktop Icons saved" + If saveCount > 0 { notifyText := saveCount . " Desktop Icons saved" } - new PleasantNotify("Desktop Icons", notifyText, 250, 100, "b r") + if (consolidatedCount > 0) + { + notifyText .= "`r`n" . consolidatedCount . " files Consolidated" + notifyHeight += 25 + } + + new PleasantNotify("Desktop Icons", notifyText, 250, notifyHeight, "b r") } } diff --git a/Lib/UserDataUtils.ahk b/Lib/UserDataUtils.ahk index 2af37df..db3e44c 100644 --- a/Lib/UserDataUtils.ahk +++ b/Lib/UserDataUtils.ahk @@ -63,3 +63,68 @@ GetUserDataFileNames(dataFilePattern, sortOrder := 0) return files } + +;-------------------------------------------------------------------------------- +; ConsolidateUserDataFilesByCRC32 : Consolidate User Data files by removing those with a duplicate CRC32 +GroupFilesByCRC32(allFiles) +{ + allFileNamesByHash := [] + + fileCount := allFiles.Length() + LogText("fileCount: " . fileCount) + + Loop, % fileCount + { + fileName := allFiles[A_Index] + + userDataFile := new DataFile(fileName) + fileHash := userDataFile.CRC32 + + items := allFileNamesByHash[fileHash] + if (!items) + { + allFileNamesByHash[fileHash] := [] + } + LogText("Hash: " . fileHash . " - " . fileName) + allFileNamesByHash[fileHash].push(userDataFile) + } + + return allFileNamesByHash +} + +;-------------------------------------------------------------------------------- +; ConsolidateUserDataFilesByCRC32 : Consolidate User Data files by removing those with a duplicate CRC32 +ConsolidateUserDataFilesByCRC32(allFiles) +{ + deleteCount := 0 + + allFileNamesByHash := GroupFilesByCRC32(allFiles) + + For hash, hashItems in allFileNamesByHash + { + hashCount := hashItems.Length() + if (hashCount < 2) + { + LogText("Hash: " . hash . " - skipping for count: " . hashCount) + continue + } + + Loop, % hashCount + { + hashFile := hashItems[A_Index] + hashFileName := hashFile.FullFileName + + if (A_Index < 2) + { + LogText("Hash: " . fileHash . " - keeping: " . hashFileName) + continue + } + + LogText("Hash: " . fileHash . " - deleting: " . hashFileName) + FileDelete, %hashFileName% + deleteCount += 1 + } + } + + return deleteCount +} diff --git a/Lib/WindowPositions.ahk b/Lib/WindowPositions.ahk index 330c223..920e2b3 100644 --- a/Lib/WindowPositions.ahk +++ b/Lib/WindowPositions.ahk @@ -265,16 +265,31 @@ SaveWindowPositions(includeOffScreenWindows, notify) } LogText("WindowPositions: " . saveCount . " windows written to " . fileName) - + + pattern := BuildWindowPositionsDataFileName(desktopSize, false, true) + allDataFiles := GetUserDataFileNames(pattern, -1) + + consolidatedCount := ConsolidateUserDataFilesByCRC32(allDataFiles) + + LogText("WindowPositions: Consolidated - " . consolidatedCount . " files removed") + if (notify) { + notifyHeight := 100 notifyText := "No Window Positions saved" + If saveCount > 0 { notifyText := saveCount . " Window Positions saved" } + + if (consolidatedCount > 0) + { + notifyText .= "`r`n" . consolidatedCount . " files Consolidated" + notifyHeight += 25 + } - new PleasantNotify("Window Positions", notifyText, 250, 100, "b r") + new PleasantNotify("Window Positions", notifyText, 250, notifyHeight, "b r") } } From c6a15fc8b55a0d732d59371e2879724156a3bb0f Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Feb 2020 18:03:12 +0000 Subject: [PATCH 5/5] Version bump and release note --- Docs/releasenotes.md | 4 ++++ Setup/WindowExtensions_Setup.iss | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Docs/releasenotes.md b/Docs/releasenotes.md index 1f1f40a..223cfd7 100644 --- a/Docs/releasenotes.md +++ b/Docs/releasenotes.md @@ -1,5 +1,9 @@ # Release Notes +## v1.6.7 - 2020-02-23 + +- Consolidate data saving + ## v1.6.6 - 2020-01-27 - Support History of Saved Desktop Icons diff --git a/Setup/WindowExtensions_Setup.iss b/Setup/WindowExtensions_Setup.iss index a8066b4..33b7b5e 100644 --- a/Setup/WindowExtensions_Setup.iss +++ b/Setup/WindowExtensions_Setup.iss @@ -1,6 +1,6 @@ #define AppName "WindowExtensions" #define AppTitle "Window Extensions" -#define AppVersion "1.6.6" +#define AppVersion "1.6.7.0" [Setup] AppName={#AppName}