[gedit] Use the right dir for tools and fix some function calls.



commit 2aa6071912dac227f04f44c07e07f159b77be7ff
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Wed Jan 19 10:29:47 2011 +0100

    Use the right dir for tools and fix some function calls.

 plugins/externaltools/tools/__init__.py    |   13 +++++++------
 plugins/externaltools/tools/capture.py     |    8 ++++----
 plugins/externaltools/tools/functions.py   |   22 +++++++++++-----------
 plugins/externaltools/tools/library.py     |    5 +++--
 plugins/externaltools/tools/outputpanel.py |    2 +-
 5 files changed, 26 insertions(+), 24 deletions(-)
---
diff --git a/plugins/externaltools/tools/__init__.py b/plugins/externaltools/tools/__init__.py
index d75f84f..86f7be5 100644
--- a/plugins/externaltools/tools/__init__.py
+++ b/plugins/externaltools/tools/__init__.py
@@ -29,10 +29,11 @@ class ToolMenu(object):
     ACTION_HANDLER_DATA_KEY = "ExternalToolActionHandlerData"
     ACTION_ITEM_DATA_KEY = "ExternalToolActionItemData"
 
-    def __init__(self, library, window, menupath):
+    def __init__(self, library, window, panel, menupath):
         super(ToolMenu, self).__init__()
         self._library = library
         self._window = window
+        self._panel = panel
         self._menupath = menupath
 
         self._merge_id = 0
@@ -85,7 +86,7 @@ class ToolMenu(object):
         for item in directory.tools:
             action_name = 'ExternalToolTool%X' % id(item)
             action = Gtk.Action(action_name, item.name.replace('_', '__'), item.comment, None)
-            handler = action.connect("activate", capture_menu_action, self._window, item)
+            handler = action.connect("activate", capture_menu_action, self._window, self._panel, item)
 
             action.set_data(self.ACTION_ITEM_DATA_KEY, item)
             action.set_data(self.ACTION_HANDLER_DATA_KEY, handler)
@@ -200,12 +201,13 @@ class ExternalToolsPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Confi
 
         self._merge_id = ui_manager.add_ui_from_string(ui_string)
 
