X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=synfig-studio%2Ftrunk%2Fsrc%2Fsynfigapp%2Faction_system.cpp;h=7aef9250a8c3e8380dcbd1cbfe3c1f747dfea0ea;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=0913a29f803e5917df601bebbfdf0eb0c956b47b;hpb=02252941b29de64037116f4d37991a38d9ff0d94;p=synfig.git diff --git a/synfig-studio/trunk/src/synfigapp/action_system.cpp b/synfig-studio/trunk/src/synfigapp/action_system.cpp index 0913a29..7aef925 100644 --- a/synfig-studio/trunk/src/synfigapp/action_system.cpp +++ b/synfig-studio/trunk/src/synfigapp/action_system.cpp @@ -2,19 +2,20 @@ /*! \file action_system.cpp ** \brief Template File ** -** $Id: action_system.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $ +** $Id$ ** ** \legal -** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley ** -** This software and associated documentation -** are CONFIDENTIAL and PROPRIETARY property of -** the above-mentioned copyright holder. +** This package is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License as +** published by the Free Software Foundation; either version 2 of +** the License, or (at your option) any later version. ** -** You may not copy, print, publish, or in any -** other way distribute this software without -** a prior written agreement with -** the copyright holder. +** This package is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. ** \endlegal */ /* ========================================================================= */ @@ -32,6 +33,8 @@ #include "instance.h" #include "canvasinterface.h" +#include "general.h" + #endif /* === U S I N G =========================================================== */ @@ -63,31 +66,34 @@ Action::System::~System() } bool -Action::System::perform_action(handle action) +Action::System::perform_action(etl::handle action) { + //// debug actions + // synfig::info("%s:%d perform_action: '%s'", __FILE__, __LINE__, action->get_name().c_str()); + handle uim(get_ui_interface()); - + assert(action); - + if(!action->is_ready()) { - uim->error(action->get_name()+": "+_("Action is not ready.")); + uim->error(action->get_local_name()+": "+_("Action is not ready.")); return false; - } - + } + most_recent_action_=action; - + static bool inuse=false; if(inuse) return false; inuse=true; try { - + assert(action); - + Action::CanvasSpecific* canvas_specific(dynamic_cast(action.get())); - + if(canvas_specific && canvas_specific->get_canvas()) { handle canvas_interface=static_cast(this)->find_canvas_interface(canvas_specific->get_canvas()); @@ -96,13 +102,13 @@ Action::System::perform_action(handle action) } handle undoable_action=handle::cast_dynamic(action); - + // If we cannot undo this action, make sure // that the user knows this. if(!undoable_action) { if(uim->yes_no( - action->get_name(), + action->get_local_name(), _("This action cannot be undone! Are you sure you want to continue?"), UIInterface::RESPONSE_NO ) == UIInterface::RESPONSE_NO @@ -122,15 +128,15 @@ Action::System::perform_action(handle action) try { action->perform(); } catch(Action::Error err) { - uim->task(action->get_name()+' '+_("Failed")); + uim->task(action->get_local_name()+' '+_("Failed")); inuse=false; if(err.get_type()!=Action::Error::TYPE_UNABLE) { if(err.get_desc().empty()) - uim->error(action->get_name()+": "+strprintf("%d",err.get_type())); + uim->error(action->get_local_name()+": "+strprintf("%d",err.get_type())); else - uim->error(action->get_name()+": "+err.get_desc()); + uim->error(action->get_local_name()+": "+err.get_desc()); } // If action failed for whatever reason, just return false and do @@ -139,10 +145,10 @@ Action::System::perform_action(handle action) } catch(std::exception err) { - uim->task(action->get_name()+' '+_("Failed")); + uim->task(action->get_local_name()+' '+_("Failed")); inuse=false; - uim->error(action->get_name()+": "+err.what()); + uim->error(action->get_local_name()+": "+err.what()); // If action failed for whatever reason, just return false and do // not add the action onto the list @@ -150,7 +156,7 @@ Action::System::perform_action(handle action) } catch(...) { - uim->task(action->get_name()+' '+_("Failed")); + uim->task(action->get_local_name()+' '+_("Failed")); inuse=false; // If action failed for whatever reason, just return false and do @@ -160,19 +166,19 @@ Action::System::perform_action(handle action) // Clear the redo stack if(clear_redo_stack_on_new_action_) - clear_redo_stack(); + clear_redo_stack(); if(!group_stack_.empty()) group_stack_.front()->inc_depth(); else inc_action_count(); - + // Push this action onto the action list if we can undo it if(undoable_action) { // If necessary, signal the change in status of undo if(undo_action_stack_.empty()) signal_undo_status_(true); - + // Add it to the list undo_action_stack_.push_front(undoable_action); @@ -180,10 +186,10 @@ Action::System::perform_action(handle action) if(group_stack_.empty()) signal_new_action()(undoable_action); } - + inuse=false; - uim->task(action->get_name()+' '+_("Successful")); + uim->task(action->get_local_name()+' '+_("Successful")); // If the action has "dirtied" the preview, signal it. if(0)if(canvas_specific && canvas_specific->is_dirty()) @@ -195,7 +201,6 @@ Action::System::perform_action(handle action) { handle canvas_interface=static_cast(this)->find_canvas_interface(canvas); assert(canvas_interface); - DEBUGPOINT(); //canvas_interface->signal_dirty_preview()(); } } @@ -206,20 +211,20 @@ Action::System::perform_action(handle action) } bool -synfigapp::Action::System::undo_(handle uim) +synfigapp::Action::System::undo_(etl::handle uim) { handle action(undo_action_stack().front()); most_recent_action_=action; - + try { if(action->is_active()) action->undo(); } catch(Action::Error err) { if(err.get_type()!=Action::Error::TYPE_UNABLE) { if(err.get_desc().empty()) - uim->error(action->get_name()+_(" (Undo): ")+strprintf("%d",err.get_type())); + uim->error(action->get_local_name()+_(" (Undo): ")+strprintf("%d",err.get_type())); else - uim->error(action->get_name()+_(" (Undo): ")+err.get_desc()); + uim->error(action->get_local_name()+_(" (Undo): ")+err.get_desc()); } return false; @@ -279,13 +284,13 @@ synfigapp::Action::System::undo() if(!undo_(uim)) { - uim->error(undo_action_stack_.front()->get_name()+": "+_("Failed to undo.")); + uim->error(undo_action_stack_.front()->get_local_name()+": "+_("Failed to undo.")); inuse=false; return false; } inuse=false; - + // If the action has "dirtied" the preview, signal it. if(0)if(action->is_active() && canvas_specific && canvas_specific->is_dirty()) { @@ -296,7 +301,6 @@ synfigapp::Action::System::undo() { handle canvas_interface=static_cast(this)->find_canvas_interface(canvas); assert(canvas_interface); - //DEBUGPOINT(); //canvas_interface->signal_dirty_preview()(); } } @@ -305,7 +309,7 @@ synfigapp::Action::System::undo() } bool -Action::System::redo_(handle uim) +Action::System::redo_(etl::handle uim) { handle action(redo_action_stack().front()); most_recent_action_=action; @@ -316,9 +320,9 @@ Action::System::redo_(handle uim) if(err.get_type()!=Action::Error::TYPE_UNABLE) { if(err.get_desc().empty()) - uim->error(action->get_name()+_(" (Redo): ")+strprintf("%d",err.get_type())); + uim->error(action->get_local_name()+_(" (Redo): ")+strprintf("%d",err.get_type())); else - uim->error(action->get_name()+_(" (Redo): ")+err.get_desc()); + uim->error(action->get_local_name()+_(" (Redo): ")+err.get_desc()); } return false; @@ -378,7 +382,7 @@ Action::System::redo() if(!redo_(uim)) { - uim->error(redo_action_stack_.front()->get_name()+": "+_("Failed to redo.")); + uim->error(redo_action_stack_.front()->get_local_name()+": "+_("Failed to redo.")); inuse=false; return false; } @@ -395,7 +399,6 @@ Action::System::redo() { handle canvas_interface=static_cast(this)->find_canvas_interface(canvas); assert(canvas_interface); - //DEBUGPOINT(); //canvas_interface->signal_dirty_preview()(); } } @@ -441,7 +444,7 @@ Action::System::clear_undo_stack() signal_undo_status_(false); signal_undo_stack_cleared_(); } - + void Action::System::clear_redo_stack() { @@ -456,7 +459,7 @@ Action::System::set_action_status(etl::handle action, bool x) { Stack::iterator iter; int failed=false; - + if(action->is_active()==x) return true; @@ -465,7 +468,7 @@ Action::System::set_action_status(etl::handle action, bool x) Action::CanvasSpecific* canvas_specific(dynamic_cast(action.get())); handle uim=new ConfidentUIInterface(); - + iter=find(undo_action_stack_.begin(),undo_action_stack_.end(),action); if(iter!=undo_action_stack_.end()) { @@ -475,12 +478,12 @@ Action::System::set_action_status(etl::handle action, bool x) { return false; } - } + } if(!undo_(uim)) { return false; } - + action->set_active(x); if(redo_(get_ui_interface())) @@ -492,8 +495,8 @@ Action::System::set_action_status(etl::handle action, bool x) action->set_active(!x); failed=true; } - - + + while(undo_action_stack_.front()!=cur_pos) { if(!redo_(uim)) @@ -508,7 +511,6 @@ Action::System::set_action_status(etl::handle action, bool x) Canvas::Handle canvas=canvas_specific->get_canvas(); handle canvas_interface=static_cast(this)->find_canvas_interface(canvas); assert(canvas_interface); - //DEBUGPOINT(); //canvas_interface->signal_dirty_preview()(); } @@ -529,7 +531,6 @@ Action::System::set_action_status(etl::handle action, bool x) Canvas::Handle canvas=canvas_specific->get_canvas(); handle canvas_interface=static_cast(this)->find_canvas_interface(canvas); assert(canvas_interface); - DEBUGPOINT(); //canvas_interface->signal_dirty_preview()(); } @@ -539,7 +540,7 @@ Action::System::set_action_status(etl::handle action, bool x) return false; } -Action::PassiveGrouper::PassiveGrouper(etl::loose_handle instance_,synfig::String name_): +Action::PassiveGrouper::PassiveGrouper(etl::loose_handle instance_,synfig::String name_): instance_(instance_), name_(name_), redraw_requested_(false), @@ -550,14 +551,12 @@ Action::PassiveGrouper::PassiveGrouper(etl::loose_handle instanc } void -Action::PassiveGrouper::request_redraw(handle x) +Action::PassiveGrouper::request_redraw(etl::handle x) { -/* DEBUGPOINT(); - if(instance_->group_stack_.empty()) +/* if(instance_->group_stack_.empty()) { if(x!=canvas_interface_) { - DEBUGPOINT(); x->signal_dirty_preview()(); } @@ -565,21 +564,16 @@ Action::PassiveGrouper::request_redraw(handle x) } else { - DEBUGPOINT(); if(instance_->group_stack_.back()==this) { - DEBUGPOINT(); redraw_requested_=true; } else { - DEBUGPOINT(); instance_->group_stack_.back()->request_redraw(x); redraw_requested_=false; } - DEBUGPOINT(); } - DEBUGPOINT(); */ if(x) { @@ -591,7 +585,7 @@ Action::PassiveGrouper::request_redraw(handle x) Action::PassiveGrouper::~PassiveGrouper() { assert(instance_->group_stack_.front()==this); - + // Remove this group from the group stack instance_->group_stack_.pop_front(); @@ -612,11 +606,11 @@ Action::PassiveGrouper::~PassiveGrouper() else { Action::CanvasSpecific* canvas_specific(dynamic_cast(action.get())); - + if(0)if(canvas_specific && canvas_specific->is_dirty() && canvas_specific->get_canvas_interface()) { if(instance_->group_stack_.empty()) - request_redraw(canvas_specific->get_canvas_interface()); + request_redraw(canvas_specific->get_canvas_interface()); } } @@ -633,34 +627,34 @@ Action::PassiveGrouper::~PassiveGrouper() if(depth_>0) { group=new Action::Group(name_); - + for(int i=0;i action(instance_->undo_action_stack_.front()); Action::CanvasSpecific* canvas_specific(dynamic_cast(action.get())); - + if(0)if(canvas_specific && canvas_specific->is_dirty()) { group->set_dirty(true); group->set_canvas(canvas_specific->get_canvas()); group->set_canvas_interface(canvas_specific->get_canvas_interface()); } - + // Copy the action from the undo stack to the group group->add_action_front(action); - + // Remove the action from the undo stack instance_->undo_action_stack_.pop_front(); } - + // Push the group onto the stack instance_->undo_action_stack_.push_front(group); - + if(0)if(group->is_dirty()) request_redraw(group->get_canvas_interface()); // group->get_canvas_interface()->signal_dirty_preview()(); - + if(instance_->group_stack_.empty()) { instance_->inc_action_count(); @@ -669,13 +663,12 @@ Action::PassiveGrouper::~PassiveGrouper() else instance_->group_stack_.front()->inc_depth(); } - + if(0)if(redraw_requested_) { if(instance_->group_stack_.empty()) { assert(canvas_interface_); - DEBUGPOINT(); canvas_interface_->signal_dirty_preview()(); } else @@ -694,16 +687,16 @@ Action::PassiveGrouper::cancel() // Cancel any groupers that may be on top of us first //while(instance_->group_stack_.front()!=this) // instance_->group_stack_.front()->cancel(); - + synfig::warning("Cancel depth: %d",depth_); - + while(depth_) if(!instance_->undo()) { error=true; break; } - + if(error) instance_->get_ui_interface()->error(_("State restore failure")); else