Skip to content

Commit

Permalink
feat: Open workspace folder option (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doublonmousse authored Nov 9, 2024
1 parent f4de1fc commit d448b4c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/rnote-ui/data/ui/workspacebrowser.ui
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
<attribute name="label" translatable="yes">Create new Folder</attribute>
<attribute name="action">workspacebrowser.create-folder</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Open Workspace Folder</attribute>
<attribute name="action">workspacebrowser.open-folder</attribute>
</item>
</section>
</menu>
</object>
Expand Down
3 changes: 3 additions & 0 deletions crates/rnote-ui/src/workspacebrowser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ impl RnWorkspaceBrowser {
self.imp()
.action_group
.add_action(&workspaceactions::create_folder(self, appwindow));
self.imp()
.action_group
.add_action(&workspaceactions::open_folder(self, appwindow));
}

fn setup_dir_controls(&self, _appwindow: &RnAppWindow) {
Expand Down
2 changes: 2 additions & 0 deletions crates/rnote-ui/src/workspacebrowser/workspaceactions/mod.rs
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;
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
}

0 comments on commit d448b4c

Please sign in to comment.