Skip to content

Cloning: Show progress in sidebar #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
25 changes: 11 additions & 14 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -1055,34 +1055,31 @@ namespace Scratch {
// Persist last entries (not necessarily valid)
Scratch.settings.set_string ("default-remote", clone_dialog.get_remote ());
Scratch.settings.set_string ("default-projects-folder", clone_dialog.get_projects_folder ());
// Clone dialog show spinner during cloning so keep visible
//TODO Show more information re progress using Ggit callbacks
if (res == Gtk.ResponseType.APPLY && clone_dialog.can_clone) {
clone_dialog.cloning_in_progress = true;
sidebar.cloning_in_progress = true;
clone_dialog.hide ();
var uri = clone_dialog.get_valid_source_repository_uri ();
var target = clone_dialog.get_valid_target ();
git_manager.clone_repository.begin (
uri,
target,
(obj, res) => {
clone_dialog.cloning_in_progress = false;
sidebar.cloning_in_progress = false;
File? workdir = null;
string? error = null;
if (git_manager.clone_repository.end (res, out workdir, out error)) {
open_folder (workdir);
clone_dialog.destroy ();
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Repository %s successfully cloned").printf (uri),
_("Local repository working directory is %s").printf (workdir.get_uri ()),
"dialog-information",
Gtk.ButtonsType.CLOSE
) {
transient_for = this
};
message_dialog.response.connect (message_dialog.destroy);
message_dialog.present ();
if (this.is_active) {
sidebar.notify_cloning_success ();
} else {
var notification = new Notification (_("Cloning completed"));
notification.set_body (_("Clone successfully created in %s").printf (target));
notification.set_icon (new ThemedIcon ("process-completed-symbolic"));
app.send_notification ("cloning-finished-%s".printf (target), notification);
}
} else {
clone_dialog.hide ();
var message_dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("Unable to clone %s").printf (uri),
error,
Expand Down
22 changes: 16 additions & 6 deletions src/Widgets/ChooseProjectButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

public class Code.ChooseProjectButton : Gtk.MenuButton {
public bool cloning_in_progress { get; set; }

private const string NO_PROJECT_SELECTED = N_("No Project Selected");
private const string PROJECT_TOOLTIP = N_("Active Git Project: %s");
private Gtk.Label label_widget;
Expand All @@ -32,15 +34,23 @@ public class Code.ChooseProjectButton : Gtk.MenuButton {

label_widget = new Gtk.Label (_(NO_PROJECT_SELECTED)) {
ellipsize = Pango.EllipsizeMode.MIDDLE,
xalign = 0.0f
xalign = 0.0f,
hexpand = true
};

var cloning_spinner = new Gtk.Spinner () {
halign = END
};
bind_property ("cloning-in-progress", cloning_spinner, "active");

var grid = new Gtk.Grid () {
halign = Gtk.Align.START
var box = new Gtk.Box (HORIZONTAL, 3) {
hexpand = true,
vexpand = false
};
grid.add (img);
grid.add (label_widget);
add (grid);
box.add (img);
box.add (label_widget);
box.add (cloning_spinner);
add (box);

project_listbox = new Gtk.ListBox () {
selection_mode = Gtk.SelectionMode.SINGLE
Expand Down
20 changes: 20 additions & 0 deletions src/Widgets/Sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@ public class Code.Sidebar : Gtk.Grid {
public Code.ChooseProjectButton choose_project_button { get; private set; }
public Hdy.HeaderBar headerbar { get; private set; }
public GLib.MenuModel project_menu_model { get; construct; }
// May show progress in different way in future
public bool cloning_in_progress {
get {
return choose_project_button.cloning_in_progress;
}

set {
choose_project_button.cloning_in_progress = value;
}
}

private Gtk.StackSwitcher stack_switcher;
private Granite.Widgets.Toast cloning_success_toast;

construct {
orientation = Gtk.Orientation.VERTICAL;
Expand All @@ -38,6 +49,10 @@ public class Code.Sidebar : Gtk.Grid {
valign = Gtk.Align.CENTER
};

cloning_success_toast = new Granite.Widgets.Toast (_("Cloning complete")) {
halign = END
};

headerbar = new Hdy.HeaderBar () {
custom_title = choose_project_button,
show_close_button = true
Expand Down Expand Up @@ -80,6 +95,7 @@ public class Code.Sidebar : Gtk.Grid {
actionbar.pack_start (project_menu_button);

add (headerbar);
add (cloning_success_toast);
add (stack_switcher);
add (stack);
add (actionbar);
Expand Down Expand Up @@ -161,4 +177,8 @@ public class Code.Sidebar : Gtk.Grid {
public void remove_tab (Code.PaneSwitcher tab) {
stack.remove (tab);
}

public void notify_cloning_success () {
cloning_success_toast.send_notification ();
}
}