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.
;; Configuration management
Config_autoSaveSession := False
Config_autoSaveSession := "auto" ;; "off" | "auto" | "ask"
; @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).
Config_filePath := A_ScriptDir "\Config.ini"

View File

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

View File

@ -20,7 +20,7 @@
Manager_init()
{
Global
Local doRestore
Manager_setWindowBorder()
Bar_getHeight()
@ -31,10 +31,23 @@ Manager_init()
Manager_aMonitor := 1
Manager_taskBarMonitor := ""
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
Loop, % Manager_monitorCount
{
Monitor_init(A_Index)
Monitor_init(A_Index, doRestore)
}
Bar_initCmdGui()
If Not Config_showTaskBar
@ -45,7 +58,7 @@ Manager_init()
Bar_hideTitleWndIds := ""
Manager_allWndIds := ""
Manager_managedWndIds := ""
Manager_initial_sync()
Manager_initial_sync(doRestore)
Bar_updateStatus()
Bar_updateTitle()
@ -70,27 +83,43 @@ Manager_maintenance_label:
Manager_maintenance()
Return
Manager_maintenance() {
Local tmp
;Debug_logMessage("Manager_maintenance", 2)
Manager_saveState()
{
Global
Critical
;Debug_logMessage("Manager_saveState", 0)
; @todo: Check for changes to the layout.
;If Manager_layoutDirty {
;If Manager_layoutDirty
;{
;Debug_logMessage("Saving layout state: " . Main_autoLayout, 0)
Config_saveSession(Config_filaPath, Main_autoLayout)
Manager_layoutDirty := 0
;}
; @todo: Manager_sync?
; @todo: Check for changes to windows.
;If Manager_windowsDirty {
;If Manager_windowsDirty
;{
;Debug_logMessage("Saving window state: " . Main_autoWindowState, 0)
Manager_saveWindowState(Main_autoWindowState, Manager_monitorCount, Config_viewCount)
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)
{
Local aView, aWndHeight, aWndId, aWndWidth, aWndX, aWndY, v, wndId
@ -1055,7 +1084,7 @@ Manager__restoreWindowState(filename)
; No windows are known to the system yet.
; 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
@ -1068,7 +1097,10 @@ Manager_initial_sync()
;; Use saved window placement settings to first determine
;; 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
WinGet, wndId, List, , ,

View File

@ -18,7 +18,7 @@
@version 8.3.0
*/
Monitor_init(m)
Monitor_init(m, doRestore)
{
Global
@ -29,7 +29,10 @@ Monitor_init(m)
{
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)
Bar_init(m)
}