Make auto-save session configurable

This commit is contained in:
Joshua Fuhs 2012-12-05 18:55:38 -05:00
parent e6ee31c281
commit 8c1c33bc1e
4 changed files with 54 additions and 18 deletions

View File

@ -89,7 +89,7 @@ Config_init()
Config_ruleCount := 12 ;; This variable has to be set to the total number of active rules above. Config_ruleCount := 12 ;; This variable has to be set to the total number of active rules above.
;; Configuration management ;; Configuration management
Config_autoSaveSession := False Config_autoSaveSession := "auto" ;; "off" | "auto" | "ask"
; @todo: To be removed? ; @todo: To be removed?
If Not Config_filePath ; The file path, to which the configuration and session is saved. This target directory must be writable by the user (%A_ScriptDir% is the diretory, in which "Main.ahk" or the executable of bug.n is saved). If Not Config_filePath ; The file path, to which the configuration and session is saved. This target directory must be writable by the user (%A_ScriptDir% is the diretory, in which "Main.ahk" or the executable of bug.n is saved).
Config_filePath := A_ScriptDir "\Config.ini" Config_filePath := A_ScriptDir "\Config.ini"

View File

@ -62,8 +62,9 @@ Return ;; end of the auto-execute section
;; Function & label definitions ;; Function & label definitions
Main_cleanup: Main_cleanup:
Debug_logMessage("====== Cleaning up ======", 0) Debug_logMessage("====== Cleaning up ======", 0)
If Config_autoSaveSession ;; Config_autoSaveSession as False is deprecated.
Config_saveSession(Config_filePath, Config_filePath) If Not (Config_autoSaveSession = "off") And Not (Config_autoSaveSession = "False")
Manager_saveState()
Manager_cleanup() Manager_cleanup()
ResourceMonitor_cleanup() ResourceMonitor_cleanup()
Debug_logMessage("====== Exiting bug.n ======", 0) Debug_logMessage("====== Exiting bug.n ======", 0)

View File

@ -20,7 +20,7 @@
Manager_init() Manager_init()
{ {
Global Local doRestore
Manager_setWindowBorder() Manager_setWindowBorder()
Bar_getHeight() Bar_getHeight()
@ -31,10 +31,23 @@ Manager_init()
Manager_aMonitor := 1 Manager_aMonitor := 1
Manager_taskBarMonitor := "" Manager_taskBarMonitor := ""
Manager_showTaskBar := True Manager_showTaskBar := True
doRestore := 0
If (Config_autoSaveSession = "ask")
{
MsgBox, 0x4, , Would you like to restore an auto-saved session?
IfMsgBox Yes
doRestore := 1
}
Else If (Config_autoSaveSession = "auto")
{
doRestore := 1
}
SysGet, Manager_monitorCount, MonitorCount SysGet, Manager_monitorCount, MonitorCount
Loop, % Manager_monitorCount Loop, % Manager_monitorCount
{ {
Monitor_init(A_Index) Monitor_init(A_Index, doRestore)
} }
Bar_initCmdGui() Bar_initCmdGui()
If Not Config_showTaskBar If Not Config_showTaskBar
@ -45,7 +58,7 @@ Manager_init()
Bar_hideTitleWndIds := "" Bar_hideTitleWndIds := ""
Manager_allWndIds := "" Manager_allWndIds := ""
Manager_managedWndIds := "" Manager_managedWndIds := ""
Manager_initial_sync() Manager_initial_sync(doRestore)
Bar_updateStatus() Bar_updateStatus()
Bar_updateTitle() Bar_updateTitle()
@ -70,27 +83,43 @@ Manager_maintenance_label:
Manager_maintenance() Manager_maintenance()
Return Return
Manager_maintenance() { Manager_saveState()
Local tmp {
;Debug_logMessage("Manager_maintenance", 2) Global
Critical
;Debug_logMessage("Manager_saveState", 0)
; @todo: Check for changes to the layout. ; @todo: Check for changes to the layout.
;If Manager_layoutDirty { ;If Manager_layoutDirty
;{
;Debug_logMessage("Saving layout state: " . Main_autoLayout, 0) ;Debug_logMessage("Saving layout state: " . Main_autoLayout, 0)
Config_saveSession(Config_filaPath, Main_autoLayout) Config_saveSession(Config_filaPath, Main_autoLayout)
Manager_layoutDirty := 0 Manager_layoutDirty := 0
;} ;}
; @todo: Manager_sync?
; @todo: Check for changes to windows. ; @todo: Check for changes to windows.
;If Manager_windowsDirty { ;If Manager_windowsDirty
;{
;Debug_logMessage("Saving window state: " . Main_autoWindowState, 0) ;Debug_logMessage("Saving window state: " . Main_autoWindowState, 0)
Manager_saveWindowState(Main_autoWindowState, Manager_monitorCount, Config_viewCount) Manager_saveWindowState(Main_autoWindowState, Manager_monitorCount, Config_viewCount)
Manager_windowsDirty := 0 Manager_windowsDirty := 0
;} ;}
} }
Manager_maintenance()
{
Local tmp
Critical
;Debug_logMessage("Manager_maintenance", 0)
; @todo: Manager_sync?
Manager__displaySync()
If Not (Config_autoSaveSession = "off") And Not (Config_autoSaveSession = "False")
Manager_saveState()
}
Manager_activateMonitor(d) Manager_activateMonitor(d)
{ {
Local aView, aWndHeight, aWndId, aWndWidth, aWndX, aWndY, v, wndId Local aView, aWndHeight, aWndId, aWndWidth, aWndX, aWndY, v, wndId
@ -1055,7 +1084,7 @@ Manager__restoreWindowState(filename)
; No windows are known to the system yet. ; No windows are known to the system yet.
; Try to do something smart with the initial layout. ; Try to do something smart with the initial layout.
Manager_initial_sync() Manager_initial_sync(doRestore)
{ {
Local wndId0, wnd, wndX, wndY, wndW, wndH, x, y, m, len Local wndId0, wnd, wndX, wndY, wndW, wndH, x, y, m, len
@ -1068,7 +1097,10 @@ Manager_initial_sync()
;; Use saved window placement settings to first determine ;; Use saved window placement settings to first determine
;; which monitor/view a window should be attached to. ;; which monitor/view a window should be attached to.
Manager__restoreWindowState(Main_autoWindowState) If doRestore
{
Manager__restoreWindowState(Main_autoWindowState)
}
;; Check all remaining visible windows against the known windows ;; Check all remaining visible windows against the known windows
WinGet, wndId, List, , , WinGet, wndId, List, , ,

View File

@ -18,7 +18,7 @@
@version 8.3.0 @version 8.3.0
*/ */
Monitor_init(m) Monitor_init(m, doRestore)
{ {
Global Global
@ -29,7 +29,10 @@ Monitor_init(m)
{ {
View_init(m, A_Index) View_init(m, A_Index)
} }
Config_restoreLayout(Main_autoLayout, m) If doRestore
Config_restoreLayout(Main_autoLayout, m)
Else
Config_restoreLayout(Config_filePath, m)
Monitor_getWorkArea(m) Monitor_getWorkArea(m)
Bar_init(m) Bar_init(m)
} }