Win32 - Lua recent menu added
This commit is contained in:
parent
09566a1ba1
commit
c0889137b1
|
@ -92,6 +92,12 @@ static CFGSTRUCT fceuconfig[] = {
|
|||
ACS(memw_recent_files[3]),
|
||||
ACS(memw_recent_files[4]),
|
||||
|
||||
ACS(recent_lua[0]),
|
||||
ACS(recent_lua[1]),
|
||||
ACS(recent_lua[2]),
|
||||
ACS(recent_lua[3]),
|
||||
ACS(recent_lua[4]),
|
||||
|
||||
AC(gNoBGFillColor),
|
||||
AC(ntsccol),AC(ntsctint),AC(ntschue),
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ BEGIN
|
|||
END
|
||||
POPUP "Lua"
|
||||
BEGIN
|
||||
MENUITEM "Recent", MENU_LUA_RECENT
|
||||
MENUITEM "Run Lua Script...", ID_FILE_RUNLUASCRIPT
|
||||
MENUITEM "Stop Lua Script", ID_FILE_STOPLUASCRIPT
|
||||
MENUITEM "Reload Lua Script", ID_FILE_LUA_RELOADLUASCRIPT
|
||||
|
|
|
@ -663,6 +663,8 @@
|
|||
#define MENU_PREVIOUSSAVESTATE 40348
|
||||
#define ID_SAVESTATE_VIEWSAVESLOTS 40349
|
||||
#define MENU_VIEWSAVESLOTS 40350
|
||||
#define ID_LUA_RECENT 40351
|
||||
#define MENU_LUA_RECENT 40352
|
||||
#define IDC_DEBUGGER_ICONTRAY 55535
|
||||
#define MW_ValueLabel2 65423
|
||||
#define MW_ValueLabel1 65426
|
||||
|
@ -672,7 +674,7 @@
|
|||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 125
|
||||
#define _APS_NEXT_COMMAND_VALUE 40351
|
||||
#define _APS_NEXT_COMMAND_VALUE 40353
|
||||
#define _APS_NEXT_CONTROL_VALUE 1199
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
|
|
|
@ -76,6 +76,7 @@ using namespace std;
|
|||
static HMENU fceumenu = 0; //Main menu.
|
||||
HWND pwindow; //Client Area
|
||||
static HMENU recentmenu; //Recent Menu
|
||||
static HMENU recentluamenu; //Recent Lua Files Menu
|
||||
HMENU hfceuxcontext; //Handle to context menu
|
||||
HMENU hfceuxcontextsub; //Handle to context sub menu
|
||||
|
||||
|
@ -124,6 +125,11 @@ char *recent_files[] = { 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 };
|
|||
const unsigned int MENU_FIRST_RECENT_FILE = 600;
|
||||
const unsigned int MAX_NUMBER_OF_RECENT_FILES = sizeof(recent_files)/sizeof(*recent_files);
|
||||
|
||||
//Lua Recent Menu ---------------------------------------
|
||||
char *recent_lua[] = {0,0,0,0,0};
|
||||
const unsigned int LUA_FIRST_RECENT_FILE = 50000;
|
||||
const unsigned int MAX_NUMBER_OF_LUA_RECENT_FILES = sizeof(recent_lua)/sizeof(*recent_lua);
|
||||
|
||||
//Exported variables ------------------------------------
|
||||
|
||||
int EnableBackgroundInput = 0;
|
||||
|
@ -590,8 +596,119 @@ void AddRecentFile(const char *filename)
|
|||
UpdateRecentArray(filename, recent_files, MAX_NUMBER_OF_RECENT_FILES, recentmenu, MENU_RECENT_FILES, MENU_FIRST_RECENT_FILE);
|
||||
}
|
||||
|
||||
/// Hides the main menu.
|
||||
///@param hide_menu Flag to turn the main menu on (0) or off (1)
|
||||
void UpdateLuaRMenu(HMENU menu, char **strs, unsigned int mitem, unsigned int baseid)
|
||||
{
|
||||
MENUITEMINFO moo;
|
||||
int x;
|
||||
|
||||
moo.cbSize = sizeof(moo);
|
||||
moo.fMask = MIIM_SUBMENU | MIIM_STATE;
|
||||
|
||||
GetMenuItemInfo(GetSubMenu(fceumenu, 0), mitem, FALSE, &moo);
|
||||
moo.hSubMenu = menu;
|
||||
moo.fState = strs[0] ? MFS_ENABLED : MFS_GRAYED;
|
||||
|
||||
SetMenuItemInfo(GetSubMenu(fceumenu, 0), mitem, FALSE, &moo);
|
||||
|
||||
// Remove all recent files submenus
|
||||
for(x = 0; x < MAX_NUMBER_OF_LUA_RECENT_FILES; x++)
|
||||
{
|
||||
RemoveMenu(menu, baseid + x, MF_BYCOMMAND);
|
||||
}
|
||||
|
||||
// Recreate the menus
|
||||
for(x = MAX_NUMBER_OF_LUA_RECENT_FILES - 1; x >= 0; x--)
|
||||
{
|
||||
// Skip empty strings
|
||||
if(!strs[x])
|
||||
continue;
|
||||
|
||||
string tmp = strs[x];
|
||||
|
||||
//clamp this string to 128 chars
|
||||
if(tmp.size()>128)
|
||||
tmp = tmp.substr(0,128);
|
||||
|
||||
moo.cbSize = sizeof(moo);
|
||||
moo.fMask = MIIM_DATA | MIIM_ID | MIIM_TYPE;
|
||||
|
||||
// Insert the menu item
|
||||
moo.cch = tmp.size();
|
||||
moo.fType = 0;
|
||||
moo.wID = baseid + x;
|
||||
moo.dwTypeData = (LPSTR)tmp.c_str();
|
||||
InsertMenuItem(menu, 0, 1, &moo);
|
||||
}
|
||||
|
||||
DrawMenuBar(hAppWnd);
|
||||
}
|
||||
|
||||
void UpdateRecentLuaArray(const char* addString, char** bufferArray, unsigned int arrayLen, HMENU menu, unsigned int menuItem, unsigned int baseId)
|
||||
{
|
||||
// Try to find out if the filename is already in the recent files list.
|
||||
for(unsigned int x = 0; x < arrayLen; x++)
|
||||
{
|
||||
if(bufferArray[x])
|
||||
{
|
||||
if(!strcmp(bufferArray[x], addString)) // Item is already in list.
|
||||
{
|
||||
// If the filename is in the file list don't add it again.
|
||||
// Move it up in the list instead.
|
||||
|
||||
int y;
|
||||
char *tmp;
|
||||
|
||||
// Save pointer.
|
||||
tmp = bufferArray[x];
|
||||
|
||||
for(y = x; y; y--)
|
||||
{
|
||||
// Move items down.
|
||||
bufferArray[y] = bufferArray[y - 1];
|
||||
}
|
||||
|
||||
// Put item on top.
|
||||
bufferArray[0] = tmp;
|
||||
|
||||
// Update the recent files menu
|
||||
UpdateRMenu(menu, bufferArray, menuItem, baseId);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The filename wasn't found in the list. That means we need to add it.
|
||||
|
||||
// If there's no space left in the recent files list, get rid of the last
|
||||
// item in the list.
|
||||
if(bufferArray[arrayLen - 1])
|
||||
{
|
||||
free(bufferArray[arrayLen - 1]);
|
||||
}
|
||||
|
||||
// Move the other items down.
|
||||
for(unsigned int x = arrayLen - 1; x; x--)
|
||||
{
|
||||
bufferArray[x] = bufferArray[x - 1];
|
||||
}
|
||||
|
||||
// Add the new item.
|
||||
bufferArray[0] = (char*)malloc(strlen(addString) + 1); //mbg merge 7/17/06 added cast
|
||||
strcpy(bufferArray[0], addString);
|
||||
|
||||
// Update the recent files menu
|
||||
UpdateLuaRMenu(menu, bufferArray, menuItem, baseId);
|
||||
|
||||
}
|
||||
|
||||
void AddRecentLuaFile(const char *filename)
|
||||
{
|
||||
UpdateRecentLuaArray(filename, recent_lua, MAX_NUMBER_OF_LUA_RECENT_FILES, recentluamenu, MENU_LUA_RECENT, LUA_FIRST_RECENT_FILE);
|
||||
}
|
||||
|
||||
// Hides the main menu.
|
||||
//@param hide_menu Flag to turn the main menu on (0) or off (1)
|
||||
void HideMenu(unsigned int hide_menu)
|
||||
{
|
||||
if(hide_menu)
|
||||
|
@ -950,6 +1067,16 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
|
|||
ALoad(fname);
|
||||
}
|
||||
}
|
||||
|
||||
// A menu item for the recent lua files menu was clicked.
|
||||
if(wParam >= LUA_FIRST_RECENT_FILE && wParam <= LUA_FIRST_RECENT_FILE + MAX_NUMBER_OF_LUA_RECENT_FILES - 1)
|
||||
{
|
||||
char*& fname = recent_lua[wParam - LUA_FIRST_RECENT_FILE];
|
||||
if(fname)
|
||||
{
|
||||
FCEU_LoadLuaCode(fname);
|
||||
}
|
||||
}
|
||||
switch(LOWORD(wParam))
|
||||
{
|
||||
//File Menu-------------------------------------------------------------
|
||||
|
@ -1621,9 +1748,11 @@ int CreateMainWindow()
|
|||
fceumenu = LoadMenu(fceu_hInstance,"FCEUMENU");
|
||||
|
||||
recentmenu = CreateMenu();
|
||||
recentluamenu = CreateMenu();
|
||||
|
||||
// Update recent files menu
|
||||
UpdateRMenu(recentmenu, recent_files, MENU_RECENT_FILES, MENU_FIRST_RECENT_FILE);
|
||||
UpdateLuaRMenu(recentluamenu, recent_lua, MENU_LUA_RECENT, LUA_FIRST_RECENT_FILE);
|
||||
|
||||
updateGameDependentMenus(0);
|
||||
if (MainWindow_wndx==-32000) MainWindow_wndx=0; //Just in case
|
||||
|
@ -1886,6 +2015,7 @@ void FCEUD_LuaRunFrom(void)
|
|||
ofn.lpstrInitialDir=initdir.c_str();
|
||||
if(GetOpenFileName( &ofn ))
|
||||
{
|
||||
AddRecentLuaFile(szFileName);
|
||||
FCEU_LoadLuaCode(szFileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ struct CreateMovieParameters
|
|||
};
|
||||
|
||||
extern char *recent_files[];
|
||||
extern char *recent_lua[];
|
||||
extern HWND pwindow;
|
||||
|
||||
void HideFWindow(int h);
|
||||
|
|
|
@ -41,6 +41,10 @@ extern "C"
|
|||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
extern void AddRecentLuaFile(const char *filename);
|
||||
#endif
|
||||
|
||||
struct LuaSaveState {
|
||||
std::string filename;
|
||||
memorystream *data;
|
||||
|
@ -1729,7 +1733,9 @@ int FCEU_LoadLuaCode(const char *filename) {
|
|||
lua_settop(L,0);
|
||||
return 0; // Oh shit.
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
AddRecentLuaFile(filename); //Add the filename to our recent lua menu
|
||||
#endif
|
||||
|
||||
// Get our function into it
|
||||
lua_xmove(L, thread, 1);
|
||||
|
|
Loading…
Reference in New Issue