Add 'Open library' button

This commit is contained in:
Eric Van Albert
2025-12-17 00:32:49 -05:00
parent 3280b96ade
commit 4986af64a1
4 changed files with 26 additions and 13 deletions
+1
View File
@@ -52,6 +52,7 @@ libmpv-sys = { git = "git+https://github.com/ervanalb/libmpv-rs", rev="189f5e45d
surfman = { version = "0.7.0", features = ["sm-x11"] }
glow = "0.12.1"
crossbeam = "0.8.2"
open = "5.3.3"
# For memory profiling (see also src/bin/main.rs)
+9
View File
@@ -176,6 +176,15 @@ pub fn library_ui(ui: &mut egui::Ui, ctx: &Context, newly_opened: bool) -> Libra
response = LibraryResponse::AddNode(item.node_props.clone());
}
}
ui.add_space(10.);
ui.vertical_centered(|ui| {
if ui.button("Open library folder").clicked() {
open::that_detached(ctx.library_directory())
.unwrap_or_else(|e| println!("Could not open library: {}", e));
}
});
ui.add_space(10.);
});
// Handle response
+15 -12
View File
@@ -563,18 +563,21 @@ impl Context {
self.render_target_states.get(&id)
}
pub fn library_directory(&self) -> PathBuf {
self.resource_dir.join("library")
}
pub fn builtin_library_directory(&self) -> PathBuf {
self.resource_dir.join("builtin_library")
}
/// Load content from disk or the library or something
pub fn fetch_library_path(&self, filename: &str) -> PathBuf {
let library_path = self.resource_dir.join("library").join(filename);
let builtin_library_path = self.resource_dir.join("builtin_library").join(filename);
if self.resource_dir.join("library").join(filename).exists() {
pub fn library_path(&self, filename: &str) -> PathBuf {
let library_path = self.library_directory().join(filename);
let builtin_library_path = self.builtin_library_directory().join(filename);
if library_path.exists() {
library_path
} else if self
.resource_dir
.join("builtin_library")
.join(filename)
.exists()
{
} else if builtin_library_path.exists() {
builtin_library_path
} else {
library_path
@@ -583,12 +586,12 @@ impl Context {
/// Load content from disk or the library or something
pub fn fetch_library_content(&self, filename: &str) -> io::Result<String> {
fs::read_to_string(self.fetch_library_path(filename))
fs::read_to_string(self.library_path(filename))
}
/// Load content from disk or the library or something as raw bytes
pub fn fetch_library_content_bytes(&self, filename: &str) -> io::Result<Vec<u8>> {
fs::read(self.fetch_library_path(filename))
fs::read(self.library_path(filename))
}
/// List all files in the library and builtin_library directories
+1 -1
View File
@@ -174,7 +174,7 @@ impl MovieNodeState {
{
name.clone()
} else {
ctx.fetch_library_path(name).to_string_lossy().to_string()
ctx.library_path(name).to_string_lossy().to_string()
};
let conf_file_path = ctx