Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adding completion to gscb#15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
chuchiperriman wants to merge1 commit intoGeditSourceCodePlugin:master
base:master
Choose a base branch
Loading
fromchuchiperriman:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletionssourcecodebrowser/completion.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
from gi.repository import GObject, Gtk, GtkSource, Gedit

class Proposal(GObject.Object, GtkSource.CompletionProposal):
__gtype_name__ = "GeditSourceCodeProposal"


def __init__(self, tag):
GObject.Object.__init__(self)
self._tag = tag

# Interface implementation
def do_get_markup(self):
return self._tag.name

"""
def do_get_info(self):
return self._tag.name
"""

class Provider(GObject.Object, GtkSource.CompletionProvider):
__gtype_name__ = "GeditSourceCodeProvider"

def __init__(self, sourcetree):
GObject.Object.__init__(self)
self.name = 'SourceCodeProvider'
self.sourcetree = sourcetree
"""
theme = Gtk.IconTheme.get_default()
f, w, h = Gtk.icon_size_lookup(Gtk.IconSize.MENU)

try:
self.icon = theme.load_icon(Gtk.STOCK_JUSTIFY_LEFT, w, 0)
except:
self.icon = None
"""
self.icon = self.sourcetree.get_pixbuf('source-code-browser')

def get_word(self, context):
it = context.get_iter()

if it.starts_word() or it.starts_line() or not it.ends_word():
return None

start = it.copy()

if start.backward_word_start():
return start.get_text(it)
else:
return None

def do_match(self, context):
return True

def do_populate(self, context):
word = self.get_word(context)
proposals = []
print word
for tag in self.sourcetree.tags:
if not word or tag.name.startswith(word):
proposals.append(Proposal(tag))
context.add_proposals(self, proposals, True)

def do_get_name(self):
return self.name

def do_activate_proposal(self, proposal, piter):
buf = piter.get_buffer()
buf.insert_at_cursor(proposal._tag.name, -1)
return True

def do_get_icon(self):
return self.icon

def do_get_activation(self):
return GtkSource.CompletionActivation.USER_REQUESTED

# ex:ts=8:et:
12 changes: 10 additions & 2 deletionssourcecodebrowser/plugin.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
import logging
import tempfile
import ctags
import completion
from gi.repository import GObject, GdkPixbuf, Gedit, Gtk, PeasGtk, Gio

logging.basicConfig()
Expand DownExpand Up@@ -179,9 +180,9 @@ def load(self, kinds, tags, uri):
# TODO: We need to go at least one more level to deal with the inline
# classes used in many python projects (eg. Models in Django)
# Recursion would be even better.

self.tags = tags
# sort
if self.sort_list:
if self.sort_list:
self._store.set_sort_column_id(1, Gtk.SortType.ASCENDING)

# expand
Expand DownExpand Up@@ -393,8 +394,11 @@ def _load_active_document_symbols(self):
self._is_loaded = False
# do not load if not the active tab in the panel
panel = self.window.get_side_panel()
#Disabled because completion needs the symbols
"""
if not panel.item_is_active(self._sourcetree):
return
"""

document = self.window.get_active_document()
if document:
Expand DownExpand Up@@ -424,6 +428,10 @@ def _load_active_document_symbols(self):

def on_active_tab_changed(self, window, tab, data=None):
self._load_active_document_symbols()

if not hasattr(self.window.get_active_view(), "sc_completion"):
self.window.get_active_view().get_completion().add_provider(completion.Provider(self._sourcetree))
self.window.get_active_view().sc_completion = True

def on_setting_changed(self, settings, key, data=None):
"""
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp