changeset 15993:41471c02d51c

gui: show menu with recently used editor files also in file menu of main window * file-editor-interface.h: new function get_mru_menu () * file-editor.h: new function get_mru_menu (), _mru_file_menu global * file-editor.cc (destructor): delete _mru_file_menu * file-editor.cc (set_focus): make editor visible before setting focus here * main-window.cc (focus_editor): and not here * file-editor.cc (request_new_file,request_open_file): set editor focus here * main-window.cc (new_file,open_file): and not here * main-window.cc (construct): add the editor's mru menu to the file menu
author Torsten <ttl@justmail.de>
date Sat, 02 Feb 2013 13:21:44 +0100
parents c4c46e1a086b
children 352ef2fb3ad1
files libgui/src/m-editor/file-editor-interface.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc
diffstat 4 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-interface.h	Sat Feb 02 09:17:26 2013 +0100
+++ b/libgui/src/m-editor/file-editor-interface.h	Sat Feb 02 13:21:44 2013 +0100
@@ -43,6 +43,7 @@
 
   virtual ~file_editor_interface () { }
 
+  virtual QMenu *get_mru_menu ( ) = 0;
   virtual QMenu *debug_menu () = 0;
   virtual QToolBar *toolbar () = 0;
 
--- a/libgui/src/m-editor/file-editor.cc	Sat Feb 02 09:17:26 2013 +0100
+++ b/libgui/src/m-editor/file-editor.cc	Sat Feb 02 13:21:44 2013 +0100
@@ -62,12 +62,17 @@
     }
   settings->setValue ("editor/savedSessionTabs", fetFileNames);
   settings->sync ();
+
+  if (_mru_file_menu)
+    delete _mru_file_menu;
 }
 
 // set focus to editor and its current tab
 void
 file_editor::set_focus ()
 {
+  if (!isVisible ())
+    setVisible (true);
   setFocus ();
   activateWindow ();
   raise ();
@@ -112,6 +117,7 @@
     {
       add_file_editor_tab (fileEditorTab, "");  // new tab with empty title
       fileEditorTab->new_file ();               // title is updated here
+      set_focus ();                             // focus editor and new tab
     }
 }
 
@@ -202,6 +208,7 @@
               msgBox->show ();
             }
         }
+      set_focus ();  // really show editor and the current editor tab
     }
 }
 
@@ -644,12 +651,12 @@
   fileMenu->addAction (save_action);
   fileMenu->addAction (save_as_action);
   fileMenu->addSeparator ();
-  QMenu *mru_file_menu = new QMenu (tr ("Open &Recent"), fileMenu);
+  _mru_file_menu = new QMenu (tr ("&Recent Editor Files"), fileMenu);
   for (int i = 0; i < MaxMRUFiles; ++i)
     {
-      mru_file_menu->addAction (_mru_file_actions[i]);
+      _mru_file_menu->addAction (_mru_file_actions[i]);
     }
-  fileMenu->addMenu (mru_file_menu);
+  fileMenu->addMenu (_mru_file_menu);
   _menu_bar->addMenu (fileMenu);
 
   QMenu *editMenu = new QMenu (tr ("&Edit"), _menu_bar);
--- a/libgui/src/m-editor/file-editor.h	Sat Feb 02 09:17:26 2013 +0100
+++ b/libgui/src/m-editor/file-editor.h	Sat Feb 02 13:21:44 2013 +0100
@@ -49,6 +49,7 @@
   ~file_editor ();
   void loadFile (const QString& fileName);
 
+  QMenu *           get_mru_menu ( ) { return _mru_file_menu; }
   QMenu *           debug_menu ();
   QToolBar *        toolbar ();
 
@@ -150,6 +151,7 @@
   int               _marker_breakpoint;
 
   enum { MaxMRUFiles = 10 };
+  QMenu *_mru_file_menu;
   QAction *_mru_file_actions[MaxMRUFiles];
   QStringList _mru_files;
 
--- a/libgui/src/main-window.cc	Sat Feb 02 09:17:26 2013 +0100
+++ b/libgui/src/main-window.cc	Sat Feb 02 13:21:44 2013 +0100
@@ -100,7 +100,6 @@
 {
 #ifdef HAVE_QSCINTILLA
   _file_editor->request_new_file ();
-  focus_editor ();
 #endif
 }
 
@@ -109,7 +108,6 @@
 {
 #ifdef HAVE_QSCINTILLA
   _file_editor->request_open_file ();
-  focus_editor ();
 #endif
 }
 
@@ -118,7 +116,6 @@
 {
 #ifdef HAVE_QSCINTILLA
   _file_editor->request_open_file (file_name);
-  focus_editor ();
 #endif
 }
 
@@ -404,10 +401,6 @@
 main_window::focus_editor ()
 {
 #ifdef HAVE_QSCINTILLA
-  if (!_file_editor->isVisible ())
-    {
-      _file_editor->setVisible (true);
-    }
   // call own function of editor in order to set focus to the current editor tab
   _file_editor->set_focus ();
 #endif
@@ -725,6 +718,9 @@
   QAction *open_action
     = file_menu->addAction (QIcon(":/actions/icons/fileopen.png"), tr ("Open..."));
   open_action->setShortcut (Qt::ControlModifier + Qt::Key_O);
+
+  file_menu->addMenu(_file_editor->get_mru_menu ());
+
   QAction *close_command_window_action
     = file_menu->addAction (tr ("Close Command Window"));
   close_command_window_action->setShortcut (Qt::ControlModifier + Qt::Key_W);