[meld] Split MeldWindow and MeldApp



commit d1fd7a9049a01d97971b713cddc0a1aae3115b86
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed Feb 9 05:54:58 2011 +1000

    Split MeldWindow and MeldApp

 bin/meld        |    3 +--
 meld/meldapp.py |   46 ++++++++++++++++++++++------------------------
 2 files changed, 23 insertions(+), 26 deletions(-)
---
diff --git a/bin/meld b/bin/meld
index e2c02b9..00e9dfc 100755
--- a/bin/meld
+++ b/bin/meld
@@ -125,8 +125,7 @@ except (ImportError, AssertionError), e:
 gtk.icon_theme_get_default().append_search_path(meld.paths.icon_dir())
 
 def main():
-    import meld.meldapp
-    app = meld.meldapp.MeldApp()
+    from meld.meldapp import app
     app.parse_args(sys.argv[1:])
     gtk.main()
 
diff --git a/meld/meldapp.py b/meld/meldapp.py
index fa10e24..797bc4e 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -110,18 +110,14 @@ class MeldStatusBar(object):
 #
 ################################################################################
 
-class MeldApp(gnomeglade.Component):
+class MeldWindow(gnomeglade.Component):
 
     #
     # init
     #
     def __init__(self):
         gladefile = paths.ui_dir("meldapp.ui")
-        gtk.window_set_default_icon_name("icon")
-        if getattr(gobject, "pygobject_version", ()) >= (2, 16, 0):
-            gobject.set_application_name("Meld")
         gnomeglade.Component.__init__(self, gladefile, "meldapp")
-        gtk.window_set_default_icon_name("meld")
         self.prefs = preferences.MeldPreferences()
 
         actions = (
@@ -561,9 +557,16 @@ class MeldApp(gnomeglade.Component):
             doc.on_button_diff_clicked(None)
         return doc
 
-    #
-    # Current doc actions
-    #
+    def _single_file_open(self, path):
+        doc = vcview.VcView(self.prefs)
+        def cleanup():
+            self.scheduler.remove_scheduler(doc.scheduler)
+        self.scheduler.add_task(cleanup)
+        self.scheduler.add_scheduler(doc.scheduler)
+        doc.set_location(path)
+        doc.connect("create-diff", lambda obj,arg: self.append_diff(arg))
+        doc.run_diff([path])
+
     def current_doc(self):
         "Get the current doc or a dummy object if there is no current"
         index = self.notebook.get_current_page()
@@ -573,9 +576,14 @@ class MeldApp(gnomeglade.Component):
             def __getattr__(self, a): return lambda *x: None
         return DummyDoc()
 
-    #
-    # Usage
-    #
+
+class MeldApp(object):
+
+    def __init__(self):
+        gobject.set_application_name("Meld")
+        gtk.window_set_default_icon_name("meld")
+        self.window = MeldWindow()
+
     def diff_files_callback(self, option, opt_str, value, parser):
         """Gather --diff arguments and append to a list"""
         assert value is None
@@ -632,27 +640,17 @@ class MeldApp(gnomeglade.Component):
         if options.outfile and tab and isinstance(tab, filediff.FileDiff):
             tab.set_merge_output_file(options.outfile)
 
-    def _single_file_open(self, path):
-        doc = vcview.VcView(self.prefs)
-        def cleanup():
-            self.scheduler.remove_scheduler(doc.scheduler)
-        self.scheduler.add_task(cleanup)
-        self.scheduler.add_scheduler(doc.scheduler)
-        doc.set_location(path)
-        doc.connect("create-diff", lambda obj,arg: self.append_diff(arg))
-        doc.run_diff([path])
-
     def open_paths(self, paths, auto_compare=False):
         tab = None
         if len(paths) == 1:
             a = paths[0]
             if os.path.isfile(a):
-                self._single_file_open(a)
+                self.window._single_file_open(a)
             else:
-                tab = self.append_vcview([a], auto_compare)
+                tab = self.window.append_vcview([a], auto_compare)
                     
         elif len(paths) in (2, 3, 4):
-            tab = self.append_diff(paths, auto_compare)
+            tab = self.window.append_diff(paths, auto_compare)
         return tab
 
 



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