-        self.menu = ToolMenu(self._library, self.window,
+        # Create output console
+        self._output_buffer = OutputPanel(self.plugin_info.get_data_dir(), self.window)
+
+        self.menu = ToolMenu(self._library, self.window, self._output_buffer,
                              "/MenuBar/ToolsMenu/ToolsOps_4/ExternalToolsMenu/ExternalToolPlaceholder")
         ui_manager.ensure_update()
 
-        # Create output console
-        self._output_buffer = OutputPanel(self.plugin_info.get_data_dir(), self.window)
         bottom = self.window.get_bottom_panel()
         image = Gtk.Image(stock=Gtk.STOCK_EXECUTE, icon_size=Gtk.IconSize.MENU)
         bottom.add_item(self._output_buffer.panel,
@@ -214,7 +216,6 @@ class ExternalToolsPlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Confi
                         image)
 
     def do_update_state(self):
-        return
         self.menu.filter(self.window.get_active_document())
         self.window.get_ui_manager().ensure_update()
 
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index 520b22a..390a87f 100644
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -101,7 +101,7 @@ class Capture(GObject.Object):
             fcntl.fcntl(self.pipe.stdout.fileno(), fcntl.F_SETFL, flags)
 
             GObject.io_add_watch(self.pipe.stdout,
-                                 GObject.IO_IN | GObject.IO_HUP,
+                                 GObject.IOCondition.IN | GObject.IOCondition.HUP,
                                  self.on_output)
 
         if self.flags & self.CAPTURE_STDERR:
@@ -110,7 +110,7 @@ class Capture(GObject.Object):
             fcntl.fcntl(self.pipe.stderr.fileno(), fcntl.F_SETFL, flags)
 
             GObject.io_add_watch(self.pipe.stderr,
-                                 GObject.IO_IN | GObject.IO_HUP,
+                                 GObject.IOCondition.IN | GObject.IOCondition.HUP,
                                  self.on_output)
 
         # IO
@@ -152,7 +152,7 @@ class Capture(GObject.Object):
             return False
 
     def on_output(self, source, condition):
-        if condition & (GLib.IO_IN | GLib.IO_PRI):
+        if condition & (GLib.IOCondition.IN | GLib.IOCondition.PRI):
             line = source.read()
 
             if len(line) > 0:
@@ -178,7 +178,7 @@ class Capture(GObject.Object):
                     else:
                         self.emit('stderr-line', line)
 
-        if condition & ~(GLib.IO_IN | GLib.IO_PRI):
+        if condition & ~(GLib.IOCondition.IN | GLib.IOCondition.PRI):
             if self.read_buffer:
                 if source == self.pipe.stdout:
                     self.emit('stdout-line', self.read_buffer)
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index a05ce54..140e85f 100644
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -40,7 +40,7 @@ def current_word(document):
     return (start, piter)
 
 # ==== Capture related functions ====
-def run_external_tool(window, node):
+def run_external_tool(window, panel, node):
     # Configure capture environment
     try:
         cwd = os.getcwd()
@@ -118,8 +118,7 @@ def run_external_tool(window, node):
     input_type = node.input
     output_type = node.output
 
-    # Get the panel
-    panel = window.get_data("ExternalToolsPluginWindowData")._output_buffer
+    # Clear the panel
     panel.clear()
 
     if output_type == 'output-panel':
@@ -209,8 +208,9 @@ def run_external_tool(window, node):
         document.end_user_action()
 
 class MultipleDocumentsSaver:
-    def __init__(self, window, docs, node):
+    def __init__(self, window, panel, docs, node):
         self._window = window
+        self._panel = panel
         self._node = node
         self._error = False
 
@@ -239,17 +239,17 @@ class MultipleDocumentsSaver:
         self._counter -= 1
         
         if self._counter == 0 and not self._error:
-            run_external_tool(self._window, self._node)
+            run_external_tool(self._window, self._panel, self._node)
 
-def capture_menu_action(action, window, node):
+def capture_menu_action(action, window, panel, node):
     if node.save_files == 'document' and window.get_active_document():
-        MultipleDocumentsSaver(window, [window.get_active_document()], node)
+        MultipleDocumentsSaver(window, panel, [window.get_active_document()], node)
         return
     elif node.save_files == 'all':
-        MultipleDocumentsSaver(window, window.get_documents(), node)
+        MultipleDocumentsSaver(window, panel, window.get_documents(), node)
         return
 
-    run_external_tool(window, node)
+    run_external_tool(window, panel, node)
 
 def capture_stderr_line_panel(capture, line, panel):
     if not panel.visible():
@@ -258,7 +258,7 @@ def capture_stderr_line_panel(capture, line, panel):
     panel.write(line, panel.error_tag)
 
 def capture_begin_execute_panel(capture, panel, view, label):
-    view.get_window(Gtk.TextWindowType.TEXT).set_cursor(Gdk.Cursor(Gdk.CursorType.WATCH))
+    view.get_window(Gtk.TextWindowType.TEXT).set_cursor(Gdk.Cursor.new(Gdk.CursorType.WATCH))
 
     panel['stop'].set_sensitive(True)
     panel.clear()
@@ -286,7 +286,7 @@ def capture_end_execute_panel(capture, exit_code, panel, view, output_type):
         if language is not None:
             doc.set_language(language)
 
-    view.get_window(Gtk.TEXT_WINDOW_TEXT).set_cursor(Gdk.Cursor(Gdk.CursorType.XTERM))
+    view.get_window(Gtk.TextWindowType.TEXT).set_cursor(Gdk.Cursor.new(Gdk.CursorType.XTERM))
     view.set_cursor_visible(True)
     view.set_editable(True)
 
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index c296b63..1e4ef64 100644
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -20,6 +20,7 @@ import os
 import re
 import locale
 import platform
+from gi.repository import GLib
 
 class Singleton(object):
     _instance = None
@@ -53,7 +54,7 @@ class ToolLibrary(Singleton):
             if userdir:
                 toolsdir = os.path.join(userdir, 'gedit/tools')
             else:
-                toolsdir = os.path.expanduser('~/.config/gedit/tools')
+                toolsdir = os.path.join(GLib.get_user_config_dir(), 'gedit/tools')
 
         self.locations.insert(0, toolsdir);
 
@@ -82,7 +83,7 @@ class ToolLibrary(Singleton):
         if userdir:
             filename = os.path.join(userdir, 'gedit/gedit-tools.xml')
         else:
-            filename = os.path.expanduser('~/.config/gedit/gedit-tools.xml')
+            filename = os.path.join(GLib.get_user_config_dir(), 'gedit/gedit-tools.xml')
 
         if not os.path.isfile(filename):
             return
diff --git a/plugins/externaltools/tools/outputpanel.py b/plugins/externaltools/tools/outputpanel.py
index 55defb6..1141427 100644
--- a/plugins/externaltools/tools/outputpanel.py
+++ b/plugins/externaltools/tools/outputpanel.py
@@ -123,7 +123,7 @@ class OutputPanel(UniqueById):
 
     def scroll_to_end(self):
         iter = self['view'].get_buffer().get_end_iter()
-        self['view'].scroll_to_iter(iter, 0.0)
+        self['view'].scroll_to_iter(iter, 0.0, False, 0.5, 0.5)
         return False  # don't requeue this handler
 
     def clear(self):



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