[meld] filediff: Add a toolbar to each pane, adapting controls and styling



commit 20d1f5abc262c02ff194a433a998c9274fa92308
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jan 26 08:08:38 2014 +1000

    filediff: Add a toolbar to each pane, adapting controls and styling
    
    This commit also adds a save button to each pane for a more obvious way
    of saving individual files that isn't based on current pane focus.

 data/meld.css       |   12 +++
 data/ui/filediff.ui |  248 +++++++++++++++++++++++++++++----------------------
 meld/filediff.py    |   52 ++++++-----
 3 files changed, 182 insertions(+), 130 deletions(-)
---
diff --git a/data/meld.css b/data/meld.css
index 61ed386..871b1e3 100644
--- a/data/meld.css
+++ b/data/meld.css
@@ -19,3 +19,15 @@
 @define-color current-line-highlight #ffff00;
 @define-color syncpoint-outline #555555;
 @define-color current-chunk-highlight #ffffff;
+
+.meld-notebook-toolbar.toolbar {
+       background-image: none;
+    background-color: @theme_base_color;
+    border-width: 0 0 1px 0;
+    border-style: solid;
+    border-color: @borders;
+
+    -GtkToolbar-button-relief: normal;
+    box-shadow: inset 0 3px alpha(black, 0.02), inset 0 2px alpha(black, 0.02), inset 0 1px alpha(black, 
0.02);
+    padding: 2px;
+}
diff --git a/data/ui/filediff.ui b/data/ui/filediff.ui
index d202074..4805686 100644
--- a/data/ui/filediff.ui
+++ b/data/ui/filediff.ui
@@ -114,6 +114,8 @@
           <object class="GtkGrid" id="grid">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="margin_top">0</property>
+            <property name="row_spacing">0</property>
             <child>
               <placeholder/>
             </child>
@@ -136,41 +138,46 @@
               <placeholder/>
             </child>
             <child>
-              <object class="GtkHBox" id="selector_hbox2">
+              <object class="GtkToolbar" id="file_toolbar2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="show-arrow">False</property>
+                <property name="icon-size">1</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
                 <child>
-                  <object class="GtkToggleButton" id="readonlytoggle2">
+                  <object class="GtkToggleToolButton" id="readonlytoggle2">
                     <property name="can_focus">False</property>
                     <property name="receives_default">False</property>
                     <property name="tooltip_text" translatable="yes">This file can not be written to. You 
may click here to unlock this file and make changes anyway, but these changes must be saved to a new 
file.</property>
-                    <property name="relief">none</property>
+                    <property name="icon_name">emblem-readonly</property>
                     <signal name="toggled" handler="on_readonly_button_toggled" swapped="no"/>
-                    <child>
-                      <object class="GtkImage" id="readonly_image2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="icon_name">emblem-readonly</property>
-                      </object>
-                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
                 </child>
                 <child>
-                  <object class="GtkFileChooserButton" id="fileentry2">
+                  <object class="GtkToolButton" id="file_save_button2">
+                    <property name="stock-id">gtk-save</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <signal name="clicked" handler="on_file_save_button_clicked" swapped="no"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkToolItem" id="fileentry_toolitem2">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
+                    <property name="receives_default">False</property>
+                    <child>
+                      <object class="GtkFileChooserButton" id="fileentry2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
+                      </object>
+                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
               <packing>
@@ -180,41 +187,46 @@
               </packing>
             </child>
             <child>
-              <object class="GtkHBox" id="selector_hbox1">
+              <object class="GtkToolbar" id="file_toolbar1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="show-arrow">False</property>
+                <property name="icon-size">1</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
                 <child>
-                  <object class="GtkToggleButton" id="readonlytoggle1">
+                  <object class="GtkToggleToolButton" id="readonlytoggle1">
                     <property name="can_focus">False</property>
                     <property name="receives_default">False</property>
                     <property name="tooltip_text" translatable="yes">This file can not be written to. You 
may click here to unlock this file and make changes anyway, but these changes must be saved to a new 
file.</property>
-                    <property name="relief">none</property>
+                    <property name="icon_name">emblem-readonly</property>
                     <signal name="toggled" handler="on_readonly_button_toggled" swapped="no"/>
-                    <child>
-                      <object class="GtkImage" id="readonly_image1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="icon_name">emblem-readonly</property>
-                      </object>
-                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
                 </child>
                 <child>
