27 #ifdef HAVE_QSCINTILLA
29 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H)
30 #define HAVE_LEXER_OCTAVE
31 #include <Qsci/qscilexeroctave.h>
32 #elif defined (HAVE_QSCI_QSCILEXERMATLAB_H)
33 #define HAVE_LEXER_MATLAB
34 #include <Qsci/qscilexermatlab.h>
36 #include <Qsci/qscilexercpp.h>
37 #include <Qsci/qscilexerbash.h>
38 #include <Qsci/qscilexerperl.h>
39 #include <Qsci/qscilexerbatch.h>
40 #include <Qsci/qscilexerdiff.h>
41 #include <Qsci/qsciprinter.h>
43 #include <QApplication>
44 #include <QFileDialog>
45 #include <QMessageBox>
46 #include <QTextStream>
47 #include <QVBoxLayout>
48 #include <QInputDialog>
49 #include <QPrintDialog>
62 QString directory = directory_arg;
68 if (directory.count () && directory.at (directory.count () - 1) !=
'/')
69 directory.append (
"/");
84 SIGNAL (cursorPositionChanged (
int,
int)),
93 QLabel *row_label =
new QLabel (tr (
"Line:"),
this);
96 QLabel *col_label =
new QLabel (tr (
"Col:"),
this);
107 _edit_area->setMarginType (1, QsciScintilla::SymbolMargin);
110 _edit_area->markerDefine (QPixmap (
":/actions/icons/redled.png"),
112 _edit_area->markerDefine (QPixmap (
":/actions/icons/bookmark.png"),
115 connect (
_edit_area, SIGNAL (marginClicked (
int,
int,
116 Qt::KeyboardModifiers)),
118 Qt::KeyboardModifiers)));
121 _edit_area->setMarginsForegroundColor (QColor (96, 96, 96));
122 _edit_area->setMarginsBackgroundColor (QColor (232, 232, 220));
123 _edit_area->setMarginType (2, QsciScintilla::TextMargin);
126 _edit_area->setMarginType (3, QsciScintilla::SymbolMargin);
127 _edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3);
130 _edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch);
139 _edit_area->setAutoCompletionSource (QsciScintilla::AcsAll);
141 QVBoxLayout *edit_area_layout =
new QVBoxLayout ();
144 edit_area_layout->setMargin (0);
145 setLayout (edit_area_layout);
148 connect (
_edit_area, SIGNAL (modificationChanged (
bool)),
151 connect (
_edit_area, SIGNAL (copyAvailable (
bool)),
203 if (!trackedFiles.isEmpty ())
205 if (!fileName.isEmpty ())
229 return (! file_name.isEmpty ()
230 && file_name.at (file_name.count () - 1) !=
'/');
235 Qt::KeyboardModifiers
state)
239 unsigned int markers_mask =
_edit_area->markersAtLine (line);
241 if (state & Qt::ControlModifier)
243 if (markers_mask && (1 <<
bookmark))
271 #if defined (HAVE_LEXER_OCTAVE)
272 lexer =
new QsciLexerOctave ();
273 #elif defined (HAVE_LEXER_MATLAB)
274 lexer =
new QsciLexerMatlab ();
290 lexer =
new QsciLexerCPP ();
294 lexer =
new QsciLexerPerl ();
298 lexer =
new QsciLexerBatch ();
302 lexer =
new QsciLexerDiff ();
307 #if defined (HAVE_LEXER_OCTAVE)
308 lexer =
new QsciLexerOctave ();
309 #elif defined (HAVE_LEXER_MATLAB)
310 lexer =
new QsciLexerMatlab ();
312 lexer =
new QsciLexerBash ();
318 lexer =
new QsciLexerBash ();
326 QDesktopServices desktopServices;
327 QString prep_apis_path
328 = desktopServices.storageLocation (QDesktopServices::HomeLocation)
338 QStringList keyword_list;
342 keyword = QString(lexer->keywords (i));
343 keyword_list = keyword.split (QRegExp (
"\\s+"));
344 for (j = 0; j < keyword_list.size (); j++)
349 disconnect (
_lexer_apis, SIGNAL (apiPreparationFinished ()), 0, 0);
351 if (QDir(
"/").mkpath (prep_apis_path))
354 connect (
_lexer_apis, SIGNAL (apiPreparationFinished ()),
363 lexer->readSettings (*settings);
368 if (settings->value (
"editor/showLineNumbers",
true).toBool ())
384 if (lexer ==
"octave" || lexer ==
"matlab")
386 else if (lexer ==
"perl" || lexer ==
"bash" || lexer ==
"diff")
388 else if (lexer ==
"cpp")
390 else if (lexer ==
"batch")
479 bool remove_on_success)
502 QsciPrinter *printer =
new QsciPrinter (QPrinter::HighResolution);
504 QPrintDialog printDlg (printer,
this);
506 if (printDlg.exec () == QDialog::Accepted)
596 line_info[0] = info.line;
606 line_info[0] = info.line;
623 QString dir = file_info.absolutePath ();
624 QString function_name = file_info.fileName ();
627 function_name.chop (file_info.suffix ().length () + 1);
629 bp_info info (
_file_name, dir, function_name, line+1);
639 QString dir = file_info.absolutePath ();
640 QString function_name = file_info.fileName ();
643 function_name.chop (file_info.suffix ().length () + 1);
645 bp_info info (
_file_name, dir, function_name, line+1);
689 int line, cur, prevline;
707 QString dir = file_info.absolutePath ();
708 QString function_name = file_info.fileName ();
711 function_name.chop (file_info.suffix ().length () + 1);
713 bp_info info (
_file_name, dir, function_name, 0);
762 qobject_cast<QWidget *> (sender ()));
791 _edit_area->getCursorPosition (&line, &index);
792 line = QInputDialog::getInt (
_edit_area, tr (
"Goto line"),
793 tr (
"Line number"), line+1, 1,
814 int lineFrom, lineTo, colFrom, colTo;
815 _edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo);
820 for (
int i = lineFrom; i <= lineTo; i++)
827 if (line.startsWith (comment_str))
829 _edit_area->setSelection (i, 0, i, comment_str.length ());
835 _edit_area->setSelection (lineFrom, 0, lineTo,
841 _edit_area->getCursorPosition (&cpline, &col);
843 _edit_area->insertAt (comment_str, cpline, 0);
847 if (line.startsWith (comment_str))
849 _edit_area->setSelection (cpline, 0, cpline, comment_str.length ());
861 QString tooltip (
"");
864 title = tr (
"<unnamed>");
872 title = file.fileName ();
895 dlg->setAttribute (Qt::WA_DeleteOnClose);
900 dlg->setWindowModality (Qt::WindowModal);
908 int decision = QMessageBox::Yes;
916 QMessageBox::StandardButtons buttons = QMessageBox::Save |
917 QMessageBox::Discard;
918 QString available_actions;
921 available_actions = tr (
"Do you want to save or discard the changes?");
924 buttons = buttons | QMessageBox::Cancel;
926 = tr (
"Do you want to cancel closing, save or discard the changes?");
933 file = tr (
"<unnamed>");
936 =
new QMessageBox (QMessageBox::Warning, tr (
"Octave Editor"),
939 "is about to be closed but has been modified.\n"
941 arg (file).
arg (available_actions),
942 buttons, qobject_cast<QWidget *> (parent ()));
944 msgBox->setDefaultButton (QMessageBox::Save);
946 connect (msgBox, SIGNAL (finished (
int)),
951 return QMessageBox::Cancel;
965 if (decision == QMessageBox::Save)
970 else if (decision == QMessageBox::Discard)
992 QFileInfo file_info = QFileInfo (fileName);
993 QString file_to_load;
994 if (file_info.exists ())
995 file_to_load = file_info.canonicalFilePath ();
997 file_to_load = fileName;
998 QFile file (file_to_load);
999 if (!file.open (QFile::ReadOnly))
1000 return file.errorString ();
1002 QTextStream in (&file);
1003 QApplication::setOverrideCursor (Qt::WaitCursor);
1005 QApplication::restoreOverrideCursor ();
1034 QFileInfo file_info = QFileInfo (saveFileName);
1035 QString file_to_save;
1036 if (file_info.exists ())
1037 file_to_save = file_info.canonicalFilePath ();
1039 file_to_save = saveFileName;
1040 QFile file (file_to_save);
1044 if (trackedFiles.contains (file_to_save))
1048 if (!file.open (QIODevice::WriteOnly))
1052 if (trackedFiles.contains (file_to_save))
1058 tr (
"Octave Editor"),
1059 tr (
"Could not open file %1 for write:\n%2.").
1060 arg (file_to_save).
arg (file.errorString ()),
1061 QMessageBox::Ok, 0);
1068 QTextStream out (&file);
1069 QApplication::setOverrideCursor (Qt::WaitCursor);
1072 QApplication::restoreOverrideCursor ();
1077 file_info = QFileInfo (file);
1078 file_to_save = file_info.canonicalFilePath ();
1089 if (remove_on_success)
1105 if (remove_on_success)
1118 fileDialog->setOption(QFileDialog::DontUseNativeDialog,
true);
1126 fileDialog->selectFile (
"");
1129 fileDialog->setDirectory (QDir::currentPath ());
1138 fileDialog->setNameFilter (tr (
"Octave Files (*.m);;All Files (*)"));
1139 fileDialog->setDefaultSuffix (
"m");
1140 fileDialog->setAcceptMode (QFileDialog::AcceptSave);
1141 fileDialog->setViewMode (QFileDialog::Detail);
1143 if (remove_on_success)
1145 connect (fileDialog, SIGNAL (fileSelected (
const QString&)),
1148 connect (fileDialog, SIGNAL (rejected ()),
1153 connect (fileDialog, SIGNAL (fileSelected (
const QString&)),
1199 if (!trackedFiles.isEmpty ())
1208 tr (
"Octave Editor"),
1209 tr (
"It seems that \'%1\' has been modified by another application. Do you want to reload it?").
1211 QMessageBox::Yes | QMessageBox::No,
this);
1213 connect (msgBox, SIGNAL (finished (
int)),
1216 msgBox->setWindowModality (Qt::WindowModal);
1217 msgBox->setAttribute (Qt::WA_DeleteOnClose);
1222 QString modified =
"";
1224 modified = tr (
"\n\nWarning: The contents in the editor is modified!");
1230 =
new QMessageBox (QMessageBox::Warning, tr (
"Octave Editor"),
1231 tr (
"It seems that the file\n"
1233 "has been deleted or renamed. Do you want to save it now?%2").
1235 QMessageBox::Save | QMessageBox::Close, 0);
1239 connect (msgBox, SIGNAL (finished (
int)),
1242 msgBox->setWindowModality (Qt::WindowModal);
1243 msgBox->setAttribute (Qt::WA_DeleteOnClose);
1256 QVariant default_var = QColor (240, 240, 240);
1257 QColor setting_color = settings->value (
"editor/highlight_current_line_color",
1258 default_var).value<QColor> ();
1259 _edit_area->setCaretLineBackgroundColor (setting_color);
1261 (settings->value (
"editor/highlightCurrentLine",
true).toBool ());
1263 if (settings->value (
"editor/codeCompletion",
true).toBool ())
1265 bool match_keywords = settings->value
1266 (
"editor/codeCompletion_keywords",
true).toBool ();
1267 bool match_document = settings->value
1268 (
"editor/codeCompletion_document",
true).toBool ();
1270 QsciScintilla::AutoCompletionSource source = QsciScintilla::AcsNone;
1273 source = QsciScintilla::AcsAll;
1275 source = QsciScintilla::AcsAPIs;
1276 else if (match_document)
1277 source = QsciScintilla::AcsDocument;
1278 _edit_area->setAutoCompletionSource (source);
1281 (settings->value (
"editor/codeCompletion_replace",
false).toBool ());
1283 (settings->value (
"editor/codeCompletion_case",
true).toBool ());
1285 (settings->value (
"editor/codeCompletion_threshold",2).toInt ());
1290 if (settings->value (
"editor/show_white_space",
false).toBool ())
1291 if (settings->value (
"editor/show_white_space_indent",
false).toBool ())
1292 _edit_area->setWhitespaceVisibility (QsciScintilla::WsVisibleAfterIndent);
1294 _edit_area->setWhitespaceVisibility (QsciScintilla::WsVisible);
1296 _edit_area->setWhitespaceVisibility (QsciScintilla::WsInvisible);
1298 if (settings->value (
"editor/showLineNumbers",
true).toBool ())
1302 connect (
_edit_area, SIGNAL (linesChanged ()),
1308 disconnect (
_edit_area, SIGNAL (linesChanged ()), 0, 0);
1312 (settings->value (
"editor/auto_indent",
true).toBool ());
1314 (settings->value (
"editor/tab_indents_line",
false).toBool ());
1316 (settings->value (
"editor/backspace_unindents_line",
false).toBool ());
1318 (settings->value (
"editor/show_indent_guides",
false).toBool ());
1321 (settings->value (
"editor/tab_width",2).toInt ());
1323 _long_title = settings->value (
"editor/longWindowTitle",
false).toBool ();
1375 if (ID !=
this && ID != 0)
1386 if (decision == QMessageBox::Yes)
1402 if (decision == QMessageBox::Save)
1421 if (ID !=
this || ID == 0)
1434 if (ID !=
this || ID == 0)
1444 if (ID !=
this || ID == 0)
1460 long int visible_lines
1461 =
_edit_area->SendScintilla (QsciScintillaBase::SCI_LINESONSCREEN);
1463 if (visible_lines > 2)
1466 _edit_area->getCursorPosition (&line, &index);
1468 int first_line =
_edit_area->firstVisibleLine ();
1469 first_line = first_line + (line - first_line - (visible_lines-1)/2);