Make View Snapshots in Properties Page show app snapshots, or prompt to make a new snapshot

This commit is contained in:
Heliguy
2024-09-27 23:45:34 -04:00
parent 06a572daeb
commit db7641da42
5 changed files with 141 additions and 125 deletions

View File

@@ -267,7 +267,10 @@ class PropertiesPage(Adw.NavigationPage):
self.more_menu.popdown()
match row.get_child():
case self.view_snapshots:
print("not implemented")
snapshots_row = HostInfo.main_window.snapshots_row
snapshots_page = HostInfo.main_window.pages[snapshots_row]
HostInfo.main_window.activate_row(snapshots_row)
snapshots_page.show_snapshot(self.package)
case self.copy_launch_command:
try:
@@ -319,10 +322,6 @@ class PropertiesPage(Adw.NavigationPage):
self.reinstall = Gtk.Label(halign=Gtk.Align.START, label=_("Reinstall"))
# Apply
self.more_list.append(self.view_snapshots)
self.more_list.append(self.copy_launch_command)
self.more_list.append(self.show_details)
self.more_list.append(self.reinstall)
# Connections
self.more_list.connect("row-activated", self.more_menu_handler)

View File

@@ -4,83 +4,85 @@ using Adw 1;
template $NewSnapshotDialog : Adw.Dialog {
follows-content-size: true;
width-request: 400;
Adw.NavigationPage nav_page {
title: "No Title Set";
Adw.ToolbarView {
[top]
Adw.HeaderBar {
show-start-title-buttons: false;
show-end-title-buttons: false;
[start]
Button list_cancel_button {
label: _("Cancel");
}
[start]
ToggleButton search_button {
icon-name: "loupe-large-symbolic";
tooltip-text: _("Search Apps");
}
[end]
Button create_button {
sensitive: false;
label: _("Create");
styles ["suggested-action"]
}
}
[top]
Adw.Clamp {
SearchBar search_bar {
search-mode-enabled: bind search_button.active bidirectional;
key-capture-widget: template;
SearchEntry search_entry {
hexpand: true;
placeholder-text: _("Search Apps");
Adw.ToastOverlay toast_overlay {
Adw.NavigationPage nav_page {
title: "No Title Set";
Adw.ToolbarView {
[top]
Adw.HeaderBar {
show-start-title-buttons: false;
show-end-title-buttons: false;
[start]
Button list_cancel_button {
label: _("Cancel");
}
[start]
ToggleButton search_button {
icon-name: "loupe-large-symbolic";
tooltip-text: _("Search Apps");
}
[end]
Button create_button {
sensitive: false;
label: _("Create");
styles ["suggested-action"]
}
}
}
Adw.Clamp {
ScrolledWindow {
propagate-natural-height: true;
propagate-natural-width: true;
Box {
orientation: vertical;
Adw.EntryRow name_entry {
title: "No Title Set";
margin-start: 12;
margin-end: 12;
margin-top: 12;
margin-bottom: 12;
styles ["card"]
}
ListBox listbox {
valign: start;
margin-start: 12;
margin-end: 12;
// margin-top: 12;
margin-bottom: 12;
selection-mode: none;
styles ["boxed-list"]
[top]
Adw.Clamp {
SearchBar search_bar {
search-mode-enabled: bind search_button.active bidirectional;
key-capture-widget: template;
SearchEntry search_entry {
hexpand: true;
placeholder-text: _("Search Apps");
}
}
}
}
[bottom]
ActionBar {
revealed: bind search_button.visible;
[start]
Button select_all_button {
styles ["raised"]
Adw.ButtonContent {
label: _("Select All");
icon-name: "selection-mode-symbolic";
Adw.Clamp {
ScrolledWindow {
propagate-natural-height: true;
propagate-natural-width: true;
Box {
orientation: vertical;
Adw.EntryRow name_entry {
title: "No Title Set";
margin-start: 12;
margin-end: 12;
margin-top: 12;
margin-bottom: 12;
styles ["card"]
}
ListBox listbox {
valign: start;
margin-start: 12;
margin-end: 12;
// margin-top: 12;
margin-bottom: 12;
selection-mode: none;
styles ["boxed-list"]
}
}
}
}
[end]
Label total_selected_label {
label: "";
ellipsize: middle;
margin-end: 6;
visible: false;
[bottom]
ActionBar {
revealed: bind search_button.visible;
[start]
Button select_all_button {
styles ["raised"]
Adw.ButtonContent {
label: _("Select All");
icon-name: "selection-mode-symbolic";
}
}
[end]
Label total_selected_label {
label: "";
ellipsize: middle;
margin-end: 6;
visible: false;
}
}
}
}

View File

@@ -11,6 +11,7 @@ class NewSnapshotDialog(Adw.Dialog):
__gtype_name__ = "NewSnapshotDialog"
gtc = Gtk.Template.Child
toast_overlay = gtc()
nav_page = gtc()
list_cancel_button = gtc()
search_button = gtc()

View File

@@ -16,14 +16,14 @@ template $SnapshotPage : Adw.BreakpointBin {
Adw.NavigationPage {
title: _("Snapshots");
Stack status_stack {
Adw.NavigationSplitView split_view {
sidebar-width-fraction: 0.5;
max-sidebar-width: 999999999;
sidebar:
Adw.NavigationPage sidebar_navpage {
title: _("Snapshots");
Adw.ToastOverlay toast_overlay {
Adw.ToastOverlay toast_overlay {
Stack status_stack {
Adw.NavigationSplitView split_view {
sidebar-width-fraction: 0.5;
max-sidebar-width: 999999999;
sidebar:
Adw.NavigationPage sidebar_navpage {
title: _("Snapshots");
Adw.ToolbarView sidebar_tbv {
[top]
Adw.HeaderBar header_bar {
@@ -132,48 +132,48 @@ template $SnapshotPage : Adw.BreakpointBin {
}
}
}
}
;
}
Adw.ToolbarView no_snapshots {
[top]
Adw.HeaderBar {
[start]
$SidebarButton {}
[start]
Button status_open_button {
icon-name: "folder-open-symbolic";
tooltip-text: _("Open Snapshots Folder");
}
;
}
Adw.ToastOverlay no_snapshots_toast {
Adw.StatusPage {
title: _("No Snapshots");
description: _("Create a Snapshot to save the state of any Flatpak application");
icon-name: "snapshots-alt-symbolic";
Button status_new_button {
styles ["suggested-action", "pill"]
halign: center;
Adw.ButtonContent {
icon-name: "plus-large-symbolic";
label: _("New Snapshot");
Adw.ToolbarView no_snapshots {
[top]
Adw.HeaderBar {
[start]
$SidebarButton {}
[start]
Button status_open_button {
icon-name: "folder-open-symbolic";
tooltip-text: _("Open Snapshots Folder");
}
}
Adw.ToastOverlay no_snapshots_toast {
Adw.StatusPage {
title: _("No Snapshots");
description: _("Create a Snapshot to save the state of any Flatpak application");
icon-name: "snapshots-alt-symbolic";
Button status_new_button {
styles ["suggested-action", "pill"]
halign: center;
Adw.ButtonContent {
icon-name: "plus-large-symbolic";
label: _("New Snapshot");
}
}
}
}
}
}
Adw.ToolbarView loading_view {
[top]
Adw.HeaderBar {
[start]
$SidebarButton {}
Adw.ToolbarView loading_view {
[top]
Adw.HeaderBar {
[start]
$SidebarButton {}
}
}
}
Adw.ToolbarView snapshotting_view {
[top]
Adw.HeaderBar {
[start]
$SidebarButton {}
Adw.ToolbarView snapshotting_view {
[top]
Adw.HeaderBar {
[start]
$SidebarButton {}
}
}
}
}

View File

@@ -34,7 +34,6 @@ class SnapshotPage(Adw.BreakpointBin):
gtc = Gtk.Template.Child
toast_overlay = gtc()
no_snapshots_toast = gtc()
active_box = gtc()
active_listbox = gtc()
leftover_box = gtc()
@@ -140,6 +139,21 @@ class SnapshotPage(Adw.BreakpointBin):
elif row := self.leftover_listbox.get_row_at_index(0):
self.leftover_listbox.select_row(row)
self.leftover_select_handler(None, row, False, True)
def show_snapshot(self, package):
i = 0
while row := self.active_listbox.get_row_at_index(i):
i += 1
if row.package is package:
self.active_listbox.select_row(row)
self.active_select_handler(None, row, True)
self.toast_overlay.add_toast(Adw.Toast(title=_("Showing snapshots for {}").format(package.info['name'])))
break
else:
dialog = NewSnapshotDialog(self, self.snapshotting_status, self.refresh, package)
toast = Adw.Toast(title=_("No snapshots for {}").format(package.info['name']), button_label=_("New"))
toast.connect("button-clicked", lambda *_: dialog.present(HostInfo.main_window))
self.toast_overlay.add_toast(toast)
def start_loading(self):
self.status_stack.set_visible_child(self.loading_view)
@@ -162,12 +176,12 @@ class SnapshotPage(Adw.BreakpointBin):
Gio.Task.new(None, None, callback).run_in_thread(self.sort_snapshots)
def open_snapshots_folder(self, button, overlay):
def open_snapshots_folder(self, button):
try:
Gio.AppInfo.launch_default_for_uri(f"file://{HostInfo.snapshots_path}", None)
overlay.add_toast(Adw.Toast.new(_("Opened snapshots folder")))
self.toast_overlay.add_toast(Adw.Toast.new(_("Opened snapshots folder")))
except Exception as e:
overlay.add_toast(ErrorToast(_("Could not open folder"), str(e)).toast)
self.toast_overlay.add_toast(ErrorToast(_("Could not open folder"), str(e)).toast)
def on_cancel(self):
for worker in self.new_snapshot_dialog.workers:
@@ -196,8 +210,8 @@ class SnapshotPage(Adw.BreakpointBin):
# Connections
self.active_listbox.connect("row-activated", self.active_select_handler)
self.leftover_listbox.connect("row-activated", self.leftover_select_handler)
self.open_button.connect("clicked", self.open_snapshots_folder, self.toast_overlay)
self.status_open_button.connect("clicked", self.open_snapshots_folder, self.no_snapshots_toast)
self.open_button.connect("clicked", self.open_snapshots_folder)
self.status_open_button.connect("clicked", self.open_snapshots_folder)
self.status_new_button.connect("clicked", self.on_new)
self.new_button.connect("clicked", self.on_new)