Skip to content

Commit

Permalink
Merge pull request #4 from martinsmith1968/feature/context-menu-options
Browse files Browse the repository at this point in the history
Feature/context menu options
  • Loading branch information
martinsmith1968 authored Jan 3, 2020
2 parents 466ab36 + 36b7254 commit 0bc46e5
Show file tree
Hide file tree
Showing 18 changed files with 674 additions and 331 deletions.
2 changes: 1 addition & 1 deletion AboutGui.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DestroyAboutGui()
Gui, About:Destroy
}

ShowAbout()
ShowAboutGui()
{
Global AppName, AppTitle, AppDescription, AppNotes, AppURL, AppVersion

Expand Down
5 changes: 5 additions & 0 deletions Docs/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## v1.6.0 - 2020-01-04

- Restructured code radically to better organise modules and avoid multi module hell of inline startup code
- Implemented options to control which menus the Save / Restore Window Positions and Desktop Icons appear in

## v1.5.0 - 2020-01-01

- Added options for Restore Window Positions on Startup and Restore Desktop Icons on Startup
Expand Down
3 changes: 0 additions & 3 deletions Docs/todo.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# To Do

- Move Window Positions Menu to Context Menu (Option?)
- Move Saved Desktop Icon Positions Menu to Context Menu (Option?)
- History list of Saved Window Positions
- History list of Saved Desktop Icon Positions
- Add icons to other context menu items
- Support other config value types as required
13 changes: 13 additions & 0 deletions Lib/ArrayUtils.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ AutoSort(Arr)

return Arr
}

;--------------------------------------------------------------------------------
; IndexOf - Find the index of an array item
IndexOf(array, item)
{
for index, param in array
{
if (param = item)
return index
}

return 0
}
24 changes: 21 additions & 3 deletions Lib/DesktopIcons.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,33 @@ global PAGE_READWRITE := 0x04
global LVM_GETITEMCOUNT := 0x00001004, LVM_GETITEMPOSITION := 0x00001010, LVM_SETITEMPOSITION := 0x0000100F, WM_SETREDRAW := 0x000B

;--------------------------------------------------------------------------------
; Configuration
DesktopIconsBaseFileName := "DesktopIcons"
; Globals
DesktopIconsBaseFileName := ""

;--------------------------------------------------------------------------------
; Initialisation
DesktopIcons_OnInit()
{
global MEM_COMMIT
global PAGE_READWRITE
global LVM_GETITEMCOUNT
global DesktopIconsBaseFileName

MEM_COMMIT := 0x1000, MEM_RESERVE := 0x2000, MEM_RELEASE := 0x8000
PAGE_READWRITE := 0x04
LVM_GETITEMCOUNT := 0x00001004, LVM_GETITEMPOSITION := 0x00001010, LVM_SETITEMPOSITION := 0x0000100F, WM_SETREDRAW := 0x000B

DesktopIconsBaseFileName := "DesktopIcons"
}

;--------------------------------------------------------------------------------
HasSavedDesktopIconsFile(desktopSize)
{
fileName := GetDesktopIconsDataFileName(desktopSize)

return FileExist(fileName)
exists := FileExist(fileName)

return (exists && exists != "X")
}

;--------------------------------------------------------------------------------
Expand Down
51 changes: 33 additions & 18 deletions Lib/Logging.ahk
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
LogFile := A_Temp
LogFile :=

SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt

; Initialise Log
LogFileSuffix := ""
IfNotEqual, A_IsCompiled, 1
;--------------------------------------------------------------------------------
; LogInit - Initialise logging (explicit call, rather than relying on include)
LogInit()
{
LogFileSuffix := ".Debug"
}
global LogFile

LogFile := A_Temp

LogFile := A_Temp . "\" . ScriptFileNameNoExt . LogFileSuffix . ".log"
LogStart()
SplitPath A_ScriptFullPath, , ScriptFilePath, , ScriptFileNameNoExt