-                  <object class="GtkFileChooserButton" id="fileentry1">
+                  <object class="GtkToolButton" id="file_save_button1">
+                    <property name="stock-id">gtk-save</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <signal name="clicked" handler="on_file_save_button_clicked" swapped="no"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkToolItem" id="fileentry_toolitem1">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
+                    <property name="receives_default">False</property>
+                    <child>
+                      <object class="GtkFileChooserButton" id="fileentry1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
+                      </object>
+                    </child>
                   </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
               <packing>
@@ -224,41 +236,46 @@
               </packing>
             </child>
             <child>
-              <object class="GtkHBox" id="selector_hbox0">
+              <object class="GtkToolbar" id="file_toolbar0">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="show-arrow">False</property>
+                <property name="icon-size">1</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
                 <child>
-                  <object class="GtkToggleButton" id="readonlytoggle0">
+                  <object class="GtkToggleToolButton" id="readonlytoggle0">
                     <property name="can_focus">False</property>
                     <property name="receives_default">False</property>
                     <property name="tooltip_text" translatable="yes">This file can not be written to. You 
may click here to unlock this file and make changes anyway, but these changes must be saved to a new 
file.</property>
-                    <property name="relief">none</property>
+                    <property name="icon_name">emblem-readonly</property>
                     <signal name="toggled" handler="on_readonly_button_toggled" swapped="no"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkToolButton" id="file_save_button0">
+                    <property name="stock-id">gtk-save</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="use_underline">True</property>
+                    <signal name="clicked" handler="on_file_save_button_clicked" swapped="no"/>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkToolItem" id="fileentry_toolitem0">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="receives_default">False</property>
                     <child>
-                      <object class="GtkImage" id="readonly_image0">
+                      <object class="GtkFileChooserButton" id="fileentry0">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="icon_name">emblem-readonly</property>
+                        <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
                       </object>
                     </child>
                   </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkFileChooserButton" id="fileentry0">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <signal name="file-set" handler="on_fileentry_file_set" swapped="no"/>
-                  </object>
-                  <packing>
-                    <property name="expand">True</property>
-                    <property name="fill">True</property>
-                    <property name="position">1</property>
-                  </packing>
                 </child>
               </object>
               <packing>
@@ -319,45 +336,6 @@
               </packing>
             </child>
             <child>
-              <object class="GtkImage" id="statusimage2">
-                <property name="width_request">20</property>
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">1</property>
-                <property name="stock">gtk-missing-image</property>
-              </object>
-              <packing>
-                <property name="left_attach">4</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="statusimage1">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">1</property>
-                <property name="stock">gtk-missing-image</property>
-              </object>
-              <packing>
-                <property name="left_attach">2</property>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkImage" id="statusimage0">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">1</property>
-                <property name="stock">gtk-missing-image</property>
-              </object>
-              <packing>
-                <property name="width">1</property>
-                <property name="height">1</property>
-              </packing>
-            </child>
-            <child>
               <object class="GtkVBox" id="vbox2">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -456,6 +434,21 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToolbar" id="dummy_toolbar_diffmap1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">6</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="DiffMap" id="diffmap1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -468,6 +461,21 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToolbar" id="dummy_toolbar_linkmap0">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="LinkMap" id="linkmap0">
                 <property name="width_request">50</property>
                 <property name="visible">True</property>
@@ -482,6 +490,21 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToolbar" id="dummy_toolbar_diffmap0">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">0</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="DiffMap" id="diffmap0">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -494,6 +517,21 @@
               </packing>
             </child>
             <child>
+              <object class="GtkToolbar" id="dummy_toolbar_linkmap1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <style>
+                  <class name="meld-notebook-toolbar"/>
+                </style>
+              </object>
+              <packing>
+                <property name="left_attach">4</property>
+                <property name="top_attach">0</property>
+                <property name="width">1</property>
+                <property name="height">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="LinkMap" id="linkmap1">
                 <property name="width_request">50</property>
                 <property name="visible">True</property>
diff --git a/meld/filediff.py b/meld/filediff.py
index 086e833..61881ec 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1,3 +1,5 @@
+# coding=UTF-8
+
 # Copyright (C) 2002-2006 Stephen Kennedy <stevek gnome org>
 # Copyright (C) 2009-2013 Kai Willadsen <kai willadsen gmail com>
 #
