Finale PDK Framework 0.77
Power Up Your Finale Music Software
Loading...
Searching...
No Matches
ff_undo.h
1/*
2 * File: ff_undo.h
3 * Author: Jari Williamsson
4 *
5 * Created on den 20 oktober 2011, 13:12
6 */
7
8#ifndef FF_UNDO_H
9#define FF_UNDO_H
10
11
13
20{
21 FCUndoController* _pOwner;
22
23public:
24 __FCUndoBlockHandler() : __FCBase() { _pOwner = NULL; }
25
32 virtual bool Execute() = 0;
33
34#ifndef DOXYGEN_SHOULD_IGNORE_THIS
36 void _SetOwner(FCUndoController* pOwner) { _pOwner = pOwner; }
37#endif
38
43 FCUndoController* GetOwner() { return _pOwner; }
44};
45
54{
55 UTRANSID _utransid;
56 FCString _lastundostring;
57 bool _sandboxmode;
58 bool _explicitrequired;
59 bool _currentisexplicit;
60 bool _isrunning;
61
62 FCString _suspendedundostring;
63 bool _suspendedisexplicit;
64 bool _suspendedisrunning;
65 bool _issuspended;
66
67 static std::map<_state_ptr, FCUndoController> _sessionundocontrollers;
68
69public:
70 const char* ClassName() const override { return "FCUndoController"; }
71
73 FCUndoController() : __FCBase(), _utransid(0), _sandboxmode(false), _explicitrequired(false),
74 _currentisexplicit(false), _isrunning(false),
75 _suspendedisexplicit(false), _issuspended(false), _suspendedisrunning(false)
76 {}
77
79 const FCString& GetLastUndoString() const { return _lastundostring; }
80
86#ifdef PDK_FRAMEWORK_LUAFRIENDLY
87 static FCUndoController& GetUndoController(_state_ptr S)
88#else
89 static FCUndoController& GetUndoController(_state_ptr S = nullptr)
90#endif
91 {
92 auto it = _sessionundocontrollers.find(_LUACODE(_GetBaseLuaState(S)) _NOLUACODE(S));
93 if (it != _sessionundocontrollers.end())
94 return it->second;
95 return CreateUndoController(false, false, S);
96 }
97
105#ifdef PDK_FRAMEWORK_LUAFRIENDLY
106 static FCUndoController& CreateUndoController(bool sandboxmode, bool explicitrequired, _state_ptr S)
107#else
108 static FCUndoController& CreateUndoController(bool sandboxmode, bool explicitrequired, _state_ptr S = nullptr)
109#endif
110 {
111 auto [newval, _] = _sessionundocontrollers.emplace(_LUACODE(_GetBaseLuaState(S)) _NOLUACODE(S), FCUndoController());
112 newval->second._sandboxmode = sandboxmode;
113 newval->second._explicitrequired = explicitrequired;
114 return newval->second;
115 }
118 static void RemoveUndoBlock(_state_ptr S)
119 {
120 auto it = _sessionundocontrollers.find(_LUACODE(_GetBaseLuaState(S)) _NOLUACODE(S));
121 if (it != _sessionundocontrollers.end())
122 _sessionundocontrollers.erase(S);
123 }
124
126 bool StartUndo(const FCString& undoString, bool savecurrent = false, bool isexplicit = true)
127 {
128 EndUndo(savecurrent); // in case we have one in progress
129 _utransid = undoString._StartFinaleEdit();
130 _lastundostring = undoString;
131 _currentisexplicit = isexplicit;
132 _isrunning = true; // we have to balance Start and End even for _utransid = 0
133 return true; // for now, always true
134 }
135
137 void EndUndo(bool savecurrent = false)
138 {
139 if (IsRunning())
140 {
141 if (savecurrent && _utransid && !_sandboxmode && (!_explicitrequired || _currentisexplicit))
142 FX_EndFinaleEdit();
143 else
144 FX_CancelFinaleEdit();
145 }
146 _isrunning = false;
147 _utransid = 0;
148 _currentisexplicit = false;
149 }
150
154 void SuspendUndo(bool savecurrent = false)
155 {
156 if (!_issuspended)
157 {
158 _suspendedundostring = _lastundostring;
159 _suspendedisexplicit = _currentisexplicit;
160 _suspendedisrunning = _isrunning;
161 _issuspended = true;
162 }
163 EndUndo(savecurrent);
164 }
165
170 void ResumeUndo(bool savecurrent = false)
171 {
172 if (!_issuspended || _suspendedisrunning)
173 {
174 if (_issuspended && ! _suspendedundostring.IsEmpty())
175 StartUndo(_suspendedundostring, savecurrent, _suspendedisexplicit);
176 else
177 StartUndo(_lastundostring, savecurrent);
178 }
179 _issuspended = false;
180 _suspendedisrunning = false;
181 _suspendedisexplicit = false;
182 _suspendedundostring.Clear();
183 }
184
193 bool Execute(__FCUndoBlockHandler *pHandler, const FCString *pUndoString);
194
206 bool AddSession(const FCString *pUndoString, bool storecurrentblock);
207
209 bool GetSandboxMode() const { return _sandboxmode; }
210
212 bool GetRequireExplicitUndo() const { return _explicitrequired; }
213
215 bool IsRunning() const { return _isrunning; }
216
218 bool GetCurrentIsExplicitUndo() const { return _currentisexplicit; }
219};
220
221#endif /* FF_UNDO_H */
222
Base class for the Finale Framework classes.
Definition ff_base.h:71
__FCBase()
The constructor.
Definition ff_base.h:278
The base class for the block handler. Intented for inheritance for use with the FCUndoController util...
Definition ff_undo.h:20
virtual bool Execute()=0
Virtual method that will be called by FCUndoController::Execute.
FCUndoController * GetOwner()
Returns the executing owner.
Definition ff_undo.h:43
Class that provides storage for text. This is to achieve platform-transparent text handling,...
Definition ff_base.h:1877
void Clear()
Creates an empty string.
Definition ff_base.h:2391
bool IsEmpty() const
Returns true if the string is empty.
Definition ff_base.h:3179
Class that handles Undo records for modeless plug-in interfaces.
Definition ff_undo.h:54
bool GetRequireExplicitUndo() const
Return if explicit undo blocks are required.
Definition ff_undo.h:212
bool GetCurrentIsExplicitUndo() const
Return currently running undo block is explicit.
Definition ff_undo.h:218
void SuspendUndo(bool savecurrent=false)
Suspends an undo session by ending it and saving all current info so that it can be resumed....
Definition ff_undo.h:154
bool GetSandboxMode() const
Return current sandbox mode.
Definition ff_undo.h:209
static FCUndoController & CreateUndoController(bool sandboxmode, bool explicitrequired, _state_ptr S=nullptr)
Creates an undo block for the specified session. If it already exists, then the session parameters ar...
Definition ff_undo.h:108
bool AddSession(const FCString *pUndoString, bool storecurrentblock)
Starts a new Undo/Redo block within a running Execute() session.
Definition finaleframework.cpp:37078
static FCUndoController & GetUndoController(_state_ptr S=nullptr)
Gets the undo block for the session, creating it if there is not already one,.
Definition ff_undo.h:89
const FCString & GetLastUndoString() const
returns the last undo string on this block.
Definition ff_undo.h:79
bool Execute(__FCUndoBlockHandler *pHandler, const FCString *pUndoString)
Executes the code within an undoable edit record.
Definition finaleframework.cpp:37062
const char * ClassName() const override
Returns the name of the class, for diagnostic purposes. This method MUST be overwritten in each child...
Definition ff_undo.h:70
void EndUndo(bool savecurrent=false)
Ends an undo session.
Definition ff_undo.h:137
void ResumeUndo(bool savecurrent=false)
Resumes an undo session by starting a session with saved info from the previous call to SuspendUndo....
Definition ff_undo.h:170
FCUndoController()
the constructor
Definition ff_undo.h:73
bool IsRunning() const
Return whether undo block is currently running.
Definition ff_undo.h:215
static void RemoveUndoBlock(_state_ptr S)
Clears out the undo block for the specified session. See comments at GetUndoController for more infor...
Definition ff_undo.h:118
bool StartUndo(const FCString &undoString, bool savecurrent=false, bool isexplicit=true)
Starts an undo session.
Definition ff_undo.h:126