Skip to content

Commit 028e373

Browse files
authored
Gtk4Prep: ProjectChooserButton (#1753)
1 parent 5ccfadb commit 028e373

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

src/Widgets/ChooseProjectButton.vala

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
2424
private Gtk.Label label_widget;
2525
private Gtk.ListBox project_listbox;
2626

27-
public ActionGroup toplevel_action_group { get; construct; }
2827
public signal void project_chosen ();
2928

3029
construct {
31-
realize.connect (() => {
32-
toplevel_action_group = get_action_group (Scratch.MainWindow.ACTION_GROUP);
33-
assert_nonnull (toplevel_action_group);
34-
});
3530

3631
var img = new Gtk.Image () {
3732
gicon = new ThemedIcon ("git-symbolic"),
@@ -142,23 +137,6 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
142137
}
143138
});
144139

145-
project_listbox.remove.connect ((row) => {
146-
var project_row = row as ProjectRow;
147-
var current_project = Scratch.Services.GitManager.get_instance ().active_project_path;
148-
if (project_row.project_path == current_project) {
149-
Scratch.Services.GitManager.get_instance ().active_project_path = "";
150-
// Label and active_path will be updated automatically
151-
}
152-
});
153-
154-
project_listbox.row_activated.connect ((row) => {
155-
var project_entry = ((ProjectRow) row);
156-
toplevel_action_group.activate_action (
157-
Scratch.MainWindow.ACTION_SET_ACTIVE_PROJECT,
158-
new Variant.string (project_entry.project_path)
159-
);
160-
});
161-
162140
toggled.connect (() => {
163141
if (active) {
164142
unowned var active_path = Scratch.Services.GitManager.get_instance ().active_project_path;
@@ -219,16 +197,28 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
219197
);
220198
}
221199

200+
private Gtk.GestureMultiPress button_controller;
201+
222202
class construct {
223203
set_css_name (Gtk.STYLE_CLASS_MENUITEM);
224204
}
225205

226206
construct {
227-
check_button = new Gtk.CheckButton.with_label (Path.get_basename (project_path));
207+
can_focus = true;
208+
action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_SET_ACTIVE_PROJECT;
209+
action_target = new Variant.string (project_path);
210+
211+
check_button = new Gtk.CheckButton.with_label (Path.get_basename (project_path)) {
212+
can_focus = false
213+
};
228214
add (check_button);
229-
check_button.button_release_event.connect (() => {
215+
216+
button_controller = new Gtk.GestureMultiPress (check_button) {
217+
propagation_phase = CAPTURE,
218+
button = 0
219+
};
220+
button_controller.released.connect (() => {
230221
activate ();
231-
return Gdk.EVENT_PROPAGATE;
232222
});
233223

234224
show_all ();

0 commit comments

Comments
 (0)