1- /* -
2- * Copyright (c) 2021-2026 elementary Inc. (https://elementary.io)
3- *
4- * This program is free software: you can redistribute it and/or modify
5- * it under the terms of the GNU General Public License as published by
6- * the Free Software Foundation, either version 3 of the License, or
7- * (at your option) any later version.
8- *
9- * This program is distributed in the hope that it will be useful,
10- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12- * GNU General Public License for more details.
13- *
14- * You should have received a copy of the GNU General Public License
15- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16- *
1+ /*
2+ * SPDX-License-Identifier: GPL-3.0-or-later
3+ * SPDX-FileCopyrightText: 2021-2026 elementary Inc. (https://elementary.io)
174 */
185
19- public class Code.ChooseProjectButton : Gtk .MenuButton {
6+ public class Code.ChooseProjectButton : Gtk .Bin {
207 public bool cloning_in_progress { get ; set ; }
218
229 private const string NO_PROJECT_SELECTED = N_ ("No Project Selected ");
@@ -27,14 +14,10 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
2714 public signal void project_chosen ();
2815
2916 construct {
30-
31- var img = new Gtk .Image () {
32- gicon = new ThemedIcon (" git-symbolic" ),
33- icon_size = Gtk . IconSize . SMALL_TOOLBAR
34- };
17+ var img = new Gtk .Image .from_icon_name (" git-symbolic" , SMALL_TOOLBAR );
3518
3619 label_widget = new Gtk .Label (_(NO_PROJECT_SELECTED )) {
37- ellipsize = Pango . EllipsizeMode . MIDDLE ,
20+ ellipsize = MIDDLE ,
3821 xalign = 0.0f ,
3922 hexpand = true
4023 };
@@ -51,11 +34,11 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
5134 box. add (img);
5235 box. add (label_widget);
5336 box. add (cloning_spinner);
54- add (box);
5537
5638 project_listbox = new Gtk .ListBox () {
57- selection_mode = Gtk . SelectionMode . SINGLE
39+ selection_mode = SINGLE
5840 };
41+
5942 var project_filter = new Gtk .SearchEntry () {
6043 margin_top = 12 ,
6144 margin_bottom = 6 ,
@@ -74,7 +57,8 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
7457 });
7558
7659 var project_scrolled = new Gtk .ScrolledWindow (null , null ) {
77- hscrollbar_policy = Gtk . PolicyType . NEVER ,
60+ child = project_listbox,
61+ hscrollbar_policy = NEVER ,
7862 hexpand = true ,
7963 vexpand = true ,
8064 margin_top = 3 ,
@@ -83,8 +67,6 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
8367 propagate_natural_height = true
8468 };
8569
86- project_scrolled.add (project_listbox );
87-
8870 var add_folder_button = new PopoverMenuItem (_(" Open Folder…" )) {
8971 action_name = Scratch . MainWindow . ACTION_PREFIX + Scratch . MainWindow . ACTION_OPEN_PROJECT ,
9072 icon_name = " folder-open-symbolic" ,
@@ -95,20 +77,25 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
9577 icon_name = " git-symbolic"
9678 };
9779
98- var popover_content = new Gtk .Box (Gtk . Orientation . VERTICAL , 0 );
80+ var popover_content = new Gtk .Box (VERTICAL , 0 );
9981 popover_content.add (project_filter );
10082 popover_content.add (project_scrolled );
10183 popover_content.add (new Gtk .Separator (HORIZONTAL ));
10284 popover_content.add (add_folder_button );
10385 popover_content.add (clone_button );
104-
10586 popover_content.show_all ();
10687
107- var project_popover = new Gtk .Popover (this ) {
108- position = Gtk . PositionType . BOTTOM ,
88+ var project_popover = new Gtk .Popover (null ) {
89+ position = BOTTOM ,
10990 child = popover_content
11091 };
111- popover = project_popover;
92+
93+ var menu_button = new Gtk .MenuButton () {
94+ child = box,
95+ popover = project_popover
96+ };
97+
98+ child = menu_button;
11299
113100 // Initialise with any pre-existing projects (needed for second and subsequent window)
114101 var git_manager = Scratch.Services.GitManager.get_instance ();
@@ -137,8 +124,8 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
137124 }
138125 });
139126
140- toggled .connect (() => {
141- if (active) {
127+ menu_button.activate .connect (() => {
128+ if (menu_button . active) {
142129 unowned var active_path = Scratch . Services . GitManager . get_instance (). active_project_path;
143130 foreach (var child in project_listbox. get_children ()) {
144131 var project_row = ((ProjectRow ) child);
@@ -180,7 +167,7 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
180167 }
181168
182169 set {
183- check_button. active = value ;
170+ check_button. active = value ;
184171 }
185172 }
186173
@@ -211,7 +198,8 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
211198 check_button = new Gtk .CheckButton .with_label (Path . get_basename (project_path)) {
212199 can_focus = false
213200 };
214- add (check_button);
201+
202+ child = check_button;
215203
216204 button_controller = new Gtk .GestureMultiPress (check_button) {
217205 propagation_phase = CAPTURE ,
0 commit comments