changed delete and clone
This commit is contained in:
parent
74cc17b9ce
commit
578bdb3d47
|
|
@ -47,9 +47,8 @@ pub(crate) fn spawn_image_thread(
|
||||||
properties: Arc<RwLock<ImageProperties>>,
|
properties: Arc<RwLock<ImageProperties>>,
|
||||||
main_win: &MainWindow,
|
main_win: &MainWindow,
|
||||||
) {
|
) {
|
||||||
|
let mut win = main_win.win.clone();
|
||||||
let mut file_choice = main_win.file_choice.clone();
|
let mut file_choice = main_win.file_choice.clone();
|
||||||
let mut next_btn = main_win.next_btn.clone();
|
|
||||||
let mut back_btn = main_win.back_btn.clone();
|
|
||||||
let mut quote = main_win.quote.clone();
|
let mut quote = main_win.quote.clone();
|
||||||
let mut tag = main_win.tag.clone();
|
let mut tag = main_win.tag.clone();
|
||||||
let mut layer_red = main_win.layer_red.clone();
|
let mut layer_red = main_win.layer_red.clone();
|
||||||
|
|
@ -72,6 +71,7 @@ pub(crate) fn spawn_image_thread(
|
||||||
match val {
|
match val {
|
||||||
DrawMessage::Open => {
|
DrawMessage::Open => {
|
||||||
status.set_label("Loading...");
|
status.set_label("Loading...");
|
||||||
|
// win.deactivate();
|
||||||
load_image(
|
load_image(
|
||||||
&mut file_choice,
|
&mut file_choice,
|
||||||
Arc::clone(&images_path),
|
Arc::clone(&images_path),
|
||||||
|
|
@ -93,13 +93,13 @@ pub(crate) fn spawn_image_thread(
|
||||||
&properties,
|
&properties,
|
||||||
&mut _container,
|
&mut _container,
|
||||||
);
|
);
|
||||||
|
// win.activate();
|
||||||
|
status.set_label("");
|
||||||
status.set_label("");
|
status.set_label("");
|
||||||
}
|
}
|
||||||
DrawMessage::ChangeCrop((x, y)) => {
|
DrawMessage::ChangeCrop((x, y)) => {
|
||||||
status.set_label("Loading...");
|
status.set_label("Loading...");
|
||||||
file_choice.deactivate();
|
// win.deactivate();
|
||||||
next_btn.deactivate();
|
|
||||||
back_btn.deactivate();
|
|
||||||
load_image(
|
load_image(
|
||||||
&mut file_choice,
|
&mut file_choice,
|
||||||
Arc::clone(&images_path),
|
Arc::clone(&images_path),
|
||||||
|
|
@ -121,9 +121,7 @@ pub(crate) fn spawn_image_thread(
|
||||||
&properties,
|
&properties,
|
||||||
&mut _container,
|
&mut _container,
|
||||||
);
|
);
|
||||||
file_choice.activate();
|
// win.activate();
|
||||||
next_btn.activate();
|
|
||||||
back_btn.activate();
|
|
||||||
status.set_label("");
|
status.set_label("");
|
||||||
}
|
}
|
||||||
DrawMessage::Recalc => {
|
DrawMessage::Recalc => {
|
||||||
|
|
@ -137,44 +135,48 @@ pub(crate) fn spawn_image_thread(
|
||||||
DrawMessage::Save => {
|
DrawMessage::Save => {
|
||||||
if let Some(cont) = &mut _container {
|
if let Some(cont) = &mut _container {
|
||||||
status.set_label("Saving...");
|
status.set_label("Saving...");
|
||||||
|
win.deactivate();
|
||||||
cont.save();
|
cont.save();
|
||||||
|
win.activate();
|
||||||
status.set_label("");
|
status.set_label("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawMessage::Clone => {
|
DrawMessage::Clone => {
|
||||||
if let Some(cont) = &mut _container {
|
if let Some(cont) = &mut _container {
|
||||||
status.set_label("Cloning...");
|
status.set_label("Cloning...");
|
||||||
|
win.deactivate();
|
||||||
if let Some(path) = cont.clone_img() {
|
if let Some(path) = cont.clone_img() {
|
||||||
images_path
|
let idx = file_choice.value();
|
||||||
.write()
|
let mut imgs = images_path.write().unwrap();
|
||||||
.unwrap()
|
imgs.insert(idx as usize, path.clone());
|
||||||
.insert(file_choice.value() as usize, path.clone());
|
|
||||||
file_choice.insert(
|
file_choice.insert(
|
||||||
file_choice.value(),
|
idx,
|
||||||
path.file_name().unwrap().to_str().unwrap(),
|
path.file_name().unwrap().to_str().unwrap(),
|
||||||
enums::Shortcut::None,
|
enums::Shortcut::None,
|
||||||
menu::MenuFlag::Normal,
|
menu::MenuFlag::Normal,
|
||||||
|_| {},
|
|a| a.do_callback(),
|
||||||
);
|
);
|
||||||
|
file_choice.set_value(idx);
|
||||||
}
|
}
|
||||||
status.set_label("");
|
status.set_label("");
|
||||||
|
win.activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawMessage::Delete => {
|
DrawMessage::Delete => {
|
||||||
if let Some(cont) = &mut _container {
|
if let Some(cont) = &mut _container {
|
||||||
status.set_label("Deleting to trash...");
|
status.set_label("Deleting...");
|
||||||
|
win.deactivate();
|
||||||
cont.delete();
|
cont.delete();
|
||||||
images_path
|
let mut imgs = images_path.write().unwrap();
|
||||||
.write()
|
imgs.remove(file_choice.value() as usize);
|
||||||
.unwrap()
|
|
||||||
.remove(file_choice.value() as usize);
|
|
||||||
file_choice.remove(file_choice.value());
|
file_choice.remove(file_choice.value());
|
||||||
if file_choice.value() > 0 {
|
if file_choice.value() != imgs.len() as i32 {
|
||||||
file_choice.set_value(file_choice.value() - 1);
|
file_choice.set_value(file_choice.value());
|
||||||
} else {
|
} else {
|
||||||
file_choice.set_value(0);
|
file_choice.set_value(file_choice.value() - 1);
|
||||||
}
|
}
|
||||||
status.set_label("");
|
status.set_label("");
|
||||||
|
win.activate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/utils.rs
17
src/utils.rs
|
|
@ -208,18 +208,25 @@ impl ImageContainer {
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
let name = path.file_stem().unwrap().to_string_lossy();
|
let name = path.file_stem().unwrap().to_string_lossy();
|
||||||
let ext = path.extension().unwrap().to_string_lossy();
|
let ext = path.extension().unwrap().to_string_lossy();
|
||||||
let new_file = format!("{}_copy.{}", name, ext);
|
let mut i = 1;
|
||||||
let new_path = path.with_file_name(&new_file);
|
let mut new_path = path.clone();
|
||||||
|
while new_path.exists() {
|
||||||
|
let new_file = format!("{}{}.{}", name, "-copy".repeat(i), ext);
|
||||||
|
new_path = path.with_file_name(&new_file);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
let path_conf = path.with_extension("conf");
|
let path_conf = path.with_extension("conf");
|
||||||
let path_conf_new = new_path.with_extension("conf");
|
let path_conf_new = new_path.with_extension("conf");
|
||||||
|
|
||||||
if fs::copy(path, &new_path).is_err() {
|
if path.exists() && fs::copy(path, &new_path).is_err() {
|
||||||
dialog::message_default("Failed to clone image!");
|
dialog::message_default("Failed to clone image!");
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if fs::copy(path_conf, &path_conf_new).is_err() {
|
if path_conf.exists() && fs::copy(path_conf, &path_conf_new).is_err() {
|
||||||
dialog::message_default("Failed to clone image conf!");
|
dialog::message_default("Failed to clone image!");
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
Some(new_path)
|
Some(new_path)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue