Skip to content

Commit fb5d3fc

Browse files
authored
BracketsCompletion: misc cleanup (#1564)
1 parent 2b8a479 commit fb5d3fc

1 file changed

Lines changed: 28 additions & 41 deletions

File tree

plugins/brackets-completion/brackets-completion.vala

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,22 @@
1-
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
2-
/***
3-
BEGIN LICENSE
4-
5-
Copyright (C) 2013 Mario Guerriero <mario@elementaryos.org>
6-
This program is free software: you can redistribute it and/or modify it
7-
under the terms of the GNU Lesser General Public License version 3, as published
8-
by the Free Software Foundation.
9-
10-
This program is distributed in the hope that it will be useful, but
11-
WITHOUT ANY WARRANTY; without even the implied warranties of
12-
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13-
PURPOSE. See the GNU General Public License for more details.
14-
15-
You should have received a copy of the GNU General Public License along
16-
with this program. If not, see <http://www.gnu.org/licenses/>
17-
18-
END LICENSE
19-
***/
1+
/*
2+
* SPDX-License-Identifier: LGPL-3.0-or-later
3+
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
4+
* 2013 Mario Guerriero <mario@elementaryos.org>
5+
*/
206

217
public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Services.ActivatablePlugin {
22-
Gee.HashMap<string, string> brackets;
23-
Gee.HashMap<uint, string> keys;
24-
const string[] VALID_NEXT_CHARS = {
8+
private const string[] VALID_NEXT_CHARS = {
259
"", " ", "\b", "\r", "\n", "\t", ",", ".", ";", ":"
2610
};
2711

28-
Gtk.TextBuffer current_buffer;
29-
Scratch.Widgets.SourceView current_source_view;
30-
31-
private string previous_selection = "";
32-
33-
Scratch.Services.Interface plugins;
3412
public Object object { owned get; construct; }
3513

36-
public void update_state () {}
14+
private Gee.HashMap<string, string> brackets;
15+
private Gee.HashMap<uint, string> keys;
16+
private Gtk.TextBuffer current_buffer;
17+
private Scratch.Services.Interface plugins;
18+
private Scratch.Widgets.SourceView current_source_view;
19+
private string previous_selection = "";
3720

3821
public void activate () {
3922
brackets = new Gee.HashMap<string, string> ();
@@ -63,7 +46,9 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
6346
plugins.hook_document.disconnect (on_hook_document);
6447
}
6548

66-
void on_hook_document (Scratch.Services.Document doc) {
49+
public void update_state () {}
50+
51+
private void on_hook_document (Scratch.Services.Document doc) {
6752
current_buffer = doc.source_view.buffer;
6853

6954
if (current_source_view != null) {
@@ -79,7 +64,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
7964
current_source_view.backspace.connect (on_backspace);
8065
}
8166

82-
string get_next_char () {
67+
private string get_next_char () {
8368
Gtk.TextIter start, end;
8469

8570
current_buffer.get_selection_bounds (null, out end);
@@ -93,7 +78,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
9378
return current_buffer.get_text (start, end, true) ;
9479
}
9580

96-
string get_previous_char () {
81+
private string get_previous_char () {
9782
Gtk.TextIter start, end;
9883

9984
current_buffer.get_selection_bounds (out start, null);
@@ -107,7 +92,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
10792
return current_buffer.get_text (start, end, true) ;
10893
}
10994

110-
void on_backspace () {
95+
private void on_backspace () {
11196
if (!current_buffer.has_selection) {
11297
string left_char = get_previous_char ();
11398
string right_char = get_next_char ();
@@ -123,7 +108,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
123108
}
124109
}
125110

126-
void complete_brackets (string opening_bracket) {
111+
private void complete_brackets (string opening_bracket) {
127112
Gtk.TextIter start, end;
128113

129114
if (opening_bracket == "'" || opening_bracket == "\"") {
@@ -154,13 +139,13 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
154139
current_buffer.end_user_action ();
155140
}
156141

157-
bool has_valid_next_char (string next_char) {
142+
private bool has_valid_next_char (string next_char) {
158143
return next_char in VALID_NEXT_CHARS ||
159144
next_char in brackets.values ||
160145
brackets.has_key (next_char);
161146
}
162147

163-
void delete_next_char () {
148+
private void delete_next_char () {
164149
current_buffer.begin_user_action ();
165150

166151
Gtk.TextIter start;
@@ -178,7 +163,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
178163
current_buffer.end_user_action ();
179164
}
180165

181-
bool on_key_down (Gdk.EventKey event) {
166+
private bool on_key_down (Gdk.EventKey event) {
182167
if (Gdk.ModifierType.MOD1_MASK in event.state || Gdk.ModifierType.CONTROL_MASK in event.state) {
183168
return false;
184169
}
@@ -198,7 +183,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
198183
return false;
199184
}
200185

201-
void check_bracket_indent () {
186+
private void check_bracket_indent () {
202187
var next_char = get_next_char ();
203188
if (next_char in brackets.values) {
204189
Gtk.TextIter start, end;
@@ -236,7 +221,7 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
236221
}
237222
}
238223

239-
void on_event_after (Gdk.Event root_event) {
224+
private void on_event_after (Gdk.Event root_event) {
240225
if (root_event.type != Gdk.EventType.KEY_PRESS) {
241226
return;
242227
}
@@ -278,6 +263,8 @@ public class Scratch.Plugins.BracketsCompletion : Peas.ExtensionBase, Scratch.Se
278263
[ModuleInit]
279264
public void peas_register_types (GLib.TypeModule module) {
280265
var objmodule = module as Peas.ObjectModule;
281-
objmodule.register_extension_type (typeof (Scratch.Services.ActivatablePlugin),
282-
typeof (Scratch.Plugins.BracketsCompletion));
266+
objmodule.register_extension_type (
267+
typeof (Scratch.Services.ActivatablePlugin),
268+
typeof (Scratch.Plugins.BracketsCompletion)
269+
);
283270
}

0 commit comments

Comments
 (0)