forked from flxzt/rnote
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize code and better error handling
- Loading branch information
1 parent
afda3c1
commit 0272d10
Showing
3 changed files
with
28 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
26 changes: 26 additions & 0 deletions
26
crates/rnote-ui/src/workspacebrowser/workspaceactions/openfolder.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |