From 6584e9bfd8e643417741df504f708e3b47c59d50 Mon Sep 17 00:00:00 2001 From: Konstantin Dmitriev Date: Dec 13 2019 04:35:51 +0000 Subject: Step 2: Closing and re-opening file now works via autobackup system. --- diff --git a/synfig-studio/src/gui/instance.cpp b/synfig-studio/src/gui/instance.cpp index ac244a4..7bab902 100644 --- a/synfig-studio/src/gui/instance.cpp +++ b/synfig-studio/src/gui/instance.cpp @@ -226,17 +226,11 @@ void studio::Instance::run_plugin(std::string plugin_path) { handle uim = this->find_canvas_view(this->get_canvas())->get_ui_interface(); - - if (!is_absolute_path(this->get_canvas()->get_file_name())) - { - uim->error(_("Please save file before running a plugin!")); - return; - } - string message = strprintf(_("Do you really want to run plugin for file \"%s\"?" ), + String message = strprintf(_("Do you really want to run plugin for file \"%s\"?" ), this->get_canvas()->get_name().c_str()); - string details = strprintf(_("This operation cannot be undone and all undo history will be cleared.")); + String details = strprintf(_("This operation cannot be undone and all undo history will be cleared.")); int answer = uim->confirmation( message, @@ -251,12 +245,15 @@ studio::Instance::run_plugin(std::string plugin_path) Canvas::Handle canvas(this->get_canvas()); + backup(true); + FileSystemTemporary::Handle temporary_filesystem = FileSystemTemporary::Handle::cast_dynamic(get_canvas()->get_file_system()); + String tmp_filename = temporary_filesystem->get_temporary_directory() + ETL_DIRECTORY_SEPARATOR + temporary_filesystem->get_temporary_filename_base(); synfigapp::PluginLauncher launcher(canvas); Time cur_time; cur_time = canvas->get_time(); - this->close(); + close(false); if(canvas->count()!=1) { @@ -292,52 +289,13 @@ studio::Instance::run_plugin(std::string plugin_path) canvas=0; - // - // QUICKHACK: - // Now dances with files :( (see https://github.com/synfig/synfig/issues/949) - // - // TODO: Replace copy operations with giomm??? - // - // create a backup of original saved file - String backup_filename; - struct stat buf; - do { - synfig::GUID guid; - backup_filename = launcher.get_original_path()+"-backup."+guid.get_string().substr(0,8); - } while (stat(backup_filename.c_str(), &buf) != -1); - std::ifstream src0(launcher.get_original_path(), std::ios::binary); - std::ofstream dst0(backup_filename, std::ios::binary); - dst0 << src0.rdbuf(); - src0.close(); - dst0.close(); - // copy processed to original - remove( launcher.get_original_path().c_str() ); - std::ifstream src1(launcher.get_result_path(), std::ios::binary); - std::ofstream dst1(launcher.get_original_path(), std::ios::binary); - dst1 << src1.rdbuf(); - src1.close(); - dst1.close(); - // open - App::open(launcher.get_result_path()); + App::open_from_temporary_filesystem(tmp_filename); etl::handle new_instance = App::instance_list.back(); - new_instance->save_as(launcher.get_original_path()); - // copy backup to original - remove( launcher.get_original_path().c_str() ); - std::ifstream src2(backup_filename, std::ios::binary); - std::ofstream dst2(launcher.get_original_path(), std::ios::binary); - dst2 << src2.rdbuf(); - src2.close(); - dst2.close(); - // remove backup file - remove( backup_filename.c_str() ); - // - // END QUICKHACK - // - - new_instance->inc_action_count(); // This file isn't saved! mark it as such + //new_instance->inc_action_count(); // This file isn't saved! mark it as such // Restore time cursor position - canvas = App::instance_list.back()->get_canvas(); + + canvas = new_instance->get_canvas(); etl::handle new_canvas_interface(new_instance->find_canvas_interface(canvas)); new_canvas_interface->set_time(cur_time); diff --git a/synfig-studio/src/synfigapp/instance.cpp b/synfig-studio/src/synfigapp/instance.cpp index 58d4c40..4456297 100644 --- a/synfig-studio/src/synfigapp/instance.cpp +++ b/synfig-studio/src/synfigapp/instance.cpp @@ -575,9 +575,9 @@ Instance::save_all_layers() } bool -Instance::backup() +Instance::backup(bool save_even_if_unchanged) { - if (!get_action_count()) + if (!get_action_count() && !save_even_if_unchanged) return true; FileSystemTemporary::Handle temporary_filesystem = FileSystemTemporary::Handle::cast_dynamic(get_canvas()->get_file_system()); diff --git a/synfig-studio/src/synfigapp/instance.h b/synfig-studio/src/synfigapp/instance.h index 011703c..a4f0a91 100644 --- a/synfig-studio/src/synfigapp/instance.h +++ b/synfig-studio/src/synfigapp/instance.h @@ -174,7 +174,7 @@ public: bool save_as(const synfig::String &filename); //! Saves the instance to current temporary container - bool backup(); + bool backup(bool save_even_if_unchanged = false); //! generate layer name (also known in code as 'description') synfig::String generate_new_description(const synfig::Layer::Handle &layer);