Commit f41a99c5 authored by Stephen Kennedy's avatar Stephen Kennedy

Add cli option to set labels Bug 138860

parent c7a2a541
......@@ -362,8 +362,8 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
state = [b.modified for b in self.bufferdata]
return 1 in state
def _get_filename(self, i):
return self.bufferdata[i].filename or "<unnamed>"
def _get_pane_label(self, i):
return self.bufferdata[i].label or "<unnamed>"
def on_delete_event(self, appquit=0):
modified = [b.modified for b in self.bufferdata]
......@@ -372,7 +372,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
dialog.widget.set_transient_for(self.widget.get_toplevel())
buttons = []
for i in range(self.num_panes):
b = gtk.CheckButton( self._get_filename(i) )
b = gtk.CheckButton( self._get_pane_label(i) )
b.set_use_underline(False)
buttons.append(b)
dialog.box.pack_start(b, 1, 1)
......@@ -540,10 +540,15 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
# text buffer loading/saving
#
def set_labels(self, lst):
assert len(lst) <= len(self.bufferdata)
for l,d in zip(lst,self.bufferdata):
if len(l): d.label = l
def recompute_label(self):
filenames = []
for i in range(self.num_panes):
filenames.append( self._get_filename(i) )
filenames.append( self._get_pane_label(i) )
shortnames = misc.shorten_names(*filenames)
for i in range(self.num_panes):
stock = None
......@@ -573,7 +578,10 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
b.delete( b.get_start_iter(), b.get_end_iter() )
absfile = os.path.abspath(f)
self.fileentry[i].set_filename(absfile)
self.bufferdata[i] = MeldBufferData(absfile)
bold, bnew = self.bufferdata[i], MeldBufferData(absfile)
if bold.filename == bnew.filename:
bnew.label = bold.label
self.bufferdata[i] = bnew
self.recompute_label()
self.scheduler.add_task( self._set_files_internal(files).next )
......@@ -790,7 +798,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
if saveas or not bufdata.filename:
filename = self._get_filename_for_saving( _("Choose a name for buffer %i.") % (pane+1) )
if filename:
bufdata.filename = os.path.abspath(filename)
bufdata.filename = bufdata.label = os.path.abspath(filename)
self.fileentry[pane].set_filename( bufdata.filename)
else:
return melddoc.RESULT_ERROR
......@@ -801,7 +809,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
text = text.replace("\n", bufdata.newlines)
elif type(bufdata.newlines) == type(()):
buttons = {'\n':("UNIX (LF)",0), '\r\n':("DOS (CR-LF)", 1), '\r':("MAC (CR)",2) }
newline = misc.run_dialog( _("This file '%s' contains a mixture of line endings.\n\nWhich format would you like to use?") % bufdata.filename,
newline = misc.run_dialog( _("This file '%s' contains a mixture of line endings.\n\nWhich format would you like to use?") % bufdata.label,
self, gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_CANCEL,
extrabuttons=[ buttons[b] for b in bufdata.newlines ] )
if newline < 0:
......@@ -817,7 +825,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
text = text.encode(bufdata.encoding)
except UnicodeEncodeError:
if misc.run_dialog(
_("'%s' contains characters not encodable with '%s'\nWould you like to save as UTF-8?") % (bufdata.filename, bufdata.encoding),
_("'%s' contains characters not encodable with '%s'\nWould you like to save as UTF-8?") % (bufdata.label, bufdata.encoding),
self, gtk.MESSAGE_ERROR, gtk.BUTTONS_YES_NO) != gtk.RESPONSE_YES:
return melddoc.RESULT_ERROR
if self._save_text_to_filename(bufdata.filename, text):
......@@ -836,7 +844,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
texts = [b.get_text(*b.get_bounds()).split("\n") for b in bufs]
texts[0] = [l+"\n" for l in texts[0]]
texts[1] = [l+"\n" for l in texts[1]]
names = [self._get_filename(i) for i in range(2)]
names = [self._get_pane_label(i) for i in range(2)]
dialog.textview.modify_font(fontdesc)
buf = dialog.textview.get_buffer()
lines = []
......@@ -904,7 +912,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
# refresh and reload
#
def on_reload_activate(self, *extra):
modified = [b.filename for b in self.bufferdata if b.modified]
modified = [os.path.basename(b.label) for b in self.bufferdata if b.modified]
if len(modified):
message = _("Reloading will discard changes in:\n%s\n\nYou cannot undo this operation.") % "\n".join(modified)
response = misc.run_dialog( message, parent=self, messagetype=gtk.MESSAGE_WARNING, buttonstype=gtk.BUTTONS_OK_CANCEL)
......@@ -1343,11 +1351,12 @@ if gobject.pygtk_version < (2,8,0):
################################################################################
class MeldBufferData(object):
__slots__ = ("modified", "writable", "filename", "encoding", "newlines")
__slots__ = ("modified", "writable", "filename", "label", "encoding", "newlines")
def __init__(self, filename=None):
self.modified = 0
self.writable = 1
self.filename = filename
self.label = filename
self.encoding = None
self.newlines = None
......
......@@ -70,7 +70,7 @@
<accelerator key="n" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image706">
<widget class="GtkImage" id="image722">
<property name="visible">True</property>
<property name="stock">gtk-new</property>
<property name="icon_size">1</property>
......@@ -92,7 +92,7 @@
<accelerator key="s" modifiers="GDK_CONTROL_MASK | GDK_SHIFT_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image707">
<widget class="GtkImage" id="image723">
<property name="visible">True</property>
<property name="stock">gtk-save-as</property>
<property name="icon_size">1</property>
......@@ -114,7 +114,7 @@
<accelerator key="s" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image708">
<widget class="GtkImage" id="image724">
<property name="visible">True</property>
<property name="stock">gtk-save</property>
<property name="icon_size">1</property>
......@@ -186,7 +186,7 @@
<accelerator key="r" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image709">
<widget class="GtkImage" id="image725">
<property name="visible">True</property>
<property name="stock">gtk-refresh</property>
<property name="icon_size">1</property>
......@@ -208,7 +208,7 @@
<accelerator key="r" modifiers="GDK_CONTROL_MASK | GDK_SHIFT_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image710">
<widget class="GtkImage" id="image726">
<property name="visible">True</property>
<property name="stock">gtk-refresh</property>
<property name="icon_size">1</property>
......@@ -258,7 +258,7 @@
<accelerator key="d" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image711">
<widget class="GtkImage" id="image727">
<property name="visible">True</property>
<property name="stock">gtk-go-down</property>
<property name="icon_size">1</property>
......@@ -280,7 +280,7 @@
<accelerator key="e" modifiers="GDK_CONTROL_MASK" signal="activate"/>
<child internal-child="image">
<widget class="GtkImage" id="image712">
<widget class="GtkImage" id="image728">
<property name="visible">True</property>
<property name="stock">gtk-go-up</property>
<property name="icon_size">1</property>
......@@ -363,7 +363,7 @@
<signal name="activate" handler="on_menu_users_manual_activate" last_modification_time="Fri, 01 Nov 2002 18:36:34 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image713">
<widget class="GtkImage" id="image729">
<property name="visible">True</property>
<property name="stock">gtk-help</property>
<property name="icon_size">1</property>
......@@ -384,7 +384,7 @@
<signal name="activate" handler="on_menu_help_bug_activate" last_modification_time="Mon, 29 Sep 2003 19:59:09 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image714">
<widget class="GtkImage" id="image730">
<property name="visible">True</property>
<property name="stock">gtk-dialog-warning</property>
<property name="icon_size">1</property>
......@@ -397,6 +397,27 @@
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menu_help_list">
<property name="visible">True</property>
<property name="label" translatable="yes">Mailing _List</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menu_help_list_activate" last_modification_time="Sun, 11 Jun 2006 11:28:28 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image731">
<property name="visible">True</property>
<property name="stock">gnome-stock-mail</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="about1">
<property name="visible">True</property>
......
......@@ -759,6 +759,7 @@ class MeldApp(gnomeglade.GnomeApp):
doc = dirdiff.DirDiff(self.prefs, len(dirs))
self._append_page(doc, "tree-folder-normal.png")
doc.set_locations(dirs)
return doc
def append_filediff(self, files):
assert len(files) in (1,2,3)
......@@ -769,6 +770,7 @@ class MeldApp(gnomeglade.GnomeApp):
seq.connect("can-redo", self.on_can_redo)
self._append_page(doc, "tree-file-normal.png")
doc.set_files(files)
return doc
def append_diff(self, paths):
aredirs = [ os.path.isdir(p) for p in paths ]
......@@ -778,9 +780,9 @@ class MeldApp(gnomeglade.GnomeApp):
parent = self,
buttonstype = gtk.BUTTONS_OK)
elif 1 in aredirs:
self.append_dirdiff(paths)
return self.append_dirdiff(paths)
else:
self.append_filediff(paths)
return self.append_filediff(paths)
def append_vcview(self, locations):
assert len(locations) in (1,)
......@@ -788,6 +790,7 @@ class MeldApp(gnomeglade.GnomeApp):
doc = vcview.VcView(self.prefs)
self._append_page(doc, "vc-icon.png")
doc.set_location(location)
return doc
#
# Current doc actions
......@@ -820,22 +823,6 @@ class MeldApp(gnomeglade.GnomeApp):
# usage
#
################################################################################
usage_string = _("""Meld is a file and directory comparison tool. Usage:
meld Start with no windows open
meld <dir> Start with VC browser in 'dir'
meld <file> Start with VC diff of 'file'
meld <file> <file> [file] Start with 2 or 3 way file comparison
meld <dir> <dir> [dir] Start with 2 or 3 way directory comparison
Options:
-h, --help Show this help text and exit
-v, --version Display the version and exit
For more information choose help -> contents.
Report bugs at http://bugzilla.gnome.org/buglist.cgi?product=meld
Discuss meld at http://mail.gnome.org/mailman/listinfo/meld-list
""")
version_string = _("""Meld %s
Written by Stephen Kennedy <stevek@gnome.org>""") % version
......@@ -846,6 +833,7 @@ Written by Stephen Kennedy <stevek@gnome.org>""") % version
#
################################################################################
def main():
import optparse
class Unbuffered(object):
def __init__(self, file):
self.file = file
......@@ -855,17 +843,25 @@ def main():
def __getattr__(self, attr):
return getattr(self.file, attr)
sys.stdout = Unbuffered(sys.stdout)
args = sys.argv[1:]
if args:
if "-h" in args or "--help" in args:
print usage_string
return
if "-v" in args or "--version" in args:
print version_string
return
parser = optparse.OptionParser(
usage="""
%prog Start with no windows open
%prog <dir> Start with VC browser in 'dir'
%prog <file> Start with VC diff of 'file'
%prog <file> <file> [file] Start with 2 or 3 way file comparison
%prog <dir> <dir> [dir] Start with 2 or 3 way directory comparison""",
description="""Meld is a file and directory comparison tool.""",
version="%prog "+version)
parser.add_option("-L", "--label", action="append", help=_("Set label to use instead of file name"))
parser.add_option("-u", "--unified", action="store_true", help=_("Ignored for compatibility"))
parser.add_option("-c", "--context", action="store_true", help=_("Ignored for compatibility"))
parser.add_option("-e", "--ed", action="store_true", help=_("Ignored for compatibility"))
parser.add_option("-r", "--recursive", action="store_true", help=_("Ignored for compatibility"))
options, args = parser.parse_args()
app = MeldApp()
tab = None
if len(args) == 0:
pass
......@@ -882,12 +878,14 @@ def main():
doc.connect("create-diff", lambda obj,arg: app.append_diff(arg) )
doc.run_diff([a])
else:
app.append_vcview( [a] )
tab = app.append_vcview( [a] )
elif len(args) in (2,3):
app.append_diff(args)
tab = app.append_diff(args)
else:
app.usage( _("Wrong number of arguments (Got %i)") % len(args))
if tab:
tab.set_labels( options.label )
app.main()
......@@ -110,6 +110,9 @@ class MeldDoc(gobject.GObject):
def label_changed(self):
self.emit("label-changed", self.label_text)
def set_labels(self, lst):
pass
def on_switch_event(self):
pass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment