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 "TextureCollectionCommand.h" 21 #include "View/MapDocumentCommandFacade.h" 22 23 #include <cassert> 24 25 namespace TrenchBroom { 26 namespace View { 27 const Command::CommandType TextureCollectionCommand::Type = Command::freeType(); 28 add(const String & collectionName)29 TextureCollectionCommand::Ptr TextureCollectionCommand::add(const String& collectionName) { 30 return Ptr(new TextureCollectionCommand("Add Texture Collection", Action_Add, StringList(1, collectionName))); 31 } 32 remove(const StringList & collectionNames)33 TextureCollectionCommand::Ptr TextureCollectionCommand::remove(const StringList& collectionNames) { 34 const String name = StringUtils::safePlural(collectionNames.size(), "Remove Texture Collection", "Remove Texture Collections"); 35 return Ptr(new TextureCollectionCommand(name, Action_Remove, collectionNames)); 36 } 37 moveUp(const String & collectionName)38 TextureCollectionCommand::Ptr TextureCollectionCommand::moveUp(const String& collectionName) { 39 return Ptr(new TextureCollectionCommand("Move Texture Collection Up", Action_MoveUp, StringList(1, collectionName))); 40 } 41 moveDown(const String & collectionName)42 TextureCollectionCommand::Ptr TextureCollectionCommand::moveDown(const String& collectionName) { 43 return Ptr(new TextureCollectionCommand("Move Texture Collection Down", Action_MoveDown, StringList(1, collectionName))); 44 } 45 TextureCollectionCommand(const String & name,const Action action,const StringList & collectionNames)46 TextureCollectionCommand::TextureCollectionCommand(const String& name, const Action action, const StringList& collectionNames) : 47 DocumentCommand(Type, name), 48 m_action(action), 49 m_collectionNames(collectionNames) { 50 switch (m_action) { 51 case Action_Add: 52 case Action_MoveUp: 53 case Action_MoveDown: 54 assert(m_collectionNames.size() == 1); 55 break; 56 case Action_Remove: 57 break; 58 } 59 } 60 doPerformDo(MapDocumentCommandFacade * document)61 bool TextureCollectionCommand::doPerformDo(MapDocumentCommandFacade* document) { 62 switch (m_action) { 63 case Action_Add: 64 document->performAddExternalTextureCollections(m_collectionNames); 65 break; 66 case Action_Remove: 67 document->performRemoveExternalTextureCollections(m_collectionNames); 68 break; 69 case Action_MoveUp: 70 document->performMoveExternalTextureCollectionUp(m_collectionNames.front()); 71 break; 72 case Action_MoveDown: 73 document->performMoveExternalTextureCollectionDown(m_collectionNames.front()); 74 break; 75 } 76 return true; 77 } 78 doPerformUndo(MapDocumentCommandFacade * document)79 bool TextureCollectionCommand::doPerformUndo(MapDocumentCommandFacade* document) { 80 switch (m_action) { 81 case Action_Add: 82 document->performRemoveExternalTextureCollections(m_collectionNames); 83 break; 84 case Action_Remove: 85 document->performAddExternalTextureCollections(m_collectionNames); 86 break; 87 case Action_MoveUp: 88 document->performMoveExternalTextureCollectionDown(m_collectionNames.front()); 89 break; 90 case Action_MoveDown: 91 document->performMoveExternalTextureCollectionUp(m_collectionNames.front()); 92 break; 93 } 94 return true; 95 } 96 doIsRepeatable(MapDocumentCommandFacade * document) const97 bool TextureCollectionCommand::doIsRepeatable(MapDocumentCommandFacade* document) const { 98 return false; 99 } 100 doCollateWith(UndoableCommand::Ptr command)101 bool TextureCollectionCommand::doCollateWith(UndoableCommand::Ptr command) { 102 return false; 103 } 104 } 105 } 106