Skip to content

Commit

Permalink
Merge pull request #5 from martinsmith1968/bugfix/restoring-hidden-wi…
Browse files Browse the repository at this point in the history
…ndows

Bugfix/restoring hidden windows
  • Loading branch information
martinsmith1968 authored Jan 4, 2020
2 parents 0bc46e5 + c8c8266 commit 5d672a3
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 82 deletions.
Binary file modified Docs/ConfigurationDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion Docs/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Release Notes

## v1.6.0 - 2020-01-04
## v1.6.1 - 2020-01-04

- Fixed issue with Restore Window Positions which would position Windows Settings screen when it wasn't visible before
- Minor documentation updates for new Config settings

## v1.6.0 - 2020-01-03

- 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
Expand Down
7 changes: 7 additions & 0 deletions Docs/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@
- History list of Saved Window Positions
- History list of Saved Desktop Icon Positions
- Add icons to other context menu items
- Convert Configuration dialog to use Tabbed controls
- Auto-Save Window Positions on a schedule
- Auto-Save Desktop Icons on a schedule

## Bugs

- If Desktop has 2 icons with the same name (1 user, 1 public), it doesn't always move the icon
10 changes: 4 additions & 6 deletions Lib/DesktopIcons.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Include Lib\Logging.ahk
#Include Lib\StringUtils.ahk
#Include Lib\PathUtils.ahk
#Include Lib\IOUtils.ahk
#Include Lib\WindowObjects.ahk
#Include Lib\MathUtils.ahk
#Include Lib\UserDataUtils.ahk
Expand Down Expand Up @@ -39,9 +39,7 @@ HasSavedDesktopIconsFile(desktopSize)
{
fileName := GetDesktopIconsDataFileName(desktopSize)

exists := FileExist(fileName)

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

;--------------------------------------------------------------------------------
Expand Down Expand Up @@ -167,7 +165,7 @@ SaveDesktopIcons()

fileName := GetDesktopIconsDataFileName(desktopSize)

If FileExist(fileName)
If (FileExists(fileName))
{
LogText("Removing old Data File: " . fileName)
FileDelete , %fileName%
Expand Down Expand Up @@ -208,7 +206,7 @@ RestoreDesktopIcons()

fileName := GetDesktopIconsDataFileName(desktopSize)

If !FileExist(fileName)
If (!FileExists(fileName))
{
MsgBox , 48, Restore Desktop Icons, Unable to locate file %fileName%
return
Expand Down
51 changes: 51 additions & 0 deletions Lib/IOUtils.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include Lib\StringUtils.ahk

;--------------------------------------------------------------------------------
; CombinePaths - Append path2 to path1, ensuring the correct delimiters are in place
CombinePaths(path1, path2)
{
return EnsureEndsWith(path1, "\") . path2
}

;--------------------------------------------------------------------------------
; CombinePaths - Append multiple paths together, ensuring the correct delimiters are in place
CombinePathA(paths*)
{
newPath :=

Loop, %path%
{
if (newPath = "")
{
newPath := path
}
else
{
newPath := EnsureEndsWith(newPath, "\") . path
}
}

return newPath
}

;--------------------------------------------------------------------------------
; FileExists - Determines if a file exists
FileExists(fileName)
{
fileAttribute := FileExist(fileName)

exists := (fileAttribute && fileAttribute != "X")

return exists
}

;--------------------------------------------------------------------------------
; FolderExists - Determines if a folder exists
FolderExists(folderName)
{
folderAttribute := FileExist(folderName)

exists := (folderAttribute && InStr(folderAttribute, "D"))

return exists
}
7 changes: 6 additions & 1 deletion Lib/MathUtils.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

;--------------------------------------------------------------------------------
; MinOf - Find the lower of 2 numbers
MinOf(a, b)
{
if (a < b)
Expand All @@ -11,6 +12,8 @@ MinOf(a, b)
}
}

;--------------------------------------------------------------------------------
; MaxOf - Find the higher of 2 numbers
MaxOf(a, b)
{
if (a > b)
Expand All @@ -23,6 +26,8 @@ MaxOf(a, b)
}
}

;--------------------------------------------------------------------------------
; ContainsFlag - Does a value contain a bitwise value
ContainsFlag(value, bitwiseFlag)
{
return (bitwiseFlag > 0) && (value & bitwiseFlag) > 0
Expand Down
30 changes: 0 additions & 30 deletions Lib/PathUtils.ahk

This file was deleted.

22 changes: 22 additions & 0 deletions Lib/UserConfig.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ class UserConfig
IniWrite, %value%, %dataFileName%, %section%, %key%
}

GetSectionNameFromFunc(func, defaultName := "General")
{
bits := StrSplit(func, ".")

sectionName := bits[2]

if (sectionName =)
sectionName := func

nameParts := StrSplit(sectionName, "_")
if (nameParts.length() > 1)
sectionName := nameParts[1]
else
sectionName := defaultName

return sectionName
}

GetPropertyNameFromFunc(func)
{
bits := StrSplit(func, ".")
Expand All @@ -67,6 +85,10 @@ class UserConfig
if (propertyName =)
propertyName := func

nameParts := StrSplit(propertyName, "_")
if (nameParts.length() > 1)
propertyName := nameParts[2]

return propertyName
}

Expand Down
4 changes: 2 additions & 2 deletions Lib/UserDataUtils.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Include Lib\Logging.ahk
#Include Lib\StringUtils.ahk
#Include Lib\PathUtils.ahk
#Include Lib\IOUtils.ahk

;--------------------------------------------------------------------------------
; Globals
Expand All @@ -17,7 +17,7 @@ UserDataUtils_OnInit()

UserDataPath := CombinePaths(A_AppData, AppName)

If (!DirectoryExists(UserDataPath))
If (!FolderExists(UserDataPath))
{
LogText("Creating UserDataPath: " . UserDataPath)
FileCreateDir, %UserDataPath%
Expand Down
34 changes: 34 additions & 0 deletions Lib/WindowFunctions.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,40 @@ IsWindowVisible(windowHandle)
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)
}

;--------------------------------------------------------------------------------
; 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
}

;--------------------------------------------------------------------------------
; GetWindowNormalPosition - Get the restored position of a window
GetWindowNormalPosition(windowHandle)
Expand Down
8 changes: 8 additions & 0 deletions Lib/WindowObjects.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ Class Window extends Rectangle
}
}

IsOnScreen
{
get
{
return IsWindowOnScreen(this.WindowHandle)
}
}

MonitorIndex
{
get
Expand Down
Loading

0 comments on commit 5d672a3

Please sign in to comment.