Mercurial > hg > octave-nkf
changeset 17903:de8591a19bc6
check for custom editor when opening a new file from the gui (bug #40496)
* file-editor.h: new functin call_custom_editor
* file-editor.cc (call_custom_editor): new function for checking preference and
call a custom editor if necessary
(request_new_file): try call_custom_editor before using internal editor
(request_open_file): try call_custom_editor before using internal editor
author | Torsten <ttl@justmail.de> |
---|---|
date | Tue, 12 Nov 2013 08:17:51 +0100 |
parents | 9bcf1614cd80 |
children | 817da22e58ed |
files | libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h |
diffstat | 2 files changed, 32 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -132,6 +132,11 @@ void file_editor::request_new_file (const QString& commands) { + // Custom editor? If yes, we can only call the editor without passing + // some initial contents and even without being sure a new file is opened + if (call_custom_editor ()) + return; + // New file isn't a file_editor_tab function since the file // editor tab has yet to be created and there is no object to // pass a signal to. Hence, functionality is here. @@ -236,23 +241,36 @@ return retval; } +bool +file_editor::call_custom_editor (const QString& file_name, int line) +{ + // Check if the user wants to use a custom file editor. + QSettings *settings = resource_manager::get_settings (); + + if (settings->value ("useCustomFileEditor").toBool ()) + { + QString editor = settings->value ("customFileEditor").toString (); + editor.replace ("%f", file_name); + editor.replace ("%l", QString::number (line)); + + QProcess::startDetached (editor); + + if (line < 0 && ! file_name.isEmpty ()) + handle_mru_add_file (QFileInfo (file_name).canonicalFilePath ()); + + return true; + } + + return false; +} + void file_editor::request_open_file (const QString& openFileName, int line, bool debug_pointer, bool breakpoint_marker, bool insert) { - // Check if the user wants to use a custom file editor. - QSettings *settings = resource_manager::get_settings (); - if (settings->value ("useCustomFileEditor").toBool ()) - { - QString editor = settings->value ("customFileEditor").toString (); - editor.replace ("%f", openFileName); - editor.replace ("%l", QString::number (line)); - QProcess::startDetached (editor); - if (line < 0) - handle_mru_add_file (QDir::cleanPath (openFileName)); - return; - } + if (call_custom_editor (openFileName, line)) + return; // custom editor called if (openFileName.isEmpty ()) { @@ -337,6 +355,7 @@ // File does not exist, should it be crated? QMessageBox *msgBox; int answer; + QSettings *settings = resource_manager::get_settings (); if (settings->value ("editor/create_new_file", false).toBool ()) { answer = QMessageBox::Yes;
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -186,6 +186,7 @@ void add_file_editor_tab (file_editor_tab *f, const QString& fn); void save_file_as (QWidget *fetabID = 0); void mru_menu_update (void); + bool call_custom_editor (const QString& file_name = QString (), int line = -1); QWidget *find_tab_widget (const QString& openFileName) const;