From 9f9ac2b47c86630d4864f9748ca0c3a1b18caff1 Mon Sep 17 00:00:00 2001 From: Ricky Kresslein Date: Sat, 11 Jun 2022 08:02:04 +0300 Subject: Export CSV disabled if no tasks --- src/application.rs | 20 +++++++++++++------- src/ui/history_box.rs | 2 ++ 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/application.rs b/src/application.rs index 157c432..cfacd93 100755 --- a/src/application.rs +++ b/src/application.rs @@ -163,13 +163,6 @@ impl FurtheranceApplication { imp.pomodoro_dialog.lock().unwrap().response(gtk::ResponseType::Reject); })); self.add_action(&stop_pomodoro_action); - - let export_csv_action = gio::SimpleAction::new("export-csv", None); - export_csv_action.connect_activate(clone!(@weak self as app => move |_, _| { - let window = FurtheranceWindow::default(); - window.open_csv_export_dialog(); - })); - self.add_action(&export_csv_action); } fn setup_application(&self) { @@ -257,6 +250,19 @@ impl FurtheranceApplication { } } + pub fn export_csv_enabled(&self, enabled: bool) { + if enabled { + let export_csv_action = gio::SimpleAction::new("export-csv", None); + export_csv_action.connect_activate(clone!(@weak self as app => move |_, _| { + let window = FurtheranceWindow::default(); + window.open_csv_export_dialog(); + })); + self.add_action(&export_csv_action); + } else { + self.remove_action("export-csv"); + } + } + pub fn update_light_dark(&self) { let manager = adw::StyleManager::default(); diff --git a/src/ui/history_box.rs b/src/ui/history_box.rs index 445d796..87631b0 100755 --- a/src/ui/history_box.rs +++ b/src/ui/history_box.rs @@ -93,6 +93,7 @@ impl FurHistoryBox { let imp = imp::FurHistoryBox::from_instance(self); let app = FurtheranceApplication::default(); app.delete_enabled(false); + app.export_csv_enabled(false); imp.spinner.set_spinning(false); let name = match view { @@ -103,6 +104,7 @@ impl FurHistoryBox { View::Empty => "empty", View::Tasks => { app.delete_enabled(true); + app.export_csv_enabled(true); "tasks" } }; -- cgit 1.4.1