Create relative pathes for saving projects
This commit is contained in:
@@ -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)]
|
||||
|
||||
Reference in New Issue
Block a user