From eb18f22399675e7511f8e8e9f386ffb1223460a2 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Mon, 13 Jun 2011 21:15:54 +0000 Subject: [PATCH] implement File->Open Recent on MacOS --- Common/DefaultOptions.h | 10 +++---- Common/OpenFile.cpp | 2 +- Fltk/menuWindow.cpp | 58 +++++++++++++++++++----------------- benchmarks/iges/cube1000.geo | 5 ++++ 4 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index b599b10d7c..ffcbbf6934 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -62,15 +62,15 @@ StringXString GeneralOptions_String[] = { { F|S, "OptionsFileName" , opt_general_options_filename , ".gmsh-options" , "Option file created with `Tools->Options->Save'; automatically read on startup" }, - { F|S, "RecentFile1", opt_general_recent_file1 , "" , + { F|S, "RecentFile1", opt_general_recent_file1 , "untitled.geo" , "Most recent opened file"}, - { F|S, "RecentFile2", opt_general_recent_file2 , "" , + { F|S, "RecentFile2", opt_general_recent_file2 , "untitled.geo" , "2nd most recent opened file"}, - { F|S, "RecentFile3", opt_general_recent_file3 , "" , + { F|S, "RecentFile3", opt_general_recent_file3 , "untitled.geo" , "3rd most recent opened file"}, - { F|S, "RecentFile4", opt_general_recent_file4 , "" , + { F|S, "RecentFile4", opt_general_recent_file4 , "untitled.geo" , "4th most recent opened file"}, - { F|S, "RecentFile5", opt_general_recent_file5 , "" , + { F|S, "RecentFile5", opt_general_recent_file5 , "untitled.geo" , "5th most recent opened file"}, { 0, "SessionFileName" , opt_general_session_filename , ".gmshrc" , diff --git a/Common/OpenFile.cpp b/Common/OpenFile.cpp index 6e10a12314..cd38f56bf8 100644 --- a/Common/OpenFile.cpp +++ b/Common/OpenFile.cpp @@ -233,7 +233,7 @@ int MergeFile(std::string fileName, bool warnIfMissing) // contain binary data FILE *fp = fopen(fileName.c_str(), "rb"); if(!fp){ - if(warnIfMissing) + if(warnIfMissing) Msg::Warning("Unable to open file '%s'", fileName.c_str()); return 0; } diff --git a/Fltk/menuWindow.cpp b/Fltk/menuWindow.cpp index 14733eeb2c..b6e52e8674 100644 --- a/Fltk/menuWindow.cpp +++ b/Fltk/menuWindow.cpp @@ -149,9 +149,8 @@ static void file_merge_cb(Fl_Widget *w, void *data) } static 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(); @@ -2310,11 +2309,11 @@ static Fl_Menu_Item bar_table[] = { {"&New...", FL_CTRL+'n', (Fl_Callback *)file_new_cb, 0}, {"&Open...", FL_CTRL+'o', (Fl_Callback *)file_open_cb, 0}, {"Open Recent", 0, 0, 0, FL_SUBMENU}, - {"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, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, {0}, {"M&erge...", FL_CTRL+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0}, {"Watch Pattern...", 0, (Fl_Callback *)file_watch_cb, 0}, @@ -2369,15 +2368,16 @@ 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}, - /* system menu bar is not dynamic in fltk 1.1; it will be in fltk 1.3 + // system menu bar is not dynamic in fltk 1.1; it is in fltk 1.3 +#if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 3) {"Open Recent", 0, 0, 0, FL_SUBMENU}, - {"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, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, + {"", 0, (Fl_Callback *)file_open_recent_cb, 0}, {0}, - */ +#endif {"Merge...", FL_META+FL_SHIFT+'o', (Fl_Callback *)file_merge_cb, 0}, {"Watch Pattern...", 0, (Fl_Callback *)file_watch_cb, 0}, {"Clear", 0, (Fl_Callback *)file_clear_cb, 0, FL_MENU_DIVIDER}, @@ -2709,6 +2709,7 @@ menuWindow::menuWindow() sysbar = new Fl_Sys_Menu_Bar(1, 1, 1, 1); sysbar->menu(sysbar_table); sysbar->global(); + fillRecentHistoryMenu(); Fl_Box *o = new Fl_Box(0, 0, width, BH + 6); o->box(FL_UP_BOX); y = 3; @@ -2719,10 +2720,7 @@ menuWindow::menuWindow() bar->menu(bar_table); bar->box(FL_UP_BOX); bar->global(); - - // create recent history menu fillRecentHistoryMenu(); - Fl_Box *o = new Fl_Box(0, BH, width, BH + 6); o->box(FL_UP_BOX); y = BH + 3; @@ -2986,15 +2984,19 @@ void menuWindow::setContext(contextItem *menu_asked, int flag) 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(); + Fl_Menu_Item *table = bar_table; +#if defined(__APPLE__) && (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 3) + if(CTX::instance()->systemMenuBar) + table = sysbar_table; +#endif + + for(int i = 0; i < 5; i++){ + table[4 + i].text = CTX::instance()->recentFiles[i].c_str(); + table[4 + i].user_data_ = (void*)CTX::instance()->recentFiles[i].c_str(); + } + +#if defined(__APPLE__) && (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 3) + if(CTX::instance()->systemMenuBar) + sysbar->menu(table); +#endif } diff --git a/benchmarks/iges/cube1000.geo b/benchmarks/iges/cube1000.geo index 37c891ef1b..6fb9fc0e61 100644 --- a/benchmarks/iges/cube1000.geo +++ b/benchmarks/iges/cube1000.geo @@ -4,3 +4,8 @@ Merge "cube1000.igs"; Surface Loop(1) = {1:6}; Volume(1) = 1; + +Transfinite Line "*" = 10; +Transfinite Surface "*"; +Recombine Surface "*"; +Transfinite Volume "*"; -- GitLab