1 /* === S Y N F I G ========================================================= */
2 /*! \file canvasproperties.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007, 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "canvasproperties.h"
34 #include <gtkmm/frame.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/label.h>
37 #include <gtkmm/alignment.h>
38 #include <synfigapp/canvasinterface.h>
39 #include "metadatatreestore.h"
40 #include <gtkmm/treeview.h>
41 #include <gtkmm/scrolledwindow.h>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
57 /* === G L O B A L S ======================================================= */
59 /* === P R O C E D U R E S ================================================= */
61 /* === M E T H O D S ======================================================= */
63 CanvasProperties::CanvasProperties(Gtk::Window& parent,etl::handle<synfigapp::CanvasInterface> canvas_interface):
64 Gtk::Dialog(_("Canvas Properties"),parent,false,true),
65 canvas_interface_(canvas_interface)
67 widget_rend_desc.show();
68 widget_rend_desc.signal_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::on_rend_desc_changed));
70 Gtk::Alignment *dialogPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
71 dialogPadding->set_padding(12, 12, 12, 12);
72 get_vbox()->pack_start(*dialogPadding, false, false, 0);
74 Gtk::VBox *dialogBox = manage(new Gtk::VBox(false, 12));
75 dialogPadding->add(*dialogBox);
77 Gtk::Frame *info_frame=manage(new Gtk::Frame(_("Canvas Info")));
78 info_frame->set_shadow_type(Gtk::SHADOW_NONE);
79 ((Gtk::Label *) info_frame->get_label_widget())->set_markup(_("<b>Canvas Info</b>"));
80 dialogBox->pack_start(*info_frame, false, false, 0);
82 Gtk::Alignment *infoPadding = manage(new Gtk::Alignment(0, 0, 1, 1));
83 infoPadding->set_padding(6, 0, 24, 0);
84 info_frame->add(*infoPadding);
86 Gtk::Table *info_table=manage(new Gtk::Table(2,2,false));
87 info_table->set_row_spacings(6);
88 info_table->set_col_spacings(12);
89 infoPadding->add(*info_table);
91 // The root canvas doesn't have an ID, so don't
92 // display it if this is a root canvas.
93 if(!canvas_interface_->get_canvas()->is_root())
95 Gtk::Label *idLabel = manage(new Gtk::Label(_("_ID"), true));
96 idLabel->set_alignment(0, 0.5);
97 idLabel->set_mnemonic_widget(entry_id);
98 info_table->attach(*idLabel, 0, 1, 0, 1, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
99 info_table->attach(entry_id, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
101 Gtk::Label *nameLabel = manage(new Gtk::Label(_("_Name"), true));
102 nameLabel->set_alignment(0, 0.5);
103 nameLabel->set_mnemonic_widget(entry_name);
104 Gtk::Label *descriptionLabel = manage(new Gtk::Label(_("_Description"), true));
105 descriptionLabel->set_alignment(0, 0.5);
106 descriptionLabel->set_mnemonic_widget(entry_description);
107 info_table->attach(*nameLabel, 0, 1, 1, 2, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
108 info_table->attach(*descriptionLabel, 0, 1, 2, 3, Gtk::SHRINK|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
109 info_table->attach(entry_name, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
110 info_table->attach(entry_description, 1, 2, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
112 dialogBox->pack_start(widget_rend_desc, false, false, 0);
114 canvas_interface_->signal_rend_desc_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::refresh));
115 canvas_interface_->signal_id_changed().connect(sigc::mem_fun(*this,&studio::CanvasProperties::refresh));
117 Gtk::Button *ok_button(manage(new class Gtk::Button(Gtk::StockID("gtk-ok"))));
119 add_action_widget(*ok_button,2);
120 ok_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_ok_pressed));
122 Gtk::Button *apply_button(manage(new class Gtk::Button(Gtk::StockID("gtk-apply"))));
123 apply_button->show();
124 add_action_widget(*apply_button,1);
125 apply_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_apply_pressed));
127 Gtk::Button *cancel_button(manage(new class Gtk::Button(Gtk::StockID("gtk-close"))));
128 cancel_button->show();
129 add_action_widget(*cancel_button,0);
130 cancel_button->signal_clicked().connect(sigc::mem_fun(*this, &studio::CanvasProperties::on_cancel_pressed));
132 //set_default_response(1);
134 get_vbox()->show_all();
141 CanvasProperties::create_meta_data_view()
143 MetaDataTreeStore::Model model;
144 meta_data_tree_view=(manage(new class Gtk::TreeView()));
146 meta_data_tree_view->append_column(_("Key"),model.key);
147 meta_data_tree_view->append_column_editable(_("Data"),model.data);
148 meta_data_tree_view->set_model(MetaDataTreeStore::create(canvas_interface_));
149 meta_data_tree_view->set_rules_hint();
150 meta_data_tree_view->show();
152 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
153 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
154 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
155 scrolledwindow->add(*meta_data_tree_view);
156 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
157 scrolledwindow->show();
161 Gtk::Table *table=manage(new Gtk::Table());
162 table->attach(*scrolledwindow, 0, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
164 Gtk::Button* button_add(manage(new Gtk::Button(Gtk::StockID("gtk-add"))));
166 button_add->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_add));
167 table->attach(*button_add, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
169 Gtk::Button* button_delete(manage(new Gtk::Button(Gtk::StockID("gtk-delete"))));
170 button_delete->show();
171 button_delete->signal_clicked().connect(sigc::mem_fun(*this,&CanvasProperties::on_button_meta_data_delete));
172 table->attach(*button_delete, 1, 2, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK|Gtk::FILL, 0, 0);
179 CanvasProperties::on_button_meta_data_add()
182 if(App::dialog_entry(_("New MetaData Entry"), _("Please enter the name of the key"),key) && !key.empty())
184 canvas_interface_->set_meta_data(key," ");
190 CanvasProperties::on_button_meta_data_delete()
195 CanvasProperties::update_title()
197 set_title(_("Properties")+String(" - ")+canvas_interface_->get_canvas()->get_name());
201 CanvasProperties::refresh()
203 widget_rend_desc.set_rend_desc(canvas_interface_->get_canvas()->rend_desc());
204 entry_id.set_text(canvas_interface_->get_canvas()->get_id());
205 entry_name.set_text(canvas_interface_->get_canvas()->get_name());
206 entry_description.set_text(canvas_interface_->get_canvas()->get_description());
208 dirty_rend_desc=false;
213 CanvasProperties::~CanvasProperties()
218 CanvasProperties::on_rend_desc_changed()
220 dirty_rend_desc=true;
224 CanvasProperties::on_apply_pressed()
226 synfigapp::Action::PassiveGrouper group(canvas_interface_->get_instance().get(),_("Edit Canvas Properties"));
228 // fetch these three values first, because each set_() method refreshes the dialog with currently set values
229 String id = entry_id.get_text();
230 String name = entry_name.get_text();
231 String description = entry_description.get_text();
233 // do this first, because the other three cause the dialog to be refreshed with currently set values
234 if (dirty_rend_desc) canvas_interface_->set_rend_desc(widget_rend_desc.get_rend_desc());
236 if (id != canvas_interface_->get_canvas()->get_id() && !id.empty()) canvas_interface_->set_id(id);
237 if (name != canvas_interface_->get_canvas()->get_name()) canvas_interface_->set_name(name);
238 if (description != canvas_interface_->get_canvas()->get_description()) canvas_interface_->set_description(description);
240 dirty_rend_desc=false;
244 CanvasProperties::on_ok_pressed()
251 CanvasProperties::on_cancel_pressed()