@@ -169,8 +171,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
         gnomeglade.Component.__init__(self, "filediff.ui", "filediff")
         self.map_widgets_into_lists(["textview", "fileentry", "diffmap",
                                      "scrolledwindow", "linkmap",
-                                     "statusimage", "msgarea_mgr", "vbox",
-                                     "selector_hbox", "readonlytoggle"])
+                                     "msgarea_mgr", "vbox",
+                                     "selector_hbox", "readonlytoggle",
+                                     "file_toolbar", "file_save_button",
+                                     "fileentry_toolitem"])
 
         # This SizeGroup isn't actually necessary for FileDiff; it's for
         # handling non-homogenous selectors in FileComp. It's also fragile.
@@ -223,6 +227,9 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             buf.connect("notify::has-selection",
                         self.update_text_actions_sensitivity)
 
+        for toolitem in self.fileentry_toolitem:
+            toolitem.set_expand(True)
+
         actions = (
             ("MakePatch", None, _("Format as Patch..."), None,
                 _("Create a patch using differences between files"),
@@ -1042,26 +1049,17 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def recompute_label(self):
         self._set_save_action_sensitivity()
-        filenames = []
-        for i in range(self.num_panes):
-            filenames.append(self.textbuffer[i].data.label)
+        filenames = [b.data.label for b in self.textbuffer[:self.num_panes]]
         shortnames = misc.shorten_names(*filenames)
-        for i in range(self.num_panes):
-            stock = None
-            if self.textbuffer[i].data.modified:
+
+        for i, buf in enumerate(self.textbuffer[:self.num_panes]):
+            if buf.data.modified:
                 shortnames[i] += "*"
-                if self.textbuffer[i].data.writable:
-                    stock = Gtk.STOCK_SAVE
-                else:
-                    stock = Gtk.STOCK_SAVE_AS
-            if stock:
-                self.statusimage[i].show()
-                self.statusimage[i].set_from_stock(stock, Gtk.IconSize.MENU)
-                width = self.diffmap[0].size_request().width
-                self.statusimage[i].set_size_request(width, -1)
-            else:
-                self.statusimage[i].hide()
-        self.label_text = " : ".join(shortnames)
+            self.file_save_button[i].set_sensitive(buf.data.modified)
+            self.file_save_button[i].props.stock_id = (
+                Gtk.STOCK_SAVE if buf.data.writable else Gtk.STOCK_SAVE_AS)
+
+        self.label_text = (" — ").decode('utf8').join(shortnames)
         self.tooltip_text = self.label_text
         self.label_changed()
 
@@ -1717,6 +1715,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             if self.textbuffer[i].data.modified:
                 self.save_file(i)
 
+    def on_file_save_button_clicked(self, button):
+        idx = self.file_save_button.index(button)
+        self.save_file(idx)
+
     def on_fileentry_file_set(self, entry):
         if self.check_save_modified() != Gtk.ResponseType.CANCEL:
             entries = self.fileentry[:self.num_panes]
@@ -1846,14 +1848,14 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
             toshow =  self.scrolledwindow[:n] + self.fileentry[:n]
             toshow += self.vbox[:n] + self.msgarea_mgr[:n]
             toshow += self.linkmap[:n-1] + self.diffmap[:n]
-            toshow += self.selector_hbox[:n]
+            toshow += self.selector_hbox[:n] + self.file_toolbar[:n]
             for widget in toshow:
                 widget.show()
 
-            tohide =  self.statusimage + self.scrolledwindow[n:] + self.fileentry[n:]
+            tohide = self.scrolledwindow[n:] + self.fileentry[n:]
             tohide += self.vbox[n:] + self.msgarea_mgr[n:]
             tohide += self.linkmap[n-1:] + self.diffmap[n:]
-            tohide += self.selector_hbox[n:]
+            tohide += self.selector_hbox[n:] + self.file_toolbar[n:]
             for widget in tohide:
                 widget.hide()
 
@@ -1886,8 +1888,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                 w.associate(self, self.textview[i], self.textview[i + 1])
 
             for i in range(self.num_panes):
-                if self.textbuffer[i].data.modified:
-                    self.statusimage[i].show()
+                self.file_save_button[i].set_sensitive(
+                    self.textbuffer[i].data.modified)
             self.queue_draw()
             self.recompute_label()
 


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