diff --git a/ogl_editor/data/macosx/appnib.xib b/ogl_editor/data/macosx/appnib.xib
index a9cfc87..1c04376 100644
--- a/ogl_editor/data/macosx/appnib.xib
+++ b/ogl_editor/data/macosx/appnib.xib
@@ -125,7 +125,30 @@
1
-
- 547
+ 567
0
diff --git a/ogl_editor/data/macosx/info.plist b/ogl_editor/data/macosx/info.plist
index ff1d020..3641a92 100644
--- a/ogl_editor/data/macosx/info.plist
+++ b/ogl_editor/data/macosx/info.plist
@@ -9,7 +9,7 @@
CFBundleIconFile
icon
CFBundleIdentifier
- com.yourcompany.someid
+ com.tbl.rocketeditor
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/ogl_editor/src/Editor.c b/ogl_editor/src/Editor.c
index 3ef398e..8f718d8 100644
--- a/ogl_editor/src/Editor.c
+++ b/ogl_editor/src/Editor.c
@@ -17,6 +17,7 @@
#include "../../sync/data.h"
extern void Window_setTitle(const char* title);
+extern void Window_populateRecentList(const char** files);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -45,10 +46,61 @@ typedef struct EditorData
int copyCount;
} EditorData;
-static char s_currentFile[2048];
static EditorData s_editorData;
static CopyData s_copyData;
static bool reset_tracks = true;
+static char s_filenames[5][2048];
+
+static char* s_recentFiles[] =
+{
+ s_filenames[0],
+ s_filenames[1],
+ s_filenames[2],
+ s_filenames[3],
+ s_filenames[4],
+};
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+char** Editor_getRecentFiles()
+{
+ return (char**)s_recentFiles;
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+const char* getMostRecentFile()
+{
+ return s_recentFiles[0];
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void setMostRecentFile(const char* filename)
+{
+ int i;
+
+ // move down all files
+ for (i = 3; i >= 0; --i)
+ strcpy(s_recentFiles[i+1], s_recentFiles[i]);
+
+ strcpy(s_recentFiles[0], filename);
+
+ // check if the string was already present and remove it if that is the case by compacting the array
+
+ for (i = 1; i < 5; ++i)
+ {
+ if (!strcmp(s_recentFiles[i], filename))
+ {
+ for (; i < 4; ++i)
+ strcpy(s_recentFiles[i], s_recentFiles[i + 1]);
+
+ break;
+ }
+ }
+
+ Window_populateRecentList((const char**)s_recentFiles);
+}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -565,6 +617,7 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
row = t->keys[idx + 1].row;
viewInfo->rowPos = row;
+ viewInfo->selectStartRow = viewInfo->selectStopRow = row;
}
break;
@@ -826,14 +879,9 @@ bool Editor_keyDown(int key, int keyCode, int modifiers)
case 14 : bias_value = 1.0f; break;
case 15 : bias_value = 10.f; break;
case 17 : bias_value = 100.0f; break;
- case 16 : bias_value = 1000.0f; break;
}
biasSelection(bias_value, selectLeft, selectRight, selectTop, selectBottom);
-
- Editor_update();
-
- return true;
}
// do edit here and biasing here
@@ -1089,12 +1137,30 @@ static void setWindowTitle(const char* path)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-static void onOpen()
+void Editor_loadRecentFile(int id)
{
- if (LoadSave_loadRocketXMLDialog(s_currentFile, getTrackData()))
+ char path[2048];
+ strcpy(path, s_recentFiles[id]); // must be unique buffer when doing set mostRecent
+
+ if (LoadSave_loadRocketXML(path, getTrackData()))
{
Editor_update();
- setWindowTitle(s_currentFile);
+ setWindowTitle(path);
+ setMostRecentFile(path);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+static void onOpen()
+{
+ char currentFile[2048];
+
+ if (LoadSave_loadRocketXMLDialog(currentFile, getTrackData()))
+ {
+ Editor_update();
+ setWindowTitle(currentFile);
+ setMostRecentFile(currentFile);
}
}
@@ -1102,7 +1168,7 @@ static void onOpen()
static void onSave()
{
- LoadSave_saveRocketXML(s_currentFile, getTrackData());
+ LoadSave_saveRocketXML(getMostRecentFile(), getTrackData());
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1110,9 +1176,11 @@ static void onSave()
static void onSaveDialog()
{
char path[2048];
+
if (!LoadSave_saveRocketXMLDialog(path, getTrackData()))
return;
+ setMostRecentFile(path);
setWindowTitle(path);
}
@@ -1120,7 +1188,6 @@ static void onSaveDialog()
void Editor_menuEvent(int menuItem)
{
- printf("%d\n", menuItem);
switch (menuItem)
{
case EDITOR_MENU_OPEN : onOpen(); break;
diff --git a/ogl_editor/src/Editor.h b/ogl_editor/src/Editor.h
index e7e4ea1..6a2e06f 100644
--- a/ogl_editor/src/Editor.h
+++ b/ogl_editor/src/Editor.h
@@ -13,6 +13,9 @@ void Editor_setWindowSize(int x, int y);
void Editor_menuEvent(int menuItem);
void Editor_scroll(float deltaX, float deltaY, int flags);
void Editor_updateTrackScroll();
+void Editor_loadRecentFile(int file);
+
+char** Editor_getRecentFiles();
enum
{
diff --git a/ogl_editor/src/macosx/RocketView.m b/ogl_editor/src/macosx/RocketView.m
index ae7eb26..28416e5 100644
--- a/ogl_editor/src/macosx/RocketView.m
+++ b/ogl_editor/src/macosx/RocketView.m
@@ -213,6 +213,43 @@ static int getModifierFlags(int flags)
return YES;
}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+- (void)onRecentFile:(id)sender
+{
+ NSString* string = [sender representedObject];
+ Editor_loadRecentFile([string intValue]);
+}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void Window_populateRecentList(const char** files)
+{
+ NSMenu* fileMenu = [[[NSApp mainMenu] itemWithTitle:@"File"] submenu];
+ NSMenu* recentItems = [[fileMenu itemWithTitle:@"Recent Files"] submenu];
+
+ [recentItems removeAllItems];
+
+ for (int i = 0; i < 4; ++i)
+ {
+ const char* filename = files[i];
+
+ if (!strcmp(filename, ""))
+ continue;
+
+ NSString* name = [NSString stringWithUTF8String: filename];
+
+ NSMenuItem* newItem = [[NSMenuItem alloc] initWithTitle:name action:@selector(onRecentFile:) keyEquivalent:@""];
+ [newItem setRepresentedObject:[NSString stringWithFormat:@"%d",i]];
+ [newItem setKeyEquivalentModifierMask: NSCommandKeyMask];
+ [newItem setKeyEquivalent:[NSString stringWithFormat:@"%d",i + 1]];
+
+ [recentItems addItem:newItem];
+
+ [newItem release];
+ }
+}
+
@end
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -229,3 +266,4 @@ void Window_setTitle(const char* title)
[g_window setTitle:[NSString stringWithUTF8String:title]];
}
+
diff --git a/ogl_editor/src/macosx/delegate.m b/ogl_editor/src/macosx/delegate.m
index 667c4a7..dc298e2 100644
--- a/ogl_editor/src/macosx/delegate.m
+++ b/ogl_editor/src/macosx/delegate.m
@@ -3,6 +3,8 @@
#include "../RemoteConnection.h"
#include "rlog.h"
+void Window_populateRecentList(char** files);
+
@implementation MinimalAppAppDelegate
@synthesize window;
@@ -12,6 +14,24 @@
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
+ char** recent_list = Editor_getRecentFiles();
+
+ NSUserDefaults* prefs = [NSUserDefaults standardUserDefaults];
+
+ if (prefs)
+ {
+ NSArray* stringArray = [prefs objectForKey:@"recentFiles"];
+
+ for (int i = 0; i < 4; ++i)
+ {
+ NSString* name = [stringArray objectAtIndex:i];
+ const char* filename = [name cStringUsingEncoding:NSASCIIStringEncoding];
+ if (filename)
+ strcpy(recent_list[i], filename);
+ }
+ }
+
+ Window_populateRecentList(recent_list);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -25,7 +45,17 @@
- (void)applicationWillTerminate:(NSNotification *)aNotification
{
- rlog(R_INFO, "Dealloc\n");
+ int i;
+ NSMutableArray* stringArray;
+ char** recent_list = Editor_getRecentFiles();
+ stringArray = [[NSMutableArray alloc] init];
+
+ for (i = 0; i < 4; ++i)
+ [stringArray addObject:[NSString stringWithUTF8String: recent_list[i]]];
+
+ [[NSUserDefaults standardUserDefaults] setObject:stringArray forKey:@"recentFiles"];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+
Editor_destroy();
RemoteConnection_close();
}