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 "EntityAttributeEditor.h" 21 22 #include "View/BorderLine.h" 23 #include "View/EntityAttributeGrid.h" 24 #include "View/EntityAttributeSelectedCommand.h" 25 #include "View/ViewConstants.h" 26 #include "View/MapDocument.h" 27 #include "View/SmartAttributeEditorManager.h" 28 #include "View/SplitterWindow2.h" 29 30 #include <wx/persist.h> 31 #include <wx/sizer.h> 32 33 namespace TrenchBroom { 34 namespace View { EntityAttributeEditor(wxWindow * parent,MapDocumentWPtr document)35 EntityAttributeEditor::EntityAttributeEditor(wxWindow* parent, MapDocumentWPtr document) : 36 wxPanel(parent), 37 m_document(document) { 38 createGui(this, document); 39 } 40 OnEntityAttributeSelected(EntityAttributeSelectedCommand & command)41 void EntityAttributeEditor::OnEntityAttributeSelected(EntityAttributeSelectedCommand& command) { 42 if (IsBeingDeleted()) return; 43 44 MapDocumentSPtr document = lock(m_document); 45 46 const String& name = command.name(); 47 const Model::AttributableNodeList& attributables = document->allSelectedAttributableNodes(); 48 m_smartEditorManager->switchEditor(name, attributables); 49 } 50 createGui(wxWindow * parent,MapDocumentWPtr document)51 void EntityAttributeEditor::createGui(wxWindow* parent, MapDocumentWPtr document) { 52 SplitterWindow2* splitter = new SplitterWindow2(parent); 53 splitter->setSashGravity(1.0); 54 splitter->SetName("EntityAttributeEditorSplitter"); 55 56 m_attributeGrid = new EntityAttributeGrid(splitter, document); 57 m_smartEditorManager = new SmartAttributeEditorManager(splitter, document); 58 59 splitter->splitHorizontally(m_attributeGrid, 60 m_smartEditorManager, 61 wxSize(100, 50), wxSize(100, 50)); 62 63 64 wxSizer* sizer = new wxBoxSizer(wxVERTICAL); 65 sizer->Add(splitter, 1, wxEXPAND); 66 sizer->SetItemMinSize(m_smartEditorManager, 500, 100); 67 SetSizer(sizer); 68 69 wxPersistenceManager::Get().RegisterAndRestore(splitter); 70 m_attributeGrid->Bind(ENTITY_ATTRIBUTE_SELECTED_EVENT, &EntityAttributeEditor::OnEntityAttributeSelected, this); 71 } 72 } 73 } 74