comparison libgui/src/m-editor/file-editor-tab.cc @ 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
comparison
equal deleted inserted replaced
19023:6504a1932637 19024:0e6f7b5f6556
1322 { 1322 {
1323 // The file name is actually the directory name from the 1323 // The file name is actually the directory name from the
1324 // constructor argument. 1324 // constructor argument.
1325 fileDialog->setDirectory (_file_name); 1325 fileDialog->setDirectory (_file_name);
1326 } 1326 }
1327
1328 // propose a name corresponding to the function name
1329 QString fname = get_function_name ();
1330 if (! fname.isEmpty ())
1331 fileDialog->selectFile (fname + ".m");
1327 } 1332 }
1328 1333
1329 fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)")); 1334 fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*)"));
1330 fileDialog->setDefaultSuffix ("m"); 1335 fileDialog->setDefaultSuffix ("m");
1331 fileDialog->setAcceptMode (QFileDialog::AcceptSave); 1336 fileDialog->setAcceptMode (QFileDialog::AcceptSave);
1737 file_editor_tab::edit_area_has_focus (bool focus) 1742 file_editor_tab::edit_area_has_focus (bool focus)
1738 { 1743 {
1739 emit set_global_edit_shortcuts_signal (! focus); 1744 emit set_global_edit_shortcuts_signal (! focus);
1740 } 1745 }
1741 1746
1747 QString
1748 file_editor_tab::get_function_name ()
1749 {
1750 QRegExp rxfun1 ("^([\t ]*)function([^=]+)=([^\\(]+)\\(([^\\)]*)\\)");
1751 QRegExp rxfun2 ("^([\t ]*)function([^\\(]+)\\(([^\\)]*)\\)");
1752 QRegExp rxfun3 ("^([\t ]*)function([\t ]*)([^\t ]+)");
1753
1754 QStringList lines = _edit_area->text ().split ("\n");
1755
1756 for (int i = 0; i < lines.count (); i++)
1757 {
1758 if (rxfun1.indexIn (lines.at (i)) != -1)
1759 return rxfun1.cap (3).remove (QRegExp("[ \t]*"));
1760 else if (rxfun2.indexIn (lines.at (i)) != -1)
1761 return rxfun2.cap (2).remove (QRegExp("[ \t]*"));
1762 else if (rxfun3.indexIn (lines.at (i)) != -1)
1763 return rxfun3.cap (3).remove (QRegExp("[ \t]*"));
1764 }
1765
1766 return QString ();
1767 }
1768
1742 #endif 1769 #endif