[gedit/wip/snipfix: 3/3] [snippets] Fix completion popup



commit c66cbf3447b1f22cf46fbe5e0233f3d7e4268016
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sat Apr 12 14:51:25 2014 +0200

    [snippets] Fix completion popup

 plugins/snippets/snippets/document.py |   42 +++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/plugins/snippets/snippets/document.py b/plugins/snippets/snippets/document.py
index ab41ecc..e25112e 100644
--- a/plugins/snippets/snippets/document.py
+++ b/plugins/snippets/snippets/document.py
@@ -18,7 +18,7 @@
 import os
 import re
 
-from gi.repository import Gtk, Gdk, Gio, GLib, Gedit, GObject
+from gi.repository import Gtk, Gdk, Gio, GLib, Gedit, GObject, GtkSource
 
 from .library import Library
 from .snippet import Snippet
@@ -54,7 +54,9 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
         self.timeout_update_id = 0
 
         self.provider = completion.Provider(_('Snippets'), self.language_id, self.on_proposal_activated)
+
         self.defaults_provider = completion.Defaults(self.on_default_activated)
+        self.ambiguous_provider = completion.Provider(_('Snippets'), self.language_id, 
self.on_proposal_activated)
 
     def do_activate(self):
         # Always have a reference to the global snippets
@@ -71,9 +73,7 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
         self.update_language()
 
         completion = self.view.get_completion()
-
         completion.add_provider(self.provider)
-        completion.add_provider(self.defaults_provider)
 
         self.connect_signal(completion, 'hide', self.on_completion_hide)
 
@@ -102,7 +102,6 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
 
         if completion:
             completion.remove_provider(self.provider)
-            completion.remove_provider(self.defaults_provider)
 
         if self.language_id != 0:
             Library().unref(self.language_id)
@@ -131,6 +130,7 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
 
         Library().ref(self.language_id)
         self.provider.language_id = self.language_id
+        self.ambiguous_provider.language_id = self.language_id
 
         SharedData().update_state(self.view.get_toplevel())
 
@@ -148,9 +148,12 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
             self.apply_snippet(snippets[0])
         else:
             # Do the fancy completion dialog
-            self.provider.set_proposals(snippets)
+            self.ambiguous_provider.set_proposals(snippets)
+
             cm = self.view.get_completion()
-            cm.show([self.provider], cm.create_context(None))
+            context = self.create_completion_context(cm)
+
+            cm.show([self.ambiguous_provider], context)
 
         return True
 
@@ -287,7 +290,9 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
                 self.defaults_provider.set_defaults(next.defaults)
 
                 cm = self.view.get_completion()
-                cm.show([self.defaults_provider], cm.create_context(None))
+                context = self.create_completion_context(cm)
+
+                cm.show([self.defaults_provider], context)
 
         if last:
             # This is the end of the placeholder, remove the snippet etc
@@ -634,6 +639,21 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
 
         self.apply_snippet(DynamicSnippet(data), iter, iter)
 
+    def create_completion_context(self, completion):
+        context = completion.create_context(None)
+
+        try:
+            set_property = GObject._introspection_module.Object.set_property
+        except:
+            return context
+
+        val = GObject.Value()
+        val.init(GtkSource.CompletionActivation)
+        val.set_flags(GtkSource.CompletionActivation.USER_REQUESTED)
+
+        set_property(context, 'activation', val)
+        return context
+
     def run_snippet_trigger(self, trigger, bounds):
         if not self.view:
             return False
@@ -653,10 +673,12 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
                 return self.apply_snippet(snippets[0], bounds[0], bounds[1])
             else:
                 # Do the fancy completion dialog
-                self.provider.set_proposals(snippets)
+                self.ambiguous_provider.set_proposals(snippets)
                 cm = self.view.get_completion()
 
-                cm.show([self.provider], cm.create_context(None))
+                context = self.create_completion_context(cm)
+                cm.show([self.ambiguous_provider], context)
+
                 return True
 
         return False
@@ -923,7 +945,7 @@ class Document(GObject.Object, Gedit.ViewActivatable, Signals):
         return self.view.drag_dest_find_target(context, lst)
 
     def on_completion_hide(self, completion):
-        self.provider.set_proposals(None)
+        self.ambiguous_provider.set_proposals(None)
 
     def on_proposal_activated(self, proposal, piter):
         if not self.view.get_editable():


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