From 2b8b02a0dea14ff1d16bc12af03308048d3b2639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Fri, 10 Jul 2026 10:11:16 -0700 Subject: [PATCH] ChooseProjectButton: code style and GTK4 prep --- src/Widgets/ChooseProjectButton.vala | 62 +++++++++++----------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/src/Widgets/ChooseProjectButton.vala b/src/Widgets/ChooseProjectButton.vala index b93affe78..132e2c74d 100644 --- a/src/Widgets/ChooseProjectButton.vala +++ b/src/Widgets/ChooseProjectButton.vala @@ -1,22 +1,9 @@ -/*- - * Copyright (c) 2021-2026 elementary Inc. (https://elementary.io) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2021-2026 elementary Inc. (https://elementary.io) */ -public class Code.ChooseProjectButton : Gtk.MenuButton { +public class Code.ChooseProjectButton : Gtk.Bin { public bool cloning_in_progress { get; set; } private const string NO_PROJECT_SELECTED = N_("No Project Selected"); @@ -27,14 +14,10 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { public signal void project_chosen (); construct { - - var img = new Gtk.Image () { - gicon = new ThemedIcon ("git-symbolic"), - icon_size = Gtk.IconSize.SMALL_TOOLBAR - }; + var img = new Gtk.Image.from_icon_name ("git-symbolic", SMALL_TOOLBAR); label_widget = new Gtk.Label (_(NO_PROJECT_SELECTED)) { - ellipsize = Pango.EllipsizeMode.MIDDLE, + ellipsize = MIDDLE, xalign = 0.0f, hexpand = true }; @@ -51,11 +34,11 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { box.add (img); box.add (label_widget); box.add (cloning_spinner); - add (box); project_listbox = new Gtk.ListBox () { - selection_mode = Gtk.SelectionMode.SINGLE + selection_mode = SINGLE }; + var project_filter = new Gtk.SearchEntry () { margin_top = 12, margin_bottom = 6, @@ -74,7 +57,8 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { }); var project_scrolled = new Gtk.ScrolledWindow (null, null) { - hscrollbar_policy = Gtk.PolicyType.NEVER, + child = project_listbox, + hscrollbar_policy = NEVER, hexpand = true, vexpand = true, margin_top = 3, @@ -83,8 +67,6 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { propagate_natural_height = true }; - project_scrolled.add (project_listbox); - var add_folder_button = new PopoverMenuItem (_("Open Folder…")) { action_name = Scratch.MainWindow.ACTION_PREFIX + Scratch.MainWindow.ACTION_OPEN_PROJECT, icon_name = "folder-open-symbolic", @@ -95,20 +77,25 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { icon_name = "git-symbolic" }; - var popover_content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + var popover_content = new Gtk.Box (VERTICAL, 0); popover_content.add (project_filter); popover_content.add (project_scrolled); popover_content.add (new Gtk.Separator (HORIZONTAL)); popover_content.add (add_folder_button); popover_content.add (clone_button); - popover_content.show_all (); - var project_popover = new Gtk.Popover (this) { - position = Gtk.PositionType.BOTTOM, + var project_popover = new Gtk.Popover (null) { + position = BOTTOM, child = popover_content }; - popover = project_popover; + + var menu_button = new Gtk.MenuButton () { + child = box, + popover = project_popover + }; + + child = menu_button; // Initialise with any pre-existing projects (needed for second and subsequent window) var git_manager = Scratch.Services.GitManager.get_instance (); @@ -137,8 +124,8 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { } }); - toggled.connect (() => { - if (active) { + menu_button.activate.connect (() => { + if (menu_button.active) { unowned var active_path = Scratch.Services.GitManager.get_instance ().active_project_path; foreach (var child in project_listbox.get_children ()) { var project_row = ((ProjectRow) child); @@ -180,7 +167,7 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { } set { - check_button.active = value; + check_button.active = value; } } @@ -211,7 +198,8 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { check_button = new Gtk.CheckButton.with_label (Path.get_basename (project_path)) { can_focus = false }; - add (check_button); + + child = check_button; button_controller = new Gtk.GestureMultiPress (check_button) { propagation_phase = CAPTURE,