[meld] Correctly handle Save/Save As action sensitivity (closes bgo#456704)



commit 2d5b2215b1ce4d29677e94d7c9d64ed93058c8e0
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Mar 30 09:01:09 2013 +1000

    Correctly handle Save/Save As action sensitivity (closes bgo#456704)

 meld/filediff.py   |   12 ++++++++++++
 meld/meldwindow.py |    7 +++++++
 2 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index b12d04f..aa23baa 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -246,6 +246,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.actiongroup.set_translation_domain("meld")
         self.actiongroup.add_actions(actions)
         self.actiongroup.add_toggle_actions(toggle_actions)
+        self.main_actiongroup = None
+
         self.findbar = findbar.FindBar(self.table)
 
         self.widget.ensure_style()
@@ -315,6 +317,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.keymask = 0
 
     def on_container_switch_in_event(self, ui):
+        self.main_actiongroup = [a for a in ui.get_action_groups()
+                                 if a.get_name() == "MainActions"][0]
         melddoc.MeldDoc.on_container_switch_in_event(self, ui)
         # FIXME: If no focussed textview, action sensitivity will be unset
 
@@ -658,6 +662,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.focus_pane = view
         self.findbar.textview = view
         self.on_cursor_position_changed(view.get_buffer(), None, True)
+        self._set_save_action_sensitivity()
         self._set_merge_action_sensitivity()
 
     def on_textview_focus_out_event(self, view, event):
@@ -943,7 +948,14 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         self.fileentry[1].set_filename(os.path.abspath(filename))
         self.recompute_label()
 
+    def _set_save_action_sensitivity(self):
+        pane = self._get_focused_pane()
+        modified = False if pane == -1 else self.textbuffer[pane].data.modified
+        if self.main_actiongroup:
+            self.main_actiongroup.get_action("Save").set_sensitive(modified)
+
     def recompute_label(self):
+        self._set_save_action_sensitivity()
         filenames = []
         for i in range(self.num_panes):
             filenames.append(self.textbuffer[i].data.label)
diff --git a/meld/meldwindow.py b/meld/meldwindow.py
index f6bf479..adc530e 100644
--- a/meld/meldwindow.py
+++ b/meld/meldwindow.py
@@ -293,6 +293,13 @@ class MeldWindow(gnomeglade.Component):
         self.actiongroup.get_action("Undo").set_sensitive(can_undo)
         self.actiongroup.get_action("Redo").set_sensitive(can_redo)
 
+        # FileDiff handles save sensitivity; it makes no sense for other modes
+        if not isinstance(newdoc, filediff.FileDiff):
+            self.actiongroup.get_action("Save").set_sensitive(False)
+            self.actiongroup.get_action("SaveAs").set_sensitive(False)
+        else:
+            self.actiongroup.get_action("SaveAs").set_sensitive(True)
+
         nbl = self.notebook.get_tab_label(newdoc.widget)
         self.widget.set_title(nbl.get_label_text() + " - Meld")
         try:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]