Skip to content

Commit c941d9c

Browse files
jeremypwzeebok
andauthored
Cloning: Show progress in sidebar (#1641)
* Fix shortcut clash * Add toast and spinner to sidebar * Align widgets at END * Revert "Fix shortcut clash" This reverts commit accd80e. * Send notification if window not active --------- Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
1 parent f9ca61b commit c941d9c

3 files changed

Lines changed: 47 additions & 20 deletions

File tree

src/MainWindow.vala

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,34 +1055,31 @@ namespace Scratch {
10551055
// Persist last entries (not necessarily valid)
10561056
Scratch.settings.set_string ("default-remote", clone_dialog.get_remote ());
10571057
Scratch.settings.set_string ("default-projects-folder", clone_dialog.get_projects_folder ());
1058-
// Clone dialog show spinner during cloning so keep visible
10591058
//TODO Show more information re progress using Ggit callbacks
10601059
if (res == Gtk.ResponseType.APPLY && clone_dialog.can_clone) {
1061-
clone_dialog.cloning_in_progress = true;
1060+
sidebar.cloning_in_progress = true;
1061+
clone_dialog.hide ();
10621062
var uri = clone_dialog.get_valid_source_repository_uri ();
10631063
var target = clone_dialog.get_valid_target ();
10641064
git_manager.clone_repository.begin (
10651065
uri,
10661066
target,
10671067
(obj, res) => {
1068-
clone_dialog.cloning_in_progress = false;
1068+
sidebar.cloning_in_progress = false;
10691069
File? workdir = null;
10701070
string? error = null;
10711071
if (git_manager.clone_repository.end (res, out workdir, out error)) {
10721072
open_folder (workdir);
10731073
clone_dialog.destroy ();
1074-
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
1075-
_("Repository %s successfully cloned").printf (uri),
1076-
_("Local repository working directory is %s").printf (workdir.get_uri ()),
1077-
"dialog-information",
1078-
Gtk.ButtonsType.CLOSE
1079-
) {
1080-
transient_for = this
1081-
};
1082-
message_dialog.response.connect (message_dialog.destroy);
1083-
message_dialog.present ();
1074+
if (this.is_active) {
1075+
sidebar.notify_cloning_success ();
1076+
} else {
1077+
var notification = new Notification (_("Cloning completed"));
1078+
notification.set_body (_("Clone successfully created in %s").printf (target));
1079+
notification.set_icon (new ThemedIcon ("process-completed-symbolic"));
1080+
app.send_notification ("cloning-finished-%s".printf (target), notification);
1081+
}
10841082
} else {
1085-
clone_dialog.hide ();
10861083
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
10871084
_("Unable to clone %s").printf (uri),
10881085
error,

src/Widgets/ChooseProjectButton.vala

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818

1919
public class Code.ChooseProjectButton : Gtk.MenuButton {
20+
public bool cloning_in_progress { get; set; }
21+
2022
private const string NO_PROJECT_SELECTED = N_("No Project Selected");
2123
private const string PROJECT_TOOLTIP = N_("Active Git Project: %s");
2224
private Gtk.Label label_widget;
@@ -32,15 +34,23 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {
3234

3335
label_widget = new Gtk.Label (_(NO_PROJECT_SELECTED)) {
3436
ellipsize = Pango.EllipsizeMode.MIDDLE,
35-
xalign = 0.0f
37+
xalign = 0.0f,
38+
hexpand = true
39+
};
40+
41+
var cloning_spinner = new Gtk.Spinner () {
42+
halign = END
3643
};
44+
bind_property ("cloning-in-progress", cloning_spinner, "active");
3745

38-
var grid = new Gtk.Grid () {
39-
halign = Gtk.Align.START
46+
var box = new Gtk.Box (HORIZONTAL, 3) {
47+
hexpand = true,
48+
vexpand = false
4049
};
41-
grid.add (img);
42-
grid.add (label_widget);
43-
add (grid);
50+
box.add (img);
51+
box.add (label_widget);
52+
box.add (cloning_spinner);
53+
add (box);
4454

4555
project_listbox = new Gtk.ListBox () {
4656
selection_mode = Gtk.SelectionMode.SINGLE

src/Widgets/Sidebar.vala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@ public class Code.Sidebar : Gtk.Grid {
2626
public Code.ChooseProjectButton choose_project_button { get; private set; }
2727
public Hdy.HeaderBar headerbar { get; private set; }
2828
public GLib.MenuModel project_menu_model { get; construct; }
29+
// May show progress in different way in future
30+
public bool cloning_in_progress {
31+
get {
32+
return choose_project_button.cloning_in_progress;
33+
}
34+
35+
set {
36+
choose_project_button.cloning_in_progress = value;
37+
}
38+
}
2939

3040
private Gtk.StackSwitcher stack_switcher;
41+
private Granite.Widgets.Toast cloning_success_toast;
3142

3243
construct {
3344
orientation = Gtk.Orientation.VERTICAL;
@@ -38,6 +49,10 @@ public class Code.Sidebar : Gtk.Grid {
3849
valign = Gtk.Align.CENTER
3950
};
4051

52+
cloning_success_toast = new Granite.Widgets.Toast (_("Cloning complete")) {
53+
halign = END
54+
};
55+
4156
headerbar = new Hdy.HeaderBar () {
4257
custom_title = choose_project_button,
4358
show_close_button = true
@@ -80,6 +95,7 @@ public class Code.Sidebar : Gtk.Grid {
8095
actionbar.pack_start (project_menu_button);
8196

8297
add (headerbar);
98+
add (cloning_success_toast);
8399
add (stack_switcher);
84100
add (stack);
85101
add (actionbar);
@@ -161,4 +177,8 @@ public class Code.Sidebar : Gtk.Grid {
161177
public void remove_tab (Code.PaneSwitcher tab) {
162178
stack.remove (tab);
163179
}
180+
181+
public void notify_cloning_success () {
182+
cloning_success_toast.send_notification ();
183+
}
164184
}

0 commit comments

Comments
 (0)