Skip to content

Commit

Permalink
Implement the stop loading button
Browse files Browse the repository at this point in the history
  • Loading branch information
sapoturge committed Dec 7, 2024
1 parent 5d29ea8 commit 2cf9b59
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public class FroggumApplication : Gtk.Application {

var new_button = new Gtk.Button.from_icon_name ("list-add-symbolic");
new_button.clicked.connect (() => {
new_tab ();
make_new_tab (null);
});
new_button.tooltip_text = _("New icon");

Expand All @@ -171,14 +171,15 @@ public class FroggumApplication : Gtk.Application {
editor.vexpand = true;
var tab = notebook.append (editor);
tab.title = real_file.get_basename ();
editor.stop_loading.connect (() => make_new_tab (tab));
if (file == focused_file) {
focused = tab;
}
}
}

if (notebook.n_pages == 0 && !will_open) {
new_tab ();
make_new_tab (null);
} else if (focused != null) {
notebook.selected_page = focused;
}
Expand Down Expand Up @@ -216,6 +217,7 @@ public class FroggumApplication : Gtk.Application {
editor.hexpand = true;
editor.vexpand = true;
var tab = notebook.append (editor);
editor.stop_loading.connect (() => make_new_tab (tab));
tab.title = file.get_basename ();
}

Expand All @@ -238,6 +240,7 @@ public class FroggumApplication : Gtk.Application {
editor.vexpand = true;
var tab = notebook.append (editor);
tab.title = file.get_basename ();
editor.stop_loading.connect (() => make_new_tab (tab));
}

recalculate_open_files ();
Expand Down Expand Up @@ -265,6 +268,7 @@ public class FroggumApplication : Gtk.Application {
var new_tab = notebook.add_page (editor, tab);
new_tab.title = _("New Image");
notebook.close_page (tab);
editor.stop_loading.connect (() => make_new_tab (new_tab));
}

private void open_image (Adw.TabPage tab) {
Expand All @@ -278,6 +282,7 @@ public class FroggumApplication : Gtk.Application {
editor.hexpand = true;
editor.vexpand = true;
var new_tab = notebook.add_page (editor, tab);
editor.stop_loading.connect (() => make_new_tab (new_tab));
new_tab.title = file.get_basename ();
notebook.close_page (tab);
recalculate_open_files ();
Expand All @@ -288,9 +293,15 @@ public class FroggumApplication : Gtk.Application {
});
}

private void new_tab () {
private void make_new_tab (Adw.TabPage? old_tab) {
var inner_layout = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 12);
var tab = notebook.append (inner_layout);
Adw.TabPage tab;
if (old_tab == null) {
tab = notebook.append (inner_layout);
} else {
tab = notebook.add_page (inner_layout, old_tab);
notebook.close_page (old_tab);
}
tab.title = _("New Image");

var title = new Gtk.Label (_("Create a new icon:"));
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/EditorView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class EditorView : Gtk.Box {
private Gtk.Button new_button;
private ErrorBar error_bar;

public signal void stop_loading ();

public EditorView (Image image) {
this.image = image;
selection = new Gtk.SingleSelection (image.tree);
Expand Down Expand Up @@ -289,6 +291,7 @@ public class EditorView : Gtk.Box {
side_bar.append (task_bar);

error_bar = new ErrorBar ();
error_bar.stop_loading.connect (() => stop_loading ());

viewport = new Viewport ();
var scrolled = new Gtk.ScrolledWindow ();
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/ErrorBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class ErrorBar : Adw.Bin {
halign = Gtk.Align.END,
};
var stop_loading_button = new Gtk.Button.with_label (_("Stop loading"));
stop_loading_button.activate.connect (() => stop_loading ());
stop_loading_button.clicked.connect (() => stop_loading ());
stop_loading_button.add_css_class ("suggested-action");
button_box.append (stop_loading_button);
container.append (header);
Expand Down

0 comments on commit 2cf9b59

Please sign in to comment.