[meld] Move patch dialog to its own file
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] Move patch dialog to its own file
- Date: Sun, 10 Oct 2010 20:20:27 +0000 (UTC)
commit e581d623cea7100f46e0d7beaf695c9fd50f9bc4
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Oct 10 07:56:07 2010 +1000
Move patch dialog to its own file
meld/filediff.py | 98 +---------------------------------------
meld/patchdialog.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
3 files changed, 127 insertions(+), 96 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index a0b1afb..76b5df8 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -34,6 +34,7 @@ from ui import gnomeglade
import matchers
import misc
import melddoc
+import patchdialog
import paths
import merge
@@ -109,101 +110,6 @@ class BufferLines(object):
return self.buf.get_line_count()
-class PatchDialog(gnomeglade.Component):
-
- def __init__(self, filediff):
- ui_file = paths.ui_dir("patch-dialog.ui")
- gnomeglade.Component.__init__(self, ui_file, "patchdialog")
-
- self.widget.set_transient_for(filediff.widget.get_toplevel())
- self.prefs = filediff.prefs
- self.prefs.notify_add(self.on_preference_changed)
- self.filediff = filediff
-
- buf = srcviewer.GtkTextBuffer()
- self.textview.set_buffer(buf)
- srcviewer.set_highlighting_enabled_from_mimetype(buf, "text/x-diff", True)
- fontdesc = pango.FontDescription(self.prefs.get_current_font())
- self.textview.modify_font(fontdesc)
- self.textview.set_editable(False)
-
- self.index_map = {self.left_radiobutton: (0, 1),
- self.right_radiobutton: (1, 2)}
- self.left_patch = True
- self.reverse_patch = self.reverse_checkbutton.get_active()
-
- if self.filediff.num_panes < 3:
- self.label3.hide()
- self.hbox2.hide()
-
- def on_preference_changed(self, key, value):
- if key == "use_custom_font" or key == "custom_font":
- fontdesc = pango.FontDescription(self.prefs.get_current_font())
- self.textview.modify_font(fontdesc)
-
- def on_buffer_selection_changed(self, radiobutton):
- if not radiobutton.get_active():
- return
- self.left_patch = radiobutton == self.left_radiobutton
- self.update_patch()
-
- def on_reverse_checkbutton_toggled(self, checkbutton):
- self.reverse_patch = checkbutton.get_active()
- self.update_patch()
-
- def update_patch(self):
- indices = (0, 1)
- if not self.left_patch:
- indices = (1, 2)
- if self.reverse_patch:
- indices = (indices[1], indices[0])
-
- texts = []
- for b in self.filediff.textbuffer:
- start, end = b.get_bounds()
- text = b.get_text(start, end, False)
- lines = text.splitlines(True)
- texts.append(lines)
-
- names = [self.filediff._get_pane_label(i) for i in range(3)]
- prefix = os.path.commonprefix(names)
- names = [n[prefix.rfind("/") + 1:] for n in names]
-
- buf = self.textview.get_buffer()
- text0, text1 = texts[indices[0]], texts[indices[1]]
- name0, name1 = names[indices[0]], names[indices[1]]
- diff_text = "".join(difflib.unified_diff(text0, text1, name0, name1))
- buf.set_text(diff_text)
-
- def run(self):
- self.update_patch()
-
- while 1:
- result = self.widget.run()
- if result < 0:
- break
-
- buf = self.textview.get_buffer()
- txt = buf.get_text(buf.get_start_iter(), buf.get_end_iter(), False)
-
- # Copy patch to clipboard
- if result == 1:
- clip = gtk.clipboard_get()
- clip.set_text(txt)
- clip.store()
- break
- # Save patch as a file
- else:
- # FIXME: These filediff methods are actually general utility.
- filename = self.filediff._get_filename_for_saving(
- _("Save Patch As..."))
- if filename:
- self.filediff._save_text_to_filename(filename, txt)
- break
-
- self.widget.hide()
-
-
################################################################################
#
# FileDiff
@@ -1195,7 +1101,7 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
return melddoc.RESULT_ERROR
def make_patch(self, *extra):
- dialog = PatchDialog(self)
+ dialog = patchdialog.PatchDialog(self)
dialog.run()
def set_buffer_writable(self, buf, yesno):
diff --git a/meld/patchdialog.py b/meld/patchdialog.py
new file mode 100644
index 0000000..c62d163
--- /dev/null
+++ b/meld/patchdialog.py
@@ -0,0 +1,124 @@
+### Copyright (C) 2002-2006 Stephen Kennedy <stevek gnome org>
+### Copyright (C) 2009-2010 Kai Willadsen <kai willadsen gmail com>
+
+### This program is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+
+### This program is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+
+### You should have received a copy of the GNU General Public License
+### along with this program; if not, write to the Free Software
+### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+import difflib
+from gettext import gettext as _
+import os
+
+import gtk
+import pango
+
+from ui import gnomeglade
+import paths
+
+from util.sourceviewer import srcviewer
+
+
+class PatchDialog(gnomeglade.Component):
+
+ def __init__(self, filediff):
+ ui_file = paths.ui_dir("patch-dialog.ui")
+ gnomeglade.Component.__init__(self, ui_file, "patchdialog")
+
+ self.widget.set_transient_for(filediff.widget.get_toplevel())
+ self.prefs = filediff.prefs
+ self.prefs.notify_add(self.on_preference_changed)
+ self.filediff = filediff
+
+ buf = srcviewer.GtkTextBuffer()
+ self.textview.set_buffer(buf)
+ srcviewer.set_highlighting_enabled_from_mimetype(buf, "text/x-diff", True)
+ fontdesc = pango.FontDescription(self.prefs.get_current_font())
+ self.textview.modify_font(fontdesc)
+ self.textview.set_editable(False)
+
+ self.index_map = {self.left_radiobutton: (0, 1),
+ self.right_radiobutton: (1, 2)}
+ self.left_patch = True
+ self.reverse_patch = self.reverse_checkbutton.get_active()
+
+ if self.filediff.num_panes < 3:
+ self.label3.hide()
+ self.hbox2.hide()
+
+ def on_preference_changed(self, key, value):
+ if key == "use_custom_font" or key == "custom_font":
+ fontdesc = pango.FontDescription(self.prefs.get_current_font())
+ self.textview.modify_font(fontdesc)
+
+ def on_buffer_selection_changed(self, radiobutton):
+ if not radiobutton.get_active():
+ return
+ self.left_patch = radiobutton == self.left_radiobutton
+ self.update_patch()
+
+ def on_reverse_checkbutton_toggled(self, checkbutton):
+ self.reverse_patch = checkbutton.get_active()
+ self.update_patch()
+
+ def update_patch(self):
+ indices = (0, 1)
+ if not self.left_patch:
+ indices = (1, 2)
+ if self.reverse_patch:
+ indices = (indices[1], indices[0])
+
+ texts = []
+ for b in self.filediff.textbuffer:
+ start, end = b.get_bounds()
+ text = b.get_text(start, end, False)
+ lines = text.splitlines(True)
+ texts.append(lines)
+
+ names = [self.filediff._get_pane_label(i) for i in range(3)]
+ prefix = os.path.commonprefix(names)
+ names = [n[prefix.rfind("/") + 1:] for n in names]
+
+ buf = self.textview.get_buffer()
+ text0, text1 = texts[indices[0]], texts[indices[1]]
+ name0, name1 = names[indices[0]], names[indices[1]]
+ diff_text = "".join(difflib.unified_diff(text0, text1, name0, name1))
+ buf.set_text(diff_text)
+
+ def run(self):
+ self.update_patch()
+
+ while 1:
+ result = self.widget.run()
+ if result < 0:
+ break
+
+ buf = self.textview.get_buffer()
+ txt = buf.get_text(buf.get_start_iter(), buf.get_end_iter(), False)
+
+ # Copy patch to clipboard
+ if result == 1:
+ clip = gtk.clipboard_get()
+ clip.set_text(txt)
+ clip.store()
+ break
+ # Save patch as a file
+ else:
+ # FIXME: These filediff methods are actually general utility.
+ filename = self.filediff._get_filename_for_saving(
+ _("Save Patch As..."))
+ if filename:
+ self.filediff._save_text_to_filename(filename, txt)
+ break
+
+ self.widget.hide()
+
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 42be58a..6260e97 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -12,6 +12,7 @@ meld/filemerge.py
meld/meldapp.py
meld/melddoc.py
meld/misc.py
+meld/patchdialog.py
meld/preferences.py
meld/vcview.py
meld/ui/findbar.py
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]