xref: /haiku/src/apps/icon-o-matic/shape/commands/UnassignPathCommand.cpp (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
1 /*
2  * Copyright 2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "UnassignPathCommand.h"
10 
11 #include "PathContainer.h"
12 #include "Shape.h"
13 #include "VectorPath.h"
14 
15 // constructor
16 UnassignPathCommand::UnassignPathCommand(Shape* shape,
17 										 VectorPath* path)
18 	: Command(),
19 	  fShape(shape),
20 	  fPath(path),
21 	  fPathRemoved(false)
22 {
23 }
24 
25 // destructor
26 UnassignPathCommand::~UnassignPathCommand()
27 {
28 	if (fPathRemoved && fPath)
29 		fPath->Release();
30 }
31 
32 // InitCheck
33 status_t
34 UnassignPathCommand::InitCheck()
35 {
36 	return fShape && fPath ? B_OK : B_NO_INIT;
37 }
38 
39 // Perform
40 status_t
41 UnassignPathCommand::Perform()
42 {
43 	// remove path from shape
44 	fShape->Paths()->RemovePath(fPath);
45 	fPathRemoved = true;
46 
47 	return B_OK;
48 }
49 
50 // Undo
51 status_t
52 UnassignPathCommand::Undo()
53 {
54 	// add path to shape
55 	fShape->Paths()->AddPath(fPath);
56 	fPathRemoved = false;
57 
58 	return B_OK;
59 }
60 
61 // GetName
62 void
63 UnassignPathCommand::GetName(BString& name)
64 {
65 	name << "Unassign Path";
66 }
67