[gnome-builder/wip/gtk4-port: 636/736] plugins/python-gi-imports-completion: port to GTK 4
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 636/736] plugins/python-gi-imports-completion: port to GTK 4
- Date: Tue, 26 Apr 2022 01:46:33 +0000 (UTC)
commit c5344ede7789954c2e7ccc49cce388991dbbd28f
Author: Christian Hergert <chergert redhat com>
Date: Tue Apr 19 10:53:26 2022 -0700
plugins/python-gi-imports-completion: port to GTK 4
src/plugins/meson.build | 2 +-
.../python_gi_imports_completion.py | 28 +++++++++++++---------
2 files changed, 18 insertions(+), 12 deletions(-)
---
diff --git a/src/plugins/meson.build b/src/plugins/meson.build
index c19478b57..ee7bdc9ee 100644
--- a/src/plugins/meson.build
+++ b/src/plugins/meson.build
@@ -107,7 +107,7 @@ subdir('open-with-external')
subdir('phpize')
#subdir('podman')
subdir('project-tree')
-#subdir('python-gi-imports-completion')
+subdir('python-gi-imports-completion')
#subdir('python-pack')
subdir('qemu')
subdir('quick-highlight')
diff --git a/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
b/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
index bd0139174..cd3effb27 100644
--- a/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
+++ b/src/plugins/python-gi-imports-completion/python_gi_imports_completion.py
@@ -34,7 +34,7 @@ from gi.repository import Ide
# 2 minutes
CACHE_EXPIRE_USEC = 2 * 60 * 1000 * 1000
-class CompletionProvider(Ide.Object, Ide.CompletionProvider):
+class CompletionProvider(Ide.Object, GtkSource.CompletionProvider):
_libraries = None
_libraries_expire_at = 0
@@ -45,14 +45,17 @@ class CompletionProvider(Ide.Object, Ide.CompletionProvider):
task = Ide.Task.new(self, cancellable, callback)
task.set_name('python gi imports')
- text = context.get_line_text()
+ _, begin, end = context.get_bounds()
+ begin.set_line_offset(0)
+ text = begin.get_slice(end)
+
if not text.startswith('from gi.repository import'):
task.return_error(Ide.NotSupportedError())
return
text = text.replace('from gi.repository import', '').strip().lower()
- proposals = Gio.ListStore.new(Ide.CompletionProposal)
+ proposals = Gio.ListStore.new(GtkSource.CompletionProposal)
for library in self.get_libraries():
if library.matches(text):
proposals.append(library)
@@ -62,13 +65,17 @@ class CompletionProvider(Ide.Object, Ide.CompletionProvider):
def do_populate_finish(self, task):
return task.propagate_object()
- def do_display_proposal(self, row, context, typed_text, proposal):
- row.set_icon_name('lang-namespace-symbolic')
- row.set_left(None)
- row.set_center(proposal.completion)
- row.set_right(None)
+ def do_display(self, context, proposal, cell):
+ column = cell.get_column()
+
+ if column == GtkSource.CompletionColumn.ICON:
+ cell.set_icon_name('lang-namespace-symbolic')
+ elif column == GtkSource.CompletionColumn.TYPED_TEXT:
+ cell.set_text(proposal.completion)
+ else:
+ cell.set_text(None)
- def do_activate_proposal(self, context, proposal, key):
+ def do_activate(self, context, proposal):
_, begin, end = context.get_bounds()
buffer = context.get_buffer()
@@ -88,7 +95,6 @@ class CompletionProvider(Ide.Object, Ide.CompletionProvider):
for library in self.get_libraries():
if library.matches(text):
proposals.append(library)
- return True
def get_libraries(self):
now = GLib.get_monotonic_time()
@@ -111,7 +117,7 @@ class CompletionProvider(Ide.Object, Ide.CompletionProvider):
return self._libraries
-class CompletionProposal(GObject.Object, Ide.CompletionProposal):
+class CompletionProposal(GObject.Object, GtkSource.CompletionProposal):
def __init__(self, completion, *args, **kwargs):
super().__init__(*args, **kwargs)
self.completion = completion
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]