Mercurial > octave
changeset 29436:2c60e63ff1db stable
fix missing file suffix m when saving a new script (bug #60214)
* file-editor-tab.cc (handle_save_as_filter_selected): ignore spurious
filter selected signals;
(handle_save_file_as_answer): as workaround for Qt bug 59401, test if
a file suffix is missing although the dialog has a default suffix and add
the missing suffix
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sat, 13 Mar 2021 17:24:43 +0100 |
parents | d07e1eeceead |
children | c24e190ae34f |
files | libgui/src/m-editor/file-editor-tab.cc |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Fri Mar 12 19:11:26 2021 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat Mar 13 17:24:43 2021 +0100 @@ -2337,6 +2337,7 @@ fileDialog->setDirectory (m_ced); // propose a name corresponding to the function name + // if the new file contains a function QString fname = get_function_name (); if (! fname.isEmpty ()) fileDialog->selectFile (fname + ".m"); @@ -2373,6 +2374,12 @@ void file_editor_tab::handle_save_as_filter_selected (const QString& filter) { + // On some systems, the filterSelected signal is emitted without user + // action and with an empty filter string when the file dialog is shown. + // Just return in this case and do not remove the current default suffix. + if (filter.isEmpty ()) + return; + QFileDialog *file_dialog = qobject_cast<QFileDialog *> (sender ()); QRegExp rx ("\\*\\.([^ ^\\)]*)[ \\)]"); // regexp for suffix in filter @@ -2472,8 +2479,20 @@ return codec; } - void file_editor_tab::handle_save_file_as_answer (const QString& saveFileName) + void file_editor_tab::handle_save_file_as_answer (const QString& save_file_name) { + QString saveFileName = save_file_name; + QFileInfo file (saveFileName); + QFileDialog *file_dialog = qobject_cast<QFileDialog *> (sender ()); + + // Test if there is the file dialog should have added a default file + // suffix, but the selected file still has no suffix (see Qt bug + // https://bugreports.qt.io/browse/QTBUG-59401) + if ((! file_dialog->defaultSuffix ().isEmpty ()) && file.suffix ().isEmpty ()) + { + saveFileName = saveFileName + "." + file_dialog->defaultSuffix (); + } + if (m_save_as_desired_eol != m_edit_area->eolMode ()) convert_eol (this,m_save_as_desired_eol);