void HistoryTreeStore::insert_action(Gtk::TreeRow row,etl::handle<synfigapp::Action::Undoable> action, bool /*is_active*/, bool is_undo, bool is_redo) { assert(action); row[model.action] = action; row[model.name] = static_cast<Glib::ustring>(action->get_local_name()); row[model.is_active] = action->is_active(); row[model.is_undo] = is_undo; row[model.is_redo] = is_redo; synfigapp::Action::CanvasSpecific *specific_action; specific_action=dynamic_cast<synfigapp::Action::CanvasSpecific*>(action.get()); if(specific_action) { row[model.canvas] = specific_action->get_canvas(); row[model.canvas_id] = specific_action->get_canvas()->get_id(); } etl::handle<synfigapp::Action::Group> group; group=etl::handle<synfigapp::Action::Group>::cast_dynamic(action); if(group) { synfigapp::Action::ActionList::const_iterator iter; for(iter=group->action_list().begin();iter!=group->action_list().end();++iter) { Gtk::TreeRow child_row = *(append(row.children())); insert_action(child_row,*iter,true,is_undo,is_redo); } } //row[model.icon] = Gtk::Button().render_icon_pixbuf(Gtk::StockID("synfig-canvas"),Gtk::ICON_SIZE_SMALL_TOOLBAR); }
void Super::add_action_front(etl::handle<Undoable> action) { action_list_.push_front(action); CanvasSpecific *specific_action=dynamic_cast<CanvasSpecific *>(action.get()); if(specific_action && !get_canvas()) set_canvas(specific_action->get_canvas()); }
int ValueNode::replace(etl::handle<ValueNode> x) { if(x.get()==this) return 0; while(parent_set.size()) { (*parent_set.begin())->add_child(x.get()); (*parent_set.begin())->remove_child(this); //x->parent_set.insert(*parent_set.begin()); //parent_set.erase(parent_set.begin()); } int r(RHandle(this).replace(x)); x->changed(); return r; }
bool Action::System::perform_action(etl::handle<Action::Base> action) { if (getenv("SYNFIG_DEBUG_ACTIONS")) synfig::info("%s:%d perform_action: '%s'", __FILE__, __LINE__, action->get_name().c_str()); handle<UIInterface> uim(get_ui_interface()); assert(action); if(!action->is_ready()) { uim->error(action->get_local_name()+": "+_("Action is not ready.")); return false; } most_recent_action_name_=action->get_name(); static bool inuse=false; if(inuse) return false; inuse=true; try { assert(action); Action::CanvasSpecific* canvas_specific(dynamic_cast<Action::CanvasSpecific*>(action.get())); if(canvas_specific && canvas_specific->get_canvas()) { handle<CanvasInterface> canvas_interface=static_cast<Instance*>(this)->find_canvas_interface(canvas_specific->get_canvas()); assert(canvas_interface); uim=canvas_interface->get_ui_interface(); } handle<Action::Undoable> undoable_action=handle<Action::Undoable>::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_local_name(), _("This action cannot be undone! Are you sure you want to continue?"), UIInterface::RESPONSE_NO ) == UIInterface::RESPONSE_NO ) return false; else { // Because this action cannot be undone, // we need to clear the undo stack clear_undo_stack(); } } else assert(undoable_action->is_active()); // Perform the action try { action->perform(); } catch(Action::Error err) { 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_local_name()+": "+strprintf("%d",err.get_type())); else uim->error(action->get_local_name()+": "+err.get_desc()); } // If action failed for whatever reason, just return false and do // not add the action onto the list return false; } catch(std::exception err) { uim->task(action->get_local_name()+' '+_("Failed")); inuse=false; 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 return false; } catch(...) { uim->task(action->get_local_name()+' '+_("Failed")); inuse=false; // If action failed for whatever reason, just return false and do // not add the action onto the list return false; } // Clear the redo stack if(clear_redo_stack_on_new_action_) 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); // Signal that a new action has been added if(group_stack_.empty()) signal_new_action()(undoable_action); } inuse=false; 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()) { Canvas::Handle canvas=canvas_specific->get_canvas(); if(!group_stack_.empty()) group_stack_.front()->request_redraw(canvas_specific->get_canvas_interface()); else { handle<CanvasInterface> canvas_interface=static_cast<Instance*>(this)->find_canvas_interface(canvas); assert(canvas_interface); //canvas_interface->signal_dirty_preview()(); } } }catch(...) { inuse=false; throw; } return true; }
bool Action::System::set_action_status(etl::handle<Action::Undoable> action, bool x) { Stack::iterator iter; int failed=false; if(action->is_active()==x) return true; handle<Action::Undoable> cur_pos=undo_action_stack_.front(); Action::CanvasSpecific* canvas_specific(dynamic_cast<Action::CanvasSpecific*>(action.get())); handle<UIInterface> uim=new ConfidentUIInterface(); iter=find(undo_action_stack_.begin(),undo_action_stack_.end(),action); if(iter!=undo_action_stack_.end()) { while(undo_action_stack_.front()!=action) { if(!undo_(uim)) { return false; } } if(!undo_(uim)) { return false; } action->set_active(x); if(redo_(get_ui_interface())) { signal_action_status_changed_(action); } else { action->set_active(!x); failed=true; } while(undo_action_stack_.front()!=cur_pos) { if(!redo_(uim)) { redo_action_stack_.front()->set_active(false); signal_action_status_changed_(redo_action_stack_.front()); } } if(!failed && canvas_specific && canvas_specific->is_dirty()) { Canvas::Handle canvas=canvas_specific->get_canvas(); handle<CanvasInterface> canvas_interface=static_cast<Instance*>(this)->find_canvas_interface(canvas); assert(canvas_interface); //canvas_interface->signal_dirty_preview()(); } return true; } iter=find(redo_action_stack_.begin(),redo_action_stack_.end(),action); if(iter!=redo_action_stack_.end()) { action->set_active(x); signal_action_status_changed_(action); if(canvas_specific && canvas_specific->is_dirty()) { Canvas::Handle canvas=canvas_specific->get_canvas(); handle<CanvasInterface> canvas_interface=static_cast<Instance*>(this)->find_canvas_interface(canvas); assert(canvas_interface); //canvas_interface->signal_dirty_preview()(); } return true; } return false; }