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 "CurrentGroupCommand.h"
21 
22 #include "View/MapDocumentCommandFacade.h"
23 
24 namespace TrenchBroom {
25     namespace View {
26         const Command::CommandType CurrentGroupCommand::Type = Command::freeType();
27 
push(Model::Group * group)28         CurrentGroupCommand::Ptr CurrentGroupCommand::push(Model::Group* group) {
29             return Ptr(new CurrentGroupCommand(group));
30         }
31 
pop()32         CurrentGroupCommand::Ptr CurrentGroupCommand::pop() {
33             return Ptr(new CurrentGroupCommand(NULL));
34         }
35 
CurrentGroupCommand(Model::Group * group)36         CurrentGroupCommand::CurrentGroupCommand(Model::Group* group) :
37         UndoableCommand(Type, group != NULL ? "Push Group" : "Pop Group"),
38         m_group(group) {}
39 
doPerformDo(MapDocumentCommandFacade * document)40         bool CurrentGroupCommand::doPerformDo(MapDocumentCommandFacade* document) {
41             if (m_group != NULL) {
42                 document->performPushGroup(m_group);
43                 m_group = NULL;
44             } else {
45                 m_group = document->currentGroup();
46                 document->performPopGroup();
47             }
48             return true;
49         }
50 
doPerformUndo(MapDocumentCommandFacade * document)51         bool CurrentGroupCommand::doPerformUndo(MapDocumentCommandFacade* document) {
52             if (m_group == NULL) {
53                 m_group = document->currentGroup();
54                 document->performPopGroup();
55             } else {
56                 document->performPushGroup(m_group);
57                 m_group = NULL;
58             }
59             return true;
60         }
61 
doCollateWith(UndoableCommand::Ptr command)62         bool CurrentGroupCommand::doCollateWith(UndoableCommand::Ptr command) {
63             return false;
64         }
65 
doIsRepeatable(MapDocumentCommandFacade * document) const66         bool CurrentGroupCommand::doIsRepeatable(MapDocumentCommandFacade* document) const {
67             return false;
68         }
69     }
70 }
71