annotate gui/src/FileEditorMdiSubWindow.cpp @ 13648:da69cec2459f

Renamed OctaveTerminal to TerminalView.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 23 Aug 2011 20:31:51 +0200
parents b7d870e9b886
children 0a19410e88c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
2 * Copyright (C) 2011 Jacob Dawid
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
3 * jacob.dawid@googlemail.com
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
4 *
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
8 * (at your option) any later version.
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
9 *
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
14 *
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
17 */
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
18
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
19 #include "FileEditorMdiSubWindow.h"
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
20 #include "MainWindow.h"
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
21 #include <QVBoxLayout>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
22 #include <QApplication>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
23 #include <QFile>
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
24 #include <QFont>
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
25 #include <QFileDialog>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
26 #include <QMessageBox>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
27 #include <QStyle>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
28 #include <QTextStream>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
29
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
30 FileEditorMdiSubWindow::FileEditorMdiSubWindow (QWidget * parent):QMdiSubWindow
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
31 (parent)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
32 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
33 construct ();
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
34 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
35
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
36 FileEditorMdiSubWindow::~FileEditorMdiSubWindow ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
37 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
38 }
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
39
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
40 void
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
41 FileEditorMdiSubWindow::closeEvent(QCloseEvent *event)
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
42 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
43 // ignore close event if file is not saved and user cancels closing this window
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
44 // TODO: This does not work if the main window is closed!
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
45 if (checkFileModified ("Close File")==QMessageBox::Cancel)
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
46 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
47 event->ignore();
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
48 }
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
49 else
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
50 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
51 event->accept();
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
52 }
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
53 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
54
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
55 void
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
56 FileEditorMdiSubWindow::handleMarginClicked(int margin, int line, Qt::KeyboardModifiers state)
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
57 {
13587
eba1ee1f31bb Added Q_UNUSED.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13584
diff changeset
58 Q_UNUSED (state);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
59 if ( margin == 1 ) // marker margin
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
60 {
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
61 unsigned int mask = m_editor->markersAtLine (line);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
62 if (mask && (1 << MARKER_BOOKMARK))
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
63 m_editor->markerDelete(line,MARKER_BOOKMARK);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
64 else
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
65 m_editor->markerAdd(line,MARKER_BOOKMARK);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
66 }
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
67 }
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
68
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
69 void
13557
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
70 FileEditorMdiSubWindow::handleModificationChanged(bool modified)
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
71 {
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
72 if ( modified )
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
73 {
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
74 QString title(m_fileName);
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
75 setWindowTitle(title.prepend("* "));
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
76 }
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
77 else
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
78 setWindowTitle (m_fileName);
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
79 }
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
80
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
81 void
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
82 FileEditorMdiSubWindow::handleCopyAvailable(bool enableCopy)
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
83 {
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
84 m_copyAction->setEnabled(enableCopy);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
85 m_cutAction->setEnabled(enableCopy);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
86 }
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
87
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
88
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
89 void
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
90 FileEditorMdiSubWindow::openFile ()
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
91 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
92 if (checkFileModified ("Open File")==QMessageBox::Cancel)
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
93 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
94 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
95 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
96 QString openFileName =
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
97 QFileDialog::getOpenFileName (this, "Open File", QDir::homePath(), SAVE_FILE_FILTER);
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
98 if (openFileName.isEmpty ())
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
99 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
100 return;
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
101 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
102 else
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
103 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
104 loadFile(openFileName);
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
105 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
106 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
107
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
108 void
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
109 FileEditorMdiSubWindow::loadFile (QString fileName)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
110 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
111 QFile file (fileName);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
112 if (!file.open (QFile::ReadOnly))
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
113 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
114 QMessageBox::warning (this, tr ("File Editor"),
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
115 tr ("Cannot read file %1:\n%2.").arg (fileName).
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
116 arg (file.errorString ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
117 return;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
118 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
119
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
120 QTextStream in (&file);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
121 QApplication::setOverrideCursor (Qt::WaitCursor);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
122 m_editor->setText (in.readAll ());
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
123 QApplication::restoreOverrideCursor ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
124
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
125 m_fileName = fileName;
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
126 setWindowTitle (fileName);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
127 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
128 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
129 }
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
130
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
131 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
132 FileEditorMdiSubWindow::newFile ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
133 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
134 if (checkFileModified ("Open New File")==QMessageBox::Cancel)
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
135 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
136 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
137 }
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
138 m_fileName = UNNAMED_FILE;
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
139 setWindowTitle (m_fileName);
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
140 m_editor->setText ("");
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
141 m_editor->setModified (false); // new file is not modified yet
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
142 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
143
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
144 int
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
145 FileEditorMdiSubWindow::checkFileModified (QString msg)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
146 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
147 int decision = QMessageBox::Yes;
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
148 if (m_editor->isModified ())
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
149 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
150 // file is modified but not saved, aks user what to do
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
151 decision = QMessageBox::question (this,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
152 msg,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
153 tr ("Do you want to save the current file\n%1 ?").
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
154 arg (m_fileName),
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
155 QMessageBox::Cancel,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
156 QMessageBox::No,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
157 QMessageBox::Yes);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
158
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
159 if (decision == QMessageBox::Yes)
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
160 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
161 saveFile ();
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
162 if (m_editor->isModified ())
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
163 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
164 // 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
165 // modified, then probably something went wrong, so return cancel
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
166 // for cancel this operation
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
167 return (QMessageBox::Cancel);
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
168 }
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
169 }
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
170 }
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
171 return (decision);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
172 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
173
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
174 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
175 FileEditorMdiSubWindow::saveFile ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
176 {
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
177 saveFile(m_fileName);
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
178 }
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
179
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
180 void
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
181 FileEditorMdiSubWindow::saveFile (QString fileName)
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
182 {
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
183 // it is a new file with the name "<unnamed>" -> call saveFielAs
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
184 if (fileName==UNNAMED_FILE)
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
185 {
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
186 saveFileAs();
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
187 return;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
188 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
189
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
190 // check for a valid file name to save the contents
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
191 QString saveFileName;
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
192 if (fileName.isEmpty ())
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
193 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
194 saveFileName = QFileDialog::getSaveFileName (this, "Save File", fileName,SAVE_FILE_FILTER);
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
195 if (saveFileName.isEmpty ())
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
196 return;
13642
b7d870e9b886 Added patch from aAndriy with adding file extension when not present.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13631
diff changeset
197 if(!saveFileName.endsWith(".m"))
b7d870e9b886 Added patch from aAndriy with adding file extension when not present.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13631
diff changeset
198 saveFileName.append(".m");
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
199 }
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
200 else
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
201 {
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
202 saveFileName = fileName;
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
203 }
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
204
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
205 // open the file
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
206 QFile file (saveFileName);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
207 if (!file.open (QFile::WriteOnly))
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
208 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
209 QMessageBox::warning (this, tr ("File Editor"),
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
210 tr ("Cannot write file %1:\n%2.").
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
211 arg (saveFileName).arg (file.errorString ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
212 return;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
213 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
214
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
215 // save the contents into the file
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
216 QTextStream out (&file);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
217 QApplication::setOverrideCursor (Qt::WaitCursor);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
218 out << m_editor->text ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
219 QApplication::restoreOverrideCursor ();
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
220 m_fileName = saveFileName; // save file name for later use
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
221 setWindowTitle(m_fileName); // set the window title to actual file name
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
222 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
223 m_editor->setModified (false); // files is save -> not modified
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
224 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
225
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
226 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
227 FileEditorMdiSubWindow::saveFileAs ()
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
228 {
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
229 QString saveDir(m_fileName);
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
230 if (saveDir==UNNAMED_FILE)
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
231 saveDir = QDir::homePath();
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
232 QString saveFileName = QFileDialog::getSaveFileName(
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
233 this, "Save File As", saveDir,SAVE_FILE_FILTER);
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
234 if(saveFileName.isEmpty())
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
235 return;
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
236 saveFile(saveFileName);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
237 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
238
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
239 // handle the run command
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
240 void
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
241 FileEditorMdiSubWindow::runFile ()
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
242 {
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
243 if (m_editor->isModified ())
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
244 saveFile(m_fileName);
13648
da69cec2459f Renamed OctaveTerminal to TerminalView.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13642
diff changeset
245 m_terminalEmulation->transmitText (QString ("run \'%1\'\n").arg (m_fileName));
da69cec2459f Renamed OctaveTerminal to TerminalView.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13642
diff changeset
246 //m_terminalEmulation->setFocus ();
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
247 }
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
248
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
249 // toggle bookmark
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
250 void
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
251 FileEditorMdiSubWindow::toggleBookmark ()
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
252 {
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
253 int line,cur;
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
254 m_editor->getCursorPosition(&line,&cur);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
255 if ( m_editor->markersAtLine (line) && (1 << MARKER_BOOKMARK) )
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
256 m_editor->markerDelete(line,MARKER_BOOKMARK);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
257 else
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
258 m_editor->markerAdd(line,MARKER_BOOKMARK);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
259 }
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
260 // goto next bookmark
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
261 void
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
262 FileEditorMdiSubWindow::nextBookmark ()
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
263 {
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
264 int line,cur,nextline;
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
265 m_editor->getCursorPosition(&line,&cur);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
266 if ( m_editor->markersAtLine(line) && (1 << MARKER_BOOKMARK) )
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
267 line++; // we have a bookmark here, so start search from next line
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
268 nextline = m_editor->markerFindNext(line,(1 << MARKER_BOOKMARK));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
269 m_editor->setCursorPosition(nextline,0);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
270 }
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
271 // goto previous bookmark
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
272 void
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
273 FileEditorMdiSubWindow::prevBookmark ()
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
274 {
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
275 int line,cur,prevline;
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
276 m_editor->getCursorPosition(&line,&cur);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
277 if ( m_editor->markersAtLine(line) && (1 << MARKER_BOOKMARK) )
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
278 line--; // we have a bookmark here, so start search from prev line
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
279 prevline = m_editor->markerFindPrevious(line,(1 << MARKER_BOOKMARK));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
280 m_editor->setCursorPosition(prevline,0);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
281 }
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
282
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
283 // 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
284 void
13648
da69cec2459f Renamed OctaveTerminal to TerminalView.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13642
diff changeset
285 FileEditorMdiSubWindow::initEditor (TerminalEmulation* terminalEmulation,
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
286 LexerOctaveGui* lexer)
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
287 {
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
288 m_editor->setLexer(lexer);
13648
da69cec2459f Renamed OctaveTerminal to TerminalView.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13642
diff changeset
289 m_terminalEmulation = terminalEmulation; // for sending commands to octave
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
290 // TODO: make a global commandOctave function?
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
291 }
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
292
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
293 // TODO: Do we still need tool tips in the status bar? Tool tips are now
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
294 // shown directly at the theme icons
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
295 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
296 FileEditorMdiSubWindow::showToolTipNew ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
297 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
298 m_statusBar->showMessage ("Create a new file", 2000);
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
299 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
300
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
301 void
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
302 FileEditorMdiSubWindow::showToolTipOpen ()
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
303 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
304 m_statusBar->showMessage ("Open a file", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
305 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
306
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
307 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
308 FileEditorMdiSubWindow::showToolTipSave ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
309 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
310 m_statusBar->showMessage ("Save the file", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
311 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
312
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
313 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
314 FileEditorMdiSubWindow::showToolTipSaveAs ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
315 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
316 m_statusBar->showMessage ("Save the file as", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
317 }
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
318
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
319 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
320 FileEditorMdiSubWindow::showToolTipUndo ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
321 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
322 m_statusBar->showMessage ("Revert previous changes", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
323 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
324
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
325 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
326 FileEditorMdiSubWindow::showToolTipRedo ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
327 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
328 m_statusBar->showMessage ("Append previous changes", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
329 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
330
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
331 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
332 FileEditorMdiSubWindow::registerModified (bool modified)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
333 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
334 m_modified = modified;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
335 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
336
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
337 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
338 FileEditorMdiSubWindow::construct ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
339 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
340 QStyle *style = QApplication::style ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
341 setWidget (new QWidget ());
13566
d22b9973120f Renamed language files to match convention.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13562
diff changeset
342
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
343 m_menuBar = new QMenuBar (this);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
344 m_toolBar = new QToolBar (this);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
345 m_statusBar = new QStatusBar (this);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
346 m_editor = new QsciScintilla (this);
13503
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
347
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
348 // markers
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
349 m_editor->setMarginType (1, QsciScintilla::SymbolMargin);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
350 m_editor->setMarginSensitivity(1,true);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
351 m_editor->markerDefine(QsciScintilla::RightTriangle,MARKER_BOOKMARK);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
352 connect(m_editor,SIGNAL(marginClicked(int,int,Qt::KeyboardModifiers)),
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
353 this,SLOT(handleMarginClicked(int,int,Qt::KeyboardModifiers)));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
354
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
355 // line numbers
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
356 QFont marginFont("Monospace",9);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
357 m_editor->setMarginsFont(marginFont);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
358 QFontMetrics metrics(marginFont);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
359 m_editor->setMarginsForegroundColor(QColor(96,96,96));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
360 m_editor->setMarginsBackgroundColor(QColor(232,232,220));
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
361 m_editor->setMarginType (2, QsciScintilla::TextMargin);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
362 m_editor->setMarginWidth(2, metrics.width("99999"));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
363 m_editor->setMarginLineNumbers(2, true);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
364
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
365 // code folding
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
366 m_editor->setMarginType (3, QsciScintilla::SymbolMargin);
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
367 m_editor->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
368
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
369 m_editor->setCaretLineVisible(true);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
370 m_editor->setCaretLineBackgroundColor(QColor(255,255,200));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
371 m_editor->setBraceMatching (QsciScintilla::SloppyBraceMatch);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
372 m_editor->setAutoIndent (true);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
373 m_editor->setIndentationWidth (2);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
374 m_editor->setIndentationsUseTabs (false);
13558
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
375 m_editor->autoCompleteFromAll();
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
376 m_editor->setAutoCompletionSource(QsciScintilla::AcsAPIs);
248b897d9f36 editor: custom lexer, syntax highlighting, auto completion
ttl <ttl@justmail.de>
parents: 13557
diff changeset
377 m_editor->setAutoCompletionThreshold (3);
13631
9ad313bcee2d Possible fixed Andriys bug with russian symbols.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13587
diff changeset
378 m_editor->setUtf8 (true);
13503
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
379
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
380 // The Actions
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
381
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
382 // Theme icons with QStyle icons as fallback
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
383 QAction *closeAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
384 QIcon::fromTheme("window-close",style->standardIcon (QStyle::SP_DialogCloseButton)),
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
385 tr("&Close File"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
386 QAction *newAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
387 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
388 tr("&New File"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
389 QAction *openAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
390 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
391 tr("&Open File"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
392 QAction *saveAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
393 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
394 tr("&Save File"), m_toolBar);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
395 QAction *saveAsAction = new QAction (
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
396 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
397 tr("Save File &As"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
398 QAction *undoAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
399 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
400 tr("&Undo"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
401 QAction *redoAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
402 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
403 tr("&Redo"), m_toolBar);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
404 m_copyAction = new QAction (QIcon::fromTheme("edit-copy"),tr("&Copy"),m_toolBar);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
405 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
406 QAction *pasteAction = new QAction (QIcon::fromTheme("edit-paste"),tr("&Paste"),m_toolBar);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
407 QAction *nextBookmarkAction = new QAction (tr("&Next Bookmark"),m_toolBar);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
408 QAction *prevBookmarkAction = new QAction (tr("Pre&vious Bookmark"),m_toolBar);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
409 QAction *toggleBookmarkAction = new QAction (tr("Toggle &Bookmark"),m_toolBar);
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
410 QAction *runAction = new QAction (
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
411 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
412 tr("&Run File"), m_toolBar);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
413
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
414 // some actions are disabled from the beginning
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
415 m_copyAction->setEnabled(false);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
416 m_cutAction->setEnabled(false);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
417 connect(m_editor,SIGNAL(copyAvailable(bool)),this,SLOT(handleCopyAvailable(bool)));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
418
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
419 // short cuts
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
420 newAction->setShortcut(QKeySequence::New);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
421 openAction->setShortcut(QKeySequence::Open);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
422 saveAction->setShortcut(QKeySequence::Save);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
423 saveAsAction->setShortcut(QKeySequence::SaveAs);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
424 undoAction->setShortcut(QKeySequence::Undo);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
425 redoAction->setShortcut(QKeySequence::Redo);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
426 m_copyAction->setShortcut(QKeySequence::Copy);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
427 m_cutAction->setShortcut(QKeySequence::Cut);
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
428 pasteAction->setShortcut(QKeySequence::Paste);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
429 runAction->setShortcut(Qt::Key_F5);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
430 nextBookmarkAction->setShortcut(Qt::Key_F2);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
431 prevBookmarkAction->setShortcut(Qt::SHIFT + Qt::Key_F2);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
432 toggleBookmarkAction->setShortcut(Qt::CTRL + Qt::Key_F2);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
433
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
434 // toolbar
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
435 m_toolBar->setIconSize(QSize(16,16)); // smaller icons (make configurable in user settings?)
13550
cd66481d55b0 Added close button to file editor, assorted subwindows after importance.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13530
diff changeset
436 m_toolBar->addAction (closeAction);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
437 m_toolBar->addAction (newAction);
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
438 m_toolBar->addAction (openAction);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
439 m_toolBar->addAction (saveAction);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
440 m_toolBar->addAction (saveAsAction);
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
441 m_toolBar->addSeparator();
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
442 m_toolBar->addAction (undoAction);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
443 m_toolBar->addAction (redoAction);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
444 m_toolBar->addAction (m_copyAction);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
445 m_toolBar->addAction (m_cutAction);
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
446 m_toolBar->addAction (pasteAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
447 m_toolBar->addSeparator();
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
448 m_toolBar->addAction (runAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
449
13566
d22b9973120f Renamed language files to match convention.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13562
diff changeset
450 // menu bar
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
451 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
452 fileMenu->addAction(newAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
453 fileMenu->addAction(openAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
454 fileMenu->addAction(saveAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
455 fileMenu->addAction(saveAsAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
456 fileMenu->addSeparator();
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
457 fileMenu->addAction (closeAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
458 m_menuBar->addMenu(fileMenu);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
459 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
460 editMenu->addAction(undoAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
461 editMenu->addAction(redoAction);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
462 editMenu->addSeparator();
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
463 editMenu->addAction(m_copyAction);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
464 editMenu->addAction(m_cutAction);
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
465 editMenu->addAction(pasteAction);
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
466 editMenu->addSeparator();
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
467 editMenu->addAction(toggleBookmarkAction);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
468 editMenu->addAction(nextBookmarkAction);
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
469 editMenu->addAction(prevBookmarkAction);
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
470 m_menuBar->addMenu(editMenu);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
471 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
472 runMenu->addAction(runAction);
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
473 m_menuBar->addMenu(runMenu);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
474
13566
d22b9973120f Renamed language files to match convention.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13562
diff changeset
475
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
476 QVBoxLayout *layout = new QVBoxLayout ();
13562
a89aa9e05e19 editor: menu bar, run editor file in octave
ttl <ttl@justmail.de>
parents: 13558
diff changeset
477 layout->addWidget (m_menuBar);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
478 layout->addWidget (m_toolBar);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
479 layout->addWidget (m_editor);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
480 layout->addWidget (m_statusBar);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
481 layout->setMargin (2);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
482 widget ()->setLayout (layout);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
483
13550
cd66481d55b0 Added close button to file editor, assorted subwindows after importance.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13530
diff changeset
484 connect (closeAction, SIGNAL (triggered()), this, SLOT (close()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
485 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
486 connect (openAction, SIGNAL (triggered ()), this, SLOT (openFile ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
487 connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
488 connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ()));
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
489 connect (m_copyAction, SIGNAL (triggered ()), m_editor, SLOT (copy ()));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
490 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
491 connect (pasteAction, SIGNAL (triggered ()), m_editor, SLOT (paste ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
492 connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ()));
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
493 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
494 connect (runAction, SIGNAL (triggered ()), this, SLOT (runFile ()));
13584
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
495 connect (toggleBookmarkAction, SIGNAL (triggered ()), this, SLOT (toggleBookmark ()));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
496 connect (nextBookmarkAction, SIGNAL (triggered ()), this, SLOT (nextBookmark ()));
e76a22bfe406 editor: added bookmark feature
ttl <ttl@justmail.de>
parents: 13566
diff changeset
497 connect (prevBookmarkAction, SIGNAL (triggered ()), this, SLOT (prevBookmark ()));
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
498
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
499 // TODO: Do we still need tool tips in the status bar? Tool tips are now
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
500 // shown directly at the theme icons
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
501 connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ()));
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
502 connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
503 connect (undoAction, SIGNAL (hovered ()), this, SLOT (showToolTipUndo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
504 connect (redoAction, SIGNAL (hovered ()), this, SLOT (showToolTipRedo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
505 connect (saveAction, SIGNAL (hovered ()), this, SLOT (showToolTipSave ()));
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
506 connect (saveAsAction, SIGNAL (hovered ()), this,SLOT (showToolTipSaveAs ()));
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
507
13557
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
508 // connect modified signal
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
509 connect (m_editor, SIGNAL (modificationChanged(bool)), this, SLOT (handleModificationChanged(bool)) );
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
510
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
511 m_fileName = "";
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
512 setWindowTitle (m_fileName);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
513 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
514 show ();
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
515 }