Mercurial > hg > octave-lyh
annotate gui/src/editor/FileEditorTab.cpp @ 14680:628eeaf879f7 gui
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
* FileEditor: Removed status bar and added slot to handle changes in tabs.
* FileEditorTab: Removed margen and added signal when copying is possible.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 24 May 2012 12:08:53 +0200 |
parents | 35512b788af2 |
children | ca733a66be7a |
rev | line source |
---|---|
14676
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
1 /* OctaveGUI - A graphical user interface for Octave |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
2 * Copyright (C) 2011 Jacob Dawid (jacob.dawid@googlemail.com) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
3 * |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
4 * This program is free software: you can redistribute it and/or modify |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
6 * published by the Free Software Foundation, either version 3 of the |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
7 * License, or (at your option) any later version. |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
8 * |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful, |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
12 * GNU General Public License for more details. |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
13 * |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
16 */ |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
17 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
18 #include "FileEditorTab.h" |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
19 #include "FileEditor.h" |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
20 #include <QMessageBox> |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
21 #include <QVBoxLayout> |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
22 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
23 FileEditorTab::FileEditorTab(FileEditor *fileEditor) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
24 : QWidget ((QWidget*)fileEditor) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
25 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
26 QSettings *settings = ResourceManager::instance ()->settings (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
27 m_fileEditor = fileEditor; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
28 m_fileName = ""; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
29 m_editArea = new QsciScintilla (this); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
30 m_editArea->setLexer (fileEditor->lexer ()); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
31 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
32 // markers |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
33 m_editArea->setMarginType (1, QsciScintilla::SymbolMargin); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
34 m_editArea->setMarginSensitivity (1, true); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
35 m_editArea->markerDefine (QsciScintilla::RightTriangle, MARKER_BOOKMARK); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
36 connect (m_editArea, SIGNAL (marginClicked (int, int, Qt::KeyboardModifiers)), |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
37 this, SLOT (handleMarginClicked (int, int, Qt::KeyboardModifiers))); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
38 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
39 // line numbers |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
40 m_editArea->setMarginsForegroundColor(QColor(96,96,96)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
41 m_editArea->setMarginsBackgroundColor(QColor(232,232,220)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
42 if (settings->value ("editor/showLineNumbers",true).toBool ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
43 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
44 QFont marginFont( settings->value ("editor/fontName","Courier").toString () , |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
45 settings->value ("editor/fontSize",10).toInt () ); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
46 m_editArea->setMarginsFont( marginFont ); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
47 QFontMetrics metrics(marginFont); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
48 m_editArea->setMarginType (2, QsciScintilla::TextMargin); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
49 m_editArea->setMarginWidth(2, metrics.width("99999")); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
50 m_editArea->setMarginLineNumbers(2, true); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
51 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
52 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
53 // code folding |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
54 m_editArea->setMarginType (3, QsciScintilla::SymbolMargin); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
55 m_editArea->setFolding (QsciScintilla::BoxedTreeFoldStyle , 3); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
56 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
57 // other features |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
58 if (settings->value ("editor/highlightCurrentLine",true).toBool ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
59 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
60 m_editArea->setCaretLineVisible(true); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
61 m_editArea->setCaretLineBackgroundColor(QColor(245,245,245)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
62 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
63 m_editArea->setBraceMatching (QsciScintilla::StrictBraceMatch); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
64 m_editArea->setAutoIndent (true); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
65 m_editArea->setIndentationWidth (2); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
66 m_editArea->setIndentationsUseTabs (false); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
67 if (settings->value ("editor/codeCompletion",true).toBool ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
68 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
69 m_editArea->autoCompleteFromAll (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
70 m_editArea->setAutoCompletionSource(QsciScintilla::AcsAll); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
71 m_editArea->setAutoCompletionThreshold (1); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
72 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
73 m_editArea->setUtf8 (true); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
74 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
75 QVBoxLayout *layout = new QVBoxLayout (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
76 layout->addWidget (m_editArea); |
14680
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
77 layout->setMargin (0); |
14676
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
78 setLayout (layout); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
79 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
80 // connect modified signal |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
81 connect (m_editArea, SIGNAL (modificationChanged (bool)), |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
82 this, SLOT (newTitle (bool))); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
83 connect (m_editArea, SIGNAL (copyAvailable (bool)), |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
84 this, SLOT (handleCopyAvailable (bool))); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
85 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
86 m_fileName = ""; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
87 newTitle (false); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
88 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
89 |
14680
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
90 bool |
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
91 FileEditorTab::copyAvailable () |
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
92 { |
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
93 return m_copyAvailable; |
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
94 } |
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
95 |
14676
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
96 void |
14680
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
97 FileEditorTab::closeEvent (QCloseEvent *event) |
14676
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
98 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
99 if (m_fileEditor->mainWindow ()->closing ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
100 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
101 // close whole application: save file or not if modified |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
102 checkFileModified ("Closing Octave", 0); // no cancel possible |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
103 event->accept (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
104 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
105 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
106 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
107 // ignore close event if file is not saved and user cancels closing this window |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
108 if (checkFileModified ("Close File",QMessageBox::Cancel) == QMessageBox::Cancel) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
109 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
110 event->ignore (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
111 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
112 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
113 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
114 event->accept(); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
115 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
116 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
117 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
118 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
119 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
120 FileEditorTab::handleMarginClicked(int margin, int line, Qt::KeyboardModifiers state) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
121 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
122 Q_UNUSED (state); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
123 if (margin == 1) // marker margin |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
124 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
125 unsigned int mask = m_editArea->markersAtLine (line); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
126 if (mask && (1 << MARKER_BOOKMARK)) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
127 m_editArea->markerDelete(line,MARKER_BOOKMARK); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
128 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
129 m_editArea->markerAdd(line,MARKER_BOOKMARK); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
130 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
131 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
132 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
133 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
134 FileEditorTab::commentSelectedText () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
135 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
136 doCommentSelectedText (true); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
137 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
138 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
139 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
140 FileEditorTab::uncommentSelectedText () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
141 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
142 doCommentSelectedText (false); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
143 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
144 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
145 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
146 FileEditorTab::doCommentSelectedText (bool comment) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
147 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
148 if ( m_editArea->hasSelectedText() ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
149 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
150 int lineFrom, lineTo, colFrom, colTo, i; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
151 m_editArea->getSelection (&lineFrom,&colFrom,&lineTo,&colTo); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
152 if ( colTo == 0 ) // the beginning of last line is not selected |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
153 lineTo--; // stop at line above |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
154 m_editArea->beginUndoAction (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
155 for ( i=lineFrom; i<=lineTo; i++ ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
156 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
157 if ( comment ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
158 m_editArea->insertAt("%",i,0); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
159 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
160 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
161 QString line(m_editArea->text(i)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
162 if ( line.startsWith("%") ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
163 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
164 m_editArea->setSelection(i,0,i,1); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
165 m_editArea->removeSelectedText(); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
166 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
167 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
168 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
169 m_editArea->endUndoAction (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
170 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
171 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
172 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
173 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
174 FileEditorTab::newTitle(bool modified) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
175 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
176 QString title(m_fileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
177 if ( !m_longTitle ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
178 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
179 QFileInfo file(m_fileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
180 title = file.fileName(); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
181 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
182 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
183 if ( modified ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
184 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
185 emit fileNameChanged (title.prepend("* ")); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
186 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
187 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
188 emit fileNameChanged (title); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
189 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
190 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
191 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
192 FileEditorTab::handleCopyAvailable(bool enableCopy) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
193 { |
14680
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
194 m_copyAvailable = enableCopy; |
628eeaf879f7
Copy/Paste buttons get greyed out in the editor correctly again. Removed margin in editor tabs and status bar.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
14676
diff
changeset
|
195 emit editorStateChanged (); |
14676
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
196 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
197 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
198 int |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
199 FileEditorTab::checkFileModified (QString msg, int cancelButton) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
200 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
201 int decision = QMessageBox::Yes; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
202 if (m_editArea->isModified ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
203 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
204 // file is modified but not saved, aks user what to do |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
205 decision = QMessageBox::warning (this, |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
206 msg, |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
207 tr ("The file %1\n" |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
208 "has been modified. Do you want to save the changes?"). |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
209 arg (m_fileName), |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
210 QMessageBox::Save, QMessageBox::Discard, cancelButton ); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
211 if (decision == QMessageBox::Save) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
212 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
213 saveFile (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
214 if (m_editArea->isModified ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
215 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
216 // If the user attempted to save the file, but it's still |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
217 // modified, then probably something went wrong, so return cancel |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
218 // for cancel this operation or try to save files as if cancel not |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
219 // possible |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
220 if ( cancelButton ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
221 return (QMessageBox::Cancel); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
222 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
223 saveFileAs (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
224 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
225 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
226 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
227 return (decision); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
228 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
229 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
230 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
231 FileEditorTab::removeBookmark () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
232 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
233 m_editArea->markerDeleteAll(MARKER_BOOKMARK); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
234 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
235 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
236 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
237 FileEditorTab::toggleBookmark () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
238 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
239 int line,cur; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
240 m_editArea->getCursorPosition(&line,&cur); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
241 if ( m_editArea->markersAtLine (line) && (1 << MARKER_BOOKMARK) ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
242 m_editArea->markerDelete(line,MARKER_BOOKMARK); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
243 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
244 m_editArea->markerAdd(line,MARKER_BOOKMARK); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
245 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
246 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
247 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
248 FileEditorTab::nextBookmark () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
249 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
250 int line,cur,nextline; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
251 m_editArea->getCursorPosition(&line,&cur); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
252 if ( m_editArea->markersAtLine(line) && (1 << MARKER_BOOKMARK) ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
253 line++; // we have a bookmark here, so start search from next line |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
254 nextline = m_editArea->markerFindNext(line,(1 << MARKER_BOOKMARK)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
255 m_editArea->setCursorPosition(nextline,0); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
256 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
257 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
258 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
259 FileEditorTab::previousBookmark () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
260 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
261 int line,cur,prevline; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
262 m_editArea->getCursorPosition(&line,&cur); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
263 if ( m_editArea->markersAtLine(line) && (1 << MARKER_BOOKMARK) ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
264 line--; // we have a bookmark here, so start search from prev line |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
265 prevline = m_editArea->markerFindPrevious(line,(1 << MARKER_BOOKMARK)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
266 m_editArea->setCursorPosition(prevline,0); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
267 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
268 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
269 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
270 FileEditorTab::cut () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
271 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
272 m_editArea->cut (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
273 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
274 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
275 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
276 FileEditorTab::copy () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
277 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
278 m_editArea->copy (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
279 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
280 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
281 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
282 FileEditorTab::paste () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
283 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
284 m_editArea->paste (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
285 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
286 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
287 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
288 FileEditorTab::undo () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
289 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
290 m_editArea->undo (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
291 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
292 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
293 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
294 FileEditorTab::redo () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
295 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
296 m_editArea->redo (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
297 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
298 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
299 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
300 FileEditorTab::setModified (bool modified) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
301 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
302 m_modified = modified; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
303 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
304 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
305 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
306 FileEditorTab::openFile () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
307 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
308 QString openFileName; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
309 QFileDialog fileDialog(this); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
310 fileDialog.setNameFilter(SAVE_FILE_FILTER); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
311 fileDialog.setAcceptMode(QFileDialog::AcceptOpen); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
312 fileDialog.setViewMode(QFileDialog::Detail); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
313 if ( fileDialog.exec() ) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
314 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
315 openFileName = fileDialog.selectedFiles().at(0); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
316 if (openFileName.isEmpty ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
317 return; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
318 loadFile(openFileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
319 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
320 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
321 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
322 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
323 FileEditorTab::loadFile (QString fileName) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
324 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
325 QFile file (fileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
326 if (!file.open (QFile::ReadOnly)) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
327 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
328 QMessageBox::warning (this, tr ("Octave Editor"), |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
329 tr ("Could not open file %1 for read:\n%2.").arg (fileName). |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
330 arg (file.errorString ())); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
331 return; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
332 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
333 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
334 QTextStream in (&file); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
335 QApplication::setOverrideCursor (Qt::WaitCursor); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
336 m_editArea->setText (in.readAll ()); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
337 QApplication::restoreOverrideCursor (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
338 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
339 m_fileName = fileName; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
340 newTitle (false); // window title (no modification) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
341 //m_statusBar->showMessage (tr ("File loaded."), 2000); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
342 m_editArea->setModified (false); // loaded file is not modified yet |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
343 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
344 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
345 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
346 FileEditorTab::newFile () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
347 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
348 m_fileName = UNNAMED_FILE; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
349 newTitle (false); // window title (no modification) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
350 m_editArea->setText (""); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
351 m_editArea->setModified (false); // new file is not modified yet |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
352 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
353 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
354 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
355 FileEditorTab::saveFile () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
356 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
357 saveFile (m_fileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
358 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
359 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
360 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
361 FileEditorTab::saveFile (QString saveFileName) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
362 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
363 // it is a new file with the name "<unnamed>" -> call saveFielAs |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
364 if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
365 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
366 saveFileAs(); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
367 return; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
368 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
369 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
370 // open the file for writing |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
371 QFile file (saveFileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
372 if (!file.open (QFile::WriteOnly)) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
373 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
374 QMessageBox::warning (this, tr ("Octave Editor"), |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
375 tr ("Could not open file %1 for write:\n%2."). |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
376 arg (saveFileName).arg (file.errorString ())); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
377 return; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
378 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
379 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
380 // save the contents into the file |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
381 QTextStream out (&file); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
382 QApplication::setOverrideCursor (Qt::WaitCursor); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
383 out << m_editArea->text (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
384 QApplication::restoreOverrideCursor (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
385 m_fileName = saveFileName; // save file name for later use |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
386 newTitle (false); // set the window title to actual file name (not modified) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
387 //m_statusBar->showMessage (tr ("File %1 saved").arg(m_fileName), 2000); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
388 m_editArea->setModified (false); // files is save -> not modified |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
389 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
390 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
391 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
392 FileEditorTab::saveFileAs () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
393 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
394 QString saveFileName(m_fileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
395 QFileDialog fileDialog(this); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
396 if (saveFileName == UNNAMED_FILE || saveFileName.isEmpty ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
397 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
398 saveFileName = QDir::homePath (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
399 fileDialog.setDirectory (saveFileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
400 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
401 else |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
402 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
403 fileDialog.selectFile (saveFileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
404 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
405 fileDialog.setNameFilter (SAVE_FILE_FILTER); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
406 fileDialog.setDefaultSuffix ("m"); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
407 fileDialog.setAcceptMode (QFileDialog::AcceptSave); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
408 fileDialog.setViewMode (QFileDialog::Detail); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
409 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
410 if (fileDialog.exec ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
411 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
412 saveFileName = fileDialog.selectedFiles ().at (0); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
413 if (saveFileName.isEmpty ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
414 return; |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
415 saveFile (saveFileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
416 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
417 } |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
418 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
419 void |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
420 FileEditorTab::runFile () |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
421 { |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
422 if (m_editArea->isModified ()) |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
423 saveFile(m_fileName); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
424 |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
425 m_fileEditor->terminal ()->sendText (QString ("run \'%1\'\n").arg (m_fileName)); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
426 m_fileEditor->terminal ()->setFocus (); |
35512b788af2
Editor can now handle multiple files in tabs.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
427 } |