25 #if defined (HAVE_CONFIG_H) 29 #if defined (HAVE_QSCINTILLA) 31 #include <Qsci/qscilexer.h> 33 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) 34 # define HAVE_LEXER_OCTAVE 1 35 # include <Qsci/qscilexeroctave.h> 36 #elif defined (HAVE_QSCI_QSCILEXERMATLAB_H) 37 # define HAVE_LEXER_MATLAB 1 38 # include <Qsci/qscilexermatlab.h> 40 #include <Qsci/qscilexercpp.h> 41 #include <Qsci/qscilexerbash.h> 42 #include <Qsci/qscilexerperl.h> 43 #include <Qsci/qscilexerbatch.h> 44 #include <Qsci/qscilexerdiff.h> 46 #include <Qsci/qscicommandset.h> 48 #include <QKeySequence> 51 #include <QVBoxLayout> 70 is_end (
const QString& candidate,
const QString& opening)
76 if (candidate ==
"until")
81 if (candidate ==
"end")
87 if (candidate ==
"catch" || candidate ==
"end_try_catch")
90 else if (opening ==
"unwind_protect")
92 if (candidate ==
"unwind_protect_cleanup" 93 || candidate ==
"end_unwind_protect")
96 else if (candidate ==
"end" + opening)
98 else if (opening ==
"if" && candidate ==
"else")
110 m_selection_replacement (), m_selection_line (-1),
111 m_selection_col (-1), m_indicator_id (1)
113 connect (
this, SIGNAL (textChanged (
void)),
116 connect (
this, SIGNAL (cursorPositionChanged (
int,
int)),
120 QsciCommandSet *cmd_set = standardCommands ();
123 SendScintilla (SCI_SETBUFFEREDDRAW,
false);
125 #if defined (HAVE_QSCI_VERSION_2_6_0) 127 cmd_set->find (QsciCommand::SelectionCopy)->setKey (0);
128 cmd_set->find (QsciCommand::SelectionCut)->setKey (0);
129 cmd_set->find (QsciCommand::Paste)->setKey (0);
130 cmd_set->find (QsciCommand::SelectAll)->setKey (0);
131 cmd_set->find (QsciCommand::SelectionDuplicate)->setKey (0);
132 cmd_set->find (QsciCommand::LineTranspose)->setKey (0);
133 cmd_set->find (QsciCommand::Undo)->setKey (0);
134 cmd_set->find (QsciCommand::Redo)->setKey (0);
135 cmd_set->find (QsciCommand::SelectionUpperCase)->setKey (0);
136 cmd_set->find (QsciCommand::SelectionLowerCase)->setKey (0);
137 cmd_set->find (QsciCommand::ZoomIn)->setKey (0);
138 cmd_set->find (QsciCommand::ZoomOut)->setKey (0);
139 cmd_set->find (QsciCommand::DeleteWordLeft)->setKey (0);
140 cmd_set->find (QsciCommand::DeleteWordRight)->setKey (0);
141 cmd_set->find (QsciCommand::DeleteLineLeft)->setKey (0);
142 cmd_set->find (QsciCommand::DeleteLineRight)->setKey (0);
143 cmd_set->find (QsciCommand::LineDelete)->setKey (0);
144 cmd_set->find (QsciCommand::LineCut)->setKey (0);
145 cmd_set->find (QsciCommand::LineCopy)->setKey (0);
149 for (
int i = 0;
i < cmd_list.length ();
i++)
151 int cmd_key = cmd_list.at (
i)->key ();
162 case Qt::Key_Z |
Qt::CTRL | Qt::SHIFT :
164 case Qt::Key_U |
Qt::CTRL | Qt::SHIFT :
167 case Qt::Key_Backspace |
Qt::CTRL | Qt::SHIFT :
168 case Qt::Key_Delete |
Qt::CTRL | Qt::SHIFT :
169 case Qt::Key_K | Qt::META :
172 case Qt::Key_L |
Qt::CTRL | Qt::SHIFT :
174 case Qt::Key_T |
Qt::CTRL | Qt::SHIFT :
175 cmd_list.at (
i)->setKey (0);
180 #if defined (Q_OS_MAC) 184 for (
int i = 0;
i < cmd_list_mac.length ();
i++)
187 int key = cmd_list_mac.at (
i)->key ();
189 if (static_cast<int> (key | Qt::META) == key &&
190 static_cast<int> (key |
Qt::CTRL) != key)
192 else if (static_cast<int> (key |
Qt::CTRL) == key)
195 cmd_list_mac.at (
i)->setKey (key);
198 key = cmd_list_mac.at (
i)->alternateKey ();
200 if (static_cast<int> (key | Qt::META) == key &&
201 static_cast<int> (key |
Qt::CTRL) != key)
203 else if (static_cast<int> (key |
Qt::CTRL) == key)
206 cmd_list_mac.at (
i)->setAlternateKey (key);
212 m_indicator_id = indicatorDefine (QsciScintilla::StraightBoxIndicator);
238 #if defined (HAVE_QSCI_VERSION_2_6_0) 239 QPoint global_pos, local_pos;
240 QMenu *context_menu = createStandardContextMenu ();
242 bool in_left_margin =
false;
245 if (
e->reason () == QContextMenuEvent::Mouse)
248 global_pos =
e->globalPos ();
249 local_pos =
e->pos ();
250 if (
e->x () < marginWidth (1) + marginWidth (2))
251 in_left_margin =
true;
257 QRect editor_rect = geometry ();
258 editor_rect.moveTopLeft
259 (parentWidget ()->mapToGlobal (editor_rect.topLeft ()));
260 if (! editor_rect.contains (global_pos))
261 global_pos = editor_rect.topLeft ();
264 #if defined (HAVE_QSCI_VERSION_2_6_0) 265 if (! in_left_margin)
272 context_menu->addSeparator ();
277 if (lexer_name ==
"octave" || lexer_name ==
"matlab")
284 context_menu->addAction (tr (
"Documentation on")
292 #if defined (HAVE_QSCI_VERSION_2_6_0) 299 foreach (
a, all_actions)
300 context_menu->removeAction (
a);
302 a = context_menu->addAction (tr (
"dbstop if ..."),
this,
304 a->setData (local_pos);
309 context_menu->exec (global_pos);
332 if (hasSelectedText ())
339 long position = SendScintilla (SCI_GETCURRENTPOS);
340 long point_x = SendScintilla (SCI_POINTXFROMPOSITION,0,position);
341 long point_y = SendScintilla (SCI_POINTYFROMPOSITION,0,position);
342 *local_pos = QPoint (point_x,point_y);
343 *global_pos = mapToGlobal (*local_pos);
349 QPoint global_pos, local_pos;
353 return ((lexer_name ==
"octave" || lexer_name ==
"matlab")
361 int end_line, end_col;
362 lineIndexFromPosition (end_pos, &end_line, &end_col);
372 *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS);
373 *
line = SendScintilla (QsciScintillaBase::SCI_LINEFROMPOSITION, *pos);
374 *col = SendScintilla (QsciScintillaBase::SCI_GETCOLUMN, *pos);
380 int lexer = SendScintilla (SCI_GETLEXER);
384 #if defined (HAVE_LEXER_OCTAVE) || defined (HAVE_LEXER_MATLAB) 385 #if defined (HAVE_LEXER_OCTAVE) 431 return QStringList (
"#");
434 return QStringList (
"//");
437 return QStringList (
"REM ");
440 return QStringList (
"%");
450 position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS) - 2;
454 return SendScintilla (QsciScintillaBase::SCI_GETSTYLEAT, position);
460 int lexer = SendScintilla (QsciScintillaBase::SCI_GETLEXER);
467 style == QsciLexerCPP::CommentLine
468 || style == QsciLexerCPP::CommentLineDoc)
470 style == QsciLexerCPP::Comment
471 || style == QsciLexerCPP::CommentDoc
472 || style == QsciLexerCPP::CommentDocKeyword
473 || style == QsciLexerCPP::CommentDocKeywordError)
476 #if defined (HAVE_LEXER_MATLAB) 480 #if defined (HAVE_LEXER_OCTAVE) 504 int do_auto_close,
int line)
508 QRegExp bkey = QRegExp (
"^[\t ]*(if|for|while|switch|case|otherwise" 509 "|do|function|properties|events|classdef" 510 "|unwind_protect|unwind_protect_cleanup|try" 519 QRegExp ekey = QRegExp (
"(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" 520 "(\\w+)[ \t;\r\n]*([%#].*)?$");
522 int bpos = bkey.indexIn (prevline, 0);
530 epos = ekey.indexIn (prevline, bpos);
531 QString first_word = bkey.cap(1);
532 bool inline_end = (epos > -1) &&
is_end (ekey.cap(1), first_word);
534 if (do_smart_indent && ! inline_end)
538 setCursorPosition (
line+1, indentation (
line) + indentationWidth ());
543 && ! first_word.contains (
544 QRegExp (
"(case|otherwise|unwind_protect_cleanup)")))
553 QRegExp mkey = QRegExp (
"^[\t ]*(else|elseif|catch)[\r]?[\t #%\n]");
554 if (prevline.contains (mkey))
556 int prev_ind = indentation (
line-1);
557 int act_ind = indentation (
line);
559 if (prev_ind == act_ind)
561 else if (prev_ind > act_ind)
563 setIndentation (
line+1, prev_ind);
564 setCursorPosition (
line+1, prev_ind);
569 ekey = QRegExp (
"^[\t ]*(end|endif|endfor|endwhile|until|endfunction" 570 "|end_try_catch|end_unwind_protext)[\r]?[\t #%\n(;]");
571 if (prevline.contains (ekey))
573 if (indentation (
line-1) <= indentation (
line))
577 setCursorPosition (
line+1,
588 QRegExp blank_line_regexp = QRegExp (
"^[\t ]*$");
590 QRegExp begin_block_regexp
591 = QRegExp (
"^([\t ]*)(if|elseif|else" 592 "|for|while|do|parfor" 593 "|switch|case|otherwise" 595 "|classdef|properties|events|enumeration|methods" 596 "|unwind_protect|unwind_protect_cleanup|try|catch)" 599 QRegExp end_block_regexp
600 = QRegExp (
"^([\t ]*)(end" 601 "|end(for|function|if|parfor|switch|while" 602 "|classdef|enumeration|events|methods|properties)" 603 "|end_(try_catch|unwind_protect)" 607 int indent_column = -1;
608 int indent_increment = indentationWidth ();
614 if (blank_line_regexp.indexIn (line_text) < 0)
621 indent_column = indentation (
line);
623 if (begin_block_regexp.indexIn (line_text) > -1)
624 indent_column += indent_increment;
630 if (indent_column < 0)
631 indent_column = indentation (lineFrom);
637 if (end_block_regexp.indexIn (line_text) > -1)
638 indent_column -= indent_increment;
640 setIndentation (
line, indent_column);
642 if (begin_block_regexp.indexIn (line_text) > -1)
643 indent_column += indent_increment;
660 QToolTip::hideText ();
699 QStringList
commands = selectedText ().split (QRegExp (
"[\r\n]"),
700 QString::SkipEmptyParts);
710 #if defined (HAVE_QSCI_VERSION_2_6_0) 711 QAction *action = qobject_cast<QAction *>(sender ());
712 QPoint local_pos = action->data ().value<QPoint> ();
715 int margins = marginWidth (1) + marginWidth (2) + marginWidth (3);
716 local_pos = QPoint (margins + 1, local_pos.y ());
724 #if defined (HAVE_QSCI_VERSION_2_6_0) 751 QsciScintilla::focusInEvent (focusEvent);
761 QKeySequence keyseq = Qt::SHIFT + Qt::Key_Return;
763 QString msg = (tr (
"Press '%1' to replace all occurrences of '%2' with '%3'.")
764 .
arg (keyseq.toString ())
773 QFontMetrics ttfm (QToolTip::font ());
778 global_pos += QPoint (2*ttfm.maxWidth (), -3*ttfm.height ());
780 QToolTip::showText (global_pos, msg);
786 QsciScintilla::keyPressEvent (key_event);
789 int key = key_event->key ();
790 Qt::KeyboardModifiers modifiers = key_event->modifiers ();
792 if (key == Qt::Key_Return && modifiers == Qt::ShiftModifier)
800 int first_line = firstVisibleLine ();
803 bool find_result_available
812 #
if defined (HAVE_QSCI_VERSION_2_6_0)
817 while (find_result_available)
825 int new_line, new_col;
828 find_result_available
837 #
if defined (HAVE_QSCI_VERSION_2_6_0)
845 setFirstVisibleLine (first_line);
846 setCursorPosition (
line, col);
862 bool cancel_replacement =
false;
864 if (key == Qt::Key_Backspace)
867 cancel_replacement =
true;
871 else if (key == Qt::Key_Delete || key == Qt::Key_Escape)
872 cancel_replacement =
true;
873 else if (!
text.isEmpty ())
875 else if (modifiers != Qt::ShiftModifier)
876 cancel_replacement =
true;
880 QsciScintilla::keyPressEvent (key_event);
882 if (cancel_replacement)
892 const QString&
line, QString& first_word)
899 bool autofill_simple_end = (auto_endif == 2);
901 size_t start =
line.toStdString ().find_first_not_of (
" \t");
906 if (linenr < lines () - 1)
913 next_line =
text (linenr + offset++);
914 next_start = next_line.toStdString ().find_first_not_of (
" \t\n");
916 while (linenr + offset < lines ()
917 && next_start == std::string::npos);
918 if (next_start == std::string::npos)
920 if (next_start >
start)
922 if (next_start ==
start)
924 QRegExp rx_start = QRegExp (R
"((\w+))"); 925 int tmp = rx_start.indexIn (next_line,
start);
926 if (
tmp != -1 &&
is_end (rx_start.cap(1), first_word))
936 if (linenr + 2 == lines ())
937 insertAt (QString (
"\n"), linenr + 2, 0);
940 if (first_word ==
"try")
941 insertAt (QString (
start,
' ')
942 + (autofill_simple_end ?
"end\n" :
"end_try_catch\n"),
944 else if (first_word ==
"unwind_protect")
945 insertAt (QString (
start,
' ')
946 + (autofill_simple_end ?
"end\n" :
"end_unwind_protect\n"),
950 if (first_word ==
"do")
951 next_line =
"until\n";
952 else if (first_word ==
"try")
953 next_line =
"catch\n";
954 else if (first_word ==
"unwind_protect")
955 next_line =
"unwind_protect_cleanup\n";
956 else if (autofill_simple_end)
960 if (first_word ==
"unwind_protect")
961 first_word =
'_' + first_word;
962 next_line =
"end" + first_word +
"\n";
965 insertAt (QString (
start,
' ') + next_line, linenr + 2, 0);
973 if (!
e->mimeData ()->hasUrls ())
975 QsciScintilla::dragEnterEvent (
e);
void contextmenu_help_doc(bool)
void execute_command_in_terminal_signal(const QString &)
void context_help_doc(bool)
const QStringList oct_comment_strings(QStringList()<< "##"<< "#"<< "%"<< "%%"<< "%!")
void status_update(bool, bool)
void contextmenu_break_condition(bool)
octave_qscintilla(QWidget *p)
void contextmenu_run(bool)
void set_word_selection(const QString &word=QString())
const int oct_comment_str_d
void get_global_textcursor_pos(QPoint *global_pos, QPoint *local_pos)
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
void contextmenu_help(bool)
bool get_actual_word(void)
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
void dragEnterEvent(QDragEnterEvent *e)
const QString oct_comment_str("editor/oct_comment_str")
void context_menu_break_once(int)
void focusInEvent(QFocusEvent *focusEvent)
void get_current_position(int *pos, int *line, int *col)
QStringList comment_string(bool comment=true)
const int oct_uncomment_str_d
text(const graphics_handle &mh, const graphics_handle &p)
int is_style_comment(int pos=-1)
const QString oct_comment_str_old("editor/octave_comment_string")
QString m_selection_replacement
void clear_selection_markers(void)
int get_style(int pos=-1)
void create_context_menu_signal(QMenu *)
OCTAVE_EXPORT octave_value_list the first data row corresponds to an index of zero The a spreadsheet style form such as the file is read until end of file is reached The such as text
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is defined
static bool is_end(const QString &candidate, const QString &opening)
void cursor_position_changed(int, int)
const QString oct_uncomment_str("editor/oct_uncomment_str")
octave_idx_type length(void) const
void contextmenu_break_once(const QPoint &)
void context_menu_break_condition_signal(int)
void show_doc_signal(const QString &)
static QSettings * get_settings(void)
void smart_indent(bool do_smart_indent, int do_auto_close, int line)
void contextmenu_edit(bool)
void auto_close(int auto_endif, int l, const QString &line, QString &first_word)
lexer(interpreter *interp=nullptr)
void keyPressEvent(QKeyEvent *e)
const int oct_comment_strings_count
void smart_indent_line_or_selected_text(int lineFrom, int lineTo)
void set_selection_marker_color(const QColor &c)
void contextmenu_doc(bool)
void show_replace_action_tooltip(void)
void show_selection_markers(int line, int col, int len)
virtual void contextMenuEvent(QContextMenuEvent *e)
to define functions rather than attempting to enter them directly on the command line The block of commands is executed as soon as you exit the editor To avoid executing any commands
void context_menu_edit_signal(const QString &)