1
//------------------------------------------------------------------------------
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
//-----------------------------------------------------------------------------
27
#include "messagedialog.h"
28
#include "drawwindow.h"
31
class FileSelectionDialog;
38
/// (abstract) document class; generalization of diagram, tree, table, etc.
40
/*@Doc: {\large {\bf scope:} editor} */
43
Document(Config *c, EditWindow *d, Viewer *v);
47
/// opens new document called untitled.'suffix'.
50
/// popup file selector dialog for loading a file.
53
/// same as load but old document remains unchanged.
54
virtual void Append();
56
/// save document to file.
59
/// popup file selector dialog for saving to a file.
62
/// popup file selector dialog for saving selection to a file.
63
void SaveSelectionAs();
65
/// closes document (asks confirmation) and quits application.
68
/// popup info dialog containing information about this document.
71
/// popup text edit dialog with document source from file.
73
/// save edited source back to file.
76
/// popup info dialog containing summary of contents of this document.
77
virtual void ShowSummary();
79
/// popup warning dialog containing soft constraint violations (syntactic)
80
virtual void CheckDocument();
82
/// popup dialog to model check a temporal logic property (semantic check)
83
virtual void ModelCheckProperty();
87
virtual void ClearTrace();
89
/// popup text edit dialog in which doc. annotation can be given.
92
/// called from file selector dialog callbacks.
93
void LoadSave(const string *file);
95
/// load document from file.
96
virtual void DoLoad(const string *file);
99
void DoSaveAs(const string *file);
101
void DoSaveSelectionAs(const string *file);
103
/// return format that was found in file that is read in.
104
double GetLoadFormat() const {return loadFormat;}
106
/// perform some document type specific initialization.
107
virtual void Initialize();
109
/// Checks if file is legal and opens new document with file as name.
110
void NewFile(const string *file);
112
/// Delete contents of the document.
113
virtual void RemoveAll() = 0;
115
/// Checks if newname is legal, and if so, changes name of document.
116
bool NewName(const string *newname);
119
void SetName(const string *newname) {name = *newname;}
122
const string *GetName() const {return &name;}
125
const string *GetDocType() const {return &docType;}
128
const string *GetSuffix() const {return &suffix;}
131
const string *GetToolName() const {return &toolName;}
134
const string *GetAuthor() const {return &author;}
137
const string *GetCreationTime() const {return &createdOn;}
139
/// return whether doc.name is the default name.
142
/// Checks if newdir is legal, and if so, changes current directory.
143
void NewDir(const string *newdir);
146
void SetDir(const string *newdir) {dir = *newdir;}
149
const string *GetDir() const {return &dir;}
151
/// Set dir from file selector.
154
/// increases number of changes.
157
/// decrease number of changes.
161
int GetChanges() const {return changes;}
163
/// set inline edit (doc. type specific).
164
virtual void SetInlineEdit(bool) {}
167
enum MoveType {UP, DOWN, LEFT, RIGHT, CENTER};
169
/// move document in mainwindow.
170
virtual void Move(MoveType) {}
173
bool IsModified() const {return changes > 0;}
175
void SetModified(bool set) { if (set) changes=1; else changes=0;}
177
bool IsLoaded() const {return loaded;}
179
/// ask user to confirm that a file may be overwritten
180
bool MayWrite(const string *path);
182
/// set main window status message to msg.
183
void SetStatus(const char *msg) {mainwindow->SetStatus(msg);}
185
void SetStatus(const string *msg) {mainwindow->SetStatus(msg);}
187
/// set document annotation text to s.
188
void SetAnnotation(const string *s);
190
/// is the document hierarchic?
191
bool IsHierarchic() const {return isHierarchic;}
192
/// sets the hierarchic (editor mode) for the document
193
virtual void SetHierarchic(bool set);
194
/// is it allowed to switch to hierarchic mode?
195
virtual bool AllowHierarchic() const { return False; }
197
/// find all strings.
198
virtual void FindAll(const string *, bool, bool, bool)=0;
200
/// find next string.
201
virtual void FindNext(const string *, bool, bool, bool) =0;
203
/// replace all strings.
204
virtual void ReplaceAll(const string *, const string *,
207
/// replace next string.
208
virtual void ReplaceNext(const string *, const string *,
211
/// issue a popup dialog for getting a search string.
214
/// issue a popup dialog for search and replace strings.
215
virtual void Replace();
217
/// update main window document text fields
221
EditWindow *GetMainWindow() const {return mainwindow;}
223
Config *GetConfig() const {return config;}
225
Viewer *GetViewer() const {return viewer;}
227
InputFile *GetInputFile() const {return ifile;}
229
OutputFile *GetOutputFile() const {return ofile;}
232
TextEditDialog *GetSourceEditDialog() const {
233
return sourceEditDialog;}
235
TextEditDialog *GetDocAnnotationDialog() const {
236
return docAnnotationDialog;}
238
TextEditDialog *GetEltAnnotationDialog() const {
239
return eltAnnotationDialog;}
241
FileSelectionDialog *GetFileSelectionDialog() const {
242
return fileSelectionDialog;}
244
FindDialog *GetFindDialog() const {return findDialog;}
247
ReplaceDialog *GetReplaceDialog() const {return replaceDialog;}
250
virtual void LoadEntries() = 0;
252
virtual void SaveEntries()=0;
254
bool IsAppending() const {return appending;}
256
bool IsSaveSelection() const {return saveSelection;}
258
/// Set directory in all dialogs.
259
virtual void UpdateDirectory(const string *s);
262
void ShowDialog(MessageDialog::DialogType t,
263
const char *title, const char *text) const;
265
void ShowDialog(MessageDialog::DialogType t,
266
const char *title, const string *text) const {
267
ShowDialog(t, title, text->getstr());
270
/// Give results of Check Document in popup dialog.
271
void ReportCheck(int errors, const string *msg);
273
/// message string filled by Check Document.
277
// attributes of current tool.
279
EditWindow *mainwindow;
286
TextEditDialog *sourceEditDialog;
288
TextEditDialog *docAnnotationDialog;
290
TextEditDialog *eltAnnotationDialog;
292
FileSelectionDialog *fileSelectionDialog;
294
TextViewDialog *checkDialog;
296
TextViewDialog *infoDialog;
298
FindDialog *findDialog;
300
ReplaceDialog *replaceDialog;
310
/// is document currently modified ?
313
/// is document loaded or created.
316
/// is document loaded (overwritten) or appended.
319
/// is selection saved or entire document;
323
Toolkit::ToolType tool;
325
/// current document suffix
328
/// login of person who runs tool.
331
/// name of the current tool.
334
/// current working directory.
337
/// current version of file format (format that will be written).
343
// attributes of document contents.
344
/// current document name.
347
/// current document type.
350
/// initial author of the document.
353
/// creation time and date.
356
// attributes of loaded document.
357
/// file name from which document is loaded.
360
/// file format of loaded document.
363
/// tool that wrote loaded document.
364
string generatedFrom;
366
/// writing time and date of loaded document.
369
/// login that wrote document to file.
372
/// document annotation text.
375
/// file in which document is saved.
378
/// Create all popup dialog for document class.
379
void CreateDialogs();
381
/// function needed for loading document from file.
385
bool Load(const string *file);
394
virtual bool LoadHeader();
397
virtual bool LoadEditInfo() {return True;}
400
virtual bool CheckEditInfo() {return True;}
406
bool CheckDocumentType();
409
/// function needed for saving to file.
410
bool Save(const string *file);
414
virtual void SaveDocInfo();
417
virtual void SaveEditInfo();
420
void PrepareSaveDialog();