fix two more bugs
[xonotic/netradiant.git] / radiant / mainframe.cpp
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //
23 // Main Window for Q3Radiant
24 //
25 // Leonardo Zide (leo@lokigames.com)
26 //
27
28 #include "mainframe.h"
29
30 #include "debugging/debugging.h"
31 #include "version.h"
32
33 #include "ifilesystem.h"
34 #include "iundo.h"
35 #include "ifilter.h"
36 #include "itoolbar.h"
37 #include "editable.h"
38 #include "ientity.h"
39 #include "ishaders.h"
40 #include "igl.h"
41 #include "moduleobserver.h"
42
43 #include <ctime>
44
45 #include <gdk/gdkkeysyms.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkframe.h>
49 #include <gtk/gtklabel.h>
50 #include <gtk/gtkhpaned.h>
51 #include <gtk/gtkvpaned.h>
52 #include <gtk/gtktoolbar.h>
53 #include <gtk/gtkmenubar.h>
54 #include <gtk/gtkimage.h>
55 #include <gtk/gtktable.h>
56
57
58 #include "cmdlib.h"
59 #include "scenelib.h"
60 #include "stream/stringstream.h"
61 #include "signal/isignal.h"
62 #include "os/path.h"
63 #include "os/file.h"
64 #include "eclasslib.h"
65 #include "moduleobservers.h"
66
67 #include "gtkutil/clipboard.h"
68 #include "gtkutil/container.h"
69 #include "gtkutil/frame.h"
70 #include "gtkutil/glfont.h"
71 #include "gtkutil/glwidget.h"
72 #include "gtkutil/image.h"
73 #include "gtkutil/menu.h"
74 #include "gtkutil/paned.h"
75 #include "gtkutil/widget.h"
76
77 #include "autosave.h"
78 #include "build.h"
79 #include "brushmanip.h"
80 #include "brushmodule.h"
81 #include "camwindow.h"
82 #include "csg.h"
83 #include "commands.h"
84 #include "console.h"
85 #include "entity.h"
86 #include "entityinspector.h"
87 #include "entitylist.h"
88 #include "filters.h"
89 #include "findtexturedialog.h"
90 #include "grid.h"
91 #include "groupdialog.h"
92 #include "gtkdlgs.h"
93 #include "gtkmisc.h"
94 #include "help.h"
95 #include "map.h"
96 #include "mru.h"
97 #include "multimon.h"
98 #include "patchdialog.h"
99 #include "patchmanip.h"
100 #include "plugin.h"
101 #include "pluginmanager.h"
102 #include "pluginmenu.h"
103 #include "plugintoolbar.h"
104 #include "points.h"
105 #include "preferences.h"
106 #include "qe3.h"
107 #include "qgl.h"
108 #include "select.h"
109 #include "server.h"
110 #include "surfacedialog.h"
111 #include "textures.h"
112 #include "texwindow.h"
113 #include "url.h"
114 #include "xywindow.h"
115 #include "windowobservers.h"
116 #include "renderstate.h"
117 #include "feedback.h"
118 #include "referencecache.h"
119
120
121
122 struct layout_globals_t
123 {
124   WindowPosition m_position;
125
126
127   int nXYHeight;
128   int nXYWidth;
129   int nCamWidth;
130   int nCamHeight;
131   int nState;
132
133   layout_globals_t() :
134     m_position(-1, -1, 640, 480),
135
136     nXYHeight(300),
137     nXYWidth(300),
138     nCamWidth(200),
139     nCamHeight(200),
140     nState(GDK_WINDOW_STATE_MAXIMIZED)
141   {
142   }
143 };
144
145 layout_globals_t g_layout_globals;
146 glwindow_globals_t g_glwindow_globals;
147
148
149 // VFS
150 class VFSModuleObserver : public ModuleObserver
151 {
152   std::size_t m_unrealised;
153 public:
154   VFSModuleObserver() : m_unrealised(1)
155   {
156   }
157   void realise()
158   {
159     if(--m_unrealised == 0)
160     {
161       QE_InitVFS();
162       GlobalFileSystem().initialise();
163     }
164   }
165   void unrealise()
166   {
167     if(++m_unrealised == 1)
168     {
169       GlobalFileSystem().shutdown();
170     }
171   }
172 };
173
174 VFSModuleObserver g_VFSModuleObserver;
175
176 void VFS_Construct()
177 {
178     Radiant_attachHomePathsObserver(g_VFSModuleObserver);
179 }
180 void VFS_Destroy()
181 {
182     Radiant_detachHomePathsObserver(g_VFSModuleObserver);
183 }
184
185 // Home Paths
186
187 void HomePaths_Realise()
188 {
189 #if defined(POSIX)
190   const char* prefix = g_pGameDescription->getKeyValue("prefix");
191   if(!string_empty(prefix))
192   {
193     StringOutputStream path(256);
194     path << DirectoryCleaned(g_get_home_dir()) << prefix << "/";
195     g_qeglobals.m_userEnginePath = path.c_str();
196     Q_mkdir(g_qeglobals.m_userEnginePath.c_str());
197   }
198   else
199 #elif defined(WIN32)
200   if(!string_empty(prefix))
201   {
202     StringOutputStream path(256);
203     TCHAR mydocsdir[MAX_PATH + 1];
204     if(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, mydocsdir))
205     {
206       path << DirectoryCleaned(mydocsdir) << "My Games/" << prefix << "/";
207       // win32: only add it if it already exists
208       if(file_is_directory(path.c_str()))
209         g_qeglobals.m_userEnginePath = path.c_str();
210       else
211         g_qeglobals.m_userEnginePath = EnginePath_get();
212     }
213     else
214     {
215       g_qeglobals.m_userEnginePath = EnginePath_get();
216     }
217   }
218   else
219 #endif
220   {
221     g_qeglobals.m_userEnginePath = EnginePath_get();
222   }
223
224   {
225     StringOutputStream path(256);
226     path << g_qeglobals.m_userEnginePath.c_str() << gamename_get() << '/';
227     g_qeglobals.m_userGamePath = path.c_str();
228   }
229   ASSERT_MESSAGE(!string_empty(g_qeglobals.m_userGamePath.c_str()), "HomePaths_Realise: user-game-path is empty");
230   Q_mkdir(g_qeglobals.m_userGamePath.c_str());
231 }
232
233 ModuleObservers g_homePathObservers;
234
235 void Radiant_attachHomePathsObserver(ModuleObserver& observer)
236 {
237   g_homePathObservers.attach(observer);
238 }
239
240 void Radiant_detachHomePathsObserver(ModuleObserver& observer)
241 {
242   g_homePathObservers.detach(observer);
243 }
244
245 class HomePathsModuleObserver : public ModuleObserver
246 {
247   std::size_t m_unrealised;
248 public:
249   HomePathsModuleObserver() : m_unrealised(1)
250   {
251   }
252   void realise()
253   {
254     if(--m_unrealised == 0)
255     {
256       HomePaths_Realise();
257       g_homePathObservers.realise();
258     }
259   }
260   void unrealise()
261   {
262     if(++m_unrealised == 1)
263     {
264       g_homePathObservers.unrealise();
265     }
266   }
267 };
268
269 HomePathsModuleObserver g_HomePathsModuleObserver;
270
271 void HomePaths_Construct()
272 {
273     Radiant_attachEnginePathObserver(g_HomePathsModuleObserver);
274 }
275 void HomePaths_Destroy()
276 {
277     Radiant_detachEnginePathObserver(g_HomePathsModuleObserver);
278 }
279
280
281 // Engine Path
282
283 CopiedString g_strEnginePath;
284 ModuleObservers g_enginePathObservers;
285 std::size_t g_enginepath_unrealised = 1;
286
287 void Radiant_attachEnginePathObserver(ModuleObserver& observer)
288 {
289   g_enginePathObservers.attach(observer);
290 }
291
292 void Radiant_detachEnginePathObserver(ModuleObserver& observer)
293 {
294   g_enginePathObservers.detach(observer);
295 }
296
297
298 void EnginePath_Realise()
299 {
300   if(--g_enginepath_unrealised == 0)
301   {
302     g_enginePathObservers.realise();
303   }
304 }
305
306
307 const char* EnginePath_get()
308 {
309   ASSERT_MESSAGE(g_enginepath_unrealised == 0, "EnginePath_get: engine path not realised");
310   return g_strEnginePath.c_str();
311 }
312
313 void EnginePath_Unrealise()
314 {
315   if(++g_enginepath_unrealised == 1)
316   {
317     g_enginePathObservers.unrealise();
318   }
319 }
320
321 void setEnginePath(const char* path)
322 {
323   StringOutputStream buffer(256);
324   buffer << DirectoryCleaned(path);
325   if(!path_equal(buffer.c_str(), g_strEnginePath.c_str()))
326   {
327 #if 0
328     while(!ConfirmModified("Paths Changed"))
329     {
330       if(Map_Unnamed(g_map))
331       {
332         Map_SaveAs();
333       }
334       else
335       {
336         Map_Save();
337       }
338     }
339     Map_RegionOff();
340 #endif
341
342     ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Changing Engine Path");
343
344     EnginePath_Unrealise();
345
346     g_strEnginePath = buffer.c_str();
347
348     EnginePath_Realise();
349   }
350 }
351
352
353 // App Path
354
355 CopiedString g_strAppPath;                 ///< holds the full path of the executable
356
357 const char* AppPath_get()
358 {
359   return g_strAppPath.c_str();
360 }
361
362 /// the path to the local rc-dir
363 const char* LocalRcPath_get(void)
364 {
365   static CopiedString rc_path;
366   if(rc_path.empty())
367   {
368     StringOutputStream stream(256);
369         stream << GlobalRadiant().getSettingsPath() << g_pGameDescription->mGameFile.c_str() << "/";
370         rc_path = stream.c_str();
371   }
372   return rc_path.c_str();
373 }
374
375 /// directory for temp files
376 /// NOTE: on *nix this is were we check for .pid
377 CopiedString g_strSettingsPath;
378 const char* SettingsPath_get()
379 {
380   return g_strSettingsPath.c_str();
381 }
382
383
384 /*!
385 points to the game tools directory, for instance
386 C:/Program Files/Quake III Arena/GtkRadiant
387 (or other games)
388 this is one of the main variables that are configured by the game selection on startup
389 [GameToolsPath]/plugins
390 [GameToolsPath]/modules
391 and also q3map, bspc
392 */
393 CopiedString g_strGameToolsPath;           ///< this is set by g_GamesDialog
394
395 const char* GameToolsPath_get()
396 {
397   return g_strGameToolsPath.c_str();
398 }
399
400 void EnginePathImport(CopiedString& self, const char* value)
401 {
402   setEnginePath(value);
403 }
404 typedef ReferenceCaller1<CopiedString, const char*, EnginePathImport> EnginePathImportCaller;
405
406 void Paths_constructPreferences(PreferencesPage& page)
407 {
408   page.appendPathEntry("Engine Path", true,
409     StringImportCallback(EnginePathImportCaller(g_strEnginePath)),
410     StringExportCallback(StringExportCaller(g_strEnginePath))
411   );
412 }
413 void Paths_constructPage(PreferenceGroup& group)
414 {
415   PreferencesPage page(group.createPage("Paths", "Path Settings"));
416   Paths_constructPreferences(page);
417 }
418 void Paths_registerPreferencesPage()
419 {
420   PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, Paths_constructPage>());
421 }
422
423
424 class PathsDialog : public Dialog
425 {
426 public:
427   GtkWindow* BuildDialog()
428   {
429     GtkFrame* frame = create_dialog_frame("Path settings", GTK_SHADOW_ETCHED_IN);
430
431     GtkVBox* vbox2 = create_dialog_vbox(0, 4);
432     gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(vbox2));
433
434     {
435       PreferencesPage preferencesPage(*this, GTK_WIDGET(vbox2));
436       Paths_constructPreferences(preferencesPage);
437     }
438
439     return create_simple_modal_dialog_window("Engine Path Not Found", m_modal, GTK_WIDGET(frame));
440   }
441 };
442
443 PathsDialog g_PathsDialog;
444
445 void EnginePath_verify()
446 {
447   if(!file_exists(g_strEnginePath.c_str()))
448   {
449     g_PathsDialog.Create();
450     g_PathsDialog.DoModal();
451     g_PathsDialog.Destroy();
452   }
453 }
454
455 namespace
456 {
457   CopiedString g_gamename;
458   CopiedString g_gamemode;
459   ModuleObservers g_gameNameObservers;
460   ModuleObservers g_gameModeObservers;
461 }
462
463 void Radiant_attachGameNameObserver(ModuleObserver& observer)
464 {
465   g_gameNameObservers.attach(observer);
466 }
467
468 void Radiant_detachGameNameObserver(ModuleObserver& observer)
469 {
470   g_gameNameObservers.detach(observer);
471 }
472
473 const char* basegame_get()
474 {
475   return g_pGameDescription->getRequiredKeyValue("basegame");
476 }
477
478 const char* gamename_get()
479 {
480   const char* gamename = g_gamename.c_str();
481   if(string_empty(gamename))
482   {
483     return basegame_get();
484   }
485   return gamename;
486 }
487
488 void gamename_set(const char* gamename)
489 {
490   if(!string_equal(gamename, g_gamename.c_str()))
491   {
492     g_gameNameObservers.unrealise();
493     g_gamename = gamename;
494     g_gameNameObservers.realise();
495   }
496 }
497
498 void Radiant_attachGameModeObserver(ModuleObserver& observer)
499 {
500   g_gameModeObservers.attach(observer);
501 }
502
503 void Radiant_detachGameModeObserver(ModuleObserver& observer)
504 {
505   g_gameModeObservers.detach(observer);
506 }
507
508 const char* gamemode_get()
509 {
510   return g_gamemode.c_str();
511 }
512
513 void gamemode_set(const char* gamemode)
514 {
515   if(!string_equal(gamemode, g_gamemode.c_str()))
516   {
517     g_gameModeObservers.unrealise();
518     g_gamemode = gamemode;
519     g_gameModeObservers.realise();
520   }
521 }
522
523 #include "os/dir.h"
524
525 class CLoadModule
526 {
527   const char* m_path;
528 public:
529   CLoadModule(const char* path) : m_path(path)
530   {
531   }
532   void operator()(const char* name) const
533   {
534     char fullname[1024];
535     ASSERT_MESSAGE(strlen(m_path) + strlen(name) < 1024, "");
536     strcpy(fullname, m_path);
537     strcat(fullname, name);
538     globalOutputStream() << "Found '" << fullname << "'\n";
539     GlobalModuleServer_loadModule(fullname);
540   }
541 };
542
543 const char* const c_library_extension =
544 #if defined(WIN32)
545 "dll"
546 #elif defined (__APPLE__)
547 "dylib"
548 #elif defined(__linux__) || defined (__FreeBSD__)
549 "so"
550 #endif
551 ;
552
553 void Radiant_loadModules(const char* path)
554 {
555   Directory_forEach(path, MatchFileExtension<CLoadModule>(c_library_extension, CLoadModule(path)));
556 }
557
558 void Radiant_loadModulesFromRoot(const char* directory)
559 {
560   {
561     StringOutputStream path(256);
562     path << directory << g_pluginsDir;
563     Radiant_loadModules(path.c_str());
564   }
565
566   if(!string_equal(g_pluginsDir, g_modulesDir))
567   {
568     StringOutputStream path(256);
569     path << directory << g_modulesDir;
570     Radiant_loadModules(path.c_str());
571   }
572 }
573
574 //! Make COLOR_BRUSHES override worldspawn eclass colour.
575 void SetWorldspawnColour(const Vector3& colour)
576 {
577   EntityClass* worldspawn = GlobalEntityClassManager().findOrInsert("worldspawn", true);
578   eclass_release_state(worldspawn);
579   worldspawn->color = colour;
580   eclass_capture_state(worldspawn);
581 }
582
583
584 class WorldspawnColourEntityClassObserver : public ModuleObserver
585 {
586   std::size_t m_unrealised;
587 public:
588   WorldspawnColourEntityClassObserver() : m_unrealised(1)
589   {
590   }
591   void realise()
592   {
593     if(--m_unrealised == 0)
594     {
595       SetWorldspawnColour(g_xywindow_globals.color_brushes);
596     }
597   }
598   void unrealise()
599   {
600     if(++m_unrealised == 1)
601     {
602     }
603   }
604 };
605
606 WorldspawnColourEntityClassObserver g_WorldspawnColourEntityClassObserver;
607
608
609 ModuleObservers g_gameToolsPathObservers;
610
611 void Radiant_attachGameToolsPathObserver(ModuleObserver& observer)
612 {
613   g_gameToolsPathObservers.attach(observer);
614 }
615
616 void Radiant_detachGameToolsPathObserver(ModuleObserver& observer)
617 {
618   g_gameToolsPathObservers.detach(observer);
619 }
620
621 void Radiant_Initialise()
622 {
623   GlobalModuleServer_Initialise();
624
625   Radiant_loadModulesFromRoot(AppPath_get());
626
627   Preferences_Load();
628
629   bool success = Radiant_Construct(GlobalModuleServer_get());
630   ASSERT_MESSAGE(success, "module system failed to initialise - see radiant.log for error messages");
631
632   g_gameToolsPathObservers.realise();
633   g_gameModeObservers.realise();
634   g_gameNameObservers.realise();
635 }
636
637 void Radiant_Shutdown()
638 {
639   g_gameNameObservers.unrealise();
640   g_gameModeObservers.unrealise();
641   g_gameToolsPathObservers.unrealise();
642
643   if (!g_preferences_globals.disable_ini)
644   {
645     globalOutputStream() << "Start writing prefs\n";
646     Preferences_Save();
647     globalOutputStream() << "Done prefs\n";
648   }
649
650   Radiant_Destroy();
651
652   GlobalModuleServer_Shutdown();
653 }
654
655 void Exit()
656 {
657   if(ConfirmModified("Exit Radiant"))
658   {
659     gtk_main_quit();
660   }
661 }
662
663
664 void Undo()
665 {
666   GlobalUndoSystem().undo();
667   SceneChangeNotify();
668 }
669
670 void Redo()
671 {
672   GlobalUndoSystem().redo();
673   SceneChangeNotify();
674 }
675
676 void deleteSelection()
677 {
678   UndoableCommand undo("deleteSelected");
679   Select_Delete();
680 }
681
682 void Map_ExportSelected(TextOutputStream& ostream)
683 {
684   Map_ExportSelected(ostream, Map_getFormat(g_map));
685 }
686
687 void Map_ImportSelected(TextInputStream& istream)
688 {
689   Map_ImportSelected(istream, Map_getFormat(g_map));
690 }
691
692 void Selection_Copy()
693 {
694   clipboard_copy(Map_ExportSelected);
695 }
696
697 void Selection_Paste()
698 {
699   clipboard_paste(Map_ImportSelected);
700 }
701
702 void Copy()
703 {
704   if(SelectedFaces_empty())
705   {
706     Selection_Copy();
707   }
708   else
709   {
710     SelectedFaces_copyTexture();
711   }
712 }
713
714 void Paste()
715 {
716   if(SelectedFaces_empty())
717   {
718     UndoableCommand undo("paste");
719
720     GlobalSelectionSystem().setSelectedAll(false);
721     Selection_Paste();
722   }
723   else
724   {
725     SelectedFaces_pasteTexture();
726   }
727 }
728
729 void PasteToCamera()
730 {
731   CamWnd& camwnd = *g_pParentWnd->GetCamWnd();
732   GlobalSelectionSystem().setSelectedAll(false);
733
734   UndoableCommand undo("pasteToCamera");
735
736   Selection_Paste();
737
738   // Work out the delta
739   Vector3 mid;
740   Select_GetMid(mid);
741   Vector3 delta = vector3_subtracted(vector3_snapped(Camera_getOrigin(camwnd), GetSnapGridSize()), mid);
742
743   // Move to camera
744   GlobalSelectionSystem().translateSelected(delta);
745 }
746
747
748 void ColorScheme_Original()
749 {
750   TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
751
752   g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
753   g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
754   CamWnd_Update(*g_pParentWnd->GetCamWnd());
755
756   g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
757   g_xywindow_globals.color_gridminor = Vector3(0.75f, 0.75f, 0.75f);
758   g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
759   g_xywindow_globals.color_gridminor_alt = Vector3(0.5f, 0.0f, 0.0f);
760   g_xywindow_globals.color_gridmajor_alt = Vector3(1.0f, 0.0f, 0.0f);
761   g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
762   g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
763   g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
764   g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
765   g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
766   SetWorldspawnColour(g_xywindow_globals.color_brushes);
767   g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
768   XY_UpdateAllWindows();
769 }
770
771 void ColorScheme_QER()
772 {
773   TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
774
775   g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
776   g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
777   CamWnd_Update(*g_pParentWnd->GetCamWnd());
778
779   g_xywindow_globals.color_gridback = Vector3(1.0f, 1.0f, 1.0f);
780   g_xywindow_globals.color_gridminor = Vector3(1.0f, 1.0f, 1.0f);
781   g_xywindow_globals.color_gridmajor = Vector3(0.5f, 0.5f, 0.5f);
782   g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
783   g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
784   g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
785   g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
786   g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
787   SetWorldspawnColour(g_xywindow_globals.color_brushes);
788   g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
789   XY_UpdateAllWindows();
790 }
791
792 void ColorScheme_Black()
793 {
794   TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
795
796   g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
797   g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
798   CamWnd_Update(*g_pParentWnd->GetCamWnd());
799
800   g_xywindow_globals.color_gridback = Vector3(0.0f, 0.0f, 0.0f);
801   g_xywindow_globals.color_gridminor = Vector3(0.2f, 0.2f, 0.2f);
802   g_xywindow_globals.color_gridmajor = Vector3(0.3f, 0.5f, 0.5f);
803   g_xywindow_globals.color_gridblock = Vector3(0.0f, 0.0f, 1.0f);
804   g_xywindow_globals.color_gridtext = Vector3(1.0f, 1.0f, 1.0f);
805   g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
806   g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
807   g_xywindow_globals.color_brushes = Vector3(1.0f, 1.0f, 1.0f);
808   SetWorldspawnColour(g_xywindow_globals.color_brushes);
809   g_xywindow_globals.color_viewname = Vector3(0.7f, 0.7f, 0.0f);
810   XY_UpdateAllWindows();
811 }
812
813 /* ydnar: to emulate maya/max/lightwave color schemes */
814 void ColorScheme_Ydnar()
815 {
816   TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), Vector3(0.25f, 0.25f, 0.25f));
817
818   g_camwindow_globals.color_cameraback = Vector3(0.25f, 0.25f, 0.25f);
819   g_camwindow_globals.color_selbrushes3d = Vector3(1.0f, 0.0f, 0.0f);
820   CamWnd_Update(*g_pParentWnd->GetCamWnd());
821
822   g_xywindow_globals.color_gridback = Vector3(0.77f, 0.77f, 0.77f);
823   g_xywindow_globals.color_gridminor = Vector3(0.83f, 0.83f, 0.83f);
824   g_xywindow_globals.color_gridmajor = Vector3(0.89f, 0.89f, 0.89f);
825   g_xywindow_globals.color_gridblock = Vector3(1.0f, 1.0f, 1.0f);
826   g_xywindow_globals.color_gridtext = Vector3(0.0f, 0.0f, 0.0f);
827   g_xywindow_globals.color_selbrushes = Vector3(1.0f, 0.0f, 0.0f);
828   g_xywindow_globals.color_clipper = Vector3(0.0f, 0.0f, 1.0f);
829   g_xywindow_globals.color_brushes = Vector3(0.0f, 0.0f, 0.0f);
830   SetWorldspawnColour(g_xywindow_globals.color_brushes);
831   g_xywindow_globals.color_viewname = Vector3(0.5f, 0.0f, 0.75f);
832   XY_UpdateAllWindows();
833 }
834
835 typedef Callback1<Vector3&> GetColourCallback;
836 typedef Callback1<const Vector3&> SetColourCallback;
837
838 class ChooseColour
839 {
840   GetColourCallback m_get;
841   SetColourCallback m_set;
842 public:
843   ChooseColour(const GetColourCallback& get, const SetColourCallback& set)
844     : m_get(get), m_set(set)
845   {
846   }
847   void operator()()
848   {
849     Vector3 colour;
850     m_get(colour);
851     color_dialog(GTK_WIDGET(MainFrame_getWindow()), colour);
852     m_set(colour);
853   }
854 };
855
856
857
858 void Colour_get(const Vector3& colour, Vector3& other)
859 {
860   other = colour;
861 }
862 typedef ConstReferenceCaller1<Vector3, Vector3&, Colour_get> ColourGetCaller;
863
864 void Colour_set(Vector3& colour, const Vector3& other)
865 {
866   colour = other;
867   SceneChangeNotify();
868 }
869 typedef ReferenceCaller1<Vector3, const Vector3&, Colour_set> ColourSetCaller;
870
871 void BrushColour_set(const Vector3& other)
872 {
873   g_xywindow_globals.color_brushes = other;
874   SetWorldspawnColour(g_xywindow_globals.color_brushes);
875   SceneChangeNotify();
876 }
877 typedef FreeCaller1<const Vector3&, BrushColour_set> BrushColourSetCaller;
878
879 void ClipperColour_set(const Vector3& other)
880 {
881   g_xywindow_globals.color_clipper = other;
882   Brush_clipperColourChanged();
883   SceneChangeNotify();
884 }
885 typedef FreeCaller1<const Vector3&, ClipperColour_set> ClipperColourSetCaller;
886
887 void TextureBrowserColour_get(Vector3& other)
888 {
889   other = TextureBrowser_getBackgroundColour(GlobalTextureBrowser());
890 }
891 typedef FreeCaller1<Vector3&, TextureBrowserColour_get> TextureBrowserColourGetCaller;
892
893 void TextureBrowserColour_set(const Vector3& other)
894 {
895   TextureBrowser_setBackgroundColour(GlobalTextureBrowser(), other);
896 }
897 typedef FreeCaller1<const Vector3&, TextureBrowserColour_set> TextureBrowserColourSetCaller;
898
899
900 class ColoursMenu
901 {
902 public:
903   ChooseColour m_textureback;
904   ChooseColour m_xyback;
905   ChooseColour m_gridmajor;
906   ChooseColour m_gridminor;
907   ChooseColour m_gridmajor_alt;
908   ChooseColour m_gridminor_alt;
909   ChooseColour m_gridtext;
910   ChooseColour m_gridblock;
911   ChooseColour m_cameraback;
912   ChooseColour m_brush;
913   ChooseColour m_selectedbrush;
914   ChooseColour m_selectedbrush3d;
915   ChooseColour m_clipper;
916   ChooseColour m_viewname;
917
918   ColoursMenu() :
919     m_textureback(TextureBrowserColourGetCaller(), TextureBrowserColourSetCaller()),
920     m_xyback(ColourGetCaller(g_xywindow_globals.color_gridback), ColourSetCaller(g_xywindow_globals.color_gridback)),
921     m_gridmajor(ColourGetCaller(g_xywindow_globals.color_gridmajor), ColourSetCaller(g_xywindow_globals.color_gridmajor)),
922     m_gridminor(ColourGetCaller(g_xywindow_globals.color_gridminor), ColourSetCaller(g_xywindow_globals.color_gridminor)),
923     m_gridmajor_alt(ColourGetCaller(g_xywindow_globals.color_gridmajor_alt), ColourSetCaller(g_xywindow_globals.color_gridmajor_alt)),
924     m_gridminor_alt(ColourGetCaller(g_xywindow_globals.color_gridminor_alt), ColourSetCaller(g_xywindow_globals.color_gridminor_alt)),
925     m_gridtext(ColourGetCaller(g_xywindow_globals.color_gridtext), ColourSetCaller(g_xywindow_globals.color_gridtext)),
926     m_gridblock(ColourGetCaller(g_xywindow_globals.color_gridblock), ColourSetCaller(g_xywindow_globals.color_gridblock)),
927     m_cameraback(ColourGetCaller(g_camwindow_globals.color_cameraback), ColourSetCaller(g_camwindow_globals.color_cameraback)),
928     m_brush(ColourGetCaller(g_xywindow_globals.color_brushes), BrushColourSetCaller()),
929     m_selectedbrush(ColourGetCaller(g_xywindow_globals.color_selbrushes), ColourSetCaller(g_xywindow_globals.color_selbrushes)),
930     m_selectedbrush3d(ColourGetCaller(g_camwindow_globals.color_selbrushes3d), ColourSetCaller(g_camwindow_globals.color_selbrushes3d)),
931     m_clipper(ColourGetCaller(g_xywindow_globals.color_clipper), ClipperColourSetCaller()),
932     m_viewname(ColourGetCaller(g_xywindow_globals.color_viewname), ColourSetCaller(g_xywindow_globals.color_viewname))
933   {
934   }
935 };
936
937 ColoursMenu g_ColoursMenu;
938
939 GtkMenuItem* create_colours_menu()
940 {
941   GtkMenuItem* colours_menu_item = new_sub_menu_item_with_mnemonic("Colors");
942   GtkMenu* menu_in_menu = GTK_MENU(gtk_menu_item_get_submenu(colours_menu_item));
943   if (g_Layout_enableDetachableMenus.m_value)
944     menu_tearoff (menu_in_menu);
945
946   GtkMenu* menu_3 = create_sub_menu_with_mnemonic(menu_in_menu, "Themes");
947   if (g_Layout_enableDetachableMenus.m_value)
948     menu_tearoff (menu_3);
949
950   create_menu_item_with_mnemonic(menu_3, "QE4 Original", "ColorSchemeOriginal");
951   create_menu_item_with_mnemonic(menu_3, "Q3Radiant Original", "ColorSchemeQER");
952   create_menu_item_with_mnemonic(menu_3, "Black and Green", "ColorSchemeBlackAndGreen");
953   create_menu_item_with_mnemonic(menu_3, "Maya/Max/Lightwave Emulation", "ColorSchemeYdnar");
954
955   menu_separator(menu_in_menu);
956
957   create_menu_item_with_mnemonic(menu_in_menu, "_Texture Background...", "ChooseTextureBackgroundColor");
958   create_menu_item_with_mnemonic(menu_in_menu, "Grid Background...", "ChooseGridBackgroundColor");
959   create_menu_item_with_mnemonic(menu_in_menu, "Grid Major...", "ChooseGridMajorColor");
960   create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor...", "ChooseGridMinorColor");
961   create_menu_item_with_mnemonic(menu_in_menu, "Grid Major Small...", "ChooseSmallGridMajorColor");
962   create_menu_item_with_mnemonic(menu_in_menu, "Grid Minor Small...", "ChooseSmallGridMinorColor");
963   create_menu_item_with_mnemonic(menu_in_menu, "Grid Text...", "ChooseGridTextColor");
964   create_menu_item_with_mnemonic(menu_in_menu, "Grid Block...", "ChooseGridBlockColor");
965   create_menu_item_with_mnemonic(menu_in_menu, "Default Brush...", "ChooseBrushColor");
966   create_menu_item_with_mnemonic(menu_in_menu, "Camera Background...", "ChooseCameraBackgroundColor");
967   create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush...", "ChooseSelectedBrushColor");
968   create_menu_item_with_mnemonic(menu_in_menu, "Selected Brush (Camera)...", "ChooseCameraSelectedBrushColor");
969   create_menu_item_with_mnemonic(menu_in_menu, "Clipper...", "ChooseClipperColor");
970   create_menu_item_with_mnemonic(menu_in_menu, "Active View name...", "ChooseOrthoViewNameColor");
971
972   return colours_menu_item;
973 }
974
975
976 void Restart()
977 {
978   PluginsMenu_clear();
979   PluginToolbar_clear();
980
981   Radiant_Shutdown();
982   Radiant_Initialise();
983
984   PluginsMenu_populate();
985
986   PluginToolbar_populate();
987 }
988
989
990 void thunk_OnSleep()
991 {
992   g_pParentWnd->OnSleep();
993 }
994
995 void OpenUpdateURL()
996 {
997   // build the URL
998   StringOutputStream URL(256);
999   URL << "http://www.icculus.org/netradiant/?cmd=update&data=dlupdate&query_dlup=1";
1000 #ifdef WIN32
1001   URL << "&OS_dlup=1";
1002 #elif defined(__APPLE__)
1003   URL << "&OS_dlup=2";
1004 #else
1005   URL << "&OS_dlup=3";
1006 #endif
1007   URL << "&Version_dlup=" RADIANT_VERSION;
1008   g_GamesDialog.AddPacksURL(URL);
1009   OpenURL(URL.c_str());
1010 }
1011
1012 // open the Q3Rad manual
1013 void OpenHelpURL()
1014 {
1015   // at least on win32, AppPath + "docs/index.html"
1016   StringOutputStream help(256);
1017   help << AppPath_get() << "docs/index.html";
1018   OpenURL(help.c_str());
1019 }
1020
1021 void OpenBugReportURL()
1022 {
1023   OpenURL("http://www.icculus.org/netradiant/?cmd=bugs");
1024 }
1025
1026
1027 GtkWidget* g_page_console;
1028
1029 void Console_ToggleShow()
1030 {
1031   GroupDialog_showPage(g_page_console);
1032 }
1033
1034 GtkWidget* g_page_entity;
1035
1036 void EntityInspector_ToggleShow()
1037 {
1038   GroupDialog_showPage(g_page_entity);
1039 }
1040
1041
1042
1043 void SetClipMode(bool enable);
1044 void ModeChangeNotify();
1045
1046 typedef void(*ToolMode)();
1047 ToolMode g_currentToolMode = 0;
1048 bool g_currentToolModeSupportsComponentEditing = false;
1049 ToolMode g_defaultToolMode = 0;
1050
1051
1052
1053 void SelectionSystem_DefaultMode()
1054 {
1055   GlobalSelectionSystem().SetMode(SelectionSystem::ePrimitive);
1056   GlobalSelectionSystem().SetComponentMode(SelectionSystem::eDefault);
1057   ModeChangeNotify();
1058 }
1059
1060
1061 bool EdgeMode()
1062 {
1063   return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1064     && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eEdge;
1065 }
1066
1067 bool VertexMode()
1068 {
1069   return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1070     && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eVertex;
1071 }
1072
1073 bool FaceMode()
1074 {
1075   return GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1076     && GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace;
1077 }
1078
1079 template<bool (*BoolFunction)()>
1080 class BoolFunctionExport
1081 {
1082 public:
1083   static void apply(const BoolImportCallback& importCallback)
1084   {
1085     importCallback(BoolFunction());
1086   }
1087 };
1088
1089 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<EdgeMode>::apply> EdgeModeApplyCaller;
1090 EdgeModeApplyCaller g_edgeMode_button_caller;
1091 BoolExportCallback g_edgeMode_button_callback(g_edgeMode_button_caller);
1092 ToggleItem g_edgeMode_button(g_edgeMode_button_callback);
1093
1094 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<VertexMode>::apply> VertexModeApplyCaller;
1095 VertexModeApplyCaller g_vertexMode_button_caller;
1096 BoolExportCallback g_vertexMode_button_callback(g_vertexMode_button_caller);
1097 ToggleItem g_vertexMode_button(g_vertexMode_button_callback);
1098
1099 typedef FreeCaller1<const BoolImportCallback&, &BoolFunctionExport<FaceMode>::apply> FaceModeApplyCaller;
1100 FaceModeApplyCaller g_faceMode_button_caller;
1101 BoolExportCallback g_faceMode_button_callback(g_faceMode_button_caller);
1102 ToggleItem g_faceMode_button(g_faceMode_button_callback);
1103
1104 void ComponentModeChanged()
1105 {
1106   g_edgeMode_button.update();
1107   g_vertexMode_button.update();
1108   g_faceMode_button.update();
1109 }
1110
1111 void ComponentMode_SelectionChanged(const Selectable& selectable)
1112 {
1113   if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent
1114     && GlobalSelectionSystem().countSelected() == 0)
1115   {
1116     SelectionSystem_DefaultMode();
1117     ComponentModeChanged();
1118   }
1119 }
1120
1121 void SelectEdgeMode()
1122 {
1123 #if 0
1124   if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1125   {
1126     GlobalSelectionSystem().Select(false);
1127   }
1128 #endif
1129
1130   if(EdgeMode())
1131   {
1132     SelectionSystem_DefaultMode();
1133   }
1134   else if(GlobalSelectionSystem().countSelected() != 0)
1135   {
1136     if(!g_currentToolModeSupportsComponentEditing)
1137     {
1138       g_defaultToolMode();
1139     }
1140
1141     GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1142     GlobalSelectionSystem().SetComponentMode(SelectionSystem::eEdge);
1143   }
1144
1145   ComponentModeChanged();
1146
1147   ModeChangeNotify();
1148 }
1149
1150 void SelectVertexMode()
1151 {
1152 #if 0
1153   if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1154   {
1155     GlobalSelectionSystem().Select(false);
1156   }
1157 #endif
1158
1159   if(VertexMode())
1160   {
1161     SelectionSystem_DefaultMode();
1162   }
1163   else if(GlobalSelectionSystem().countSelected() != 0)
1164   {
1165     if(!g_currentToolModeSupportsComponentEditing)
1166     {
1167       g_defaultToolMode();
1168     }
1169
1170     GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1171     GlobalSelectionSystem().SetComponentMode(SelectionSystem::eVertex);
1172   }
1173
1174   ComponentModeChanged();
1175
1176   ModeChangeNotify();
1177 }
1178
1179 void SelectFaceMode()
1180 {
1181 #if 0
1182   if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1183   {
1184     GlobalSelectionSystem().Select(false);
1185   }
1186 #endif
1187
1188   if(FaceMode())
1189   {
1190     SelectionSystem_DefaultMode();
1191   }
1192   else if(GlobalSelectionSystem().countSelected() != 0)
1193   {
1194     if(!g_currentToolModeSupportsComponentEditing)
1195     {
1196       g_defaultToolMode();
1197     }
1198
1199     GlobalSelectionSystem().SetMode(SelectionSystem::eComponent);
1200     GlobalSelectionSystem().SetComponentMode(SelectionSystem::eFace);
1201   }
1202
1203   ComponentModeChanged();
1204
1205   ModeChangeNotify();
1206 }
1207
1208
1209 class CloneSelected : public scene::Graph::Walker
1210 {
1211   bool doMakeUnique;
1212   NodeSmartReference worldspawn;
1213 public:
1214   CloneSelected(bool d): doMakeUnique(d), worldspawn(Map_FindOrInsertWorldspawn(g_map))
1215   {
1216   }
1217   bool pre(const scene::Path& path, scene::Instance& instance) const
1218   {
1219     if(path.size() == 1)
1220       return true;
1221
1222     // ignore worldspawn, but keep checking children
1223     NodeSmartReference me(path.top().get());
1224     if(me == worldspawn)
1225            return true;
1226
1227     if(!path.top().get().isRoot())
1228     {
1229       Selectable* selectable = Instance_getSelectable(instance);
1230       if(selectable != 0
1231         && selectable->isSelected())
1232       {
1233         return false;
1234       }
1235     }
1236
1237     return true;
1238   }
1239   void post(const scene::Path& path, scene::Instance& instance) const
1240   {
1241     if(path.size() == 1)
1242       return;
1243
1244     // ignore worldspawn, but keep checking children
1245     NodeSmartReference me(path.top().get());
1246     if(me == worldspawn)
1247            return;
1248
1249     if(!path.top().get().isRoot())
1250     {
1251       Selectable* selectable = Instance_getSelectable(instance);
1252       if(selectable != 0
1253         && selectable->isSelected())
1254       {
1255         NodeSmartReference clone(Node_Clone(path.top()));
1256                 if(doMakeUnique)
1257                         Map_gatherNamespaced(clone);
1258         Node_getTraversable(path.parent().get())->insert(clone);
1259       }
1260     }
1261   }
1262 };
1263
1264 void Scene_Clone_Selected(scene::Graph& graph, bool doMakeUnique)
1265 {
1266   graph.traverse(CloneSelected(doMakeUnique));
1267
1268   Map_mergeClonedNames();
1269 }
1270
1271 enum ENudgeDirection
1272 {
1273   eNudgeUp = 1,
1274   eNudgeDown = 3,
1275   eNudgeLeft = 0,
1276   eNudgeRight = 2,
1277 };
1278
1279 struct AxisBase
1280 {
1281   Vector3 x;
1282   Vector3 y;
1283   Vector3 z;
1284   AxisBase(const Vector3& x_, const Vector3& y_, const Vector3& z_)
1285     : x(x_), y(y_), z(z_)
1286   {
1287   }
1288 };
1289
1290 AxisBase AxisBase_forViewType(VIEWTYPE viewtype)
1291 {
1292   switch(viewtype)
1293   {
1294   case XY:
1295     return AxisBase(g_vector3_axis_x, g_vector3_axis_y, g_vector3_axis_z);
1296   case XZ:
1297     return AxisBase(g_vector3_axis_x, g_vector3_axis_z, g_vector3_axis_y);
1298   case YZ:
1299     return AxisBase(g_vector3_axis_y, g_vector3_axis_z, g_vector3_axis_x);
1300   }
1301
1302   ERROR_MESSAGE("invalid viewtype");
1303   return AxisBase(Vector3(0, 0, 0), Vector3(0, 0, 0), Vector3(0, 0, 0));
1304 }
1305
1306 Vector3 AxisBase_axisForDirection(const AxisBase& axes, ENudgeDirection direction)
1307 {
1308   switch (direction)
1309   {
1310   case eNudgeLeft:
1311     return vector3_negated(axes.x);
1312   case eNudgeUp:
1313     return axes.y;
1314   case eNudgeRight:
1315     return axes.x;
1316   case eNudgeDown:
1317     return vector3_negated(axes.y);
1318   }
1319
1320   ERROR_MESSAGE("invalid direction");
1321   return Vector3(0, 0, 0);
1322 }
1323
1324 void NudgeSelection(ENudgeDirection direction, float fAmount, VIEWTYPE viewtype)
1325 {
1326   AxisBase axes(AxisBase_forViewType(viewtype));
1327   Vector3 view_direction(vector3_negated(axes.z));
1328   Vector3 nudge(vector3_scaled(AxisBase_axisForDirection(axes, direction), fAmount));
1329   GlobalSelectionSystem().NudgeManipulator(nudge, view_direction);
1330 }
1331
1332 void Selection_Clone()
1333 {
1334   if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1335   {
1336     UndoableCommand undo("cloneSelected");
1337
1338     Scene_Clone_Selected(GlobalSceneGraph(), false);
1339
1340     //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1341     //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1342   }
1343 }
1344
1345 void Selection_Clone_MakeUnique()
1346 {
1347   if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
1348   {
1349     UndoableCommand undo("cloneSelectedMakeUnique");
1350
1351     Scene_Clone_Selected(GlobalSceneGraph(), true);
1352
1353     //NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1354     //NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1355   }
1356 }
1357
1358 // called when the escape key is used (either on the main window or on an inspector)
1359 void Selection_Deselect()
1360 {
1361   if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1362   {
1363     if(GlobalSelectionSystem().countSelectedComponents() != 0)
1364     {
1365       GlobalSelectionSystem().setSelectedAllComponents(false);
1366     }
1367     else
1368     {
1369       SelectionSystem_DefaultMode();
1370       ComponentModeChanged();
1371     }
1372   }
1373   else
1374   {
1375     if(GlobalSelectionSystem().countSelectedComponents() != 0)
1376     {
1377       GlobalSelectionSystem().setSelectedAllComponents(false);
1378     }
1379     else
1380     {
1381       GlobalSelectionSystem().setSelectedAll(false);
1382     }
1383   }
1384 }
1385
1386
1387 void Selection_NudgeUp()
1388 {
1389   UndoableCommand undo("nudgeSelectedUp");
1390   NudgeSelection(eNudgeUp, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1391 }
1392
1393 void Selection_NudgeDown()
1394 {
1395   UndoableCommand undo("nudgeSelectedDown");
1396   NudgeSelection(eNudgeDown, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1397 }
1398
1399 void Selection_NudgeLeft()
1400 {
1401   UndoableCommand undo("nudgeSelectedLeft");
1402   NudgeSelection(eNudgeLeft, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1403 }
1404
1405 void Selection_NudgeRight()
1406 {
1407   UndoableCommand undo("nudgeSelectedRight");
1408   NudgeSelection(eNudgeRight, GetGridSize(), GlobalXYWnd_getCurrentViewType());
1409 }
1410
1411
1412 void TranslateToolExport(const BoolImportCallback& importCallback)
1413 {
1414   importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eTranslate);
1415 }
1416
1417 void RotateToolExport(const BoolImportCallback& importCallback)
1418 {
1419   importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eRotate);
1420 }
1421
1422 void ScaleToolExport(const BoolImportCallback& importCallback)
1423 {
1424   importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eScale);
1425 }
1426
1427 void DragToolExport(const BoolImportCallback& importCallback)
1428 {
1429   importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eDrag);
1430 }
1431
1432 void ClipperToolExport(const BoolImportCallback& importCallback)
1433 {
1434   importCallback(GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip);
1435 }
1436
1437 FreeCaller1<const BoolImportCallback&, TranslateToolExport> g_translatemode_button_caller;
1438 BoolExportCallback g_translatemode_button_callback(g_translatemode_button_caller);
1439 ToggleItem g_translatemode_button(g_translatemode_button_callback);
1440
1441 FreeCaller1<const BoolImportCallback&, RotateToolExport> g_rotatemode_button_caller;
1442 BoolExportCallback g_rotatemode_button_callback(g_rotatemode_button_caller);
1443 ToggleItem g_rotatemode_button(g_rotatemode_button_callback);
1444
1445 FreeCaller1<const BoolImportCallback&, ScaleToolExport> g_scalemode_button_caller;
1446 BoolExportCallback g_scalemode_button_callback(g_scalemode_button_caller);
1447 ToggleItem g_scalemode_button(g_scalemode_button_callback);
1448
1449 FreeCaller1<const BoolImportCallback&, DragToolExport> g_dragmode_button_caller;
1450 BoolExportCallback g_dragmode_button_callback(g_dragmode_button_caller);
1451 ToggleItem g_dragmode_button(g_dragmode_button_callback);
1452
1453 FreeCaller1<const BoolImportCallback&, ClipperToolExport> g_clipper_button_caller;
1454 BoolExportCallback g_clipper_button_callback(g_clipper_button_caller);
1455 ToggleItem g_clipper_button(g_clipper_button_callback);
1456
1457 void ToolChanged()
1458 {
1459   g_translatemode_button.update();
1460   g_rotatemode_button.update();
1461   g_scalemode_button.update();
1462   g_dragmode_button.update();
1463   g_clipper_button.update();
1464 }
1465
1466 const char* const c_ResizeMode_status = "QE4 Drag Tool: move and resize objects";
1467
1468 void DragMode()
1469 {
1470   if(g_currentToolMode == DragMode && g_defaultToolMode != DragMode)
1471   {
1472     g_defaultToolMode();
1473   }
1474   else
1475   {
1476     g_currentToolMode = DragMode;
1477     g_currentToolModeSupportsComponentEditing = true;
1478
1479     OnClipMode(false);
1480
1481     Sys_Status(c_ResizeMode_status);
1482     GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eDrag);
1483     ToolChanged();
1484     ModeChangeNotify();
1485   }
1486 }
1487
1488
1489 const char* const c_TranslateMode_status = "Translate Tool: translate objects and components";
1490
1491 void TranslateMode()
1492 {
1493   if(g_currentToolMode == TranslateMode && g_defaultToolMode != TranslateMode)
1494   {
1495     g_defaultToolMode();
1496   }
1497   else
1498   {
1499     g_currentToolMode = TranslateMode;
1500     g_currentToolModeSupportsComponentEditing = true;
1501
1502     OnClipMode(false);
1503
1504     Sys_Status(c_TranslateMode_status);
1505     GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eTranslate);
1506     ToolChanged();
1507     ModeChangeNotify();
1508   }
1509 }
1510
1511 const char* const c_RotateMode_status = "Rotate Tool: rotate objects and components";
1512
1513 void RotateMode()
1514 {
1515   if(g_currentToolMode == RotateMode && g_defaultToolMode != RotateMode)
1516   {
1517     g_defaultToolMode();
1518   }
1519   else
1520   {
1521     g_currentToolMode = RotateMode;
1522     g_currentToolModeSupportsComponentEditing = true;
1523
1524     OnClipMode(false);
1525
1526     Sys_Status(c_RotateMode_status);
1527     GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eRotate);
1528     ToolChanged();
1529     ModeChangeNotify();
1530   }
1531 }
1532
1533 const char* const c_ScaleMode_status = "Scale Tool: scale objects and components";
1534
1535 void ScaleMode()
1536 {
1537   if(g_currentToolMode == ScaleMode && g_defaultToolMode != ScaleMode)
1538   {
1539     g_defaultToolMode();
1540   }
1541   else
1542   {
1543     g_currentToolMode = ScaleMode;
1544     g_currentToolModeSupportsComponentEditing = true;
1545
1546     OnClipMode(false);
1547
1548     Sys_Status(c_ScaleMode_status);
1549     GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eScale);
1550     ToolChanged();
1551     ModeChangeNotify();
1552   }
1553 }
1554
1555
1556 const char* const c_ClipperMode_status = "Clipper Tool: apply clip planes to objects";
1557
1558
1559 void ClipperMode()
1560 {
1561   if(g_currentToolMode == ClipperMode && g_defaultToolMode != ClipperMode)
1562   {
1563     g_defaultToolMode();
1564   }
1565   else
1566   {
1567     g_currentToolMode = ClipperMode;
1568     g_currentToolModeSupportsComponentEditing = false;
1569
1570     SelectionSystem_DefaultMode();
1571
1572     OnClipMode(true);
1573
1574     Sys_Status(c_ClipperMode_status);
1575     GlobalSelectionSystem().SetManipulatorMode(SelectionSystem::eClip);
1576     ToolChanged();
1577     ModeChangeNotify();
1578   }
1579 }
1580
1581
1582 void Texdef_Rotate(float angle)
1583 {
1584   StringOutputStream command;
1585   command << "brushRotateTexture -angle " << angle;
1586   UndoableCommand undo(command.c_str());
1587   Select_RotateTexture(angle);
1588 }
1589
1590 void Texdef_RotateClockwise()
1591 {
1592   Texdef_Rotate(static_cast<float>(fabs(g_si_globals.rotate)));
1593 }
1594
1595 void Texdef_RotateAntiClockwise()
1596 {
1597   Texdef_Rotate(static_cast<float>(-fabs(g_si_globals.rotate)));
1598 }
1599
1600 void Texdef_Scale(float x, float y)
1601 {
1602   StringOutputStream command;
1603   command << "brushScaleTexture -x " << x << " -y " << y;
1604   UndoableCommand undo(command.c_str());
1605   Select_ScaleTexture(x, y);
1606 }
1607
1608 void Texdef_ScaleUp()
1609 {
1610   Texdef_Scale(0, g_si_globals.scale[1]);
1611 }
1612
1613 void Texdef_ScaleDown()
1614 {
1615   Texdef_Scale(0, -g_si_globals.scale[1]);
1616 }
1617
1618 void Texdef_ScaleLeft()
1619 {
1620   Texdef_Scale(-g_si_globals.scale[0],0);
1621 }
1622
1623 void Texdef_ScaleRight()
1624 {
1625   Texdef_Scale(g_si_globals.scale[0],0);
1626 }
1627
1628 void Texdef_Shift(float x, float y)
1629 {
1630   StringOutputStream command;
1631   command << "brushShiftTexture -x " << x << " -y " << y;
1632   UndoableCommand undo(command.c_str());
1633   Select_ShiftTexture(x, y);
1634 }
1635
1636 void Texdef_ShiftLeft()
1637 {
1638   Texdef_Shift(-g_si_globals.shift[0], 0);
1639 }
1640
1641 void Texdef_ShiftRight()
1642 {
1643   Texdef_Shift(g_si_globals.shift[0], 0);
1644 }
1645
1646 void Texdef_ShiftUp()
1647 {
1648   Texdef_Shift(0, g_si_globals.shift[1]);
1649 }
1650
1651 void Texdef_ShiftDown()
1652 {
1653   Texdef_Shift(0, -g_si_globals.shift[1]);
1654 }
1655
1656
1657
1658 class SnappableSnapToGridSelected : public scene::Graph::Walker
1659 {
1660   float m_snap;
1661 public:
1662   SnappableSnapToGridSelected(float snap)
1663     : m_snap(snap)
1664   {
1665   }
1666   bool pre(const scene::Path& path, scene::Instance& instance) const
1667   {
1668     if(path.top().get().visible())
1669     {
1670       Snappable* snappable = Node_getSnappable(path.top());
1671       if(snappable != 0
1672         && Instance_getSelectable(instance)->isSelected())
1673       {
1674         snappable->snapto(m_snap);
1675       }
1676     }
1677     return true;
1678   }
1679 };
1680
1681 void Scene_SnapToGrid_Selected(scene::Graph& graph, float snap)
1682 {
1683   graph.traverse(SnappableSnapToGridSelected(snap));
1684 }
1685
1686 class ComponentSnappableSnapToGridSelected : public scene::Graph::Walker
1687 {
1688   float m_snap;
1689 public:
1690   ComponentSnappableSnapToGridSelected(float snap)
1691     : m_snap(snap)
1692   {
1693   }
1694   bool pre(const scene::Path& path, scene::Instance& instance) const
1695   {
1696     if(path.top().get().visible())
1697     {
1698       ComponentSnappable* componentSnappable = Instance_getComponentSnappable(instance);
1699       if(componentSnappable != 0
1700         && Instance_getSelectable(instance)->isSelected())
1701       {
1702         componentSnappable->snapComponents(m_snap);
1703       }
1704     }
1705     return true;
1706   }
1707 };
1708
1709 void Scene_SnapToGrid_Component_Selected(scene::Graph& graph, float snap)
1710 {
1711   graph.traverse(ComponentSnappableSnapToGridSelected(snap));
1712 }
1713
1714 void Selection_SnapToGrid()
1715 {
1716   StringOutputStream command;
1717   command << "snapSelected -grid " << GetGridSize();
1718   UndoableCommand undo(command.c_str());
1719
1720   if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
1721   {
1722     Scene_SnapToGrid_Component_Selected(GlobalSceneGraph(), GetGridSize());
1723   }
1724   else
1725   {
1726     Scene_SnapToGrid_Selected(GlobalSceneGraph(), GetGridSize());
1727   }
1728 }
1729
1730
1731 static gint qe_every_second(gpointer data)
1732 {
1733   GdkModifierType mask;
1734
1735   gdk_window_get_pointer (0, 0, 0, &mask);
1736
1737   if ((mask & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK|GDK_BUTTON3_MASK)) == 0)
1738   {
1739     QE_CheckAutoSave();
1740   }
1741
1742   return TRUE;
1743 }
1744
1745 guint s_qe_every_second_id = 0;
1746
1747 void EverySecondTimer_enable()
1748 {
1749   if(s_qe_every_second_id == 0)
1750   {
1751     s_qe_every_second_id = gtk_timeout_add(1000, qe_every_second, 0);
1752   }
1753 }
1754
1755 void EverySecondTimer_disable()
1756 {
1757   if(s_qe_every_second_id != 0)
1758   {
1759     gtk_timeout_remove(s_qe_every_second_id);
1760     s_qe_every_second_id = 0;
1761   }
1762 }
1763
1764 gint window_realize_remove_decoration(GtkWidget* widget, gpointer data)
1765 {
1766   gdk_window_set_decorations(widget->window, (GdkWMDecoration)(GDK_DECOR_ALL|GDK_DECOR_MENU|GDK_DECOR_MINIMIZE|GDK_DECOR_MAXIMIZE));
1767   return FALSE;
1768 }
1769
1770 class WaitDialog
1771 {
1772 public:
1773   GtkWindow* m_window;
1774   GtkLabel* m_label;
1775 };
1776
1777 WaitDialog create_wait_dialog(const char* title, const char* text)
1778 {
1779   WaitDialog dialog;
1780
1781   dialog.m_window = create_floating_window(title, MainFrame_getWindow());
1782   gtk_window_set_resizable(dialog.m_window, FALSE);
1783   gtk_container_set_border_width(GTK_CONTAINER(dialog.m_window), 0);
1784   gtk_window_set_position(dialog.m_window, GTK_WIN_POS_CENTER_ON_PARENT);
1785
1786   g_signal_connect(G_OBJECT(dialog.m_window), "realize", G_CALLBACK(window_realize_remove_decoration), 0);
1787
1788   {
1789     dialog.m_label = GTK_LABEL(gtk_label_new(text));
1790     gtk_misc_set_alignment(GTK_MISC(dialog.m_label), 0.0, 0.5);
1791     gtk_label_set_justify(dialog.m_label, GTK_JUSTIFY_LEFT);
1792     gtk_widget_show(GTK_WIDGET(dialog.m_label));
1793     gtk_widget_set_size_request(GTK_WIDGET(dialog.m_label), 200, -1);
1794
1795     gtk_container_add(GTK_CONTAINER(dialog.m_window), GTK_WIDGET(dialog.m_label));
1796   }
1797   return dialog;
1798 }
1799
1800 namespace
1801 {
1802   clock_t g_lastRedrawTime = 0;
1803   const clock_t c_redrawInterval = clock_t(CLOCKS_PER_SEC / 10);
1804
1805   bool redrawRequired()
1806   {
1807     clock_t currentTime = std::clock();
1808     if(currentTime - g_lastRedrawTime >= c_redrawInterval)
1809     {
1810       g_lastRedrawTime = currentTime;
1811       return true;
1812     }
1813     return false;
1814   }
1815 }
1816
1817 bool MainFrame_isActiveApp()
1818 {
1819   //globalOutputStream() << "listing\n";
1820   GList* list = gtk_window_list_toplevels();
1821   for(GList* i = list; i != 0; i = g_list_next(i))
1822   {
1823     //globalOutputStream() << "toplevel.. ";
1824     if(gtk_window_is_active(GTK_WINDOW(i->data)))
1825     {
1826       //globalOutputStream() << "is active\n";
1827       return true;
1828     }
1829     //globalOutputStream() << "not active\n";
1830   }
1831   return false;
1832 }
1833
1834 typedef std::list<CopiedString> StringStack;
1835 StringStack g_wait_stack;
1836 WaitDialog g_wait;
1837
1838 bool ScreenUpdates_Enabled()
1839 {
1840   return g_wait_stack.empty();
1841 }
1842
1843 void ScreenUpdates_process()
1844 {
1845   if(redrawRequired() && GTK_WIDGET_VISIBLE(g_wait.m_window))
1846   {
1847     process_gui();
1848   }
1849 }
1850
1851
1852 void ScreenUpdates_Disable(const char* message, const char* title)
1853 {
1854   if(g_wait_stack.empty())
1855   {
1856     EverySecondTimer_disable();
1857
1858     process_gui();
1859
1860     bool isActiveApp = MainFrame_isActiveApp();
1861
1862     g_wait = create_wait_dialog(title, message);
1863     gtk_grab_add(GTK_WIDGET(g_wait.m_window));
1864
1865     if(isActiveApp)
1866     {
1867       gtk_widget_show(GTK_WIDGET(g_wait.m_window));
1868       ScreenUpdates_process();
1869     }
1870   }
1871   else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1872   {
1873     gtk_label_set_text(g_wait.m_label, message);
1874     ScreenUpdates_process();
1875   }
1876   g_wait_stack.push_back(message);
1877 }
1878
1879 void ScreenUpdates_Enable()
1880 {
1881   ASSERT_MESSAGE(!ScreenUpdates_Enabled(), "screen updates already enabled");
1882   g_wait_stack.pop_back();
1883   if(g_wait_stack.empty())
1884   {
1885     EverySecondTimer_enable();
1886     //gtk_widget_set_sensitive(GTK_WIDGET(MainFrame_getWindow()), TRUE);
1887
1888     gtk_grab_remove(GTK_WIDGET(g_wait.m_window));
1889     destroy_floating_window(g_wait.m_window);
1890     g_wait.m_window = 0;
1891
1892     //gtk_window_present(MainFrame_getWindow());
1893   }
1894   else if(GTK_WIDGET_VISIBLE(g_wait.m_window))
1895   {
1896     gtk_label_set_text(g_wait.m_label, g_wait_stack.back().c_str());
1897     ScreenUpdates_process();
1898   }
1899 }
1900
1901
1902
1903 void GlobalCamera_UpdateWindow()
1904 {
1905   if(g_pParentWnd != 0)
1906   {
1907     CamWnd_Update(*g_pParentWnd->GetCamWnd());
1908   }
1909 }
1910
1911 void XY_UpdateWindow(MainFrame& mainframe)
1912 {
1913   if(mainframe.GetXYWnd() != 0)
1914   {
1915     XYWnd_Update(*mainframe.GetXYWnd());
1916   }
1917 }
1918
1919 void XZ_UpdateWindow(MainFrame& mainframe)
1920 {
1921   if(mainframe.GetXZWnd() != 0)
1922   {
1923     XYWnd_Update(*mainframe.GetXZWnd());
1924   }
1925 }
1926
1927 void YZ_UpdateWindow(MainFrame& mainframe)
1928 {
1929   if(mainframe.GetYZWnd() != 0)
1930   {
1931     XYWnd_Update(*mainframe.GetYZWnd());
1932   }
1933 }
1934
1935 void XY_UpdateAllWindows(MainFrame& mainframe)
1936 {
1937   XY_UpdateWindow(mainframe);
1938   XZ_UpdateWindow(mainframe);
1939   YZ_UpdateWindow(mainframe);
1940 }
1941
1942 void XY_UpdateAllWindows()
1943 {
1944   if(g_pParentWnd != 0)
1945   {
1946     XY_UpdateAllWindows(*g_pParentWnd);
1947   }
1948 }
1949
1950 void UpdateAllWindows()
1951 {
1952   GlobalCamera_UpdateWindow();
1953   XY_UpdateAllWindows();
1954 }
1955
1956
1957 void ModeChangeNotify()
1958 {
1959   SceneChangeNotify();
1960 }
1961
1962 void ClipperChangeNotify()
1963 {
1964   GlobalCamera_UpdateWindow();
1965   XY_UpdateAllWindows();
1966 }
1967
1968
1969 LatchedInt g_Layout_viewStyle(0, "Window Layout");
1970 LatchedBool g_Layout_enableDetachableMenus(true, "Detachable Menus");
1971 LatchedBool g_Layout_enablePatchToolbar(true, "Patch Toolbar");
1972 LatchedBool g_Layout_enablePluginToolbar(true, "Plugin Toolbar");
1973
1974
1975
1976 GtkMenuItem* create_file_menu()
1977 {
1978   // File menu
1979   GtkMenuItem* file_menu_item = new_sub_menu_item_with_mnemonic("_File");
1980   GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(file_menu_item));
1981   if (g_Layout_enableDetachableMenus.m_value)
1982     menu_tearoff (menu);
1983
1984   create_menu_item_with_mnemonic(menu, "_New Map", "NewMap");
1985   menu_separator(menu);
1986
1987 #if 0
1988   //++timo temporary experimental stuff for sleep mode..
1989   create_menu_item_with_mnemonic(menu, "_Sleep", "Sleep");
1990   menu_separator(menu);
1991   // end experimental
1992 #endif
1993
1994   create_menu_item_with_mnemonic(menu, "_Open...", "OpenMap");
1995
1996   create_menu_item_with_mnemonic(menu, "_Import...", "ImportMap");
1997   create_menu_item_with_mnemonic(menu, "_Save", "SaveMap");
1998   create_menu_item_with_mnemonic(menu, "Save _as...", "SaveMapAs");
1999   create_menu_item_with_mnemonic(menu, "Save s_elected...", "SaveSelected");
2000   menu_separator(menu);
2001   create_menu_item_with_mnemonic(menu, "Save re_gion...", "SaveRegion");
2002   menu_separator(menu);
2003   create_menu_item_with_mnemonic(menu, "_Refresh models", "RefreshReferences");
2004   menu_separator(menu);
2005   create_menu_item_with_mnemonic(menu, "Pro_ject settings...", "ProjectSettings");
2006   menu_separator(menu);
2007   create_menu_item_with_mnemonic(menu, "_Pointfile...", "TogglePointfile");
2008   menu_separator(menu);
2009   MRU_constructMenu(menu);
2010   menu_separator(menu);
2011   create_menu_item_with_mnemonic(menu, "Check for NetRadiant update (web)", "CheckForUpdate"); // FIXME
2012   create_menu_item_with_mnemonic(menu, "E_xit", "Exit");
2013
2014   return file_menu_item;
2015 }
2016
2017 GtkMenuItem* create_edit_menu()
2018 {
2019   // Edit menu
2020   GtkMenuItem* edit_menu_item = new_sub_menu_item_with_mnemonic("_Edit");
2021   GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(edit_menu_item));
2022   if (g_Layout_enableDetachableMenus.m_value)
2023     menu_tearoff (menu);
2024   create_menu_item_with_mnemonic(menu, "_Undo", "Undo");
2025   create_menu_item_with_mnemonic(menu, "_Redo", "Redo");
2026   menu_separator(menu);
2027   create_menu_item_with_mnemonic(menu, "_Copy", "Copy");
2028   create_menu_item_with_mnemonic(menu, "_Paste", "Paste");
2029   create_menu_item_with_mnemonic(menu, "P_aste To Camera", "PasteToCamera");
2030   menu_separator(menu);
2031   create_menu_item_with_mnemonic(menu, "_Duplicate", "CloneSelection");
2032   create_menu_item_with_mnemonic(menu, "Duplicate, make uni_que", "CloneSelectionAndMakeUnique");
2033   create_menu_item_with_mnemonic(menu, "D_elete", "DeleteSelection");
2034   menu_separator(menu);
2035   create_menu_item_with_mnemonic(menu, "Pa_rent", "ParentSelection");
2036   menu_separator(menu);
2037   create_menu_item_with_mnemonic(menu, "C_lear Selection", "UnSelectSelection");
2038   create_menu_item_with_mnemonic(menu, "_Invert Selection", "InvertSelection");
2039   create_menu_item_with_mnemonic(menu, "Select i_nside", "SelectInside");
2040   create_menu_item_with_mnemonic(menu, "Select _touching", "SelectTouching");
2041
2042   GtkMenu* convert_menu = create_sub_menu_with_mnemonic(menu, "E_xpand Selection");
2043   if (g_Layout_enableDetachableMenus.m_value)
2044     menu_tearoff (convert_menu);
2045   create_menu_item_with_mnemonic(convert_menu, "To Whole _Entities", "ExpandSelectionToEntities");
2046
2047   menu_separator(menu);
2048   create_menu_item_with_mnemonic(menu, "Pre_ferences...", "Preferences");
2049
2050   return edit_menu_item;
2051 }
2052
2053 void fill_view_xy_top_menu(GtkMenu* menu)
2054 {
2055   create_check_menu_item_with_mnemonic(menu, "XY (Top) View", "ToggleView");
2056 }
2057
2058
2059 void fill_view_yz_side_menu(GtkMenu* menu)
2060 {
2061   create_check_menu_item_with_mnemonic(menu, "YZ (Side) View", "ToggleSideView");
2062 }
2063
2064
2065 void fill_view_xz_front_menu(GtkMenu* menu)
2066 {
2067   create_check_menu_item_with_mnemonic(menu, "XZ (Front) View", "ToggleFrontView");
2068 }
2069
2070
2071 GtkWidget* g_toggle_z_item = 0;
2072 GtkWidget* g_toggle_console_item = 0;
2073 GtkWidget* g_toggle_entity_item = 0;
2074 GtkWidget* g_toggle_entitylist_item = 0;
2075
2076 GtkMenuItem* create_view_menu(MainFrame::EViewStyle style)
2077 {
2078   // View menu
2079   GtkMenuItem* view_menu_item = new_sub_menu_item_with_mnemonic("Vie_w");
2080   GtkMenu* menu = GTK_MENU(gtk_menu_item_get_submenu(view_menu_item));
2081   if (g_Layout_enableDetachableMenus.m_value)
2082     menu_tearoff (menu);
2083
2084   if(style == MainFrame::eFloating)
2085   {
2086     fill_view_camera_menu(menu);
2087     fill_view_xy_top_menu(menu);
2088     fill_view_yz_side_menu(menu);
2089     fill_view_xz_front_menu(menu);
2090   }
2091   if(style == MainFrame::eFloating || style == MainFrame::eSplit)
2092   {