Skip to content

Commit

Permalink
feat: add new placeholder and dialog to replace
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Sep 26, 2024
1 parent 389156c commit 75b0b29
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 58 deletions.
4 changes: 2 additions & 2 deletions data/Application.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ button.pathbar {
padding: 0 6px;
}

.combo {
padding: 2.5px 3px;
.linked .combo {
padding: 2.5px 3px;
}
3 changes: 1 addition & 2 deletions src/API/IFileOperations.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace Taxi {

public signal void operation_added (IOperationInfo operation);
public signal void operation_removed (IOperationInfo operation);
public signal int ask_overwrite (File destination);


public async abstract bool delete_recursive (
File file,
Cancellable? cancellable
Expand Down
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Taxi.Taxi : Gtk.Application {

settings.bind ("maximized", main_window, "maximized", SettingsBindFlags.SET);

main_window.show ();
main_window.present ();
}

public static int main (string[] args) {
Expand Down
38 changes: 37 additions & 1 deletion src/Backend/FileOperations.vala
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace Taxi {
} else if (file_type == FileType.REGULAR) {
var tmp_flag = *flags;
if (*flags == FileCopyFlags.NONE && destination.query_exists ()) {
switch ((ConflictFlag)ask_overwrite (destination)) {
switch ((ConflictFlag) ask_overwrite (destination)) {
case ConflictFlag.REPLACE_ALL:
*flags = FileCopyFlags.OVERWRITE;
tmp_flag = *flags;
Expand All @@ -138,6 +138,7 @@ namespace Taxi {
return;
}
}

yield source.copy_async (
destination,
tmp_flag,
Expand All @@ -149,4 +150,39 @@ namespace Taxi {
}
}
}

private int ask_overwrite (File destination) {
var message_dialog = new Granite.MessageDialog (
_("Replace existing file?"),
_("<i>\"%s\"</i> already exists. You can replace this file, replace all conflicting files or choose not to replace the file by skipping.".printf (destination.get_basename ())),
new ThemedIcon ("dialog-warning"),
Gtk.ButtonsType.CANCEL
) {
modal = true
};

var replace_all_button = new Gtk.Button.with_label (_("Replace All Conflicts"));
message_dialog.add_action_widget (replace_all_button, ConflictFlag.REPLACE_ALL);

var skip_button = new Gtk.Button.with_label (_("Skip"));
message_dialog.add_action_widget (skip_button, ConflictFlag.SKIP);

var replace_button = new Gtk.Button.with_label (_("Replace"));
replace_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
message_dialog.add_action_widget (replace_button, ConflictFlag.REPLACE);

message_dialog.show ();

int response = 0;
var loop = new MainLoop ();
message_dialog.response.connect ((response_id) => {
response = response_id;
message_dialog.destroy ();
loop.quit();
});

loop.run();

return response;
}
}
71 changes: 31 additions & 40 deletions src/Frontend/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
private Gtk.MenuButton bookmark_menu_button;
private Gtk.Stack alert_stack;
private ConnectBox connect_box;
private Granite.Placeholder welcome;
private FilePane local_pane;
private FilePane remote_pane;
private GLib.Uri conn_uri;
private GLib.Settings saved_state;
private Gtk.Popover bookmark_popover;
private Gtk.Box welcome_box;
private Gtk.Label title_label;

public MainWindow (
Gtk.Application application,
Expand Down Expand Up @@ -83,12 +84,8 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
child = operations_button
};

bookmark_list = new Gtk.Box (Gtk.Orientation.VERTICAL, 0) {
margin_top = 6,
margin_bottom = 6,
margin_start = 3,
margin_end = 3
};
bookmark_list = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
bookmark_list.add_css_class (Granite.STYLE_CLASS_MENU);

var bookmark_scrollbox = new Gtk.ScrolledWindow () {
child = bookmark_list,
Expand All @@ -97,7 +94,7 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
propagate_natural_height = true,
};

var bookmark_popover = new Gtk.Popover () {
bookmark_popover = new Gtk.Popover () {
child = bookmark_scrollbox,
width_request = 250
};
Expand All @@ -108,6 +105,7 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
popover = bookmark_popover,
valign = CENTER
};
bookmark_menu_button.add_css_class (Granite.STYLE_CLASS_LARGE_ICONS);

update_bookmark_menu ();

Expand All @@ -118,11 +116,27 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
header_bar.pack_start (spinner_revealer);
header_bar.pack_start (bookmark_menu_button);

welcome = new Granite.Placeholder (_("Connect")) {
description = _("Type a URL and press 'Enter' to connect to a server."),
vexpand = true
var app_icon = new Gtk.Image.from_icon_name ("com.github.alecaddd.taxi") {
pixel_size = 64
};

title_label = new Gtk.Label (_("Connect"));
title_label.add_css_class (Granite.STYLE_CLASS_H1_LABEL);

var description_label = new Gtk.Label (_("Type a URL and press 'Enter' to\nconnect to a server.")) {
justify = CENTER
};

welcome_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6) {
hexpand = true,
vexpand = true,
halign = CENTER,
valign = CENTER
};
welcome_box.append (app_icon);
welcome_box.append (title_label);
welcome_box.append (description_label);

local_pane = new FilePane ();
local_pane.open.connect (on_local_open);
local_pane.navigate.connect (on_local_navigate);
Expand All @@ -146,7 +160,7 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
size_group.add_widget (remote_pane);

alert_stack = new Gtk.Stack ();
alert_stack.add_child (welcome);
alert_stack.add_child (welcome_box);
alert_stack.add_child (outer_box);

toast = new Granite.Toast ("");
Expand All @@ -168,15 +182,12 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {

child = grid;

saved_state = new GLib.Settings ("com.github.alecaddd.taxi.state");

connect_box.connect_initiated.connect (on_connect_initiated);
connect_box.ask_hostname.connect (on_ask_hostname);
connect_box.bookmarked.connect (bookmark);

file_operation.operation_added.connect (popover.add_operation);
file_operation.operation_removed.connect (popover.remove_operation);
// file_operation.ask_overwrite.connect (on_ask_overwrite);

popover.operations_pending.connect (show_spinner);
popover.operations_finished.connect (hide_spinner);
Expand All @@ -194,8 +205,8 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
);
conn_uri = uri;
} else {
alert_stack.visible_child = welcome;
welcome.title = _("Could not connect to '%s'").printf (uri.to_string ());
alert_stack.visible_child = welcome_box;
title_label.label = _("Could not connect to '%s'").printf (uri.to_string ());
}
hide_spinner ();
});
Expand Down Expand Up @@ -239,9 +250,10 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
halign = START
}
};
bookmark_item.add_css_class (Granite.STYLE_CLASS_FLAT);
bookmark_item.add_css_class (Granite.STYLE_CLASS_MENUITEM);
bookmark_item.clicked.connect (() => {
connect_box.go_to_uri (uri);
bookmark_popover.popdown ();
});

