1 # Copyright (c) 2008 David Aguilar
2 """This handles saving complex settings such as bookmarks, etc.
8 from cola
.models
.observable
import ObservableModel
10 class SettingsModel(ObservableModel
):
12 """Load existing settings if they exist"""
13 ObservableModel
.__init
__(self
)
19 """Path to the model's on-disk representation"""
20 return os
.path
.join(user
.home
, '.cola')
23 """Loads settings if they exist"""
24 settings
= self
.path()
25 if os
.path
.exists(settings
):
26 ObservableModel
.load(self
, settings
)
29 """Saves settings to the .cola file"""
30 # Call the base method
31 ObservableModel
.save(self
, self
.path())
33 def add_bookmark(self
, bookmark
):
34 """Adds a bookmark to the saved settings"""
35 if bookmark
not in self
.bookmarks
:
36 self
.bookmarks
.append(bookmark
)
38 def remove_bookmark(self
, bookmark
):
39 """Removes a bookmark from the saved settings"""
40 if bookmark
in self
.bookmarks
:
41 self
.bookmarks
.remove(bookmark
)
43 class SettingsManager(object):
44 """Manages a SettingsModel singleton
46 _settings
= SettingsModel()
50 """Returns the SettingsModel singleton"""
51 return SettingsManager
._settings
54 def save_gui_state(gui
):
55 """Saves settings for a cola view"""
57 state
= gui
.export_state()
58 model
= SettingsManager
.settings()
59 model
.gui_state
[name
] = state
64 """Returns the state for a gui"""
65 return SettingsManager
.settings().gui_state
.get(gui
.name(), {})