Mercurial > hg > octave-nkf
changeset 19024:0e6f7b5f6556 gui-release
propose function name as file name when saving a new file (bug #42568)
* file-editor-tab.cc (get_function_name): new function, get a possible
function name from the contents of the file;
(save_file_as): when saving a new file, try to detect the function name
by get_function_name and propose this name as file name
* file-editor-tab.h (get_function_name): new function
author | Torsten <ttl@justmail.de> |
---|---|
date | Mon, 16 Jun 2014 17:40:53 +0200 |
parents | 6504a1932637 |
children | 08d7dbd728bc |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h |
diffstat | 2 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -1324,6 +1324,11 @@ // constructor argument. fileDialog->setDirectory (_file_name); } + + // propose a name corresponding to the function name + QString fname = get_function_name (); + if (! fname.isEmpty ()) + fileDialog->selectFile (fname + ".m"); } fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); @@ -1739,4 +1744,26 @@ emit set_global_edit_shortcuts_signal (! focus); } +QString +file_editor_tab::get_function_name () +{ + QRegExp rxfun1 ("^([\t ]*)function([^=]+)=([^\\(]+)\\(([^\\)]*)\\)"); + QRegExp rxfun2 ("^([\t ]*)function([^\\(]+)\\(([^\\)]*)\\)"); + QRegExp rxfun3 ("^([\t ]*)function([\t ]*)([^\t ]+)"); + + QStringList lines = _edit_area->text ().split ("\n"); + + for (int i = 0; i < lines.count (); i++) + { + if (rxfun1.indexIn (lines.at (i)) != -1) + return rxfun1.cap (3).remove (QRegExp("[ \t]*")); + else if (rxfun2.indexIn (lines.at (i)) != -1) + return rxfun2.cap (2).remove (QRegExp("[ \t]*")); + else if (rxfun3.indexIn (lines.at (i)) != -1) + return rxfun3.cap (3).remove (QRegExp("[ \t]*")); + } + + return QString (); +} + #endif