1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "EntityInspector.h"
21 
22 #include "StringUtils.h"
23 #include "View/BorderLine.h"
24 #include "View/CollapsibleTitledPanel.h"
25 #include "View/EntityBrowser.h"
26 #include "View/EntityDefinitionFileChooser.h"
27 #include "View/EntityAttributeEditor.h"
28 #include "View/SplitterWindow2.h"
29 #include "View/TitledPanel.h"
30 #include "View/ViewConstants.h"
31 #include "View/MapDocument.h"
32 
33 #include <wx/event.h>
34 #include <wx/notebook.h>
35 #include <wx/persist.h>
36 #include <wx/sizer.h>
37 
38 namespace TrenchBroom {
39     namespace View {
EntityInspector(wxWindow * parent,MapDocumentWPtr document,GLContextManager & contextManager)40         EntityInspector::EntityInspector(wxWindow* parent, MapDocumentWPtr document, GLContextManager& contextManager) :
41         TabBookPage(parent) {
42 #if defined __APPLE__
43             SetWindowVariant(wxWINDOW_VARIANT_SMALL);
44 #endif
45             createGui(document, contextManager);
46         }
47 
createGui(MapDocumentWPtr document,GLContextManager & contextManager)48         void EntityInspector::createGui(MapDocumentWPtr document, GLContextManager& contextManager) {
49             SplitterWindow2* splitter = new SplitterWindow2(this);
50             splitter->setSashGravity(0.0);
51             splitter->SetName("EntityInspectorSplitter");
52 
53             splitter->splitHorizontally(createAttributeEditor(splitter, document),
54                                         createEntityBrowser(splitter, document, contextManager),
55                                         wxSize(100, 150), wxSize(100, 150));
56 
57             wxSizer* outerSizer = new wxBoxSizer(wxVERTICAL);
58             outerSizer->Add(splitter, 1, wxEXPAND);
59             outerSizer->Add(new BorderLine(this, BorderLine::Direction_Horizontal), 0, wxEXPAND);
60             outerSizer->Add(createEntityDefinitionFileChooser(this, document), 0, wxEXPAND);
61             SetSizer(outerSizer);
62 
63             wxPersistenceManager::Get().RegisterAndRestore(splitter);
64         }
65 
createAttributeEditor(wxWindow * parent,MapDocumentWPtr document)66         wxWindow* EntityInspector::createAttributeEditor(wxWindow* parent, MapDocumentWPtr document) {
67             m_attributeEditor = new EntityAttributeEditor(parent, document);
68             return m_attributeEditor;
69         }
70 
createEntityBrowser(wxWindow * parent,MapDocumentWPtr document,GLContextManager & contextManager)71         wxWindow* EntityInspector::createEntityBrowser(wxWindow* parent, MapDocumentWPtr document, GLContextManager& contextManager) {
72             TitledPanel* panel = new TitledPanel(parent, "Entity Browser");
73             m_entityBrowser = new EntityBrowser(panel->getPanel(), document, contextManager);
74 
75             wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
76             sizer->Add(m_entityBrowser, 1, wxEXPAND);
77             panel->getPanel()->SetSizer(sizer);
78 
79             return panel;
80         }
81 
createEntityDefinitionFileChooser(wxWindow * parent,MapDocumentWPtr document)82         wxWindow* EntityInspector::createEntityDefinitionFileChooser(wxWindow* parent, MapDocumentWPtr document) {
83             CollapsibleTitledPanel* panel = new CollapsibleTitledPanel(parent, "Entity Definitions", false);
84             m_entityDefinitionFileChooser = new EntityDefinitionFileChooser(panel->getPanel(), document);
85 
86             wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
87             sizer->Add(m_entityDefinitionFileChooser, 1, wxEXPAND);
88             panel->getPanel()->SetSizer(sizer);
89 
90             return panel;
91         }
92     }
93 }
94