ladanyi@130
|
1 |
#ifdef HAVE_CONFIG_H
|
ladanyi@130
|
2 |
#include <config.h>
|
ladanyi@130
|
3 |
#endif
|
ladanyi@130
|
4 |
|
ladanyi@53
|
5 |
#include "main_win.h"
|
ladanyi@100
|
6 |
#include "guipixbufs.h"
|
ladanyi@6
|
7 |
|
ladanyi@133
|
8 |
#include "i18n.h"
|
ladanyi@130
|
9 |
|
hegyi@96
|
10 |
MainWin::MainWin()
|
ladanyi@6
|
11 |
{
|
hegyi@96
|
12 |
set_title ("no file");
|
ladanyi@6
|
13 |
set_default_size(WIN_WIDTH,WIN_HEIGHT);
|
ladanyi@6
|
14 |
add(vbox);
|
ladanyi@6
|
15 |
|
ladanyi@60
|
16 |
// custom icons for the toolbar
|
ladanyi@60
|
17 |
Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
|
ladanyi@60
|
18 |
|
ladanyi@61
|
19 |
Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
20 |
2328, gui_icons_move);
|
ladanyi@61
|
21 |
Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
22 |
2328, gui_icons_addnode);
|
ladanyi@61
|
23 |
Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
24 |
2328, gui_icons_addlink);
|
ladanyi@61
|
25 |
Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
26 |
2328, gui_icons_delete);
|
ladanyi@61
|
27 |
Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
28 |
2328, gui_icons_editlink);
|
ladanyi@61
|
29 |
Glib::RefPtr<Gdk::Pixbuf> p_editnode_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
30 |
2328, gui_icons_editnode);
|
ladanyi@61
|
31 |
Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
|
ladanyi@61
|
32 |
2328, gui_icons_newmap);
|
ladanyi@60
|
33 |
|
ladanyi@60
|
34 |
Gtk::IconSource move_icon_source;
|
ladanyi@61
|
35 |
move_icon_source.set_pixbuf(p_move_pixbuf);
|
ladanyi@60
|
36 |
Gtk::IconSet move_icon_set;
|
ladanyi@60
|
37 |
move_icon_set.add_source(move_icon_source);
|
ladanyi@60
|
38 |
p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
|
ladanyi@60
|
39 |
|
ladanyi@60
|
40 |
Gtk::IconSource addnode_icon_source;
|
ladanyi@61
|
41 |
addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
|
ladanyi@60
|
42 |
Gtk::IconSet addnode_icon_set;
|
ladanyi@60
|
43 |
addnode_icon_set.add_source(addnode_icon_source);
|
ladanyi@60
|
44 |
p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
|
ladanyi@60
|
45 |
|
ladanyi@60
|
46 |
Gtk::IconSource addlink_icon_source;
|
ladanyi@61
|
47 |
addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
|
ladanyi@60
|
48 |
Gtk::IconSet addlink_icon_set;
|
ladanyi@60
|
49 |
addlink_icon_set.add_source(addlink_icon_source);
|
ladanyi@60
|
50 |
p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
|
ladanyi@60
|
51 |
|
ladanyi@60
|
52 |
Gtk::IconSource delete_icon_source;
|
ladanyi@61
|
53 |
delete_icon_source.set_pixbuf(p_delete_pixbuf);
|
ladanyi@60
|
54 |
Gtk::IconSet delete_icon_set;
|
ladanyi@60
|
55 |
delete_icon_set.add_source(delete_icon_source);
|
ladanyi@60
|
56 |
p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
|
ladanyi@60
|
57 |
|
ladanyi@60
|
58 |
Gtk::IconSource editlink_icon_source;
|
ladanyi@61
|
59 |
editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
|
ladanyi@60
|
60 |
Gtk::IconSet editlink_icon_set;
|
ladanyi@60
|
61 |
editlink_icon_set.add_source(editlink_icon_source);
|
ladanyi@60
|
62 |
p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
|
ladanyi@60
|
63 |
|
ladanyi@60
|
64 |
Gtk::IconSource editnode_icon_source;
|
ladanyi@61
|
65 |
editnode_icon_source.set_pixbuf(p_editnode_pixbuf);
|
ladanyi@60
|
66 |
Gtk::IconSet editnode_icon_set;
|
ladanyi@60
|
67 |
editnode_icon_set.add_source(editnode_icon_source);
|
ladanyi@60
|
68 |
p_icon_factory->add(Gtk::StockID("gd-editnode"), editnode_icon_set);
|
ladanyi@60
|
69 |
|
ladanyi@60
|
70 |
Gtk::IconSource newmap_icon_source;
|
ladanyi@61
|
71 |
newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
|
ladanyi@60
|
72 |
Gtk::IconSet newmap_icon_set;
|
ladanyi@60
|
73 |
newmap_icon_set.add_source(newmap_icon_source);
|
ladanyi@60
|
74 |
p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
|
ladanyi@60
|
75 |
|
ladanyi@60
|
76 |
p_icon_factory->add_default();
|
ladanyi@60
|
77 |
|
ladanyi@6
|
78 |
ag=Gtk::ActionGroup::create();
|
ladanyi@6
|
79 |
|
ladanyi@130
|
80 |
ag->add( Gtk::Action::create("FileMenu", _("_File")) );
|
hegyi@102
|
81 |
ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
|
hegyi@96
|
82 |
sigc::mem_fun(*this, &MainWin::newTab));
|
ladanyi@6
|
83 |
ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
|
ladanyi@6
|
84 |
sigc::mem_fun(*this, &MainWin::openFile));
|
ladanyi@130
|
85 |
ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
|
hegyi@102
|
86 |
sigc::mem_fun(*this, &MainWin::newFile));
|
ladanyi@6
|
87 |
ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
|
ladanyi@6
|
88 |
sigc::mem_fun(*this, &MainWin::saveFile));
|
ladanyi@6
|
89 |
ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
|
ladanyi@6
|
90 |
sigc::mem_fun(*this, &MainWin::saveFileAs));
|
ladanyi@53
|
91 |
ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
|
hegyi@102
|
92 |
sigc::mem_fun(*this, &MainWin::closeTab));
|
ladanyi@53
|
93 |
ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
|
hegyi@47
|
94 |
sigc::mem_fun(*this, &MainWin::hide));
|
ladanyi@6
|
95 |
|
ladanyi@130
|
96 |
ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
|
ladanyi@6
|
97 |
ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
|
hegyi@96
|
98 |
sigc::mem_fun(*this, &MainWin::zoomIn));
|
ladanyi@6
|
99 |
ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
|
hegyi@96
|
100 |
sigc::mem_fun(*this, &MainWin::zoomOut));
|
ladanyi@6
|
101 |
ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
|
hegyi@96
|
102 |
sigc::mem_fun(*this, &MainWin::zoomFit));
|
ladanyi@6
|
103 |
ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
|
hegyi@96
|
104 |
sigc::mem_fun(*this, &MainWin::zoom100));
|
ladanyi@6
|
105 |
|
ladanyi@130
|
106 |
ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
|
ladanyi@130
|
107 |
ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
|
hegyi@95
|
108 |
sigc::mem_fun(*this, &MainWin::createMapWin));
|
ladanyi@6
|
109 |
|
ladanyi@130
|
110 |
ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
|
ladanyi@130
|
111 |
ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
|
hegyi@103
|
112 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
|
ladanyi@130
|
113 |
ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
|
hegyi@106
|
114 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
|
hegyi@103
|
115 |
|
ladanyi@53
|
116 |
Gtk::RadioAction::Group tool_group;
|
ladanyi@130
|
117 |
ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
|
hegyi@96
|
118 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
|
ladanyi@130
|
119 |
ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
|
hegyi@96
|
120 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
|
ladanyi@130
|
121 |
ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
|
hegyi@96
|
122 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
|
ladanyi@130
|
123 |
ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
|
hegyi@96
|
124 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
|
ladanyi@60
|
125 |
|
ladanyi@130
|
126 |
ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
|
hegyi@96
|
127 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
|
ladanyi@130
|
128 |
ag->add( Gtk::RadioAction::create(tool_group, "EditNodeMap", Gtk::StockID("gd-editnode"), _("Edit node map")),
|
hegyi@96
|
129 |
sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 5) );
|
ladanyi@60
|
130 |
|
ladanyi@60
|
131 |
ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
|
hegyi@96
|
132 |
sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
|
hegyi@22
|
133 |
|
ladanyi@6
|
134 |
uim=Gtk::UIManager::create();
|
ladanyi@6
|
135 |
uim->insert_action_group(ag);
|
ladanyi@6
|
136 |
add_accel_group(uim->get_accel_group());
|
ladanyi@6
|
137 |
|
ladanyi@6
|
138 |
try
|
ladanyi@6
|
139 |
{
|
ladanyi@6
|
140 |
|
ladanyi@6
|
141 |
Glib::ustring ui_info =
|
ladanyi@6
|
142 |
"<ui>"
|
ladanyi@6
|
143 |
" <menubar name='MenuBar'>"
|
ladanyi@6
|
144 |
" <menu action='FileMenu'>"
|
ladanyi@6
|
145 |
" <menuitem action='FileNew'/>"
|
ladanyi@6
|
146 |
" <menuitem action='FileOpen'/>"
|
hegyi@102
|
147 |
" <menuitem action='FileClearTab'/>"
|
ladanyi@6
|
148 |
" <menuitem action='FileSave'/>"
|
ladanyi@6
|
149 |
" <menuitem action='FileSaveAs'/>"
|
ladanyi@53
|
150 |
" <menuitem action='Close'/>"
|
ladanyi@53
|
151 |
" <menuitem action='Quit'/>"
|
ladanyi@6
|
152 |
" </menu>"
|
ladanyi@6
|
153 |
" <menu action='ViewMenu'>"
|
ladanyi@6
|
154 |
" <menuitem action='ViewZoomIn' />"
|
ladanyi@6
|
155 |
" <menuitem action='ViewZoomOut' />"
|
ladanyi@6
|
156 |
" <menuitem action='ViewZoom100' />"
|
ladanyi@87
|
157 |
" <menuitem action='ViewZoomFit' />"
|
ladanyi@6
|
158 |
" </menu>"
|
ladanyi@6
|
159 |
" <menu action='ShowMenu'>"
|
ladanyi@6
|
160 |
" <menuitem action='ShowMaps'/>"
|
ladanyi@6
|
161 |
" </menu>"
|
hegyi@103
|
162 |
" <menu action='AlgoMenu'>"
|
hegyi@103
|
163 |
" <menuitem action='AlgoGeneral'/>"
|
hegyi@106
|
164 |
" <menuitem action='AlgoKruskal'/>"
|
hegyi@103
|
165 |
" </menu>"
|
ladanyi@6
|
166 |
" </menubar>"
|
ladanyi@6
|
167 |
" <toolbar name='ToolBar'>"
|
ladanyi@6
|
168 |
" <toolitem action='FileNew' />"
|
ladanyi@6
|
169 |
" <toolitem action='FileOpen' />"
|
ladanyi@6
|
170 |
" <toolitem action='FileSave' />"
|
ladanyi@53
|
171 |
" <toolitem action='Close' />"
|
ladanyi@6
|
172 |
" <separator />"
|
ladanyi@6
|
173 |
" <toolitem action='ViewZoomIn' />"
|
ladanyi@6
|
174 |
" <toolitem action='ViewZoomOut' />"
|
ladanyi@6
|
175 |
" <toolitem action='ViewZoom100' />"
|
ladanyi@87
|
176 |
" <toolitem action='ViewZoomFit' />"
|
hegyi@22
|
177 |
" <separator />"
|
ladanyi@53
|
178 |
" <toolitem action='MoveItem' />"
|
hegyi@22
|
179 |
" <toolitem action='CreateNode' />"
|
hegyi@22
|
180 |
" <toolitem action='CreateEdge' />"
|
hegyi@22
|
181 |
" <toolitem action='EraseItem' />"
|
hegyi@32
|
182 |
" <toolitem action='EditEdgeMap' />"
|
hegyi@32
|
183 |
" <toolitem action='EditNodeMap' />"
|
ladanyi@60
|
184 |
" <separator />"
|
hegyi@41
|
185 |
" <toolitem action='AddMap' />"
|
ladanyi@6
|
186 |
" </toolbar>"
|
ladanyi@6
|
187 |
"</ui>";
|
ladanyi@6
|
188 |
|
ladanyi@6
|
189 |
uim->add_ui_from_string(ui_info);
|
ladanyi@6
|
190 |
|
ladanyi@6
|
191 |
}
|
ladanyi@6
|
192 |
catch(const Glib::Error& ex)
|
ladanyi@6
|
193 |
{
|
ladanyi@6
|
194 |
std::cerr << "building menus failed: " << ex.what();
|
ladanyi@6
|
195 |
}
|
ladanyi@6
|
196 |
|
ladanyi@6
|
197 |
Gtk::Widget* menubar = uim->get_widget("/MenuBar");
|
ladanyi@6
|
198 |
if (menubar){
|
ladanyi@6
|
199 |
vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
|
ladanyi@6
|
200 |
}
|
ladanyi@6
|
201 |
|
ladanyi@6
|
202 |
Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
|
ladanyi@6
|
203 |
if (toolbar)
|
ladanyi@6
|
204 |
{
|
ladanyi@6
|
205 |
static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
|
ladanyi@6
|
206 |
vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
|
ladanyi@6
|
207 |
}
|
ladanyi@6
|
208 |
|
hegyi@50
|
209 |
tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
|
hegyi@50
|
210 |
tooltips.enable();
|
ladanyi@6
|
211 |
|
hegyi@96
|
212 |
active_tab=-1;
|
hegyi@96
|
213 |
notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
|
hegyi@96
|
214 |
|
ladanyi@107
|
215 |
active_tool = MOVE;
|
ladanyi@107
|
216 |
|
hegyi@96
|
217 |
vbox.pack_start(notebook);
|
hegyi@96
|
218 |
|
ladanyi@6
|
219 |
show_all_children();
|
ladanyi@6
|
220 |
}
|
ladanyi@6
|
221 |
|
hegyi@96
|
222 |
void MainWin::set_tabtitle(std::string name)
|
ladanyi@57
|
223 |
{
|
hegyi@104
|
224 |
if(strinst.find(name)==strinst.end())
|
hegyi@104
|
225 |
{
|
hegyi@104
|
226 |
tabnames[active_tab]=name;
|
hegyi@104
|
227 |
strinst[name]=1;
|
hegyi@104
|
228 |
}
|
hegyi@104
|
229 |
else
|
hegyi@104
|
230 |
{
|
hegyi@104
|
231 |
strinst[name]++;
|
hegyi@104
|
232 |
std::ostringstream o;
|
hegyi@104
|
233 |
o << strinst[name];
|
hegyi@104
|
234 |
tabnames[active_tab]=name+" - "+o.str();
|
hegyi@104
|
235 |
}
|
hegyi@96
|
236 |
set_title(tabnames[active_tab] + " - " + prog_name);
|
hegyi@96
|
237 |
notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
|
hegyi@106
|
238 |
updateAlgoWinTabs();
|
hegyi@96
|
239 |
}
|
hegyi@96
|
240 |
|
hegyi@96
|
241 |
void MainWin::readFile(const std::string & filename)
|
hegyi@96
|
242 |
{
|
hegyi@96
|
243 |
newTab();
|
hegyi@96
|
244 |
tabs[active_tab]->readFile(filename);
|
hegyi@96
|
245 |
}
|
hegyi@96
|
246 |
|
hegyi@96
|
247 |
void MainWin::newTab()
|
hegyi@96
|
248 |
{
|
hegyi@96
|
249 |
int size=tabs.size();
|
hegyi@96
|
250 |
tabs.resize(size+1);
|
hegyi@96
|
251 |
tabnames.resize(size+1);
|
hegyi@96
|
252 |
active_tab=size;
|
hegyi@96
|
253 |
tabs[active_tab]=new NoteBookTab();
|
hegyi@96
|
254 |
tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
|
hegyi@96
|
255 |
tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
|
hegyi@96
|
256 |
tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
|
hegyi@96
|
257 |
notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
|
hegyi@96
|
258 |
notebook.set_current_page(size);
|
ladanyi@130
|
259 |
set_tabtitle(_("unsaved file"));
|
hegyi@106
|
260 |
updateAlgoWinTabs();
|
hegyi@96
|
261 |
}
|
hegyi@96
|
262 |
|
hegyi@97
|
263 |
void MainWin::closeTab()
|
hegyi@97
|
264 |
{
|
hegyi@97
|
265 |
if(active_tab!=-1)
|
hegyi@97
|
266 |
{
|
hegyi@102
|
267 |
if (tabs[active_tab]->mapstorage.modified)
|
hegyi@102
|
268 |
{
|
ladanyi@130
|
269 |
Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
|
hegyi@102
|
270 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
ladanyi@130
|
271 |
mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
|
hegyi@102
|
272 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@102
|
273 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@102
|
274 |
switch (mdialog.run())
|
hegyi@102
|
275 |
{
|
hegyi@102
|
276 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@102
|
277 |
return;
|
hegyi@102
|
278 |
case Gtk::RESPONSE_REJECT:
|
hegyi@102
|
279 |
break;
|
hegyi@102
|
280 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@102
|
281 |
tabs[active_tab]->saveFile();
|
hegyi@102
|
282 |
break;
|
hegyi@102
|
283 |
}
|
hegyi@102
|
284 |
}
|
hegyi@97
|
285 |
//tabs vector will be decreased with the deleted value
|
hegyi@97
|
286 |
int size=tabs.size();
|
hegyi@97
|
287 |
if(size>1)
|
hegyi@97
|
288 |
{
|
hegyi@97
|
289 |
for(int i=active_tab+1;i<size;i++)
|
hegyi@97
|
290 |
{
|
hegyi@103
|
291 |
tabnames[i-1]=tabnames[i];
|
hegyi@97
|
292 |
tabs[i-1]=tabs[i];
|
hegyi@97
|
293 |
}
|
hegyi@97
|
294 |
}
|
hegyi@97
|
295 |
//if size==1 resize will delete the only element
|
hegyi@97
|
296 |
tabs.resize(size-1);
|
hegyi@103
|
297 |
tabnames.resize(size-1);
|
hegyi@97
|
298 |
|
hegyi@97
|
299 |
int old_active_tab=active_tab;
|
hegyi@97
|
300 |
notebook.remove_page(active_tab);
|
hegyi@97
|
301 |
|
hegyi@97
|
302 |
//If the first tab was active, upon delete notebook
|
hegyi@97
|
303 |
//will first switch one tab upper and not lower like
|
hegyi@97
|
304 |
//in the case, when not the first tab was active.
|
hegyi@97
|
305 |
//But after deletion it will become the first tab,
|
hegyi@97
|
306 |
//and this should be registrated in tabs vector,
|
hegyi@97
|
307 |
//as well.
|
hegyi@103
|
308 |
if((old_active_tab==0)&&(size!=1))
|
hegyi@97
|
309 |
{
|
hegyi@97
|
310 |
onChangeTab(NULL,0);
|
hegyi@97
|
311 |
}
|
hegyi@97
|
312 |
|
hegyi@97
|
313 |
//if this was the last page in notebook, there is
|
hegyi@97
|
314 |
//no active_tab now
|
hegyi@97
|
315 |
if(size==1)
|
hegyi@97
|
316 |
{
|
hegyi@97
|
317 |
active_tab=-1;
|
hegyi@97
|
318 |
}
|
hegyi@103
|
319 |
|
hegyi@106
|
320 |
updateAlgoWinTabs();
|
hegyi@97
|
321 |
}
|
hegyi@97
|
322 |
}
|
hegyi@97
|
323 |
|
hegyi@96
|
324 |
void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
|
hegyi@96
|
325 |
{
|
hegyi@96
|
326 |
page=page;
|
hegyi@96
|
327 |
active_tab=page_num;
|
hegyi@96
|
328 |
tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
|
hegyi@96
|
329 |
set_title(tabnames[active_tab]);
|
hegyi@96
|
330 |
}
|
hegyi@96
|
331 |
|
ladanyi@6
|
332 |
void MainWin::newFile()
|
ladanyi@6
|
333 |
{
|
hegyi@96
|
334 |
if(active_tab!=-1)
|
ladanyi@53
|
335 |
{
|
hegyi@96
|
336 |
tabs[active_tab]->newFile();
|
ladanyi@53
|
337 |
}
|
ladanyi@6
|
338 |
}
|
hegyi@96
|
339 |
|
ladanyi@6
|
340 |
void MainWin::openFile()
|
ladanyi@6
|
341 |
{
|
ladanyi@140
|
342 |
if(active_tab==-1)
|
ladanyi@53
|
343 |
{
|
ladanyi@140
|
344 |
newTab();
|
ladanyi@53
|
345 |
}
|
ladanyi@140
|
346 |
tabs[active_tab]->openFile();
|
ladanyi@6
|
347 |
}
|
hegyi@96
|
348 |
|
ladanyi@6
|
349 |
void MainWin::saveFile()
|
ladanyi@6
|
350 |
{
|
hegyi@96
|
351 |
if(active_tab!=-1)
|
hegyi@96
|
352 |
{
|
hegyi@96
|
353 |
tabs[active_tab]->saveFile();
|
hegyi@96
|
354 |
}
|
ladanyi@6
|
355 |
}
|
hegyi@96
|
356 |
|
ladanyi@6
|
357 |
void MainWin::saveFileAs()
|
ladanyi@6
|
358 |
{
|
hegyi@96
|
359 |
if(active_tab!=-1)
|
hegyi@96
|
360 |
{
|
hegyi@96
|
361 |
tabs[active_tab]->saveFileAs();
|
hegyi@96
|
362 |
}
|
ladanyi@6
|
363 |
}
|
hegyi@96
|
364 |
|
ladanyi@53
|
365 |
void MainWin::close()
|
ladanyi@53
|
366 |
{
|
hegyi@96
|
367 |
if(active_tab!=-1)
|
ladanyi@53
|
368 |
{
|
hegyi@96
|
369 |
tabs[active_tab]->close();
|
hegyi@95
|
370 |
}
|
hegyi@94
|
371 |
}
|
hegyi@94
|
372 |
|
hegyi@96
|
373 |
void MainWin::zoomIn()
|
hegyi@94
|
374 |
{
|
hegyi@96
|
375 |
if(active_tab!=-1)
|
hegyi@95
|
376 |
{
|
hegyi@96
|
377 |
tabs[active_tab]->gd_canvas->zoomIn();
|
hegyi@96
|
378 |
}
|
hegyi@96
|
379 |
}
|
hegyi@96
|
380 |
|
hegyi@96
|
381 |
void MainWin::zoomOut()
|
hegyi@96
|
382 |
{
|
hegyi@96
|
383 |
if(active_tab!=-1)
|
hegyi@96
|
384 |
{
|
hegyi@96
|
385 |
tabs[active_tab]->gd_canvas->zoomOut();
|
hegyi@96
|
386 |
}
|
hegyi@96
|
387 |
}
|
hegyi@96
|
388 |
|
hegyi@96
|
389 |
void MainWin::zoomFit()
|
hegyi@96
|
390 |
{
|
hegyi@96
|
391 |
if(active_tab!=-1)
|
hegyi@96
|
392 |
{
|
hegyi@96
|
393 |
tabs[active_tab]->gd_canvas->zoomFit();
|
hegyi@96
|
394 |
}
|
hegyi@96
|
395 |
}
|
hegyi@96
|
396 |
|
hegyi@96
|
397 |
void MainWin::zoom100()
|
hegyi@96
|
398 |
{
|
hegyi@96
|
399 |
if(active_tab!=-1)
|
hegyi@96
|
400 |
{
|
hegyi@96
|
401 |
tabs[active_tab]->gd_canvas->zoom100();
|
hegyi@95
|
402 |
}
|
hegyi@94
|
403 |
}
|
hegyi@95
|
404 |
|
hegyi@95
|
405 |
void MainWin::createMapWin()
|
hegyi@95
|
406 |
{
|
hegyi@96
|
407 |
if(active_tab!=-1)
|
hegyi@95
|
408 |
{
|
hegyi@96
|
409 |
tabs[active_tab]->createMapWin(tabnames[active_tab]);
|
hegyi@95
|
410 |
}
|
hegyi@95
|
411 |
}
|
hegyi@95
|
412 |
|
hegyi@103
|
413 |
void MainWin::createAlgoWin(int algoid)
|
hegyi@103
|
414 |
{
|
hegyi@108
|
415 |
AlgoWin * aw=new AlgoWin(algoid, tabnames);
|
hegyi@103
|
416 |
aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
|
hegyi@106
|
417 |
aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
|
hegyi@114
|
418 |
aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
|
hegyi@103
|
419 |
aws.insert(aw);
|
hegyi@103
|
420 |
aw->show();
|
hegyi@103
|
421 |
}
|
hegyi@103
|
422 |
|
hegyi@106
|
423 |
void MainWin::updateAlgoWinTabs()
|
hegyi@103
|
424 |
{
|
hegyi@103
|
425 |
std::set< AlgoWin* >::iterator awsi=aws.begin();
|
hegyi@103
|
426 |
for(;awsi!=aws.end();awsi++)
|
hegyi@103
|
427 |
{
|
hegyi@103
|
428 |
(*awsi)->update_tablist(tabnames);
|
hegyi@103
|
429 |
}
|
hegyi@103
|
430 |
}
|
hegyi@103
|
431 |
|
hegyi@108
|
432 |
void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
|
hegyi@108
|
433 |
{
|
hegyi@108
|
434 |
int i=0;
|
hegyi@108
|
435 |
for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
|
hegyi@108
|
436 |
{
|
hegyi@108
|
437 |
}
|
hegyi@108
|
438 |
awp->update_maplist(&(tabs[i]->mapstorage));
|
hegyi@108
|
439 |
}
|
hegyi@108
|
440 |
|
hegyi@108
|
441 |
void MainWin::deRegisterAlgoWin(AlgoWin * awp)
|
hegyi@108
|
442 |
{
|
hegyi@108
|
443 |
aws.erase(awp);
|
hegyi@108
|
444 |
}
|
hegyi@108
|
445 |
|
hegyi@96
|
446 |
void MainWin::changeEditorialTool(int tool)
|
hegyi@95
|
447 |
{
|
hegyi@96
|
448 |
active_tool=tool;
|
hegyi@96
|
449 |
if(active_tab!=-1)
|
hegyi@96
|
450 |
{
|
hegyi@96
|
451 |
tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
|
hegyi@96
|
452 |
}
|
hegyi@95
|
453 |
}
|
hegyi@96
|
454 |
|
hegyi@96
|
455 |
void MainWin::createNewMapWin()
|
hegyi@96
|
456 |
{
|
hegyi@96
|
457 |
if(active_tab!=-1)
|
hegyi@96
|
458 |
{
|
ladanyi@130
|
459 |
NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
|
hegyi@96
|
460 |
nmw->show();
|
hegyi@96
|
461 |
}
|
hegyi@96
|
462 |
}
|
hegyi@96
|
463 |
|
hegyi@114
|
464 |
void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
|
hegyi@114
|
465 |
{
|
hegyi@114
|
466 |
int i=0;
|
hegyi@120
|
467 |
for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
|
hegyi@114
|
468 |
{
|
hegyi@114
|
469 |
}
|
hegyi@114
|
470 |
createNewMapWinAfterSignal(tabs[i], itisedge);
|
hegyi@114
|
471 |
}
|
hegyi@114
|
472 |
|
hegyi@96
|
473 |
void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
|
hegyi@96
|
474 |
{
|
hegyi@96
|
475 |
std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
|
hegyi@96
|
476 |
int i=0;
|
hegyi@96
|
477 |
for(;nbti!=tabs.end();nbti++)
|
hegyi@96
|
478 |
{
|
hegyi@96
|
479 |
if(*nbti!=nbt)
|
hegyi@96
|
480 |
{
|
hegyi@96
|
481 |
i++;
|
hegyi@96
|
482 |
}
|
hegyi@96
|
483 |
else
|
hegyi@96
|
484 |
{
|
hegyi@96
|
485 |
continue;
|
hegyi@96
|
486 |
}
|
hegyi@96
|
487 |
}
|
ladanyi@130
|
488 |
NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);
|
hegyi@96
|
489 |
nmw->run();
|
hegyi@96
|
490 |
}
|