Show "*" next to filename if it needs to be saved

Closes #46
This commit is contained in:
Daniel Collin 2012-12-31 15:36:55 +01:00
parent 7654f01277
commit 3d1f747f62
3 changed files with 50 additions and 25 deletions

View File

@ -58,6 +58,7 @@ void Commands_init(struct sync_track** syncTracks, struct TrackData* trackData)
s_trackData = trackData; s_trackData = trackData;
memset(&s_undoStack, 0, sizeof(CommandList)); 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) static void execCommand(Command* command)
{ {
// set if we have multi command recording enabled) // set if we have multi command recording enabled)
if (s_multiCommand) if (s_multiCommand)
{ {
printf("cmd add to multicommand %p\n", command);
CommandList_addEntry(&s_multiCommand->list, command); CommandList_addEntry(&s_multiCommand->list, command);
} }
else else
{ {
printf("cmd add to undoStack %p\n", command);
CommandList_addEntry(&s_undoStack, command); CommandList_addEntry(&s_undoStack, command);
printf("undo stack size %d\n", countEntriesInList(&s_undoStack));
command->exec(command->userData); command->exec(command->userData);
} }
@ -122,7 +127,6 @@ void Commands_beginMulti(const char* name)
{ {
s_multiCommand = malloc(sizeof(struct MultiCommandData)); s_multiCommand = malloc(sizeof(struct MultiCommandData));
memset(s_multiCommand, 0, 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; Command* command;
// Check if any command was added during multi command // Check if any command was added during multi command
if (CommandList_isEmpty(&s_multiCommand->list)) if (CommandList_isEmpty(&s_multiCommand->list))
{ {
printf("multi_cmd: end (nothing to add)\n");
free(s_multiCommand); free(s_multiCommand);
s_multiCommand = 0; s_multiCommand = 0;
return; return;
} }
printf("multi_cmd: end %p\n", s_multiCommand);
command = malloc(sizeof(Command)); command = malloc(sizeof(Command));
memset(command, 0, sizeof(Command)); memset(command, 0, sizeof(Command));
@ -176,8 +176,6 @@ static void execDeleteKey(void* userData)
data->oldKey = t->keys[idx]; data->oldKey = t->keys[idx];
sync_del_key(t, data->row); sync_del_key(t, data->row);
printf("del_cmd exec: %d %d\n", data->track, data->row);
RemoteConnection_sendDeleteKeyCommand(t->name, 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]; struct sync_track* t = s_syncTracks[data->track];
sync_set_key(t, &data->oldKey); sync_set_key(t, &data->oldKey);
printf("del_cmd undo: %d %d\n", data->track, data->oldKey.row);
RemoteConnection_sendSetKeyCommand(t->name, &data->oldKey); RemoteConnection_sendSetKeyCommand(t->name, &data->oldKey);
} }
@ -214,8 +210,6 @@ void Commands_deleteKey(int track, int row)
data->track = track; data->track = track;
data->row = row; data->row = row;
printf("del_cmd add: %p %d %d\n", command, track, row);
execCommand(command); execCommand(command);
} }
@ -334,21 +328,14 @@ void Commands_undo()
{ {
Command* command; Command* command;
printf("calling undo\n");
if (CommandList_isEmpty(&s_undoStack)) if (CommandList_isEmpty(&s_undoStack))
{ {
printf("Thinks undo stack is empty.\n");
return; return;
} }
printf("undo stack size before pop %d\n", countEntriesInList(&s_undoStack));
command = s_undoStack.last; command = s_undoStack.last;
CommandList_pop(&s_undoStack); CommandList_pop(&s_undoStack);
printf("undo stack size after pop %d\n", countEntriesInList(&s_undoStack));
command->prev = 0; command->prev = 0;
command->next = 0; command->next = 0;

View File

@ -24,6 +24,7 @@ void Commands_toogleBookmark(int track, int row);
void Commands_updateKey(int track, struct track_key* key); 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_beginMulti(const char* name); // Used (for example) when changing many value at the same time
void Commands_endMulti(); void Commands_endMulti();
int Commands_undoCount();
#endif #endif

View File

@ -19,6 +19,7 @@
extern void Window_setTitle(const char* title); extern void Window_setTitle(const char* title);
extern void Window_populateRecentList(const char** files); extern void Window_populateRecentList(const char** files);
static void updateNeedsSaving();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -47,8 +48,11 @@ typedef struct EditorData
int copyCount; int copyCount;
} EditorData; } EditorData;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static EditorData s_editorData; static EditorData s_editorData;
static CopyData s_copyData; static CopyData s_copyData;
static int s_undoLevel = 0;
static bool reset_tracks = true; static bool reset_tracks = true;
static char s_filenames[5][2048]; static char s_filenames[5][2048];
static char* s_loadedFilename = 0; static char* s_loadedFilename = 0;
@ -513,6 +517,7 @@ static void deleteArea(int rowPos, int track, int bufferWidth, int bufferHeight)
} }
Commands_endMulti(); Commands_endMulti();
updateNeedsSaving();
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -543,6 +548,7 @@ static void biasSelection(float value, int selectLeft, int selectRight, int sele
} }
Commands_endMulti(); Commands_endMulti();
updateNeedsSaving();
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -578,6 +584,7 @@ static void endEditing()
track_name = track->name; track_name = track->name;
Commands_addOrUpdateKey(active_track, &key); Commands_addOrUpdateKey(active_track, &key);
updateNeedsSaving();
is_editing = false; is_editing = false;
s_editorData.trackData.editText = 0; s_editorData.trackData.editText = 0;
@ -887,6 +894,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
else else
Commands_undo(); Commands_undo();
updateNeedsSaving();
Editor_update(); Editor_update();
return true; return true;
@ -934,6 +942,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
} }
Commands_endMulti(); Commands_endMulti();
updateNeedsSaving();
handled_key = true; 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; key.type = t->keys[emaxi(idx - 1, 0)].type;
Commands_addOrUpdateKey(active_track, &key); Commands_addOrUpdateKey(active_track, &key);
updateNeedsSaving();
} }
handled_key = true; handled_key = true;
@ -1034,6 +1044,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
newKey.type = ((newKey.type + 1) % KEY_TYPE_COUNT); newKey.type = ((newKey.type + 1) % KEY_TYPE_COUNT);
Commands_addOrUpdateKey(active_track, &newKey); Commands_addOrUpdateKey(active_track, &newKey);
updateNeedsSaving();
handled_key = true; 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]; char windowTitle[4096];
if (needsSave)
sprintf(windowTitle, "RocketEditor - (%s) *", path);
else
sprintf(windowTitle, "RocketEditor - (%s)", path); sprintf(windowTitle, "RocketEditor - (%s)", path);
Window_setTitle(windowTitle); 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) static void onFinishedLoad(const char* path)
{ {
Editor_update(); Editor_update();
setWindowTitle(path); setWindowTitle(path, false);
setMostRecentFile(path); setMostRecentFile(path);
s_undoLevel = Commands_undoCount();
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -1264,7 +1297,8 @@ static bool onSaveDialog()
return false; return false;
setMostRecentFile(path); setMostRecentFile(path);
setWindowTitle(path); setWindowTitle(path, false);
s_undoLevel = Commands_undoCount();
return true; return true;
} }
@ -1277,6 +1311,9 @@ static void onSave()
onSaveDialog(); onSaveDialog();
else else
LoadSave_saveRocketXML(getMostRecentFile(), getTrackData()); LoadSave_saveRocketXML(getMostRecentFile(), getTrackData());
setWindowTitle(getMostRecentFile(), false);
s_undoLevel = Commands_undoCount();
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////