Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 25 additions & 37 deletions src/Widgets/ChooseProjectButton.vala
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
/*
* 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");
Expand All @@ -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
};
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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 ();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -180,7 +167,7 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
}

set {
check_button.active = value;
check_button.active = value;
}
}

Expand Down Expand Up @@ -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,
Expand Down
Loading