Mercurial > hg > octave-lyh
annotate gui/src/FileEditor.cpp @ 14602:c8453a013000 gui
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
* FileEditor: Now the call of another process returns immediately. Adjusted text when closing a file.
* MainWindow: Moved creating a lexer into the constructor.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Mon, 07 May 2012 02:36:49 +0200 |
parents | 97cb9286919c |
children | 7605e7136b50 |
rev | line source |
---|---|
13504
13e3d60aff2d
Replaced Quint with OctaveGUI.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13503
diff
changeset
|
1 /* OctaveGUI - A graphical user interface for Octave |
13674
c0e66d6e3dc8
Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13672
diff
changeset
|
2 * Copyright (C) 2011 Jacob Dawid (jacob.dawid@googlemail.com) |
13501 | 3 * |
4 * This program is free software: you can redistribute it and/or modify | |
14290
faece6b2ab90
Corrected license headers in all files to GPL.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14255
diff
changeset
|
5 * it under the terms of the GNU General Public License as |
13674
c0e66d6e3dc8
Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13672
diff
changeset
|
6 * published by the Free Software Foundation, either version 3 of the |
c0e66d6e3dc8
Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13672
diff
changeset
|
7 * License, or (at your option) any later version. |
13501 | 8 * |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14290
faece6b2ab90
Corrected license headers in all files to GPL.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14255
diff
changeset
|
12 * GNU General Public License for more details. |
13501 | 13 * |
14290
faece6b2ab90
Corrected license headers in all files to GPL.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14255
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
13674
c0e66d6e3dc8
Updated license headers and moved to AGPLv3.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13672
diff
changeset
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
13501 | 16 */ |
17 | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
18 #include "FileEditor.h" |
13501 | 19 #include <QVBoxLayout> |
20 #include <QApplication> | |
21 #include <QFile> | |
13584 | 22 #include <QFont> |
13501 | 23 #include <QFileDialog> |
24 #include <QMessageBox> | |
25 #include <QStyle> | |
26 #include <QTextStream> | |
27 | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
28 FileEditor::FileEditor (QWidget * parent) |
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
29 : QWidget (parent) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
30 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
31 construct (); |
13501 | 32 } |
33 | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
34 FileEditor::~FileEditor () |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
35 { |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
36 } |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
37 |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
38 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
39 FileEditor::closeEvent(QCloseEvent *event) |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
40 { |
14602
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
41 if ( m_mainWindow->closing () ) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
42 { |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
43 // close wohle application: save file or not if modified |
14602
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
44 checkFileModified ("Closing Octave", 0); // no cancel possible |
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
45 event->accept (); |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
46 } |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
47 else |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
48 { |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
49 // ignore close event if file is not saved and user cancels closing this window |
14602
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
50 if (checkFileModified ("Close File",QMessageBox::Cancel) == QMessageBox::Cancel) |
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
51 { |
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
52 event->ignore (); |
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
53 } |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
54 else |
14602
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
55 { |
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
56 event->accept(); |
c8453a013000
Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14599
diff
changeset
|
57 } |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
58 } |
13501 | 59 } |
60 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
61 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
62 FileEditor::handleMarginClicked(int margin, int line, Qt::KeyboardModifiers state) |
13584 | 63 { |
13587 | 64 Q_UNUSED (state); |
13584 | 65 if ( margin == 1 ) // marker margin |
66 { | |
67 unsigned int mask = m_editor->markersAtLine (line); | |
68 if (mask && (1 << MARKER_BOOKMARK)) | |
69 m_editor->markerDelete(line,MARKER_BOOKMARK); | |
70 else | |
71 m_editor->markerAdd(line,MARKER_BOOKMARK); | |
72 } | |
73 } | |
74 | |
75 void | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
76 FileEditor::newWindowTitle(bool modified) |
13557
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
77 { |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
78 QString title(m_fileName); |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
79 if ( !m_longTitle ) |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
80 { |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
81 QFileInfo file(m_fileName); |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
82 title = file.fileName(); |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
83 } |
13557
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
84 if ( modified ) |
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
85 { |
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
86 setWindowTitle(title.prepend("* ")); |
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
87 } |
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
88 else |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
89 setWindowTitle (title); |
13557
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
90 } |
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
91 |
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
92 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
93 FileEditor::handleCopyAvailable(bool enableCopy) |
13584 | 94 { |
95 m_copyAction->setEnabled(enableCopy); | |
96 m_cutAction->setEnabled(enableCopy); | |
97 } | |
98 | |
99 | |
100 void | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
101 FileEditor::openFile () |
13530
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
102 { |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
103 if (checkFileModified ("Open File",QMessageBox::Cancel)==QMessageBox::Cancel) |
13530
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
104 { |
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
105 return; // existing file not saved and opening another file canceled by user |
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
106 } |
13649
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
107 QString openFileName; |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
108 QFileDialog dlg(this); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
109 dlg.setNameFilter(SAVE_FILE_FILTER); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
110 dlg.setAcceptMode(QFileDialog::AcceptOpen); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
111 dlg.setViewMode(QFileDialog::Detail); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
112 if ( dlg.exec() ) |
13530
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
113 { |
13649
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
114 openFileName = dlg.selectedFiles().at(0); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
115 if (openFileName.isEmpty ()) |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
116 return; |
13530
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
117 loadFile(openFileName); |
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
118 } |
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
119 } |
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
120 |
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
121 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
122 FileEditor::loadFile (QString fileName) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
123 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
124 QFile file (fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
125 if (!file.open (QFile::ReadOnly)) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
126 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
127 QMessageBox::warning (this, tr ("File Editor"), |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
128 tr ("Cannot read file %1:\n%2.").arg (fileName). |
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
129 arg (file.errorString ())); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
130 return; |
13501 | 131 } |
132 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
133 QTextStream in (&file); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
134 QApplication::setOverrideCursor (Qt::WaitCursor); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
135 m_editor->setText (in.readAll ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
136 QApplication::restoreOverrideCursor (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
137 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
138 m_fileName = fileName; |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
139 newWindowTitle (false); // window title (no modification) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
140 m_statusBar->showMessage (tr ("File loaded."), 2000); |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
141 m_editor->setModified (false); // loaded file is not modified yet |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
142 } |
13501 | 143 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
144 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
145 FileEditor::newFile () |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
146 { |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
147 if (checkFileModified ("Create New File",QMessageBox::Cancel)==QMessageBox::Cancel) |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
148 { |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
149 return; // existing file not saved and creating new file canceled by user |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
150 } |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
151 |
13529 | 152 m_fileName = UNNAMED_FILE; |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
153 newWindowTitle (false); // window title (no modification) |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
154 m_editor->setText (""); |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
155 m_editor->setModified (false); // new file is not modified yet |
13501 | 156 } |
157 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
158 int |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
159 FileEditor::checkFileModified (QString msg, int cancelButton) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
160 { |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
161 int decision = QMessageBox::Yes; |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
162 if (m_editor->isModified ()) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
163 { |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
164 // file is modified but not saved, aks user what to do |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
165 decision = QMessageBox::warning (this, |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
166 msg, |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
167 tr ("The file %1\n" |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
168 "has been modified. Do you want to save the changes?"). |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
169 arg (m_fileName), |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
170 QMessageBox::Save, QMessageBox::Discard, cancelButton ); |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
171 if (decision == QMessageBox::Save) |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
172 { |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
173 saveFile (); |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
174 if (m_editor->isModified ()) |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
175 { |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
176 // If the user attempted to save the file, but it's still |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
177 // modified, then probably something went wrong, so return cancel |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
178 // for cancel this operation or try to save files as if cancel not |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
179 // possible |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
180 if ( cancelButton ) |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
181 return (QMessageBox::Cancel); |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
182 else |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
183 saveFileAs (); |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
184 } |
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
185 } |
13501 | 186 } |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
187 return (decision); |
13501 | 188 } |
189 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
190 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
191 FileEditor::saveFile () |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
192 { |
13529 | 193 saveFile(m_fileName); |
194 } | |
195 | |
196 void | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
197 FileEditor::saveFile (QString saveFileName) |
13529 | 198 { |
199 // it is a new file with the name "<unnamed>" -> call saveFielAs | |
13649
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
200 if (saveFileName==UNNAMED_FILE || saveFileName.isEmpty ()) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
201 { |
13529 | 202 saveFileAs(); |
203 return; | |
13501 | 204 } |
205 | |
13649
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
206 // open the file for writing |
13529 | 207 QFile file (saveFileName); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
208 if (!file.open (QFile::WriteOnly)) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
209 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
210 QMessageBox::warning (this, tr ("File Editor"), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
211 tr ("Cannot write file %1:\n%2."). |
13529 | 212 arg (saveFileName).arg (file.errorString ())); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
213 return; |
13501 | 214 } |
215 | |
13529 | 216 // save the contents into the file |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
217 QTextStream out (&file); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
218 QApplication::setOverrideCursor (Qt::WaitCursor); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
219 out << m_editor->text (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
220 QApplication::restoreOverrideCursor (); |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
221 m_fileName = saveFileName; // save file name for later use |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
222 newWindowTitle(false); // set the window title to actual file name (not modified) |
13529 | 223 m_statusBar->showMessage (tr ("File %1 saved").arg(m_fileName), 2000); |
13524
8c143d6d0330
gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents:
13506
diff
changeset
|
224 m_editor->setModified (false); // files is save -> not modified |
13501 | 225 } |
226 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
227 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
228 FileEditor::saveFileAs () |
13529 | 229 { |
13649
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
230 QString saveFileName(m_fileName); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
231 QFileDialog dlg(this); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
232 if (saveFileName==UNNAMED_FILE || saveFileName.isEmpty ()) |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
233 { |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
234 saveFileName = QDir::homePath(); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
235 dlg.setDirectory(saveFileName); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
236 } |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
237 else |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
238 { |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
239 dlg.selectFile(saveFileName); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
240 } |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
241 dlg.setNameFilter(SAVE_FILE_FILTER); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
242 dlg.setDefaultSuffix("m"); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
243 dlg.setAcceptMode(QFileDialog::AcceptSave); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
244 dlg.setViewMode(QFileDialog::Detail); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
245 if ( dlg.exec() ) |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
246 { |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
247 saveFileName = dlg.selectedFiles().at(0); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
248 if (saveFileName.isEmpty ()) |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
249 return; |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
250 saveFile(saveFileName); |
0a19410e88c0
improve save as: auto-add extension .m with check for overwrite
ttl <ttl@justmail.de>
parents:
13648
diff
changeset
|
251 } |
13501 | 252 } |
253 | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
254 // handle the run command |
13558
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
255 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
256 FileEditor::runFile () |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
257 { |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
258 if (m_editor->isModified ()) |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
259 saveFile(m_fileName); |
14306
c3b62d211b80
.m-files can be directly run from the editor again. Autocompletion works again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14290
diff
changeset
|
260 m_terminalView->sendText (QString ("run \'%1\'\n").arg (m_fileName)); |
c3b62d211b80
.m-files can be directly run from the editor again. Autocompletion works again.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14290
diff
changeset
|
261 m_terminalView->setFocus (); |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
262 } |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
263 |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
264 |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
265 // (un)comment selected text |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
266 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
267 FileEditor::commentSelectedText () |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
268 { |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
269 doCommentSelectedText (true); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
270 } |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
271 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
272 FileEditor::uncommentSelectedText () |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
273 { |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
274 doCommentSelectedText (false); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
275 } |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
276 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
277 FileEditor::doCommentSelectedText (bool comment) |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
278 { |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
279 if ( m_editor->hasSelectedText() ) |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
280 { |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
281 int lineFrom, lineTo, colFrom, colTo, i; |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
282 m_editor->getSelection (&lineFrom,&colFrom,&lineTo,&colTo); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
283 if ( colTo == 0 ) // the beginning of last line is not selected |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
284 lineTo--; // stop at line above |
13656
1347d498959c
Comment/uncomment selected text operation can be undone with a single Undo action
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
13654
diff
changeset
|
285 m_editor->beginUndoAction (); |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
286 for ( i=lineFrom; i<=lineTo; i++ ) |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
287 { |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
288 if ( comment ) |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
289 m_editor->insertAt("%",i,0); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
290 else |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
291 { |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
292 QString line(m_editor->text(i)); |
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
293 if ( line.startsWith("%") ) |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
294 { |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
295 m_editor->setSelection(i,0,i,1); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
296 m_editor->removeSelectedText(); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
297 } |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
298 } |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
299 } |
13656
1347d498959c
Comment/uncomment selected text operation can be undone with a single Undo action
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
13654
diff
changeset
|
300 m_editor->endUndoAction (); |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
301 } |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
302 } |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
303 |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
304 |
13650
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
305 // remove bookmarks |
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
306 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
307 FileEditor::removeBookmark () |
13650
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
308 { |
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
309 m_editor->markerDeleteAll(MARKER_BOOKMARK); |
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
310 } |
13584 | 311 // toggle bookmark |
312 void | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
313 FileEditor::toggleBookmark () |
13584 | 314 { |
315 int line,cur; | |
316 m_editor->getCursorPosition(&line,&cur); | |
317 if ( m_editor->markersAtLine (line) && (1 << MARKER_BOOKMARK) ) | |
318 m_editor->markerDelete(line,MARKER_BOOKMARK); | |
319 else | |
320 m_editor->markerAdd(line,MARKER_BOOKMARK); | |
321 } | |
322 // goto next bookmark | |
323 void | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
324 FileEditor::nextBookmark () |
13584 | 325 { |
326 int line,cur,nextline; | |
327 m_editor->getCursorPosition(&line,&cur); | |
328 if ( m_editor->markersAtLine(line) && (1 << MARKER_BOOKMARK) ) | |
329 line++; // we have a bookmark here, so start search from next line | |
330 nextline = m_editor->markerFindNext(line,(1 << MARKER_BOOKMARK)); | |
331 m_editor->setCursorPosition(nextline,0); | |
332 } | |
333 // goto previous bookmark | |
334 void | |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
335 FileEditor::prevBookmark () |
13584 | 336 { |
337 int line,cur,prevline; | |
338 m_editor->getCursorPosition(&line,&cur); | |
339 if ( m_editor->markersAtLine(line) && (1 << MARKER_BOOKMARK) ) | |
340 line--; // we have a bookmark here, so start search from prev line | |
341 prevline = m_editor->markerFindPrevious(line,(1 << MARKER_BOOKMARK)); | |
342 m_editor->setCursorPosition(prevline,0); | |
343 } | |
344 | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
345 // function for setting the already existing lexer from MainWindow |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
346 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
347 FileEditor::initEditor (QTerminal* terminalView, |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
348 LexerOctaveGui* lexer, |
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
349 MainWindow* mainWindow) |
13558
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
350 { |
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
351 m_editor->setLexer(lexer); |
13869
d80086a9880e
Initial implementation of a Qt Win32 terminal widget.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13674
diff
changeset
|
352 m_terminalView = terminalView; // for sending commands to octave |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
353 // TODO: make a global commandOctave function? |
13657
347dfbea2c8a
modified editor files can be saved when main window is closed
ttl <ttl@justmail.de>
parents:
13656
diff
changeset
|
354 m_mainWindow = mainWindow; // get the MainWindow for chekcing state at subwindow close |
13558
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
355 } |
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
356 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
357 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
358 FileEditor::setModified (bool modified) |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
359 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
360 m_modified = modified; |
13501 | 361 } |
362 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
363 void |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
364 FileEditor::construct () |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
365 { |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
366 QSettings *settings = ResourceManager::instance ()->settings (); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
367 QStyle *style = QApplication::style (); |
13566
d22b9973120f
Renamed language files to match convention.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13562
diff
changeset
|
368 |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
369 m_menuBar = new QMenuBar (this); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
370 m_toolBar = new QToolBar (this); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
371 m_statusBar = new QStatusBar (this); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
372 m_editor = new QsciScintilla (this); |
13503
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
373 |
13584 | 374 // markers |
13558
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
375 m_editor->setMarginType (1, QsciScintilla::SymbolMargin); |
13584 | 376 m_editor->setMarginSensitivity(1,true); |
377 m_editor->markerDefine(QsciScintilla::RightTriangle,MARKER_BOOKMARK); | |
378 connect(m_editor,SIGNAL(marginClicked(int,int,Qt::KeyboardModifiers)), | |
379 this,SLOT(handleMarginClicked(int,int,Qt::KeyboardModifiers))); | |
380 | |
381 // line numbers | |
382 m_editor->setMarginsForegroundColor(QColor(96,96,96)); | |
383 m_editor->setMarginsBackgroundColor(QColor(232,232,220)); | |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
384 if ( settings->value ("editor/showLineNumbers",true).toBool () ) |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
385 { |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
386 QFont marginFont( settings->value ("editor/fontName","Courier").toString () , |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
387 settings->value ("editor/fontSize",10).toInt () ); |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
388 m_editor->setMarginsFont( marginFont ); |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
389 QFontMetrics metrics(marginFont); |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
390 m_editor->setMarginType (2, QsciScintilla::TextMargin); |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
391 m_editor->setMarginWidth(2, metrics.width("99999")); |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
392 m_editor->setMarginLineNumbers(2, true); |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
393 } |
13584 | 394 // code folding |
13558
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
395 m_editor->setMarginType (3, QsciScintilla::SymbolMargin); |
248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents:
13557
diff
changeset
|
396 m_editor->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3); |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
397 // other features |
14307
be3e1a14a6de
Added an interface settings tab to the settings dialog. Made a few improvements on the editor. Wrote a small welcome text in the welcome wizard. Moved configuration file to ~/.config/octave-gui/settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14306
diff
changeset
|
398 if ( settings->value ("editor/highlightCurrentLine",true).toBool () ) |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
399 { |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
400 m_editor->setCaretLineVisible(true); |
14307
be3e1a14a6de
Added an interface settings tab to the settings dialog. Made a few improvements on the editor. Wrote a small welcome text in the welcome wizard. Moved configuration file to ~/.config/octave-gui/settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14306
diff
changeset
|
401 m_editor->setCaretLineBackgroundColor(QColor(245,245,245)); |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
402 } |
14307
be3e1a14a6de
Added an interface settings tab to the settings dialog. Made a few improvements on the editor. Wrote a small welcome text in the welcome wizard. Moved configuration file to ~/.config/octave-gui/settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14306
diff
changeset
|
403 m_editor->setBraceMatching (QsciScintilla::StrictBraceMatch); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
404 m_editor->setAutoIndent (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
405 m_editor->setIndentationWidth (2); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
406 m_editor->setIndentationsUseTabs (false); |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
407 if ( settings->value ("editor/codeCompletion",true).toBool () ) |
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
408 { |
14307
be3e1a14a6de
Added an interface settings tab to the settings dialog. Made a few improvements on the editor. Wrote a small welcome text in the welcome wizard. Moved configuration file to ~/.config/octave-gui/settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14306
diff
changeset
|
409 m_editor->autoCompleteFromAll (); |
be3e1a14a6de
Added an interface settings tab to the settings dialog. Made a few improvements on the editor. Wrote a small welcome text in the welcome wizard. Moved configuration file to ~/.config/octave-gui/settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14306
diff
changeset
|
410 m_editor->setAutoCompletionSource(QsciScintilla::AcsAll); |
be3e1a14a6de
Added an interface settings tab to the settings dialog. Made a few improvements on the editor. Wrote a small welcome text in the welcome wizard. Moved configuration file to ~/.config/octave-gui/settings.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14306
diff
changeset
|
411 m_editor->setAutoCompletionThreshold (1); |
13659
d98c6ef06dff
included some editor setting into the setting dialog
ttl <ttl@justmail.de>
parents:
13657
diff
changeset
|
412 } |
13631
9ad313bcee2d
Possible fixed Andriys bug with russian symbols.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13587
diff
changeset
|
413 m_editor->setUtf8 (true); |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
414 m_longTitle = settings->value ("editor/longWindowTitle",true).toBool (); |
13503
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
415 |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
416 // The Actions |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
417 |
13555
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
418 // Theme icons with QStyle icons as fallback |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
419 QAction *newAction = new QAction ( |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
420 QIcon::fromTheme("document-new",style->standardIcon (QStyle::SP_FileIcon)), |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
421 tr("&New File"), m_toolBar); |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
422 QAction *openAction = new QAction ( |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
423 QIcon::fromTheme("document-open",style->standardIcon (QStyle::SP_DirOpenIcon)), |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
424 tr("&Open File"), m_toolBar); |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
425 QAction *saveAction = new QAction ( |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
426 QIcon::fromTheme("document-save",style->standardIcon (QStyle::SP_DriveHDIcon)), |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
427 tr("&Save File"), m_toolBar); |
13556
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
428 QAction *saveAsAction = new QAction ( |
13555
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
429 QIcon::fromTheme("document-save-as",style->standardIcon (QStyle::SP_DriveFDIcon)), |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
430 tr("Save File &As"), m_toolBar); |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
431 QAction *undoAction = new QAction ( |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
432 QIcon::fromTheme("edit-undo",style->standardIcon (QStyle::SP_ArrowLeft)), |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
433 tr("&Undo"), m_toolBar); |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
434 QAction *redoAction = new QAction ( |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
435 QIcon::fromTheme("edit-redo",style->standardIcon (QStyle::SP_ArrowRight)), |
be425f45f9e3
editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents:
13550
diff
changeset
|
436 tr("&Redo"), m_toolBar); |
13584 | 437 m_copyAction = new QAction (QIcon::fromTheme("edit-copy"),tr("&Copy"),m_toolBar); |
438 m_cutAction = new QAction (QIcon::fromTheme("edit-cut"),tr("Cu&t"),m_toolBar); | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
439 QAction *pasteAction = new QAction (QIcon::fromTheme("edit-paste"),tr("&Paste"),m_toolBar); |
13584 | 440 QAction *nextBookmarkAction = new QAction (tr("&Next Bookmark"),m_toolBar); |
441 QAction *prevBookmarkAction = new QAction (tr("Pre&vious Bookmark"),m_toolBar); | |
442 QAction *toggleBookmarkAction = new QAction (tr("Toggle &Bookmark"),m_toolBar); | |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
443 QAction *removeBookmarkAction = new QAction (tr("&Remove All Bookmarks"),m_toolBar); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
444 QAction *commentSelectedAction = new QAction (tr("&Comment Selected Text"),m_toolBar); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
445 QAction *uncommentSelectedAction = new QAction (tr("&Uncomment Selected Text"),m_toolBar); |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
446 QAction *runAction = new QAction ( |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
447 QIcon::fromTheme("media-play",style->standardIcon (QStyle::SP_MediaPlay)), |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
448 tr("&Run File"), m_toolBar); |
13501 | 449 |
13584 | 450 // some actions are disabled from the beginning |
451 m_copyAction->setEnabled(false); | |
452 m_cutAction->setEnabled(false); | |
453 connect(m_editor,SIGNAL(copyAvailable(bool)),this,SLOT(handleCopyAvailable(bool))); | |
454 | |
13556
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
455 // short cuts |
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
456 newAction->setShortcut(QKeySequence::New); |
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
457 openAction->setShortcut(QKeySequence::Open); |
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
458 saveAction->setShortcut(QKeySequence::Save); |
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
459 saveAsAction->setShortcut(QKeySequence::SaveAs); |
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
460 undoAction->setShortcut(QKeySequence::Undo); |
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
461 redoAction->setShortcut(QKeySequence::Redo); |
13584 | 462 m_copyAction->setShortcut(QKeySequence::Copy); |
463 m_cutAction->setShortcut(QKeySequence::Cut); | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
464 pasteAction->setShortcut(QKeySequence::Paste); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
465 runAction->setShortcut(Qt::Key_F5); |
13584 | 466 nextBookmarkAction->setShortcut(Qt::Key_F2); |
467 prevBookmarkAction->setShortcut(Qt::SHIFT + Qt::Key_F2); | |
13650
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
468 toggleBookmarkAction->setShortcut(Qt::Key_F7); |
13656
1347d498959c
Comment/uncomment selected text operation can be undone with a single Undo action
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
13654
diff
changeset
|
469 commentSelectedAction->setShortcut(Qt::CTRL + Qt::Key_R); |
1347d498959c
Comment/uncomment selected text operation can be undone with a single Undo action
Andriy Shinkarchuck <adriano32.gnu@gmail.com>
parents:
13654
diff
changeset
|
470 uncommentSelectedAction->setShortcut(Qt::CTRL + Qt::Key_T); |
13556
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
471 |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
472 // toolbar |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
473 m_toolBar->addAction (newAction); |
13530
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
474 m_toolBar->addAction (openAction); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
475 m_toolBar->addAction (saveAction); |
13556
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
476 m_toolBar->addAction (saveAsAction); |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
477 m_toolBar->addSeparator(); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
478 m_toolBar->addAction (undoAction); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
479 m_toolBar->addAction (redoAction); |
13584 | 480 m_toolBar->addAction (m_copyAction); |
481 m_toolBar->addAction (m_cutAction); | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
482 m_toolBar->addAction (pasteAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
483 m_toolBar->addSeparator(); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
484 m_toolBar->addAction (runAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
485 |
13566
d22b9973120f
Renamed language files to match convention.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13562
diff
changeset
|
486 // menu bar |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
487 QMenu *fileMenu = new QMenu(tr("&File"),m_menuBar); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
488 fileMenu->addAction(newAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
489 fileMenu->addAction(openAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
490 fileMenu->addAction(saveAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
491 fileMenu->addAction(saveAsAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
492 fileMenu->addSeparator(); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
493 m_menuBar->addMenu(fileMenu); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
494 QMenu *editMenu = new QMenu(tr("&Edit"),m_menuBar); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
495 editMenu->addAction(undoAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
496 editMenu->addAction(redoAction); |
13584 | 497 editMenu->addSeparator(); |
498 editMenu->addAction(m_copyAction); | |
499 editMenu->addAction(m_cutAction); | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
500 editMenu->addAction(pasteAction); |
13584 | 501 editMenu->addSeparator(); |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
502 editMenu->addAction(commentSelectedAction); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
503 editMenu->addAction(uncommentSelectedAction); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
504 editMenu->addSeparator(); |
13584 | 505 editMenu->addAction(toggleBookmarkAction); |
506 editMenu->addAction(nextBookmarkAction); | |
507 editMenu->addAction(prevBookmarkAction); | |
13650
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
508 editMenu->addAction(removeBookmarkAction); |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
509 m_menuBar->addMenu(editMenu); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
510 QMenu *runMenu = new QMenu(tr("&Run"),m_menuBar); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
511 runMenu->addAction(runAction); |
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
512 m_menuBar->addMenu(runMenu); |
13501 | 513 |
13566
d22b9973120f
Renamed language files to match convention.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13562
diff
changeset
|
514 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
515 QVBoxLayout *layout = new QVBoxLayout (); |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
516 layout->addWidget (m_menuBar); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
517 layout->addWidget (m_toolBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
518 layout->addWidget (m_editor); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
519 layout->addWidget (m_statusBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
520 layout->setMargin (2); |
14599
97cb9286919c
Cleaned up code.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14307
diff
changeset
|
521 setLayout (layout); |
13501 | 522 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
523 connect (newAction, SIGNAL (triggered ()), this, SLOT (newFile ())); |
13530
8c7390b78911
gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents:
13529
diff
changeset
|
524 connect (openAction, SIGNAL (triggered ()), this, SLOT (openFile ())); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
525 connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
526 connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ())); |
13584 | 527 connect (m_copyAction, SIGNAL (triggered ()), m_editor, SLOT (copy ())); |
528 connect (m_cutAction, SIGNAL (triggered ()), m_editor, SLOT (cut ())); | |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
529 connect (pasteAction, SIGNAL (triggered ()), m_editor, SLOT (paste ())); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
530 connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ())); |
13556
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
531 connect (saveAsAction, SIGNAL (triggered ()), this, SLOT (saveFileAs ())); |
13562
a89aa9e05e19
editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents:
13558
diff
changeset
|
532 connect (runAction, SIGNAL (triggered ()), this, SLOT (runFile ())); |
13584 | 533 connect (toggleBookmarkAction, SIGNAL (triggered ()), this, SLOT (toggleBookmark ())); |
534 connect (nextBookmarkAction, SIGNAL (triggered ()), this, SLOT (nextBookmark ())); | |
535 connect (prevBookmarkAction, SIGNAL (triggered ()), this, SLOT (prevBookmark ())); | |
13650
b93bfa9486ad
editor: bookmarks now toggled by F7 (bug #34066), menu entry for removing all bookmarks
ttl <ttl@justmail.de>
parents:
13649
diff
changeset
|
536 connect (removeBookmarkAction, SIGNAL (triggered ()), this, SLOT (removeBookmark ())); |
13654
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
537 connect (commentSelectedAction, SIGNAL (triggered ()), this, SLOT (commentSelectedText ())); |
c67f7d390a1a
editor: comment/uncomment selected text
ttl <ttl@justmail.de>
parents:
13650
diff
changeset
|
538 connect (uncommentSelectedAction, SIGNAL (triggered ()), this, SLOT (uncommentSelectedText ())); |
13501 | 539 |
540 | |
13557
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
541 // connect modified signal |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
542 connect (m_editor, SIGNAL (modificationChanged(bool)), this, SLOT (newWindowTitle(bool)) ); |
13557
ad18a8e7fb02
editor: change window title if text is modified
ttl <ttl@justmail.de>
parents:
13556
diff
changeset
|
543 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
544 m_fileName = ""; |
13672
c9501268a194
filename with or without full path in tabs of the editor
ttl <ttl@justmail.de>
parents:
13659
diff
changeset
|
545 newWindowTitle (false); |
13556
0d18b0e168ae
editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents:
13555
diff
changeset
|
546 setWindowIcon(QIcon::fromTheme("accessories-text-editor",style->standardIcon (QStyle::SP_FileIcon))); |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
547 show (); |
13501 | 548 } |