Skip to content

Commit

Permalink
reorganize code and better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Doublonmousse committed Jun 7, 2024
1 parent afda3c1 commit 0272d10
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,6 @@ pub(crate) fn create_folder(
new_folder_action
}

pub(crate) fn open_folder(
workspacebrowser: &RnWorkspaceBrowser,
appwindow: &RnAppWindow,
) -> gio::SimpleAction {
let open_folder_action = gio::SimpleAction::new("open-folder", None);

open_folder_action.connect_activate(clone!(@weak workspacebrowser, @weak appwindow => move |_, _| {
if let Some(parent_path) = workspacebrowser.dir_list_file().and_then(|f| f.path()) {
opener::open(parent_path).unwrap(); //for now not robust to errors
// maybe more things
} else {
tracing::warn!("Can't create new folder when there currently is no workspace selected");
}
}
));

open_folder_action
}
fn create_folder_name_entry() -> Entry {
Entry::builder()
.placeholder_text(gettext("Folder Name"))
Expand Down
3 changes: 2 additions & 1 deletion crates/rnote-ui/src/workspacebrowser/workspaceactions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Modules
mod createfolder;
mod openfolder;

// Re-exports
pub(crate) use createfolder::create_folder;
pub(crate) use createfolder::open_folder;
pub(crate) use openfolder::open_folder;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::{RnAppWindow, RnWorkspaceBrowser};
use gettextrs::gettext;
use gtk4::{gio, glib, glib::clone, prelude::*};

pub(crate) fn open_folder(
workspacebrowser: &RnWorkspaceBrowser,
appwindow: &RnAppWindow,
) -> gio::SimpleAction {
let open_folder_action = gio::SimpleAction::new("open-folder", None);

open_folder_action.connect_activate(clone!(@weak workspacebrowser, @weak appwindow => move |_, _| {
if let Some(parent_path) = workspacebrowser.dir_list_file().and_then(|f| f.path()) {
if let Err(e) = opener::open(&parent_path) {
let path_string = &parent_path.into_os_string().into_string().ok().unwrap_or(String::from("path not found"));
tracing::error!("Opening the parent folder '{path_string}' in the file manager failed, Err: {e:?}");
appwindow.overlays().dispatch_toast_error(&gettext("Failed to open the file in the file manager"));
}
} else {
tracing::warn!("No path found");
appwindow.overlays().dispatch_toast_error(&gettext("Failed to open the file in the file manager"));
}
}
));

open_folder_action
}

0 comments on commit 0272d10

Please sign in to comment.