Skip to content
Snippets Groups Projects
Commit 0a2909a0 authored by Bastien Gorissen's avatar Bastien Gorissen
Browse files

Add list of recently opened files in the GUI, closes ticket #18.

parent ae3ad7d5
No related branches found
No related tags found
No related merge requests found
...@@ -64,6 +64,9 @@ class CTX { ...@@ -64,6 +64,9 @@ class CTX {
std::string meshStatReportFileName; std::string meshStatReportFileName;
// the home directory // the home directory
std::string homeDir; std::string homeDir;
// file history
int history_size;
std::string recent_files[5];
// create mesh statistics report (0: do nothing, 1: create, 2: append) // create mesh statistics report (0: do nothing, 1: create, 2: append)
int createAppendMeshStatReport; int createAppendMeshStatReport;
// save session/option file on exit? // save session/option file on exit?
......
...@@ -60,6 +60,17 @@ StringXString GeneralOptions_String[] = { ...@@ -60,6 +60,17 @@ StringXString GeneralOptions_String[] = {
{ F|S, "OptionsFileName" , opt_general_options_filename , ".gmsh-options" , { F|S, "OptionsFileName" , opt_general_options_filename , ".gmsh-options" ,
"Option file created with `Tools->Options->Save'; automatically read on startup" }, "Option file created with `Tools->Options->Save'; automatically read on startup" },
{ F|S, "RecentFile1", opt_general_recent_file1 , "" ,
"Most recent opened file"},
{ F|S, "RecentFile2", opt_general_recent_file2 , "" ,
"2nd most recent opened file"},
{ F|S, "RecentFile3", opt_general_recent_file3 , "" ,
"3rd most recent opened file"},
{ F|S, "RecentFile4", opt_general_recent_file4 , "" ,
"4th most recent opened file"},
{ F|S, "RecentFile5", opt_general_recent_file5 , "" ,
"5th most recent opened file"},
{ 0, "SessionFileName" , opt_general_session_filename , ".gmshrc" , { 0, "SessionFileName" , opt_general_session_filename , ".gmshrc" ,
"Option file into which session specific information is saved; automatically " "Option file into which session specific information is saved; automatically "
"read on startup" }, "read on startup" },
...@@ -598,6 +609,9 @@ StringXNumber GeneralOptions_Number[] = { ...@@ -598,6 +609,9 @@ StringXNumber GeneralOptions_Number[] = {
{ F|S, "GraphicsWidth" , opt_general_graphics_size0 , 600. , { F|S, "GraphicsWidth" , opt_general_graphics_size0 , 600. ,
"Width (in pixels) of the graphic window" }, "Width (in pixels) of the graphic window" },
{ F|S, "HistorySize", opt_general_history_size , 0,
"Number of recently opened files in the menu"},
{ F|O, "InitialModule", opt_general_initial_context, 0. , { F|O, "InitialModule", opt_general_initial_context, 0. ,
"Module launched on startup (0=automatic, 1=geometry, 2=mesh, 3=solver, " "Module launched on startup (0=automatic, 1=geometry, 2=mesh, 3=solver, "
"4=post-processing) " }, "4=post-processing) " },
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "StringUtils.h" #include "StringUtils.h"
#include "GeomMeshMatcher.h" #include "GeomMeshMatcher.h"
#include "LuaBindings.h" #include "LuaBindings.h"
#include "menuWindow.h"
#if defined(HAVE_PARSER) #if defined(HAVE_PARSER)
#include "Parser.h" #include "Parser.h"
...@@ -450,11 +451,18 @@ void OpenProject(std::string fileName) ...@@ -450,11 +451,18 @@ void OpenProject(std::string fileName)
// temporary hack until we fill the current GModel on the fly during // temporary hack until we fill the current GModel on the fly during
// parsing // parsing
ResetTemporaryBoundingBox(); ResetTemporaryBoundingBox();
// merge the file // merge the file
MergeFile(fileName); if(MergeFile(fileName)) {
for (int i=4; i > 0; i--)
CTX::instance()->recent_files[i] = CTX::instance()->recent_files[i-1];
CTX::instance()->recent_files[0] = fileName;
if (CTX::instance()->history_size < 5)
CTX::instance()->history_size++;
FlGui::instance()->menu->fillRecentHistoryMenu();
}
CTX::instance()->lock = 0; CTX::instance()->lock = 0;
#if defined(HAVE_FLTK) #if defined(HAVE_FLTK)
......
...@@ -987,6 +987,41 @@ std::string opt_general_options_filename(OPT_ARGS_STR) ...@@ -987,6 +987,41 @@ std::string opt_general_options_filename(OPT_ARGS_STR)
return CTX::instance()->optionsFileName; return CTX::instance()->optionsFileName;
} }
std::string opt_general_recent_file1(OPT_ARGS_STR)
{
if(action & GMSH_SET)
CTX::instance()->recent_files[0] = val;
return CTX::instance()->recent_files[0];
}
std::string opt_general_recent_file2(OPT_ARGS_STR)
{
if(action & GMSH_SET)
CTX::instance()->recent_files[1] = val;
return CTX::instance()->recent_files[1];
}
std::string opt_general_recent_file3(OPT_ARGS_STR)
{
if(action & GMSH_SET)
CTX::instance()->recent_files[2] = val;
return CTX::instance()->recent_files[2];
}
std::string opt_general_recent_file4(OPT_ARGS_STR)
{
if(action & GMSH_SET)
CTX::instance()->recent_files[3] = val;
return CTX::instance()->recent_files[3];
}
std::string opt_general_recent_file5(OPT_ARGS_STR)
{
if(action & GMSH_SET)
CTX::instance()->recent_files[4] = val;
return CTX::instance()->recent_files[4];
}
std::string opt_general_editor(OPT_ARGS_STR) std::string opt_general_editor(OPT_ARGS_STR)
{ {
if(action & GMSH_SET) if(action & GMSH_SET)
...@@ -2495,6 +2530,14 @@ double opt_general_message_auto_scroll(OPT_ARGS_NUM) ...@@ -2495,6 +2530,14 @@ double opt_general_message_auto_scroll(OPT_ARGS_NUM)
return CTX::instance()->msgAutoScroll; return CTX::instance()->msgAutoScroll;
} }
double opt_general_history_size(OPT_ARGS_NUM)
{
if(action & GMSH_SET)
if ((int)val >= 0 && (int)val < 6)
CTX::instance()->history_size = (int)val;
return CTX::instance()->history_size;
}
double opt_general_option_position0(OPT_ARGS_NUM) double opt_general_option_position0(OPT_ARGS_NUM)
{ {
if(action & GMSH_SET) if(action & GMSH_SET)
......
...@@ -39,6 +39,11 @@ std::string opt_general_tmp_filename(OPT_ARGS_STR); ...@@ -39,6 +39,11 @@ std::string opt_general_tmp_filename(OPT_ARGS_STR);
std::string opt_general_error_filename(OPT_ARGS_STR); std::string opt_general_error_filename(OPT_ARGS_STR);
std::string opt_general_session_filename(OPT_ARGS_STR); std::string opt_general_session_filename(OPT_ARGS_STR);
std::string opt_general_options_filename(OPT_ARGS_STR); std::string opt_general_options_filename(OPT_ARGS_STR);
std::string opt_general_recent_file1(OPT_ARGS_STR);
std::string opt_general_recent_file2(OPT_ARGS_STR);
std::string opt_general_recent_file3(OPT_ARGS_STR);
std::string opt_general_recent_file4(OPT_ARGS_STR);
std::string opt_general_recent_file5(OPT_ARGS_STR);
std::string opt_general_editor(OPT_ARGS_STR); std::string opt_general_editor(OPT_ARGS_STR);
std::string opt_general_web_browser(OPT_ARGS_STR); std::string opt_general_web_browser(OPT_ARGS_STR);
std::string opt_general_gui_theme(OPT_ARGS_STR); std::string opt_general_gui_theme(OPT_ARGS_STR);
...@@ -243,6 +248,7 @@ double opt_general_message_position1(OPT_ARGS_NUM); ...@@ -243,6 +248,7 @@ double opt_general_message_position1(OPT_ARGS_NUM);
double opt_general_message_size0(OPT_ARGS_NUM); double opt_general_message_size0(OPT_ARGS_NUM);
double opt_general_message_size1(OPT_ARGS_NUM); double opt_general_message_size1(OPT_ARGS_NUM);
double opt_general_message_auto_scroll(OPT_ARGS_NUM); double opt_general_message_auto_scroll(OPT_ARGS_NUM);
double opt_general_history_size(OPT_ARGS_NUM);
double opt_general_option_position0(OPT_ARGS_NUM); double opt_general_option_position0(OPT_ARGS_NUM);
double opt_general_option_position1(OPT_ARGS_NUM); double opt_general_option_position1(OPT_ARGS_NUM);
double opt_general_plugin_position0(OPT_ARGS_NUM); double opt_general_plugin_position0(OPT_ARGS_NUM);
......
...@@ -231,7 +231,7 @@ FlGui::FlGui(int argc, char **argv) ...@@ -231,7 +231,7 @@ FlGui::FlGui(int argc, char **argv)
gmsh32x32, 32, 32)); gmsh32x32, 32, 32));
menu->win->icon menu->win->icon
((const char*)XCreateBitmapFromData(fl_display, DefaultRootWindow(fl_display), ((const char*)XCreateBitmapFromData(fl_display, DefaultRootWindow(fl_display),
gmsh32x32, 32, 32)); gmsh32x32, 32, 32));
#endif #endif
// open graphic window first for correct non-modal behaviour on // open graphic window first for correct non-modal behaviour on
......
...@@ -141,6 +141,17 @@ static void file_merge_cb(Fl_Widget *w, void *data) ...@@ -141,6 +141,17 @@ static void file_merge_cb(Fl_Widget *w, void *data)
FlGui::instance()->menu->setContext(menu_post, 0); FlGui::instance()->menu->setContext(menu_post, 0);
} }
void file_open_recent_cb(Fl_Widget *w, void *data)
{
std::string str((const char*)data);
int n = PView::list.size();
OpenProject(str);
drawContext::global()->draw();
if(n != (int)PView::list.size())
FlGui::instance()->menu->setContext(menu_post, 0);
}
static void file_clear_cb(Fl_Widget *w, void *data) static void file_clear_cb(Fl_Widget *w, void *data)
{ {
ClearProject(); ClearProject();
...@@ -2218,6 +2229,13 @@ static Fl_Menu_Item bar_table[] = { ...@@ -2218,6 +2229,13 @@ static Fl_Menu_Item bar_table[] = {
{"&New...", FL_CTRL+'n', (Fl_Callback *)file_new_cb, 0}, {"&New...", FL_CTRL+'n', (Fl_Callback *)file_new_cb, 0},
{"&Open...", FL_CTRL+'o', (Fl_Callback *)file_open_cb, 0}, {"&Open...", FL_CTRL+'o', (Fl_Callback *)file_open_cb, 0},
{"M&erge...", FL_CTRL+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0}, {"M&erge...", FL_CTRL+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0},
{"Open recent", 0, 0, 0, FL_SUBMENU},
{"History1", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History2", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History3", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History4", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History5", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{0},
{"&Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER}, {"&Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER},
{"Remote", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU}, {"Remote", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU},
{"Start...", 0, (Fl_Callback *)file_remote_cb, (void*)"start"}, {"Start...", 0, (Fl_Callback *)file_remote_cb, (void*)"start"},
...@@ -2271,6 +2289,13 @@ static Fl_Menu_Item sysbar_table[] = { ...@@ -2271,6 +2289,13 @@ static Fl_Menu_Item sysbar_table[] = {
{"Open...", FL_META+'o', (Fl_Callback *)file_open_cb, 0}, {"Open...", FL_META+'o', (Fl_Callback *)file_open_cb, 0},
{"Merge...", FL_META+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0}, {"Merge...", FL_META+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0},
{"Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER}, {"Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER},
{"Open recent", 0, 0, 0, FL_SUBMENU},
{"History1", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History2", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History3", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History4", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{"History5", 0,(Fl_Callback *)file_open_recent_cb, 0, FL_MENU_INVISIBLE},
{0},
{"Remote", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU}, {"Remote", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU},
{"Start...", 0, (Fl_Callback *)file_remote_cb, (void*)"start"}, {"Start...", 0, (Fl_Callback *)file_remote_cb, (void*)"start"},
{"Merge...", 0, (Fl_Callback *)file_remote_cb, (void*)"merge"}, {"Merge...", 0, (Fl_Callback *)file_remote_cb, (void*)"merge"},
...@@ -2598,6 +2623,10 @@ menuWindow::menuWindow() ...@@ -2598,6 +2623,10 @@ menuWindow::menuWindow()
bar->menu(bar_table); bar->menu(bar_table);
bar->box(FL_UP_BOX); bar->box(FL_UP_BOX);
bar->global(); bar->global();
// create recent history menu
fillRecentHistoryMenu();
Fl_Box *o = new Fl_Box(0, BH, width, BH + 6); Fl_Box *o = new Fl_Box(0, BH, width, BH + 6);
o->box(FL_UP_BOX); o->box(FL_UP_BOX);
y = BH + 3; y = BH + 3;
...@@ -2872,3 +2901,18 @@ void menuWindow::setContext(contextItem *menu_asked, int flag) ...@@ -2872,3 +2901,18 @@ void menuWindow::setContext(contextItem *menu_asked, int flag)
else else
win->size(width, _MH + NB_BUTT_SCROLL * BH); win->size(width, _MH + NB_BUTT_SCROLL * BH);
} }
void menuWindow::fillRecentHistoryMenu() {
for (int i = 0; i < CTX::instance()->history_size; i++){
#if defined(__APPLE__)
sysbar_table[i+5].text = (CTX::instance()->recent_files[i]).c_str();
sysbar_table[i+5].callback_ = (Fl_Callback *)file_open_recent_cb;
sysbar_table[i+5].user_data_ = (void*)(CTX::instance()->recent_files[i]).c_str();
sysbar_table[i+5].show();
#endif
bar_table[i+5].text = (CTX::instance()->recent_files[i]).c_str();
bar_table[i+5].callback_ = (Fl_Callback *)file_open_recent_cb;
bar_table[i+5].user_data_ = (void*)(CTX::instance()->recent_files[i]).c_str();
bar_table[i+5].show();
};
}
...@@ -72,9 +72,11 @@ class menuWindow{ ...@@ -72,9 +72,11 @@ class menuWindow{
std::vector<popupButton*> popup; std::vector<popupButton*> popup;
std::vector<popupButton*> popup2; std::vector<popupButton*> popup2;
std::vector<char*> label, label2; std::vector<char*> label, label2;
public: public:
menuWindow(); menuWindow();
void setContext(contextItem *menu_asked, int flag); void setContext(contextItem *menu_asked, int flag);
void fillRecentHistoryMenu();
}; };
void file_quit_cb(Fl_Widget *w, void *data); void file_quit_cb(Fl_Widget *w, void *data);
...@@ -88,5 +90,6 @@ void geometry_reload_cb(Fl_Widget *w, void *data); ...@@ -88,5 +90,6 @@ void geometry_reload_cb(Fl_Widget *w, void *data);
void mesh_1d_cb(Fl_Widget *w, void *data); void mesh_1d_cb(Fl_Widget *w, void *data);
void mesh_2d_cb(Fl_Widget *w, void *data); void mesh_2d_cb(Fl_Widget *w, void *data);
void mesh_3d_cb(Fl_Widget *w, void *data); void mesh_3d_cb(Fl_Widget *w, void *data);
void file_open_recent_cb(Fl_Widget *w, void *data);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment