annotate gui/src/m-editor/file-editor-tab.cc @ 15080:4c4f2fb07a50 gui

Added find functionality in editor by to.lil. * find.png: Added find icon. * find-dialog.cc: Added find dialog. * find-dialog.h: Added find dialog. * file-editor-tab.cc: Integrated find dialog. * file-editor-tab.h: Added new method for find. * file-editor.cc: Added new actions, menus and toolbuttons. * file-editor.h: Added new method/slot for find.
author Jacob Dawid <jacob.dawid@gmail.com>
date Thu, 02 Aug 2012 11:08:45 +0200
parents 1ffaad442161
children bc801a44bb1f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1 /* OctaveGUI - A graphical user interface for Octave
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
2 * Copyright (C) 2011 Jacob Dawid (jacob.dawid@googlemail.com)
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
3 *
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
4 * This program is free software: you can redistribute it and/or modify
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
6 * published by the Free Software Foundation, either version 3 of the
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
7 * License, or (at your option) any later version.
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
8 *
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
12 * GNU General Public License for more details.
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
13 *
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
16 */
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
17
14707
674740c44c09 Changed various files to matche file naming conventions.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14703
diff changeset
18 #include "file-editor-tab.h"
674740c44c09 Changed various files to matche file naming conventions.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14703
diff changeset
19 #include "file-editor.h"
15080
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
20 #include "find-dialog.h"
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
21 #include "octave-link.h"
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
22
14873
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
23
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
24 #include <Qsci/qsciapis.h>
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
25 // Not available in the Debian repos yet!
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
26 // #include <Qsci/qscilexeroctave.h>
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
27 #include "lexer-octave-gui.h"
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
28 #include <Qsci/qscilexercpp.h>
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
29 #include <Qsci/qscilexerbash.h>
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
30 #include <Qsci/qscilexerperl.h>
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
31 #include <Qsci/qscilexerbatch.h>
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
32 #include <Qsci/qscilexerdiff.h>
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
33 #include "resource-manager.h"
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
34 #include <QMessageBox>
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
35 #include <QVBoxLayout>
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
36
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
37 file_editor_tab::file_editor_tab(file_editor *fileEditor)
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
38 : QWidget ((QWidget*)fileEditor), octave_event_observer ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
39 {
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
40 QSettings *settings = resource_manager::instance ()->get_settings ();
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
41 _file_editor = fileEditor;
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
42 _file_name = "";
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
43 _edit_area = new QsciScintilla (this);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
44
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
45 // symbols
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
46 _edit_area->setMarginType (1, QsciScintilla::SymbolMargin);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
47 _edit_area->setMarginSensitivity (1, true);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
48 _edit_area->markerDefine (QsciScintilla::RightTriangle, bookmark);
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
49 _edit_area->markerDefine (QPixmap (":/actions/icons/redled.png"),
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
50 breakpoint);
14826
ed0f820c7ce0 Changed QImage to QPixmap to allow compilation with QScintilla2 < 2.6.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14825
diff changeset
51 _edit_area->markerDefine (QPixmap (":/actions/icons/arrow_right.png"),
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
52 debugger_position);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
53
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
54 connect (_edit_area, SIGNAL (marginClicked (int, int,
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
55 Qt::KeyboardModifiers)),
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
56 this, SLOT (handle_margin_clicked (int, int,
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
57 Qt::KeyboardModifiers)));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
58
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
59 // line numbers
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
60 _edit_area->setMarginsForegroundColor(QColor(96,96,96));
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
61 _edit_area->setMarginsBackgroundColor(QColor(232,232,220));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
62 if (settings->value ("editor/showLineNumbers",true).toBool ())
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
63 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
64 QFont marginFont( settings->value ("editor/fontName","Courier").toString () ,
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
65 settings->value ("editor/fontSize",10).toInt () );
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
66 _edit_area->setMarginsFont( marginFont );
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
67 QFontMetrics metrics(marginFont);
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
68 _edit_area->setMarginType (2, QsciScintilla::TextMargin);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
69 _edit_area->setMarginWidth(2, metrics.width("9999"));
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
70 _edit_area->setMarginLineNumbers (2, true);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
71 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
72
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
73 // code folding
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
74 _edit_area->setMarginType (3, QsciScintilla::SymbolMargin);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
75 _edit_area->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
76
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
77 // other features
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
78 if (settings->value ("editor/highlightCurrentLine",true).toBool ())
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
79 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
80 _edit_area->setCaretLineVisible(true);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
81 _edit_area->setCaretLineBackgroundColor(QColor(245,245,245));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
82 }
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
83 _edit_area->setBraceMatching (QsciScintilla::StrictBraceMatch);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
84 _edit_area->setAutoIndent (true);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
85 _edit_area->setIndentationWidth (2);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
86 _edit_area->setIndentationsUseTabs (false);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
87 if (settings->value ("editor/codeCompletion",true).toBool ())
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
88 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
89 _edit_area->autoCompleteFromAll ();
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
90 _edit_area->setAutoCompletionSource(QsciScintilla::AcsAll);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
91 _edit_area->setAutoCompletionThreshold (1);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
92 }
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
93 _edit_area->setUtf8 (true);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
94
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
95 QVBoxLayout *layout = new QVBoxLayout ();
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
96 layout->addWidget (_edit_area);
14680
628eeaf879f7 Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14676
diff changeset
97 layout->setMargin (0);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
98 setLayout (layout);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
99
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
100 // connect modified signal
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
101 connect (_edit_area, SIGNAL (modificationChanged (bool)),
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
102 this, SLOT (update_window_title (bool)));
14715
b4db843b1f26 Done some extra method renaming to fit the overall octave coding style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14712
diff changeset
103 connect (_edit_area, SIGNAL (copyAvailable (bool)),
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
104 this, SLOT (handle_copy_available (bool)));
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
105 connect (&_file_system_watcher, SIGNAL (fileChanged (QString)),
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
106 this, SLOT (file_has_changed (QString)));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
107
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
108 _file_name = "";
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
109 update_window_title (false);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
110 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
111
14680
628eeaf879f7 Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14676
diff changeset
112 bool
14712
5cb54cca8a06 Completion of code reformatting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14709
diff changeset
113 file_editor_tab::copy_available ()
14680
628eeaf879f7 Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14676
diff changeset
114 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
115 return _copy_available;
14680
628eeaf879f7 Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14676
diff changeset
116 }
628eeaf879f7 Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14676
diff changeset
117
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
118 void
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
119 file_editor_tab::event_accepted (octave_event *e)
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
120 {
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
121 if (dynamic_cast<octave_run_file_event*> (e))
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
122 {
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
123 // File was run successfully.
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
124 }
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
125
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
126 if (octave_add_breakpoint_event *abe
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
127 = dynamic_cast<octave_add_breakpoint_event*> (e))
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
128 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
129 // TODO: Check file.
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
130 _edit_area->markerAdd (abe->get_line (), breakpoint);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
131 }
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
132
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
133 if (octave_remove_breakpoint_event *rbe
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
134 = dynamic_cast<octave_remove_breakpoint_event*> (e))
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
135 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
136 // TODO: Check file.
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
137 _edit_area->markerDelete (rbe->get_line (), breakpoint);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
138 }
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
139
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
140 if (octave_remove_all_breakpoints_event *rabe
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
141 = dynamic_cast<octave_remove_all_breakpoints_event*> (e))
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
142 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
143 Q_UNUSED (rabe);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
144 _edit_area->markerDeleteAll (breakpoint);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
145 }
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
146
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
147 delete e;
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
148 }
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
149
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
150 void
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
151 file_editor_tab::event_reject (octave_event *e)
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
152 {
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
153 if (dynamic_cast<octave_run_file_event*> (e))
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
154 {
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
155 // Running file failed.
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
156 }
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
157 delete e;
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
158 }
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
159
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
160 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
161 file_editor_tab::closeEvent (QCloseEvent *event)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
162 {
14795
e3ae0850b105 Fixed integrating debug menu in the editor window.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14788
diff changeset
163 if (_file_editor->get_main_window ()->is_closing ())
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
164 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
165 // close whole application: save file or not if modified
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
166 check_file_modified ("Closing Octave", 0); // no cancel possible
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
167 event->accept ();
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
168 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
169 else
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
170 {
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
171 // ignore close event if file is not saved and user cancels
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
172 // closing this window
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
173 if (check_file_modified ("Close File",
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
174 QMessageBox::Cancel) == QMessageBox::Cancel)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
175 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
176 event->ignore ();
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
177 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
178 else
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
179 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
180 event->accept();
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
181 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
182 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
183 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
184
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
185 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
186 file_editor_tab::set_file_name (QString fileName)
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
187 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
188 _file_name = fileName;
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
189 update_lexer ();
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
190 update_tracked_file ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
191 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
192
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
193 void
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
194 file_editor_tab::handle_margin_clicked(int margin, int line,
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
195 Qt::KeyboardModifiers state)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
196 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
197 Q_UNUSED (state);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
198 if (margin == 1)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
199 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
200 unsigned int mask = _edit_area->markersAtLine (line);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
201
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
202 if (state & Qt::ControlModifier)
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
203 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
204 if (mask && (1 << bookmark))
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
205 _edit_area->markerDelete(line,bookmark);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
206 else
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
207 _edit_area->markerAdd(line,bookmark);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
208 }
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
209 else
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
210 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
211 if (mask && (1 << breakpoint))
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
212 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
213 request_remove_breakpoint (line);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
214 }
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
215 else
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
216 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
217 request_add_breakpoint (line);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
218 }
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
219 }
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
220 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
221 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
222
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
223 void
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
224 file_editor_tab::update_lexer ()
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
225 {
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
226 QsciLexer *lexer = _edit_area->lexer ();
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
227 delete lexer;
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
228
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
229 if (_file_name.endsWith (".m") || _file_name.endsWith (".M"))
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
230 {
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
231 lexer = new lexer_octave_gui ();
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
232
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
233 // The API info that is used for auto completion
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
234 // TODO: Where to store a file with API info (raw or prepared?)?
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
235 // TODO: Also provide infos on octave-forge functions?
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
236 // TODO: Also provide infos on function parameters?
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
237 // By now, use the keywords-list from syntax highlighting
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
238
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
239 QsciAPIs *lexer_api = new QsciAPIs (lexer);
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
240
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
241 QString keyword;
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
242 QStringList keywordList;
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
243
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
244 // get whole string with all keywords
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
245 keyword = lexer->keywords (1);
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
246 // split into single strings
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
247 keywordList = keyword.split (QRegExp ("\\s+"));
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
248
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
249 int i;
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
250 for (i = 0; i < keywordList.size (); i++)
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
251 {
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
252 // add single strings to the API
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
253 lexer_api->add (keywordList.at (i));
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
254 }
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
255 // prepare API info ... this make take some time
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
256 lexer_api->prepare ();
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
257 }
14874
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
258 else if (_file_name.endsWith (".c")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
259 || _file_name.endsWith (".cc")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
260 || _file_name.endsWith (".cpp")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
261 || _file_name.endsWith (".cxx")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
262 || _file_name.endsWith (".c++")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
263 || _file_name.endsWith (".h")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
264 || _file_name.endsWith (".hh")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
265 || _file_name.endsWith (".hpp")
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
266 || _file_name.endsWith (".h++"))
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
267 {
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
268 lexer = new QsciLexerCPP ();
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
269 }
14873
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
270 else if (_file_name.endsWith (".pl"))
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
271 {
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
272 lexer = new QsciLexerPerl ();
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
273 }
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
274 else if (_file_name.endsWith (".bat"))
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
275 {
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
276 lexer = new QsciLexerBatch ();
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
277 }
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
278 else if (_file_name.endsWith (".diff"))
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
279 {
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
280 lexer = new QsciLexerDiff ();
355d6c165df0 Added syntax highlighting support for .sh/.bat/.pl and .diff-files.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14869
diff changeset
281 }
14874
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
282 else // Default to bash lexer.
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
283 {
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
284 lexer = new QsciLexerBash ();
5d74d8b982a5 Forgot to have a fallback lexer when the file suffix is unknown. Removed unused variable and added comments.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14873
diff changeset
285 }
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
286
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
287 QSettings *settings = resource_manager::instance ()->get_settings ();
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
288
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
289 // Editor font (default or from settings)
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
290 lexer->setDefaultFont (QFont (
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
291 settings->value ("editor/fontName",
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
292 "Courier").toString (),
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
293 settings->value ("editor/fontSize",
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
294 10).toInt ()));
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
295
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
296 // TODO: Autoindent not working as it should
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
297 lexer->setAutoIndentStyle (QsciScintilla::AiMaintain ||
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
298 QsciScintilla::AiOpening ||
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
299 QsciScintilla::AiClosing);
14869
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
300
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
301 _edit_area->setLexer (lexer);
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
302 }
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
303
db3c84d38345 Now supporting c/cc/cpp syntax highlighting.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14833
diff changeset
304 void
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
305 file_editor_tab::request_add_breakpoint (int line)
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
306 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
307 QFileInfo file_info (_file_name);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
308 QString path = file_info.absolutePath ();
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
309 QString function_name = file_info.fileName ();
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
310
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
311 // We have to cut off the suffix, because octave appends it.
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
312 function_name.chop (file_info.suffix ().length () + 1);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
313
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
314 octave_link::instance ()->post_event
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
315 (new octave_add_breakpoint_event (*this,
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
316 path.toStdString (),
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
317 function_name.toStdString (),
14833
422b0b2ce5f8 Second attempt to fix setting breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14832
diff changeset
318 line));
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
319 }
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
320
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
321 void
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
322 file_editor_tab::request_remove_breakpoint (int line)
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
323 {
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
324 QFileInfo file_info (_file_name);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
325 QString path = file_info.absolutePath ();
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
326 QString function_name = file_info.fileName ();
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
327
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
328 // We have to cut off the suffix, because octave appends it.
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
329 function_name.chop (file_info.suffix ().length () + 1);
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
330
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
331 octave_link::instance ()->post_event
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
332 (new octave_remove_breakpoint_event (*this,
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
333 path.toStdString (),
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
334 function_name.toStdString (),
14833
422b0b2ce5f8 Second attempt to fix setting breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14832
diff changeset
335 line));
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
336 }
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
337
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
338 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
339 file_editor_tab::comment_selected_text ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
340 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
341 do_comment_selected_text (true);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
342 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
343
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
344 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
345 file_editor_tab::uncomment_selected_text ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
346 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
347 do_comment_selected_text (false);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
348 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
349
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
350 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
351 file_editor_tab::do_comment_selected_text (bool comment)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
352 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
353 if ( _edit_area->hasSelectedText() )
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
354 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
355 int lineFrom, lineTo, colFrom, colTo, i;
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
356 _edit_area->getSelection (&lineFrom,&colFrom,&lineTo,&colTo);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
357 if ( colTo == 0 ) // the beginning of last line is not selected
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
358 lineTo--; // stop at line above
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
359 _edit_area->beginUndoAction ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
360 for ( i=lineFrom; i<=lineTo; i++ )
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
361 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
362 if ( comment )
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
363 _edit_area->insertAt("%",i,0);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
364 else
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
365 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
366 QString line(_edit_area->text(i));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
367 if ( line.startsWith("%") )
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
368 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
369 _edit_area->setSelection(i,0,i,1);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
370 _edit_area->removeSelectedText();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
371 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
372 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
373 }
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
374 _edit_area->endUndoAction ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
375 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
376 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
377
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
378 void
15080
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
379 file_editor_tab::find ()
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
380 {
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
381 find_dialog dialog (_edit_area);
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
382 dialog.exec ();
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
383 }
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
384
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
385 void
4c4f2fb07a50 Added find functionality in editor by to.lil.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 15045
diff changeset
386 file_editor_tab::update_window_title (bool modified)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
387 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
388 QString title(_file_name);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
389 if ( !_long_title )
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
390 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
391 QFileInfo file(_file_name);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
392 title = file.fileName();
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
393 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
394
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
395 if ( modified )
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
396 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
397 emit file_name_changed (title.prepend("* "));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
398 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
399 else
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
400 emit file_name_changed (title);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
401 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
402
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
403 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
404 file_editor_tab::handle_copy_available(bool enableCopy)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
405 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
406 _copy_available = enableCopy;
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
407 emit editor_state_changed ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
408 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
409
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
410 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
411 file_editor_tab::update_tracked_file ()
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
412 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
413 QStringList trackedFiles = _file_system_watcher.files ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
414 if (!trackedFiles.isEmpty ())
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
415 _file_system_watcher.removePaths (trackedFiles);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
416
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
417 if (_file_name != UNNAMED_FILE)
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
418 _file_system_watcher.addPath (_file_name);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
419 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
420
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
421 int
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
422 file_editor_tab::check_file_modified (QString msg, int cancelButton)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
423 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
424 int decision = QMessageBox::Yes;
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
425 if (_edit_area->isModified ())
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
426 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
427 // file is modified but not saved, aks user what to do
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
428 decision = QMessageBox::warning (this,
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
429 msg,
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
430 tr ("The file %1\n"
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
431 "has been modified. Do you want to save the changes?").
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
432 arg (_file_name),
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
433 QMessageBox::Save,
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
434 QMessageBox::Discard, cancelButton );
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
435 if (decision == QMessageBox::Save)
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
436 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
437 save_file ();
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
438 if (_edit_area->isModified ())
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
439 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
440 // If the user attempted to save the file, but it's still
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
441 // modified, then probably something went wrong, so return
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
442 // cancel for cancel this operation or try to save files
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
443 // as if cancel not possible
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
444 if ( cancelButton )
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
445 return (QMessageBox::Cancel);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
446 else
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
447 save_file_as ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
448 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
449 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
450 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
451 return (decision);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
452 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
453
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
454 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
455 file_editor_tab::remove_bookmark ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
456 {
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
457 _edit_area->markerDeleteAll (bookmark);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
458 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
459
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
460 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
461 file_editor_tab::toggle_bookmark ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
462 {
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
463 int line, cur;
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
464 _edit_area->getCursorPosition (&line,&cur);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
465 if ( _edit_area->markersAtLine (line) && (1 << bookmark) )
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
466 _edit_area->markerDelete (line, bookmark);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
467 else
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
468 _edit_area->markerAdd (line, bookmark);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
469 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
470
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
471 void
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
472 file_editor_tab::next_bookmark()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
473 {
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
474 int line, cur, nextline;
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
475 _edit_area->getCursorPosition (&line, &cur);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
476 if ( _edit_area->markersAtLine (line) && (1 << bookmark) )
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
477 line++; // we have a breakpoint here, so start search from next line
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
478 nextline = _edit_area->markerFindNext (line, (1 << bookmark));
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
479 _edit_area->setCursorPosition (nextline, 0);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
480 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
481
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
482 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
483 file_editor_tab::previous_bookmark ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
484 {
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
485 int line, cur, prevline;
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
486 _edit_area->getCursorPosition (&line, &cur);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
487 if ( _edit_area->markersAtLine (line) && (1 << bookmark) )
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
488 line--; // we have a breakpoint here, so start search from prev line
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
489 prevline = _edit_area->markerFindPrevious (line, (1 << bookmark));
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
490 _edit_area->setCursorPosition (prevline, 0);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
491 }
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
492
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
493 void
14829
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
494 file_editor_tab::remove_all_breakpoints ()
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
495 {
14829
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
496 QFileInfo file_info (_file_name);
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
497 QString path = file_info.absolutePath ();
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
498 QString function_name = file_info.fileName ();
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
499
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
500 // We have to cut off the suffix, because octave appends it.
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
501 function_name.chop (file_info.suffix ().length () + 1);
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
502
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
503 octave_link::instance ()->post_event
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
504 (new octave_remove_all_breakpoints_event (*this,
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
505 path.toStdString (),
e97be88fc478 Fixed removing all breakpoints.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14827
diff changeset
506 function_name.toStdString ()));
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
507 }
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
508
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
509 void
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
510 file_editor_tab::toggle_breakpoint ()
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
511 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
512 int line, cur;
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
513 _edit_area->getCursorPosition (&line, &cur);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
514 if ( _edit_area->markersAtLine (line) && (1 << breakpoint) )
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
515 request_remove_breakpoint (line);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
516 else
14827
6b90737f69cc Very basic breakpoint setting and removing in the editor works.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14826
diff changeset
517 request_add_breakpoint (line);
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
518 }
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
519
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
520 void
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
521 file_editor_tab::next_breakpoint ()
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
522 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
523 int line, cur, nextline;
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
524 _edit_area->getCursorPosition (&line, &cur);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
525 if ( _edit_area->markersAtLine (line) && (1 << breakpoint) )
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
526 line++; // we have a breakpoint here, so start search from next line
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
527 nextline = _edit_area->markerFindNext (line, (1 << breakpoint));
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
528 _edit_area->setCursorPosition (nextline, 0);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
529 }
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
530
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
531 void
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
532 file_editor_tab::previous_breakpoint ()
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
533 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
534 int line, cur, prevline;
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
535 _edit_area->getCursorPosition (&line, &cur);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
536 if ( _edit_area->markersAtLine (line) && (1 << breakpoint) )
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
537 line--; // we have a breakpoint here, so start search from prev line
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
538 prevline = _edit_area->markerFindPrevious (line, (1 << breakpoint));
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
539 _edit_area->setCursorPosition (prevline, 0);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
540 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
541
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
542 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
543 file_editor_tab::cut ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
544 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
545 _edit_area->cut ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
546 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
547
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
548 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
549 file_editor_tab::copy ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
550 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
551 _edit_area->copy ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
552 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
553
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
554 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
555 file_editor_tab::paste ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
556 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
557 _edit_area->paste ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
558 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
559
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
560 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
561 file_editor_tab::undo ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
562 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
563 _edit_area->undo ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
564 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
565
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
566 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
567 file_editor_tab::redo ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
568 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
569 _edit_area->redo ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
570 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
571
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
572 void
14825
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
573 file_editor_tab::set_debugger_position (int line)
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
574 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
575 _edit_area->markerDeleteAll (debugger_position);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
576 if (line > 0)
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
577 {
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
578 _edit_area->markerAdd (line, debugger_position);
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
579 }
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
580 }
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
581
eae0e9f2a8c6 Added menus, markers and methods to visualize debugging in the editor and add, remove and navigate breakpoints* .
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14804
diff changeset
582 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
583 file_editor_tab::set_modified (bool modified)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
584 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
585 _edit_area->setModified (modified);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
586 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
587
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
588 bool
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
589 file_editor_tab::open_file ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
590 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
591 QString openFileName;
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
592 QFileDialog fileDialog(this);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
593 fileDialog.setNameFilter(SAVE_FILE_FILTER);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
594 fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
595 fileDialog.setViewMode(QFileDialog::Detail);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
596 if (fileDialog.exec () == QDialog::Accepted)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
597 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
598 openFileName = fileDialog.selectedFiles().at(0);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
599 if (openFileName.isEmpty ())
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
600 return false;
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
601
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
602 load_file(openFileName);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
603 return true;
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
604 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
605 else
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
606 {
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
607 return false;
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
608 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
609 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
610
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
611 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
612 file_editor_tab::load_file (QString fileName)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
613 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
614 if (!_file_editor->isVisible ())
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
615 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
616 _file_editor->show ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
617 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
618
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
619 QFile file (fileName);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
620 if (!file.open (QFile::ReadOnly))
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
621 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
622 QMessageBox::warning (this, tr ("Octave Editor"),
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
623 tr ("Could not open file %1 for read:\n%2.").arg (fileName).
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
624 arg (file.errorString ()));
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
625 return;
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
626 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
627
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
628 QTextStream in (&file);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
629 QApplication::setOverrideCursor (Qt::WaitCursor);
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
630 _edit_area->setText (in.readAll ());
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
631 QApplication::restoreOverrideCursor ();
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
632
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
633 set_file_name (fileName);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
634 update_tracked_file ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
635
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
636
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
637 update_window_title (false); // window title (no modification)
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
638 _edit_area->setModified (false); // loaded file is not modified yet
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
639 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
640
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
641 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
642 file_editor_tab::new_file ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
643 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
644 if (!_file_editor->isVisible ())
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
645 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
646 _file_editor->show ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
647 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
648
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
649 set_file_name (UNNAMED_FILE);
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
650 update_window_title (false); // window title (no modification)
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
651 _edit_area->setText ("");
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
652 _edit_area->setModified (false); // new file is not modified yet
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
653 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
654
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
655 bool file_editor_tab::save_file()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
656 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
657 return save_file (_file_name);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
658 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
659
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
660 bool
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
661 file_editor_tab::save_file (QString saveFileName)
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
662 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
663 // it is a new file with the name "<unnamed>" -> call saveFielAs
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
664 if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ())
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
665 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
666 return save_file_as();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
667 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
668
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
669 QStringList watched_files = _file_system_watcher.files();
14796
e10d7bcfdd9e Now recognizing more symbol types in workspace view. Fixed bug with file system watcher complaining with new files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14795
diff changeset
670 if (!watched_files.isEmpty ())
e10d7bcfdd9e Now recognizing more symbol types in workspace view. Fixed bug with file system watcher complaining with new files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14795
diff changeset
671 _file_system_watcher.removePaths(watched_files);
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
672
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
673 // open the file for writing
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
674 QFile file (saveFileName);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
675 if (!file.open (QFile::WriteOnly))
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
676 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
677 QMessageBox::warning (this, tr ("Octave Editor"),
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
678 tr ("Could not open file %1 for write:\n%2.").
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
679 arg (saveFileName).arg (file.errorString ()));
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
680 _file_system_watcher.addPaths (watched_files);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
681 return false;
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
682 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
683
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
684 // save the contents into the file
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
685 QTextStream out (&file);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
686 QApplication::setOverrideCursor (Qt::WaitCursor);
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
687 out << _edit_area->text ();
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
688 QApplication::restoreOverrideCursor ();
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
689
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
690 // save file name for later use
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
691 _file_name = saveFileName;
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
692 // set the window title to actual file name (not modified)
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
693 update_window_title (false);
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
694 // files is save -> not modified
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
695 _edit_area->setModified (false);
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
696 file.close();
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
697
14796
e10d7bcfdd9e Now recognizing more symbol types in workspace view. Fixed bug with file system watcher complaining with new files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14795
diff changeset
698 if (!watched_files.isEmpty ())
e10d7bcfdd9e Now recognizing more symbol types in workspace view. Fixed bug with file system watcher complaining with new files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14795
diff changeset
699 _file_system_watcher.addPaths (watched_files);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
700 return true;
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
701 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
702
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
703 bool
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
704 file_editor_tab::save_file_as ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
705 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
706 QString saveFileName(_file_name);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
707 QFileDialog fileDialog(this);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
708 if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ())
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
709 {
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
710 QString directory = QString::fromStdString
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
711 (octave_link::instance ()->get_last_working_directory ());
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
712
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
713 if (directory.isEmpty ())
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
714 {
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
715 directory = QDir::homePath ();
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
716 }
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
717
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
718 fileDialog.setDirectory (directory);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
719 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
720 else
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
721 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
722 fileDialog.selectFile (saveFileName);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
723 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
724 fileDialog.setNameFilter (SAVE_FILE_FILTER);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
725 fileDialog.setDefaultSuffix ("m");
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
726 fileDialog.setAcceptMode (QFileDialog::AcceptSave);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
727 fileDialog.setViewMode (QFileDialog::Detail);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
728
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
729 if (fileDialog.exec ())
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
730 {
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
731 saveFileName = fileDialog.selectedFiles ().at (0);
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
732 if (saveFileName.isEmpty ())
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
733 return false;
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
734
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
735 return save_file (saveFileName);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
736 }
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
737
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
738 return false;
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
739 }
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
740
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
741 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
742 file_editor_tab::run_file ()
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
743 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
744 if (_edit_area->isModified ())
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
745 save_file(_file_name);
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
746
14830
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
747 QFileInfo file_info (_file_name);
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
748 QString path = file_info.absolutePath ();
14890
3ad363879015 Fixed bug with error message about missing arguments when running a file.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14877
diff changeset
749 //QString current_path = QString::fromStdString
14830
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
750 (octave_link::instance ()->get_last_working_directory ());
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
751 QString function_name = file_info.fileName ();
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
752
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
753 // We have to cut off the suffix, because octave appends it.
41b86dc61306 Removed run command, instead cding into the script directory and executing script directly.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14829
diff changeset
754 function_name.chop (file_info.suffix ().length () + 1);
14877
bc6c099eacc0 Removed cd'ing back after running a script for compatibility with less.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14874
diff changeset
755 _file_editor->terminal ()->sendText (QString ("cd \'%1\'\n%2\n")
14890
3ad363879015 Fixed bug with error message about missing arguments when running a file.
Jacob Dawid <jacob.dawid@gmail.com>
parents: 14877
diff changeset
756 .arg(path).arg (function_name));
14804
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
757 // TODO: Sending a run event crashes for long scripts. Find out why.
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
758 // octave_link::instance ()
a565c560e654 Replaced a lot of terminal interaction with events: Clearing, loading and saving workspace, running a file. Default location for saving a new file is now the current working directory. Fixed bad settings with a fresh installation of the GUI by providing a file with default settings and installing it when appropriate.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14796
diff changeset
759 // ->post_event (new octave_run_file_event (*this, _file_name.toStdString ()));
14676
35512b788af2 Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
760 }
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
761
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
762 void
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
763 file_editor_tab::file_has_changed (QString fileName)
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
764 {
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
765 Q_UNUSED (fileName);
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
766 if (QFile::exists (_file_name))
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
767 {
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
768 // Prevent popping up multiple message boxes when the file has
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
769 // been changed multiple times.
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
770 static bool alreadyAsking = false;
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
771 if (!alreadyAsking)
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
772 {
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
773 alreadyAsking = true;
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
774
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
775 int decision =
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
776 QMessageBox::warning (this, tr ("Octave Editor"),
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
777 tr ("It seems that \'%1\' has been modified by another application. Do you want to reload it?").
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
778 arg (_file_name), QMessageBox::Yes,
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
779 QMessageBox::No);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
780
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
781 if (decision == QMessageBox::Yes)
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
782 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
783 load_file (_file_name);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
784 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
785
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
786 alreadyAsking = false;
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
787 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
788 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
789 else
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
790 {
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
791 int decision =
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
792 QMessageBox::warning (this, tr ("Octave Editor"),
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
793 tr ("It seems that \'%1\' has been deleted or renamed. Do you want to save it now?").
15045
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
794 arg (_file_name), QMessageBox::Save,
1ffaad442161 Source code formatting (80-column lines, mostly whitespace changes)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14890
diff changeset
795 QMessageBox::Close);
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
796 if (decision == QMessageBox::Save)
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
797 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
798 if (!save_file_as ())
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
799 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
800 set_file_name (UNNAMED_FILE);
14788
85daba52b2d4 Fixed bug with editor complaining that a file has been modified by another application when saving.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14715
diff changeset
801 update_window_title (true); // window title (no modification)
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
802 set_modified (true);
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
803 update_tracked_file ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
804 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
805 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
806 else
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
807 {
14709
f50591409306 Started to rename class names and methods from camel case to underscore-
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14707
diff changeset
808 emit close_request ();
14690
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
809 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
810 }
ca733a66be7a Fixed bug with not opening the editor when clicking a file from the file browser. Implemented watching the file on disk.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 14680
diff changeset
811 }