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 "SetLockStateCommand.h"
21 #include "Macros.h"
22 #include "View/MapDocumentCommandFacade.h"
23 
24 namespace TrenchBroom {
25     namespace View {
26         const Command::CommandType SetLockStateCommand::Type = Command::freeType();
27 
lock(const Model::NodeList & nodes)28         SetLockStateCommand::Ptr SetLockStateCommand::lock(const Model::NodeList& nodes) {
29             return Ptr(new SetLockStateCommand(nodes, Model::Lock_Locked));
30         }
31 
unlock(const Model::NodeList & nodes)32         SetLockStateCommand::Ptr SetLockStateCommand::unlock(const Model::NodeList& nodes) {
33             return Ptr(new SetLockStateCommand(nodes, Model::Lock_Unlocked));
34         }
35 
reset(const Model::NodeList & nodes)36         SetLockStateCommand::Ptr SetLockStateCommand::reset(const Model::NodeList& nodes) {
37             return Ptr(new SetLockStateCommand(nodes, Model::Lock_Inherited));
38         }
39 
SetLockStateCommand(const Model::NodeList & nodes,const Model::LockState state)40         SetLockStateCommand::SetLockStateCommand(const Model::NodeList& nodes, const Model::LockState state) :
41         UndoableCommand(Type, makeName(state)),
42         m_nodes(nodes),
43         m_state(state) {}
44 
makeName(const Model::LockState state)45         String SetLockStateCommand::makeName(const Model::LockState state) {
46             switch (state) {
47                 case Model::Lock_Inherited:
48                     return "Reset Locking";
49                 case Model::Lock_Locked:
50                     return "Lock Objects";
51                 case Model::Lock_Unlocked:
52                     return "Unlock Objects";
53 		switchDefault()
54             }
55         }
56 
doPerformDo(MapDocumentCommandFacade * document)57         bool SetLockStateCommand::doPerformDo(MapDocumentCommandFacade* document) {
58             m_oldState = document->setLockState(m_nodes, m_state);
59             return true;
60         }
61 
doPerformUndo(MapDocumentCommandFacade * document)62         bool SetLockStateCommand::doPerformUndo(MapDocumentCommandFacade* document) {
63             document->restoreLockState(m_oldState);
64             return true;
65         }
66 
doCollateWith(UndoableCommand::Ptr command)67         bool SetLockStateCommand::doCollateWith(UndoableCommand::Ptr command) {
68             return false;
69         }
70 
doIsRepeatable(MapDocumentCommandFacade * document) const71         bool SetLockStateCommand::doIsRepeatable(MapDocumentCommandFacade* document) const {
72             return false;
73         }
74     }
75 }
76