27 #ifdef HAVE_QSCINTILLA
33 #include <QVBoxLayout>
34 #include <QApplication>
37 #include <QFileDialog>
38 #include <QMessageBox>
40 #include <QTextStream>
43 #include <QInputDialog>
44 #include <Qsci/qscicommandset.h>
55 ced = QDir::currentPath ();
81 QStringList fetFileNames;
85 QString file_name = p->first;
86 if (!file_name.isEmpty ())
87 fetFileNames.append (p->first);
90 settings->setValue (
"editor/savedSessionTabs", fetFileNames);
186 QString new_name = QInputDialog::getText (
this, tr (
"New Function"),
187 tr (
"New function name:\n"), QLineEdit::Normal,
"", &ok);
188 if (ok && new_name.length () > 0)
191 if (new_name.rightRef (2) !=
".m")
192 new_name.append (
".m");
195 if (! settings->value (
"editor/create_new_file",
false).toBool ())
198 settings->setValue (
"editor/create_new_file",
true);
212 settings->setValue (
"editor/create_new_file",
false);
226 fileDialog->setNameFilter (tr (
"Octave Files (*.m);;All Files (*)"));
231 fileDialog->setOption(QFileDialog::DontUseNativeDialog,
true);
233 fileDialog->setAcceptMode (QFileDialog::AcceptOpen);
234 fileDialog->setViewMode (QFileDialog::Detail);
235 fileDialog->setFileMode (QFileDialog::ExistingFiles);
236 fileDialog->setDirectory (
ced);
238 connect (fileDialog, SIGNAL (filesSelected (
const QStringList&)),
241 fileDialog->setWindowModality (Qt::NonModal);
242 fileDialog->setAttribute (Qt::WA_DeleteOnClose);
255 QString tab_file = p->first;
257 if (
same_file (file.toStdString (), tab_file.toStdString ()))
273 if (settings->value (
"useCustomFileEditor",
false).toBool ())
278 QString editor = settings->value (
"customFileEditor").toString ();
279 editor.replace (
"%f", file_name);
280 editor.replace (
"%l", QString::number (line));
282 bool started_ok = QProcess::startDetached (editor);
284 if (started_ok !=
true)
288 tr (
"Octave Editor"),
289 tr (
"Could not start custom file editor\n%1").
291 QMessageBox::Ok,
this);
293 msgBox->setWindowModality (Qt::NonModal);
294 msgBox->setAttribute (Qt::WA_DeleteOnClose);
298 if (line < 0 && ! file_name.isEmpty ())
315 for (
int i = 0; i < w_list.count (); i++)
317 if (w_list.at (i) == console)
327 for (
int i = 0; i < open_file_names.count (); i++)
334 bool breakpoint_marker,
bool insert)
339 if (openFileName.isEmpty ())
365 if (breakpoint_marker)
380 QString result = fileEditorTab->
load_file (openFileName);
388 QFileInfo file_info = QFileInfo (openFileName);
398 if (breakpoint_marker)
405 delete fileEditorTab;
407 if (QFile::exists (openFileName))
413 tr (
"Octave Editor"),
414 tr (
"Could not open file\n%1\nfor read: %2.").
415 arg (openFileName).
arg (result),
416 QMessageBox::Ok,
this);
418 msgBox->setWindowModality (Qt::NonModal);
419 msgBox->setAttribute (Qt::WA_DeleteOnClose);
425 bool create_file =
true;
429 if (!settings->value (
"editor/create_new_file",
false).toBool ())
432 tr (
"Octave Editor"),
433 tr (
"File\n%1\ndoes not exist. "
434 "Do you want to create it?").
arg (openFileName),
435 QMessageBox::NoButton,0);
437 msgBox->addButton (tr (
"Create"), QMessageBox::YesRole);
438 msgBox->addButton (tr (
"Cancel"), QMessageBox::RejectRole);
439 msgBox->setDefaultButton (create_button);
442 QAbstractButton *clicked_button = msgBox->clickedButton ();
443 if (clicked_button != create_button)
452 QFile file (openFileName);
453 if (!file.open (QIODevice::WriteOnly))
457 tr (
"Octave Editor"),
458 tr (
"Could not open file\n%1\nfor write: %2.").
459 arg (openFileName).
arg (file.errorString ()),
460 QMessageBox::Ok,
this);
462 msgBox->setWindowModality (Qt::NonModal);
463 msgBox->setAttribute (Qt::WA_DeleteOnClose);
499 bool remove_on_success)
519 =
new QMessageBox (QMessageBox::Critical, tr (
"Octave Editor"),
520 tr (
"File not saved! A file with the selected name\n%1\n"
521 "is already open in the editor").
525 msgBox->setWindowModality (Qt::NonModal);
526 msgBox->setAttribute (Qt::WA_DeleteOnClose);
532 QObject *saveFileObject = sender ();
547 =
new QMessageBox (QMessageBox::Critical, tr (
"Octave Editor"),
548 tr (
"The associated file editor tab has disappeared."),
551 msgBox->setWindowModality (Qt::NonModal);
552 msgBox->setAttribute (Qt::WA_DeleteOnClose);
559 emit
fetab_save_file (saveFileWidget, saveFileName, remove_on_success);
573 if (! file.isEmpty ())
612 QsciScintillaBase::SCI_UNDO);
619 QsciScintillaBase::SCI_REDO);
626 QsciScintillaBase::SCI_COPY);
633 QsciScintillaBase::SCI_CUT);
640 QsciScintillaBase::SCI_PASTE);
647 QsciScintillaBase::SCI_SELECTALL);
751 QsciScintillaBase::SCI_DELWORDLEFT);
757 QsciScintillaBase::SCI_DELWORDRIGHT);
763 QsciScintillaBase::SCI_DELLINELEFT);
769 QsciScintillaBase::SCI_DELLINERIGHT);
775 QsciScintillaBase::SCI_LINEDELETE);
781 QsciScintillaBase::SCI_LINECOPY);
787 QsciScintillaBase::SCI_LINECUT);
793 QsciScintillaBase::SCI_SELECTIONDUPLICATE);
799 QsciScintillaBase::SCI_LINETRANSPOSE);
817 QsciScintillaBase::SCI_UPPERCASE);
823 QsciScintillaBase::SCI_LOWERCASE);
841 QsciScintilla::EolWindows);
847 QsciScintilla::EolUnix);
853 QsciScintilla::EolMac);
905 for (
int i = 0; i < num_files; ++i)
907 QString
text = tr (
"&%1 %2").
926 settings->setValue (
"editor/mru_file_list",
_mru_files);
934 QObject *fileEditorTab = sender ();
962 for (
int index =
_tab_widget->count ()-1; index >= 0; index--)
976 for (
int index =
_tab_widget->count ()-1; index >= 0; index--)
999 QObject *fileEditorTab = sender ();
1009 delete fileEditorTab;
1038 foreach (a, all_actions)
1039 menu->removeAction (a);
1044 menu->addSeparator ();
1048 menu->addSeparator ();
1050 menu->addSeparator ();
1058 bool old = settings->value (preference,def).toBool ();
1059 settings->setValue (preference,!old);
1116 bool is_octave_file)
1134 int icon_size_settings = settings->value (
"toolbar_icon_size",0).toInt ();
1135 QStyle *st = style ();
1136 int icon_size = st->pixelMetric (QStyle::PM_ToolBarIconSize);
1138 if (icon_size_settings == 1)
1139 icon_size = st->pixelMetric (QStyle::PM_LargeIconSize);
1140 else if (icon_size_settings == -1)
1141 icon_size = st->pixelMetric (QStyle::PM_SmallIconSize);
1143 _tool_bar->setIconSize (QSize (icon_size,icon_size));
1145 int tab_width_min = settings->value (
"editor/notebook_tab_width_min", 160)
1147 int tab_width_max = settings->value (
"editor/notebook_tab_width_max", 300)
1150 if (settings->value (
"editor/longWindowTitle",
false).toBool ())
1152 QString style_sheet = QString (
"QTabBar::tab "
1153 "{min-width: %1px; max-width: %2px;}")
1154 .arg (tab_width_min).arg (tab_width_max);
1164 show_it = settings->value (
"editor/showLineNumbers",
true).toBool ();
1166 show_it = settings->value (
"editor/show_white_space",
false).toBool ();
1168 show_it = settings->value (
"editor/show_eol_chars",
false).toBool ();
1170 show_it = settings->value (
"editor/show_indent_guides",
false).toBool ();
1172 show_it = settings->value (
"editor/long_line_marker",
true).toBool ();
1195 QAction *new_fcn_action,
1196 QAction *open_action)
1199 _fileMenu->insertAction (open_action, new_fcn_action);
1200 _fileMenu->insertAction (new_fcn_action, new_action);
1202 _tool_bar->insertAction (open_action, new_action);
1209 QAction *a = menu->addAction (icon, text,
this, member);
1211 a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
1218 QHash<QMenu*, QStringList>::const_iterator i =
_hash_menu_text.constBegin();
1222 i.key ()->setTitle (i.value ().at (! enable));
1230 QMenu *menu = p->addMenu (name);
1232 QString base_name = name;
1234 base_name.replace (
"&&",
"___octave_amp_replacement___");
1236 base_name.remove (
"&");
1238 base_name.replace (
"___octave_amp_replacement___",
"&&");
1254 #if defined (Q_OS_MAC)
1257 _tool_bar =
new QToolBar (editor_widget);
1261 #ifdef HAVE_QTABWIDGET_SETMOVABLE
1268 _mru_files = settings->value (
"editor/mru_file_list").toStringList ();
1324 editMenu->addSeparator ();
1335 editMenu->addSeparator ();
1340 editMenu->addSeparator ();
1343 tr (
"&Find and Replace..."), SLOT (
request_find (
bool)));
1345 editMenu->addSeparator ();
1403 tr (
"Convert Line Endings to &Windows (CRLF)"),
1406 tr (
"Convert Line Endings to &Unix (LF)"),
1409 tr (
"Convert Line Endings to &Mac (CR)"),
1435 editMenu->addSeparator ();
1468 view_menu->addSeparator ();
1471 tr (
"Zoom &In"), SLOT (
zoom_in (
bool)));
1473 tr (
"Zoom &Out"), SLOT (
zoom_out (
bool)));
1542 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
1546 vbox_layout->setMargin (0);
1547 editor_widget->setLayout (vbox_layout);
1548 setWidget (editor_widget);
1553 SLOT (process_settings_dialog_request (
const QString&)));
1555 connect (
main_win (), SIGNAL (new_file_signal (
const QString&)),
1558 connect (
main_win (), SIGNAL (open_file_signal (
const QString&)),
1566 connect (
_tab_widget, SIGNAL (tabCloseRequested (
int)),
1569 connect (
_tab_widget, SIGNAL (currentChanged (
int)),
1573 main_win (), SLOT (execute_command_in_terminal (
const QString&)));
1576 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
1580 if (settings->value (
"editor/restoreSession",
true).toBool ())
1582 QStringList sessionFileNames
1583 = settings->value (
"editor/savedSessionTabs",
1584 QStringList ()).toStringList ();
1586 for (
int n = 0; n < sessionFileNames.count (); ++n)
1588 QFileInfo file = QFileInfo (sessionFileNames.at (n));
1603 connect (f->
qsci_edit_area (), SIGNAL (status_update (
bool,
bool)),
1606 connect (f->
qsci_edit_area (), SIGNAL (show_doc_signal (
const QString&)),
1607 main_win (), SLOT (handle_show_doc (
const QString&)));
1609 connect (f->
qsci_edit_area (), SIGNAL (create_context_menu_signal (QMenu *)),
1613 main_win (), SLOT (execute_command_in_terminal (
const QString&)));
1616 connect (f, SIGNAL (file_name_changed (
const QString&,
const QString&)),
1620 connect (f, SIGNAL (editor_state_changed (
bool,
bool)),
1623 connect (f, SIGNAL (tab_remove_request ()),
1626 connect (f, SIGNAL (add_filename_to_list (
const QString&,
QWidget*)),
1629 connect (f, SIGNAL (editor_check_conflict_save (
const QString&,
bool)),
1632 connect (f, SIGNAL (mru_add_file (
const QString&)),
1635 connect (f, SIGNAL (run_file_signal (
const QFileInfo&)),
1636 main_win (), SLOT (run_file_in_terminal (
const QFileInfo&)));
1641 connect (f, SIGNAL (set_global_edit_shortcuts_signal (
bool)),
1642 main_win (), SLOT (set_global_edit_shortcuts (
bool)));
1649 f, SLOT (change_editor_state (
const QWidget*)));
1652 f, SLOT (file_name_query (
const QWidget*)));
1656 f, SLOT (save_file (
const QWidget*,
const QString&,
bool)));
1659 f, SLOT (check_modified_file (
void)));
1663 f, SLOT (set_current_directory (
const QString&)));
1673 f, SLOT (context_help (
const QWidget*,
bool)));
1676 f, SLOT (context_edit (
const QWidget*)));
1679 f, SLOT (save_file (
const QWidget*)));
1685 f, SLOT (print_file (
const QWidget*)));
1688 f, SLOT (run_file (
const QWidget*)));
1691 f, SLOT (context_run (
const QWidget*)));
1694 f, SLOT (toggle_bookmark (
const QWidget*)));
1697 f, SLOT (next_bookmark (
const QWidget*)));
1700 f, SLOT (previous_bookmark (
const QWidget*)));
1703 f, SLOT (remove_bookmark (
const QWidget*)));
1706 f, SLOT (toggle_breakpoint (
const QWidget*)));
1709 f, SLOT (next_breakpoint (
const QWidget*)));
1712 f, SLOT (previous_breakpoint (
const QWidget*)));
1715 f, SLOT (remove_all_breakpoints (
const QWidget*)));
1718 f, SLOT (scintilla_command (
const QWidget *,
unsigned int)));
1721 f, SLOT (comment_selected_text (
const QWidget*)));
1724 f, SLOT (uncomment_selected_text (
const QWidget*)));
1727 f, SLOT (indent_selected_text (
const QWidget*)));
1730 f, SLOT (unindent_selected_text (
const QWidget*)));
1733 f, SLOT (convert_eol (
const QWidget*, QsciScintilla::EolMode)));
1739 f, SLOT (goto_line (
const QWidget*,
int)));
1742 f, SLOT (move_match_brace (
const QWidget*,
bool)));
1745 f, SLOT (show_auto_completion (
const QWidget*)));
1748 f, SLOT (set_focus (
const QWidget*)));
1751 f, SLOT (insert_debugger_pointer (
const QWidget*,
int)));
1754 f, SLOT (delete_debugger_pointer (
const QWidget*,
int)));
1758 f, SLOT (do_breakpoint_marker (
bool,
const QWidget*,
int)));
1769 if (foc_w && foc_w->inherits (
"octave_qscintilla"))
1923 if (settings->value (
"useCustomFileEditor",
false).toBool ())
1929 real_visible = isVisible ();
1931 real_visible = visible;
1936 if (startup && ! isFloating ())
1941 bool in_tab =
false;
1943 while ((i < tab_list.count ()) && (! in_tab))
1945 QTabBar *tab = tab_list.at (i);
1949 while ((j < tab->count ()) && (! in_tab))
1952 if (tab->tabText (j) == windowTitle ())
1956 int top = tab->currentIndex ();
1957 if (top > -1 && tab->tabText (top) == windowTitle ())
1958 real_visible =
true;
1978 if (visible && ! isFloating ())
1985 if (e->mimeData ()->hasUrls ())
1987 e->acceptProposedAction();
1994 if (e->mimeData ()->hasUrls ())
1996 foreach (QUrl url, e->mimeData ()->urls ())
QAction * _delete_end_line_action
void fetab_save_file(const QWidget *ID, const QString &fileName, bool remove_on_success)
void fetab_set_focus(const QWidget *ID)
void request_save_file(bool)
void dragEnterEvent(QDragEnterEvent *event)
void request_close_file(bool)
void request_delete_start_word(bool)
void update_window_title(bool modified)
void request_save_file_as(bool)
QAction * _toggle_bookmark_action
bool same_file(const std::string &f, const std::string &g)
void request_delete_start_line(bool)
void fetab_context_run(const QWidget *ID)
QAction * _show_eol_action
QAction * _delete_start_word_action
QAction * _remove_all_breakpoints_action
void fetab_run_file(const QWidget *ID)
QAction * _goto_line_action
void request_uncomment_selected_text(bool)
QAction * _next_bookmark_action
QAction * _sel_to_matching_brace
void request_selectall(bool)
QAction * _delete_line_action
void request_delete_line(bool)
void show_white_space(bool)
void fetab_context_edit(const QWidget *ID)
void fetab_find(const QWidget *ID)
void restore_create_file_setting()
bool is_editor_console_tabbed()
void request_new_file(const QString &commands)
void handle_edit_file_request(const QString &file)
void handle_enter_debug_mode(void)
void fetab_change_request(const QWidget *ID)
void request_duplicate_selection(bool)
void fetab_completion(const QWidget *)
void request_indent_selected_text(bool)
void request_unindent_selected_text(bool)
void fetab_unindent_selected_text(const QWidget *ID)
void update_octave_directory(const QString &dir)
QAction * _conv_eol_windows_action
bool editor_tab_has_focus()
QAction * _conv_eol_unix_action
QAction * _delete_start_line_action
QAction * _context_doc_action
QAction * _delete_end_word_action
void request_new_function(bool triggered=true)
void request_delete_end_word(bool)
void request_preferences(bool)
void fetab_delete_debugger_pointer(const QWidget *ID, int line=-1)
void fetab_scintilla_command(const QWidget *ID, unsigned int sci_msg)
void handle_add_filename_to_list(const QString &fileName, QWidget *ID)
void fetab_toggle_bookmark(const QWidget *ID)
QAction * _previous_bookmark_action
void request_comment_selected_text(bool)
void request_conv_eol_unix(bool)
void request_completion(bool)
void fetab_zoom_in(const QWidget *ID)
void request_next_breakpoint(bool)
QAction * _conv_eol_mac_action
QAction * _show_whitespace_action
bool call_custom_editor(const QString &file_name=QString(), int line=-1)
void show_indent_guides(bool)
QAction * _selectall_action
QAction * _close_all_action
void fetab_move_match_brace(const QWidget *ID, bool select)
QAction * _indent_selection_action
void fetab_uncomment_selected_text(const QWidget *ID)
void request_upper_case(bool)
std::map< QString, QWidget * >::const_iterator editor_tab_map_const_iterator
QAction * _close_others_action
void empty_script(bool startup, bool visible)
QAction * _show_linenum_action
void handle_update_breakpoint_marker_request(bool insert, const QString &file, int line)
QAction * _move_to_matching_brace
QAction * add_action(QMenu *menu, const QIcon &icon, const QString &text, const char *member)
void fetab_context_help(const QWidget *ID, bool)
void fetab_remove_bookmark(const QWidget *ID)
void handle_insert_debugger_pointer_request(const QString &file, int line)
QAction * _show_longline_action
QAction * _edit_function_action
void fetab_save_file_as(const QWidget *ID)
void execute_command_in_terminal_signal(const QString &)
void request_remove_breakpoint(bool)
void request_mru_open_file(QAction *action)
void fetab_zoom_out(const QWidget *ID)
F77_RET_T const double const double * f
void fetab_convert_eol(const QWidget *ID, QsciScintilla::EolMode eol_mode)
QAction * _cut_line_action
void fetab_indent_selected_text(const QWidget *ID)
octave_qscintilla * qsci_edit_area()
QAction * _previous_breakpoint_action
void enable_menu_shortcuts(bool)
void request_styles_preferences(bool)
QAction * _show_indguide_action
void fetab_next_breakpoint(const QWidget *ID)
void request_delete_end_line(bool)
void request_context_doc(bool)
std::complex< double > w(std::complex< double > z, double relerr=0)
void request_context_edit(bool)
QAction * _context_help_action
QAction * _lower_case_action
QAction * _styles_preferences_action
QAction * _preferences_action
void request_next_bookmark(bool)
QAction * _duplicate_selection_action
void file_loaded_signal()
QAction * _zoom_normal_action
QAction * _uncomment_selection_action
void fetab_zoom_normal(const QWidget *ID)
void check_conflict_save(const QString &fileName, bool remove_on_success)
void request_goto_line(bool)
void show_long_line(bool)
void insert_new_open_actions(QAction *, QAction *, QAction *)
QAction * _completion_action
void handle_tab_remove_request(void)
void request_open_files(const QStringList &)
QHash< QMenu *, QStringList > _hash_menu_text
QAction * _transpose_line_action
void toggle_preference(const QString &preference, bool def)
void fetab_next_bookmark(const QWidget *ID)
QAction * _unindent_selection_action
void request_conv_eol_windows(bool)
void fetab_check_modified_file(void)
void handle_editor_state_changed(bool enableCopy, bool is_octave_file)
void request_settings_dialog(const QString &)
static QSettings * get_settings(void)
void request_context_run(bool)
void fetab_settings_changed(const QSettings *settings)
QAction * _next_breakpoint_action
void handle_exit_debug_mode(void)
void mru_menu_update(void)
void fetab_file_name_query(const QWidget *ID)
void show_eol_chars(bool)
void handle_tab_close_request(int index)
void notice_settings(const QSettings *settings)
QAction * _save_as_action
void request_cut_line(bool)
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
void request_previous_breakpoint(bool)
void handle_delete_debugger_pointer_request(const QString &file, int line)
void request_context_help(bool)
void request_toggle_breakpoint(bool)
void request_remove_bookmark(bool)
void request_sel_match_brace(bool)
void request_run_file(bool)
static bool was_cancelled(void)
void fetab_print_file(const QWidget *ID)
void handle_mru_add_file(const QString &file_name)
void request_conv_eol_mac(bool)
void request_open_file(void)
void request_new_script(const QString &commands)
QMenu * m_add_menu(QMenuBar *p, QString text)
void create_context_menu(QMenu *)
void request_move_match_brace(bool)
void request_close_other_files(bool)
void fetab_comment_selected_text(const QWidget *ID)
QWidget * find_tab_widget(const QString &openFileName) const
void edit_status_update(bool, bool)
void fetab_set_directory(const QString &dir)
QList< octave_dock_widget * > get_dock_widget_list()
static QIcon icon(const QString &icon_name, bool fallback=true)
bool conditional_close(void)
void fetab_goto_line(const QWidget *ID, int line=-1)
void request_print_file(bool)
QAction * _mru_file_actions[MaxMRUFiles]
QAction * _upper_case_action
QAction * _toggle_breakpoint_action
void handle_visibility(bool visible)
void request_copy_line(bool)
QString load_file(const QString &fileName)
QAction * _run_selection_action
void active_tab_changed(int index)
void fetab_remove_all_breakpoints(const QWidget *ID)
void fetab_toggle_breakpoint(const QWidget *ID)
QAction * _zoom_in_action
void handle_file_name_changed(const QString &fileName, const QString &toolTip)
static void reset_cancel(void)
void request_previous_bookmark(bool)
void request_close_all_files(bool)
QAction * _copy_line_action
void fetab_previous_breakpoint(const QWidget *ID)
void fetab_insert_debugger_pointer(const QWidget *ID, int line=-1)
void add_file_editor_tab(file_editor_tab *f, const QString &fn)
void fetab_do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1)
QAction * _remove_bookmark_action
QAction * _comment_selection_action
QAction * _zoom_out_action
void save_file_as(QWidget *fetabID=0)
void dropEvent(QDropEvent *event)
std::map< QString, QWidget * > editor_tab_map
void request_lower_case(bool)
void request_toggle_bookmark(bool)
static void set_shortcut(QAction *action, const QString &key)
void request_transpose_line(bool)
void new_file(const QString &commands=QString())
QMenu * _view_editor_menu
void fetab_previous_bookmark(const QWidget *ID)
void show_line_numbers(bool)