-
-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Open workspace folder option (#1272)
- Loading branch information
1 parent
f4de1fc
commit d448b4c
Showing
4 changed files
with
40 additions
and
0 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
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,5 +1,7 @@ | ||
// Modules | ||
mod createfolder; | ||
mod openfolder; | ||
|
||
// Re-exports | ||
pub(crate) use createfolder::create_folder; | ||
pub(crate) use openfolder::open_folder; |
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
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) = open::that(&parent_path) { | ||
let path_string = &parent_path.into_os_string().into_string().ok().unwrap_or(String::from("Failed to get the path of the workspace folder")); | ||
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 | ||
} |