parent
7654f01277
commit
3d1f747f62
@ -58,6 +58,7 @@ void Commands_init(struct sync_track** syncTracks, struct TrackData* trackData)
|
||||
s_trackData = trackData;
|
||||
|
||||
memset(&s_undoStack, 0, sizeof(CommandList));
|
||||
memset(&s_redoStack, 0, sizeof(CommandList));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -75,19 +76,23 @@ static int countEntriesInList(CommandList* list)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int Commands_undoCount()
|
||||
{
|
||||
return countEntriesInList(&s_undoStack);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void execCommand(Command* command)
|
||||
{
|
||||
// set if we have multi command recording enabled)
|
||||
if (s_multiCommand)
|
||||
{
|
||||
printf("cmd add to multicommand %p\n", command);
|
||||
CommandList_addEntry(&s_multiCommand->list, command);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("cmd add to undoStack %p\n", command);
|
||||
CommandList_addEntry(&s_undoStack, command);
|
||||
printf("undo stack size %d\n", countEntriesInList(&s_undoStack));
|
||||
command->exec(command->userData);
|
||||
}
|
||||
|
||||
@ -122,7 +127,6 @@ void Commands_beginMulti(const char* name)
|
||||
{
|
||||
s_multiCommand = malloc(sizeof(struct MultiCommandData));
|
||||
memset(s_multiCommand, 0, sizeof(struct MultiCommandData));
|
||||
printf("multi_cmd: %s start %p\n", name, s_multiCommand);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -131,19 +135,15 @@ void Commands_endMulti()
|
||||
{
|
||||
Command* command;
|
||||
|
||||
|
||||
// Check if any command was added during multi command
|
||||
|
||||
if (CommandList_isEmpty(&s_multiCommand->list))
|
||||
{
|
||||
printf("multi_cmd: end (nothing to add)\n");
|
||||
free(s_multiCommand);
|
||||
s_multiCommand = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
printf("multi_cmd: end %p\n", s_multiCommand);
|
||||
|
||||
command = malloc(sizeof(Command));
|
||||
memset(command, 0, sizeof(Command));
|
||||
|
||||
@ -176,8 +176,6 @@ static void execDeleteKey(void* userData)
|
||||
data->oldKey = t->keys[idx];
|
||||
sync_del_key(t, data->row);
|
||||
|
||||
printf("del_cmd exec: %d %d\n", data->track, data->row);
|
||||
|
||||
RemoteConnection_sendDeleteKeyCommand(t->name, data->row);
|
||||
}
|
||||
|
||||
@ -189,8 +187,6 @@ static void undoDeleteKey(void* userData)
|
||||
struct sync_track* t = s_syncTracks[data->track];
|
||||
sync_set_key(t, &data->oldKey);
|
||||
|
||||
printf("del_cmd undo: %d %d\n", data->track, data->oldKey.row);
|
||||
|
||||
RemoteConnection_sendSetKeyCommand(t->name, &data->oldKey);
|
||||
}
|
||||
|
||||
@ -214,8 +210,6 @@ void Commands_deleteKey(int track, int row)
|
||||
data->track = track;
|
||||
data->row = row;
|
||||
|
||||
printf("del_cmd add: %p %d %d\n", command, track, row);
|
||||
|
||||
execCommand(command);
|
||||
}
|
||||
|
||||
@ -334,21 +328,14 @@ void Commands_undo()
|
||||
{
|
||||
Command* command;
|
||||
|
||||
printf("calling undo\n");
|
||||
|
||||
if (CommandList_isEmpty(&s_undoStack))
|
||||
{
|
||||
printf("Thinks undo stack is empty.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf("undo stack size before pop %d\n", countEntriesInList(&s_undoStack));
|
||||
|
||||
command = s_undoStack.last;
|
||||
CommandList_pop(&s_undoStack);
|
||||
|
||||
printf("undo stack size after pop %d\n", countEntriesInList(&s_undoStack));
|
||||
|
||||
command->prev = 0;
|
||||
command->next = 0;
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ void Commands_toogleBookmark(int track, int row);
|
||||
void Commands_updateKey(int track, struct track_key* key);
|
||||
void Commands_beginMulti(const char* name); // Used (for example) when changing many value at the same time
|
||||
void Commands_endMulti();
|
||||
int Commands_undoCount();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
extern void Window_setTitle(const char* title);
|
||||
extern void Window_populateRecentList(const char** files);
|
||||
static void updateNeedsSaving();
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -47,8 +48,11 @@ typedef struct EditorData
|
||||
int copyCount;
|
||||
} EditorData;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static EditorData s_editorData;
|
||||
static CopyData s_copyData;
|
||||
static int s_undoLevel = 0;
|
||||
static bool reset_tracks = true;
|
||||
static char s_filenames[5][2048];
|
||||
static char* s_loadedFilename = 0;
|
||||
@ -513,6 +517,7 @@ static void deleteArea(int rowPos, int track, int bufferWidth, int bufferHeight)
|
||||
}
|
||||
|
||||
Commands_endMulti();
|
||||
updateNeedsSaving();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -543,6 +548,7 @@ static void biasSelection(float value, int selectLeft, int selectRight, int sele
|
||||
}
|
||||
|
||||
Commands_endMulti();
|
||||
updateNeedsSaving();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -578,6 +584,7 @@ static void endEditing()
|
||||
track_name = track->name;
|
||||
|
||||
Commands_addOrUpdateKey(active_track, &key);
|
||||
updateNeedsSaving();
|
||||
|
||||
is_editing = false;
|
||||
s_editorData.trackData.editText = 0;
|
||||
@ -887,6 +894,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
else
|
||||
Commands_undo();
|
||||
|
||||
updateNeedsSaving();
|
||||
Editor_update();
|
||||
|
||||
return true;
|
||||
@ -934,6 +942,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
}
|
||||
|
||||
Commands_endMulti();
|
||||
updateNeedsSaving();
|
||||
|
||||
handled_key = true;
|
||||
}
|
||||
@ -1015,6 +1024,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
key.type = t->keys[emaxi(idx - 1, 0)].type;
|
||||
|
||||
Commands_addOrUpdateKey(active_track, &key);
|
||||
updateNeedsSaving();
|
||||
}
|
||||
|
||||
handled_key = true;
|
||||
@ -1034,6 +1044,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
|
||||
newKey.type = ((newKey.type + 1) % KEY_TYPE_COUNT);
|
||||
|
||||
Commands_addOrUpdateKey(active_track, &newKey);
|
||||
updateNeedsSaving();
|
||||
|
||||
handled_key = true;
|
||||
}
|
||||
@ -1216,20 +1227,42 @@ void Editor_timedUpdate()
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void setWindowTitle(const char* path)
|
||||
static void setWindowTitle(const char* path, bool needsSave)
|
||||
{
|
||||
char windowTitle[4096];
|
||||
sprintf(windowTitle, "RocketEditor - (%s)", path);
|
||||
if (needsSave)
|
||||
sprintf(windowTitle, "RocketEditor - (%s) *", path);
|
||||
else
|
||||
sprintf(windowTitle, "RocketEditor - (%s)", path);
|
||||
|
||||
Window_setTitle(windowTitle);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void updateNeedsSaving()
|
||||
{
|
||||
int undoCount;
|
||||
|
||||
if (!s_loadedFilename)
|
||||
return;
|
||||
|
||||
undoCount = Commands_undoCount();
|
||||
|
||||
if (s_undoLevel != undoCount)
|
||||
setWindowTitle(s_loadedFilename, true);
|
||||
else
|
||||
setWindowTitle(s_loadedFilename, false);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void onFinishedLoad(const char* path)
|
||||
{
|
||||
Editor_update();
|
||||
setWindowTitle(path);
|
||||
setWindowTitle(path, false);
|
||||
setMostRecentFile(path);
|
||||
s_undoLevel = Commands_undoCount();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1264,7 +1297,8 @@ static bool onSaveDialog()
|
||||
return false;
|
||||
|
||||
setMostRecentFile(path);
|
||||
setWindowTitle(path);
|
||||
setWindowTitle(path, false);
|
||||
s_undoLevel = Commands_undoCount();
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1277,6 +1311,9 @@ static void onSave()
|
||||
onSaveDialog();
|
||||
else
|
||||
LoadSave_saveRocketXML(getMostRecentFile(), getTrackData());
|
||||
|
||||
setWindowTitle(getMostRecentFile(), false);
|
||||
s_undoLevel = Commands_undoCount();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user