|
1 | 1 | /* |
| 2 | + * Copyright 2024 elementary, Inc. <https://elementary.io> |
2 | 3 | * Copyright (c) 2013 Mario Guerriero <[email protected]> |
3 | 4 | * |
4 | 5 | * This is a free software; you can redistribute it and/or |
|
18 | 19 | * |
19 | 20 | */ |
20 | 21 |
|
21 | | -public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, Object { |
22 | | - public string name; |
23 | | - public int priority; |
| 22 | +public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, GLib.Object { |
| 23 | + private const int MAX_COMPLETIONS = 10; |
| 24 | + public string name { get; construct; } |
| 25 | + public int priority { get; construct; } |
| 26 | + public int interactive_delay { get; construct; } |
| 27 | + public Gtk.SourceCompletionActivation activation { get; construct; } |
24 | 28 |
|
25 | 29 | public const string COMPLETION_END_MARK_NAME = "ScratchWordCompletionEnd"; |
26 | 30 | public const string COMPLETION_START_MARK_NAME = "ScratchWordCompletionStart"; |
27 | 31 |
|
28 | | - private Gtk.TextView? view; |
29 | | - private Gtk.TextBuffer? buffer; |
30 | | - private Euclide.Completion.Parser parser; |
| 32 | + public Gtk.TextView? view { get; construct; } |
| 33 | + public Euclide.Completion.Parser parser { get; construct; } |
| 34 | + |
| 35 | + private unowned Gtk.TextBuffer buffer { |
| 36 | + get { |
| 37 | + return view.buffer; |
| 38 | + } |
| 39 | + } |
| 40 | + |
31 | 41 | private Gtk.TextMark completion_end_mark; |
32 | 42 | private Gtk.TextMark completion_start_mark; |
| 43 | + private string current_text_to_find = ""; |
33 | 44 |
|
34 | 45 | public signal void can_propose (bool b); |
35 | 46 |
|
36 | | - public CompletionProvider (Scratch.Plugins.Completion completion) { |
37 | | - this.view = completion.current_view as Gtk.TextView; |
38 | | - this.buffer = completion.current_view.buffer; |
39 | | - this.parser = completion.parser; |
40 | | - Gtk.TextIter iter; |
41 | | - buffer.get_iter_at_offset (out iter, 0); |
42 | | - completion_end_mark = buffer.create_mark (COMPLETION_END_MARK_NAME, iter, false); |
43 | | - completion_start_mark = buffer.create_mark (COMPLETION_START_MARK_NAME, iter, false); |
44 | | - } |
| 47 | + public CompletionProvider ( |
| 48 | + Euclide.Completion.Parser _parser, |
| 49 | + Scratch.Services.Document _doc |
| 50 | + ) { |
45 | 51 |
|
46 | | - public string get_name () { |
47 | | - return this.name; |
| 52 | + Object ( |
| 53 | + parser: _parser, |
| 54 | + view: _doc.source_view, |
| 55 | + name: _("%s - Word Completion").printf (_doc.get_basename ()) |
| 56 | + ); |
48 | 57 | } |
49 | 58 |
|
50 | | - public int get_priority () { |
51 | | - return this.priority; |
| 59 | + construct { |
| 60 | + interactive_delay = (int) Completion.INTERACTIVE_DELAY; |
| 61 | + activation = INTERACTIVE | USER_REQUESTED; |
| 62 | + Gtk.TextIter iter; |
| 63 | + view.buffer.get_iter_at_offset (out iter, 0); |
| 64 | + completion_end_mark = buffer.create_mark (COMPLETION_END_MARK_NAME, iter, false); |
| 65 | + completion_start_mark = buffer.create_mark (COMPLETION_START_MARK_NAME, iter, false); |
52 | 66 | } |
53 | 67 |
|
54 | 68 | public bool match (Gtk.SourceCompletionContext context) { |
@@ -85,15 +99,6 @@ public class Scratch.Plugins.CompletionProvider : Gtk.SourceCompletionProvider, |
85 | 99 | return true; |
86 | 100 | } |
87 | 101 |
|
88 | | - public Gtk.SourceCompletionActivation get_activation () { |
89 | | - return Gtk.SourceCompletionActivation.INTERACTIVE | |
90 | | - Gtk.SourceCompletionActivation.USER_REQUESTED; |
91 | | - } |
92 | | - |
93 | | - public int get_interactive_delay () { |
94 | | - return 0; |
95 | | - } |
96 | | - |
97 | 102 | public bool get_start_iter (Gtk.SourceCompletionContext context, |
98 | 103 | Gtk.SourceCompletionProposal proposal, |
99 | 104 | out Gtk.TextIter iter) { |
|
0 commit comments