1 /* === S Y N F I G ========================================================= */
2 /*! \file dockmanager.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 "docks/dockmanager.h"
35 #include "docks/dockable.h"
36 #include "docks/dockdialog.h"
37 #include <synfigapp/settings.h>
38 #include <synfigapp/main.h>
39 #include <gdkmm/general.h>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 class studio::DockSettings : public synfigapp::Settings
58 DockManager* dock_manager;
61 DockSettings(DockManager* dock_manager):dock_manager(dock_manager)
63 synfigapp::Main::settings().add_domain(this,"dock");
66 virtual ~DockSettings()
68 synfigapp::Main::settings().remove_domain("dock");
70 virtual bool get_value(const synfig::String& key_, synfig::String& value)const
73 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")try
75 synfig::String key(key_.begin()+7,key_.end());
76 synfig::String::size_type separator=key.find_first_of('.');
77 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
78 key=synfig::String(key.begin()+separator+1,key.end());
80 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
82 if(key=="contents_size")
84 dock_dialog.rebuild_sizes();
85 vector<int>::const_iterator iter(dock_dialog.get_dock_book_sizes().begin());
86 vector<int>::const_iterator end(dock_dialog.get_dock_book_sizes().end());
88 for(;iter!=end;++iter)
89 value+=strprintf("%d ",*iter);
94 int x,y; dock_dialog.get_position(x,y);
95 value=strprintf("%d %d",x,y);
100 int x,y; dock_dialog.get_size(x,y);
101 value=strprintf("%d %d",x,y);
106 value=dock_dialog.get_contents();
109 if(key=="comp_selector")
111 value=dock_dialog.get_composition_selector()?"1":"0";
114 }catch (...) { return false; }
115 return synfigapp::Settings::get_value(key_,value);
118 virtual bool set_value(const synfig::String& key_,const synfig::String& value)
121 if(key_.size()>6 && String(key_.begin(),key_.begin()+6)=="dialog")
123 synfig::String key(key_.begin()+7,key_.end());
124 synfig::String::size_type separator=key.find_first_of('.');
125 int id(atoi(synfig::String(key.begin(),key.begin()+separator).c_str()));
126 key=synfig::String(key.begin()+separator+1,key.end());
128 DockDialog& dock_dialog(dock_manager->find_dock_dialog(id));
130 if(key=="contents_size")
134 Gtk::IconSize::lookup(Gtk::IconSize(4),width,height);
136 String::size_type n=0;
137 String value_(value);
138 while(value_.size() && value_.size()>n){
139 value_=String(value_.begin()+n,value_.end());
141 if(!strscanf(value_,"%d",&size))
144 data.push_back(size);
151 dock_dialog.set_dock_book_sizes(data);
155 synfig::error("Exception caught!!!");
163 if(!strscanf(value,"%d %d",&x, &y))
165 //synfig::info("dock_manager. move to: %d, %d", x,y);
166 dock_dialog.move(x,y);
172 if(!strscanf(value,"%d %d",&x, &y))
174 //synfig::info("dock_manager. size to: %d, %d", x,y);
175 dock_dialog.set_default_size(x,y);
176 dock_dialog.resize(x,y);
181 dock_dialog.set_contents(value);
184 if(key=="comp_selector")
186 if(value.empty() || value[0]=='0')
187 dock_dialog.set_composition_selector(false);
189 dock_dialog.set_composition_selector(true);
193 return synfigapp::Settings::set_value(key_,value);
196 virtual KeyList get_key_list()const
198 synfigapp::Settings::KeyList ret(synfigapp::Settings::get_key_list());
200 std::list<DockDialog*>::const_iterator iter;
201 for(iter=dock_manager->dock_dialog_list_.begin();iter!=dock_manager->dock_dialog_list_.end();++iter)
203 ret.push_back(strprintf("dialog.%d.contents",(*iter)->get_id()));
204 ret.push_back(strprintf("dialog.%d.comp_selector",(*iter)->get_id()));
205 ret.push_back(strprintf("dialog.%d.pos",(*iter)->get_id()));
206 ret.push_back(strprintf("dialog.%d.size",(*iter)->get_id()));
207 ret.push_back(strprintf("dialog.%d.contents_size",(*iter)->get_id()));
213 /* === M E T H O D S ======================================================= */
215 DockManager::DockManager():
216 dock_settings(new DockSettings(this))
220 DockManager::~DockManager()
222 while(!dock_dialog_list_.empty())
224 dock_dialog_list_.back()->close();
226 while(!dockable_list_.empty())
228 Dockable* dockable(dockable_list_.back());
229 // synfig::info("DockManager::~DockManager(): Deleting dockable \"%s\"",dockable->get_name().c_str());
230 dockable_list_.pop_back();
236 DockManager::register_dockable(Dockable& x)
238 dockable_list_.push_back(&x);
239 // synfig::info("DockManager::register_dockable(): Registered dockable \"%s\"",dockable_list_.back()->get_name().c_str());
240 signal_dockable_registered()(&x);
244 DockManager::unregister_dockable(Dockable& x)
246 std::list<Dockable*>::iterator iter;
247 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
252 dockable_list_.erase(iter);
253 synfig::info("DockManager::unregister_dockable(): \"%s\" has been Unregistered",x.get_name().c_str());
261 DockManager::find_dockable(const synfig::String& x)
263 std::list<Dockable*>::iterator iter;
264 for(iter=dockable_list_.begin();iter!=dockable_list_.end();++iter)
265 if((*iter)->get_name()==x)
268 throw std::runtime_error("DockManager::find_dockable(): not found");
272 DockManager::present(synfig::String x)
276 find_dockable(x).present();
284 DockManager::find_dock_dialog(int id)
286 std::list<DockDialog*>::iterator iter;
287 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
288 if((*iter)->get_id()==id)
291 DockDialog* dock_dialog(new DockDialog());
292 dock_dialog->set_id(id);
297 DockManager::find_dock_dialog(int id)const
299 std::list<DockDialog*>::const_iterator iter;
300 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)
301 if((*iter)->get_id()==id)
304 throw std::runtime_error("DockManager::find_dock_dialog(int id)const: not found");
308 DockManager::show_all_dock_dialogs()
310 std::list<DockDialog*>::iterator iter;
311 for(iter=dock_dialog_list_.begin();iter!=dock_dialog_list_.end();++iter)