WSF
TextSource.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef TEXTSOURCE_HPP
13#define TEXTSOURCE_HPP
14
15#include <algorithm>
16#include <deque>
17#include <string>
18#include <vector>
19
20#include <QVector>
21
22#include "FileSignature.hpp"
23#include "TextSourceChange.hpp"
24#include "UtCallback.hpp"
25#include "UtPath.hpp"
26#include "UtTextDocument.hpp"
27#include "ViExport.hpp"
28
29class QDataStream;
30class QWidget;
31class UtTextRange;
32class WsfParseNode;
33class QTextCursor;
34class QTextDocument;
35
36namespace wizard
37{
38class Editor;
39class Project;
41class TextSourceView;
42
47class VI_EXPORT TextSource : public UtTextDocument
48{
49public:
54 static UtCallbackListN<void(TextSource*, size_t, int)> TextSourceCharDeleted;
55
56 enum Flags
57 {
58 cINCLUDED = 1, // The file has been included by a scenario and must stay in memory
59 cCRITICAL = 2, // The file is critical in some manner and must be kept in memory
60
62 };
63 friend class wizard::Project;
65
66 TextSource(ProjectWorkspace* aProjectManagerPtr, const UtPath& aSourcePath);
67 virtual ~TextSource();
68
69 void AddedToWorkspace();
70
72 bool Load();
73
74 UtTextDocument* GetSource();
75 bool IsDeleted() const { return mDeleted; }
76 void SetDeleted(bool aIsDeleted);
77 bool CheckForFileModifications(bool aAlwaysFullyReload);
78 void HandleInsert(int aPosition, int aLength, const char* aText);
79 void HandleDelete(int aPosition, int aLength);
80 TextSourceView* NewView(Project* aProjectPtr);
81 TextSourceView* GetView(Project* aParentPtr);
82 const std::vector<TextSourceView*>& GetViews() const { return mViews; }
83 void EditorClosed(Editor* aEditorPtr);
84 void* GetQtDocument() const { return mDocumentPtr; }
85 QTextDocument* GetDocumentAsQTextDocument() const { return static_cast<QTextDocument*>(mDocumentPtr); }
86 // void UpdateStyling();
87 void ProjectParseUpdated();
88 bool Save();
89 void SaveWithNotifications();
90 void SaveAs();
91 std::string GetFileName();
92 std::string GetSystemPath() const { return mFilePath.GetSystemPath(); }
93
94 void Replace(const UtTextRange& aReplaceRange, const std::string& aText);
95 void Append(const std::string& aText);
96
97 const std::vector<TextSourceChange>& GetPendingChanges() const { return mPendingChanges; }
98
100 UtCallbackListN<void(TextSource&)> FileModifiedChange;
101
102 bool IsModified() const { return mModified; }
103 void SavePointReached();
104 bool ReadSource(bool aAlwaysFullyReload = false);
105
106 ProjectWorkspace* GetWorkspace() const { return mProjectWorkspacePtr; }
107 Project* GetProject();
108 void WaitForSourceModifications();
109 int GetFlags() const { return mFlags; }
110 void SetFlags(int aFlags) { mFlags = aFlags; }
111 bool IsCritical() const { return (cCRITICAL_MASK & mFlags) != 0; }
112 bool IsLoaded() const { return mLoaded; }
113 void Unload();
114
115 void ApplyModifications(UtTextRange& aRange, long long aStartSequenceNumber) const;
116
117 size_t ApplyModifications(size_t aPos, long long aStartSequenceNumber) const;
118
119 void ApplyPendingModifications(UtTextRange& aRange, UtTextDocument& aDocument) const;
120
121 bool HasAppliedChanges(long long aSequenceNumber) const;
122 bool HasPendingChanges() const { return !mPendingChanges.empty(); }
123
124 // For each change to a text document, it is given a sequence number. These changes are recorded
125 // and stored until no longer needed. The Obsolete sequence number is the last sequence number that
126 // needs to be kept.
127 static long long GetNextSequenceNumber() { return sNextSequenceNumber; }
128 static void SetObsoleteSequenceNumber(long long aNumber) { sObsoleteSequenceNumber = aNumber; }
129
130 FileSignature FileSignatureAtLoad() const { return mFileSignature; }
131
132 void ReloadViews();
133
134 static void DiffDocuments(const char* aOld, const char* aNew, QVector<TextSourceChange>& aChanges);
135 void FindIncludeLocations();
136 void BrowseContainingFolder();
137 void CopyPathToClipboard();
138
139private:
140 void SaveAndStore();
141
142 void ApplyChangeToQt(const TextSourceChange& aChange, Editor& aEditor);
143
144 void ApplyChangeToQt(const TextSourceChange& aChange, QTextCursor& aCursor);
145 int GetNextAppliedChange(long long aSequenceNumber) const;
146 void InsertText(size_t aPosition, size_t aLength, const char* aText);
147 void DeleteText(size_t aPosition, size_t aLength);
148
149 void ReloadEditor(Editor& aEditor, bool aInitialLoad, bool aForceUnmodified = false, bool aForceReload = false);
150
151 void SetModified(bool aModified, bool aTellQt = true)
152 {
153 if (mModified != aModified)
154 {
155 SetModifiedUpdate(aModified, aTellQt);
156 }
157 }
158 void SetModifiedUpdate(bool aModified, bool aTellQt);
159
160 void NotifyProjectOfChange();
161 void HandleChangeContents(int aPos, int aRemovedChars, int aAddChars);
162
163 void SyncChangesToSource();
164
165 int mFlags;
166
167 ProjectWorkspace* mProjectWorkspacePtr;
168
170 bool mLoaded;
172 bool mDeleted;
174 bool mModified;
175
177 std::vector<TextSourceChange> mPendingChanges;
180 std::deque<TextSourceChange> mAppliedChanges;
182 int mAppliedChangesBytes;
183 FileSignature mFileSignature;
185 std::vector<TextSourceView*> mViews;
186
189 void* mDocumentPtr;
190
191 static long long sNextSequenceNumber;
192 static long long sObsoleteSequenceNumber;
193};
194} // namespace wizard
195
196#endif
#define VI_EXPORT
Definition ViExport.hpp:38
void Load(PakI &aBuff, WsfXIO_PlatformPartInfo *&aPtr)
Definition WsfXIO_ObjectInfo.cpp:345
void Save(PakO &aBuff, WsfXIO_PlatformPartInfo *&aPtr)
Definition WsfXIO_ObjectInfo.cpp:352
Definition WsfParseNode.hpp:61
Definition Editor.hpp:57
Definition FileSignature.hpp:22
Definition ProjectWorkspace.hpp:48
A WSF 'project'. Manages WSF sources files in a WSF project.
Definition Project.hpp:66
Definition TextSourceView.hpp:23
const std::vector< TextSourceChange > & GetPendingChanges() const
Definition TextSource.hpp:97
void * GetQtDocument() const
Definition TextSource.hpp:84
ProjectWorkspace * GetWorkspace() const
Definition TextSource.hpp:106
bool IsDeleted() const
Definition TextSource.hpp:75
bool IsModified() const
Definition TextSource.hpp:102
static long long GetNextSequenceNumber()
Definition TextSource.hpp:127
int GetFlags() const
Definition TextSource.hpp:109
QTextDocument * GetDocumentAsQTextDocument() const
Definition TextSource.hpp:85
UtCallbackListN< void(TextSource &)> FileModifiedChange
Executes when file's modification state has changed.
Definition TextSource.hpp:100
const std::vector< TextSourceView * > & GetViews() const
Definition TextSource.hpp:82
bool IsCritical() const
Definition TextSource.hpp:111
bool HasPendingChanges() const
Definition TextSource.hpp:122
bool IsLoaded() const
Definition TextSource.hpp:112
FileSignature FileSignatureAtLoad() const
Definition TextSource.hpp:130
void AddedToWorkspace()
Definition TextSource.cpp:72
std::string GetSystemPath() const
Definition TextSource.hpp:92
Flags
Definition TextSource.hpp:57
@ cCRITICAL
Definition TextSource.hpp:59
@ cINCLUDED
Definition TextSource.hpp:58
@ cCRITICAL_MASK
Definition TextSource.hpp:61
static UtCallbackListN< void(TextSource *, size_t, int)> TextSourceCharDeleted
Definition TextSource.hpp:54
friend class wizard::ProjectWorkspace
Definition TextSource.hpp:64
void SetFlags(int aFlags)
Definition TextSource.hpp:110
UtTextDocument * GetSource()
Definition TextSource.cpp:318
TextSource(ProjectWorkspace *aProjectManagerPtr, const UtPath &aSourcePath)
Definition TextSource.cpp:52
static void SetObsoleteSequenceNumber(long long aNumber)
Definition TextSource.hpp:128
Definition Runner.hpp:22
Definition TextSourceChange.hpp:24
Copyrights Multiple, All Rights Reserved