bookmark_list.append (bookmark_item);
Expand Down Expand Up @@ -388,25 +400,4 @@ class Taxi.MainWindow : Gtk.ApplicationWindow {
private GLib.Uri on_ask_hostname () {
return conn_uri;
}

// private int on_ask_overwrite (File destination) {
// var dialog = new Gtk.MessageDialog (
// this,
// Gtk.DialogFlags.MODAL,
// Gtk.MessageType.QUESTION,
// Gtk.ButtonsType.NONE,
// _("Replace existing file?")
// );
// dialog.format_secondary_markup (
// _("<i>\"%s\"</i> already exists. You can replace this file, replace all conflicting files or choose not to replace the file by skipping.".printf (destination.get_basename ()))
// );
// dialog.add_button (_("Replace All Conflicts"), 2);
// dialog.add_button (_("Skip"), 0);
// dialog.add_button (_("Replace"), 1);
// dialog.get_widget_for_response (1).get_style_context ().add_class ("suggested-action");

// var response = dialog.run ();
// dialog.destroy ();
// return response;
// }
}
1 change: 0 additions & 1 deletion src/Frontend/Widgets/ConnectBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace Taxi {
string[] entries = {"FTP", "SFTP", "DAV", "AFP"};

protocol_combobox = new Gtk.ComboBoxText ();
protocol_combobox.add_css_class ("combobox-linked");
foreach (var entry in entries) {
protocol_combobox.append_text (entry);
}
Expand Down
21 changes: 10 additions & 11 deletions src/Frontend/Widgets/OperationsPopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,26 @@ namespace Taxi {
grid.attach (placeholder, 0, 0);
}

public void add_operation (IOperationInfo operation) {
public async void add_operation (IOperationInfo operation) {
if (grid.get_child_at (0, 0) == placeholder) {
grid.remove (placeholder);
operations_pending ();
}
var row = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
operation_map.set (operation, row);

row.append (new Gtk.Label (operation.get_file_name ()));
var icon = yield operation.get_file_icon ();
row.append (new Gtk.Image.from_gicon (icon));

operation.get_file_icon.begin ((obj, res) => {
row.append (
new Gtk.Image.from_gicon (
operation.get_file_icon.end (res)
)
);
row.append (new Gtk.Label (operation.get_file_name ()) {
margin_start = 6
});

var cancel = new Gtk.Image.from_icon_name ("process-stop-symbolic");
var cancel_container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
cancel_container.append (cancel);
var cancel_container = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0) {
hexpand = true,
halign = END
};
cancel_container.append (new Gtk.Image.from_icon_name ("process-stop-symbolic"));

var click_controller = new Gtk.GestureClick ();
cancel_container.add_controller (click_controller);
Expand Down

0 comments on commit 75b0b29

Please sign in to comment.