[bug 802] - Ability to undo or restore changes to the preferences #802
- added basic config restore option from preferences window - changes to glade made in addition to addition of destory signal - minor cleaup in config to have a single function return confilg filename via get_config_filename
This commit is contained in:
parent
a6a0eca553
commit
2fe3ad8b08
|
@ -622,12 +622,7 @@ class ConfigBase(Borg):
|
||||||
dbg('config already loaded')
|
dbg('config already loaded')
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.command_line_options and self.command_line_options.config:
|
filename = self.get_config_filename()
|
||||||
filename = self.command_line_options.config
|
|
||||||
else:
|
|
||||||
filename = os.path.join(get_config_dir(), 'config')
|
|
||||||
if not os.path.exists(filename):
|
|
||||||
filename = os.path.join(get_system_config_dir(), 'config')
|
|
||||||
dbg('looking for config file: %s' % filename)
|
dbg('looking for config file: %s' % filename)
|
||||||
try:
|
try:
|
||||||
#
|
#
|
||||||
|
@ -706,6 +701,35 @@ class ConfigBase(Borg):
|
||||||
|
|
||||||
self.loaded = True
|
self.loaded = True
|
||||||
|
|
||||||
|
def get_config_filename(self):
|
||||||
|
filename = ''
|
||||||
|
if self.command_line_options and self.command_line_options.config:
|
||||||
|
filename = self.command_line_options.config
|
||||||
|
else:
|
||||||
|
filename = os.path.join(get_config_dir(), 'config')
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
filename = os.path.join(get_system_config_dir(), 'config')
|
||||||
|
|
||||||
|
return filename
|
||||||
|
|
||||||
|
def save_config_with_suffix(self, suffix):
|
||||||
|
filename = self.get_config_filename()
|
||||||
|
#save the current config, to revert any changes make in preferences
|
||||||
|
cur_loaded_file = filename + suffix
|
||||||
|
shutil.copy2(filename, cur_loaded_file)
|
||||||
|
|
||||||
|
def restore_config_with_suffix(self, suffix):
|
||||||
|
filename = self.get_config_filename()
|
||||||
|
cur_loaded_file = filename + suffix
|
||||||
|
dbg("restoring from file:%s to file:%s" % (cur_loaded_file, filename))
|
||||||
|
shutil.copy2(cur_loaded_file, filename)
|
||||||
|
|
||||||
|
def remove_config_with_suffix(self, suffix):
|
||||||
|
filename = self.get_config_filename()
|
||||||
|
cur_loaded_file = filename + suffix
|
||||||
|
if os.path.exists(cur_loaded_file):
|
||||||
|
os.remove(cur_loaded_file)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""Force a reload of the base config"""
|
"""Force a reload of the base config"""
|
||||||
self.loaded = False
|
self.loaded = False
|
||||||
|
|
|
@ -424,6 +424,7 @@
|
||||||
<property name="title" translatable="yes">Terminator Preferences</property>
|
<property name="title" translatable="yes">Terminator Preferences</property>
|
||||||
<property name="default-width">640</property>
|
<property name="default-width">640</property>
|
||||||
<property name="default-height">400</property>
|
<property name="default-height">400</property>
|
||||||
|
<signal name="destroy" handler="on_destroy_event" swapped="no"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="dialog_vbox1">
|
<object class="GtkBox" id="dialog_vbox1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -1241,7 +1242,7 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<!-- n-columns=2 n-rows=4 -->
|
<!-- n-columns=2 n-rows=5 -->
|
||||||
<object class="GtkGrid" id="grid4">
|
<object class="GtkGrid" id="grid4">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
|
@ -4410,6 +4411,21 @@ Much of the behavior of Terminator is based on GNOME Terminal, and we are adding
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="restoreconfigbutton">
|
||||||
|
<property name="label">Discard Changes</property>
|
||||||
|
<property name="use-action-appearance">False</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="receives-default">True</property>
|
||||||
|
<signal name="clicked" handler="on_restoreconfigbutton_clicked" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="okbutton">
|
<object class="GtkButton" id="okbutton">
|
||||||
<property name="label">gtk-close</property>
|
<property name="label">gtk-close</property>
|
||||||
|
@ -4423,7 +4439,7 @@ Much of the behavior of Terminator is based on GNOME Terminal, and we are adding
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -235,14 +235,25 @@ class PrefsEditor:
|
||||||
nb = guiget('notebook1')
|
nb = guiget('notebook1')
|
||||||
nb.set_current_page(cur_page)
|
nb.set_current_page(cur_page)
|
||||||
|
|
||||||
|
self.config.base.save_config_with_suffix('_cur')
|
||||||
|
|
||||||
|
def on_destroy_event(self, _widget):
|
||||||
|
self.config.base.remove_config_with_suffix('_cur')
|
||||||
|
|
||||||
def on_closebutton_clicked(self, _button):
|
def on_closebutton_clicked(self, _button):
|
||||||
"""Close the window"""
|
"""Close the window"""
|
||||||
|
self.config.base.remove_config_with_suffix('_cur')
|
||||||
terminator = Terminator()
|
terminator = Terminator()
|
||||||
terminator.reconfigure()
|
terminator.reconfigure()
|
||||||
self.window.destroy()
|
self.window.destroy()
|
||||||
self.calling_window.preventHide = False
|
self.calling_window.preventHide = False
|
||||||
del(self)
|
del(self)
|
||||||
|
|
||||||
|
def on_restoreconfigbutton_clicked(self, _button):
|
||||||
|
"""restore config to load time"""
|
||||||
|
self.config.base.restore_config_with_suffix('_cur')
|
||||||
|
self.on_closebutton_clicked(_button)
|
||||||
|
|
||||||
def set_values(self):
|
def set_values(self):
|
||||||
"""Update the preferences window with all the configuration from
|
"""Update the preferences window with all the configuration from
|
||||||
Config()"""
|
Config()"""
|
||||||
|
|
Loading…
Reference in New Issue