# HG changeset patch # User Torsten # Date 1413121789 -7200 # Node ID d10c711a08d83ebd2647485c852fe2ae6d501a3a # Parent 54943eb0ce3751b330ba5ad1b281a515c31e12d4 add a drop down menu with the eol mode in the save-file-as-dialog * file-editor-tab.cc (save_file_as): add a combo box with the eol modes to the file dialog; (handle_combo_eol_current_index): new slot for changes in the combo box saving the current index in a class variable; (handle_save_file_as_answer, handle_save_file_as_answer_close): convert into the desired eol mode when it differs from the current one before saving * file-editor-tab.h: new slot for changes of the current index in the combo box, new class variable for saving the current index diff -r 54943eb0ce37 -r d10c711a08d8 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sat Oct 11 15:44:07 2014 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Oct 12 15:49:49 2014 +0200 @@ -1543,6 +1543,41 @@ // it had/has no effect on Windows, though) fileDialog->setOption(QFileDialog::DontUseNativeDialog, true); + // get the dialog's layout for adding extra elements + QGridLayout *dialog_layout = dynamic_cast (fileDialog->layout ()); + int rows = dialog_layout->rowCount (); + + // define a new grid layout with the extra elements + QGridLayout *extra = new QGridLayout (fileDialog); + QSpacerItem *spacer = new QSpacerItem (1,1,QSizePolicy::Expanding, + QSizePolicy::Fixed); + QFrame *separator = new QFrame (fileDialog); + separator->setFrameShape (QFrame::HLine); // horizontal line as separator + separator->setFrameStyle (QFrame::Sunken); + + // combo box for choosing new line ending chars + QLabel *label_eol = new QLabel (tr ("Line Endings:")); + QComboBox *combo_eol = new QComboBox (); + combo_eol->addItem ("Windows (CRLF)"); // ensure the same order as in + combo_eol->addItem ("Mac (CR)"); // the settings dialog + combo_eol->addItem ("Unix (LF)"); + _save_as_desired_eol = _edit_area->eolMode (); // init with current eol + combo_eol->setCurrentIndex (_save_as_desired_eol); + + // track changes in the combo box + connect (combo_eol, SIGNAL (currentIndexChanged (int)), + this, SLOT (handle_combo_eol_current_index (int))); + + // build the extra grid layout + extra->addWidget (separator,0,0,1,3); + extra->addWidget (label_eol,1,0); + extra->addWidget (combo_eol,1,1); + extra->addItem (spacer, 1,2); + + // and add the extra grid layout to the dialog's layout + dialog_layout->addLayout (extra,rows,0,1,dialog_layout->columnCount ()); + + if (valid_file_name ()) { fileDialog->selectFile (_file_name); @@ -1588,6 +1623,12 @@ show_dialog (fileDialog); } +void +file_editor_tab::handle_combo_eol_current_index (int index) +{ + _save_as_desired_eol = static_cast (index); +} + bool file_editor_tab::check_valid_identifier (QString file_name) { @@ -1615,6 +1656,9 @@ void file_editor_tab::handle_save_file_as_answer (const QString& saveFileName) { + if (_save_as_desired_eol != _edit_area->eolMode ()) + convert_eol (this,_save_as_desired_eol); + if (saveFileName == _file_name) { // same name as actual file, save it as "save" would do @@ -1633,6 +1677,13 @@ void file_editor_tab::handle_save_file_as_answer_close (const QString& saveFileName) { + if (_save_as_desired_eol != _edit_area->eolMode ()) + { + _edit_area->setReadOnly (false); // was set to read-only in save_file_as + convert_eol (this,_save_as_desired_eol); + _edit_area->setReadOnly (true); // restore read-only mode + } + // saveFileName == _file_name can not happen, because we only can get here // when we close a tab and _file_name is not a valid file name yet diff -r 54943eb0ce37 -r d10c711a08d8 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sat Oct 11 15:44:07 2014 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Oct 12 15:49:49 2014 +0200 @@ -31,6 +31,7 @@ #include #include #include +#include #include "find-dialog.h" #include "octave-qscintilla.h" @@ -161,6 +162,7 @@ void handle_save_file_as_answer (const QString& fileName); void handle_save_file_as_answer_close (const QString& fileName); void handle_save_file_as_answer_cancel (); + void handle_combo_eol_current_index (int index); // When apis preparation has finished and is ready to save void save_apis_info (); @@ -222,6 +224,8 @@ QLabel *_col_indicator; QLabel *_eol_indicator; + QsciScintilla::EolMode _save_as_desired_eol; + QString _file_name; QString _file_name_short;