OpenASIP  2.0
SaveDocumentCmd.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 SaveDocumentCmd.cc
26  *
27  * Definition of SaveDocumentCmd class.
28  *
29  * @author Veli-Pekka Jääskeläinen (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include <wx/docview.h>
34 
35 #include "SaveDocumentCmd.hh"
36 #include "ProDeConstants.hh"
37 #include "ProDe.hh"
38 
39 using std::string;
40 
41 /**
42  * The Constructor.
43  */
45  EditorCommand(ProDeConstants::CMD_NAME_SAVE_DOC) {
46 
47 }
48 
49 
50 /**
51  * The Destructor.
52  */
54 
55 
56 /**
57  * Executes the command.
58  *
59  * @return Always false. Returning true here would cause problems with the
60  * wxCommandProcessor, and the command is never undoable so it's
61  * safe to return false even if the command was succesfully executed.
62  */
63 bool
65  wxDocument* doc = wxGetApp().docManager()->GetCurrentDocument();
66  assert(doc != NULL);
67 
68  // warning: Dirty trick to avoid file dialog on saving a document
69  // already assigned into a specific file name. wxID_SAVE handler
70  // always opens file dialog. Checking that file name does not
71  // contain a . should verify that the document has not been
72  // saved before.
73  wxString currentDocFilename = doc->GetFilename();
74  if (doc->GetFilename().Find('.') == -1) {
75  wxCommandEvent dummy(wxID_SAVE, 0);
76  wxGetApp().docManager()->OnFileSave(dummy);
77  } else {
78  doc->OnSaveDocument(currentDocFilename);
79  }
80 
81  return false;
82 }
83 
84 
85 /**
86  * Returns id of this command.
87  *
88  * @return ID for this command to be used in menus and toolbars.
89  */
90 int
93 }
94 
95 
96 /**
97  * Creates and returns a new instance of this command.
98  *
99  * @return Newly created instance of this command.
100  */
103  return new SaveDocumentCmd();
104 }
105 
106 
107 /**
108  * Returns short version of the command name.
109  *
110  * @return Short name of the command to be used in the toolbar.
111  */
112 string
115 }
116 
117 
118 /**
119  * Returns path to the command's icon file.
120  *
121  * @return Full path to the command's icon file.
122  */
123 string
126 }
127 
128 
129 /**
130  * Returns true when the command is executable, false when not.
131  *
132  * This command is executable when a document is open.
133  *
134  * @return True, if a document is open.
135  */
136 bool
138  wxDocument* doc = wxGetApp().docManager()->GetCurrentDocument();
139  if (doc != NULL && doc->IsModified()) {
140  return true;
141  }
142  return false;
143 }
144 
ProDe.hh
SaveDocumentCmd::Do
virtual bool Do()
Definition: SaveDocumentCmd.cc:64
SaveDocumentCmd
Definition: SaveDocumentCmd.hh:41
ProDeConstants::CMD_ICON_SAVE_DOC
static const std::string CMD_ICON_SAVE_DOC
Icon location for the "Save Document" command.
Definition: ProDeConstants.hh:292
assert
#define assert(condition)
Definition: Application.hh:86
SaveDocumentCmd::id
virtual int id() const
Definition: SaveDocumentCmd.cc:91
SaveDocumentCmd::~SaveDocumentCmd
virtual ~SaveDocumentCmd()
Definition: SaveDocumentCmd.cc:53
ProDeConstants::COMMAND_SAVE_DOC
@ COMMAND_SAVE_DOC
Definition: ProDeConstants.hh:410
SaveDocumentCmd::create
virtual SaveDocumentCmd * create() const
Definition: SaveDocumentCmd.cc:102
dummy
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
SaveDocumentCmd::icon
virtual std::string icon() const
Definition: SaveDocumentCmd.cc:124
SaveDocumentCmd::shortName
virtual std::string shortName() const
Definition: SaveDocumentCmd.cc:113
ProDeConstants.hh
ProDeConstants::CMD_SNAME_SAVE_DOC
static const std::string CMD_SNAME_SAVE_DOC
Command name for the "Save Document" command.
Definition: ProDeConstants.hh:194
SaveDocumentCmd::SaveDocumentCmd
SaveDocumentCmd()
Definition: SaveDocumentCmd.cc:44
EditorCommand
Definition: EditorCommand.hh:46
ProDeConstants
Definition: ProDeConstants.hh:43
SaveDocumentCmd.hh
SaveDocumentCmd::isEnabled
virtual bool isEnabled()
Definition: SaveDocumentCmd.cc:137