diff --git a/plugins/word-completion/completion-provider.vala b/plugins/word-completion/completion-provider.vala index d9abbc7b7..4f2430c8b 100644 --- a/plugins/word-completion/completion-provider.vala +++ b/plugins/word-completion/completion-provider.vala @@ -1,4 +1,5 @@ /* + * Copyright 2024 elementary, Inc. * Copyright (c) 2013 Mario Guerriero * * This is a free software; you can redistribute it and/or @@ -18,37 +19,50 @@ * */ -public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, Object { - public string name; - public int priority; +public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, GLib.Object { + private const int MAX_COMPLETIONS = 10; + public string name { get; construct; } + public int priority { get; construct; } + public int interactive_delay { get; construct; } + public Gtk.SourceCompletionActivation activation { get; construct; } public const string COMPLETION_END_MARK_NAME = "ScratchWordCompletionEnd"; public const string COMPLETION_START_MARK_NAME = "ScratchWordCompletionStart"; - private Gtk.TextView? view; - private Gtk.TextBuffer? buffer; - private Euclide.Completion.Parser parser; + public Gtk.TextView? view { get; construct; } + public Euclide.Completion.Parser parser { get; construct; } + + private unowned Gtk.TextBuffer buffer { + get { + return view.buffer; + } + } + private Gtk.TextMark completion_end_mark; private Gtk.TextMark completion_start_mark; + private string current_text_to_find = ""; public signal void can_propose (bool b); - public CompletionProvider (Scratch.Plugins.Completion completion) { - this.view = completion.current_view as Gtk.TextView; - this.buffer = completion.current_view.buffer; - this.parser = completion.parser; - Gtk.TextIter iter; - buffer.get_iter_at_offset (out iter, 0); - completion_end_mark = buffer.create_mark (COMPLETION_END_MARK_NAME, iter, false); - completion_start_mark = buffer.create_mark (COMPLETION_START_MARK_NAME, iter, false); - } + public CompletionProvider ( + Euclide.Completion.Parser _parser, + Scratch.Services.Document _doc + ) { - public string get_name () { - return this.name; + Object ( + parser: _parser, + view: _doc.source_view, + name: _("%s - Word Completion").printf (_doc.get_basename ()) + ); } - public int get_priority () { - return this.priority; + construct { + interactive_delay = (int) Completion.INTERACTIVE_DELAY; + activation = INTERACTIVE | USER_REQUESTED; + Gtk.TextIter iter; + view.buffer.get_iter_at_offset (out iter, 0); + completion_end_mark = buffer.create_mark (COMPLETION_END_MARK_NAME, iter, false); + completion_start_mark = buffer.create_mark (COMPLETION_START_MARK_NAME, iter, false); } public bool match (Gtk.SourceCompletionContext context) { @@ -85,15 +99,6 @@ public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, return true; } - public Gtk.SourceCompletionActivation get_activation () { - return Gtk.SourceCompletionActivation.INTERACTIVE | - Gtk.SourceCompletionActivation.USER_REQUESTED; - } - - public int get_interactive_delay () { - return 0; - } - public bool get_start_iter (Gtk.SourceCompletionContext context, Gtk.SourceCompletionProposal proposal, out Gtk.TextIter iter) { diff --git a/plugins/word-completion/plugin.vala b/plugins/word-completion/plugin.vala index d227d12a6..ceccafa8d 100644 --- a/plugins/word-completion/plugin.vala +++ b/plugins/word-completion/plugin.vala @@ -19,6 +19,8 @@ */ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { + public const uint INTERACTIVE_DELAY = 500; + public Object object { owned get; construct; } private List text_view_list = new List (); @@ -88,9 +90,7 @@ public class Scratch.Plugins.Completion : Peas.ExtensionBase, Peas.Activatable { if (text_view_list.find (current_view) == null) text_view_list.append (current_view); - var comp_provider = new Scratch.Plugins.CompletionProvider (this); - comp_provider.priority = 1; - comp_provider.name = provider_name_from_document (doc); + var comp_provider = new Scratch.Plugins.CompletionProvider (parser, doc); try { current_view.completion.add_provider (comp_provider);