1 /* === S Y N F I G ========================================================= */
2 /*!	\file canvasmetadataerase.cpp
3 **	\brief Template File
4 **
5 **	$Id$
6 **
7 **	\legal
8 **	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **	Copyright (c) 2008 Chris Moore
10 **	Copyright (c) 2011 Nikita Kitaev
11 **
12 **	This package is free software; you can redistribute it and/or
13 **	modify it under the terms of the GNU General Public License as
14 **	published by the Free Software Foundation; either version 2 of
15 **	the License, or (at your option) any later version.
16 **
17 **	This package is distributed in the hope that it will be useful,
18 **	but WITHOUT ANY WARRANTY; without even the implied warranty of
19 **	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 **	General Public License for more details.
21 **	\endlegal
22 */
23 /* ========================================================================= */
24 
25 /* === H E A D E R S ======================================================= */
26 
27 #ifdef USING_PCH
28 #	include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #	include <config.h>
32 #endif
33 
34 #include <synfig/general.h>
35 
36 #include "canvasmetadataerase.h"
37 #include <synfigapp/canvasinterface.h>
38 #include <synfigapp/localization.h>
39 
40 #endif
41 
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45 using namespace synfigapp;
46 using namespace Action;
47 
48 /* === M A C R O S ========================================================= */
49 
50 ACTION_INIT_NO_GET_LOCAL_NAME(Action::CanvasMetadataErase);
51 ACTION_SET_NAME(Action::CanvasMetadataErase,"CanvasMetadataErase");
52 ACTION_SET_LOCAL_NAME(Action::CanvasMetadataErase,N_("Erase Canvas Metadata"));
53 ACTION_SET_TASK(Action::CanvasMetadataErase,"set");
54 ACTION_SET_CATEGORY(Action::CanvasMetadataErase,Action::CATEGORY_CANVAS);
55 ACTION_SET_PRIORITY(Action::CanvasMetadataErase,0);
56 ACTION_SET_VERSION(Action::CanvasMetadataErase,"0.0");
57 ACTION_SET_CVS_ID(Action::CanvasMetadataErase,"$Id$");
58 
59 /* === G L O B A L S ======================================================= */
60 
61 /* === P R O C E D U R E S ================================================= */
62 
63 /* === M E T H O D S ======================================================= */
64 
CanvasMetadataErase()65 Action::CanvasMetadataErase::CanvasMetadataErase()
66 {
67 }
68 
69 synfig::String
get_local_name() const70 Action::CanvasMetadataErase::get_local_name()const
71 {
72 	// TRANSLATORS: This is used in the 'history' dialog when a Canvas has its name changed.
73 	return _("Erase canvas metadata");
74 }
75 
76 Action::ParamVocab
get_param_vocab()77 Action::CanvasMetadataErase::get_param_vocab()
78 {
79 	ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
80 
81 	ret.push_back(ParamDesc("key",Param::TYPE_STRING)
82 		.set_local_name(_("Key"))
83 	);
84 
85 	return ret;
86 }
87 
88 bool
is_candidate(const ParamList & x)89 Action::CanvasMetadataErase::is_candidate(const ParamList &x)
90 {
91 	return candidate_check(get_param_vocab(),x);
92 }
93 
94 bool
set_param(const synfig::String & name,const Action::Param & param)95 Action::CanvasMetadataErase::set_param(const synfig::String& name, const Action::Param &param)
96 {
97 	if(name=="key" && param.get_type()==Param::TYPE_STRING)
98 	{
99 		key=param.get_string();
100 
101 		return true;
102 	}
103 
104 	return Action::CanvasSpecific::set_param(name,param);
105 }
106 
107 bool
is_ready() const108 Action::CanvasMetadataErase::is_ready()const
109 {
110 	if(key.empty())
111 	{
112 		synfig::error("Action::CanvasMetadataErase::is_ready(): Metadata Key not specified!");
113 		return false;
114 	}
115 
116 	return Action::CanvasSpecific::is_ready();
117 }
118 
119 void
perform()120 Action::CanvasMetadataErase::perform()
121 {
122 	old_value=get_canvas()->get_meta_data(key);
123 
124 	get_canvas()->erase_meta_data(key);
125 }
126 
127 void
undo()128 Action::CanvasMetadataErase::undo()
129 {
130 	get_canvas()->set_meta_data(key,old_value);
131 }
132