OpenASIP 2.2
Loading...
Searching...
No Matches
OSEdRemoveModuleCmd.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file OSEdRemoveModuleCmd.cc
26 *
27 * Definition of OSEdRemoveModuleCmd class.
28 *
29 * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30 * @note rating: red
31 */
32
33#include <boost/format.hpp>
34#include <iostream>
35
37#include "OSEdConstants.hh"
38#include "ConfirmDialog.hh"
39#include "OSEdTextGenerator.hh"
40#include "OperationContainer.hh"
41#include "WxConversion.hh"
42#include "FileSystem.hh"
43#include "Application.hh"
44#include "OperationModule.hh"
45#include "OSEd.hh"
46#include "OSEdTreeView.hh"
47#include "OSEdInfoView.hh"
48#include "OperationIndex.hh"
49
50using std::string;
51using boost::format;
52using std::cout;
53using std::endl;
54
55/**
56 * Constructor.
57 */
59 GUICommand(OSEdConstants::CMD_NAME_REMOVE_MODULE, NULL) {
60}
61
62/**
63 * Destructor.
64 */
67
68/**
69 * Returns the id of the command.
70 *
71 * @return Id of the command.
72 */
73int
77
78/**
79 * Returns a new command.
80 *
81 * @return A new command.
82 */
85 return new OSEdRemoveModuleCmd();
86}
87
88/**
89 * Executes the command.
90 *
91 * @return True if execution is successful.
92 */
93bool
95
97 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
98 string modName = treeView->selectedModule();
99 wxTreeItemId modId = treeView->selectedModuleId();
100 string path = treeView->pathOfModule(modId);
101
102 OperationModule& module = OperationContainer::module(path, modName);
103
105 fmt % modName;
107
108 if (dialog.ShowModal() == wxID_YES) {
109 bool removed =
110 FileSystem::removeFileOrDirectory(module.propertiesModule());
111 assert(removed == true);
112
113 if (module.hasBehaviorSource()) {
114 fmt = texts.text(
116
117 fmt % FileSystem::fileOfPath(module.behaviorSourceModule());
118
119 wxString confText = WxConversion::toWxString(fmt.str());
120 ConfirmDialog confirm(parentWindow(), confText);
121
122 if (confirm.ShowModal() == wxID_YES) {
123 FileSystem::removeFileOrDirectory(module.behaviorSourceModule());
124 }
125 }
126
127 if (module.definesBehavior()) {
128 FileSystem::removeFileOrDirectory(module.behaviorModule());
129 }
130
132 index.removeModule(path, modName);
133 treeView->removeItem(modId);
134 treeView->infoView()->moduleView(path);
135 }
136 return true;
137}
138
139/**
140 * Returns true if command is enabled.
141 *
142 * @return True if command is enabled.
143 */
144bool
146 OSEdTreeView* treeView = wxGetApp().mainFrame()->treeView();
147 if (treeView->isModuleSelected()) {
148 wxTreeItemId modId = treeView->selectedModuleId();
149 string path = treeView->pathOfModule(modId);
150 if (path != "") {
151 return FileSystem::fileIsWritable(path);
152 } else {
153 return false;
154 }
155 } else {
156 return false;
157 }
158
159 assert(false);
160 return false;
161}
162
163/**
164 * Returns icon path.
165 *
166 * @return Empty string (no icons used).
167 */
168string
170 return "";
171}
#define assert(condition)
static bool removeFileOrDirectory(const std::string &path)
static std::string fileOfPath(const std::string pathName)
static bool fileIsWritable(const std::string fileName)
wxWindow * parentWindow() const
Definition GUICommand.cc:75
@ CMD_REMOVE_MODULE
Remove module command id.
void moduleView(const std::string &name)
virtual std::string icon() const
virtual GUICommand * create() const
virtual int id() const
static OSEdTextGenerator & instance()
@ TXT_QUESTION_REMOVE_MODULE
Remove module question.
@ TXT_QUESTION_REMOVE_BEHAVIOR_FILE
Remove behavior question.
bool isModuleSelected() const
wxTreeItemId selectedModuleId()
std::string pathOfModule(wxTreeItemId id)
OSEdInfoView * infoView() const
void removeItem(wxTreeItemId id)
std::string selectedModule()
static OperationIndex & operationIndex()
void removeModule(const std::string &path, const std::string &modName)
virtual boost::format text(int textId)
static wxString toWxString(const std::string &source)