[PATCH 4/7] Update handling of tab labels and tooltips



Previously there were some shortcomings of the dirdiff and filediff tabs:
- When comparing a version-controlled file, the tab contents would say
  "fileA:fileA".  Showing fileA two times is misleading, since you're
  really diffing fileA vs the version control repository, not another
  file called fileA.
- Frequently the tab labels contents would be hard to read and comprehend
  when the contents of the tab were greater than the tab width, eg
  "[tmpL2lz5m-meld...notebooklabel.py]" for a meld diff of meld's
  meld/ui/notebooklabel.py
- The tab tooltips were sometimes not very useful.  For example,
  when using meld to view a change to meld/ui/notebooklabel.py the
  tooltip will say something like
  "[tmp6GD0ec-meld] notebooklabel.py : [meld] notebooklabel.py".
  The output is somewhat confusing as Joe User wouldn't be
  aware of where the [tmp6GD0ec-meld] and [meld] prefixes came
  from.

In an attempt to improve the tab labels and tooltips, this change does
the following:
- If the all the filenames that are being diffed are the same,
  just title the label "fileA", instead of "fileA:fileA"
- Don't put the non-common directory suffixes in brackets
- In a file diff tooltip, show the full path of the files in the form:
    FileA: /tmp/tmp-6GD0ec-meld/meld/ui/notebooklabel.py
    FileB: /home/ptyser/meld.devel/meld/ui/notebooklabel.py
- In a directory diff tooltip, show the full path of the directories
  in the form:
    DirA: /home/ptyser/meld.devel/meld/ui/notebooklabel.py
    DirB: /home/ptyser/meld.stock/meld/ui/notebooklabel.py

Signed-off-by: Peter Tyser <ptyser gmail com>
---
 meld/dirdiff.py  |   12 +++++++++---
 meld/filediff.py |   24 +++++++++++++++++++-----
 meld/misc.py     |   26 --------------------------
 3 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/meld/dirdiff.py b/meld/dirdiff.py
index bf96e09..cb51a87 100644
--- a/meld/dirdiff.py
+++ b/meld/dirdiff.py
@@ -879,9 +879,15 @@ class DirDiff(melddoc.MeldDoc, gnomeglade.Component):
     def recompute_label(self):
         root = self.model.get_iter_root()
         filenames = self.model.value_paths(root)
-        shortnames = misc.shorten_names(*filenames)
-        self.label_text = " : ".join(shortnames)
-        self.tooltip_text = self.label_text
+        self.label_text = os.path.basename(filenames[0])
+
+        # List the directories we are comparing in the tooltip
+        self.tooltip_text = ""
+        for i in range(len(filenames)):
+            # TRANSLATORS: "Dir" == a directory that is being diffed
+            self.tooltip_text += _("Dir %s: %s\n") % (chr(ord('A') + i), filenames[i])
+        self.tooltip_text = self.tooltip_text.rstrip('\n')
+
         self.label_changed()
 
     def _update_diffmaps(self):
diff --git a/meld/filediff.py b/meld/filediff.py
index 8470fdc..0e6a207 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -659,13 +659,18 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
 
     def recompute_label(self):
         filenames = []
+
+        # Monitor if any files have been modified so we can update the label
+        # text later
+        modified = False
+
         for i in range(self.num_panes):
-            filenames.append( self._get_pane_label(i) )
-        shortnames = misc.shorten_names(*filenames)
+            filenames.append(self._get_pane_label(i))
+        self.label_text = os.path.basename(filenames[0])
         for i in range(self.num_panes):
             stock = None
             if self.bufferdata[i].modified == 1:
-                shortnames[i] += "*"
+                modified = True
                 if self.bufferdata[i].writable == 1:
                     stock = gtk.STOCK_SAVE
                 else:
@@ -678,8 +683,17 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
                 self.statusimage[i].set_size_request(self.diffmap[0].size_request()[0],-1)
             else:
                 self.statusimage[i].hide()
-        self.label_text = " : ".join(shortnames)
-        self.tooltip_text = self.label_text
+
+        if modified:
+            self.label_text += "*"
+
+        # List the files we are comparing in the tooltip
+        self.tooltip_text = ""
+        for i in range(len(filenames)):
+            # TRANSLATORS: "File" == a file name that is being diffed
+            self.tooltip_text += _("File %s: %s\n") % (chr(ord('A') + i), filenames[i])
+        self.tooltip_text = self.tooltip_text.rstrip('\n')
+
         self.label_changed()
 
     def set_files(self, files):
diff --git a/meld/misc.py b/meld/misc.py
index 2139452..99464e4 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -162,32 +162,6 @@ def all_equal(alist):
                 return 0
     return 1
     
-def shorten_names(*names):
-    """Remove redunant parts of a list of names (e.g. /tmp/foo{1,2} -> foo{1,2}
-    """
-    prefix = os.path.commonprefix( names )
-    prefixslash = prefix.rfind("/") + 1
-    
-    names = map(lambda x: x[prefixslash:], names) # remove common prefix
-    paths = map(lambda x: x.split("/"), names) # split on /
-
-    try:
-        basenames = map(lambda x: x[-1], paths)
-    except IndexError:
-        pass
-    else:
-        if all_equal(basenames):
-            def firstpart(alist):
-                if len(alist) > 1:
-                    return "[%s] " % alist[0]
-                else:
-                    return ""
-            roots = map(firstpart, paths)
-            base = basenames[0].strip()
-            return [ r+base for r in roots ]
-    # no common path. empty names get changed to "[None]"
-    return map(lambda x: x or _("[None]"), basenames)
-
 def read_pipe_iter(command, errorstream, yield_interval=0.1, workdir=None):
     """Read the output of a shell command iteratively.
 
-- 
1.7.1.13.gcfb88



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