Skip to content

Commit d448b4c

Browse files
feat: Open workspace folder option (#1272)
1 parent f4de1fc commit d448b4c

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

crates/rnote-ui/data/ui/workspacebrowser.ui

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@
163163
<attribute name="label" translatable="yes">Create new Folder</attribute>
164164
<attribute name="action">workspacebrowser.create-folder</attribute>
165165
</item>
166+
<item>
167+
<attribute name="label" translatable="yes">Open Workspace Folder</attribute>
168+
<attribute name="action">workspacebrowser.open-folder</attribute>
169+
</item>
166170
</section>
167171
</menu>
168172
</object>

crates/rnote-ui/src/workspacebrowser/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ impl RnWorkspaceBrowser {
195195
self.imp()
196196
.action_group
197197
.add_action(&workspaceactions::create_folder(self, appwindow));
198+
self.imp()
199+
.action_group
200+
.add_action(&workspaceactions::open_folder(self, appwindow));
198201
}
199202

200203
fn setup_dir_controls(&self, _appwindow: &RnAppWindow) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Modules
22
mod createfolder;
3+
mod openfolder;
34

45
// Re-exports
56
pub(crate) use createfolder::create_folder;
7+
pub(crate) use openfolder::open_folder;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use crate::{RnAppWindow, RnWorkspaceBrowser};
2+
use gettextrs::gettext;
3+
use gtk4::{gio, glib, glib::clone, prelude::*};
4+
5+
pub(crate) fn open_folder(
6+
workspacebrowser: &RnWorkspaceBrowser,
7+
appwindow: &RnAppWindow,
8+
) -> gio::SimpleAction {
9+
let open_folder_action = gio::SimpleAction::new("open-folder", None);
10+
11+
open_folder_action.connect_activate(clone!(
12+
#[weak]
13+
workspacebrowser,
14+
#[weak]
15+
appwindow,
16+
move |_, _| {
17+
if let Some(parent_path) = workspacebrowser.dir_list_file().and_then(|f| f.path()) {
18+
if let Err(e) = open::that(&parent_path) {
19+
let path_string = &parent_path.into_os_string().into_string().ok().unwrap_or(String::from("Failed to get the path of the workspace folder"));
20+
tracing::error!("Opening the parent folder '{path_string}' in the file manager failed, Err: {e:?}");
21+
appwindow.overlays().dispatch_toast_error(&gettext("Failed to open the file in the file manager"));
22+
}
23+
} else {
24+
tracing::warn!("No path found");
25+
appwindow.overlays().dispatch_toast_error(&gettext("Failed to open the file in the file manager"));
26+
}
27+
}
28+
));
29+
30+
open_folder_action
31+
}

0 commit comments

Comments
 (0)