annotate gui/src/FileEditorMdiSubWindow.cpp @ 13557:ad18a8e7fb02

editor: change window title if text is modified
author ttl <ttl@justmail.de>
date Sat, 30 Jul 2011 15:19:42 +0200
parents 0d18b0e168ae
children 248b897d9f36
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"
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
20 #include <QVBoxLayout>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
21 #include <QApplication>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
22 #include <QFile>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
23 #include <QFileDialog>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
24 #include <QMessageBox>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
25 #include <QAction>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
26 #include <QStyle>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
27 #include <QTextStream>
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
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
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
33 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
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 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
37 }
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
38
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
39 void
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
40 FileEditorMdiSubWindow::closeEvent(QCloseEvent *event)
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
41 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
42 // 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
43 // 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
44 if (checkFileModified ("Close File")==QMessageBox::Cancel)
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
45 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
46 event->ignore();
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
47 }
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
48 else
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
49 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
50 event->accept();
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
51 }
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
52 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
53
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
54 void
13557
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
55 FileEditorMdiSubWindow::handleModificationChanged(bool modified)
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
56 {
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
57 if ( modified )
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
58 {
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
59 QString title(m_fileName);
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
60 setWindowTitle(title.prepend("* "));
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
61 }
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
62 else
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
63 setWindowTitle (m_fileName);
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
64 }
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
65
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
66 void
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
67 FileEditorMdiSubWindow::openFile ()
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
68 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
69 if (checkFileModified ("Open File")==QMessageBox::Cancel)
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
70 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
71 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
72 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
73 QString openFileName =
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
74 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
75 if (openFileName.isEmpty ())
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
76 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
77 return;
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
78 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
79 else
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
80 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
81 loadFile(openFileName);
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
82 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
83 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
84
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
85 void
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
86 FileEditorMdiSubWindow::loadFile (QString fileName)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
87 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
88 QFile file (fileName);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
89 if (!file.open (QFile::ReadOnly))
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 QMessageBox::warning (this, tr ("File Editor"),
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
92 tr ("Cannot read file %1:\n%2.").arg (fileName).
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
93 arg (file.errorString ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
94 return;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
95 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
96
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
97 QTextStream in (&file);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
98 QApplication::setOverrideCursor (Qt::WaitCursor);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
99 m_editor->setText (in.readAll ());
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
100 QApplication::restoreOverrideCursor ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
101
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
102 m_fileName = fileName;
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
103 setWindowTitle (fileName);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
104 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
105 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
106 }
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
107
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
108 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
109 FileEditorMdiSubWindow::newFile ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
110 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
111 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
112 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
113 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
114 }
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
115 m_fileName = UNNAMED_FILE;
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
116 setWindowTitle (m_fileName);
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
117 m_editor->setText ("");
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
118 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
119 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
120
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
121 int
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
122 FileEditorMdiSubWindow::checkFileModified (QString msg)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
123 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
124 int decision = QMessageBox::Yes;
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
125 if (m_editor->isModified ())
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
126 {
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
127 // 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
128 decision = QMessageBox::question (this,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
129 msg,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
130 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
131 arg (m_fileName),
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
132 QMessageBox::Cancel,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
133 QMessageBox::No,
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
134 QMessageBox::Yes);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
135
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
136 if (decision == QMessageBox::Yes)
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
137 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
138 saveFile ();
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
139 if (m_editor->isModified ())
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
140 {
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
141 // 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
142 // 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
143 // for cancel this operation
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
144 return (QMessageBox::Cancel);
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
145 }
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
146 }
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
147 }
13524
8c143d6d0330 gui-editor: improved behaviour when closing a modified file
ttl (Torsten) <ttl@justmail.de>
parents: 13506
diff changeset
148 return (decision);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
149 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
150
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
151 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
152 FileEditorMdiSubWindow::saveFile ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
153 {
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
154 saveFile(m_fileName);
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
155 }
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
156
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
157 void
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
158 FileEditorMdiSubWindow::saveFile (QString fileName)
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
159 {
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
160 // 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
161 if (fileName==UNNAMED_FILE)
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
162 {
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
163 saveFileAs();
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
164 return;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
165 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
166
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
167 // 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
168 QString saveFileName;
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
169 if (fileName.isEmpty ())
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
170 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
171 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
172 if (saveFileName.isEmpty ())
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
173 return;
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
174 }
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
175 else
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
176 {
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
177 saveFileName = 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 // open the file
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
181 QFile file (saveFileName);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
182 if (!file.open (QFile::WriteOnly))
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
183 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
184 QMessageBox::warning (this, tr ("File Editor"),
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
185 tr ("Cannot write file %1:\n%2.").
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
186 arg (saveFileName).arg (file.errorString ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
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 // save the contents into the file
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
191 QTextStream out (&file);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
192 QApplication::setOverrideCursor (Qt::WaitCursor);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
193 out << m_editor->text ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
194 QApplication::restoreOverrideCursor ();
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
195 m_fileName = saveFileName; // save file name for later use
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
196 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
197 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
198 m_editor->setModified (false); // files is save -> not modified
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
199 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
200
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
201 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
202 FileEditorMdiSubWindow::saveFileAs ()
13529
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 QString saveDir(m_fileName);
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
205 if (saveDir==UNNAMED_FILE)
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
206 saveDir = QDir::homePath();
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
207 QString saveFileName = QFileDialog::getSaveFileName(
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
208 this, "Save File As", saveDir,SAVE_FILE_FILTER);
13529
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
209 if(saveFileName.isEmpty())
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
210 return;
8e87f3ba3beb gui-editor: enabled 'Save File As'
ttl <ttl@justmail.de>
parents: 13524
diff changeset
211 saveFile(saveFileName);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
212 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
213
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
214 // 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
215 // shown directly at the theme icons
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
216 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
217 FileEditorMdiSubWindow::showToolTipNew ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
218 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
219 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
220 }
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
221
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
222 void
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
223 FileEditorMdiSubWindow::showToolTipOpen ()
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
224 {
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
225 m_statusBar->showMessage ("Open a file", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
226 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
227
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
228 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
229 FileEditorMdiSubWindow::showToolTipSave ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
230 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
231 m_statusBar->showMessage ("Save the file", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
232 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
233
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
234 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
235 FileEditorMdiSubWindow::showToolTipSaveAs ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
236 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
237 m_statusBar->showMessage ("Save the file as", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
238 }
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
239
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
240 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
241 FileEditorMdiSubWindow::showToolTipUndo ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
242 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
243 m_statusBar->showMessage ("Revert previous changes", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
244 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
245
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
246 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
247 FileEditorMdiSubWindow::showToolTipRedo ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
248 {
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
249 m_statusBar->showMessage ("Append previous changes", 2000);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
250 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
251
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
252 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
253 FileEditorMdiSubWindow::registerModified (bool modified)
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
254 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
255 m_modified = modified;
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
256 }
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
257
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
258 void
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
259 FileEditorMdiSubWindow::construct ()
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
260 {
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
261 QStyle *style = QApplication::style ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
262 setWidget (new QWidget ());
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
263 m_toolBar = new QToolBar (this);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
264 m_statusBar = new QStatusBar (this);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
265 m_editor = new QsciScintilla (this);
13503
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
266
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
267 // Not available in the Debian repos yet!
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
268 /*
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
269 m_lexer = new QsciLexerOctave(m_editor);
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
270 m_lexer->setDefaultFont(QFont("Monospace",9));
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
271 m_lexer->setAutoIndentStyle(QsciScintilla::AiMaintain ||
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
272 QsciScintilla::AiOpening ||
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
273 QsciScintilla::AiClosing);
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
274 m_editor->setLexer(m_lexer);
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
275 */
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
276
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
277 m_editor->setMarginType (1, QsciScintilla::TextMargin);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
278 m_editor->setMarginType (2, QsciScintilla::SymbolMargin);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
279 m_editor->setFolding (QsciScintilla::BoxedTreeFoldStyle, 2);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
280 m_editor->setMarginLineNumbers (1, true);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
281 m_editor->setMarginWidth (1, "99999");
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
282
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
283 m_editor->setBraceMatching (QsciScintilla::SloppyBraceMatch);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
284 m_editor->setAutoIndent (true);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
285 m_editor->setIndentationWidth (2);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
286 m_editor->setIndentationsUseTabs (false);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
287 m_editor->setAutoCompletionThreshold (2);
13503
5ab40ef3d241 Merged diff from Torsten.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13501
diff changeset
288
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
289 // Theme icons with QStyle icons as fallback
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
290 m_toolBar->setIconSize(QSize(20,20)); // smaller icons (make configurable in user settings?)
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
291 QAction *closeAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
292 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
293 tr("&Close File"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
294 QAction *newAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
295 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
296 tr("&New File"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
297 QAction *openAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
298 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
299 tr("&Open File"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
300 QAction *saveAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
301 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
302 tr("&Save File"), m_toolBar);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
303 QAction *saveAsAction = new QAction (
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
304 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
305 tr("Save File &As"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
306 QAction *undoAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
307 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
308 tr("&Undo"), m_toolBar);
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
309 QAction *redoAction = new QAction (
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
310 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
311 tr("&Redo"), m_toolBar);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
312
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
313 // short cuts
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
314 closeAction->setShortcut(QKeySequence::Close);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
315 newAction->setShortcut(QKeySequence::New);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
316 openAction->setShortcut(QKeySequence::Open);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
317 saveAction->setShortcut(QKeySequence::Save);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
318 saveAsAction->setShortcut(QKeySequence::SaveAs);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
319 undoAction->setShortcut(QKeySequence::Undo);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
320 redoAction->setShortcut(QKeySequence::Redo);
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
321
13550
cd66481d55b0 Added close button to file editor, assorted subwindows after importance.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13530
diff changeset
322 m_toolBar->addAction (closeAction);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
323 m_toolBar->addAction (newAction);
13530
8c7390b78911 gui-editor: open new editor window via interface menu
ttl <ttl@justmail.de>
parents: 13529
diff changeset
324 m_toolBar->addAction (openAction);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
325 m_toolBar->addAction (saveAction);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
326 m_toolBar->addAction (saveAsAction);
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
327 m_toolBar->addAction (undoAction);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
328 m_toolBar->addAction (redoAction);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
329
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
330 QVBoxLayout *layout = new QVBoxLayout ();
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
331 layout->addWidget (m_toolBar);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
332 layout->addWidget (m_editor);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
333 layout->addWidget (m_statusBar);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
334 layout->setMargin (2);
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
335 widget ()->setLayout (layout);
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
336
13550
cd66481d55b0 Added close button to file editor, assorted subwindows after importance.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13530
diff changeset
337 connect (closeAction, SIGNAL (triggered()), this, SLOT (close()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
338 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
339 connect (openAction, SIGNAL (triggered ()), this, SLOT (openFile ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
340 connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
341 connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
342 connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ()));
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
343 connect (saveAsAction, SIGNAL (triggered ()), this, SLOT (saveFileAs ()));
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
344
13555
be425f45f9e3 editor: toolbar icons from current icon theme
ttl <ttl@justmail.de>
parents: 13550
diff changeset
345 // 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
346 // shown directly at the theme icons
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
347 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
348 connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ()));
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
349 connect (undoAction, SIGNAL (hovered ()), this, SLOT (showToolTipUndo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
350 connect (redoAction, SIGNAL (hovered ()), this, SLOT (showToolTipRedo ()));
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
351 connect (saveAction, SIGNAL (hovered ()), this, SLOT (showToolTipSave ()));
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
352 connect (saveAsAction, SIGNAL (hovered ()), this,SLOT (showToolTipSaveAs ()));
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
353
13557
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
354 // connect modified signal
ad18a8e7fb02 editor: change window title if text is modified
ttl <ttl@justmail.de>
parents: 13556
diff changeset
355 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
356
13506
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
357 m_fileName = "";
c70511cf64ee Reformatted to GNU Style.
Jacob Dawid <jacob.dawid@googlemail.com>
parents: 13504
diff changeset
358 setWindowTitle (m_fileName);
13556
0d18b0e168ae editor: shortcuts for toolbar actions, window icon
ttl <ttl@justmail.de>
parents: 13555
diff changeset
359 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
360 show ();
13501
86d6c3b90ad7 Added new gui files.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
361 }