Mercurial > hg > octave-lyh
annotate gui/src/FileEditorMdiSubWindow.cpp @ 13506:c70511cf64ee
Reformatted to GNU Style.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Sun, 17 Jul 2011 22:59:28 +0200 |
parents | 13e3d60aff2d |
children | 8c143d6d0330 |
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 |
13501 | 2 * Copyright (C) 2011 Jacob Dawid |
3 * jacob.dawid@googlemail.com | |
4 * | |
5 * This program is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation, either version 3 of the License, or | |
8 * (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 */ | |
18 | |
19 #include "FileEditorMdiSubWindow.h" | |
20 #include <QVBoxLayout> | |
21 #include <QApplication> | |
22 #include <QFile> | |
23 #include <QFileDialog> | |
24 #include <QMessageBox> | |
25 #include <QAction> | |
26 #include <QStyle> | |
27 #include <QTextStream> | |
28 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
29 FileEditorMdiSubWindow::FileEditorMdiSubWindow (QWidget * parent):QMdiSubWindow |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
30 (parent) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
31 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
32 construct (); |
13501 | 33 } |
34 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
35 FileEditorMdiSubWindow::~FileEditorMdiSubWindow () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
36 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
37 while (checkFileModified ("Close File")) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
38 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
39 } // don't close if something went wrong while saving the file |
13501 | 40 } |
41 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
42 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
43 FileEditorMdiSubWindow::loadFile (QString fileName) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
44 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
45 QFile file (fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
46 if (!file.open (QFile::ReadOnly)) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
47 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
48 QMessageBox::warning (this, tr ("File Editor"), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
49 tr ("Cannot read file %1:\n%2.").arg (fileName). |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
50 arg (file.errorString ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
51 return; |
13501 | 52 } |
53 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
54 QTextStream in (&file); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
55 QApplication::setOverrideCursor (Qt::WaitCursor); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
56 m_editor->setText (in.readAll ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
57 QApplication::restoreOverrideCursor (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
58 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
59 m_fileName = fileName; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
60 setWindowTitle (fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
61 m_statusBar->showMessage (tr ("File loaded."), 2000); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
62 m_editor->setModified (false); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
63 } |
13501 | 64 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
65 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
66 FileEditorMdiSubWindow::newFile () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
67 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
68 if (checkFileModified ("Open New File")) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
69 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
70 return; // something went wrong while saving the old file |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
71 } |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
72 m_fileName = "<unnamed>"; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
73 setWindowTitle (m_fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
74 m_editor->setText (""); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
75 m_editor->setModified (false); |
13501 | 76 } |
77 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
78 int |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
79 FileEditorMdiSubWindow::checkFileModified (QString msg) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
80 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
81 if (m_editor->isModified ()) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
82 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
83 int decision = QMessageBox::question (this, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
84 msg, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
85 "Do you want to save the current file?", |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
86 QMessageBox::Yes, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
87 QMessageBox::No); |
13501 | 88 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
89 if (decision == QMessageBox::Yes) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
90 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
91 saveFile (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
92 if (m_editor->isModified ()) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
93 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
94 // If the user attempted to save the file, but it's still |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
95 // modified, then probably something went wrong, so return error |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
96 return (1); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
97 } |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
98 } |
13501 | 99 } |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
100 return (0); |
13501 | 101 } |
102 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
103 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
104 FileEditorMdiSubWindow::saveFile () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
105 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
106 if (m_fileName.isEmpty ()) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
107 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
108 m_fileName = |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
109 QFileDialog::getSaveFileName (this, "Save File", m_fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
110 if (m_fileName.isEmpty ()) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
111 return; |
13501 | 112 } |
113 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
114 QFile file (m_fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
115 if (!file.open (QFile::WriteOnly)) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
116 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
117 QMessageBox::warning (this, tr ("File Editor"), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
118 tr ("Cannot write file %1:\n%2."). |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
119 arg (m_fileName).arg (file.errorString ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
120 return; |
13501 | 121 } |
122 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
123 QTextStream out (&file); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
124 QApplication::setOverrideCursor (Qt::WaitCursor); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
125 out << m_editor->text (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
126 QApplication::restoreOverrideCursor (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
127 m_statusBar->showMessage (tr ("File saved"), 2000); |
13501 | 128 } |
129 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
130 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
131 FileEditorMdiSubWindow::saveFileAs () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
132 { /* |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
133 QString saveFileName = QFileDialog::getSaveFileName(this, "Save File", m_fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
134 if(saveFileName.isEmpty()) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
135 return; |
13501 | 136 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
137 QFile file(saveFileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
138 file.open(QFile::WriteOnly); |
13501 | 139 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
140 if(file.write(m_simpleEditor->toPlainText().toLocal8Bit()) == -1) { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
141 QMessageBox::warning(this, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
142 "Error Saving File", |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
143 QString("The file could not be saved: %1.").arg(file.errorString())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
144 } else { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
145 m_simpleEditor->document()->setModified(false); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
146 m_fileName = saveFileName; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
147 setWindowTitle(m_fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
148 } |
13501 | 149 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
150 file.close(); */ |
13501 | 151 } |
152 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
153 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
154 FileEditorMdiSubWindow::showToolTipNew () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
155 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
156 m_statusBar->showMessage ("Create a new file.", 2000); |
13501 | 157 } |
158 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
159 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
160 FileEditorMdiSubWindow::showToolTipSave () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
161 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
162 m_statusBar->showMessage ("Save the file.", 2000); |
13501 | 163 } |
164 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
165 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
166 FileEditorMdiSubWindow::showToolTipSaveAs () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
167 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
168 m_statusBar->showMessage ("Save the file as.", 2000); |
13501 | 169 } |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
170 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
171 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
172 FileEditorMdiSubWindow::showToolTipUndo () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
173 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
174 m_statusBar->showMessage ("Revert previous changes.", 2000); |
13501 | 175 } |
176 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
177 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
178 FileEditorMdiSubWindow::showToolTipRedo () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
179 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
180 m_statusBar->showMessage ("Append previous changes.", 2000); |
13501 | 181 } |
182 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
183 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
184 FileEditorMdiSubWindow::registerModified (bool modified) |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
185 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
186 m_modified = modified; |
13501 | 187 } |
188 | |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
189 void |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
190 FileEditorMdiSubWindow::construct () |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
191 { |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
192 QStyle *style = QApplication::style (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
193 setWidget (new QWidget ()); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
194 m_toolBar = new QToolBar (this); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
195 m_statusBar = new QStatusBar (this); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
196 m_editor = new QsciScintilla (this); |
13503
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
197 |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
198 // Not available in the Debian repos yet! |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
199 /* |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
200 m_lexer = new QsciLexerOctave(m_editor); |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
201 m_lexer->setDefaultFont(QFont("Monospace",9)); |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
202 m_lexer->setAutoIndentStyle(QsciScintilla::AiMaintain || |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
203 QsciScintilla::AiOpening || |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
204 QsciScintilla::AiClosing); |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
205 m_editor->setLexer(m_lexer); |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
206 */ |
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
207 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
208 m_editor->setMarginType (1, QsciScintilla::TextMargin); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
209 m_editor->setMarginType (2, QsciScintilla::SymbolMargin); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
210 m_editor->setFolding (QsciScintilla::BoxedTreeFoldStyle, 2); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
211 m_editor->setMarginLineNumbers (1, true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
212 m_editor->setMarginWidth (1, "99999"); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
213 |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
214 m_editor->setBraceMatching (QsciScintilla::SloppyBraceMatch); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
215 m_editor->setAutoIndent (true); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
216 m_editor->setIndentationWidth (2); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
217 m_editor->setIndentationsUseTabs (false); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
218 m_editor->setAutoCompletionThreshold (2); |
13503
5ab40ef3d241
Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13501
diff
changeset
|
219 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
220 QAction *newAction = new QAction (style->standardIcon (QStyle::SP_FileIcon), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
221 "", m_toolBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
222 QAction *saveAction = |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
223 new QAction (style->standardIcon (QStyle::SP_DriveHDIcon), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
224 "", m_toolBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
225 QAction *saveActionAs = |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
226 new QAction (style->standardIcon (QStyle::SP_DriveFDIcon), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
227 "", m_toolBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
228 QAction *undoAction = |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
229 new QAction (style->standardIcon (QStyle::SP_ArrowLeft), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
230 "", m_toolBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
231 QAction *redoAction = |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
232 new QAction (style->standardIcon (QStyle::SP_ArrowRight), |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
233 "", m_toolBar); |
13501 | 234 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
235 m_toolBar->addAction (newAction); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
236 m_toolBar->addAction (saveAction); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
237 m_toolBar->addAction (saveActionAs); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
238 m_toolBar->addAction (undoAction); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
239 m_toolBar->addAction (redoAction); |
13501 | 240 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
241 QVBoxLayout *layout = new QVBoxLayout (); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
242 layout->addWidget (m_toolBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
243 layout->addWidget (m_editor); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
244 layout->addWidget (m_statusBar); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
245 layout->setMargin (2); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
246 widget ()->setLayout (layout); |
13501 | 247 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
248 connect (newAction, SIGNAL (triggered ()), this, SLOT (newFile ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
249 connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
250 connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
251 connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
252 connect (saveActionAs, SIGNAL (triggered ()), this, SLOT (saveFileAs ())); |
13501 | 253 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
254 connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
255 connect (undoAction, SIGNAL (hovered ()), this, SLOT (showToolTipUndo ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
256 connect (redoAction, SIGNAL (hovered ()), this, SLOT (showToolTipRedo ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
257 connect (saveAction, SIGNAL (hovered ()), this, SLOT (showToolTipSave ())); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
258 connect (saveActionAs, SIGNAL (hovered ()), this, |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
259 SLOT (showToolTipSaveAs ())); |
13501 | 260 |
13506
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
261 m_fileName = ""; |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
262 setWindowTitle (m_fileName); |
c70511cf64ee
Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13504
diff
changeset
|
263 show (); |
13501 | 264 } |