# HG changeset patch # User John W. Eaton # Date 1366767805 14400 # Node ID 5fc1ce2947bd992421396f13aeea96c621f0d491 # Parent d50bca1cdc22372e899143563dc8ebacb9130471 style fixes * file-editor.h, file-editor.cc, file-editor-tab.h, file-editor-tab.cc: Style fixes. (file_editor_tab::editor_markers): Declare enum inside file_editor class instead of in global scope. diff --git a/libgui/src/files-dock-widget.cc b/libgui/src/files-dock-widget.cc --- a/libgui/src/files-dock-widget.cc +++ b/libgui/src/files-dock-widget.cc @@ -28,6 +28,8 @@ #include "files-dock-widget.h" #include +#include +#include #include #include #include @@ -289,7 +291,9 @@ if (is_octave_data_file (abs_fname.toStdString ())) emit load_file_signal (abs_fname); else - emit open_file (fileInfo.absoluteFilePath ()); + QDesktopServices::openUrl (QUrl::fromLocalFile (abs_fname)); + + // emit open_file (fileInfo.absoluteFilePath ()); } } } diff --git a/libgui/src/m-editor/file-editor-tab.cc b/libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -57,13 +57,17 @@ // Make parent null for the file editor tab so that warning // WindowModal messages don't affect grandparents. -file_editor_tab::file_editor_tab (QString directory) +file_editor_tab::file_editor_tab (const QString& directory_arg) { + QString directory = directory_arg; + // Make sure there is a slash at the end of the directory name // for identification when saved later. if (directory.count () && directory.at (directory.count () - 1) != '/') directory.append ("/"); + _file_name = directory; + _edit_area = new QsciScintilla (this); // Leave the find dialog box out of memory until requested. @@ -85,8 +89,8 @@ Qt::KeyboardModifiers))); // line numbers - _edit_area->setMarginsForegroundColor(QColor(96,96,96)); - _edit_area->setMarginsBackgroundColor(QColor(232,232,220)); + _edit_area->setMarginsForegroundColor (QColor (96, 96, 96)); + _edit_area->setMarginsBackgroundColor (QColor (232, 232, 220)); _edit_area->setMarginType (2, QsciScintilla::TextMargin); // code folding @@ -94,7 +98,7 @@ _edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3); //highlight current line color - _edit_area->setCaretLineBackgroundColor(QColor(245,245,245)); + _edit_area->setCaretLineBackgroundColor (QColor (245, 245, 245)); // other features _edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch); @@ -106,7 +110,7 @@ // auto completion _edit_area->autoCompleteFromAll (); - _edit_area->setAutoCompletionSource(QsciScintilla::AcsAll); + _edit_area->setAutoCompletionSource (QsciScintilla::AcsAll); QVBoxLayout *edit_area_layout = new QVBoxLayout (); edit_area_layout->addWidget (_edit_area); @@ -116,24 +120,26 @@ // connect modified signal connect (_edit_area, SIGNAL (modificationChanged (bool)), this, SLOT (update_window_title (bool))); + connect (_edit_area, SIGNAL (copyAvailable (bool)), this, SLOT (handle_copy_available (bool))); - connect (&_file_system_watcher, SIGNAL (fileChanged (QString)), - this, SLOT (file_has_changed (QString))); + + connect (&_file_system_watcher, SIGNAL (fileChanged (const QString&)), + this, SLOT (file_has_changed (const QString&))); QSettings *settings = resource_manager::get_settings (); if (settings) notice_settings (settings); } -file_editor_tab::~file_editor_tab () +file_editor_tab::~file_editor_tab (void) { // Destroy items attached to _edit_area. QsciLexer *lexer = _edit_area->lexer (); if (lexer) { delete lexer; - _edit_area->setLexer(0); + _edit_area->setLexer (0); } if (_find_dialog) { @@ -151,13 +157,9 @@ // ignore close event if file is not saved and user cancels // closing this window if (check_file_modified () == QMessageBox::Cancel) - { - e->ignore (); - } + e->ignore (); else - { - e->accept(); - } + e->accept (); } void @@ -181,7 +183,7 @@ } void -file_editor_tab::handle_margin_clicked(int margin, int line, +file_editor_tab::handle_margin_clicked (int margin, int line, Qt::KeyboardModifiers state) { if (margin == 1) @@ -191,9 +193,9 @@ if (state & Qt::ControlModifier) { if (markers_mask && (1 << bookmark)) - _edit_area->markerDelete(line,bookmark); + _edit_area->markerDelete (line, bookmark); else - _edit_area->markerAdd(line,bookmark); + _edit_area->markerAdd (line, bookmark); } else { @@ -253,7 +255,7 @@ // slot for fetab_set_focus: sets the focus to the current edit area void -file_editor_tab::set_focus (const QWidget* ID) +file_editor_tab::set_focus (const QWidget *ID) { if (ID != this) return; @@ -261,7 +263,7 @@ } void -file_editor_tab::undo (const QWidget* ID) +file_editor_tab::undo (const QWidget *ID) { if (ID != this) return; @@ -270,7 +272,7 @@ } void -file_editor_tab::redo (const QWidget* ID) +file_editor_tab::redo (const QWidget *ID) { if (ID != this) return; @@ -279,7 +281,7 @@ } void -file_editor_tab::copy (const QWidget* ID) +file_editor_tab::copy (const QWidget *ID) { if (ID != this) return; @@ -288,7 +290,7 @@ } void -file_editor_tab::cut (const QWidget* ID) +file_editor_tab::cut (const QWidget *ID) { if (ID != this) return; @@ -297,7 +299,7 @@ } void -file_editor_tab::paste (const QWidget* ID) +file_editor_tab::paste (const QWidget *ID) { if (ID != this) return; @@ -306,7 +308,7 @@ } void -file_editor_tab::save_file (const QWidget* ID) +file_editor_tab::save_file (const QWidget *ID) { if (ID != this) return; @@ -315,7 +317,8 @@ } void -file_editor_tab::save_file (const QWidget* ID, const QString& fileName, bool remove_on_success) +file_editor_tab::save_file (const QWidget *ID, const QString& fileName, + bool remove_on_success) { if (ID != this) return; @@ -324,7 +327,7 @@ } void -file_editor_tab::save_file_as (const QWidget* ID) +file_editor_tab::save_file_as (const QWidget *ID) { if (ID != this) return; @@ -333,19 +336,18 @@ } void -file_editor_tab::print_file (const QWidget* ID) +file_editor_tab::print_file (const QWidget *ID) { if (ID != this) return; - QsciPrinter * printer = new QsciPrinter( QPrinter::HighResolution ); + QsciPrinter *printer = new QsciPrinter (QPrinter::HighResolution); - QPrintDialog printDlg(printer, this); + QPrintDialog printDlg (printer, this); - if(printDlg.exec() == QDialog::Accepted) - { - printer->printRange(_edit_area); - } + if (printDlg.exec () == QDialog::Accepted) + printer->printRange (_edit_area); + delete printer; } @@ -357,7 +359,7 @@ } void -file_editor_tab::run_file (const QWidget* ID) +file_editor_tab::run_file (const QWidget *ID) { if (ID != this) return; @@ -372,7 +374,7 @@ // We have to cut off the suffix, because octave appends it. function_name.chop (file_info.suffix ().length () + 1); emit process_octave_code (QString ("cd \'%1\'\n%2\n") - .arg(path).arg (function_name)); + .arg (path).arg (function_name)); // TODO: Sending a run event crashes for long scripts. Find out why. // octave_link::post_event @@ -380,49 +382,56 @@ } void -file_editor_tab::toggle_bookmark (const QWidget* ID) +file_editor_tab::toggle_bookmark (const QWidget *ID) { if (ID != this) return; int line, cur; - _edit_area->getCursorPosition (&line,&cur); - if ( _edit_area->markersAtLine (line) && (1 << bookmark) ) + _edit_area->getCursorPosition (&line, &cur); + + if (_edit_area->markersAtLine (line) && (1 << bookmark)) _edit_area->markerDelete (line, bookmark); else _edit_area->markerAdd (line, bookmark); } void -file_editor_tab::next_bookmark (const QWidget* ID) +file_editor_tab::next_bookmark (const QWidget *ID) { if (ID != this) return; - int line, cur, nextline; + int line, cur; _edit_area->getCursorPosition (&line, &cur); - if ( _edit_area->markersAtLine (line) && (1 << bookmark) ) + + if (_edit_area->markersAtLine (line) && (1 << bookmark)) line++; // we have a breakpoint here, so start search from next line - nextline = _edit_area->markerFindNext (line, (1 << bookmark)); + + int nextline = _edit_area->markerFindNext (line, (1 << bookmark)); + _edit_area->setCursorPosition (nextline, 0); } void -file_editor_tab::previous_bookmark (const QWidget* ID) +file_editor_tab::previous_bookmark (const QWidget *ID) { if (ID != this) return; - int line, cur, prevline; + int line, cur; _edit_area->getCursorPosition (&line, &cur); - if ( _edit_area->markersAtLine (line) && (1 << bookmark) ) + + if (_edit_area->markersAtLine (line) && (1 << bookmark)) line--; // we have a breakpoint here, so start search from prev line - prevline = _edit_area->markerFindPrevious (line, (1 << bookmark)); + + int prevline = _edit_area->markerFindPrevious (line, (1 << bookmark)); + _edit_area->setCursorPosition (prevline, 0); } void -file_editor_tab::remove_bookmark (const QWidget* ID) +file_editor_tab::remove_bookmark (const QWidget *ID) { if (ID != this) return; @@ -555,49 +564,56 @@ } void -file_editor_tab::toggle_breakpoint (const QWidget* ID) +file_editor_tab::toggle_breakpoint (const QWidget *ID) { if (ID != this) return; int line, cur; _edit_area->getCursorPosition (&line, &cur); - if ( _edit_area->markersAtLine (line) && (1 << breakpoint) ) + + if (_edit_area->markersAtLine (line) && (1 << breakpoint)) request_remove_breakpoint (line); else request_add_breakpoint (line); } void -file_editor_tab::next_breakpoint (const QWidget* ID) +file_editor_tab::next_breakpoint (const QWidget *ID) { if (ID != this) return; - int line, cur, nextline; + int line, cur; _edit_area->getCursorPosition (&line, &cur); - if ( _edit_area->markersAtLine (line) && (1 << breakpoint) ) + + if (_edit_area->markersAtLine (line) && (1 << breakpoint)) line++; // we have a breakpoint here, so start search from next line - nextline = _edit_area->markerFindNext (line, (1 << breakpoint)); + + int nextline = _edit_area->markerFindNext (line, (1 << breakpoint)); + _edit_area->setCursorPosition (nextline, 0); } void -file_editor_tab::previous_breakpoint (const QWidget* ID) +file_editor_tab::previous_breakpoint (const QWidget *ID) { if (ID != this) return; int line, cur, prevline; _edit_area->getCursorPosition (&line, &cur); - if ( _edit_area->markersAtLine (line) && (1 << breakpoint) ) + + if (_edit_area->markersAtLine (line) && (1 << breakpoint)) line--; // we have a breakpoint here, so start search from prev line + prevline = _edit_area->markerFindPrevious (line, (1 << breakpoint)); + _edit_area->setCursorPosition (prevline, 0); } void -file_editor_tab::remove_all_breakpoints (const QWidget* ID) +file_editor_tab::remove_all_breakpoints (const QWidget *ID) { if (ID != this) return; @@ -616,7 +632,7 @@ } void -file_editor_tab::comment_selected_text (const QWidget* ID) +file_editor_tab::comment_selected_text (const QWidget *ID) { if (ID != this) return; @@ -625,7 +641,7 @@ } void -file_editor_tab::uncomment_selected_text (const QWidget* ID) +file_editor_tab::uncomment_selected_text (const QWidget *ID) { if (ID != this) return; @@ -643,7 +659,7 @@ } void -file_editor_tab::find (const QWidget* ID) +file_editor_tab::find (const QWidget *ID) { if (ID != this) return; @@ -658,7 +674,7 @@ if (!_find_dialog) { _find_dialog = new find_dialog (_edit_area, - qobject_cast(sender ())); + qobject_cast (sender ())); connect (_find_dialog, SIGNAL (finished (int)), this, SLOT (handle_find_dialog_finished (int))); _find_dialog->setWindowModality (Qt::NonModal); @@ -678,7 +694,7 @@ } void -file_editor_tab::goto_line (const QWidget* ID, int line) +file_editor_tab::goto_line (const QWidget *ID, int line) { if (ID != this) return; @@ -687,9 +703,10 @@ { bool ok = false; int index; - _edit_area->getCursorPosition(&line, &index); - line = QInputDialog::getInt (_edit_area, tr("Goto line"), tr("Line number"), - line+1, 1, _edit_area->lines(), 1, &ok); + _edit_area->getCursorPosition (&line, &index); + line = QInputDialog::getInt (_edit_area, tr ("Goto line"), + tr ("Line number"), line+1, 1, + _edit_area->lines (), 1, &ok); if (ok) { _edit_area->setCursorPosition (line-1, 0); @@ -697,36 +714,38 @@ } } else // go to given line without dialog - { - _edit_area->setCursorPosition (line-1, 0); - } + _edit_area->setCursorPosition (line-1, 0); } void file_editor_tab::do_comment_selected_text (bool comment) { - if ( _edit_area->hasSelectedText() ) + if (_edit_area->hasSelectedText ()) { - int lineFrom, lineTo, colFrom, colTo, i; - _edit_area->getSelection (&lineFrom,&colFrom,&lineTo,&colTo); - if ( colTo == 0 ) // the beginning of last line is not selected + int lineFrom, lineTo, colFrom, colTo; + _edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo); + + if (colTo == 0) // the beginning of last line is not selected lineTo--; // stop at line above + _edit_area->beginUndoAction (); - for ( i=lineFrom; i<=lineTo; i++ ) + + for (int i = lineFrom; i <= lineTo; i++) { - if ( comment ) - _edit_area->insertAt("%",i,0); + if (comment) + _edit_area->insertAt ("%", i, 0); else { - QString line(_edit_area->text(i)); - if ( line.startsWith("%") ) + QString line (_edit_area->text (i)); + if (line.startsWith ("%")) { - _edit_area->setSelection(i,0,i,1); - _edit_area->removeSelectedText(); + _edit_area->setSelection (i, 0, i, 1); + _edit_area->removeSelectedText (); } } } + _edit_area->endUndoAction (); } } @@ -736,30 +755,29 @@ { QString title (""); QString tooltip (""); + if (_file_name.isEmpty () || _file_name.at (_file_name.count () - 1) == '/') - title = tr(""); + title = tr (""); else { - if ( _long_title ) + if (_long_title) title = _file_name; else { - QFileInfo file(_file_name); - title = file.fileName(); + QFileInfo file (_file_name); + title = file.fileName (); tooltip = _file_name; } } - if ( modified ) - { - emit file_name_changed (title.prepend("* "), tooltip); - } + if (modified) + emit file_name_changed (title.prepend ("* "), tooltip); else emit file_name_changed (title, tooltip); } void -file_editor_tab::handle_copy_available(bool enableCopy) +file_editor_tab::handle_copy_available (bool enableCopy) { _copy_available = enableCopy; emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name)); @@ -774,14 +792,15 @@ // File is modified but not saved, ask user what to do. The file // editor tab can't be made parent because it may be deleted depending // upon the response. Instead, change the _edit_area to read only. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Warning, tr ("Octave Editor"), - tr ("The file\n" - "%1\n" - "is about to be closed but has been modified.\n" - "Do you want to cancel closing, save or discard the changes?"). - arg (_file_name), - QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard, 0); + QMessageBox* msgBox + = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), + tr ("The file\n" + "%1\n" + "is about to be closed but has been modified.\n" + "Do you want to cancel closing, save or discard the changes?"). + arg (_file_name), + QMessageBox::Save | QMessageBox::Cancel | QMessageBox::Discard, 0); + msgBox->setDefaultButton (QMessageBox::Save); _edit_area->setReadOnly (true); connect (msgBox, SIGNAL (finished (int)), @@ -789,7 +808,8 @@ msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); - return (QMessageBox::Cancel); + + return QMessageBox::Cancel; } else { @@ -797,7 +817,7 @@ emit tab_remove_request (); } - return (decision); + return decision; } void @@ -827,13 +847,11 @@ } QString -file_editor_tab::load_file(const QString& fileName) +file_editor_tab::load_file (const QString& fileName) { QFile file (fileName); if (!file.open (QFile::ReadOnly)) - { - return file.errorString (); - } + return file.errorString (); QTextStream in (&file); QApplication::setOverrideCursor (Qt::WaitCursor); @@ -860,7 +878,8 @@ { // If it is a new file with no name, signal that saveFileAs // should be performed. - if (saveFileName.isEmpty () || saveFileName.at (saveFileName.count () - 1) == '/') + if (saveFileName.isEmpty () + || saveFileName.at (saveFileName.count () - 1) == '/') { save_file_as (remove_on_success); return; @@ -881,14 +900,16 @@ _file_system_watcher.addPath (saveFileName); // Create a NonModal message about error. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Critical, tr ("Octave Editor"), - tr ("Could not open file %1 for write:\n%2."). - arg (saveFileName).arg (file.errorString ()), - QMessageBox::Ok, 0); + QMessageBox* msgBox + = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Could not open file %1 for write:\n%2."). + arg (saveFileName).arg (file.errorString ()), + QMessageBox::Ok, 0); msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); + return; } @@ -897,12 +918,14 @@ QApplication::setOverrideCursor (Qt::WaitCursor); out << _edit_area->text (); QApplication::restoreOverrideCursor (); - file.close(); + file.close (); // save file name after closing file as set_file_name starts watching again set_file_name (saveFileName); + // set the window title to actual file name (not modified) update_window_title (false); + // files is save -> not modified _edit_area->setModified (false); @@ -939,10 +962,9 @@ else { fileDialog->selectFile (""); + if (_file_name.isEmpty ()) - { - fileDialog->setDirectory (QDir::currentPath ()); - } + fileDialog->setDirectory (QDir::currentPath ()); else { // The file name is actually the directory name from the @@ -950,14 +972,17 @@ fileDialog->setDirectory (_file_name); } } - fileDialog->setNameFilter (tr("Octave Files (*.m);;All Files (*.*)")); + + fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*.*)")); fileDialog->setDefaultSuffix ("m"); fileDialog->setAcceptMode (QFileDialog::AcceptSave); fileDialog->setViewMode (QFileDialog::Detail); + if (remove_on_success) { connect (fileDialog, SIGNAL (fileSelected (const QString&)), this, SLOT (handle_save_file_as_answer_close (const QString&))); + connect (fileDialog, SIGNAL (rejected ()), this, SLOT (handle_save_file_as_answer_cancel ())); } @@ -966,6 +991,7 @@ connect (fileDialog, SIGNAL (fileSelected (const QString&)), this, SLOT (handle_save_file_as_answer (const QString&))); } + fileDialog->setWindowModality (Qt::WindowModal); fileDialog->setAttribute (Qt::WA_DeleteOnClose); fileDialog->show (); @@ -979,12 +1005,13 @@ // selected the same name not intending to overwrite. // Create a NonModal message about error. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Critical, tr ("Octave Editor"), - tr ("File not saved! The selected file name\n%1\n" - "is the same as the current file name"). - arg (saveFileName), - QMessageBox::Ok, 0); + QMessageBox* msgBox + = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), + tr ("File not saved! The selected file name\n%1\n" + "is the same as the current file name"). + arg (saveFileName), + QMessageBox::Ok, 0); + msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); @@ -1043,12 +1070,16 @@ { // Create a WindowModal message that blocks the edit area // by making _edit_area parent. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Warning, tr ("Octave Editor"), - tr ("It seems that \'%1\' has been modified by another application. Do you want to reload it?"). - arg (_file_name), QMessageBox::Yes | QMessageBox::No, this); + QMessageBox* msgBox + = new QMessageBox (QMessageBox::Warning, + tr ("Octave Editor"), + tr ("It seems that \'%1\' has been modified by another application. Do you want to reload it?"). + arg (_file_name), + QMessageBox::Yes | QMessageBox::No, this); + connect (msgBox, SIGNAL (finished (int)), this, SLOT (handle_file_reload_answer (int))); + msgBox->setWindowModality (Qt::WindowModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); @@ -1058,19 +1089,23 @@ QString modified = ""; if (_edit_area->isModified ()) modified = tr ("\n\nWarning: The contents in the editor is modified!"); + // Create a WindowModal message. The file editor tab can't be made // parent because it may be deleted depending upon the response. // Instead, change the _edit_area to read only. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Warning, tr ("Octave Editor"), - tr ("It seems that the file\n" - "%1\n" - "has been deleted or renamed. Do you want to save it now?%2"). - arg (_file_name).arg (modified), - QMessageBox::Save | QMessageBox::Close, 0); + QMessageBox* msgBox + = new QMessageBox (QMessageBox::Warning, tr ("Octave Editor"), + tr ("It seems that the file\n" + "%1\n" + "has been deleted or renamed. Do you want to save it now?%2"). + arg (_file_name).arg (modified), + QMessageBox::Save | QMessageBox::Close, 0); + _edit_area->setReadOnly (true); + connect (msgBox, SIGNAL (finished (int)), this, SLOT (handle_file_resave_answer (int))); + msgBox->setWindowModality (Qt::WindowModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); @@ -1083,33 +1118,35 @@ // QSettings pointer is checked before emitting. update_lexer (); + QFontMetrics lexer_font_metrics (_edit_area->lexer ()->defaultFont (0)); - _edit_area->setCaretLineVisible(settings->value ("editor/highlightCurrentLine",true).toBool ()); + _edit_area->setCaretLineVisible + (settings->value ("editor/highlightCurrentLine", true).toBool ()); - if (settings->value ("editor/codeCompletion",true).toBool ()) + if (settings->value ("editor/codeCompletion", true).toBool ()) _edit_area->setAutoCompletionThreshold (1); else _edit_area->setAutoCompletionThreshold (-1); - if (settings->value ("editor/showLineNumbers",true).toBool ()) + if (settings->value ("editor/showLineNumbers", true).toBool ()) { _edit_area->setMarginLineNumbers (2, true); - _edit_area->setMarginWidth(2, lexer_font_metrics.width("9999")); + _edit_area->setMarginWidth (2, lexer_font_metrics.width ("9999")); } else { _edit_area->setMarginLineNumbers (2, false); - _edit_area->setMarginWidth(2, 0); + _edit_area->setMarginWidth (2, 0); } - _long_title = settings->value ("editor/longWindowTitle",false).toBool (); + _long_title = settings->value ("editor/longWindowTitle", false).toBool (); update_window_title (false); } void -file_editor_tab::conditional_close (const QWidget* ID) +file_editor_tab::conditional_close (const QWidget *ID) { if (ID != this) return; @@ -1118,7 +1155,7 @@ } void -file_editor_tab::change_editor_state (const QWidget* ID) +file_editor_tab::change_editor_state (const QWidget *ID) { if (ID != this) { @@ -1139,11 +1176,12 @@ _find_dialog->setGeometry (_find_dialog_geometry); _find_dialog->show (); } + emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name)); } void -file_editor_tab::file_name_query (const QWidget* ID) +file_editor_tab::file_name_query (const QWidget *ID) { // A zero (null pointer) means that all file editor tabs // should respond, otherwise just the desired file editor tab. @@ -1159,11 +1197,13 @@ file_editor_tab::handle_file_reload_answer (int decision) { if (decision == QMessageBox::Yes) - { // reload: file is readded to the file watcher in set_file_name () + { + // reload: file is readded to the file watcher in set_file_name () load_file (_file_name); } else - { // do not reload: readd to the file watche + { + // do not reload: readd to the file watche _file_system_watcher.addPath (_file_name); } } @@ -1230,14 +1270,17 @@ void file_editor_tab::center_current_line () { - long int visible_lines = _edit_area->SendScintilla - (QsciScintillaBase::SCI_LINESONSCREEN); + long int visible_lines + = _edit_area->SendScintilla (QsciScintillaBase::SCI_LINESONSCREEN); + if (visible_lines > 2) { int line, index; - _edit_area->getCursorPosition(&line,&index); + _edit_area->getCursorPosition (&line, &index); + int first_line = _edit_area->firstVisibleLine (); first_line = first_line + (line - first_line - (visible_lines-1)/2); + _edit_area->setFirstVisibleLine (first_line); } } diff --git a/libgui/src/m-editor/file-editor-tab.h b/libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -20,64 +20,75 @@ */ -#ifndef FILEEDITORTAB_H -#define FILEEDITORTAB_H +#if !defined (file_editor_tab_h) +#define file_editor_tab_h 1 -#include #include #include #include #include +#include + #include "find-dialog.h" class file_editor; + class file_editor_tab : public QWidget { Q_OBJECT - public: - file_editor_tab (QString directory = ""); - ~file_editor_tab (); + +public: + + file_editor_tab (const QString& directory = ""); + + ~file_editor_tab (void); public slots: - void update_window_title(bool modified); - void handle_copy_available(bool enableCopy); - void handle_margin_clicked (int line, int margin, Qt::KeyboardModifiers state); - /** Tells the editor tab to react on changed settings. */ + void update_window_title (bool modified); + void handle_copy_available (bool enableCopy); + void handle_margin_clicked (int line, int margin, + Qt::KeyboardModifiers state); + + // Tells the editor tab to react on changed settings. void notice_settings (const QSettings *settings); - /** Will initiate close if associated with the identifier tag. */ - void conditional_close (const QWidget* ID); - /** Change to a different editor tab by identifier tag. */ - void change_editor_state (const QWidget* ID); - /** Simply transmit file name. */ - void file_name_query (const QWidget* ID); + + // Will initiate close if associated with the identifier tag. + void conditional_close (const QWidget *ID); + + // Change to a different editor tab by identifier tag. + void change_editor_state (const QWidget *ID); + + // Simply transmit file name. + void file_name_query (const QWidget *ID); - void set_focus (const QWidget* ID); - void undo (const QWidget* ID); - void redo (const QWidget* ID); - void copy (const QWidget* ID); - void cut (const QWidget* ID); - void paste (const QWidget* ID); - void save_file (const QWidget* ID); - void save_file (const QWidget* ID, const QString& fileName, bool remove_on_success); - void save_file_as (const QWidget* ID); - void print_file (const QWidget* ID); - void run_file (const QWidget* ID); - void toggle_bookmark (const QWidget* ID); - void next_bookmark (const QWidget* ID); - void previous_bookmark (const QWidget* ID); - void remove_bookmark (const QWidget* ID); + void set_focus (const QWidget *ID); + void undo (const QWidget *ID); + void redo (const QWidget *ID); + void copy (const QWidget *ID); + void cut (const QWidget *ID); + void paste (const QWidget *ID); + void save_file (const QWidget *ID); + void save_file (const QWidget *ID, const QString& fileName, + bool remove_on_success); + void save_file_as (const QWidget *ID); + void print_file (const QWidget *ID); + void run_file (const QWidget *ID); + void toggle_bookmark (const QWidget *ID); + void next_bookmark (const QWidget *ID); + void previous_bookmark (const QWidget *ID); + void remove_bookmark (const QWidget *ID); - void toggle_breakpoint (const QWidget* ID); - void next_breakpoint (const QWidget* ID); - void previous_breakpoint (const QWidget* ID); - void remove_all_breakpoints (const QWidget* ID); + void toggle_breakpoint (const QWidget *ID); + void next_breakpoint (const QWidget *ID); + void previous_breakpoint (const QWidget *ID); + void remove_all_breakpoints (const QWidget *ID); - void comment_selected_text (const QWidget* ID); - void uncomment_selected_text (const QWidget* ID); - void find (const QWidget* ID); - void goto_line (const QWidget* ID, int line = -1); + void comment_selected_text (const QWidget *ID); + void uncomment_selected_text (const QWidget *ID); + void find (const QWidget *ID); + void goto_line (const QWidget *ID, int line = -1); void insert_debugger_pointer (const QWidget *ID, int line = -1); void delete_debugger_pointer (const QWidget *ID, int line = -1); @@ -92,34 +103,49 @@ void file_has_changed (const QString& fileName); signals: + void file_name_changed (const QString& fileName, const QString& toolTip); void editor_state_changed (bool copy_available, const QString& fileName); void tab_remove_request (); void add_filename_to_list (const QString&, QWidget *); void mru_add_file (const QString& file_name); - void editor_check_conflict_save (const QString& saveFileName, bool remove_on_success); + void editor_check_conflict_save (const QString& saveFileName, + bool remove_on_success); void process_octave_code (const QString& command); protected: + void closeEvent (QCloseEvent *event); void set_file_name (const QString& fileName); private slots: - /** When user closes message box for reload question. */ + + // When user closes message box for reload question. void handle_file_reload_answer (int decision); - /** When user closes message box for resave question. */ + + // When user closes message box for resave question. void handle_file_resave_answer (int decision); - /** When user closes message box for modified question. */ + + // When user closes message box for modified question. void handle_file_modified_answer (int decision); - /** When user closes find_dialog box. */ + + // When user closes find_dialog box. void handle_find_dialog_finished (int decision); - /** When user closes QFileDialog box. */ + + // When user closes QFileDialog box. 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 (); private: + enum editor_markers + { + bookmark, + breakpoint, + debugger_position + }; + struct bp_info { bp_info (const QString& f, const QString& p, const QString& fn, int l) @@ -153,19 +179,19 @@ void remove_all_breakpoints_callback (const bp_info& info); void center_current_line (); - QsciScintilla * _edit_area; + QsciScintilla *_edit_area; - QString _file_name; - QString _file_name_short; + QString _file_name; + QString _file_name_short; - bool _long_title; - bool _copy_available; + bool _long_title; + bool _copy_available; - QFileSystemWatcher _file_system_watcher; + QFileSystemWatcher _file_system_watcher; - find_dialog * _find_dialog; - bool _find_dialog_is_visible; - QRect _find_dialog_geometry; + find_dialog *_find_dialog; + bool _find_dialog_is_visible; + QRect _find_dialog_geometry; }; -#endif // FILEEDITORTAB_H +#endif diff --git a/libgui/src/m-editor/file-editor.cc b/libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -53,11 +53,13 @@ setVisible (false); } -file_editor::~file_editor () +file_editor::~file_editor (void) { QSettings *settings = resource_manager::get_settings (); + editor_tab_map.clear (); - if (settings->value ("editor/restoreSession",true).toBool ()) + + if (settings->value ("editor/restoreSession", true).toBool ()) { // Have all file editor tabs signal what their file names are. emit fetab_file_name_query (0); @@ -96,7 +98,7 @@ // set focus to editor and its current tab void -file_editor::set_focus () +file_editor::set_focus (void) { if (!isVisible ()) setVisible (true); @@ -109,13 +111,13 @@ } QMenu * -file_editor::debug_menu () +file_editor::debug_menu (void) { return _debug_menu; } QToolBar * -file_editor::toolbar () +file_editor::toolbar (void) { return _tool_bar; } @@ -149,20 +151,22 @@ } void -file_editor::request_open_file () +file_editor::request_open_file (void) { // Open 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. // Create a NonModal message. - QFileDialog* fileDialog = new QFileDialog (this); - fileDialog->setNameFilter (tr("Octave Files (*.m);;All Files (*.*)")); + QFileDialog *fileDialog = new QFileDialog (this); + fileDialog->setNameFilter (tr ("Octave Files (*.m);;All Files (*.*)")); fileDialog->setAcceptMode (QFileDialog::AcceptOpen); fileDialog->setViewMode (QFileDialog::Detail); fileDialog->setDirectory (ced); + connect (fileDialog, SIGNAL (fileSelected (const QString&)), this, SLOT (request_open_file (const QString&))); + fileDialog->setWindowModality (Qt::NonModal); fileDialog->setAttribute (Qt::WA_DeleteOnClose); fileDialog->show (); @@ -199,11 +203,11 @@ if (settings->value ("useCustomFileEditor").toBool ()) { QString editor = settings->value ("customFileEditor").toString (); - editor.replace ("%f",openFileName); - editor.replace ("%l",QString::number (line)); + editor.replace ("%f", openFileName); + editor.replace ("%l", QString::number (line)); QProcess::startDetached (editor); if (line < 0) - handle_mru_add_file(QDir::cleanPath (openFileName)); + handle_mru_add_file (QDir::cleanPath (openFileName)); return; } @@ -243,7 +247,7 @@ file_editor_tab *fileEditorTab = new file_editor_tab (); if (fileEditorTab) { - QString result = fileEditorTab->load_file(openFileName); + QString result = fileEditorTab->load_file (openFileName); if (result == "") { // Supply empty title then have the file_editor_tab update @@ -251,7 +255,7 @@ add_file_editor_tab (fileEditorTab, ""); fileEditorTab->update_window_title (false); // file already loaded, add file to mru list here - handle_mru_add_file(QDir::cleanPath (openFileName)); + handle_mru_add_file (QDir::cleanPath (openFileName)); if (line > 0) { @@ -269,11 +273,13 @@ { delete fileEditorTab; // Create a NonModal message about error. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Critical, tr ("Octave Editor"), - tr ("Could not open file %1 for read:\n%2."). - arg (openFileName).arg (result), - QMessageBox::Ok, 0); + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, + tr ("Octave Editor"), + tr ("Could not open file %1 for read:\n%2."). + arg (openFileName).arg (result), + QMessageBox::Ok, 0); + msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); @@ -288,9 +294,9 @@ // open a file from the mru list void -file_editor::request_mru_open_file () +file_editor::request_mru_open_file (void) { - QAction *action = qobject_cast(sender ()); + QAction *action = qobject_cast (sender ()); if (action) { request_open_file (action->data ().toString ()); @@ -318,12 +324,13 @@ // somewhat confusing to the user. For now, opt to do nothing. // Create a NonModal message about error. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Critical, tr ("Octave Editor"), - tr ("File not saved! A file with the selected name\n%1\n" - "is already open in the editor"). - arg (saveFileName), - QMessageBox::Ok, 0); + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), + tr ("File not saved! A file with the selected name\n%1\n" + "is already open in the editor"). + arg (saveFileName), + QMessageBox::Ok, 0); + msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); @@ -331,9 +338,10 @@ return; } - QObject* saveFileObject = sender (); - QWidget* saveFileWidget = 0; - for(int i = 0; i < _tab_widget->count (); i++) + QObject *saveFileObject = sender (); + QWidget *saveFileWidget = 0; + + for (int i = 0; i < _tab_widget->count (); i++) { if (_tab_widget->widget (i) == saveFileObject) { @@ -344,13 +352,15 @@ if (!saveFileWidget) { // Create a NonModal message about error. - QMessageBox* msgBox = new QMessageBox ( - QMessageBox::Critical, tr ("Octave Editor"), - tr ("The associated file editor tab has disappeared. It was likely closed by some means."), - QMessageBox::Ok, 0); + QMessageBox *msgBox + = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"), + tr ("The associated file editor tab has disappeared. It was likely closed by some means."), + QMessageBox::Ok, 0); + msgBox->setWindowModality (Qt::NonModal); msgBox->setAttribute (Qt::WA_DeleteOnClose); msgBox->show (); + return; } @@ -359,13 +369,15 @@ } void -file_editor::handle_insert_debugger_pointer_request (const QString& file, int line) +file_editor::handle_insert_debugger_pointer_request (const QString& file, + int line) { request_open_file (file, line, true); } void -file_editor::handle_delete_debugger_pointer_request (const QString& file, int line) +file_editor::handle_delete_debugger_pointer_request (const QString& file, + int line) { if (! file.isEmpty ()) { @@ -390,7 +402,8 @@ void file_editor::handle_update_breakpoint_marker_request (bool insert, - const QString& file, int line) + const QString& file, + int line) { request_open_file (file, line, false, true, insert); } @@ -402,128 +415,128 @@ } void -file_editor::request_undo () +file_editor::request_undo (void) { emit fetab_undo (_tab_widget->currentWidget ()); } void -file_editor::request_redo () +file_editor::request_redo (void) { emit fetab_redo (_tab_widget->currentWidget ()); } void -file_editor::request_copy () +file_editor::request_copy (void) { emit fetab_copy (_tab_widget->currentWidget ()); } void -file_editor::request_cut () +file_editor::request_cut (void) { emit fetab_cut (_tab_widget->currentWidget ()); } void -file_editor::request_paste () +file_editor::request_paste (void) { emit fetab_paste (_tab_widget->currentWidget ()); } void -file_editor::request_save_file () +file_editor::request_save_file (void) { emit fetab_save_file (_tab_widget->currentWidget ()); } void -file_editor::request_save_file_as () +file_editor::request_save_file_as (void) { emit fetab_save_file_as (_tab_widget->currentWidget ()); } void -file_editor::request_print_file () +file_editor::request_print_file (void) { emit fetab_print_file (_tab_widget->currentWidget ()); } void -file_editor::request_run_file () +file_editor::request_run_file (void) { emit fetab_run_file (_tab_widget->currentWidget ()); } void -file_editor::request_toggle_bookmark () +file_editor::request_toggle_bookmark (void) { emit fetab_toggle_bookmark (_tab_widget->currentWidget ()); } void -file_editor::request_next_bookmark () +file_editor::request_next_bookmark (void) { emit fetab_next_bookmark (_tab_widget->currentWidget ()); } void -file_editor::request_previous_bookmark () +file_editor::request_previous_bookmark (void) { emit fetab_previous_bookmark (_tab_widget->currentWidget ()); } void -file_editor::request_remove_bookmark () +file_editor::request_remove_bookmark (void) { emit fetab_remove_bookmark (_tab_widget->currentWidget ()); } void -file_editor::request_toggle_breakpoint () +file_editor::request_toggle_breakpoint (void) { emit fetab_toggle_breakpoint (_tab_widget->currentWidget ()); } void -file_editor::request_next_breakpoint () +file_editor::request_next_breakpoint (void) { emit fetab_next_breakpoint (_tab_widget->currentWidget ()); } void -file_editor::request_previous_breakpoint () +file_editor::request_previous_breakpoint (void) { emit fetab_previous_breakpoint (_tab_widget->currentWidget ()); } void -file_editor::request_remove_breakpoint () +file_editor::request_remove_breakpoint (void) { emit fetab_remove_all_breakpoints (_tab_widget->currentWidget ()); } void -file_editor::request_comment_selected_text () +file_editor::request_comment_selected_text (void) { emit fetab_comment_selected_text (_tab_widget->currentWidget ()); } void -file_editor::request_uncomment_selected_text () +file_editor::request_uncomment_selected_text (void) { emit fetab_uncomment_selected_text (_tab_widget->currentWidget ()); } void -file_editor::request_find () +file_editor::request_find (void) { emit fetab_find (_tab_widget->currentWidget ()); } void -file_editor::request_goto_line () +file_editor::request_goto_line (void) { emit fetab_goto_line (_tab_widget->currentWidget ()); } @@ -538,28 +551,33 @@ } void -file_editor::mru_menu_update () +file_editor::mru_menu_update (void) { - int num_files = qMin (_mru_files.size(), int (MaxMRUFiles)); + int num_files = qMin (_mru_files.size (), int (MaxMRUFiles)); + // configure and show active actions of mru-menu for (int i = 0; i < num_files; ++i) { - QString text = tr("&%1 %2"). + QString text = tr ("&%1 %2"). arg ((i+1) % int (MaxMRUFiles)).arg (_mru_files.at (i)); _mru_file_actions[i]->setText (text); _mru_file_actions[i]->setData (_mru_files.at (i)); _mru_file_actions[i]->setVisible (true); } + // hide unused mru-menu entries for (int j = num_files; j < MaxMRUFiles; ++j) _mru_file_actions[j]->setVisible (false); + // delete entries in string-list beyond MaxMRUFiles while (_mru_files.size () > MaxMRUFiles) _mru_files.removeLast (); + // save actual mru-list in settings QSettings *settings = resource_manager::get_settings (); + // FIXME -- what should happen if settings is 0? - settings->setValue ("editor/mru_file_list",_mru_files); + settings->setValue ("editor/mru_file_list", _mru_files); settings->sync (); } @@ -567,10 +585,10 @@ file_editor::handle_file_name_changed (const QString& fname, const QString& tip) { - QObject *fileEditorTab = sender(); + QObject *fileEditorTab = sender (); if (fileEditorTab) { - for(int i = 0; i < _tab_widget->count (); i++) + for (int i = 0; i < _tab_widget->count (); i++) { if (_tab_widget->widget (i) == fileEditorTab) { @@ -593,12 +611,12 @@ } void -file_editor::handle_tab_remove_request () +file_editor::handle_tab_remove_request (void) { - QObject *fileEditorTab = sender(); + QObject *fileEditorTab = sender (); if (fileEditorTab) { - for(int i = 0; i < _tab_widget->count (); i++) + for (int i = 0; i < _tab_widget->count (); i++) { if (_tab_widget->widget (i) == fileEditorTab) { @@ -624,25 +642,27 @@ } void -file_editor::handle_editor_state_changed (bool copy_available, const QString& file_name) +file_editor::handle_editor_state_changed (bool copy_available, + const QString& file_name) { // In case there is some scenario where traffic could be coming from // all the file editor tabs, just process info from the current active tab. - if (sender() == _tab_widget->currentWidget ()) + if (sender () == _tab_widget->currentWidget ()) { _copy_action->setEnabled (copy_available); _cut_action->setEnabled (copy_available); + if (!file_name.isEmpty ()) { ced = QDir::cleanPath (file_name); int lastslash = ced.lastIndexOf ('/'); + // Test against > 0 because if somehow the directory is "/" the // slash should be retained. Otherwise, last slash is removed. if (lastslash > 0 && lastslash != ced.count ()) - { - ced = ced.left (lastslash); - } + ced = ced.left (lastslash); } + setFocusProxy (_tab_widget->currentWidget ()); } } @@ -650,14 +670,14 @@ void file_editor::notice_settings (const QSettings *settings) { - int icon_size = settings->value ("toolbar_icon_size",24).toInt (); - _tool_bar->setIconSize (QSize (icon_size,icon_size)); + int icon_size = settings->value ("toolbar_icon_size", 24).toInt (); + _tool_bar->setIconSize (QSize (icon_size, icon_size)); // Relay signal to file editor tabs. emit fetab_settings_changed (settings); } void -file_editor::construct () +file_editor::construct (void) { QWidget *editor_widget = new QWidget (this); @@ -669,42 +689,50 @@ _tab_widget = new QTabWidget (editor_widget); _tab_widget->setTabsClosable (true); - QAction *new_action = new QAction (QIcon(":/actions/icons/filenew.png"), - tr("&New File"), _tool_bar); + QAction *new_action = new QAction (QIcon (":/actions/icons/filenew.png"), + tr ("&New File"), _tool_bar); - QAction *open_action = new QAction (QIcon(":/actions/icons/fileopen.png"), - tr("&Open File"), _tool_bar); + QAction *open_action = new QAction (QIcon (":/actions/icons/fileopen.png"), + tr ("&Open File"), _tool_bar); - QAction *save_action = new QAction (QIcon(":/actions/icons/filesave.png"), - tr("&Save File"), _tool_bar); + QAction *save_action = new QAction (QIcon (":/actions/icons/filesave.png"), + tr ("&Save File"), _tool_bar); QAction *save_as_action - = new QAction (QIcon(":/actions/icons/filesaveas.png"), - tr("Save File &As"), _tool_bar); + = new QAction (QIcon (":/actions/icons/filesaveas.png"), + tr ("Save File &As"), _tool_bar); QAction *print_action - = new QAction ( QIcon(":/actions/icons/fileprint.png"), + = new QAction ( QIcon (":/actions/icons/fileprint.png"), tr ("Print"), _tool_bar); - QAction *undo_action = new QAction (QIcon(":/actions/icons/undo.png"), - tr("&Undo"), _tool_bar); + QAction *undo_action = new QAction (QIcon (":/actions/icons/undo.png"), + tr ("&Undo"), _tool_bar); - QAction *redo_action = new QAction (QIcon(":/actions/icons/redo.png"), - tr("&Redo"), _tool_bar); + QAction *redo_action = new QAction (QIcon (":/actions/icons/redo.png"), + tr ("&Redo"), _tool_bar); - _copy_action = new QAction (QIcon(":/actions/icons/editcopy.png"), + _copy_action = new QAction (QIcon (":/actions/icons/editcopy.png"), tr ("&Copy"), _tool_bar); - _cut_action = new QAction (QIcon(":/actions/icons/editcut.png"), + _cut_action = new QAction (QIcon (":/actions/icons/editcut.png"), tr ("Cu&t"), _tool_bar); QAction *paste_action = new QAction (QIcon (":/actions/icons/editpaste.png"), - tr("Paste"), _tool_bar); - QAction *next_bookmark_action = new QAction (tr ("&Next Bookmark"),_tool_bar); - QAction *previous_bookmark_action = new QAction (tr ("Pre&vious Bookmark"),_tool_bar); - QAction *toggle_bookmark_action = new QAction (tr ("Toggle &Bookmark"),_tool_bar); - QAction *remove_bookmark_action = new QAction (tr ("&Remove All Bookmarks"),_tool_bar); + tr ("Paste"), _tool_bar); + + QAction *next_bookmark_action + = new QAction (tr ("&Next Bookmark"), _tool_bar); + + QAction *previous_bookmark_action + = new QAction (tr ("Pre&vious Bookmark"), _tool_bar); + + QAction *toggle_bookmark_action + = new QAction (tr ("Toggle &Bookmark"), _tool_bar); + + QAction *remove_bookmark_action + = new QAction (tr ("&Remove All Bookmarks"), _tool_bar); QAction *next_breakpoint_action = new QAction (QIcon (":/actions/icons/bp_next.png"), @@ -719,16 +747,19 @@ = new QAction (QIcon (":/actions/icons/bp_rm_all.png"), tr ("&Remove All breakpoints"), _tool_bar); - QAction *comment_selection_action = new QAction (tr ("&Comment Selected Text"),_tool_bar); - QAction *uncomment_selection_action = new QAction (tr ("&Uncomment Selected Text"),_tool_bar); + QAction *comment_selection_action + = new QAction (tr ("&Comment Selected Text"), _tool_bar); - QAction *find_action = new QAction (QIcon(":/actions/icons/search.png"), + QAction *uncomment_selection_action + = new QAction (tr ("&Uncomment Selected Text"), _tool_bar); + + QAction *find_action = new QAction (QIcon (":/actions/icons/search.png"), tr ("&Find and Replace"), _tool_bar); - _run_action = new QAction (QIcon(":/actions/icons/artsbuilderexecute.png"), - tr("Save File And Run"), _tool_bar); + _run_action = new QAction (QIcon (":/actions/icons/artsbuilderexecute.png"), + tr ("Save File And Run"), _tool_bar); - QAction *goto_line_action = new QAction (tr ("Go&to Line"), _tool_bar); + QAction *goto_line_action = new QAction (tr ("Go&to Line"), _tool_bar); // the mru-list and an empty array of actions QSettings *settings = resource_manager::get_settings (); @@ -741,32 +772,32 @@ } // some actions are disabled from the beginning - _copy_action->setEnabled(false); - _cut_action->setEnabled(false); - _run_action->setShortcut (Qt::ControlModifier+ Qt::Key_R); - _run_action->setShortcutContext (Qt::WindowShortcut); - save_action->setShortcut (QKeySequence::Save); - save_action->setShortcutContext (Qt::WindowShortcut); - save_as_action->setShortcut (QKeySequence::SaveAs); - save_as_action->setShortcutContext (Qt::WindowShortcut); + _copy_action->setEnabled (false); + _cut_action->setEnabled (false); + _run_action->setShortcut (Qt::ControlModifier+ Qt::Key_R); + _run_action->setShortcutContext (Qt::WindowShortcut); + save_action->setShortcut (QKeySequence::Save); + save_action->setShortcutContext (Qt::WindowShortcut); + save_as_action->setShortcut (QKeySequence::SaveAs); + save_as_action->setShortcutContext (Qt::WindowShortcut); - print_action->setShortcut (QKeySequence::Print); - print_action->setShortcutContext (Qt::WindowShortcut); + print_action->setShortcut (QKeySequence::Print); + print_action->setShortcutContext (Qt::WindowShortcut); - next_bookmark_action->setShortcut (Qt::Key_F2); - next_bookmark_action->setShortcutContext (Qt::WindowShortcut); - previous_bookmark_action->setShortcut (Qt::SHIFT + Qt::Key_F2); - previous_bookmark_action->setShortcutContext (Qt::WindowShortcut); - toggle_bookmark_action->setShortcut (Qt::Key_F7); - toggle_bookmark_action->setShortcutContext (Qt::WindowShortcut); - comment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_7); - comment_selection_action->setShortcutContext (Qt::WindowShortcut); - uncomment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_8); - uncomment_selection_action->setShortcutContext(Qt::WindowShortcut); - find_action->setShortcut (QKeySequence::Find); - find_action->setShortcutContext (Qt::WindowShortcut); - goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); - goto_line_action->setShortcutContext (Qt::WindowShortcut); + next_bookmark_action->setShortcut (Qt::Key_F2); + next_bookmark_action->setShortcutContext (Qt::WindowShortcut); + previous_bookmark_action->setShortcut (Qt::SHIFT + Qt::Key_F2); + previous_bookmark_action->setShortcutContext (Qt::WindowShortcut); + toggle_bookmark_action->setShortcut (Qt::Key_F7); + toggle_bookmark_action->setShortcutContext (Qt::WindowShortcut); + comment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_7); + comment_selection_action->setShortcutContext (Qt::WindowShortcut); + uncomment_selection_action->setShortcut (Qt::ControlModifier + Qt::Key_8); + uncomment_selection_action->setShortcutContext (Qt::WindowShortcut); + find_action->setShortcut (QKeySequence::Find); + find_action->setShortcutContext (Qt::WindowShortcut); + goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); + goto_line_action->setShortcutContext (Qt::WindowShortcut); // toolbar _tool_bar->addAction (new_action); @@ -774,7 +805,7 @@ _tool_bar->addAction (save_action); _tool_bar->addAction (save_as_action); _tool_bar->addSeparator (); - _tool_bar->addAction(print_action); + _tool_bar->addAction (print_action); _tool_bar->addSeparator (); _tool_bar->addAction (undo_action); _tool_bar->addAction (redo_action); @@ -798,10 +829,10 @@ fileMenu->addAction (save_as_action); fileMenu->addSeparator (); _mru_file_menu = new QMenu (tr ("&Recent Editor Files"), fileMenu); + for (int i = 0; i < MaxMRUFiles; ++i) - { - _mru_file_menu->addAction (_mru_file_actions[i]); - } + _mru_file_menu->addAction (_mru_file_actions[i]); + fileMenu->addMenu (_mru_file_menu); _menu_bar->addMenu (fileMenu); @@ -859,162 +890,226 @@ connect (parent (), SIGNAL (open_file_signal (const QString&)), this, SLOT (request_open_file (const QString&))); - connect (new_action, - SIGNAL (triggered ()), this, SLOT (request_new_file ())); - connect (open_action, - SIGNAL (triggered ()), this, SLOT (request_open_file ())); - connect (undo_action, - SIGNAL (triggered ()), this, SLOT (request_undo ())); - connect (redo_action, - SIGNAL (triggered ()), this, SLOT (request_redo ())); - connect (_copy_action, - SIGNAL (triggered ()), this, SLOT (request_copy ())); - connect (_cut_action, - SIGNAL (triggered ()), this, SLOT (request_cut ())); - connect (paste_action, - SIGNAL (triggered ()), this, SLOT (request_paste ())); - connect (save_action, - SIGNAL (triggered ()), this, SLOT (request_save_file ())); - connect (save_as_action, - SIGNAL (triggered ()), this, SLOT (request_save_file_as ())); - connect (print_action, - SIGNAL (triggered ()), this, SLOT (request_print_file ())); - connect (_run_action, - SIGNAL (triggered ()), this, SLOT (request_run_file ())); - connect (toggle_bookmark_action, - SIGNAL (triggered ()), this, SLOT (request_toggle_bookmark ())); - connect (next_bookmark_action, - SIGNAL (triggered ()), this, SLOT (request_next_bookmark ())); - connect (previous_bookmark_action, - SIGNAL (triggered ()), this, SLOT (request_previous_bookmark ())); - connect (remove_bookmark_action, - SIGNAL (triggered ()), this, SLOT (request_remove_bookmark ())); - connect (toggle_breakpoint_action, - SIGNAL (triggered ()), this, SLOT (request_toggle_breakpoint ())); - connect (next_breakpoint_action, - SIGNAL (triggered ()), this, SLOT (request_next_breakpoint ())); - connect (previous_breakpoint_action, - SIGNAL (triggered ()), this, SLOT (request_previous_breakpoint ())); - connect (remove_all_breakpoints_action, - SIGNAL (triggered ()), this, SLOT (request_remove_breakpoint ())); - connect (comment_selection_action, - SIGNAL (triggered ()), this, SLOT (request_comment_selected_text ())); - connect (uncomment_selection_action, - SIGNAL (triggered ()), this, SLOT (request_uncomment_selected_text ())); - connect (find_action, - SIGNAL (triggered ()), this, SLOT (request_find ())); + connect (new_action, SIGNAL (triggered ()), + this, SLOT (request_new_file ())); + + connect (open_action, SIGNAL (triggered ()), + this, SLOT (request_open_file ())); + + connect (undo_action, SIGNAL (triggered ()), + this, SLOT (request_undo ())); + + connect (redo_action, SIGNAL (triggered ()), + this, SLOT (request_redo ())); + + connect (_copy_action, SIGNAL (triggered ()), + this, SLOT (request_copy ())); + + connect (_cut_action, SIGNAL (triggered ()), + this, SLOT (request_cut ())); + + connect (paste_action, SIGNAL (triggered ()), + this, SLOT (request_paste ())); + + connect (save_action, SIGNAL (triggered ()), + this, SLOT (request_save_file ())); + + connect (save_as_action, SIGNAL (triggered ()), + this, SLOT (request_save_file_as ())); + + connect (print_action, SIGNAL (triggered ()), + this, SLOT (request_print_file ())); + + connect (_run_action, SIGNAL (triggered ()), + this, SLOT (request_run_file ())); - connect (goto_line_action, - SIGNAL (triggered ()), this, SLOT (request_goto_line ())); - + connect (toggle_bookmark_action, SIGNAL (triggered ()), + this, SLOT (request_toggle_bookmark ())); + + connect (next_bookmark_action, SIGNAL (triggered ()), + this, SLOT (request_next_bookmark ())); + + connect (previous_bookmark_action, SIGNAL (triggered ()), + this, SLOT (request_previous_bookmark ())); + + connect (remove_bookmark_action, SIGNAL (triggered ()), + this, SLOT (request_remove_bookmark ())); + + connect (toggle_breakpoint_action, SIGNAL (triggered ()), + this, SLOT (request_toggle_breakpoint ())); + + connect (next_breakpoint_action, SIGNAL (triggered ()), + this, SLOT (request_next_breakpoint ())); + + connect (previous_breakpoint_action, SIGNAL (triggered ()), + this, SLOT (request_previous_breakpoint ())); + + connect (remove_all_breakpoints_action, SIGNAL (triggered ()), + this, SLOT (request_remove_breakpoint ())); + + connect (comment_selection_action, SIGNAL (triggered ()), + this, SLOT (request_comment_selected_text ())); + + connect (uncomment_selection_action, SIGNAL (triggered ()), + this, SLOT (request_uncomment_selected_text ())); + + connect (find_action, SIGNAL (triggered ()), + this, SLOT (request_find ())); + + connect (goto_line_action, SIGNAL (triggered ()), + this, SLOT (request_goto_line ())); + // The actions of the mru file menu for (int i = 0; i < MaxMRUFiles; ++i) { - connect(_mru_file_actions[i], SIGNAL (triggered ()), this, SLOT (request_mru_open_file ())); + connect (_mru_file_actions[i], SIGNAL (triggered ()), + this, SLOT (request_mru_open_file ())); } + mru_menu_update (); - connect (_tab_widget, - SIGNAL (tabCloseRequested (int)), this, SLOT (handle_tab_close_request (int))); - connect (_tab_widget, - SIGNAL (currentChanged(int)), this, SLOT (active_tab_changed (int))); + + connect (_tab_widget, SIGNAL (tabCloseRequested (int)), + this, SLOT (handle_tab_close_request (int))); + + connect (_tab_widget, SIGNAL (currentChanged (int)), + this, SLOT (active_tab_changed (int))); resize (500, 400); - setWindowIcon (QIcon(":/actions/icons/logo.png")); + setWindowIcon (QIcon (":/actions/icons/logo.png")); setWindowTitle ("Editor"); //restore previous session - if (settings->value ("editor/restoreSession",true).toBool ()) + if (settings->value ("editor/restoreSession", true).toBool ()) { - QStringList sessionFileNames = settings->value("editor/savedSessionTabs", QStringList()).toStringList (); + QStringList sessionFileNames + = settings->value ("editor/savedSessionTabs", QStringList ()).toStringList (); - for (int n=0; n < sessionFileNames.count (); ++n) + for (int n = 0; n < sessionFileNames.count (); ++n) request_open_file (sessionFileNames.at (n)); } } void -file_editor::add_file_editor_tab (file_editor_tab *f, const QString &fn) +file_editor::add_file_editor_tab (file_editor_tab *f, const QString& fn) { _tab_widget->addTab (f, fn); // Signals from the file editor_tab connect (f, SIGNAL (file_name_changed (const QString&, const QString&)), - this, SLOT (handle_file_name_changed (const QString&, const QString&))); + this, SLOT (handle_file_name_changed (const QString&, + const QString&))); + connect (f, SIGNAL (editor_state_changed (bool, const QString&)), this, SLOT (handle_editor_state_changed (bool, const QString&))); + connect (f, SIGNAL (tab_remove_request ()), this, SLOT (handle_tab_remove_request ())); - connect (f, SIGNAL (add_filename_to_list (const QString&, QWidget *)), - this, SLOT (handle_add_filename_to_list (const QString&, QWidget *))); + + connect (f, SIGNAL (add_filename_to_list (const QString&, QWidget*)), + this, SLOT (handle_add_filename_to_list (const QString&, QWidget*))); + connect (f, SIGNAL (editor_check_conflict_save (const QString&, bool)), this, SLOT (check_conflict_save (const QString&, bool))); + connect (f, SIGNAL (mru_add_file (const QString&)), this, SLOT (handle_mru_add_file (const QString&))); + connect (f, SIGNAL (process_octave_code (const QString&)), parent (), SLOT (handle_command_double_clicked (const QString&))); // Signals from the file_editor non-trivial operations connect (this, SIGNAL (fetab_settings_changed (const QSettings *)), f, SLOT (notice_settings (const QSettings *))); + connect (this, SIGNAL (fetab_close_request (const QWidget*)), f, SLOT (conditional_close (const QWidget*))); + connect (this, SIGNAL (fetab_change_request (const QWidget*)), f, SLOT (change_editor_state (const QWidget*))); + connect (this, SIGNAL (fetab_file_name_query (const QWidget*)), f, SLOT (file_name_query (const QWidget*))); - connect (this, SIGNAL (fetab_save_file (const QWidget*, const QString&, bool)), + + connect (this, SIGNAL (fetab_save_file (const QWidget*, const QString&, + bool)), f, SLOT (save_file (const QWidget*, const QString&, bool))); + // Signals from the file_editor trivial operations connect (this, SIGNAL (fetab_undo (const QWidget*)), f, SLOT (undo (const QWidget*))); + connect (this, SIGNAL (fetab_redo (const QWidget*)), f, SLOT (redo (const QWidget*))); + connect (this, SIGNAL (fetab_copy (const QWidget*)), f, SLOT (copy (const QWidget*))); + connect (this, SIGNAL (fetab_cut (const QWidget*)), f, SLOT (cut (const QWidget*))); + connect (this, SIGNAL (fetab_paste (const QWidget*)), f, SLOT (paste (const QWidget*))); + connect (this, SIGNAL (fetab_save_file (const QWidget*)), f, SLOT (save_file (const QWidget*))); + connect (this, SIGNAL (fetab_save_file_as (const QWidget*)), f, SLOT (save_file_as (const QWidget*))); + connect (this, SIGNAL (fetab_print_file (const QWidget*)), f, SLOT (print_file (const QWidget*))); + connect (this, SIGNAL (fetab_run_file (const QWidget*)), f, SLOT (run_file (const QWidget*))); + connect (this, SIGNAL (fetab_toggle_bookmark (const QWidget*)), f, SLOT (toggle_bookmark (const QWidget*))); + connect (this, SIGNAL (fetab_next_bookmark (const QWidget*)), f, SLOT (next_bookmark (const QWidget*))); + connect (this, SIGNAL (fetab_previous_bookmark (const QWidget*)), f, SLOT (previous_bookmark (const QWidget*))); + connect (this, SIGNAL (fetab_remove_bookmark (const QWidget*)), f, SLOT (remove_bookmark (const QWidget*))); + connect (this, SIGNAL (fetab_toggle_breakpoint (const QWidget*)), f, SLOT (toggle_breakpoint (const QWidget*))); + connect (this, SIGNAL (fetab_next_breakpoint (const QWidget*)), f, SLOT (next_breakpoint (const QWidget*))); + connect (this, SIGNAL (fetab_previous_breakpoint (const QWidget*)), f, SLOT (previous_breakpoint (const QWidget*))); + connect (this, SIGNAL (fetab_remove_all_breakpoints (const QWidget*)), f, SLOT (remove_all_breakpoints (const QWidget*))); + connect (this, SIGNAL (fetab_comment_selected_text (const QWidget*)), f, SLOT (comment_selected_text (const QWidget*))); + connect (this, SIGNAL (fetab_uncomment_selected_text (const QWidget*)), f, SLOT (uncomment_selected_text (const QWidget*))); + connect (this, SIGNAL (fetab_find (const QWidget*)), f, SLOT (find (const QWidget*))); - connect (this, SIGNAL (fetab_goto_line (const QWidget *, int)), - f, SLOT (goto_line (const QWidget *, int))); + + connect (this, SIGNAL (fetab_goto_line (const QWidget*, int)), + f, SLOT (goto_line (const QWidget*, int))); + connect (this, SIGNAL (fetab_set_focus (const QWidget*)), f, SLOT (set_focus (const QWidget*))); - connect (this, SIGNAL (fetab_insert_debugger_pointer (const QWidget *, int)), - f, SLOT (insert_debugger_pointer (const QWidget *, int))); - connect (this, SIGNAL (fetab_delete_debugger_pointer (const QWidget *, int)), - f, SLOT (delete_debugger_pointer (const QWidget *, int))); - connect (this, SIGNAL (fetab_do_breakpoint_marker (bool, const QWidget *, int)), - f, SLOT (do_breakpoint_marker (bool, const QWidget *, int))); + + connect (this, SIGNAL (fetab_insert_debugger_pointer (const QWidget*, int)), + f, SLOT (insert_debugger_pointer (const QWidget*, int))); + + connect (this, SIGNAL (fetab_delete_debugger_pointer (const QWidget*, int)), + f, SLOT (delete_debugger_pointer (const QWidget*, int))); + + connect (this, SIGNAL (fetab_do_breakpoint_marker (bool, const QWidget*, + int)), + f, SLOT (do_breakpoint_marker (bool, const QWidget*, int))); _tab_widget->setCurrentWidget (f); } diff --git a/libgui/src/m-editor/file-editor.h b/libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -36,13 +36,6 @@ #include "file-editor-interface.h" #include "file-editor-tab.h" -enum editor_markers - { - bookmark, - breakpoint, - debugger_position - }; - class file_editor : public file_editor_interface { Q_OBJECT @@ -53,27 +46,29 @@ typedef std::map::const_iterator editor_tab_map_const_iterator; file_editor (QWidget *p); - ~file_editor (); + ~file_editor (void); void connect_visibility_changed (void); void loadFile (const QString& fileName); - QMenu * get_mru_menu ( ) { return _mru_file_menu; } - QMenu * debug_menu (); - QToolBar * toolbar (); + QMenu *get_mru_menu (void) { return _mru_file_menu; } + QMenu *debug_menu (void); + QToolBar *toolbar (void); - void set_focus (); + void set_focus (void); void handle_enter_debug_mode (void); void handle_exit_debug_mode (void); signals: + void fetab_settings_changed (const QSettings *settings); void fetab_close_request (const QWidget* ID); void fetab_change_request (const QWidget* ID); void fetab_file_name_query (const QWidget* ID); // Save is a ping-pong type of communication - void fetab_save_file (const QWidget* ID, const QString& fileName, bool remove_on_success); + void fetab_save_file (const QWidget* ID, const QString& fileName, + bool remove_on_success); // No fetab_open, functionality in editor // No fetab_new, functionality in editor void fetab_undo (const QWidget* ID); @@ -99,7 +94,8 @@ void fetab_goto_line (const QWidget* ID, int line = -1); void fetab_insert_debugger_pointer (const QWidget* ID, int line = -1); void fetab_delete_debugger_pointer (const QWidget* ID, int line = -1); - void fetab_do_breakpoint_marker (bool insert, const QWidget* ID, int line = -1); + void fetab_do_breakpoint_marker (bool insert, const QWidget* ID, + int line = -1); void fetab_set_focus (const QWidget* ID); public slots: @@ -107,37 +103,38 @@ void handle_visibility (bool visible); void request_new_file (const QString& commands); - void request_open_file (); - void request_mru_open_file (); - void request_print_file (); + void request_open_file (void); + void request_mru_open_file (void); + void request_print_file (void); - void request_undo (); - void request_redo (); - void request_copy (); - void request_cut (); - void request_paste (); - void request_save_file (); - void request_save_file_as (); - void request_run_file (); - void request_toggle_bookmark (); - void request_next_bookmark (); - void request_previous_bookmark (); - void request_remove_bookmark (); + void request_undo (void); + void request_redo (void); + void request_copy (void); + void request_cut (void); + void request_paste (void); + void request_save_file (void); + void request_save_file_as (void); + void request_run_file (void); + void request_toggle_bookmark (void); + void request_next_bookmark (void); + void request_previous_bookmark (void); + void request_remove_bookmark (void); - void request_toggle_breakpoint (); - void request_next_breakpoint (); - void request_previous_breakpoint (); - void request_remove_breakpoint (); + void request_toggle_breakpoint (void); + void request_next_breakpoint (void); + void request_previous_breakpoint (void); + void request_remove_breakpoint (void); - void request_comment_selected_text (); - void request_uncomment_selected_text (); - void request_find (); + void request_comment_selected_text (void); + void request_uncomment_selected_text (void); + void request_find (void); - void request_goto_line (); + void request_goto_line (void); - void handle_file_name_changed (const QString& fileName, const QString& toolTip); + void handle_file_name_changed (const QString& fileName, + const QString& toolTip); void handle_tab_close_request (int index); - void handle_tab_remove_request (); + void handle_tab_remove_request (void); void handle_add_filename_to_list (const QString& fileName, QWidget *ID); void active_tab_changed (int index); void handle_editor_state_changed (bool enableCopy, const QString& fileName); @@ -146,23 +143,26 @@ void handle_insert_debugger_pointer_request (const QString& file, int line); void handle_delete_debugger_pointer_request (const QString& file, int line); - void handle_update_breakpoint_marker_request (bool insert, const QString& file, - int line); + void handle_update_breakpoint_marker_request (bool insert, + const QString& file, int line); + void handle_edit_file_request (const QString& file); - /** Tells the editor to react on changed settings. */ + // Tells the editor to react on changed settings. void notice_settings (const QSettings *settings); private slots: + void request_open_file (const QString& fileName, int line = -1, bool debug_pointer = false, bool breakpoint_marker = false, bool insert = true); private: - void construct (); - void add_file_editor_tab(file_editor_tab *f, const QString &fn); + + void construct (void); + void add_file_editor_tab (file_editor_tab *f, const QString& fn); void save_file_as (QWidget *fetabID = 0); - void mru_menu_update (); + void mru_menu_update (void); QWidget *find_tab_widget (const QString& openFileName) const; @@ -170,14 +170,14 @@ QString ced; - QMenuBar * _menu_bar; - QToolBar * _tool_bar; - QMenu * _debug_menu; - QAction * _copy_action; - QAction * _cut_action; - QAction * _run_action; - QTabWidget * _tab_widget; - int _marker_breakpoint; + QMenuBar *_menu_bar; + QToolBar *_tool_bar; + QMenu *_debug_menu; + QAction *_copy_action; + QAction *_cut_action; + QAction *_run_action; + QTabWidget *_tab_widget; + int _marker_breakpoint; enum { MaxMRUFiles = 10 }; QMenu *_mru_file_menu;