30 #if defined (HAVE_CONFIG_H)
34 #if defined (HAVE_QSCINTILLA)
36 #include <QApplication>
39 #include <QDesktopServices>
40 #include <QDialogButtonBox>
41 #include <QFileDialog>
42 #include <QInputDialog>
44 #include <QMessageBox>
45 #include <QPrintDialog>
46 #include <QPushButton>
50 #include <QTextStream>
51 #include <QVBoxLayout>
52 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H)
53 # define HAVE_LEXER_OCTAVE 1
54 # include <Qsci/qscilexeroctave.h>
55 #elif defined (HAVE_QSCI_QSCILEXERMATLAB_H)
56 # define HAVE_LEXER_MATLAB 1
57 # include <Qsci/qscilexermatlab.h>
59 #include <Qsci/qscilexerbash.h>
60 #include <Qsci/qscilexerbatch.h>
61 #include <Qsci/qscilexercpp.h>
62 #include <Qsci/qscilexerdiff.h>
63 #include <Qsci/qscilexerperl.h>
64 #include <Qsci/qsciprinter.h>
81 #include "builtin-defun-decls.h"
103 const QString& directory_arg)
104 : m_octave_qobj (oct_qobj)
111 m_ced = directory_arg;
130 connect (
m_edit_area, SIGNAL (cursorPositionChanged (
int,
int)),
133 connect (
m_edit_area, SIGNAL (SCN_CHARADDED (
int)),
136 connect (
m_edit_area, SIGNAL (SCN_DOUBLECLICK (
int,
int,
int)),
142 connect (
m_edit_area, SIGNAL (context_menu_edit_signal (
const QString&)),
152 QLabel *row_label =
new QLabel (tr (
"line:"),
this);
155 QLabel *col_label =
new QLabel (tr (
"col:"),
this);
162 QLabel *enc_label =
new QLabel (tr (
"encoding:"),
this);
169 QLabel *eol_label =
new QLabel (tr (
"eol:"),
this);
176 m_edit_area->setMarginType (1, QsciScintilla::SymbolMargin);
184 m_edit_area->markerDefine (QsciScintilla::RightArrow,
186 m_edit_area->setMarkerBackgroundColor (QColor (255,255,0),
188 m_edit_area->markerDefine (QsciScintilla::RightArrow,
190 m_edit_area->setMarkerBackgroundColor (QColor (192,192,192),
193 connect (
m_edit_area, SIGNAL (marginClicked (
int,
int,
194 Qt::KeyboardModifiers)),
196 Qt::KeyboardModifiers)));
198 connect (
m_edit_area, SIGNAL (context_menu_break_condition_signal (
int)),
202 m_edit_area->setMarginsForegroundColor (QColor (96, 96, 96));
203 m_edit_area->setMarginsBackgroundColor (QColor (232, 232, 220));
204 m_edit_area->setMarginType (2, QsciScintilla::TextMargin);
207 m_edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch);
215 m_edit_area->SendScintilla (QsciScintillaBase::SCI_AUTOCSETCANCELATSTART,
false);
217 QVBoxLayout *edit_area_layout =
new QVBoxLayout ();
220 edit_area_layout->setMargin (0);
221 edit_area_layout->setSpacing (0);
222 setLayout (edit_area_layout);
234 connect (
m_edit_area, SIGNAL (modificationChanged (
bool)),
237 connect (
m_edit_area, SIGNAL (copyAvailable (
bool)),
246 connect (
this, SIGNAL (
dbstop_if (
const QString&,
int,
const QString&)),
260 this, SLOT (
do_save_file (
const QString&,
bool,
bool)));
268 QString locale_enc_name =
269 QString (
"SYSTEM (") +
295 if (new_encoding.isEmpty ())
307 if ((save_dialog == QMessageBox::Cancel) ||
308 (save_dialog == QMessageBox::Save))
332 QRegExp rxfun1 (
"^[\t ]*function[^=]+=[\t ]*"
333 + word_at_cursor +
"[\t ]*\\([^\\)]*\\)[\t ]*$");
334 QRegExp rxfun2 (
"^[\t ]*function[\t ]+"
335 + word_at_cursor +
"[\t ]*\\([^\\)]*\\)[\t ]*$");
336 QRegExp rxfun3 (
"^[\t ]*function[\t ]+"
337 + word_at_cursor +
"[\t ]*$");
338 QRegExp rxfun4 (
"^[\t ]*function[^=]+=[\t ]*"
339 + word_at_cursor +
"[\t ]*$");
342 QStringList lines =
m_edit_area->text ().split (
"\n");
347 if ((pos_fct = rxfun1.indexIn (lines.at (
line))) != -1)
349 if ((pos_fct = rxfun2.indexIn (lines.at (
line))) != -1)
351 if ((pos_fct = rxfun3.indexIn (lines.at (
line))) != -1)
353 if ((pos_fct = rxfun4.indexIn (lines.at (
line))) != -1)
387 for (
int i = 0; i <
m_bp_lines.length (); i++)
406 cond =
'(' + cond +
") || (" +
m_edit_area->selectedText () +
')';
409 emit
dbstop_if (
"dbstop if", linenr+1, cond);
423 = QInputDialog::getText (
this, tr (
"Breakpoint condition"),
424 prompt, QLineEdit::Normal, cond, &ok);
428 if (ok && ! new_cond.isEmpty ())
466 catch (
const interrupt_exception&)
470 msg =
"evaluation interrupted";
479 QString new_prompt = (tr (
"ERROR: ")
493 if (! trackedFiles.isEmpty ())
495 if (! fileName.isEmpty () && QFile::exists (fileName))
540 int ans = QMessageBox::question (
nullptr, tr (
"Octave Editor"),
541 tr (
"Cannot add breakpoint to modified or unnamed file.\n"
542 "Save and add breakpoint, or cancel?"),
543 QMessageBox::Save | QMessageBox::Cancel, QMessageBox::Save);
545 if (ans == QMessageBox::Save)
557 Qt::KeyboardModifiers
state)
561 unsigned int markers_mask =
m_edit_area->markersAtLine (editor_linenr);
563 if (
state & Qt::ControlModifier)
596 #if defined (HAVE_LEXER_OCTAVE)
597 lexer =
new QsciLexerOctave ();
598 #elif defined (HAVE_LEXER_MATLAB)
599 lexer =
new QsciLexerMatlab ();
618 lexer =
new QsciLexerCPP ();
622 lexer =
new QsciLexerPerl ();
626 lexer =
new QsciLexerBatch ();
630 lexer =
new QsciLexerDiff ();
634 lexer =
new QsciLexerBash ();
639 #if defined (HAVE_LEXER_OCTAVE)
640 lexer =
new QsciLexerOctave ();
642 #elif defined (HAVE_LEXER_MATLAB)
643 lexer =
new QsciLexerMatlab ();
662 || QString(old_lexer->lexer ()) != QString(
lexer->
lexer ()))
700 bool update_apis =
false;
705 QString tmp_app_name = QCoreApplication::applicationName ();
706 QCoreApplication::setApplicationName (
"octave");
708 #if defined (HAVE_QSTANDARDPATHS)
709 QString local_data_path
710 = QStandardPaths::writableLocation (QStandardPaths::CacheLocation);
712 QString local_data_path
713 = QDesktopServices::storageLocation (QDesktopServices::CacheLocation);
716 QCoreApplication::setApplicationName (
"octave");
724 bool octave_functions
727 QCoreApplication::setApplicationName (tmp_app_name);
743 if (octave_functions)
752 update_apis = ! apis_file.exists ();
754 if (octave_functions)
759 QDateTime apis_time = apis_file.lastModified ();
760 if (QDateTime::currentDateTime () > apis_time.addSecs (180))
775 bool apis_usable =
f.open (QIODevice::ReadOnly);
778 QDir ().mkpath (QFileInfo (
f).absolutePath ());
779 apis_usable =
f.open (QIODevice::WriteOnly);
795 ([
this, octave_functions, octave_builtins] (
interpreter& interp)
799 QStringList api_entries;
805 std::string kw = ctmp(i).string_value ();
820 if (octave_functions)
839 for (
int i = 1; i <= 3; i++)
843 QString keyword = QString (
lexer->keywords (i));
845 QStringList keyword_list
846 = keyword.split (QRegExp (R
"(\s+)"));
848 for (
int j = 0; j < keyword_list.size (); j++)
863 QColor bg =
lexer->paper (0);
864 QColor fg =
lexer->color (0);
866 int bh, bs, bv, fh, fs, fv, h, s, v;
867 bg.getHsv (&bh,&bs,&bv);
868 fg.getHsv (&fh,&fs,&fv);
873 v = bv + (fv - bv)/5;
878 v = bv + (fv - bv)/8;
880 v = bv + (fv - bv)/4;
890 QColor hg = QApplication::palette ().color (QPalette::Highlight);
901 QFont line_numbers_font =
lexer->defaultFont ();
902 int font_size = line_numbers_font.pointSize ();
903 font_size = font_size
907 line_numbers_font.setPointSize (font_size);
918 for (
int idx = 0; idx < api_entries.size (); idx++)
927 disconnect (
m_lexer_apis, SIGNAL (apiPreparationFinished ()),
934 connect (
m_lexer_apis, SIGNAL (apiPreparationFinished ()),
980 bool remove_on_success)
1001 QsciPrinter *printer =
new QsciPrinter (QPrinter::HighResolution);
1003 QPrintDialog printDlg (printer,
this);
1005 if (printDlg.exec () == QDialog::Accepted)
1117 const QString& cond)
1122 QString q_dir =
file_info.absolutePath ();
1123 QString q_function_name =
file_info.fileName ();
1126 q_function_name.chop (
file_info.suffix ().length () + 1);
1128 dir = q_dir.toStdString ();
1136 if (pos != std::string::npos && pos <
dir.length () - 1)
1138 if (
dir[pos+1] ==
'@')
1142 dir =
dir.substr (0, pos);
1148 const QString& condition)
1167 line_info[0] = info.
line;
1171 tree_evaluator& tw = interp.get_evaluator ();
1173 bp_table& bptab = tw.get_bp_table ();
1175 bptab.remove_breakpoint (info.function_name, line_info);
1185 int editor_linenr, cur;
1186 m_edit_area->getCursorPosition (&editor_linenr, &cur);
1213 if (nextcond != -1 && (nextcond < nextline || nextline == -1))
1214 nextline = nextcond;
1226 int line, cur, prevline, prevcond;
1235 if (prevcond != -1 && prevcond > prevline)
1236 prevline = prevcond;
1257 tree_evaluator& tw = interp.get_evaluator ();
1259 bp_table& bptab = tw.get_bp_table ();
1261 bptab.remove_all_breakpoints_in_file (info.function_name, true);
1267 unsigned int sci_msg)
1317 QsciScintilla::EolMode eol_mode)
1367 line_info[0] = info.
line;
1371 tree_evaluator& tw = interp.get_evaluator ();
1373 bp_table& bptab = tw.get_bp_table ();
1375 bp_table::intmap bpmap
1376 = bptab.add_breakpoint (info.function_name,
"", line_info,
1379 if (! bpmap.empty ())
1381 bp_table::intmap::iterator bp_it = bpmap.begin ();
1383 int remove_line = bp_it->second;
1385 emit maybe_remove_next (remove_line);
1420 tr (
"Line number"),
line+1, 1,
1449 QsciScintilla::AutoCompletionSource s =
m_edit_area->autoCompletionSource ();
1452 case QsciScintilla::AcsAll:
1456 case QsciScintilla::AcsAPIs:
1460 case QsciScintilla::AcsDocument:
1464 case QsciScintilla::AcsNone:
1476 int lineFrom, lineTo, colFrom, colTo;
1477 m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo);
1482 for (
int i = lineFrom; i <= lineTo; i++)
1510 int lineFrom, lineTo;
1515 m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo);
1536 QString ws =
"^(?:[ \\t]*)";
1538 QString used_comment_str = comment_str.at (0);
1549 = QInputDialog::getText (
this, tr (
"Comment selected text"),
1550 tr (
"Comment string to use:\n"),
1555 if ((! ok) || used_comment_str.isEmpty ())
1566 QStringList comment_str_sorted (comment_str.at (0));
1569 for (
int i = 1; i < comment_str.length (); i++)
1572 for (
int j = 0; j < comment_str_sorted.length (); j++)
1574 if (comment_str.at (i).length () > comment_str_sorted.at (j).length ())
1576 comment_str_sorted.insert (j, comment_str.at (i));
1582 comment_str_sorted << comment_str.at (i);
1587 for (
int i = 0; i < comment_str_sorted.length (); i++)
1593 rxc = QRegExp (ws +
"(" +
regexp +
")");
1597 int len = 0, lenc = 0;
1602 int lineFrom, lineTo, colFrom, colTo;
1603 int change_col_from = 1;
1604 int change_col_to = 1;
1607 m_edit_area->getSelection (&lineFrom, &colFrom, &lineTo, &colTo);
1612 for (
int i = lineFrom; i <= lineTo; i++)
1621 if ((removed =
line.contains (rxc)))
1623 len = rxc.matchedLength ();
1624 QString matched_text = rxc.capturedTexts ().at (0);
1625 lenc = matched_text.remove (QRegExp (ws)).length ();
1631 if (i == lineFrom && (colFrom <
len-lenc || ! removed))
1632 change_col_from = 0;
1633 if (i == lineTo && (colTo <
len-lenc || ! removed))
1641 colFrom = colFrom + lenc;
1643 colTo = colTo + lenc;
1651 colFrom = colFrom - change_col_from*lenc;
1652 colTo = colTo - change_col_to*lenc;
1656 m_edit_area->setSelection (lineFrom, colFrom, lineTo, colTo);
1663 m_edit_area->insertAt (used_comment_str, cpline, 0);
1667 if (
line.contains (rxc))
1669 len = rxc.matchedLength ();
1670 QString matched_text = rxc.capturedTexts ().at (0);
1671 lenc = matched_text.remove (QRegExp (ws)).length ();
1683 QString tooltip (
"");
1686 title = tr (
"<unnamed>");
1694 title = file.fileName ();
1711 dlg->setAttribute (Qt::WA_DeleteOnClose);
1716 dlg->setWindowModality (Qt::NonModal);
1723 int decision = QMessageBox::Yes;
1729 QMessageBox::StandardButtons buttons = QMessageBox::Save |
1730 QMessageBox::Discard |
1731 QMessageBox::Cancel;
1736 QString available_actions =
1737 tr (
"Do you want to cancel closing, save or discard the changes?");
1743 file = tr (
"<unnamed>");
1746 =
new QMessageBox (QMessageBox::Warning, tr (
"Octave Editor"),
1749 "is about to be closed but has been modified. "
1751 arg (file). arg (available_actions),
1752 buttons, qobject_cast<QWidget *> (parent ()));
1754 msgBox->setDefaultButton (QMessageBox::Save);
1757 decision = msgBox->exec ();
1759 if (decision == QMessageBox::Cancel)
1761 else if (decision == QMessageBox::Save)
1801 for (
int i = 0; i <
m_bp_lines.length (); i++)
1814 QFileInfo
file_info = QFileInfo (fileName);
1815 QString file_to_load;
1817 file_to_load =
file_info.canonicalFilePath ();
1819 file_to_load = fileName;
1820 QFile file (file_to_load);
1821 if (!file.open(QIODevice::ReadOnly))
1822 return file.errorString ();
1824 int col = 0,
line = 0;
1832 QApplication::setOverrideCursor (Qt::WaitCursor);
1835 const QByteArray text_data = file.readAll ();
1838 QTextCodec::ConverterState st;
1839 QTextCodec *codec = QTextCodec::codecForName (
m_encoding.toLatin1 ());
1840 if (codec ==
nullptr)
1841 codec = QTextCodec::codecForLocale ();
1843 const QString
text = codec->toUnicode(text_data.constData(),
1844 text_data.size(), &st);
1847 if (st.invalidChars > 0)
1853 QString msg = tr (
"There were problems reading the file\n"
1855 "with the selected encoding %2.\n\n"
1856 "Modifying and saving the file might "
1860 msg_box->setIcon (QMessageBox::Warning);
1861 msg_box->setText (msg);
1862 msg_box->setWindowTitle (tr (
"Octave Editor"));
1863 msg_box->addButton (tr (
"&Edit anyway"), QMessageBox::YesRole);
1864 msg_box->addButton (tr (
"Chan&ge encoding"), QMessageBox::AcceptRole);
1865 msg_box->addButton (tr (
"&Close"), QMessageBox::RejectRole);
1867 connect (msg_box, SIGNAL (buttonClicked (QAbstractButton *)),
1870 msg_box->setWindowModality (Qt::WindowModal);
1871 msg_box->setAttribute (Qt::WA_DeleteOnClose);
1878 QApplication::restoreOverrideCursor ();
1894 QString txt = btn->text ();
1896 if (txt == tr (
"&Close"))
1903 if (txt == tr (
"Chan&ge encoding"))
1907 dlg.setWindowTitle (tr (
"Select new default encoding"));
1910 =
new QLabel (tr (
"Please select a new encoding\n"
1911 "for reloading the current file.\n\n"
1912 "This does not change the default encoding.\n"));
1914 QComboBox *enc_combo =
new QComboBox ();
1918 connect (enc_combo, SIGNAL (currentTextChanged (
const QString&)),
1921 QDialogButtonBox *buttons
1922 =
new QDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
1924 connect (buttons, SIGNAL (accepted ()), &dlg, SLOT (accept ()));
1925 connect (buttons, SIGNAL (rejected ()), &dlg, SLOT (reject ()));
1927 QGridLayout *main_layout =
new QGridLayout;
1928 main_layout->setSizeConstraint (QLayout::SetFixedSize);
1929 main_layout->addWidget (
text, 0, 0);
1930 main_layout->addWidget (enc_combo, 1, 0);
1931 main_layout->addWidget (buttons, 2, 0);
1932 dlg.setLayout (main_layout);
1934 int answer = dlg.exec ();
1936 if (answer == QDialog::Accepted)
1958 QByteArray eol_lf = QByteArray (1,0x0a);
1959 QByteArray eol_cr = QByteArray (1,0x0d);
1960 QByteArray eol_crlf = eol_cr;
1961 eol_crlf.append (eol_lf);
1963 int count_crlf =
text.count (eol_crlf);
1964 int count_lf =
text.count (eol_lf) - count_crlf;
1965 int count_cr =
text.count (eol_cr) - count_crlf;
1969 QsciScintilla::EolMode eol_mode
1974 if (count_crlf > count_max)
1976 eol_mode = QsciScintilla::EolWindows;
1977 count_max = count_crlf;
1979 if (count_lf > count_max)
1981 eol_mode = QsciScintilla::EolUnix;
1982 count_max = count_lf;
1984 if (count_cr > count_max)
1986 eol_mode = QsciScintilla::EolMac;
1996 case QsciScintilla::EolWindows:
1999 case QsciScintilla::EolMac:
2002 case QsciScintilla::EolUnix:
2024 Qt::QueuedConnection);
2041 if (file (i).string_value () ==
m_file_name.toStdString ())
2067 const QString& base_name,
2068 bool remove_on_success,
2069 bool restore_breakpoints)
2071 int ans = QMessageBox::question (
nullptr, tr (
"Debug or Save"),
2072 tr (
"This file is currently being executed.\n"
2073 "Quit debugging and save?"),
2074 QMessageBox::Save | QMessageBox::Cancel);
2076 if (ans == QMessageBox::Save)
2079 ([
this, file_to_save, base_name, remove_on_success, restore_breakpoints] (
interpreter& interp)
2089 std::string std_base_name = base_name.toStdString ();
2096 restore_breakpoints);
2102 bool remove_on_success,
2103 bool restore_breakpoints)
2126 QFileInfo
file_info = QFileInfo (saveFileName);
2127 QString file_to_save;
2130 file_to_save =
file_info.canonicalFilePath ();
2131 QString base_name =
file_info.baseName ();
2134 ([
this, file_to_save, base_name, remove_on_success, restore_breakpoints] (
interpreter& interp)
2146 std::string std_base_name = base_name.toStdString ();
2153 sym = symtab.find_user_function (std_base_name);
2164 if (! sym.is_defined () || ! sym.is_user_code ())
2166 emit do_save_file_signal (file_to_save, remove_on_success,
2167 restore_breakpoints);
2173 std::string full_name = file_to_save.toStdString ();
2178 emit do_save_file_signal (file_to_save, remove_on_success,
2179 restore_breakpoints);
2191 Cell names = stk.contents (
"name");
2195 if (names(i).string_value () == std_base_name)
2197 emit confirm_dbquit_and_save_signal
2198 (file_to_save, base_name, remove_on_success,
2199 restore_breakpoints);
2205 symtab.clear_user_function (std_base_name);
2208 restore_breakpoints);
2212 emit do_save_file_signal (saveFileName, remove_on_success,
2213 restore_breakpoints);
2217 bool remove_on_success,
2218 bool restore_breakpoints)
2220 QFile file (file_to_save);
2224 if (trackedFiles.contains (file_to_save))
2228 if (! file.open (QIODevice::WriteOnly))
2232 if (trackedFiles.contains (file_to_save))
2238 tr (
"Octave Editor"),
2239 tr (
"Could not open file %1 for write:\n%2.").
2240 arg (file_to_save).arg (file.errorString ()),
2241 QMessageBox::Ok,
nullptr);
2250 QTextStream out (&file);
2257 out.setCodec (codec);
2259 QApplication::setOverrideCursor (Qt::WaitCursor);
2262 QApplication::restoreOverrideCursor ();
2268 QString full_file_to_save =
file_info.canonicalFilePath ();
2282 if (remove_on_success)
2291 if (restore_breakpoints)
2306 if (remove_on_success)
2317 QStringList filters;
2318 filters << tr (
"Octave Files (*.m)")
2319 << tr (
"All Files (*)");
2320 fileDialog->setNameFilters (filters);
2321 fileDialog->setDefaultSuffix (
"m");
2330 fileDialog->selectNameFilter (filters.at (1));
2331 fileDialog->setDefaultSuffix (
"");
2336 fileDialog->selectFile (
"");
2337 fileDialog->setDirectory (
m_ced);
2341 if (! fname.isEmpty ())
2342 fileDialog->selectFile (fname +
".m");
2345 fileDialog->setAcceptMode (QFileDialog::AcceptSave);
2346 fileDialog->setViewMode (QFileDialog::Detail);
2352 fileDialog->setOption(QFileDialog::DontUseNativeDialog);
2354 connect (fileDialog, SIGNAL (filterSelected (
const QString&)),
2357 if (remove_on_success)
2359 connect (fileDialog, SIGNAL (fileSelected (
const QString&)),
2362 connect (fileDialog, SIGNAL (rejected ()),
2367 connect (fileDialog, SIGNAL (fileSelected (
const QString&)),
2376 QFileDialog *file_dialog = qobject_cast<QFileDialog *> (sender ());
2378 QRegExp rx (
"\\*\\.([^ ^\\)]*)[ \\)]");
2379 int index = rx.indexIn (
filter,0);
2382 file_dialog->setDefaultSuffix (rx.cap (1));
2384 file_dialog->setDefaultSuffix (
"");
2390 QString base_name = file.baseName ();
2392 if ((file.suffix () ==
"m")
2395 int ans = QMessageBox::question (
nullptr, tr (
"Octave Editor"),
2397 "is not a valid identifier.\n\n"
2398 "If you keep this filename, you will not be able to\n"
2399 "call your script using its name as an Octave command.\n\n"
2400 "Do you want to choose another name?").arg (base_name),
2401 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
2403 if (ans == QMessageBox::Yes)
2412 QTextCodec *codec = QTextCodec::codecForName (
m_encoding.toLatin1 ());
2415 if ((! codec) &&
m_encoding.startsWith(
"SYSTEM"))
2416 codec = QTextCodec::codecForLocale ();
2420 QMessageBox::critical (
nullptr,
2421 tr (
"Octave Editor"),
2422 tr (
"The current encoding %1\n"
2423 "can not be applied.\n\n"
2424 "Please select another one!").arg (
m_encoding));
2430 bool can_encode = codec->canEncode (editor_text);
2437 QVector<uint> u32_str = editor_text.toUcs4 ();
2438 const uint32_t *src =
reinterpret_cast<const uint32_t *
>
2444 src, u32_str.size (), &
length);
2447 if (errno == EILSEQ)
2451 ::free (
static_cast<void *
> (res_str));
2456 QMessageBox::StandardButton pressed_button
2457 = QMessageBox::critical (
nullptr,
2458 tr (
"Octave Editor"),
2459 tr (
"The current editor contents can not be encoded\n"
2460 "with the selected encoding %1.\n"
2461 "Using it would result in data loss!\n\n"
2462 "Please select another one!").arg (
m_encoding),
2463 QMessageBox::Cancel | QMessageBox::Ignore,
2464 QMessageBox::Cancel);
2466 if (pressed_button == QMessageBox::Ignore)
2523 if (file_exists && ! do_close)
2527 QDateTime modified = QFileInfo (
m_file_name).lastModified ().toUTC ();
2539 if (! trackedFiles.isEmpty ())
2542 if (file_exists && ! do_close)
2560 tr (
"Octave Editor"),
2561 tr (
"It seems that \'%1\' has been modified by another application. Do you want to reload it?").
2563 QMessageBox::Yes | QMessageBox::No,
this);
2565 connect (msgBox, SIGNAL (finished (
int)),
2568 msgBox->setWindowModality (Qt::WindowModal);
2569 msgBox->setAttribute (Qt::WA_DeleteOnClose);
2588 QString modified =
"";
2590 modified = tr (
"\n\nWarning: The contents in the editor is modified!");
2596 =
new QMessageBox (QMessageBox::Warning, tr (
"Octave Editor"),
2597 tr (
"It seems that the file\n"
2599 "has been deleted or renamed. Do you want to save it now?%2").
2601 QMessageBox::Save | QMessageBox::Close,
nullptr);
2605 connect (msgBox, SIGNAL (finished (
int)),
2608 msgBox->setWindowModality (Qt::WindowModal);
2609 msgBox->setAttribute (Qt::WA_DeleteOnClose);
2625 m_edit_area->setMarginType (3, QsciScintilla::SymbolMargin);
2626 m_edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle, 3);
2630 m_edit_area->setFolding (QsciScintilla::NoFoldStyle, 3);
2641 m_edit_area->setCaretLineBackgroundColor (setting_color);
2645 bool match_keywords =
settings->value
2647 bool match_document =
settings->value
2650 QsciScintilla::AutoCompletionSource source = QsciScintilla::AcsNone;
2653 source = QsciScintilla::AcsAll;
2655 source = QsciScintilla::AcsAPIs;
2656 else if (match_document)
2657 source = QsciScintilla::AcsDocument;
2673 m_edit_area->setWhitespaceVisibility (QsciScintilla::WsVisibleAfterIndent);
2675 m_edit_area->setWhitespaceVisibility (QsciScintilla::WsVisible);
2677 m_edit_area->setWhitespaceVisibility (QsciScintilla::WsInvisible);
2691 disconnect (
m_edit_area, SIGNAL (linesChanged ()),
nullptr,
nullptr);
2714 m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETHSCROLLBAR,
2716 m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETSCROLLWIDTH,-1);
2717 m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETSCROLLWIDTHTRACKING,
true);
2731 m_edit_area->setEdgeMode (QsciScintilla::EdgeLine);
2736 m_edit_area->setEdgeMode (QsciScintilla::EdgeBackground);
2738 m_edit_area->setEdgeMode (QsciScintilla::EdgeLine);
2742 m_edit_area->setEdgeMode (QsciScintilla::EdgeNone);
2745 m_edit_area->setWrapVisualFlags (QsciScintilla::WrapFlagByBorder);
2746 m_edit_area->setWrapIndentMode (QsciScintilla::WrapIndentSame);
2749 m_edit_area->setWrapMode (QsciScintilla::WrapWord);
2751 m_edit_area->setWrapMode (QsciScintilla::WrapNone);
2772 bool cursor_blinking;
2779 if (cursor_blinking)
2780 m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD,500);
2782 m_edit_area->SendScintilla (QsciScintillaBase::SCI_SETCARETPERIOD,0);
2812 if (decision == QMessageBox::Yes)
2827 if (decision == QMessageBox::Save)
2845 if (ID !=
this || ID ==
nullptr)
2862 int editor_linenr = -1;
2865 if (editor_linenr != -1)
2873 int original_linenr = -1;
2876 if (original_linenr >= 0)
2879 int linenr_guess = editor_linenr +
line - original_linenr;
2908 dp, SLOT (handle_remove_via_original_linenr (
int)));
2910 dp, SLOT (handle_remove (
void)));
2918 if (ID !=
this || ID ==
nullptr)
2927 const QString& cond)
2929 if (ID !=
this || ID ==
nullptr)
2936 int editor_linenr = -1;
2944 if ((cond ==
"") != (bp->
get_cond () ==
""))
2962 bp, SLOT (handle_remove_via_original_linenr (
int)));
2965 bp, SLOT (handle_request_remove_via_editor_linenr
2968 bp, SLOT (handle_remove (
void)));
2971 bp, SLOT (handle_find_translation (
int,
int&,
2974 bp, SLOT (handle_find_just_before (
int,
int&,
int&)));
2977 bp, SLOT (handle_report_editor_linenr (
QIntList&,
2979 connect (bp, SIGNAL (request_remove (
int)),
2990 long int visible_lines
2991 =
m_edit_area->SendScintilla (QsciScintillaBase::SCI_LINESONSCREEN);
2993 if (visible_lines > 2)
3004 int first_line =
m_edit_area->firstVisibleLine ();
3006 if (always || vis_line == first_line
3007 || vis_line > first_line + visible_lines - 2)
3009 first_line += (vis_line - first_line - (visible_lines - 1) / 2);
3027 if (
m_edit_area->SendScintilla (QsciScintillaBase::SCI_AUTOCACTIVE))
3079 if (! style_comment)
3090 int col_space = col;
3095 while (c !=
' ' && c !=
'\t' && col_space > indentation)
3098 c =
m_edit_area->SendScintilla (QsciScintillaBase::SCI_GETCHARAT, pos);
3103 int col_newline = col - 1;
3104 if (c ==
' ' || c ==
'\t')
3105 col_newline = col_space + 1;
3109 QString newline = QString (
"\n");
3118 m_edit_area->SendScintilla (QsciScintillaBase::SCI_LINEEND);
3145 word = word.trimmed ();
3147 if (! word.isEmpty ())
3152 int first_line =
m_edit_area->firstVisibleLine ();
3153 int x_offset =
m_edit_area->SendScintilla(QsciScintillaBase::SCI_GETXOFFSET);
3156 bool find_result_available
3165 #
if defined (HAVE_QSCI_VERSION_2_6_0)
3172 int wlen = word.length ();
3174 while (find_result_available)
3188 m_edit_area->SendScintilla(QsciScintillaBase::SCI_SETXOFFSET, x_offset);
3199 QRegExp rxfun1 (
"^[\t ]*function[^=]+=([^\\(]+)\\([^\\)]*\\)[\t ]*$");
3200 QRegExp rxfun2 (
"^[\t ]*function[\t ]+([^\\(]+)\\([^\\)]*\\)[\t ]*$");
3201 QRegExp rxfun3 (
"^[\t ]*function[^=]+=[\t ]*([^\\s]+)[\t ]*$");
3202 QRegExp rxfun4 (
"^[\t ]*function[\t ]+([^\\s]+)[\t ]*$");
3203 QRegExp rxfun5 (
"^[\t ]*classdef[\t ]+([^\\s]+)[\t ]*$");
3205 QStringList lines =
m_edit_area->text ().split (
"\n");
3207 for (
int i = 0; i < lines.count (); i++)
3209 if (rxfun1.indexIn (lines.at (i)) != -1)
3210 return rxfun1.cap (1).remove (QRegExp (
"[ \t]*"));
3211 else if (rxfun2.indexIn (lines.at (i)) != -1)
3212 return rxfun2.cap (1).remove (QRegExp (
"[ \t]*"));
3213 else if (rxfun3.indexIn (lines.at (i)) != -1)
3214 return rxfun3.cap (1).remove (QRegExp (
"[ \t]*"));
3215 else if (rxfun4.indexIn (lines.at (i)) != -1)
3216 return rxfun4.cap (1).remove (QRegExp (
"[ \t]*"));
3217 else if (rxfun5.indexIn (lines.at (i)) != -1)
3218 return rxfun5.cap (1).remove (QRegExp (
"[ \t]*"));
octave_idx_type numel(void) const
Number of elements in the array.
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
bool condition_valid(const std::string &cond)
std::map< int, int > intmap
static bool interrupt(bool=true)
void interpreter_try(octave::unwind_protect &frame)
void set_encoding(const QString &new_encoding)
void confirm_dbquit_and_save_signal(const QString &file_to_save, const QString &base_name, bool remove_on_success, bool restore_breakpoints)
void set_file_name(const QString &fileName)
void goto_line(const QWidget *ID, int line=-1)
void report_marker_linenr(QIntList &lines, QStringList &conditions)
QsciScintilla::EolMode m_save_as_desired_eol
void toggle_breakpoint(const QWidget *ID)
void zoom_out(const QWidget *ID)
void delete_debugger_pointer(const QWidget *ID, int line=-1)
QStringList m_bp_conditions
void run_file(const QWidget *ID, bool step_into=false)
void remove_breakpoint_via_debugger_linenr(int debugger_linenr)
void save_file_as(const QWidget *ID)
void tab_ready_to_close(void)
void set_current_directory(const QString &dir)
void handle_file_resave_answer(int decision)
file_editor_tab(base_qobject &oct_qobj, const QString &directory="")
A file_editor_tab object consists of a text area and three left margins.
bool m_line_break_comments
void handle_margin_clicked(int line, int margin, Qt::KeyboardModifiers state)
void editor_state_changed(bool copy_available, bool is_octave_file)
void handle_save_as_filter_selected(const QString &filter)
void check_restore_breakpoints(void)
void handle_double_click(int p, int l, int modifier)
void update_breakpoints()
octave_qscintilla * m_edit_area
void set_modified(bool modified=true)
void dbstop_if(const QString &prompt, int line, const QString &cond)
void handle_request_add_breakpoint(int line, const QString &cond)
void zoom_normal(const QWidget *ID)
void set_focus_editor_signal(QWidget *)
void editor_check_conflict_save(const QString &saveFileName, bool remove_on_success)
void interpreter_event(const fcn_callback &fcn)
bool check_valid_identifier(QString file_name)
QString load_file(const QString &fileName)
void next_bookmark(const QWidget *ID)
void previous_breakpoint(const QWidget *ID)
void convert_eol(const QWidget *ID, QsciScintilla::EolMode)
void save_file(const QWidget *ID)
void handle_save_file_as_answer(const QString &fileName)
void add_breakpoint_event(const bp_info &info)
void toggle_bookmark(const QWidget *ID)
bool m_highlight_all_occurrences
void do_comment_selected_text(bool comment, bool input_str=false)
void handle_remove_next(int remove_line)
void handle_file_reload_answer(int decision)
void notice_settings(const gui_settings *settings, bool init=false)
void set_focus(const QWidget *ID)
QFileSystemWatcher m_file_system_watcher
void unindent_selected_text(const QWidget *ID)
void update_window_title(bool modified)
void handle_cursor_moved(int line, int col)
void do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1, const QString &cond="")
void request_remove_breakpoint_via_editor_linenr(int editor_linenr)
void update_breakpoints_signal(const octave_value_list &args)
void handle_save_file_as_answer_close(const QString &fileName)
void insert_debugger_pointer(const QWidget *ID, int line=-1)
void move_match_brace(const QWidget *ID, bool select)
void next_breakpoint(const QWidget *ID)
void find_linenr_just_before(int linenr, int &original_linenr, int &editor_linenr)
void show_dialog(QDialog *dlg, bool modal)
void edit_mfile_request(const QString &, const QString &, const QString &, int)
void do_indent_selected_text(bool indent)
void handle_context_menu_edit(const QString &)
void previous_bookmark(const QWidget *ID)
void handle_api_entries_added(void)
void request_add_breakpoint(int line, const QString &cond)
void update_breakpoints_handler(const octave_value_list &argout)
void handle_save_file_as_answer_cancel(void)
void print_file(const QWidget *ID)
bool m_always_reload_changed_files
void do_save_file_signal(const QString &file_to_save, bool remove_on_success, bool restore_breakpoints)
void run_file_signal(const QFileInfo &info)
bool conditional_close(void)
void update_lexer_settings(void)
void indent_selected_text(const QWidget *ID)
QStatusBar * m_status_bar
bool valid_file_name(const QString &file=QString())
void file_name_changed(const QString &fileName, const QString &toolTip, bool modified)
void smart_indent_line_or_selected_text(const QWidget *ID)
void closeEvent(QCloseEvent *event)
base_qobject & m_octave_qobj
void do_save_file(const QString &file_to_save, bool remove_on_success, bool restore_breakpoints)
int check_file_modified(bool remove=false)
QString get_function_name(void)
void context_edit(const QWidget *ID)
void uncomment_selected_text(const QWidget *ID)
void handle_current_enc_changed(const QString &enc)
void tab_remove_request(void)
void do_smart_indent_line_or_selected_text(void)
void handle_add_octave_apis(const QStringList &api_entries)
void context_help(const QWidget *ID, bool)
void remove_bookmark(const QWidget *ID)
void find_translated_line_number(int original_linenr, int &translated_linenr, marker *&)
void recover_from_exit(void)
void auto_margin_width(void)
void context_run(const QWidget *ID)
void handle_decode_warning_answer(QAbstractButton *btn)
void confirm_dbquit_and_save(const QString &file_to_save, const QString &base_name, bool remove_on_success, bool restore_breakpoints)
QDateTime m_last_modified
void scintilla_command(const QWidget *, unsigned int)
void comment_selected_text(const QWidget *ID, bool input_str)
QsciScintilla::EolMode detect_eol_mode(void)
void change_editor_state(const QWidget *ID)
void maybe_remove_next(int remove_line)
void edit_area_changed(octave_qscintilla *edit_area)
bool unchanged_or_saved(void)
void remove_all_breakpoints(void)
void zoom_in(const QWidget *ID)
void remove_all_positions(void)
void handle_context_menu_break_condition(int linenr)
void handle_char_added(int character)
void handle_lines_changed(void)
void file_has_changed(const QString &path, bool do_close=false)
void handle_request_remove_breakpoint(int line)
void save_apis_info(void)
void mru_add_file(const QString &file_name, const QString &encoding)
void api_entries_added(void)
void request_open_file(const QString &, const QString &=QString())
void handle_dbstop_if(const QString &prompt, int line, const QString &cond)
void center_current_line(bool always=true)
void remove_position_via_debugger_linenr(int debugger_linenr)
QString file_name(void) const
QTextCodec * check_valid_codec(void)
void update_eol_indicator(void)
void new_file(const QString &commands=QString())
void show_auto_completion(const QWidget *ID)
breakpoint_info m_breakpoint_info
void request_add_octave_apis(const QStringList &)
void handle_copy_available(bool enableCopy)
std::list< std::string > autoloaded_functions(void) const
load_path & get_load_path(void)
void recover_from_exception(void)
symbol_table & get_symbol_table(void)
error_system & get_error_system(void)
tree_evaluator & get_evaluator(void)
lexer(interpreter &interp)
bool contains_file_in_dir(const std::string &file_name, const std::string &dir_name)
string_vector fcn_names(void) const
@ unsure_debugger_position
const QString & get_cond(void) const
void set_cond(const QString &cond)
void get_current_position(int *pos, int *line, int *col)
void smart_indent_line_or_selected_text(int lineFrom, int lineTo)
void set_selection_marker_color(const QColor &c)
void smart_indent(bool do_smart_indent, int do_auto_close, int line, int ind_char_width)
void set_word_selection(const QString &word=QString())
QStringList comment_string(bool comment=true)
void show_selection_markers(int l1, int c1, int l2, int c2)
void clear_selection_markers(void)
int is_style_comment(int pos=-1)
void context_help_doc(bool)
void combo_encoding(QComboBox *combo, const QString ¤t=QString())
gui_settings * get_settings(void) const
void clear_user_function(const std::string &name)
std::list< std::string > built_in_function_names(void)
bool in_debug_repl(void) const
bp_table & get_bp_table(void)
void dbquit(bool all=false)
octave_map backtrace(octave_idx_type &curr_user_frame, bool print_subfn=true) const
virtual octave_user_code * user_code_value(bool silent=false)
octave_idx_type numel(void) const
const Cell & contents(const_iterator p) const
Cell cell_value(void) const
octave_idx_type numel(void) const
OCTAVE_EXPORT octave_value_list Fdbstatus(octave::interpreter &interp, const octave_value_list &args, int nargout)
MArray< T > filter(MArray< T > &b, MArray< T > &a, MArray< T > &x, MArray< T > &si, int dim=0)
const gui_pref cs_cursor_blinking("terminal/cursorBlinking", QVariant(true))
const gui_pref ed_always_reload_changed_files("editor/always_reload_changed_files", QVariant(false))
const gui_pref ed_indent_uses_tabs("editor/indent_uses_tabs", QVariant(false))
const gui_pref ed_code_completion("editor/codeCompletion", QVariant(true))
const gui_pref ed_show_hscroll_bar("editor/show_hscroll_bar", QVariant(true))
const gui_pref ed_code_completion_octave_functions("editor/codeCompletion_octave_functions", QVariant(true))
const gui_pref ed_auto_endif("editor/auto_endif", QVariant(1))
const gui_pref ed_highlight_current_line_color("editor/highlight_current_line_color", QVariant(QColor(240, 240, 240)))
const gui_pref ed_long_window_title("editor/longWindowTitle", QVariant(false))
const gui_pref ed_show_white_space("editor/show_white_space", QVariant(false))
const gui_pref ed_default_enc("editor/default_encoding", QVariant(QString("SYSTEM (")+QString(octave_locale_charset_wrapper()).toUpper()+QString(")")))
const gui_pref ed_line_numbers_size("editor/line_numbers_size", QVariant(0))
const gui_pref ed_wrap_lines("editor/wrap_lines", QVariant(false))
const gui_pref ed_highlight_current_line("editor/highlightCurrentLine", QVariant(true))
const gui_pref ed_code_completion_threshold("editor/codeCompletion_threshold", QVariant(2))
const gui_pref ed_break_lines("editor/break_lines", QVariant(false))
const gui_pref ed_break_lines_comments("editor/break_lines_comments", QVariant(false))
const QString ed_last_comment_str("editor/oct_last_comment_str")
const gui_pref ed_long_line_marker("editor/long_line_marker", QVariant(true))
const gui_pref ed_tab_indents_line("editor/tab_indents_line", QVariant(false))
const gui_pref ed_code_completion_octave_builtins("editor/codeCompletion_octave_builtins", QVariant(true))
const gui_pref ed_show_edit_status_bar("editor/show_edit_status_bar", QVariant(true))
const gui_pref ed_code_completion_document("editor/codeCompletion_document", QVariant(true))
const gui_pref ed_backspace_unindents_line("editor/backspace_unindents_line", QVariant(false))
const gui_pref ed_code_completion_case("editor/codeCompletion_case", QVariant(true))
const gui_pref ed_long_line_marker_background("editor/long_line_marker_background", QVariant(false))
const gui_pref ed_show_white_space_indent("editor/show_white_space_indent", QVariant(false))
const gui_pref ed_show_line_numbers("editor/showLineNumbers", QVariant(true))
const gui_pref ed_highlight_all_occurrences("editor/highlight_all_occurrences", QVariant(true))
const gui_pref ed_show_eol_chars("editor/show_eol_chars", QVariant(false))
const gui_pref ed_show_indent_guides("editor/show_indent_guides", QVariant(false))
const gui_pref ed_code_folding("editor/code_folding", QVariant(true))
const gui_pref ed_indent_width("editor/indent_width", QVariant(2))
const gui_pref ed_tab_width("editor/tab_width", QVariant(2))
const gui_pref ed_long_line_column("editor/long_line_column", QVariant(80))
const gui_pref ed_default_eol_mode("editor/default_eol_mode", QVariant(os_eol_mode))
const gui_pref ed_code_completion_replace("editor/codeCompletion_replace", QVariant(false))
const gui_pref ed_code_completion_keywords("editor/codeCompletion_keywords", QVariant(true))
const gui_pref ed_auto_indent("editor/auto_indent", QVariant(true))
const gui_pref ed_long_line_marker_line("editor/long_line_marker_line", QVariant(true))
const gui_pref global_use_native_dialogs("use_native_file_dialogs", QVariant(true))
const gui_pref global_cursor_blinking("cursor_blinking", QVariant(true))
OCTAVE_EXPORT octave_value_list Fiskeyword(const octave_value_list &args, int)
const char * octave_locale_charset_wrapper(void)
for(octave_idx_type i=0;i< n;i++) ac+
QString fromStdString(const std::string &s)
std::string toStdString(const QString &s)
std::string concat(const std::string &dir, const std::string &file)
std::string dir_sep_chars(void)
std::string canonicalize_file_name(const std::string &name)
static uint32_t state[624]
bool valid_identifier(const char *s)
std::function< void(octave::interpreter &)> meth_callback
static double f(double k, double l_nu, double c_pm)
std::function< void(void)> fcn_callback
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
static OCTAVE_NORETURN void eval_error(const char *msg, const dim_vector &x, const dim_vector &y)
bp_info(const QString &fname, int l=0, const QString &cond="")
std::string function_name
char * octave_u32_conv_to_encoding_strict(const char *tocode, const uint32_t *src, size_t srclen, size_t *lengthp)