From e0e1ecdcbb0fb34d927d74c03afabf11e7f24dbc Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 15 Jan 2010 16:17:55 +0000 Subject: [PATCH] improve bastien's recently opened file history (and disable on mac sys menu bar: it's not dynamic in fltk 1.1) --- Common/Context.cpp | 1 + Common/Context.h | 3 +-- Common/DefaultOptions.h | 3 --- Common/OpenFile.cpp | 10 ++++---- Common/Options.cpp | 28 ++++++++------------- Common/Options.h | 1 - Fltk/menuWindow.cpp | 54 +++++++++++++++++++++-------------------- Geo/GModel.cpp | 7 +++--- 8 files changed, 48 insertions(+), 59 deletions(-) diff --git a/Common/Context.cpp b/Common/Context.cpp index 67dfe899f9..6287edd277 100644 --- a/Common/Context.cpp +++ b/Common/Context.cpp @@ -79,6 +79,7 @@ CTX::CTX() hideUnselected = 0; numWindows = numTiles = 1; deltaFontSize = 0; + recentFiles.resize(5); } CTX *CTX::_instance = 0; diff --git a/Common/Context.h b/Common/Context.h index d8ccc0bacd..2f3faad624 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -65,8 +65,7 @@ class CTX { // the home directory std::string homeDir; // file history - int history_size; - std::string recent_files[5]; + std::vector<std::string> recentFiles; // create mesh statistics report (0: do nothing, 1: create, 2: append) int createAppendMeshStatReport; // save session/option file on exit? diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 218d733ff6..208f724bca 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -609,9 +609,6 @@ StringXNumber GeneralOptions_Number[] = { { F|S, "GraphicsWidth" , opt_general_graphics_size0 , 600. , "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. , "Module launched on startup (0=automatic, 1=geometry, 2=mesh, 3=solver, " "4=post-processing) " }, diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index a7da175b57..48cbf27ede 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -455,11 +455,11 @@ void OpenProject(std::string fileName) // merge the file 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++; + if(fileName != CTX::instance()->recentFiles.front()) + CTX::instance()->recentFiles.insert + (CTX::instance()->recentFiles.begin(), fileName); + if(CTX::instance()->recentFiles.size() > 5) + CTX::instance()->recentFiles.resize(5); #if defined(HAVE_FLTK) if(FlGui::available()) FlGui::instance()->menu->fillRecentHistoryMenu(); diff --git a/Common/Options.cpp b/Common/Options.cpp index e2a318bfed..2f8e5b23dd 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -990,36 +990,36 @@ std::string opt_general_options_filename(OPT_ARGS_STR) 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]; + CTX::instance()->recentFiles[0] = val; + return CTX::instance()->recentFiles[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]; + CTX::instance()->recentFiles[1] = val; + return CTX::instance()->recentFiles[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]; + CTX::instance()->recentFiles[2] = val; + return CTX::instance()->recentFiles[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]; + CTX::instance()->recentFiles[3] = val; + return CTX::instance()->recentFiles[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]; + CTX::instance()->recentFiles[4] = val; + return CTX::instance()->recentFiles[4]; } std::string opt_general_editor(OPT_ARGS_STR) @@ -2530,14 +2530,6 @@ double opt_general_message_auto_scroll(OPT_ARGS_NUM) 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) { if(action & GMSH_SET) diff --git a/Common/Options.h b/Common/Options.h index 7414368ff4..15bd46530a 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -248,7 +248,6 @@ double opt_general_message_position1(OPT_ARGS_NUM); double opt_general_message_size0(OPT_ARGS_NUM); double opt_general_message_size1(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_position1(OPT_ARGS_NUM); double opt_general_plugin_position0(OPT_ARGS_NUM); diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp index f148b3bd1e..9f791ddaad 100644 --- a/Fltk/menuWindow.cpp +++ b/Fltk/menuWindow.cpp @@ -2228,14 +2228,14 @@ static Fl_Menu_Item bar_table[] = { {"&File", 0, 0, 0, FL_SUBMENU}, {"&New...", FL_CTRL+'n', (Fl_Callback *)file_new_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}, {"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}, + {"History1", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History2", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History3", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History4", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History5", 0, 0, 0, FL_MENU_INVISIBLE}, {0}, + {"M&erge...", FL_CTRL+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0}, {"&Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER}, {"Remote", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU}, {"Start...", 0, (Fl_Callback *)file_remote_cb, (void*)"start"}, @@ -2287,15 +2287,17 @@ static Fl_Menu_Item sysbar_table[] = { {"File", 0, 0, 0, FL_SUBMENU}, {"New...", FL_META+'n', (Fl_Callback *)file_new_cb, 0}, {"Open...", FL_META+'o', (Fl_Callback *)file_open_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}, + /* system menu bar is not dynamic in fltk 1.1; it will be in fltk 1.3 {"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}, + {"History1", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History2", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History3", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History4", 0, 0, 0, FL_MENU_INVISIBLE}, + {"History5", 0, 0, 0, FL_MENU_INVISIBLE}, {0}, + */ + {"Merge...", FL_META+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0}, + {"Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER}, {"Remote", 0, 0, 0, FL_MENU_DIVIDER | FL_SUBMENU}, {"Start...", 0, (Fl_Callback *)file_remote_cb, (void*)"start"}, {"Merge...", 0, (Fl_Callback *)file_remote_cb, (void*)"merge"}, @@ -2902,17 +2904,17 @@ void menuWindow::setContext(contextItem *menu_asked, int flag) 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(); - }; +void menuWindow::fillRecentHistoryMenu() +{ + int last = 0; + for(unsigned int i = 0; i < CTX::instance()->recentFiles.size(); i++) + if(CTX::instance()->recentFiles[i].size()) last = i + 1; + for(int i = 0; i < last; i++){ + bar_table[4 + i].text = CTX::instance()->recentFiles[i].c_str(); + bar_table[4 + i].callback_ = (Fl_Callback *)file_open_recent_cb; + bar_table[4 + i].user_data_ = (void*)CTX::instance()->recentFiles[i].c_str(); + bar_table[4 + i].show(); + } + for (unsigned int i = last; i < 5; i++) + bar_table[4 + i].hide(); } diff --git a/Geo/GModel.cpp b/Geo/GModel.cpp index fa3958872d..74d614020c 100644 --- a/Geo/GModel.cpp +++ b/Geo/GModel.cpp @@ -1392,15 +1392,14 @@ void GModel::save(std::string fileName) GModel::setCurrent(temp); } - #include "Bindings.h" void GModel::registerBindings(binding *b) { classBinding *cb = b->addClass<GModel>("GModel"); methodBinding *cm; - cm = cb->addMethod("mesh",&GModel::mesh); - cm = cb->addMethod("load",&GModel::load); - cm = cb->addMethod("save",&GModel::save); + cm = cb->addMethod("mesh", &GModel::mesh); + cm = cb->addMethod("load", &GModel::load); + cm = cb->addMethod("save", &GModel::save); cm = cb->setConstructor<GModel>(); } -- GitLab