Commits

Ali Afshar  committed 07cd66c

Made Vim embedding optional.

  • Participants
  • Parent commits 7608482

Comments (0)

Files changed (2)

File pida/editors/vim/embed.py

 
 import subprocess
 
+class VimStarter(gtk.EventBox):
+
+    def __init__(self, command, script_path, args=None):
+        gtk.EventBox.__init__(self)
+        self.command = command
+        self.init_script = script_path
+        self.pid = None
+        self.args = args or []
+
+    def run(self):
+        if not self.pid:
+            try:
+                popen = subprocess.Popen(
+                    [self.command,
+                    # XXX: leftover from vim com
+                    #'--servername', self.server_name,
+                    '--cmd', 'let PIDA_EMBEDDED=1',
+                    '--cmd', 'so %s' % self.init_script,
+                    ] + self.args,
+                    close_fds=True,
+                )
+                self.pid = popen.pid
+            except OSError:
+                raise
+                return False
+        self.show_all()
+        return True
+
+
 class VimEmbedWidget(gtk.EventBox):
 
-    def __init__(self, command, script_path, args=[]):
+    def __init__(self, command, script_path, args=None):
         gtk.EventBox.__init__(self)
         self._command = command
         self._init_script = script_path
         self.pid = None
-        self.args = args
+        self.args = args or []
         self.r_cb_plugged = None
         self.r_cb_unplugged = None
         self.__eb = None

File pida/editors/vim/vim.py

 
 from pida.core.environment import get_data_path
 from pida.core.editors import EditorService, _
+from pida.core.options import OptionsConfig, choices
 from pida.ui.views import PidaView
 
-from .embed import VimEmbedWidget
+from .embed import VimEmbedWidget, VimStarter
 from .client import get_vim
 
 _ignore = dict(reply_handler=lambda *a: None,
 class VimView(PidaView):
 
     def create_ui(self):
-        self._vim = VimEmbedWidget('gvim', self.svc.script_path)
+        if self.svc.opt('embed_vim'):
+            vim_factory = VimEmbedWidget
+        else:
+            vim_factory = VimStarter
+        self._vim = vim_factory('gvim', self.svc.script_path)
         self.add_main_widget(self._vim)
 
     def run(self):
         pass
 
 
+class VimOptionsConfig(OptionsConfig):
+
+    def create_options(self):
+        self.create_option(
+            'embed_vim',
+            _('Embed Vim inside PIDA (requires restart)'),
+            bool,
+            True,
+            _('Embed Vim inside PIDA (requires restart).'),
+        )
+
+
 # Service class
 class Vim(EditorService):
     """Vim Editor Service
     """
+
+    options_config = VimOptionsConfig
+
     def __init__(self, *args, **kw):
         EditorService.__init__(self, *args, **kw)
         self._sign_index = 0