-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update construction of completion provider
- Loading branch information
Jeremy Wootten
authored and
Jeremy Wootten
committed
Jan 31, 2025
1 parent
6056e9a
commit d1c3f7a
Showing
2 changed files
with
36 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* | ||
* Copyright 2024 elementary, Inc. <https://elementary.io> | ||
* Copyright (c) 2013 Mario Guerriero <[email protected]> | ||
* | ||
* 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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters