Mercurial > hg > octave-shane
changeset 16615:cb09eecbd84e
add close actions to the file menu of the editor
* file-editor.cc(consruct): new actions for close, close all and clos other
* file-editor.cc/.h
(request_close_file.request_close_all_files,request_close_other_files):
new slots for the new actions
author | Torsten <ttl@justmail.de> |
---|---|
date | Sun, 05 May 2013 16:34:11 +0200 |
parents | 49653ed9561b |
children | b383c8a22116 |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/module.mk libgui/src/resource.qrc |
diffstat | 4 files changed, 60 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -624,6 +624,36 @@ } void +file_editor::request_close_file (bool) +{ + emit fetab_close_request (_tab_widget->currentWidget ()); +} + +void +file_editor::request_close_all_files (bool) +{ + int index; + while ((index = _tab_widget->currentIndex ()) > -1) + emit fetab_close_request (_tab_widget->widget (index)); +} + +void +file_editor::request_close_other_files (bool) +{ + int index = 0; + QWidget *tabID = _tab_widget->currentWidget (); + + while (_tab_widget->count () > 1) + { + if (tabID != _tab_widget->widget (index)) + emit fetab_close_request (_tab_widget->widget (index)); + else + index++; + } +} + + +void file_editor::handle_tab_close_request (int index) { // Signal to the tabs a request to close whomever matches the identifying @@ -847,22 +877,40 @@ // menu bar QMenu *fileMenu = new QMenu (tr ("&File"), _menu_bar); - fileMenu->addAction (new_action); - fileMenu->addAction (open_action); - fileMenu->addAction (save_action); - fileMenu->addAction (save_as_action); - fileMenu->addSeparator (); + _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]); + fileMenu->addAction (new_action); + fileMenu->addAction (open_action); fileMenu->addMenu (_mru_file_menu); - _menu_bar->addMenu (fileMenu); + + fileMenu->addSeparator (); + fileMenu->addAction (save_action); + fileMenu->addAction (save_as_action); + + fileMenu->addSeparator (); + fileMenu->addAction (QIcon::fromTheme("window-close", + QIcon (":/actions/icons/fileclose.png")), + tr ("&Close"), + this, SLOT (request_close_file (bool)), + QKeySequence::Close); + fileMenu->addAction (QIcon::fromTheme("window-close", + QIcon (":/actions/icons/fileclose.png")), + tr ("Close All"), + this, SLOT (request_close_all_files (bool))); + fileMenu->addAction (QIcon::fromTheme("window-close", + QIcon (":/actions/icons/fileclose.png")), + tr ("Close Other Files"), + this, SLOT (request_close_other_files (bool))); fileMenu->addSeparator (); fileMenu->addAction (print_action); + _menu_bar->addMenu (fileMenu); + + QMenu *editMenu = new QMenu (tr ("&Edit"), _menu_bar); editMenu->addAction (undo_action); editMenu->addAction (redo_action);
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -105,6 +105,9 @@ void request_new_script (const QString& commands); void request_new_function (const QString& commands); void request_open_file (void); + void request_close_file (bool); + void request_close_all_files (bool); + void request_close_other_files (bool); void request_mru_open_file (QAction *action); void request_print_file (void);
--- a/libgui/src/module.mk +++ b/libgui/src/module.mk @@ -23,6 +23,7 @@ src/icons/editcut.png \ src/icons/editdelete.png \ src/icons/editpaste.png \ + src/icons/fileclose.png \ src/icons/filenew.png \ src/icons/fileopen.png \ src/icons/fileprint.png \
--- a/libgui/src/resource.qrc +++ b/libgui/src/resource.qrc @@ -5,6 +5,7 @@ <file>icons/editcut.png</file> <file>icons/editdelete.png</file> <file>icons/editpaste.png</file> + <file>icons/fileclose.png</file> <file>icons/filenew.png</file> <file>icons/fileopen.png</file> <file>icons/filesave.png</file>