1/*
2    PPDocument_ActiveTool.m
3
4    Copyright 2013-2018 Josh Freeman
5    http://www.twilightedge.com
6
7    This file is part of PikoPixel for Mac OS X and GNUstep.
8    PikoPixel is a graphical application for drawing & editing pixel-art images.
9
10    PikoPixel is free software: you can redistribute it and/or modify it under
11    the terms of the GNU Affero General Public License as published by the
12    Free Software Foundation, either version 3 of the License, or (at your
13    option) any later version approved for PikoPixel by its copyright holder (or
14    an authorized proxy).
15
16    PikoPixel is distributed in the hope that it will be useful, but WITHOUT ANY
17    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18    FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19    details.
20
21    You should have received a copy of the GNU Affero General Public License
22    along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#import "PPDocument.h"
26
27#import "PPDocument_Notifications.h"
28#import "PPToolbox.h"
29
30
31@implementation PPDocument (ActiveTool)
32
33- (void) setSelectedToolType: (PPToolType) toolType
34{
35    if (!PPToolType_IsValid(toolType) || (toolType == _selectedToolType))
36    {
37        return;
38    }
39
40    _lastSelectedToolType = _selectedToolType;
41    _selectedToolType = toolType;
42
43    [self postNotification_SwitchedSelectedTool];
44}
45
46- (void) setSelectedToolTypeToLastSelectedType
47{
48    [self setSelectedToolType: _lastSelectedToolType];
49}
50
51- (PPToolType) selectedToolType
52{
53    return _selectedToolType;
54}
55
56- (void) setActiveToolType: (PPToolType) toolType
57{
58    if (!PPToolType_IsValid(toolType) || (toolType == _activeToolType))
59    {
60        return;
61    }
62
63    _activeTool = [[PPToolbox sharedToolbox] toolOfType: toolType];
64    _activeToolType = toolType;
65
66    [self postNotification_SwitchedActiveTool];
67}
68
69- (PPToolType) activeToolType
70{
71    return _activeToolType;
72}
73
74- (PPTool *) activeTool
75{
76    return _activeTool;
77}
78
79@end
80