OpenASIP  2.0
NewDocumentCmd.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 NewDocumentCmd.cc
26  *
27  * Definition of NewDocumentCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/docmdi.h>
34 
35 #include "NewDocumentCmd.hh"
36 #include "ProDeConstants.hh"
37 #include "ProDe.hh"
38 
39 using std::string;
40 
41 
42 /**
43  * The Constructor.
44  */
46  EditorCommand(ProDeConstants::CMD_NAME_NEW_DOC) {
47 
48 }
49 
50 
51 /**
52  * The Destructor.
53  */
55 
56 
57 /**
58  * Executes the command.
59  *
60  * @return Always false. Returning true here would cause problems with the
61  * wxCommandProcessor, and the command is never undoable so it's
62  * safe to return false even if the command was succesfully executed.
63  */
64 bool
66 
67  wxDocManager* docManager = wxGetApp().docManager();
68 
69  // Disable multiple tabs if we're not using wxWidgets 2.8 or above
70  if (wxCHECK_VERSION(2, 8, 0)) {
71  docManager->CreateDocument(_T(""), wxDOC_NEW);
72  return false;
73  }
74  else {
75  // close the active document if there is any
76  wxDocument *doc = docManager->GetCurrentDocument();
77  if (doc) {
78  if (doc->Close()) {
79  doc->DeleteAllViews();
80  }
81  else { // cancel was pressed -> cancel the command
82  return false;
83  }
84  }
85  }
86 
87  // create a new document
88  docManager->CreateDocument(_T(""), wxDOC_NEW);
89  return false;
90 }
91 
92 
93 /**
94  * Returns id of this command.
95  *
96  * @return ID for this command to be used in menus and toolbars.
97  */
98 int
101 }
102 
103 
104 /**
105  * Creates and returns a new instance of this command.
106  *
107  * @return Newly created instance of this command.
108  */
111  return new NewDocumentCmd();
112 }
113 
114 
115 /**
116  * Returns short version of the command name.
117  *
118  * @return Short name of the command to be used in the toolbar.
119  */
120 string
123 }
124 
125 
126 /**
127  * Returns path to the command's icon file.
128  *
129  * @return Full path to the command's icon file.
130  */
131 string
134 }
135 
136 
137 /**
138  * This command is always executable.
139  *
140  * @return Always true.
141  */
142 bool
144  return true;
145 }
NewDocumentCmd
Definition: NewDocumentCmd.hh:41
ProDeConstants::COMMAND_NEW_DOC
@ COMMAND_NEW_DOC
Definition: ProDeConstants.hh:407
NewDocumentCmd::shortName
virtual std::string shortName() const
Definition: NewDocumentCmd.cc:121
ProDe.hh
NewDocumentCmd::Do
virtual bool Do()
Definition: NewDocumentCmd.cc:65
NewDocumentCmd::id
virtual int id() const
Definition: NewDocumentCmd.cc:99
NewDocumentCmd::icon
virtual std::string icon() const
Definition: NewDocumentCmd.cc:132
ProDeConstants::CMD_SNAME_NEW_DOC
static const std::string CMD_SNAME_NEW_DOC
Command name for the "New Document" command.
Definition: ProDeConstants.hh:192
ProDeConstants::CMD_ICON_NEW_DOC
static const std::string CMD_ICON_NEW_DOC
Icon location for the "New Document" command.
Definition: ProDeConstants.hh:296
NewDocumentCmd::isEnabled
virtual bool isEnabled()
Definition: NewDocumentCmd.cc:143
NewDocumentCmd::create
virtual NewDocumentCmd * create() const
Definition: NewDocumentCmd.cc:110
NewDocumentCmd.hh
ProDeConstants.hh
NewDocumentCmd::NewDocumentCmd
NewDocumentCmd()
Definition: NewDocumentCmd.cc:45
NewDocumentCmd::~NewDocumentCmd
virtual ~NewDocumentCmd()
Definition: NewDocumentCmd.cc:54
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants
Definition: ProDeConstants.hh:43