Create relative pathes for saving projects

This commit is contained in:
2025-04-02 20:47:50 +02:00
parent 5f93549a05
commit a89699334e
4 changed files with 41 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
pub mod types;
use pathdiff::diff_paths;
use std::{fs::File, path::PathBuf};
use slint::{Rgba8Pixel, SharedPixelBuffer};
use tool_helper::Error;
@@ -132,6 +133,15 @@ impl TIMInfo {
pub fn get_path(&self) -> std::path::PathBuf {
self.path.clone()
}
pub fn get_path_rel_to(&self, mut reference_path: std::path::PathBuf) -> Result<std::path::PathBuf, Error> {
let file_path = self.path.clone();
reference_path.pop();
diff_paths(&file_path, &reference_path).ok_or_else(|| {
Error::from_text(format!("Can not create relative path from {} to {}", file_path.to_string_lossy().as_ref(), reference_path.to_string_lossy().as_ref()))
})
}
}
#[derive(Clone)]