; Initialise Log
LogFileSuffix := ""
IfNotEqual, A_IsCompiled, 1
{
LogFileSuffix := ".Debug"
}

LogFile := A_Temp . "\" . ScriptFileNameNoExt . LogFileSuffix . ".log"
LogStart()
}

;--------------------------------------------------------------------------------
; LogText - Debug Text to a file
LogText(text)
{
global LogFile

FormatTime now,, yyy-MM-dd HH:mm.ss
FileAppend %now% %text%`r`n, %LogFile%
if (LogFile)
{
FormatTime now,, yyy-MM-dd HH:mm.ss
FileAppend %now% %text%`r`n, %LogFile%
}
}

;--------------------------------------------------------------------------------
; LogText - Debug Text to a file
; LogStart - Begin a logging session
LogStart()
{
global LogFile

IfNotEqual, A_IsCompiled, 1
if (LogFile)
{
FileDelete, LogFile
file := FileOpen(LogFile, "w")
if IsObject(file)
IfNotEqual, A_IsCompiled, 1
{
file.Close()
FileDelete, LogFile
file := FileOpen(LogFile, "w")
if IsObject(file)
{
file.Close()
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions Lib/MathUtils.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ MaxOf(a, b)
return b
}
}

ContainsFlag(value, bitwiseFlag)
{
return (bitwiseFlag > 0) && (value & bitwiseFlag) > 0
}
57 changes: 57 additions & 0 deletions Lib/MenuFunctions.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#Include Lib\Logging.ahk

;--------------------------------------------------------------------------------
; ResetMenu - Remove all items from a Menu
ResetMenu(menuName)
{
try Menu, %menuName%, DeleteAll
}

;--------------------------------------------------------------------------------
; AddMenuItem - Add a Menu Item to a Menu
AddMenuItem(menuName, text, handler, menuIndex := 0)
{
If (text = "")
{
LogText("Adding Menu Separator: " . menuName)
Menu, %menuName%, Add
}
else
{
LogText("Adding Menu: " . menuName . " - " . text . " = " . handler)
Menu, %menuName%, Add, %text%, %handler%
}

return menuIndex + 1
}

;--------------------------------------------------------------------------------
; AddMenuItem - Add a Menu Item to a Menu, and set its Icon
AddMenuItemWithIcon(menuName, text, handler, iconFileName, iconIndex, menuIndex := 0)
{
menuIndex := AddMenuItem(menuName, text, handler, menuIndex)

if (iconIndex > 0)
{
try Menu, %menuName%, Icon, %text%, %iconFileName%, %iconIndex%
}

return menuIndex + 1
}

;--------------------------------------------------------------------------------
; AddMenuItemSeparator - Add a Menu Item separator to a Menu
AddMenuItemSeparator(menuName, menuIndex)
{
AddMenuItem(menuName, "", "", menuIndex)
}

;--------------------------------------------------------------------------------
; EnableMenuItem - Enable / Disable a menu item
EnableMenuItem(menuName, menuTitle, enabled)
{
state := enabled ? "Enable" : "Disable"
LogText("Enabling: " . menuName . " - " . menuTitle . ", with " . enabled . " = " . state)

Menu, %menuName%, %state%, %menuTitle%
}
16 changes: 13 additions & 3 deletions Lib/UserConfig.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#Include Lib\UserDataUtils.ahk
#Include Lib\Logging.ahk
#Include Lib\WindowPositions.ahk

;--------------------------------------------------------------------------------
; Initialisation
UserConfig_OnInit()
{
UserDataUtils_OnInit()
}

;--------------------------------------------------------------------------------
; UserConfig base class
class UserConfig
{
Properties := []
Expand All @@ -16,14 +26,13 @@ class UserConfig
{
dataFileName := this.DataFileName

LogText("Getting Value: [" . section . "]." . key . ", default:" . defaultValue)
LogText("Getting Value: [" . section . "]." . key . ", default: " . defaultValue)
IniRead, readValue, %dataFileName%, %section%, %key%, %defaultValue%

LogText("Got Value: " . readValue)

if (type <> "")
{
; TODO - Support other types
if (type = "integer")
{
if readValue is not integer
Expand All @@ -35,6 +44,7 @@ class UserConfig
{
readValue := (readValue) ? true : false
}
; TODO - Support other types as necessary
}

return readValue
Expand All @@ -44,7 +54,7 @@ class UserConfig
{
dataFileName := this.DataFileName

LogText("Setting Value: [" . section . "]." . key . ", value:" . value)
LogText("Setting Value: [" . section . "]." . key . ", value: " . value)
IniWrite, %value%, %dataFileName%, %section%, %key%
}

Expand Down
24 changes: 18 additions & 6 deletions Lib/UserDataUtils.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
#Include Lib\StringUtils.ahk
#Include Lib\PathUtils.ahk

;--------------------------------------------------------------------------------
; Globals
UserDataPath := ""

;--------------------------------------------------------------------------------
; Initialisation
SplitPath A_ScriptFullPath, , , , AppName
UserDataUtils_OnInit()
{
global AppName
global UserDataPath

SplitPath A_ScriptFullPath, , , , AppName

UserDataPath := CombinePaths(A_AppData, AppName)
UserDataPath := CombinePaths(A_AppData, AppName)

If !DirectoryExists(UserDataPath)
{
LogText("Creating UserDataPath: " . UserDataPath)
FileCreateDir, %UserDataPath%
If (!DirectoryExists(UserDataPath))
{
LogText("Creating UserDataPath: " . UserDataPath)
FileCreateDir, %UserDataPath%
}
}

;--------------------------------------------------------------------------------
; GetUserDataFileName : Build an appropriate file name for the specified User data
GetUserDataFileName(dataFileName)
{
global UserDataPath
Expand Down
17 changes: 14 additions & 3 deletions Lib/WindowPositions.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@
#Include Lib\PleasantNotify.ahk

;--------------------------------------------------------------------------------
; Configuration
WindowPositionsBaseFileName := "WindowPositions"
; Globals
WindowPositionsBaseFileName := ""

;--------------------------------------------------------------------------------
; Initialisation
WindowPositions_OnInit()
{
global WindowPositionsBaseFileName

WindowPositionsBaseFileName := "WindowPositions"
}

;--------------------------------------------------------------------------------
HasSavedWindowPositionFile(desktopSize)
{
fileName := GetWindowPositionsDataFileName(desktopSize)

return FileExist(fileName)
exists := FileExist(fileName)

return (exists && exists != "X")
}

;--------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Window Extensions has the ability to save window positions and restore them on d

This was originally intended as a remedy to the widely known Multi-Monitor bug in Windows that doesn't restore window positions when unlocking or activating / deactivating monitors.

Window positions are saved to a file in the Users data folder (E.g. %APPDATA%\Roaming\WindowExtensions)
Window positions are saved to a file in the Users data folder (E.g. %APPDATA%\WindowExtensions)

### Desktop Icons

Window Extensions has the ability to save desktop icon positions and restore them on demand.

There are other tools available which are dedicated to this task, with perhaps more functionality. This feature was added to Window Extensions due to restrictions in being able to use these tools on some sites that I visit.

Desktop Icon positions are saved to a file in the Users data folder (E.g. %APPDATA%\Roaming\WindowExtensions)
Desktop Icon positions are saved to a file in the Users data folder (E.g. %APPDATA%\WindowExtensions)

## [To Do](Docs/todo.md)
2 changes: 1 addition & 1 deletion Setup/WindowMenu_Setup.iss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define AppName "WindowExtensions"
#define AppTitle "Window Extensions"
#define AppVersion "1.5.0"
#define AppVersion "1.6.0"

[Setup]
AppName={#AppName}
Expand Down
Loading

0 comments on commit 0bc46e5

Please sign in to comment.