27 #ifdef HAVE_QSCINTILLA
31 #include <QVBoxLayout>
32 #include <QApplication>
35 #include <QFileDialog>
36 #include <QMessageBox>
38 #include <QTextStream>
40 #include <QInputDialog>
50 ced = QDir::currentPath ();
66 QStringList fetFileNames;
70 QString file_name = p->first;
71 if (!file_name.isEmpty () && file_name.at (file_name.size () - 1) !=
'/')
72 fetFileNames.append (p->first);
75 settings->setValue (
"editor/savedSessionTabs", fetFileNames);
78 for (
int index =
_tab_widget->count ()-1; index >= 0; index--)
164 QString new_name = QInputDialog::getText (
this, tr (
"New Function"),
165 tr (
"New function name:\n"), QLineEdit::Normal,
"", &ok);
166 if (ok && new_name.length () > 0)
169 if (new_name.rightRef (2) !=
".m")
170 new_name.append (
".m");
173 if (! settings->value (
"editor/create_new_file",
false).toBool ())
176 settings->setValue (
"editor/create_new_file",
true);
190 settings->setValue (
"editor/create_new_file",
false);
204 fileDialog->setNameFilter (tr (
"Octave Files (*.m);;All Files (*)"));
209 fileDialog->setOption(QFileDialog::DontUseNativeDialog,
true);
211 fileDialog->setAcceptMode (QFileDialog::AcceptOpen);
212 fileDialog->setViewMode (QFileDialog::Detail);
213 fileDialog->setDirectory (
ced);
215 connect (fileDialog, SIGNAL (fileSelected (
const QString&)),
218 fileDialog->setWindowModality (Qt::NonModal);
219 fileDialog->setAttribute (Qt::WA_DeleteOnClose);
232 QString tab_file = p->first;
234 if (
same_file (file.toStdString (), tab_file.toStdString ()))
250 if (settings->value (
"useCustomFileEditor").toBool ())
252 QString editor = settings->value (
"customFileEditor").toString ();
253 editor.replace (
"%f", file_name);
254 editor.replace (
"%l", QString::number (line));
256 QProcess::startDetached (editor);
258 if (line < 0 && ! file_name.isEmpty ())
270 bool breakpoint_marker,
bool insert)
275 if (openFileName.isEmpty ())
301 if (breakpoint_marker)
313 QString result = fileEditorTab->
load_file (openFileName);
321 QFileInfo file_info = QFileInfo (openFileName);
331 if (breakpoint_marker)
338 delete fileEditorTab;
346 tr (
"Octave Editor"),
347 tr (
"Could not open file\n%1\nfor read: %2.").
348 arg (openFileName).
arg (result),
349 QMessageBox::Ok,
this);
351 msgBox->setWindowModality (Qt::NonModal);
352 msgBox->setAttribute (Qt::WA_DeleteOnClose);
361 if (settings->value (
"editor/create_new_file",
false).toBool ())
363 answer = QMessageBox::Yes;
368 tr (
"Octave Editor"),
369 tr (
"File\n%1\ndoes not exist. "
370 "Do you want to create it?").
arg (openFileName),
372 | QMessageBox::No,
this);
374 msgBox->setAttribute (Qt::WA_DeleteOnClose);
375 answer = msgBox->exec ();
378 if (answer == QMessageBox::Yes)
381 QFile file (openFileName);
382 if (!file.open (QIODevice::WriteOnly))
386 tr (
"Octave Editor"),
387 tr (
"Could not open file\n%1\nfor write: %2.").
388 arg (openFileName).
arg (file.errorString ()),
389 QMessageBox::Ok,
this);
391 msgBox->setWindowModality (Qt::NonModal);
392 msgBox->setAttribute (Qt::WA_DeleteOnClose);
425 bool remove_on_success)
445 =
new QMessageBox (QMessageBox::Critical, tr (
"Octave Editor"),
446 tr (
"File not saved! A file with the selected name\n%1\n"
447 "is already open in the editor").
451 msgBox->setWindowModality (Qt::NonModal);
452 msgBox->setAttribute (Qt::WA_DeleteOnClose);
458 QObject *saveFileObject = sender ();
473 =
new QMessageBox (QMessageBox::Critical, tr (
"Octave Editor"),
474 tr (
"The associated file editor tab has disappeared. It was likely closed by some means."),
477 msgBox->setWindowModality (Qt::NonModal);
478 msgBox->setAttribute (Qt::WA_DeleteOnClose);
485 emit
fetab_save_file (saveFileWidget, saveFileName, remove_on_success);
499 if (! file.isEmpty ())
699 for (
int i = 0; i < num_files; ++i)
701 QString
text = tr (
"&%1 %2").
720 settings->setValue (
"editor/mru_file_list",
_mru_files);
728 QObject *fileEditorTab = sender ();
752 for (
int index =
_tab_widget->count ()-1; index >= 0; index--)
761 for (
int index =
_tab_widget->count ()-1; index >= 0; index--)
783 QObject *fileEditorTab = sender ();
791 delete fileEditorTab;
815 const QString& file_name)
825 if (!file_name.isEmpty ())
827 ced = QDir::cleanPath (file_name);
828 int lastslash =
ced.lastIndexOf (
'/');
832 if (lastslash > 0 && lastslash !=
ced.count ())
833 ced =
ced.left (lastslash);
843 int icon_size = settings->value (
"toolbar_icon_size", 16).toInt ();
844 _tool_bar->setIconSize (QSize (icon_size, icon_size));
869 _menu_bar =
new QMenuBar (editor_widget);
870 _tool_bar =
new QToolBar (editor_widget);
875 QAction *new_action =
new QAction (QIcon (
":/actions/icons/filenew.png"),
878 QAction *open_action =
new QAction (QIcon (
":/actions/icons/fileopen.png"),
881 _save_action =
new QAction (QIcon (
":/actions/icons/filesave.png"),
884 _save_as_action =
new QAction (QIcon (
":/actions/icons/filesaveas.png"),
887 _print_action =
new QAction ( QIcon (
":/actions/icons/fileprint.png"),
890 _undo_action =
new QAction (QIcon (
":/actions/icons/undo.png"),
893 _redo_action =
new QAction (QIcon (
":/actions/icons/redo.png"),
896 _copy_action =
new QAction (QIcon (
":/actions/icons/editcopy.png"),
900 _cut_action =
new QAction (QIcon (
":/actions/icons/editcut.png"),
905 =
new QAction (QIcon (
":/actions/icons/editpaste.png"),
916 =
new QAction (tr (
"&Remove All Bookmarks"),
_tool_bar);
918 QAction *next_breakpoint_action
919 =
new QAction (QIcon (
":/actions/icons/bp_next.png"),
921 QAction *previous_breakpoint_action
922 =
new QAction (QIcon (
":/actions/icons/bp_prev.png"),
924 QAction *toggle_breakpoint_action
925 =
new QAction (QIcon (
":/actions/icons/bp_toggle.png"),
927 QAction *remove_all_breakpoints_action
928 =
new QAction (QIcon (
":/actions/icons/bp_rm_all.png"),
929 tr (
"&Remove All Breakpoints"),
_tool_bar);
932 =
new QAction (tr (
"&Comment"),
_tool_bar);
934 =
new QAction (tr (
"&Uncomment"),
_tool_bar);
936 _find_action =
new QAction (QIcon (
":/actions/icons/search.png"),
939 _run_action =
new QAction (QIcon (
":/actions/icons/artsbuilderexecute.png"),
947 _mru_files = settings->value (
"editor/mru_file_list").toStringList ();
958 _run_action->setShortcutContext (Qt::WindowShortcut);
989 _tool_bar->addAction (toggle_breakpoint_action);
990 _tool_bar->addAction (next_breakpoint_action);
991 _tool_bar->addAction (previous_breakpoint_action);
992 _tool_bar->addAction (remove_all_breakpoints_action);
995 QMenu *fileMenu =
new QMenu (tr (
"&File"),
_menu_bar);
997 _mru_file_menu =
new QMenu (tr (
"&Recent Editor Files"), fileMenu);
1001 fileMenu->addAction (new_action);
1002 fileMenu->addAction (QIcon (), tr (
"New &Function"),
1004 fileMenu->addAction (open_action);
1006 fileMenu->addSeparator ();
1008 fileMenu->addAction (QIcon (), tr (
"&Edit Function"),
1010 fileMenu->addSeparator ();
1014 fileMenu->addSeparator ();
1016 fileMenu->addAction (QIcon::fromTheme(
"window-close",
1017 QIcon (
":/actions/icons/fileclose.png")),
1020 fileMenu->addAction (QIcon::fromTheme(
"window-close",
1021 QIcon (
":/actions/icons/fileclose.png")),
1025 fileMenu->addAction (QIcon::fromTheme(
"window-close",
1026 QIcon (
":/actions/icons/fileclose.png")),
1027 tr (
"Close Other Files"),
1030 fileMenu->addSeparator ();
1036 QMenu *editMenu =
new QMenu (tr (
"&Edit"),
_menu_bar);
1039 editMenu->addSeparator ();
1043 editMenu->addSeparator ();
1045 editMenu->addSeparator ();
1048 editMenu->addSeparator ();
1053 editMenu->addSeparator ();
1055 editMenu->addSeparator ();
1057 editMenu->addAction (QIcon (
":/actions/icons/configure.png"),
1058 tr (
"&Preferences"),
1061 editMenu->addAction (QIcon (
":/actions/icons/configure.png"),
1062 tr (
"&Styles Preferences"),
1067 _debug_menu->addAction (toggle_breakpoint_action);
1069 _debug_menu->addAction (previous_breakpoint_action);
1070 _debug_menu->addAction (remove_all_breakpoints_action);
1075 QMenu *_run_menu =
new QMenu (tr (
"&Run"),
_menu_bar);
1078 _run_menu->addAction (QIcon (), tr (
"Run &Selection"),
1083 QMenu *_help_menu =
new QMenu (tr (
"&Help"),
_menu_bar);
1085 _help_menu->addAction (QIcon (), tr (
"&Help on Keyword"),
1088 _help_menu->addAction (QIcon (), tr (
"&Documentation on Keyword"),
1096 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
1100 vbox_layout->setMargin (0);
1101 editor_widget->setLayout (vbox_layout);
1102 setWidget (editor_widget);
1107 SLOT (process_settings_dialog_request (
const QString&)));
1109 connect (
main_win (), SIGNAL (new_file_signal (
const QString&)),
1112 connect (
main_win (), SIGNAL (open_file_signal (
const QString&)),
1115 connect (new_action, SIGNAL (triggered ()),
1118 connect (open_action, SIGNAL (triggered ()),
1160 connect (toggle_breakpoint_action, SIGNAL (triggered ()),
1163 connect (next_breakpoint_action, SIGNAL (triggered ()),
1166 connect (previous_breakpoint_action, SIGNAL (triggered ()),
1169 connect (remove_all_breakpoints_action, SIGNAL (triggered ()),
1189 connect (
_tab_widget, SIGNAL (tabCloseRequested (
int)),
1192 connect (
_tab_widget, SIGNAL (currentChanged (
int)),
1196 main_win (), SLOT (execute_command_in_terminal (
const QString&)));
1199 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
1203 if (settings->value (
"editor/restoreSession",
true).toBool ())
1205 QStringList sessionFileNames
1206 = settings->value (
"editor/savedSessionTabs",
1207 QStringList ()).toStringList ();
1209 for (
int n = 0; n < sessionFileNames.count (); ++n)
1222 connect (f, SIGNAL (file_name_changed (
const QString&,
const QString&)),
1226 connect (f, SIGNAL (editor_state_changed (
bool,
const QString&)),
1229 connect (f, SIGNAL (tab_remove_request ()),
1232 connect (f, SIGNAL (add_filename_to_list (
const QString&,
QWidget*)),
1235 connect (f, SIGNAL (editor_check_conflict_save (
const QString&,
bool)),
1238 connect (f, SIGNAL (mru_add_file (
const QString&)),
1241 connect (f, SIGNAL (run_file_signal (
const QFileInfo&)),
1242 main_win (), SLOT (run_file_in_terminal (
const QFileInfo&)));
1245 main_win (), SLOT (execute_command_in_terminal (
const QString&)));
1252 f, SLOT (conditional_close (
const QWidget*,
bool)));
1255 f, SLOT (change_editor_state (
const QWidget*)));
1258 f, SLOT (file_name_query (
const QWidget*)));
1262 f, SLOT (save_file (
const QWidget*,
const QString&,
bool)));
1266 f, SLOT (undo (
const QWidget*)));
1269 f, SLOT (redo (
const QWidget*)));
1272 f, SLOT (copy (
const QWidget*)));
1275 f, SLOT (cut (
const QWidget*)));
1278 f, SLOT (paste (
const QWidget*)));
1281 f, SLOT (context_help (
const QWidget*,
bool)));
1284 f, SLOT (context_edit (
const QWidget*)));
1287 f, SLOT (save_file (
const QWidget*)));
1293 f, SLOT (print_file (
const QWidget*)));
1296 f, SLOT (run_file (
const QWidget*)));
1299 f, SLOT (context_run (
const QWidget*)));
1302 f, SLOT (toggle_bookmark (
const QWidget*)));
1305 f, SLOT (next_bookmark (
const QWidget*)));
1308 f, SLOT (previous_bookmark (
const QWidget*)));
1311 f, SLOT (remove_bookmark (
const QWidget*)));
1314 f, SLOT (toggle_breakpoint (
const QWidget*)));
1317 f, SLOT (next_breakpoint (
const QWidget*)));
1320 f, SLOT (previous_breakpoint (
const QWidget*)));
1323 f, SLOT (remove_all_breakpoints (
const QWidget*)));
1326 f, SLOT (comment_selected_text (
const QWidget*)));
1329 f, SLOT (uncomment_selected_text (
const QWidget*)));
1335 f, SLOT (goto_line (
const QWidget*,
int)));
1341 f, SLOT (insert_debugger_pointer (
const QWidget*,
int)));
1344 f, SLOT (delete_debugger_pointer (
const QWidget*,
int)));
1348 f, SLOT (do_breakpoint_marker (
bool,
const QWidget*,
int)));
1360 if (foc_w && foc_w->inherits (
"octave_qscintilla"))
1370 if (foc_w && foc_w->inherits (
"octave_qscintilla"))
1383 + Qt::ControlModifier
1413 QKeySequence no_key = QKeySequence ();