GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
file-editor.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2011-2018 Jacob Dawid
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #if defined (HAVE_QSCINTILLA)
28 
29 #include "file-editor.h"
30 #include "resource-manager.h"
31 #include "shortcut-manager.h"
32 
33 #include <QApplication>
34 #include <QFile>
35 #include <QFileDialog>
36 #include <QFont>
37 #include <QMessageBox>
38 #include <QMimeData>
39 #include <QProcess>
40 #include <QPushButton>
41 #include <QStyle>
42 #include <QTabBar>
43 #include <QTextStream>
44 #include <QVBoxLayout>
45 #include <Qsci/qscicommandset.h>
46 
47 #include "main-window.h"
48 #include "oct-map.h"
49 #include "octave-link.h"
50 #include "utils.h"
51 
52 namespace octave
53 {
54  // Functions of the the reimplemented tab widget
55 
57  : QTabWidget (p)
58  {
59  tab_bar *bar = new tab_bar (this);
60 
61  connect (bar, SIGNAL (close_current_tab_signal (bool)),
62  p->parent (), SLOT (request_close_file (bool)));
63 
64  this->setTabBar (bar);
65 
66  setTabsClosable (true);
67 #if defined (HAVE_QTABWIDGET_SETMOVABLE)
68  setMovable (true);
69 #endif
70  }
71 
73  {
74  return qobject_cast<tab_bar *> (tabBar ());
75  }
76 
77 
78  // File editor
79 
82  {
83  // Set current editing directory before construct because loaded
84  // files will change ced accordingly.
85  m_ced = QDir::currentPath ();
86 
87  // set action that are later added by the main window to null,
88  // preventing access to them when they are still undefined
89  m_undo_action = nullptr;
90  m_copy_action = nullptr;
91  m_paste_action = nullptr;
92  m_selectall_action = nullptr;
93  m_closed = false;
94  m_no_focus = false;
95 
96  construct ();
97 
98  // actions that should also be available in the find dialog
101 
102  setVisible (false);
103  setAcceptDrops (true);
104  }
105 
107  {
108  delete m_mru_file_menu;
109  }
110 
111  // insert global actions, that should also be displayed in the editor window,
112  // into the editor's menu and/or toolbar
114  {
115  // actions/menus that have to be added to the toolbar or the menu
116  QAction *open_action = shared_actions.at (OPEN_ACTION);
117  QAction *new_action = shared_actions.at (NEW_SCRIPT_ACTION);
118  QAction *new_fcn_action = shared_actions.at (NEW_FUNCTION_ACTION);
119  m_fileMenu->insertAction (m_mru_file_menu->menuAction (), open_action);
120  m_fileMenu->insertAction (open_action, new_fcn_action);
121  m_fileMenu->insertAction (new_fcn_action, new_action);
122  m_tool_bar->insertAction (m_popdown_mru_action, open_action);
123  m_tool_bar->insertAction (open_action, new_action);
124 
125  // actions that are additionally enabled/disabled later by the editor
126  // undo
127  m_undo_action = shared_actions.at (UNDO_ACTION);
128  m_tool_bar->insertAction (m_redo_action,m_undo_action);
129  m_edit_menu->insertAction (m_redo_action,m_undo_action);
130  // copy
131  m_copy_action = shared_actions.at (COPY_ACTION);
132  m_tool_bar->insertAction (m_cut_action,m_copy_action);
133  m_edit_menu->insertAction (m_cut_action,m_copy_action);
134  // select all
135  m_selectall_action = shared_actions.at (SELECTALL_ACTION);
137  m_edit_menu->insertSeparator (m_find_action);
138  // paste
139  m_paste_action = shared_actions.at (PASTE_ACTION);
140  m_tool_bar->insertAction (m_find_action,m_paste_action);
142  m_edit_menu->insertSeparator (m_selectall_action);
143  // find files
144  m_find_files_action = shared_actions.at (FIND_FILES_ACTION);
146  }
147 
149  {
150  m_run_action->setEnabled (false);
151  m_run_action->setShortcut (QKeySequence ());
152  }
153 
155  {
156  m_run_action->setEnabled (true);
157  shortcut_manager::set_shortcut (m_run_action, "editor_run:run_file");
158  }
159 
161  {
162  bool have_tabs = m_tab_widget->count () > 0;
163 
164  m_edit_cmd_menu->setEnabled (have_tabs);
165  m_edit_fmt_menu->setEnabled (have_tabs);
166  m_edit_nav_menu->setEnabled (have_tabs);
167 
168  m_comment_selection_action->setEnabled (have_tabs);
169  m_uncomment_selection_action->setEnabled (have_tabs);
170  m_comment_var_selection_action->setEnabled (have_tabs);
171  m_indent_selection_action->setEnabled (have_tabs);
172  m_unindent_selection_action->setEnabled (have_tabs);
173  m_smart_indent_line_or_selection_action->setEnabled (have_tabs);
174 
175  m_context_help_action->setEnabled (have_tabs);
176  m_context_doc_action->setEnabled (have_tabs);
177 
178  m_view_editor_menu->setEnabled (have_tabs);
179  m_zoom_in_action->setEnabled (have_tabs);
180  m_zoom_out_action->setEnabled (have_tabs);
181  m_zoom_normal_action->setEnabled (have_tabs);
182 
183  m_find_action->setEnabled (have_tabs);
184  m_find_next_action->setEnabled (have_tabs);
185  m_find_previous_action->setEnabled (have_tabs);
186  m_print_action->setEnabled (have_tabs);
187  m_run_action->setEnabled (have_tabs);
188 
189  m_edit_function_action->setEnabled (have_tabs);
190  m_save_action->setEnabled (have_tabs);
191  m_save_as_action->setEnabled (have_tabs);
192  m_close_action->setEnabled (have_tabs);
193  m_close_all_action->setEnabled (have_tabs);
194  m_close_others_action->setEnabled (have_tabs && m_tab_widget->count () > 1);
195  }
196 
197  // empty_script determines whether we have to create an empty script
198  // 1. At startup, when the editor has to be (really) visible
199  // (Here we can not use the visibility changed signal)
200  // 2. When the editor becomes visible when octave is running
201  void file_editor::empty_script (bool startup, bool visible)
202  {
203  QSettings *settings = resource_manager::get_settings ();
204  if (settings->value ("useCustomFileEditor",false).toBool ())
205  return; // do not open an empty script in the external editor
206 
207  bool real_visible;
208 
209  if (startup)
210  real_visible = isVisible ();
211  else
212  real_visible = visible;
213 
214  if (! real_visible || m_tab_widget->count () > 0)
215  return;
216 
217  if (startup && ! isFloating ())
218  {
219  // check is editor is really visible or hidden between tabbed widgets
220  QList<QTabBar *> tab_list = main_win ()->findChildren<QTabBar *>();
221 
222  bool in_tab = false;
223  int i = 0;
224  while ((i < tab_list.count ()) && (! in_tab))
225  {
226  QTabBar *tab = tab_list.at (i);
227  i++;
228 
229  int j = 0;
230  while ((j < tab->count ()) && (! in_tab))
231  {
232  // check all tabs for the editor
233  if (tab->tabText (j) == windowTitle ())
234  {
235  // editor is in this tab widget
236  in_tab = true;
237  int top = tab->currentIndex ();
238  if (top > -1 && tab->tabText (top) == windowTitle ())
239  real_visible = true; // and is the current tab
240  else
241  return; // not current tab -> not visible
242  }
243  j++;
244  }
245  }
246  }
247 
248  request_new_file ("");
249  }
250 
251  void file_editor::restore_session (QSettings *settings)
252  {
253  //restore previous session
254  if (! settings->value ("editor/restoreSession", true).toBool ())
255  return;
256 
257  // get the data from the settings file
258  QStringList sessionFileNames
259  = settings->value ("editor/savedSessionTabs",
260  QStringList ()).toStringList ();
261 
262  QStringList session_encodings
263  = settings->value ("editor/saved_session_encodings",
264  QStringList ()).toStringList ();
265 
266  QStringList session_index
267  = settings->value ("editor/saved_session_tab_index",
268  QStringList ()).toStringList ();
269 
270  // fill a list of the struct and sort it (depending on index)
271  QList<session_data> s_data;
272 
273  bool do_encoding = (session_encodings.count () == sessionFileNames.count ());
274  bool do_index = (session_index.count () == sessionFileNames.count ());
275 
276  for (int n = 0; n < sessionFileNames.count (); ++n)
277  {
278  QFileInfo file = QFileInfo (sessionFileNames.at (n));
279  if (! file.exists ())
280  continue;
281 
282  session_data item = { 0, sessionFileNames.at (n), QString ()};
283  if (do_index)
284  item.index = session_index.at (n).toInt ();
285  if (do_encoding)
286  item.encoding = session_encodings.at (n);
287 
288  s_data << item;
289  }
290 
291  qSort (s_data);
292 
293  // finally open the file with the desired encoding in the desired order
294  for (int n = 0; n < s_data.count (); ++n)
295  request_open_file (s_data.at (n).file_name, s_data.at (n).encoding);
296  }
297 
298  void file_editor::focus (void)
299  {
300  if (m_no_focus)
301  return; // No focus for the editor if external open/close request
302 
304 
305  // set focus to current tab
306  QWidget *fileEditorTab = m_tab_widget->currentWidget ();
307  if (fileEditorTab)
308  emit fetab_set_focus (fileEditorTab);
309  }
310 
312  {
314 
315  // set focus to desired tab
316  if (fet)
317  m_tab_widget->setCurrentWidget (fet);
318  }
319 
320  // function enabling/disabling the menu accelerators depending on the
321  // focus of the editor
323  {
324  QHash<QMenu*, QStringList>::const_iterator i = m_hash_menu_text.constBegin ();
325 
326  while (i != m_hash_menu_text.constEnd ())
327  {
328  i.key ()->setTitle (i.value ().at (! enable));
329  ++i;
330  }
331 
332  // when editor loses focus, enable the actions, which are always active
333  // in the main window due to missing info on selected text and undo actions
334  if (! enable && m_copy_action && m_undo_action)
335  {
336  m_copy_action->setEnabled (true);
337  m_undo_action->setEnabled (true);
338  }
339  }
340 
342  {
343  // When the application or the editor is closing and the user wants to close
344  // all files in the latter case all editor tabs are checked whether
345  // they need to be saved. During these ckecked the tabs are not closed
346  // since the user might cancel closing octave during one of these saving
347  // dialogs. Therefore, saving the session for restoring at next start
348  // is not done before the application is definitely closing
349 
350  // Have all file editor tabs signal what their filenames are.
351  m_editor_tab_map.clear ();
352  emit fetab_file_name_query (nullptr);
353 
354  // Save all tabs with confirmation.
357 
358  // If there was a cancellation, make the already saved/discarded tabs
359  // recovering from the exit by removing the read-only state and by
360  // recovering the debugger breakpoints. Finally return false in order to
361  // cancel closing the application or the editor
363  {
364  emit fetab_recover_from_exit ();
365  return false;
366  }
367 
368  // Here, the application or the editor will be closed -> store the session
369 
370  // Save open files for restoring in next session; this only is possible
371  QSettings *settings = resource_manager::get_settings ();
372 
373  // save filenames (even if last session will not be restored next time)
374  // together with encoding and the tab index
375  QStringList fetFileNames;
376  QStringList fet_encodings;
377  QStringList fet_index;
378 
379  // save all open tabs before they are definitely closed
381  p != m_editor_tab_map.end (); p++)
382  {
383  QString file_name = p->first; // get file name of tab
384  if (! file_name.isEmpty ()) // do not append unnamed files
385  {
386  fetFileNames.append (file_name);
387  fet_encodings.append (m_editor_tab_map[file_name].encoding);
388  QString index;
389  fet_index.append (index.setNum
390  (m_tab_widget->indexOf (m_editor_tab_map[file_name].fet_ID)));
391  }
392  }
393 
394  settings->setValue ("editor/savedSessionTabs", fetFileNames);
395  settings->setValue ("editor/saved_session_encodings", fet_encodings);
396  settings->setValue ("editor/saved_session_tab_index", fet_index);
397  settings->sync ();
398 
399  // Finally close all the tabs and return indication that we can exit
400  // the application or close the editor
401  for (int i = m_tab_widget->count () - 1; i >= 0; i--)
402  {
403  // backwards loop since m_tab_widget->count () changes during the loop
404  delete m_tab_widget->widget (i);
405  m_tab_widget->removeTab (i);
406  }
407 
408  return true;
409  }
410 
412  {
413  // Custom editor? If yes, we can only call the editor without passing
414  // some initial contents and even without being sure a new file is opened
415  if (call_custom_editor ())
416  return;
417 
418  // New file isn't a file_editor_tab function since the file
419  // editor tab has yet to be created and there is no object to
420  // pass a signal to. Hence, functionality is here.
421 
422  file_editor_tab *fileEditorTab = new file_editor_tab (m_ced);
423  if (fileEditorTab)
424  {
425  add_file_editor_tab (fileEditorTab, ""); // new tab with empty title
426  fileEditorTab->new_file (commands); // title is updated here
427  focus (); // focus editor and new tab
428  }
429  }
430 
432  {
433  file_editor_tab *editor_tab
434  = static_cast<file_editor_tab *> (m_tab_widget->currentWidget ());
435  editor_tab->conditional_close ();
436  }
437 
439  {
440  file_editor_tab *editor_tab;
441 
442  // loop over all tabs starting from last one otherwise deletion changes index
443  for (int index = m_tab_widget->count ()-1; index >= 0; index--)
444  {
445  editor_tab = static_cast<file_editor_tab *> (m_tab_widget->widget (index));
446  editor_tab->conditional_close ();
447  }
448  }
449 
451  {
452  file_editor_tab *editor_tab;
453  QWidget *tabID = m_tab_widget->currentWidget ();
454 
455  // loop over all tabs starting from last one otherwise deletion changes index
456  for (int index = m_tab_widget->count ()-1; index >= 0; index--)
457  {
458  if (tabID != m_tab_widget->widget (index))
459  {
460  editor_tab
461  = static_cast<file_editor_tab *> (m_tab_widget->widget (index));
462  editor_tab->conditional_close ();
463  }
464  }
465  }
466 
467  // open a file from the mru list
468  void file_editor::request_mru_open_file (QAction *action)
469  {
470  if (action)
471  {
472  request_open_file (action->data ().toStringList ().at (0),
473  action->data ().toStringList ().at (1));
474  }
475  }
476 
478  {
479  emit fetab_print_file (m_tab_widget->currentWidget ());
480  }
481 
483  {
484  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
485  QsciScintillaBase::SCI_REDO);
486  }
487 
489  {
490  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
491  QsciScintillaBase::SCI_CUT);
492  }
493 
495  {
496  emit fetab_context_help (m_tab_widget->currentWidget (), false);
497  }
498 
500  {
501  emit fetab_context_help (m_tab_widget->currentWidget (), true);
502  }
503 
505  {
506  emit fetab_context_edit (m_tab_widget->currentWidget ());
507  }
508 
510  {
511  emit fetab_save_file (m_tab_widget->currentWidget ());
512  }
513 
515  {
516  emit fetab_save_file_as (m_tab_widget->currentWidget ());
517  }
518 
520  {
521  emit fetab_run_file (m_tab_widget->currentWidget ());
522  }
523 
525  {
526  emit fetab_context_run (m_tab_widget->currentWidget ());
527  }
528 
530  {
531  emit fetab_toggle_bookmark (m_tab_widget->currentWidget ());
532  }
533 
535  {
536  emit fetab_next_bookmark (m_tab_widget->currentWidget ());
537  }
538 
540  {
541  emit fetab_previous_bookmark (m_tab_widget->currentWidget ());
542  }
543 
545  {
546  emit fetab_remove_bookmark (m_tab_widget->currentWidget ());
547  }
548 
550  {
551  emit fetab_move_match_brace (m_tab_widget->currentWidget (), false);
552  }
553 
555  {
556  emit fetab_move_match_brace (m_tab_widget->currentWidget (), true);
557  }
558 
559  // FIXME: What should this do with conditional breakpoints?
561  {
562  emit fetab_toggle_breakpoint (m_tab_widget->currentWidget ());
563  }
564 
566  {
567  emit fetab_next_breakpoint (m_tab_widget->currentWidget ());
568  }
569 
571  {
572  emit fetab_previous_breakpoint (m_tab_widget->currentWidget ());
573  }
574 
576  {
577  emit fetab_remove_all_breakpoints (m_tab_widget->currentWidget ());
578  }
579 
580  // slots for Edit->Commands actions
582  {
583  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
584  QsciScintillaBase::SCI_DELWORDLEFT);
585  }
586 
588  {
589  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
590  QsciScintillaBase::SCI_DELWORDRIGHT);
591  }
592 
594  {
595  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
596  QsciScintillaBase::SCI_DELLINELEFT);
597  }
598 
600  {
601  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
602  QsciScintillaBase::SCI_DELLINERIGHT);
603  }
604 
606  {
607  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
608  QsciScintillaBase::SCI_LINEDELETE);
609  }
610 
612  {
613  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
614  QsciScintillaBase::SCI_LINECOPY);
615  }
616 
618  {
619  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
620  QsciScintillaBase::SCI_LINECUT);
621  }
622 
624  {
625  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
626  QsciScintillaBase::SCI_SELECTIONDUPLICATE);
627  }
628 
630  {
631  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
632  QsciScintillaBase::SCI_LINETRANSPOSE);
633  }
634 
636  {
637  emit fetab_comment_selected_text (m_tab_widget->currentWidget (), false);
638  }
639 
641  {
642  emit fetab_uncomment_selected_text (m_tab_widget->currentWidget ());
643  }
644 
646  {
647  emit fetab_comment_selected_text (m_tab_widget->currentWidget (), true);
648  }
649 
650  // slots for Edit->Format actions
652  {
653  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
654  QsciScintillaBase::SCI_UPPERCASE);
655  }
656 
658  {
659  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
660  QsciScintillaBase::SCI_LOWERCASE);
661  }
662 
664  {
665  emit fetab_indent_selected_text (m_tab_widget->currentWidget ());
666  }
667 
669  {
670  emit fetab_unindent_selected_text (m_tab_widget->currentWidget ());
671  }
672 
674  {
676  }
677 
679  {
680  emit fetab_convert_eol (m_tab_widget->currentWidget (),
681  QsciScintilla::EolWindows);
682  }
683  void
685  {
686  emit fetab_convert_eol (m_tab_widget->currentWidget (),
687  QsciScintilla::EolUnix);
688  }
689 
691  {
692  emit fetab_convert_eol (m_tab_widget->currentWidget (),
693  QsciScintilla::EolMac);
694  }
695 
697  {
698  emit fetab_find (m_tab_widget->currentWidget (), m_fetab_actions);
699  }
700 
702  {
703  emit fetab_find_next (m_tab_widget->currentWidget ());
704  }
705 
707  {
708  emit fetab_find_previous (m_tab_widget->currentWidget ());
709  }
710 
712  {
713  emit fetab_goto_line (m_tab_widget->currentWidget ());
714  }
715 
717  {
718  emit fetab_completion (m_tab_widget->currentWidget ());
719  }
720 
722  const QString& tip)
723  {
724  QObject *fileEditorTab = sender ();
725  if (fileEditorTab)
726  {
727  for (int i = 0; i < m_tab_widget->count (); i++)
728  {
729  if (m_tab_widget->widget (i) == fileEditorTab)
730  {
731  m_tab_widget->setTabText (i, fname);
732  m_tab_widget->setTabToolTip (i, tip);
733  }
734  }
735  }
736  }
737 
739  {
740  file_editor_tab *editor_tab
741  = static_cast<file_editor_tab *> (m_tab_widget->widget (index));
742  editor_tab->conditional_close ();
743  }
744 
745  void
747  {
748  QObject *fileEditorTab = sender ();
749  if (fileEditorTab)
750  {
751  for (int i = 0; i < m_tab_widget->count (); i++)
752  {
753  if (m_tab_widget->widget (i) == fileEditorTab)
754  {
755  m_tab_widget->removeTab (i);
756  // Deleting sender is dodgy, but works because the signal
757  // is the last item in the sender's routines.
758  delete fileEditorTab;
759  break;
760  }
761  }
762  }
763  check_actions ();
764 
765  focus (); // focus stays in editor when tab is closed
766 
767  }
768 
769  void file_editor::handle_add_filename_to_list (const QString& fileName,
770  const QString& encoding, QWidget *ID)
771  {
772  // Should we allow multiple tabs for a single file?
773  m_editor_tab_map[fileName].fet_ID = ID;
774  m_editor_tab_map[fileName].encoding = encoding;
775  }
776 
777  // context menu of edit area
779  {
780  emit fetab_change_request (m_tab_widget->widget (index));
781  focus ();
782  }
783 
784  void file_editor::handle_editor_state_changed (bool copy_available,
785  bool is_octave_file)
786  {
787  // In case there is some scenario where traffic could be coming from
788  // all the file editor tabs, just process info from the current active tab.
789  if (sender () == m_tab_widget->currentWidget ())
790  {
791  if (m_copy_action)
792  m_copy_action->setEnabled (copy_available);
793  m_cut_action->setEnabled (copy_available);
794  m_run_selection_action->setEnabled (copy_available);
795  m_run_action->setEnabled (is_octave_file);
796 
797  setFocusProxy (m_tab_widget->currentWidget ());
798  }
799  }
800 
801  void file_editor::handle_mru_add_file (const QString& file_name,
802  const QString& encoding)
803  {
804  int index;
805  while ((index = m_mru_files.indexOf (file_name)) >= 0)
806  {
807  m_mru_files.removeAt (index);
808  m_mru_files_encodings.removeAt (index);
809  }
810 
811  m_mru_files.prepend (file_name);
812  m_mru_files_encodings.prepend (encoding);
813 
814  mru_menu_update ();
815  }
816 
817  void file_editor::check_conflict_save (const QString& saveFileName,
818  bool remove_on_success)
819  {
820  // Check whether this file is already open in the editor.
821  QWidget *tab = find_tab_widget (saveFileName);
822 
823  if (tab)
824  {
825  // Note: to overwrite the contents of some other file editor tab
826  // with the same name requires identifying which file editor tab
827  // that is (not too difficult) then close that tab. Of course,
828  // that could trigger another dialog box if the file editor tab
829  // with the same name has modifications in it. This could become
830  // somewhat confusing to the user. For now, opt to do nothing.
831 
832  // Create a NonModal message about error.
833  QMessageBox *msgBox
834  = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"),
835  tr ("File not saved! A file with the selected name\n%1\n"
836  "is already open in the editor").
837  arg (saveFileName),
838  QMessageBox::Ok, nullptr);
839 
840  msgBox->setWindowModality (Qt::NonModal);
841  msgBox->setAttribute (Qt::WA_DeleteOnClose);
842  msgBox->show ();
843 
844  return;
845  }
846 
847  QObject *saveFileObject = sender ();
848  QWidget *saveFileWidget = nullptr;
849 
850  for (int i = 0; i < m_tab_widget->count (); i++)
851  {
852  if (m_tab_widget->widget (i) == saveFileObject)
853  {
854  saveFileWidget = m_tab_widget->widget (i);
855  break;
856  }
857  }
858  if (! saveFileWidget)
859  {
860  // Create a NonModal message about error.
861  QMessageBox *msgBox
862  = new QMessageBox (QMessageBox::Critical, tr ("Octave Editor"),
863  tr ("The associated file editor tab has disappeared."),
864  QMessageBox::Ok, nullptr);
865 
866  msgBox->setWindowModality (Qt::NonModal);
867  msgBox->setAttribute (Qt::WA_DeleteOnClose);
868  msgBox->show ();
869 
870  return;
871  }
872 
873  // Can save without conflict, have the file editor tab do so.
874  emit fetab_save_file (saveFileWidget, saveFileName, remove_on_success);
875  }
876 
878  int line)
879  {
880  request_open_file (file, QString (), line, true); // default encoding
881  }
882 
884  int line)
885  {
886  if (! file.isEmpty ())
887  {
888  // Check whether this file is already open in the editor.
889  QWidget *tab = find_tab_widget (file);
890 
891  if (tab)
892  {
893  m_tab_widget->setCurrentWidget (tab);
894 
895  if (line > 0)
897 
898  emit fetab_set_focus (tab);
899  }
900  }
901  }
902 
904  const QString& file,
905  int line,
906  const QString& cond)
907  {
908  request_open_file (file, QString (), line, false, true, insert, cond);
909  }
910 
912  {
914  }
915 
916  // Slot used for signals indicating that a file was changed/rename or
917  // is going to be deleted/renamed
918  void file_editor::handle_file_remove (const QString& old_name,
919  const QString& new_name)
920  {
921  // Clear old lsit of files to reload
922  m_tmp_closed_files.clear ();
923 
924  // Check if old name is a file or directory
925  QFileInfo old (old_name);
926  if (old.isDir ())
927  {
928  // Call the function which handles directories and return
929  handle_dir_remove (old_name, new_name);
930  return;
931  }
932 
933  // Is old file open?
934  file_editor_tab *editor_tab
935  = static_cast<file_editor_tab *> (find_tab_widget (old_name));
936 
937  if (editor_tab)
938  {
939  // Yes, close it silently
940  m_no_focus = true; // Remember for not focussing editor
941  editor_tab->file_has_changed (QString (), true); // Close the tab
942  m_no_focus = false; // Back to normal
943 
944  m_tmp_closed_files << old_name; // for reloading if error removing
945 
946  if (! new_name.isEmpty ())
947  m_tmp_closed_files << new_name; // store new name
948  else
949  m_tmp_closed_files << ""; // no new name, just removing this file
950 
951  // Get and store the related encoding
953  p != m_editor_tab_map.end (); p++)
954  {
955  if (editor_tab == p->second.fet_ID)
956  {
957  m_tmp_closed_files << p->second.encoding;
958  break;
959  }
960  }
961  }
962  }
963 
964  // Slot for signal indicating that a file was renamed
965  void file_editor::handle_file_renamed (bool load_new)
966  {
967  m_no_focus = true; // Remember for not focussing editor
968  for (int i = 0; i < m_tmp_closed_files.count (); i = i + 3)
969  {
970  if (! m_tmp_closed_files.at (i + load_new).isEmpty ())
971  request_open_file (m_tmp_closed_files.at (i + load_new),
972  m_tmp_closed_files.at (i+2));
973  }
974  m_no_focus = false; // Back to normal focus
975  }
976 
977  void file_editor::notice_settings (const QSettings *settings)
978  {
979  int icon_size_settings = settings->value ("toolbar_icon_size",0).toInt ();
980  QStyle *st = style ();
981  int icon_size = st->pixelMetric (QStyle::PM_ToolBarIconSize);
982 
983  if (icon_size_settings == 1)
984  icon_size = st->pixelMetric (QStyle::PM_LargeIconSize);
985  else if (icon_size_settings == -1)
986  icon_size = st->pixelMetric (QStyle::PM_SmallIconSize);
987 
988  m_tool_bar->setIconSize (QSize (icon_size,icon_size));
989 
990  int tab_width_min = settings->value ("editor/notebook_tab_width_min", 160)
991  .toInt ();
992  int tab_width_max = settings->value ("editor/notebook_tab_width_max", 300)
993  .toInt ();
994 
995  if (settings->value ("editor/longWindowTitle", false).toBool ())
996  {
997  QString style_sheet = QString ("QTabBar::tab "
998  "{min-width: %1px; max-width: %2px;}")
999  .arg (tab_width_min).arg (tab_width_max);
1000  m_tab_widget->setElideMode (Qt::ElideLeft);
1001  m_tab_widget->setStyleSheet (style_sheet);
1002  }
1003  else
1004  m_tab_widget->setElideMode (Qt::ElideNone);
1005 
1006  m_tab_widget->setUsesScrollButtons (true);
1007 
1008  bool show_it;
1009  show_it = settings->value ("editor/showLineNumbers",true).toBool ();
1010  m_show_linenum_action->setChecked (show_it);
1011  show_it = settings->value ("editor/show_white_space",false).toBool ();
1012  m_show_whitespace_action->setChecked (show_it);
1013  show_it = settings->value ("editor/show_eol_chars",false).toBool ();
1014  m_show_eol_action->setChecked (show_it);
1015  show_it = settings->value ("editor/show_indent_guides",false).toBool ();
1016  m_show_indguide_action->setChecked (show_it);
1017  show_it = settings->value ("editor/long_line_marker",true).toBool ();
1018  m_show_longline_action->setChecked (show_it);
1019 
1020  show_it = settings->value ("editor/show_toolbar",true).toBool ();
1021  m_show_toolbar_action->setChecked (show_it);
1022  m_tool_bar->setVisible (show_it);
1023  show_it = settings->value ("editor/show_edit_status_bar",true).toBool ();
1024  m_show_statusbar_action->setChecked (show_it);
1025  show_it = settings->value ("editor/show_hscroll_bar",true).toBool ();
1026  m_show_hscrollbar_action->setChecked (show_it);
1027 
1028  set_shortcuts ();
1029 
1030  // Relay signal to file editor tabs.
1031  emit fetab_settings_changed (settings);
1032  }
1033 
1035  {
1036  // Shortcuts also available in the main window, as well as the realted
1037  // ahotcuts, are defined in main_window and added to the editor
1038 
1039  // File menu
1040  shortcut_manager::set_shortcut (m_edit_function_action, "editor_file:edit_function");
1041  shortcut_manager::set_shortcut (m_save_action, "editor_file:save");
1042  shortcut_manager::set_shortcut (m_save_as_action, "editor_file:save_as");
1043  shortcut_manager::set_shortcut (m_close_action, "editor_file:close");
1044  shortcut_manager::set_shortcut (m_close_all_action, "editor_file:close_all");
1045  shortcut_manager::set_shortcut (m_close_others_action, "editor_file:close_other");
1046  shortcut_manager::set_shortcut (m_print_action, "editor_file:print");
1047 
1048  // Edit menu
1049  shortcut_manager::set_shortcut (m_redo_action, "editor_edit:redo");
1050  shortcut_manager::set_shortcut (m_cut_action, "editor_edit:cut");
1051  shortcut_manager::set_shortcut (m_find_action, "editor_edit:find_replace");
1052  shortcut_manager::set_shortcut (m_find_next_action, "editor_edit:find_next");
1053  shortcut_manager::set_shortcut (m_find_previous_action, "editor_edit:find_previous");
1054 
1055  shortcut_manager::set_shortcut (m_delete_start_word_action, "editor_edit:delete_start_word");
1056  shortcut_manager::set_shortcut (m_delete_end_word_action, "editor_edit:delete_end_word");
1057  shortcut_manager::set_shortcut (m_delete_start_line_action, "editor_edit:delete_start_line");
1058  shortcut_manager::set_shortcut (m_delete_end_line_action, "editor_edit:delete_end_line");
1059  shortcut_manager::set_shortcut (m_delete_line_action, "editor_edit:delete_line");
1060  shortcut_manager::set_shortcut (m_copy_line_action, "editor_edit:copy_line");
1061  shortcut_manager::set_shortcut (m_cut_line_action, "editor_edit:cut_line");
1062  shortcut_manager::set_shortcut (m_duplicate_selection_action, "editor_edit:duplicate_selection");
1063  shortcut_manager::set_shortcut (m_transpose_line_action, "editor_edit:transpose_line");
1064  shortcut_manager::set_shortcut (m_comment_selection_action, "editor_edit:comment_selection");
1065  shortcut_manager::set_shortcut (m_uncomment_selection_action, "editor_edit:uncomment_selection");
1066  shortcut_manager::set_shortcut (m_comment_var_selection_action, "editor_edit:comment_var_selection");
1067 
1068  shortcut_manager::set_shortcut (m_upper_case_action, "editor_edit:upper_case");
1069  shortcut_manager::set_shortcut (m_lower_case_action, "editor_edit:lower_case");
1070  shortcut_manager::set_shortcut (m_indent_selection_action, "editor_edit:indent_selection");
1071  shortcut_manager::set_shortcut (m_unindent_selection_action, "editor_edit:unindent_selection");
1072  shortcut_manager::set_shortcut (m_smart_indent_line_or_selection_action, "editor_edit:smart_indent_line_or_selection");
1073  shortcut_manager::set_shortcut (m_completion_action, "editor_edit:completion_list");
1074  shortcut_manager::set_shortcut (m_goto_line_action, "editor_edit:goto_line");
1075  shortcut_manager::set_shortcut (m_move_to_matching_brace, "editor_edit:move_to_brace");
1076  shortcut_manager::set_shortcut (m_sel_to_matching_brace, "editor_edit:select_to_brace");
1077  shortcut_manager::set_shortcut (m_toggle_bookmark_action, "editor_edit:toggle_bookmark");
1078  shortcut_manager::set_shortcut (m_next_bookmark_action, "editor_edit:next_bookmark");
1079  shortcut_manager::set_shortcut (m_previous_bookmark_action, "editor_edit:previous_bookmark");
1080  shortcut_manager::set_shortcut (m_remove_bookmark_action, "editor_edit:remove_bookmark");
1081  shortcut_manager::set_shortcut (m_preferences_action, "editor_edit:preferences");
1082  shortcut_manager::set_shortcut (m_styles_preferences_action, "editor_edit:styles_preferences");
1083 
1084  shortcut_manager::set_shortcut (m_conv_eol_windows_action, "editor_edit:conv_eol_winows");
1085  shortcut_manager::set_shortcut (m_conv_eol_unix_action, "editor_edit:conv_eol_unix");
1086  shortcut_manager::set_shortcut (m_conv_eol_mac_action, "editor_edit:conv_eol_mac");
1087 
1088  // View menu
1089  shortcut_manager::set_shortcut (m_show_linenum_action, "editor_view:show_line_numbers");
1090  shortcut_manager::set_shortcut (m_show_whitespace_action, "editor_view:show_white_spaces");
1091  shortcut_manager::set_shortcut (m_show_eol_action, "editor_view:show_eol_chars");
1092  shortcut_manager::set_shortcut (m_show_indguide_action, "editor_view:show_ind_guides");
1093  shortcut_manager::set_shortcut (m_show_longline_action, "editor_view:show_long_line");
1094  shortcut_manager::set_shortcut (m_show_toolbar_action, "editor_view:show_toolbar");
1095  shortcut_manager::set_shortcut (m_show_statusbar_action, "editor_view:show_statusbar");
1096  shortcut_manager::set_shortcut (m_show_hscrollbar_action, "editor_view:show_hscrollbar");
1097  shortcut_manager::set_shortcut (m_zoom_in_action, "editor_view:zoom_in");
1098  shortcut_manager::set_shortcut (m_zoom_out_action, "editor_view:zoom_out");
1099  shortcut_manager::set_shortcut (m_zoom_normal_action, "editor_view:zoom_normal");
1100 
1101  // Debug menu
1102  shortcut_manager::set_shortcut (m_toggle_breakpoint_action, "editor_debug:toggle_breakpoint");
1103  shortcut_manager::set_shortcut (m_next_breakpoint_action, "editor_debug:next_breakpoint");
1104  shortcut_manager::set_shortcut (m_previous_breakpoint_action, "editor_debug:previous_breakpoint");
1105  shortcut_manager::set_shortcut (m_remove_all_breakpoints_action, "editor_debug:remove_breakpoints");
1106 
1107  // Run menu
1108  shortcut_manager::set_shortcut (m_run_action, "editor_run:run_file");
1109  shortcut_manager::set_shortcut (m_run_selection_action, "editor_run:run_selection");
1110 
1111  // Help menu
1112  shortcut_manager::set_shortcut (m_context_help_action, "editor_help:help_keyword");
1113  shortcut_manager::set_shortcut (m_context_doc_action, "editor_help:doc_keyword");
1114 
1115  // Tab navigation without menu entries
1116  shortcut_manager::set_shortcut (m_switch_left_tab_action, "editor_tabs:switch_left_tab");
1117  shortcut_manager::set_shortcut (m_switch_right_tab_action, "editor_tabs:switch_right_tab");
1118  shortcut_manager::set_shortcut (m_move_tab_left_action, "editor_tabs:move_tab_left");
1119  shortcut_manager::set_shortcut (m_move_tab_right_action, "editor_tabs:move_tab_right");
1120 
1121  }
1122 
1123  // This slot is a reimplementation of the virtual slot in octave_dock_widget.
1124  // We need this for creating an empty script when the editor has no open files
1125  // and is made visible
1127  {
1128  if (m_closed && visible)
1129  {
1130  m_closed = false;
1131  QSettings *settings = resource_manager::get_settings ();
1132  restore_session (settings);
1133  }
1134 
1135  empty_script (false, visible);
1136 
1137  if (visible && ! isFloating ())
1138  focus ();
1139 
1140  }
1141 
1142  void file_editor::update_octave_directory (const QString& dir)
1143  {
1144  m_ced = dir;
1145  emit fetab_set_directory (m_ced); // for save dialog
1146  }
1147 
1149  {
1150  if (editor_tab_has_focus ())
1151  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
1152  QsciScintillaBase::SCI_COPY);
1153  }
1154 
1156  {
1157  if (editor_tab_has_focus ())
1158  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
1159  QsciScintillaBase::SCI_PASTE);
1160  }
1161 
1163  {
1164  if (editor_tab_has_focus ())
1165  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
1166  QsciScintillaBase::SCI_SELECTALL);
1167  }
1168 
1170  {
1171  if (editor_tab_has_focus ())
1172  emit fetab_scintilla_command (m_tab_widget->currentWidget (),
1173  QsciScintillaBase::SCI_UNDO);
1174  }
1175 
1176  // Open a file, if not already open, and mark the current execution location
1177  // and/or a breakpoint with condition cond.
1178  void file_editor::request_open_file (const QString& openFileName,
1179  const QString& encoding,
1180  int line, bool debug_pointer,
1181  bool breakpoint_marker, bool insert,
1182  const QString& cond)
1183  {
1184  if (call_custom_editor (openFileName, line))
1185  return; // custom editor called
1186 
1187  if (openFileName.isEmpty ())
1188  {
1189  // This happens if edit is calles without an argument
1190  // Open eitor with empty edit area instead (as new file would do)
1191  request_new_file ("");
1192  }
1193  else
1194  {
1195  // Check whether this file is already open in the editor.
1196  QWidget *tab = find_tab_widget (openFileName);
1197 
1198  if (tab)
1199  {
1200  m_tab_widget->setCurrentWidget (tab);
1201 
1202  if (line > 0)
1203  {
1204  if (insert)
1205  emit fetab_goto_line (tab, line);
1206 
1207  if (debug_pointer)
1208  emit fetab_insert_debugger_pointer (tab, line);
1209 
1210  if (breakpoint_marker)
1211  emit fetab_do_breakpoint_marker (insert, tab, line, cond);
1212  }
1213 
1214  if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ()))
1215  {
1216  emit fetab_set_focus (tab);
1217  focus ();
1218  }
1219  }
1220  else
1221  {
1222  file_editor_tab *fileEditorTab = nullptr;
1223  // Reuse <unnamed> tab if it hasn't yet been modified.
1224  bool reusing = false;
1225  tab = find_tab_widget ("");
1226  if (tab)
1227  {
1228  fileEditorTab = static_cast<file_editor_tab *>(tab);
1229  if (fileEditorTab->qsci_edit_area ()->isModified ())
1230  fileEditorTab = nullptr;
1231  else
1232  reusing = true;
1233  }
1234 
1235  // If <unnamed> was absent or modified, create a new tab.
1236  if (! fileEditorTab)
1237  fileEditorTab = new file_editor_tab ();
1238 
1239  if (fileEditorTab)
1240  {
1241  fileEditorTab->set_encoding (encoding);
1242  QString result = fileEditorTab->load_file (openFileName);
1243  if (result == "")
1244  {
1245  // Supply empty title then have the file_editor_tab update
1246  // with full or short name.
1247  if (! reusing)
1248  add_file_editor_tab (fileEditorTab, "");
1249  fileEditorTab->update_window_title (false);
1250  // file already loaded, add file to mru list here
1251  QFileInfo file_info = QFileInfo (openFileName);
1252  handle_mru_add_file (file_info.canonicalFilePath (),
1253  encoding);
1254 
1255  if (line > 0)
1256  {
1257  if (insert)
1258  emit fetab_goto_line (fileEditorTab, line);
1259 
1260  if (debug_pointer)
1261  emit fetab_insert_debugger_pointer (fileEditorTab,
1262  line);
1263  if (breakpoint_marker)
1264  emit fetab_do_breakpoint_marker (insert, fileEditorTab,
1265  line, cond);
1266  }
1267  }
1268  else
1269  {
1270  delete fileEditorTab;
1271 
1272  if (QFile::exists (openFileName))
1273  {
1274  // File not readable:
1275  // create a NonModal message about error.
1276  QMessageBox *msgBox
1277  = new QMessageBox (QMessageBox::Critical,
1278  tr ("Octave Editor"),
1279  tr ("Could not open file\n%1\nfor read: %2.").
1280  arg (openFileName).arg (result),
1281  QMessageBox::Ok, this);
1282 
1283  msgBox->setWindowModality (Qt::NonModal);
1284  msgBox->setAttribute (Qt::WA_DeleteOnClose);
1285  msgBox->show ();
1286  }
1287  else
1288  {
1289  // File does not exist, should it be created?
1290  bool create_file = true;
1291  QMessageBox *msgBox;
1292  QSettings *settings = resource_manager::get_settings ();
1293 
1294  if (! settings->value ("editor/create_new_file", false).toBool ())
1295  {
1296  msgBox = new QMessageBox (QMessageBox::Question,
1297  tr ("Octave Editor"),
1298  tr ("File\n%1\ndoes not exist. "
1299  "Do you want to create it?").arg (openFileName),
1300  QMessageBox::NoButton,nullptr);
1301  QPushButton *create_button =
1302  msgBox->addButton (tr ("Create"), QMessageBox::YesRole);
1303  msgBox->addButton (tr ("Cancel"), QMessageBox::RejectRole);
1304  msgBox->setDefaultButton (create_button);
1305  msgBox->exec ();
1306 
1307  QAbstractButton *clicked_button = msgBox->clickedButton ();
1308  if (clicked_button != create_button)
1309  create_file = false;
1310 
1311  delete msgBox;
1312  }
1313 
1314  if (create_file)
1315  {
1316  // create the file and call the editor again
1317  QFile file (openFileName);
1318  if (! file.open (QIODevice::WriteOnly))
1319  {
1320  // error opening the file
1321  msgBox = new QMessageBox (QMessageBox::Critical,
1322  tr ("Octave Editor"),
1323  tr ("Could not open file\n%1\nfor write: %2.").
1324  arg (openFileName).arg (file.errorString ()),
1325  QMessageBox::Ok, this);
1326 
1327  msgBox->setWindowModality (Qt::NonModal);
1328  msgBox->setAttribute (Qt::WA_DeleteOnClose);
1329  msgBox->show ();
1330  }
1331  else
1332  {
1333  file.close ();
1334  request_open_file (openFileName);
1335  }
1336  }
1337  }
1338  }
1339  }
1340 
1341  if (! ((breakpoint_marker || debug_pointer) && is_editor_console_tabbed ()))
1342  {
1343  // really show editor and the current editor tab
1344  focus ();
1345  emit file_loaded_signal ();
1346  }
1347  }
1348  }
1349  }
1350 
1352  {
1353  emit request_settings_dialog ("editor");
1354  }
1355 
1357  {
1358  emit request_settings_dialog ("editor_styles");
1359  }
1360 
1362  {
1363  toggle_preference ("editor/showLineNumbers",true);
1364  }
1365 
1367  {
1368  toggle_preference ("editor/show_white_space",false);
1369  }
1370 
1372  {
1373  toggle_preference ("editor/show_eol_chars",false);
1374  }
1375 
1377  {
1378  toggle_preference ("editor/show_indent_guides",false);
1379  }
1380 
1382  {
1383  toggle_preference ("editor/long_line_marker",true);
1384  }
1385 
1387  {
1388  toggle_preference ("editor/show_toolbar",true);
1389  }
1390 
1392  {
1393  toggle_preference ("editor/show_edit_status_bar",true);
1394  }
1395 
1397  {
1398  toggle_preference ("editor/show_hscroll_bar",true);
1399  }
1400 
1402  {
1403  emit fetab_zoom_in (m_tab_widget->currentWidget ());
1404  }
1405 
1407  {
1408  emit fetab_zoom_out (m_tab_widget->currentWidget ());
1409  }
1410 
1412  {
1413  emit fetab_zoom_normal (m_tab_widget->currentWidget ());
1414  }
1415 
1417  {
1418  // remove all standard actions from scintilla
1419  QList<QAction *> all_actions = menu->actions ();
1420  QAction *a;
1421 
1422  foreach (a, all_actions)
1423  menu->removeAction (a);
1424 
1425  // add editor's actions with icons and customized shortcuts
1426  menu->addAction (m_undo_action);
1427  menu->addAction (m_redo_action);
1428  menu->addSeparator ();
1429  menu->addAction (m_cut_action);
1430  menu->addAction (m_copy_action);
1431  menu->addAction (m_paste_action);
1432  menu->addSeparator ();
1433  menu->addAction (m_selectall_action);
1434  menu->addSeparator ();
1435  menu->addAction (m_find_files_action);
1436  menu->addAction (m_find_action);
1437  menu->addAction (m_find_next_action);
1438  menu->addAction (m_find_previous_action);
1439  menu->addSeparator ();
1440  menu->addMenu (m_edit_cmd_menu);
1441  menu->addMenu (m_edit_fmt_menu);
1442  menu->addMenu (m_edit_nav_menu);
1443  menu->addSeparator ();
1444  menu->addAction (m_run_selection_action);
1445  }
1446 
1447  void file_editor::edit_status_update (bool undo, bool redo)
1448  {
1449  if (m_undo_action)
1450  m_undo_action->setEnabled (undo);
1451  m_redo_action->setEnabled (redo);
1452  }
1453 
1454  // handler for the close event
1455  void file_editor::closeEvent (QCloseEvent *e)
1456  {
1457  QSettings *settings = resource_manager::get_settings ();
1458  if (settings->value ("editor/hiding_closes_files",false).toBool ())
1459  {
1460  if (check_closing ())
1461  {
1462  // all tabs are closed without cancelling,
1463  // store closing state for restoring session when shown again
1464  m_closed = true;
1465  e->accept ();
1466  }
1467  else
1468  e->ignore ();
1469  }
1470  else
1471  e->accept ();
1472  }
1473 
1474  void file_editor::dragEnterEvent (QDragEnterEvent *e)
1475  {
1476  if (e->mimeData ()->hasUrls ())
1477  {
1478  e->acceptProposedAction ();
1479  }
1480  }
1481 
1482  void file_editor::dropEvent (QDropEvent *e)
1483  {
1484  if (e->mimeData ()->hasUrls ())
1485  {
1486  foreach (QUrl url, e->mimeData ()->urls ())
1487  request_open_file (url.toLocalFile ());
1488  }
1489  }
1490 
1492  {
1493  octave::main_window *w = static_cast<octave::main_window *>(main_win ());
1494  QList<QDockWidget *> w_list = w->tabifiedDockWidgets (this);
1495  QDockWidget *console =
1496  static_cast<QDockWidget *> (w->get_dock_widget_list ().at (0));
1497 
1498  for (int i = 0; i < w_list.count (); i++)
1499  {
1500  if (w_list.at (i) == console)
1501  return true;
1502  }
1503 
1504  return false;
1505  }
1506 
1508  {
1509  QWidget *editor_widget = new QWidget (this);
1510 
1511  // FIXME: what was the intended purpose of this unused variable?
1512  // QStyle *editor_style = QApplication::style ();
1513 
1514  // Menu bar: do not set it native, required in MacOS and Ubuntu Unity (Qt5)
1515  // for a visible menu bar in the editor widget. This property is ignored
1516  // on other platforms.
1517  m_menu_bar = new QMenuBar (editor_widget);
1518  m_menu_bar->setNativeMenuBar (false);
1519 
1520  m_tool_bar = new QToolBar (editor_widget);
1521  m_tool_bar->setMovable (true);
1522 
1523  m_tab_widget = new file_editor_tab_widget (editor_widget);
1524 
1525  // the mru-list and an empty array of actions
1526  QSettings *settings = resource_manager::get_settings ();
1527  m_mru_files = settings->value ("editor/mru_file_list").toStringList ();
1528  m_mru_files_encodings = settings->value ("editor/mru_file_encodings")
1529  .toStringList ();
1530 
1531  if (m_mru_files_encodings.count () != m_mru_files.count ())
1532  {
1533  // encodings don't have the same count -> do not use them!
1534  m_mru_files_encodings = QStringList ();
1535  for (int i = 0; i < m_mru_files.count (); i++)
1536  m_mru_files_encodings << QString ();
1537  }
1538 
1539  for (int i = 0; i < MaxMRUFiles; ++i)
1540  {
1541  m_mru_file_actions[i] = new QAction (this);
1542  m_mru_file_actions[i]->setVisible (false);
1543  }
1544 
1545  // menu bar
1546 
1547  // file menu
1548 
1549  m_fileMenu = add_menu (m_menu_bar, tr ("&File"));
1550 
1551  // new and open menus are inserted later by the main window
1552  m_mru_file_menu = new QMenu (tr ("&Recent Editor Files"), m_fileMenu);
1553  for (int i = 0; i < MaxMRUFiles; ++i)
1554  m_mru_file_menu->addAction (m_mru_file_actions[i]);
1555  m_fileMenu->addMenu (m_mru_file_menu);
1556 
1557  m_fileMenu->addSeparator ();
1558 
1561  tr ("&Edit Function"),
1562  SLOT (request_context_edit (bool)));
1563 
1564  m_fileMenu->addSeparator ();
1565 
1568  resource_manager::icon ("document-save"),
1569  tr ("&Save File"),
1570  SLOT (request_save_file (bool)));
1571 
1574  resource_manager::icon ("document-save-as"),
1575  tr ("Save File &As..."),
1576  SLOT (request_save_file_as (bool)));
1577 
1578  m_fileMenu->addSeparator ();
1579 
1582  resource_manager::icon ("window-close",false),
1583  tr ("&Close"),
1584  SLOT (request_close_file (bool)));
1585 
1588  resource_manager::icon ("window-close",false),
1589  tr ("Close All"),
1590  SLOT (request_close_all_files (bool)));
1591 
1594  resource_manager::icon ("window-close",false),
1595  tr ("Close Other Files"),
1596  SLOT (request_close_other_files (bool)));
1597 
1598  m_fileMenu->addSeparator ();
1599 
1602  resource_manager::icon ("document-print"),
1603  tr ("Print..."),
1604  SLOT (request_print_file (bool)));
1605 
1606  // edit menu (undo, copy, paste and select all later via main window)
1607 
1608  m_edit_menu = add_menu (m_menu_bar, tr ("&Edit"));
1609 
1612  resource_manager::icon ("edit-redo"),
1613  tr ("&Redo"),
1614  SLOT (request_redo (bool)));
1615  m_redo_action->setEnabled (false);
1616 
1617  m_edit_menu->addSeparator ();
1618 
1619  m_cut_action
1621  resource_manager::icon ("edit-cut"),
1622  tr ("Cu&t"),
1623  SLOT (request_cut (bool)));
1624  m_cut_action->setEnabled (false);
1625 
1628  resource_manager::icon ("edit-find-replace"),
1629  tr ("&Find and Replace..."),
1630  SLOT (request_find (bool)));
1631 
1634  tr ("Find &Next..."),
1635  SLOT (request_find_next (bool)));
1636 
1639  tr ("Find &Previous..."),
1640  SLOT (request_find_previous (bool)));
1641 
1642  m_edit_menu->addSeparator ();
1643 
1644  m_edit_cmd_menu = m_edit_menu->addMenu (tr ("&Commands"));
1645 
1648  tr ("Delete Line"),
1649  SLOT (request_delete_line (bool)));
1650 
1653  tr ("Copy Line"),
1654  SLOT (request_copy_line (bool)));
1655 
1658  tr ("Cut Line"),
1659  SLOT (request_cut_line (bool)));
1660 
1661  m_edit_cmd_menu->addSeparator ();
1662 
1665  tr ("Delete to Start of Word"),
1666  SLOT (request_delete_start_word (bool)));
1667 
1670  tr ("Delete to End of Word"),
1671  SLOT (request_delete_end_word (bool)));
1672 
1675  tr ("Delete to Start of Line"),
1676  SLOT (request_delete_start_line (bool)));
1677 
1680  tr ("Delete to End of Line"),
1681  SLOT (request_delete_end_line (bool)));
1682 
1683  m_edit_cmd_menu->addSeparator ();
1684 
1687  tr ("Duplicate Selection/Line"),
1688  SLOT (request_duplicate_selection (bool)));
1689 
1692  tr ("Transpose Line"),
1693  SLOT (request_transpose_line (bool)));
1694 
1695  m_edit_cmd_menu->addSeparator ();
1696 
1699  tr ("&Show Completion List"),
1700  SLOT (request_completion (bool)));
1701 
1702  m_edit_fmt_menu = m_edit_menu->addMenu (tr ("&Format"));
1703 
1706  tr ("&Uppercase Selection"),
1707  SLOT (request_upper_case (bool)));
1708 
1711  tr ("&Lowercase Selection"),
1712  SLOT (request_lower_case (bool)));
1713 
1714  m_edit_fmt_menu->addSeparator ();
1715 
1718  tr ("&Comment"),
1719  SLOT (request_comment_selected_text (bool)));
1720 
1723  tr ("&Uncomment"),
1724  SLOT (request_uncomment_selected_text (bool)));
1725 
1728  tr ("Comment (Choosing String)"),
1729  SLOT (request_comment_var_selected_text (bool)));
1730 
1731  m_edit_fmt_menu->addSeparator ();
1732 
1735  tr ("&Indent Selection Rigidly"),
1736  SLOT (request_indent_selected_text (bool)));
1737 
1740  tr ("&Unindent Selection Rigidly"),
1741  SLOT (request_unindent_selected_text (bool)));
1742 
1745  tr ("Indent Code"),
1747 
1748  m_edit_fmt_menu->addSeparator ();
1749 
1752  tr ("Convert Line Endings to &Windows (CRLF)"),
1753  SLOT (request_conv_eol_windows (bool)));
1754 
1757  tr ("Convert Line Endings to &Unix (LF)"),
1758  SLOT (request_conv_eol_unix (bool)));
1759 
1762  tr ("Convert Line Endings to &Mac (CR)"),
1763  SLOT (request_conv_eol_mac (bool)));
1764 
1765  m_edit_nav_menu = m_edit_menu->addMenu (tr ("Navi&gation"));
1766 
1769  tr ("Go &to Line..."),
1770  SLOT (request_goto_line (bool)));
1771 
1772  m_edit_cmd_menu->addSeparator ();
1773 
1776  tr ("Move to Matching Brace"),
1777  SLOT (request_move_match_brace (bool)));
1778 
1781  tr ("Select to Matching Brace"),
1782  SLOT (request_sel_match_brace (bool)));
1783 
1784  m_edit_nav_menu->addSeparator ();
1785 
1788  tr ("&Next Bookmark"),
1789  SLOT (request_next_bookmark (bool)));
1790 
1793  tr ("Pre&vious Bookmark"),
1794  SLOT (request_previous_bookmark (bool)));
1795 
1798  tr ("Toggle &Bookmark"),
1799  SLOT (request_toggle_bookmark (bool)));
1800 
1803  tr ("&Remove All Bookmarks"),
1804  SLOT (request_remove_bookmark (bool)));
1805 
1806  m_edit_menu->addSeparator ();
1807 
1810  resource_manager::icon ("preferences-system"),
1811  tr ("&Preferences..."),
1812  SLOT (request_preferences (bool)));
1813 
1815  = add_action (m_edit_menu, resource_manager::icon ("preferences-system"),
1816  tr ("&Styles Preferences..."),
1817  SLOT (request_styles_preferences (bool)));
1818 
1819  // view menu
1820 
1821  QMenu *view_menu = add_menu (m_menu_bar, tr ("&View"));
1822 
1823  m_view_editor_menu = view_menu->addMenu (tr ("&Editor"));
1824 
1827  tr ("Show &Line Numbers"),
1828  SLOT (show_line_numbers (bool)));
1829  m_show_linenum_action->setCheckable (true);
1830 
1833  tr ("Show &Whitespace Characters"),
1834  SLOT (show_white_space (bool)));
1835  m_show_whitespace_action->setCheckable (true);
1836 
1839  tr ("Show Line &Endings"),
1840  SLOT (show_eol_chars (bool)));
1841  m_show_eol_action->setCheckable (true);
1842 
1845  tr ("Show &Indentation Guides"),
1846  SLOT (show_indent_guides (bool)));
1847  m_show_indguide_action->setCheckable (true);
1848 
1851  tr ("Show Long Line &Marker"),
1852  SLOT (show_long_line (bool)));
1853  m_show_longline_action->setCheckable (true);
1854 
1855  m_view_editor_menu->addSeparator ();
1856 
1859  tr ("Show &Toolbar"),
1860  SLOT (show_toolbar (bool)));
1861  m_show_toolbar_action->setCheckable (true);
1862 
1865  tr ("Show &Statusbar"),
1866  SLOT (show_statusbar (bool)));
1867  m_show_statusbar_action->setCheckable (true);
1868 
1871  tr ("Show &Horizontal Scrollbar"),
1872  SLOT (show_hscrollbar (bool)));
1873  m_show_hscrollbar_action->setCheckable (true);
1874 
1875  view_menu->addSeparator ();
1876 
1878  = add_action (view_menu, resource_manager::icon ("zoom-in"),
1879  tr ("Zoom &In"),
1880  SLOT (zoom_in (bool)));
1881 
1883  = add_action (view_menu, resource_manager::icon ("zoom-out"),
1884  tr ("Zoom &Out"),
1885  SLOT (zoom_out (bool)));
1886 
1888  = add_action (view_menu,
1889  tr ("&Normal Size"),
1890  SLOT (zoom_normal (bool)));
1891 
1892  m_menu_bar->addMenu (view_menu);
1893 
1894  // debug menu
1895 
1896  m_debug_menu = add_menu (m_menu_bar, tr ("&Debug"));
1897 
1900  resource_manager::icon ("bp-toggle"),
1901  tr ("Toggle &Breakpoint"),
1902  SLOT (request_toggle_breakpoint (bool)));
1903 
1906  resource_manager::icon ("bp-next"),
1907  tr ("&Next Breakpoint"),
1908  SLOT (request_next_breakpoint (bool)));
1909 
1912  resource_manager::icon ("bp-prev"),
1913  tr ("Pre&vious Breakpoint"),
1914  SLOT (request_previous_breakpoint (bool)));
1915 
1918  resource_manager::icon ("bp-rm-all"),
1919  tr ("&Remove All Breakpoints"),
1920  SLOT (request_remove_breakpoint (bool)));
1921 
1922  m_debug_menu->addSeparator ();
1923 
1924  // The other debug actions will be added by the main window.
1925 
1926  // run menu
1927 
1928  QMenu *_run_menu = add_menu (m_menu_bar, tr ("&Run"));
1929 
1930  m_run_action
1931  = add_action (_run_menu,
1932  resource_manager::icon ("system-run"),
1933  tr ("Save File and Run"),
1934  SLOT (request_run_file (bool)));
1935 
1937  = add_action (_run_menu,
1938  tr ("Run &Selection"),
1939  SLOT (request_context_run (bool)));
1940  m_run_selection_action->setEnabled (false);
1941 
1942  // help menu
1943 
1944  QMenu *_help_menu = add_menu (m_menu_bar, tr ("&Help"));
1945 
1947  = add_action (_help_menu,
1948  tr ("&Help on Keyword"),
1949  SLOT (request_context_help (bool)));
1950 
1952  = add_action (_help_menu,
1953  tr ("&Documentation on Keyword"),
1954  SLOT (request_context_doc (bool)));
1955 
1956  // tab navigation (no menu, only actions; slots in tab_bar)
1957 
1959  = add_action (nullptr, "", SLOT (switch_left_tab (void)),
1961 
1963  = add_action (nullptr, "", SLOT (switch_right_tab (void)),
1965 
1967  = add_action (nullptr, "", SLOT (move_tab_left (void)),
1969 
1971  = add_action (nullptr, "", SLOT (move_tab_right (void)),
1973 
1974  // toolbar
1975 
1976  // popdown menu with mru files
1977  QToolButton *popdown_button = new QToolButton ();
1978  popdown_button->setToolTip (tr ("Recent Files"));
1979  popdown_button->setMenu (m_mru_file_menu);
1980  popdown_button->setPopupMode (QToolButton::InstantPopup);
1981  popdown_button->setToolButtonStyle (Qt::ToolButtonTextOnly);
1982 
1983  // new and open actions are inserted later from main window
1984  m_popdown_mru_action = m_tool_bar->addWidget (popdown_button);
1985  m_tool_bar->addAction (m_save_action);
1986  m_tool_bar->addAction (m_save_as_action);
1987  m_tool_bar->addAction (m_print_action);
1988  m_tool_bar->addSeparator ();
1989  // m_undo_action: later via main window
1990  m_tool_bar->addAction (m_redo_action);
1991  // m_copy_action: later via the main window
1992  m_tool_bar->addAction (m_cut_action);
1993  // m_paste_action: later via the main window
1994  m_tool_bar->addAction (m_find_action);
1995  //m_tool_bar->addAction (m_find_next_action);
1996  //m_tool_bar->addAction (m_find_previous_action);
1997  m_tool_bar->addSeparator ();
1998  m_tool_bar->addAction (m_run_action);
1999  m_tool_bar->addSeparator ();
2002  m_tool_bar->addAction (m_next_breakpoint_action);
2004 
2005  // layout
2006  QVBoxLayout *vbox_layout = new QVBoxLayout ();
2007  vbox_layout->addWidget (m_menu_bar);
2008  vbox_layout->addWidget (m_tool_bar);
2009  vbox_layout->addWidget (m_tab_widget);
2010  vbox_layout->setMargin (0);
2011  editor_widget->setLayout (vbox_layout);
2012  setWidget (editor_widget);
2013 
2014  // create the context menu of the tab bar
2015  tab_bar *bar = m_tab_widget->get_tab_bar ();
2016  QMenu *ctx_men = bar->get_context_menu ();
2017  ctx_men->addAction (m_close_action);
2018  ctx_men->addAction (m_close_all_action);
2019  ctx_men->addAction (m_close_others_action);
2020 
2021  // signals
2022  connect (this,
2023  SIGNAL (execute_command_in_terminal_signal (const QString&)),
2024  main_win (), SLOT (execute_command_in_terminal (const QString&)));
2025 
2026  connect (this, SIGNAL (request_settings_dialog (const QString&)),
2027  main_win (),
2028  SLOT (process_settings_dialog_request (const QString&)));
2029 
2030  connect (m_mru_file_menu, SIGNAL (triggered (QAction *)),
2031  this, SLOT (request_mru_open_file (QAction *)));
2032 
2033  mru_menu_update ();
2034 
2035  connect (m_tab_widget, SIGNAL (tabCloseRequested (int)),
2036  this, SLOT (handle_tab_close_request (int)));
2037 
2038  connect (m_tab_widget, SIGNAL (currentChanged (int)),
2039  this, SLOT (active_tab_changed (int)));
2040 
2041  resize (500, 400);
2042  setWindowIcon (QIcon (":/actions/icons/logo.png"));
2043  set_title (tr ("Editor"));
2044 
2045  check_actions ();
2046  }
2047 
2049  {
2050  m_tab_widget->addTab (f, fn);
2051 
2052  // signals from the qscintilla edit area
2053  connect (f->qsci_edit_area (), SIGNAL (status_update (bool, bool)),
2054  this, SLOT (edit_status_update (bool, bool)));
2055 
2056  connect (f->qsci_edit_area (), SIGNAL (show_doc_signal (const QString&)),
2057  main_win (), SLOT (handle_show_doc (const QString&)));
2058 
2059  connect (f->qsci_edit_area (), SIGNAL (create_context_menu_signal (QMenu *)),
2060  this, SLOT (create_context_menu (QMenu *)));
2061 
2062  connect (f->qsci_edit_area (),
2063  SIGNAL (execute_command_in_terminal_signal (const QString&)),
2064  main_win (), SLOT (execute_command_in_terminal (const QString&)));
2065 
2066  // Signals from the file editor_tab
2067  connect (f, SIGNAL (file_name_changed (const QString&, const QString&)),
2068  this, SLOT (handle_file_name_changed (const QString&,
2069  const QString&)));
2070 
2071  connect (f, SIGNAL (editor_state_changed (bool, bool)),
2072  this, SLOT (handle_editor_state_changed (bool, bool)));
2073 
2074  connect (f, SIGNAL (tab_remove_request ()),
2075  this, SLOT (handle_tab_remove_request ()));
2076 
2077  connect (f, SIGNAL (add_filename_to_list (const QString&,
2078  const QString&, QWidget*)),
2079  this, SLOT (handle_add_filename_to_list (const QString&,
2080  const QString&,
2081  QWidget*)));
2082 
2083  connect (f, SIGNAL (editor_check_conflict_save (const QString&, bool)),
2084  this, SLOT (check_conflict_save (const QString&, bool)));
2085 
2086  connect (f, SIGNAL (mru_add_file (const QString&, const QString&)),
2087  this, SLOT (handle_mru_add_file (const QString&, const QString&)));
2088 
2089  connect (f, SIGNAL (run_file_signal (const QFileInfo&)),
2090  main_win (), SLOT (run_file_in_terminal (const QFileInfo&)));
2091 
2092  connect (f, SIGNAL (request_open_file (const QString&)),
2093  this, SLOT (request_open_file (const QString&)));
2094 
2095  connect (f, SIGNAL (edit_mfile_request (const QString&, const QString&,
2096  const QString&, int)),
2097  main_win (), SLOT (handle_edit_mfile_request (const QString&,
2098  const QString&,
2099  const QString&, int)));
2100 
2101  connect (f, SIGNAL (set_focus_editor_signal (QWidget*)),
2102  this, SLOT (set_focus (QWidget*)));
2103 
2104  // Signals from the file_editor non-trivial operations
2105  connect (this, SIGNAL (fetab_settings_changed (const QSettings *)),
2106  f, SLOT (notice_settings (const QSettings *)));
2107 
2108  connect (this, SIGNAL (fetab_change_request (const QWidget*)),
2109  f, SLOT (change_editor_state (const QWidget*)));
2110 
2111  connect (this, SIGNAL (fetab_file_name_query (const QWidget*)),
2112  f, SLOT (file_name_query (const QWidget*)));
2113 
2114  connect (this, SIGNAL (fetab_save_file (const QWidget*, const QString&,
2115  bool)),
2116  f, SLOT (save_file (const QWidget*, const QString&, bool)));
2117 
2118  connect (this, SIGNAL (fetab_check_modified_file (void)),
2119  f, SLOT (check_modified_file (void)));
2120 
2121  connect (f, SIGNAL (execute_command_in_terminal_signal (const QString&)),
2122  main_win (), SLOT (execute_command_in_terminal (const QString&)));
2123 
2124  // Signals from the file_editor trivial operations
2125  connect (this, SIGNAL (fetab_recover_from_exit (void)),
2126  f, SLOT (recover_from_exit (void)));
2127 
2128  connect (this, SIGNAL (fetab_set_directory (const QString&)),
2129  f, SLOT (set_current_directory (const QString&)));
2130 
2131  connect (this, SIGNAL (fetab_zoom_in (const QWidget*)),
2132  f, SLOT (zoom_in (const QWidget*)));
2133  connect (this, SIGNAL (fetab_zoom_out (const QWidget*)),
2134  f, SLOT (zoom_out (const QWidget*)));
2135  connect (this, SIGNAL (fetab_zoom_normal (const QWidget*)),
2136  f, SLOT (zoom_normal (const QWidget*)));
2137 
2138  connect (this, SIGNAL (fetab_context_help (const QWidget*, bool)),
2139  f, SLOT (context_help (const QWidget*, bool)));
2140 
2141  connect (this, SIGNAL (fetab_context_edit (const QWidget*)),
2142  f, SLOT (context_edit (const QWidget*)));
2143 
2144  connect (this, SIGNAL (fetab_save_file (const QWidget*)),
2145  f, SLOT (save_file (const QWidget*)));
2146 
2147  connect (this, SIGNAL (fetab_save_file_as (const QWidget*)),
2148  f, SLOT (save_file_as (const QWidget*)));
2149 
2150  connect (this, SIGNAL (fetab_print_file (const QWidget*)),
2151  f, SLOT (print_file (const QWidget*)));
2152 
2153  connect (this, SIGNAL (fetab_run_file (const QWidget*)),
2154  f, SLOT (run_file (const QWidget*)));
2155 
2156  connect (this, SIGNAL (fetab_context_run (const QWidget*)),
2157  f, SLOT (context_run (const QWidget*)));
2158 
2159  connect (this, SIGNAL (fetab_toggle_bookmark (const QWidget*)),
2160  f, SLOT (toggle_bookmark (const QWidget*)));
2161 
2162  connect (this, SIGNAL (fetab_next_bookmark (const QWidget*)),
2163  f, SLOT (next_bookmark (const QWidget*)));
2164 
2165  connect (this, SIGNAL (fetab_previous_bookmark (const QWidget*)),
2166  f, SLOT (previous_bookmark (const QWidget*)));
2167 
2168  connect (this, SIGNAL (fetab_remove_bookmark (const QWidget*)),
2169  f, SLOT (remove_bookmark (const QWidget*)));
2170 
2171  connect (this, SIGNAL (fetab_toggle_breakpoint (const QWidget*)),
2172  f, SLOT (toggle_breakpoint (const QWidget*)));
2173 
2174  connect (this, SIGNAL (fetab_next_breakpoint (const QWidget*)),
2175  f, SLOT (next_breakpoint (const QWidget*)));
2176 
2177  connect (this, SIGNAL (fetab_previous_breakpoint (const QWidget*)),
2178  f, SLOT (previous_breakpoint (const QWidget*)));
2179 
2180  connect (this, SIGNAL (fetab_remove_all_breakpoints (const QWidget*)),
2181  f, SLOT (remove_all_breakpoints (const QWidget*)));
2182 
2183  connect (this, SIGNAL (fetab_scintilla_command (const QWidget *,
2184  unsigned int)),
2185  f, SLOT (scintilla_command (const QWidget *, unsigned int)));
2186 
2187  connect (this, SIGNAL (fetab_comment_selected_text (const QWidget*, bool)),
2188  f, SLOT (comment_selected_text (const QWidget*, bool)));
2189 
2190  connect (this, SIGNAL (fetab_uncomment_selected_text (const QWidget*)),
2191  f, SLOT (uncomment_selected_text (const QWidget*)));
2192 
2193  connect (this, SIGNAL (fetab_indent_selected_text (const QWidget*)),
2194  f, SLOT (indent_selected_text (const QWidget*)));
2195 
2196  connect (this, SIGNAL (fetab_unindent_selected_text (const QWidget*)),
2197  f, SLOT (unindent_selected_text (const QWidget*)));
2198 
2199  connect (this, SIGNAL (fetab_smart_indent_line_or_selected_text (const QWidget*)),
2200  f, SLOT (smart_indent_line_or_selected_text (const QWidget*)));
2201 
2202  connect (this,
2203  SIGNAL (fetab_convert_eol (const QWidget*, QsciScintilla::EolMode)),
2204  f, SLOT (convert_eol (const QWidget*, QsciScintilla::EolMode)));
2205 
2206  connect (this, SIGNAL (fetab_find (const QWidget*, QList<QAction *>)),
2207  f, SLOT (find (const QWidget*, QList<QAction *>)));
2208 
2209  connect (this, SIGNAL (fetab_find_next (const QWidget*)),
2210  f, SLOT (find_next (const QWidget*)));
2211 
2212  connect (this, SIGNAL (fetab_find_previous (const QWidget*)),
2213  f, SLOT (find_previous (const QWidget*)));
2214 
2215  connect (this, SIGNAL (fetab_goto_line (const QWidget*, int)),
2216  f, SLOT (goto_line (const QWidget*, int)));
2217 
2218  connect (this, SIGNAL (fetab_move_match_brace (const QWidget*, bool)),
2219  f, SLOT (move_match_brace (const QWidget*, bool)));
2220 
2221  connect (this, SIGNAL (fetab_completion (const QWidget*)),
2222  f, SLOT (show_auto_completion (const QWidget*)));
2223 
2224  connect (this, SIGNAL (fetab_set_focus (const QWidget*)),
2225  f, SLOT (set_focus (const QWidget*)));
2226 
2227  connect (this, SIGNAL (fetab_insert_debugger_pointer (const QWidget*, int)),
2228  f, SLOT (insert_debugger_pointer (const QWidget*, int)));
2229 
2230  connect (this, SIGNAL (fetab_delete_debugger_pointer (const QWidget*, int)),
2231  f, SLOT (delete_debugger_pointer (const QWidget*, int)));
2232 
2233  connect (this, SIGNAL (fetab_do_breakpoint_marker (bool, const QWidget*,
2234  int, const QString&)),
2235  f, SLOT (do_breakpoint_marker (bool, const QWidget*, int,
2236  const QString&)));
2237 
2238  m_tab_widget->setCurrentWidget (f);
2239 
2240  check_actions ();
2241  }
2242 
2244  {
2245  int num_files = qMin (m_mru_files.size (), int (MaxMRUFiles));
2246 
2247  // configure and show active actions of mru-menu
2248  for (int i = 0; i < num_files; ++i)
2249  {
2250  QString text = QString ("&%1 %2").
2251  arg ((i+1) % int (MaxMRUFiles)).arg (m_mru_files.at (i));
2252  m_mru_file_actions[i]->setText (text);
2253 
2254  QStringList action_data;
2255  action_data << m_mru_files.at (i) << m_mru_files_encodings.at (i);
2256  m_mru_file_actions[i]->setData (action_data);
2257 
2258  m_mru_file_actions[i]->setVisible (true);
2259  }
2260 
2261  // hide unused mru-menu entries
2262  for (int j = num_files; j < MaxMRUFiles; ++j)
2263  m_mru_file_actions[j]->setVisible (false);
2264 
2265  // delete entries in string-list beyond MaxMRUFiles
2266  while (m_mru_files.size () > MaxMRUFiles)
2267  {
2268  m_mru_files.removeLast ();
2269  m_mru_files_encodings.removeLast ();
2270  }
2271 
2272  // save actual mru-list in settings
2273  QSettings *settings = resource_manager::get_settings ();
2274 
2275  settings->setValue ("editor/mru_file_list", m_mru_files);
2276  settings->setValue ("editor/mru_file_encodings", m_mru_files_encodings);
2277  settings->sync ();
2278  }
2279 
2280  bool file_editor::call_custom_editor (const QString& file_name, int line)
2281  {
2282  // Check if the user wants to use a custom file editor.
2283  QSettings *settings = resource_manager::get_settings ();
2284 
2285  if (settings->value ("useCustomFileEditor",false).toBool ())
2286  {
2287  // use the external editor interface for handling the call
2288  emit request_open_file_external (file_name, line);
2289 
2290  if (line < 0 && ! file_name.isEmpty ())
2291  handle_mru_add_file (QFileInfo (file_name).canonicalFilePath (),
2292  QString ());
2293 
2294  return true;
2295  }
2296 
2297  return false;
2298  }
2299 
2300  void file_editor::toggle_preference (const QString& preference, bool def)
2301  {
2302  QSettings *settings = resource_manager::get_settings ();
2303  bool old = settings->value (preference,def).toBool ();
2304  settings->setValue (preference,! old);
2305  notice_settings (settings);
2306  }
2307 
2308  // Function for closing the files in a removed directory
2309  void file_editor::handle_dir_remove (const QString& old_name,
2310  const QString& new_name)
2311  {
2312  QDir old_dir (old_name);
2313 
2314  // Have all file editor tabs signal what their filenames are.
2315  m_editor_tab_map.clear ();
2316  emit fetab_file_name_query (nullptr);
2317 
2318  // Loop over all open files and pick those within old_dir
2320  p != m_editor_tab_map.end (); p++)
2321  {
2322  QString rel_path_to_file = old_dir.relativeFilePath (p->first);
2323  if (rel_path_to_file.left (3) != QString ("../"))
2324  {
2325  // We directly go down from old_dir to reach our file: Our
2326  // file is included in the removed/renamed diectory.
2327  // Thus delete it.
2328  m_no_focus = true; // Remember for not focussing editor
2329  file_editor_tab *editor_tab
2330  = static_cast<file_editor_tab *> (p->second.fet_ID);
2331  editor_tab->file_has_changed (QString (), true); // Close
2332  m_no_focus = false; // Back to normal
2333 
2334  // Store file for possible later reload
2335  m_tmp_closed_files << p->first;
2336 
2337  // Add the new file path and the encoding for later reloading
2338  // if new_name is given
2339  if (! new_name.isEmpty ())
2340  {
2341  QDir new_dir (new_name);
2342  m_tmp_closed_files << new_dir.absoluteFilePath (rel_path_to_file);
2343  }
2344  else
2345  m_tmp_closed_files << ""; // no new name, just removing this file
2346 
2347  m_tmp_closed_files << p->second.encoding; // store the encoding
2348  }
2349  }
2350  }
2351 
2353  {
2354  QWidget *foc_w = focusWidget ();
2355  if (foc_w && foc_w->inherits ("octave::octave_qscintilla"))
2356  return true;
2357  return false;
2358  }
2359 
2360  // Check whether this file is already open in the editor.
2362  {
2363  // Have all file editor tabs signal what their filenames are.
2364  m_editor_tab_map.clear ();
2365  emit fetab_file_name_query (nullptr);
2366 
2367  // Check all tabs for the given file name
2368  QWidget *retval = nullptr;
2369 
2371  p != m_editor_tab_map.end (); p++)
2372  {
2373  QString tab_file = p->first;
2374  if (same_file (file.toStdString (), tab_file.toStdString ())
2375  || file == tab_file) // needed as same_file ("","") is false.
2376  {
2377  retval = p->second.fet_ID;
2378  break;
2379  }
2380  }
2381 
2382  return retval;
2383  }
2384 
2385  QAction * file_editor::add_action (QMenu *menu, const QString& text,
2386  const char *member,
2387  QWidget *receiver)
2388  {
2389  return add_action (menu, QIcon (), text, member, receiver);
2390  }
2391 
2392  QAction * file_editor::add_action (QMenu *menu, const QIcon& icon,
2393  const QString& text, const char *member,
2394  QWidget *receiver)
2395  {
2396  QAction *a;
2397  QWidget *r = this;
2398 
2399  if (receiver != nullptr)
2400  r = receiver;
2401 
2402  if (menu)
2403  a = menu->addAction (icon, text, r, member);
2404  else
2405  {
2406  a = new QAction (this);
2407  connect (a, SIGNAL (triggered ()), r, member);
2408  }
2409 
2410  addAction (a); // important for shortcut context
2411  a->setShortcutContext (Qt::WidgetWithChildrenShortcut);
2412 
2413  return a;
2414  }
2415 
2417  {
2418  QMenu *menu = p->addMenu (name);
2419 
2420  QString base_name = name; // get a copy
2421  // replace intended '&' ("&&") by a temp. string
2422  base_name.replace ("&&", "___octave_amp_replacement___");
2423  // remove single '&' (shortcut)
2424  base_name.remove ("&");
2425  // restore intended '&'
2426  base_name.replace ("___octave_amp_replacement___", "&&");
2427 
2428  // remember names with and without shortcut
2429  m_hash_menu_text[menu] = QStringList () << name << base_name;
2430 
2431  return menu;
2432  }
2433 }
2434 
2435 #endif
bool check_closing(void)
Definition: file-editor.cc:341
void fetab_zoom_normal(const QWidget *ID)
QAction * m_cut_line_action
Definition: file-editor.h:384
QString load_file(const QString &fileName)
QAction * m_switch_right_tab_action
Definition: file-editor.h:421
void update_octave_directory(const QString &dir)
QAction * m_styles_preferences_action
Definition: file-editor.h:418
QAction * m_run_selection_action
Definition: file-editor.h:404
void fetab_context_edit(const QWidget *ID)
QAction * m_mru_file_actions[MaxMRUFiles]
Definition: file-editor.h:448
bool is_editor_console_tabbed(void)
void request_context_edit(bool)
Definition: file-editor.cc:504
void handle_insert_debugger_pointer_request(const QString &file, int line)
Definition: file-editor.cc:877
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
file_editor_tab_widget * m_tab_widget
Definition: file-editor.h:439
void zoom_normal(bool)
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:130
void notice_settings(const QSettings *settings)
Definition: file-editor.cc:977
QAction * m_uncomment_selection_action
Definition: file-editor.h:351
QAction * m_show_longline_action
Definition: file-editor.h:370
void fetab_smart_indent_line_or_selected_text(const QWidget *ID)
void request_delete_start_word(bool)
Definition: file-editor.cc:581
fname
Definition: load-save.cc:767
QAction * m_edit_function_action
Definition: file-editor.h:406
void request_delete_end_line(bool)
Definition: file-editor.cc:599
void edit_status_update(bool, bool)
void copyClipboard(void)
QMenu * add_menu(QMenuBar *p, QString text)
void request_goto_line(bool)
Definition: file-editor.cc:711
void request_toggle_bookmark(bool)
Definition: file-editor.cc:529
void fetab_zoom_out(const QWidget *ID)
QAction * m_lower_case_action
Definition: file-editor.h:348
void request_remove_breakpoint(bool)
Definition: file-editor.cc:575
void fetab_indent_selected_text(const QWidget *ID)
void request_sel_match_brace(bool)
Definition: file-editor.cc:554
void fetab_set_focus(const QWidget *ID)
void fetab_unindent_selected_text(const QWidget *ID)
void show_eol_chars(bool)
QAction * m_zoom_normal_action
Definition: file-editor.h:376
void request_mru_open_file(QAction *action)
Definition: file-editor.cc:468
void fetab_toggle_bookmark(const QWidget *ID)
QToolBar * m_tool_bar
Definition: file-editor.h:340
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
QAction * m_smart_indent_line_or_selection_action
Definition: file-editor.h:354
QAction * m_conv_eol_mac_action
Definition: file-editor.h:357
void fetab_check_modified_file(void)
QAction * m_conv_eol_windows_action
Definition: file-editor.h:355
void request_remove_bookmark(bool)
Definition: file-editor.cc:544
void request_redo(bool)
Definition: file-editor.cc:482
void request_context_run(bool)
Definition: file-editor.cc:524
void create_context_menu(QMenu *)
void request_upper_case(bool)
Definition: file-editor.cc:651
void closeEvent(QCloseEvent *event)
void check_actions(void)
Definition: file-editor.cc:160
file_editor(QWidget *p)
Definition: file-editor.cc:80
void file_has_changed(const QString &path, bool do_close=false)
QStringList m_tmp_closed_files
Definition: file-editor.h:456
void fetab_remove_bookmark(const QWidget *ID)
QAction * m_comment_var_selection_action
Definition: file-editor.h:350
void request_indent_selected_text(bool)
Definition: file-editor.cc:663
void show_toolbar(bool)
QAction * m_show_whitespace_action
Definition: file-editor.h:367
void execute_command_in_terminal_signal(const QString &)
QStringList m_mru_files
Definition: file-editor.h:449
void request_duplicate_selection(bool)
Definition: file-editor.cc:623
QAction * m_delete_start_line_action
Definition: file-editor.h:380
void request_lower_case(bool)
Definition: file-editor.cc:657
void fetab_file_name_query(const QWidget *ID)
QAction * m_print_action
Definition: file-editor.h:402
void dragEnterEvent(QDragEnterEvent *event)
QAction * m_indent_selection_action
Definition: file-editor.h:352
void handle_file_remove(const QString &, const QString &)
Definition: file-editor.cc:918
QAction * m_selectall_action
Definition: file-editor.h:362
void fetab_insert_debugger_pointer(const QWidget *ID, int line=-1)
QAction * m_find_action
Definition: file-editor.h:388
QHash< QMenu *, QStringList > m_hash_menu_text
Definition: file-editor.h:335
static bool was_cancelled(void)
QAction * m_unindent_selection_action
Definition: file-editor.h:353
QAction * m_move_to_matching_brace
Definition: file-editor.h:395
void request_save_file(bool)
Definition: file-editor.cc:509
void fetab_toggle_breakpoint(const QWidget *ID)
QAction * m_comment_selection_action
Definition: file-editor.h:349
void fetab_find(const QWidget *ID, QList< QAction *>)
void request_conv_eol_mac(bool)
Definition: file-editor.cc:690
void request_close_all_files(bool)
Definition: file-editor.cc:438
void show_long_line(bool)
std::map< QString, tab_info >::const_iterator editor_tab_map_const_iterator
Definition: file-editor.h:75
void fetab_print_file(const QWidget *ID)
bool call_custom_editor(const QString &file_name=QString(), int line=-1)
void update_window_title(bool modified)
QAction * m_move_tab_right_action
Definition: file-editor.h:423
void fetab_zoom_in(const QWidget *ID)
void request_previous_bookmark(bool)
Definition: file-editor.cc:539
void request_copy_line(bool)
Definition: file-editor.cc:611
QAction * m_show_linenum_action
Definition: file-editor.h:366
i e
Definition: data.cc:2591
void request_smart_indent_line_or_selected_text(void)
Definition: file-editor.cc:673
void handle_mru_add_file(const QString &file_name, const QString &encoding)
Definition: file-editor.cc:801
octave_value arg
Definition: pr-output.cc:3244
void fetab_remove_all_breakpoints(const QWidget *ID)
QMenuBar * m_menu_bar
Definition: file-editor.h:339
void request_comment_var_selected_text(bool)
Definition: file-editor.cc:645
QAction * m_find_next_action
Definition: file-editor.h:389
QAction * m_delete_end_line_action
Definition: file-editor.h:381
QAction * m_show_indguide_action
Definition: file-editor.h:369
QAction * m_previous_breakpoint_action
Definition: file-editor.h:427
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
Definition: cellfun.cc:400
void request_delete_end_word(bool)
Definition: file-editor.cc:587
void handle_delete_debugger_pointer_request(const QString &file, int line)
Definition: file-editor.cc:883
QAction * m_copy_line_action
Definition: file-editor.h:383
void fetab_previous_breakpoint(const QWidget *ID)
QAction * m_remove_all_breakpoints_action
Definition: file-editor.h:428
QAction * m_switch_left_tab_action
Definition: file-editor.h:420
void handle_add_filename_to_list(const QString &fileName, const QString &encoding, QWidget *ID)
Definition: file-editor.cc:769
nd deftypefn *std::string name
Definition: sysdep.cc:647
QAction * m_zoom_in_action
Definition: file-editor.h:374
QAction * add_action(QMenu *menu, const QString &text, const char *member, QWidget *receiver=nullptr)
void show_indent_guides(bool)
void fetab_recover_from_exit(void)
QAction * m_next_breakpoint_action
Definition: file-editor.h:426
void request_settings_dialog(const QString &)
void fetab_set_directory(const QString &dir)
QAction * m_delete_line_action
Definition: file-editor.h:382
static void set_shortcut(QAction *action, const QString &key)
QAction * m_show_hscrollbar_action
Definition: file-editor.h:373
QList< QAction * > m_fetab_actions
Definition: file-editor.h:437
void fetab_previous_bookmark(const QWidget *ID)
void active_tab_changed(int index)
Definition: file-editor.cc:778
QAction * m_zoom_out_action
Definition: file-editor.h:375
void request_completion(bool)
Definition: file-editor.cc:716
QAction * m_move_tab_left_action
Definition: file-editor.h:422
std::complex< double > w(std::complex< double > z, double relerr=0)
void set_shortcuts(void)
void dropEvent(QDropEvent *event)
void request_move_match_brace(bool)
Definition: file-editor.cc:549
void fetab_move_match_brace(const QWidget *ID, bool select)
tab_bar * get_tab_bar(void) const
Definition: file-editor.cc:72
void handle_visibility(bool visible)
void request_unindent_selected_text(bool)
Definition: file-editor.cc:668
static void reset_cancel(void)
QAction * m_redo_action
Definition: file-editor.h:414
octave_qscintilla * qsci_edit_area(void)
octave_value arg(void) const
Definition: ov.h:1411
void request_cut(bool)
Definition: file-editor.cc:488
QMainWindow * main_win(void)
void request_find(bool)
Definition: file-editor.cc:696
void request_next_breakpoint(bool)
Definition: file-editor.cc:565
octave_value retval
Definition: data.cc:6246
void fetab_find_previous(const QWidget *ID)
void handle_file_name_changed(const QString &fileName, const QString &toolTip)
Definition: file-editor.cc:721
void show_white_space(bool)
void fetab_completion(const QWidget *)
void handle_enter_debug_mode(void)
Definition: file-editor.cc:148
void request_uncomment_selected_text(bool)
Definition: file-editor.cc:640
void request_context_help(bool)
Definition: file-editor.cc:494
void fetab_run_file(const QWidget *ID)
void handle_tab_remove_request(void)
Definition: file-editor.cc:746
QAction * m_find_previous_action
Definition: file-editor.h:390
QAction * m_delete_end_word_action
Definition: file-editor.h:379
QAction * m_delete_start_word_action
Definition: file-editor.h:378
void request_close_file(bool)
Definition: file-editor.cc:431
void enable_menu_shortcuts(bool)
Definition: file-editor.cc:322
QMenu * get_context_menu(void)
Definition: tab-bar.h:47
void request_find_previous(bool)
Definition: file-editor.cc:706
void show_statusbar(bool)
QAction * m_show_statusbar_action
Definition: file-editor.h:372
void fetab_settings_changed(const QSettings *settings)
void show_hscrollbar(bool)
QAction * m_remove_bookmark_action
Definition: file-editor.h:400
QAction * m_sel_to_matching_brace
Definition: file-editor.h:396
QAction * m_run_action
Definition: file-editor.h:403
QAction * m_close_others_action
Definition: file-editor.h:412
void request_styles_preferences(bool)
void set_title(const QString &)
void restore_session(QSettings *settings)
Definition: file-editor.cc:251
Represents the main window.
Definition: main-window.h:96
With real return the complex result
Definition: data.cc:3260
QStringList m_mru_files_encodings
Definition: file-editor.h:450
QAction * m_show_toolbar_action
Definition: file-editor.h:371
void request_delete_start_line(bool)
Definition: file-editor.cc:593
std::string url
Definition: urlwrite.cc:118
QAction * m_preferences_action
Definition: file-editor.h:417
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
Definition: colamd.cc:103
void request_next_bookmark(bool)
Definition: file-editor.cc:534
void set_focus(QWidget *fet)
Definition: file-editor.cc:311
void request_preferences(bool)
void file_loaded_signal(void)
static QIcon icon(const QString &icon_name, bool fallback=true)
void fetab_context_help(const QWidget *ID, bool)
void fetab_do_breakpoint_marker(bool insert, const QWidget *ID, int line=-1, const QString &="")
QAction * m_show_eol_action
Definition: file-editor.h:368
QAction * m_duplicate_selection_action
Definition: file-editor.h:385
void request_new_file(const QString &commands)
Definition: file-editor.cc:411
void handle_editor_state_changed(bool enableCopy, bool is_octave_file)
Definition: file-editor.cc:784
void toggle_preference(const QString &preference, bool def)
void fetab_next_breakpoint(const QWidget *ID)
void fetab_scintilla_command(const QWidget *ID, unsigned int sci_msg)
void request_run_file(bool)
Definition: file-editor.cc:519
void handle_dir_remove(const QString &old_name, const QString &new_name)
QAction * m_conv_eol_unix_action
Definition: file-editor.h:356
QAction * m_transpose_line_action
Definition: file-editor.h:386
void request_open_file_external(const QString &file_name, int line)
void handle_exit_debug_mode(void)
Definition: file-editor.cc:154
QAction * m_completion_action
Definition: file-editor.h:393
std::map< QString, tab_info > m_editor_tab_map
Definition: file-editor.h:334
void fetab_context_run(const QWidget *ID)
void request_close_other_files(bool)
Definition: file-editor.cc:450
void request_transpose_line(bool)
Definition: file-editor.cc:629
p
Definition: lu.cc:138
QAction * m_save_as_action
Definition: file-editor.h:409
QAction * m_context_help_action
Definition: file-editor.h:363
void request_comment_selected_text(bool)
Definition: file-editor.cc:635
void show_line_numbers(bool)
void fetab_save_file(const QWidget *ID, const QString &fileName, bool remove_on_success)
QAction * m_copy_action
Definition: file-editor.h:359
void request_delete_line(bool)
Definition: file-editor.cc:605
void check_conflict_save(const QString &fileName, bool remove_on_success)
Definition: file-editor.cc:817
void handle_file_renamed(bool load_new=true)
Definition: file-editor.cc:965
void fetab_comment_selected_text(const QWidget *ID, bool)
QAction * m_paste_action
Definition: file-editor.h:361
void add_file_editor_tab(file_editor_tab *f, const QString &fn)
static QSettings * get_settings(void)
void fetab_convert_eol(const QWidget *ID, QsciScintilla::EolMode eol_mode)
void request_toggle_breakpoint(bool)
Definition: file-editor.cc:560
void fetab_save_file_as(const QWidget *ID)
void fetab_delete_debugger_pointer(const QWidget *ID, int line=-1)
void handle_update_breakpoint_marker_request(bool insert, const QString &file, int line, const QString &cond)
Definition: file-editor.cc:903
for i
Definition: data.cc:5264
void set_encoding(const QString &new_encoding)
QAction * m_next_bookmark_action
Definition: file-editor.h:397
void request_find_next(bool)
Definition: file-editor.cc:701
QAction * m_cut_action
Definition: file-editor.h:360
QAction * m_close_action
Definition: file-editor.h:410
QAction * m_toggle_bookmark_action
Definition: file-editor.h:399
void request_previous_breakpoint(bool)
Definition: file-editor.cc:570
void fetab_next_bookmark(const QWidget *ID)
void handle_edit_file_request(const QString &file)
Definition: file-editor.cc:911
QAction * m_save_action
Definition: file-editor.h:408
void request_context_doc(bool)
Definition: file-editor.cc:499
void request_cut_line(bool)
Definition: file-editor.cc:617
void new_file(const QString &commands=QString())
bool editor_tab_has_focus(void)
void handle_tab_close_request(int index)
Definition: file-editor.cc:738
void request_conv_eol_windows(bool)
Definition: file-editor.cc:678
QAction * m_context_doc_action
Definition: file-editor.h:364
void fetab_change_request(const QWidget *ID)
QAction * m_undo_action
Definition: file-editor.h:415
void mru_menu_update(void)
QAction * m_upper_case_action
Definition: file-editor.h:347
void request_open_file(const QString &fileName, const QString &encoding=QString(), int line=-1, bool debug_pointer=false, bool breakpoint_marker=false, bool insert=true, const QString &cond="")
QAction * m_find_files_action
Definition: file-editor.h:391
QAction * m_goto_line_action
Definition: file-editor.h:392
QAction * m_previous_bookmark_action
Definition: file-editor.h:398
void pasteClipboard(void)
void request_save_file_as(bool)
Definition: file-editor.cc:514
void empty_script(bool startup, bool visible)
Definition: file-editor.cc:201
QWidget * find_tab_widget(const QString &openFileName)
QMenu * m_view_editor_menu
Definition: file-editor.h:435
QAction * m_popdown_mru_action
Definition: file-editor.h:407
void fetab_find_next(const QWidget *ID)
void request_print_file(bool)
Definition: file-editor.cc:477
QAction * m_close_all_action
Definition: file-editor.h:411
void fetab_goto_line(const QWidget *ID, int line=-1)
void fetab_uncomment_selected_text(const QWidget *ID)
void insert_global_actions(QList< QAction *>)
Definition: file-editor.cc:113
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
Definition: oct-hist.cc:587
QAction * m_toggle_breakpoint_action
Definition: file-editor.h:425
void request_conv_eol_unix(bool)
Definition: file-editor.cc:684