author | llornkcor <llornkcor> | 2003-02-28 18:13:41 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-28 18:13:41 (UTC) |
commit | 64423f1852a13178f23365f2bba995ef2c355b3b (patch) (unidiff) | |
tree | 074d12cbd3b762fbcd0eac686c5b7fab3617453d | |
parent | d4db61dbd748040bed740e08a839e01b86af2c87 (diff) | |
download | opie-64423f1852a13178f23365f2bba995ef2c355b3b.zip opie-64423f1852a13178f23365f2bba995ef2c355b3b.tar.gz opie-64423f1852a13178f23365f2bba995ef2c355b3b.tar.bz2 |
no goto for 0 length texts
-rw-r--r-- | core/apps/textedit/textedit.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 797c61b..5edf102 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -1,1203 +1,1205 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | // textedit.cpp | 2 | // textedit.cpp |
3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 3 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
4 | ** | 4 | ** |
5 | ** This file is part of Opie Environment. | 5 | ** This file is part of Opie Environment. |
6 | ** | 6 | ** |
7 | ** This file may be distributed and/or modified under the terms of the | 7 | ** This file may be distributed and/or modified under the terms of the |
8 | ** GNU General Public License version 2 as published by the Free Software | 8 | ** GNU General Public License version 2 as published by the Free Software |
9 | ** Foundation and appearing in the file LICENSE.GPL included in the | 9 | ** Foundation and appearing in the file LICENSE.GPL included in the |
10 | ** packaging of this file. | 10 | ** packaging of this file. |
11 | ** | 11 | ** |
12 | **********************************************************************/ | 12 | **********************************************************************/ |
13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 | 13 | // changes added by L. J. Potter Sun 02-17-2002 21:31:31 |
14 | #include "textedit.h" | 14 | #include "textedit.h" |
15 | #include "filePermissions.h" | 15 | #include "filePermissions.h" |
16 | 16 | ||
17 | 17 | ||
18 | #include <opie/ofileselector.h> | 18 | #include <opie/ofileselector.h> |
19 | #include <opie/ofiledialog.h> | 19 | #include <opie/ofiledialog.h> |
20 | #include <opie/ofontselector.h> | 20 | #include <opie/ofontselector.h> |
21 | 21 | ||
22 | #include <qpe/fontdatabase.h> | 22 | #include <qpe/fontdatabase.h> |
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | #include <qpe/fileselector.h> | 24 | #include <qpe/fileselector.h> |
25 | #include <qpe/applnk.h> | 25 | #include <qpe/applnk.h> |
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | #include <qpe/qpeapplication.h> | 28 | #include <qpe/qpeapplication.h> |
29 | #include <qpe/qpemenubar.h> | 29 | #include <qpe/qpemenubar.h> |
30 | #include <qpe/qpetoolbar.h> | 30 | #include <qpe/qpetoolbar.h> |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | 32 | ||
33 | #include <qpoint.h> | 33 | #include <qpoint.h> |
34 | #include <qtextstream.h> | 34 | #include <qtextstream.h> |
35 | #include <qdatetime.h> | 35 | #include <qdatetime.h> |
36 | #include <qclipboard.h> | 36 | #include <qclipboard.h> |
37 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
38 | #include <qaction.h> | 38 | #include <qaction.h> |
39 | #include <qcolordialog.h> | 39 | #include <qcolordialog.h> |
40 | #include <qfileinfo.h> | 40 | #include <qfileinfo.h> |
41 | #include <qlineedit.h> | 41 | #include <qlineedit.h> |
42 | #include <qmessagebox.h> | 42 | #include <qmessagebox.h> |
43 | #include <qobjectlist.h> | 43 | #include <qobjectlist.h> |
44 | #include <qpopupmenu.h> | 44 | #include <qpopupmenu.h> |
45 | #include <qspinbox.h> | 45 | #include <qspinbox.h> |
46 | #include <qtoolbutton.h> | 46 | #include <qtoolbutton.h> |
47 | #include <qwidgetstack.h> | 47 | #include <qwidgetstack.h> |
48 | #include <qcheckbox.h> | 48 | #include <qcheckbox.h> |
49 | #include <qcombo.h> | 49 | #include <qcombo.h> |
50 | #include <qlayout.h> | 50 | #include <qlayout.h> |
51 | #include <qapplication.h> | 51 | #include <qapplication.h> |
52 | #include <qtimer.h> | 52 | #include <qtimer.h> |
53 | #include <qdir.h> | 53 | #include <qdir.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <sys/stat.h> | 55 | #include <sys/stat.h> |
56 | #include <stdlib.h> //getenv | 56 | #include <stdlib.h> //getenv |
57 | 57 | ||
58 | #include "resource.h" | 58 | #include "resource.h" |
59 | 59 | ||
60 | #if QT_VERSION < 300 | 60 | #if QT_VERSION < 300 |
61 | 61 | ||
62 | class QpeEditor : public QMultiLineEdit | 62 | class QpeEditor : public QMultiLineEdit |
63 | { | 63 | { |
64 | 64 | ||
65 | public: | 65 | public: |
66 | QpeEditor( QWidget *parent, const char * name = 0 ) | 66 | QpeEditor( QWidget *parent, const char * name = 0 ) |
67 | : QMultiLineEdit( parent, name ) { | 67 | : QMultiLineEdit( parent, name ) { |
68 | clearTableFlags(); | 68 | clearTableFlags(); |
69 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 69 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
70 | } | 70 | } |
71 | 71 | ||
72 | void find( const QString &txt, bool caseSensitive, | 72 | void find( const QString &txt, bool caseSensitive, |
73 | bool backwards ); | 73 | bool backwards ); |
74 | protected: | 74 | protected: |
75 | bool markIt; | 75 | bool markIt; |
76 | int line1, line2, col1, col2; | 76 | int line1, line2, col1, col2; |
77 | void mousePressEvent( QMouseEvent * ); | 77 | void mousePressEvent( QMouseEvent * ); |
78 | void mouseReleaseEvent( QMouseEvent * ); | 78 | void mouseReleaseEvent( QMouseEvent * ); |
79 | 79 | ||
80 | //public slots: | 80 | //public slots: |
81 | /* | 81 | /* |
82 | signals: | 82 | signals: |
83 | void notFound(); | 83 | void notFound(); |
84 | void searchWrapped(); | 84 | void searchWrapped(); |
85 | */ | 85 | */ |
86 | 86 | ||
87 | private: | 87 | private: |
88 | 88 | ||
89 | }; | 89 | }; |
90 | 90 | ||
91 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { | 91 | void QpeEditor::mousePressEvent( QMouseEvent *e ) { |
92 | switch(e->button()) { | 92 | switch(e->button()) { |
93 | case RightButton: | 93 | case RightButton: |
94 | { //rediculous workaround for qt popup menu | 94 | { //rediculous workaround for qt popup menu |
95 | //and the hold right click mechanism | 95 | //and the hold right click mechanism |
96 | this->setSelection( line1, col1, line2, col2); | 96 | this->setSelection( line1, col1, line2, col2); |
97 | QMultiLineEdit::mousePressEvent( e ); | 97 | QMultiLineEdit::mousePressEvent( e ); |
98 | markIt = false; | 98 | markIt = false; |
99 | } | 99 | } |
100 | break; | 100 | break; |
101 | default: | 101 | default: |
102 | { | 102 | { |
103 | if(!markIt) { | 103 | if(!markIt) { |
104 | int line, col; | 104 | int line, col; |
105 | this->getCursorPosition(&line, &col); | 105 | this->getCursorPosition(&line, &col); |
106 | line1=line2=line; | 106 | line1=line2=line; |
107 | col1=col2=col; | 107 | col1=col2=col; |
108 | } | 108 | } |
109 | QMultiLineEdit::mousePressEvent( e ); | 109 | QMultiLineEdit::mousePressEvent( e ); |
110 | } | 110 | } |
111 | break; | 111 | break; |
112 | }; | 112 | }; |
113 | } | 113 | } |
114 | 114 | ||
115 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { | 115 | void QpeEditor::mouseReleaseEvent( QMouseEvent * ) { |
116 | if(this->hasMarkedText()) { | 116 | if(this->hasMarkedText()) { |
117 | markIt = true; | 117 | markIt = true; |
118 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); | 118 | this->getMarkedRegion( &line1, &col1, &line2, & col2 ); |
119 | } else { | 119 | } else { |
120 | markIt = false; | 120 | markIt = false; |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
124 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 124 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
125 | bool backwards ) | 125 | bool backwards ) |
126 | { | 126 | { |
127 | static bool wrap = false; | 127 | static bool wrap = false; |
128 | int line, col; | 128 | int line, col; |
129 | if ( wrap ) { | 129 | if ( wrap ) { |
130 | if ( !backwards ) | 130 | if ( !backwards ) |
131 | line = col = 0; | 131 | line = col = 0; |
132 | wrap = false; | 132 | wrap = false; |
133 | // emit searchWrapped(); | 133 | // emit searchWrapped(); |
134 | } else { | 134 | } else { |
135 | getCursorPosition( &line, &col ); | 135 | getCursorPosition( &line, &col ); |
136 | } | 136 | } |
137 | //ignore backwards for now.... | 137 | //ignore backwards for now.... |
138 | if ( !backwards ) { | 138 | if ( !backwards ) { |
139 | for ( ; ; ) { | 139 | for ( ; ; ) { |
140 | if ( line >= numLines() ) { | 140 | if ( line >= numLines() ) { |
141 | wrap = true; | 141 | wrap = true; |
142 | //emit notFound(); | 142 | //emit notFound(); |
143 | break; | 143 | break; |
144 | } | 144 | } |
145 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 145 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
146 | if ( findCol >= 0 ) { | 146 | if ( findCol >= 0 ) { |
147 | setCursorPosition( line, findCol, false ); | 147 | setCursorPosition( line, findCol, false ); |
148 | col = findCol + txt.length(); | 148 | col = findCol + txt.length(); |
149 | setCursorPosition( line, col, true ); | 149 | setCursorPosition( line, col, true ); |
150 | 150 | ||
151 | //found = true; | 151 | //found = true; |
152 | break; | 152 | break; |
153 | } | 153 | } |
154 | line++; | 154 | line++; |
155 | col = 0; | 155 | col = 0; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | #else | 161 | #else |
162 | 162 | ||
163 | #error "Must make a QpeEditor that inherits QTextEdit" | 163 | #error "Must make a QpeEditor that inherits QTextEdit" |
164 | 164 | ||
165 | #endif | 165 | #endif |
166 | 166 | ||
167 | 167 | ||
168 | static const int nfontsizes = 6; | 168 | static const int nfontsizes = 6; |
169 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 169 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
170 | 170 | ||
171 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 171 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
172 | : QMainWindow( parent, name, f ), bFromDocView( false ) | 172 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
173 | { | 173 | { |
174 | doc = 0; | 174 | doc = 0; |
175 | edited=false; | 175 | edited=false; |
176 | fromSetDocument=false; | 176 | fromSetDocument=false; |
177 | 177 | ||
178 | setToolBarsMovable( false ); | 178 | setToolBarsMovable( false ); |
179 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 179 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
180 | 180 | ||
181 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 181 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
182 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 182 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
183 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 183 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
184 | 184 | ||
185 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 185 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
186 | 186 | ||
187 | QPEToolBar *bar = new QPEToolBar( this ); | 187 | QPEToolBar *bar = new QPEToolBar( this ); |
188 | bar->setHorizontalStretchable( true ); | 188 | bar->setHorizontalStretchable( true ); |
189 | menu = bar; | 189 | menu = bar; |
190 | 190 | ||
191 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 191 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
192 | QPopupMenu *file = new QPopupMenu( this ); | 192 | QPopupMenu *file = new QPopupMenu( this ); |
193 | QPopupMenu *edit = new QPopupMenu( this ); | 193 | QPopupMenu *edit = new QPopupMenu( this ); |
194 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 194 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
195 | 195 | ||
196 | font = new QPopupMenu( this ); | 196 | font = new QPopupMenu( this ); |
197 | 197 | ||
198 | bar = new QPEToolBar( this ); | 198 | bar = new QPEToolBar( this ); |
199 | editBar = bar; | 199 | editBar = bar; |
200 | 200 | ||
201 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), | 201 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), |
202 | QString::null, 0, this, 0 ); | 202 | QString::null, 0, this, 0 ); |
203 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 203 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
204 | // a->addTo( bar ); | 204 | // a->addTo( bar ); |
205 | a->addTo( file ); | 205 | a->addTo( file ); |
206 | 206 | ||
207 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), | 207 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), |
208 | QString::null, 0, this, 0 ); | 208 | QString::null, 0, this, 0 ); |
209 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 209 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
210 | a->addTo( bar ); | 210 | a->addTo( bar ); |
211 | a->addTo( file ); | 211 | a->addTo( file ); |
212 | 212 | ||
213 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , | 213 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , |
214 | QString::null, 0, this, 0 ); | 214 | QString::null, 0, this, 0 ); |
215 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 215 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
216 | file->insertSeparator(); | 216 | file->insertSeparator(); |
217 | a->addTo( bar ); | 217 | a->addTo( bar ); |
218 | a->addTo( file ); | 218 | a->addTo( file ); |
219 | 219 | ||
220 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , | 220 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , |
221 | QString::null, 0, this, 0 ); | 221 | QString::null, 0, this, 0 ); |
222 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | 222 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); |
223 | a->addTo( file ); | 223 | a->addTo( file ); |
224 | 224 | ||
225 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), | 225 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), |
226 | QString::null, 0, this, 0 ); | 226 | QString::null, 0, this, 0 ); |
227 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 227 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
228 | a->addTo( editBar ); | 228 | a->addTo( editBar ); |
229 | a->addTo( edit ); | 229 | a->addTo( edit ); |
230 | 230 | ||
231 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), | 231 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), |
232 | QString::null, 0, this, 0 ); | 232 | QString::null, 0, this, 0 ); |
233 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 233 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
234 | a->addTo( editBar ); | 234 | a->addTo( editBar ); |
235 | a->addTo( edit ); | 235 | a->addTo( edit ); |
236 | 236 | ||
237 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), | 237 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), |
238 | QString::null, 0, this, 0 ); | 238 | QString::null, 0, this, 0 ); |
239 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 239 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
240 | a->addTo( editBar ); | 240 | a->addTo( editBar ); |
241 | a->addTo( edit ); | 241 | a->addTo( edit ); |
242 | 242 | ||
243 | 243 | ||
244 | #ifndef QT_NO_CLIPBOARD | 244 | #ifndef QT_NO_CLIPBOARD |
245 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), | 245 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), |
246 | QString::null, 0, this, 0 ); | 246 | QString::null, 0, this, 0 ); |
247 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 247 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
248 | a->addTo( edit ); | 248 | a->addTo( edit ); |
249 | #endif | 249 | #endif |
250 | 250 | ||
251 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), | 251 | a = new QAction( tr( "Goto Line..." ), Resource::loadPixmap( "find" ), |
252 | QString::null, 0, this, 0 ); | 252 | QString::null, 0, this, 0 ); |
253 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); | 253 | connect( a, SIGNAL( activated() ), this, SLOT( gotoLine() ) ); |
254 | edit->insertSeparator(); | 254 | edit->insertSeparator(); |
255 | a->addTo( edit ); | 255 | a->addTo( edit ); |
256 | 256 | ||
257 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), | 257 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), |
258 | QString::null, 0, this, 0 ); | 258 | QString::null, 0, this, 0 ); |
259 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 259 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
260 | a->addTo( bar ); | 260 | a->addTo( bar ); |
261 | a->addTo( edit ); | 261 | a->addTo( edit ); |
262 | 262 | ||
263 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 263 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
264 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 264 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
265 | zin->addTo( font ); | 265 | zin->addTo( font ); |
266 | 266 | ||
267 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 267 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
268 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 268 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
269 | zout->addTo( font ); | 269 | zout->addTo( font ); |
270 | 270 | ||
271 | font->insertSeparator(); | 271 | font->insertSeparator(); |
272 | 272 | ||
273 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 273 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
274 | 274 | ||
275 | font->insertSeparator(); | 275 | font->insertSeparator(); |
276 | font->insertItem(tr("Advanced Features"), advancedMenu); | 276 | font->insertItem(tr("Advanced Features"), advancedMenu); |
277 | 277 | ||
278 | QAction *wa = new QAction( tr("Wrap lines"), | 278 | QAction *wa = new QAction( tr("Wrap lines"), |
279 | QString::null, 0, this, 0 ); | 279 | QString::null, 0, this, 0 ); |
280 | connect( wa, SIGNAL( toggled(bool) ), | 280 | connect( wa, SIGNAL( toggled(bool) ), |
281 | this, SLOT( setWordWrap(bool) ) ); | 281 | this, SLOT( setWordWrap(bool) ) ); |
282 | wa->setToggleAction(true); | 282 | wa->setToggleAction(true); |
283 | wa->addTo( advancedMenu); | 283 | wa->addTo( advancedMenu); |
284 | 284 | ||
285 | nStart = new QAction( tr("Start with new file"), | 285 | nStart = new QAction( tr("Start with new file"), |
286 | QString::null, 0, this, 0 ); | 286 | QString::null, 0, this, 0 ); |
287 | connect( nStart, SIGNAL( toggled(bool) ), | 287 | connect( nStart, SIGNAL( toggled(bool) ), |
288 | this, SLOT( changeStartConfig(bool) ) ); | 288 | this, SLOT( changeStartConfig(bool) ) ); |
289 | nStart->setToggleAction(true); | 289 | nStart->setToggleAction(true); |
290 | nStart->addTo( advancedMenu ); | 290 | nStart->addTo( advancedMenu ); |
291 | nStart->setEnabled(false); | 291 | nStart->setEnabled(false); |
292 | 292 | ||
293 | nAdvanced = new QAction( tr("Prompt on Exit"), | 293 | nAdvanced = new QAction( tr("Prompt on Exit"), |
294 | QString::null, 0, this, 0 ); | 294 | QString::null, 0, this, 0 ); |
295 | connect( nAdvanced, SIGNAL( toggled(bool) ), | 295 | connect( nAdvanced, SIGNAL( toggled(bool) ), |
296 | this, SLOT( doPrompt(bool) ) ); | 296 | this, SLOT( doPrompt(bool) ) ); |
297 | nAdvanced->setToggleAction(true); | 297 | nAdvanced->setToggleAction(true); |
298 | nAdvanced->addTo( advancedMenu ); | 298 | nAdvanced->addTo( advancedMenu ); |
299 | 299 | ||
300 | desktopAction = new QAction( tr("Always open linked file"), | 300 | desktopAction = new QAction( tr("Always open linked file"), |
301 | QString::null, 0, this, 0 ); | 301 | QString::null, 0, this, 0 ); |
302 | connect( desktopAction, SIGNAL( toggled(bool) ), | 302 | connect( desktopAction, SIGNAL( toggled(bool) ), |
303 | this, SLOT( doDesktop(bool) ) ); | 303 | this, SLOT( doDesktop(bool) ) ); |
304 | desktopAction->setToggleAction(true); | 304 | desktopAction->setToggleAction(true); |
305 | desktopAction->addTo( advancedMenu); | 305 | desktopAction->addTo( advancedMenu); |
306 | 306 | ||
307 | filePermAction = new QAction( tr("File Permissions"), | 307 | filePermAction = new QAction( tr("File Permissions"), |
308 | QString::null, 0, this, 0 ); | 308 | QString::null, 0, this, 0 ); |
309 | connect( filePermAction, SIGNAL( toggled(bool) ), | 309 | connect( filePermAction, SIGNAL( toggled(bool) ), |
310 | this, SLOT( doFilePerms(bool) ) ); | 310 | this, SLOT( doFilePerms(bool) ) ); |
311 | filePermAction->setToggleAction(true); | 311 | filePermAction->setToggleAction(true); |
312 | filePermAction->addTo( advancedMenu); | 312 | filePermAction->addTo( advancedMenu); |
313 | 313 | ||
314 | searchBarAction = new QAction( tr("Search Bar Open"), | 314 | searchBarAction = new QAction( tr("Search Bar Open"), |
315 | QString::null, 0, this, 0 ); | 315 | QString::null, 0, this, 0 ); |
316 | connect( searchBarAction, SIGNAL( toggled(bool) ), | 316 | connect( searchBarAction, SIGNAL( toggled(bool) ), |
317 | this, SLOT( setSearchBar(bool) ) ); | 317 | this, SLOT( setSearchBar(bool) ) ); |
318 | searchBarAction->setToggleAction(true); | 318 | searchBarAction->setToggleAction(true); |
319 | searchBarAction->addTo( advancedMenu); | 319 | searchBarAction->addTo( advancedMenu); |
320 | 320 | ||
321 | nAutoSave = new QAction( tr("Auto Save 5 min."), | 321 | nAutoSave = new QAction( tr("Auto Save 5 min."), |
322 | QString::null, 0, this, 0 ); | 322 | QString::null, 0, this, 0 ); |
323 | connect( nAutoSave, SIGNAL( toggled(bool) ), | 323 | connect( nAutoSave, SIGNAL( toggled(bool) ), |
324 | this, SLOT( doTimer(bool) ) ); | 324 | this, SLOT( doTimer(bool) ) ); |
325 | nAutoSave->setToggleAction(true); | 325 | nAutoSave->setToggleAction(true); |
326 | nAutoSave->addTo( advancedMenu); | 326 | nAutoSave->addTo( advancedMenu); |
327 | 327 | ||
328 | 328 | ||
329 | font->insertSeparator(); | 329 | font->insertSeparator(); |
330 | 330 | ||
331 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 331 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
332 | 332 | ||
333 | mb->insertItem( tr( "File" ), file ); | 333 | mb->insertItem( tr( "File" ), file ); |
334 | mb->insertItem( tr( "Edit" ), edit ); | 334 | mb->insertItem( tr( "Edit" ), edit ); |
335 | mb->insertItem( tr( "View" ), font ); | 335 | mb->insertItem( tr( "View" ), font ); |
336 | 336 | ||
337 | searchBar = new QPEToolBar(this); | 337 | searchBar = new QPEToolBar(this); |
338 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 338 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
339 | 339 | ||
340 | searchBar->setHorizontalStretchable( true ); | 340 | searchBar->setHorizontalStretchable( true ); |
341 | 341 | ||
342 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 342 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
343 | searchBar->setStretchableWidget( searchEdit ); | 343 | searchBar->setStretchableWidget( searchEdit ); |
344 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 344 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
345 | this, SLOT( search() ) ); | 345 | this, SLOT( search() ) ); |
346 | 346 | ||
347 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), | 347 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
348 | QString::null, 0, this, 0 ); | 348 | QString::null, 0, this, 0 ); |
349 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 349 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
350 | a->addTo( searchBar ); | 350 | a->addTo( searchBar ); |
351 | a->addTo( edit ); | 351 | a->addTo( edit ); |
352 | 352 | ||
353 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), | 353 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
354 | QString::null, 0, this, 0 ); | 354 | QString::null, 0, this, 0 ); |
355 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 355 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
356 | a->addTo( searchBar ); | 356 | a->addTo( searchBar ); |
357 | 357 | ||
358 | edit->insertSeparator(); | 358 | edit->insertSeparator(); |
359 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), | 359 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), |
360 | QString::null, 0, this, 0 ); | 360 | QString::null, 0, this, 0 ); |
361 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 361 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
362 | a->addTo( edit ); | 362 | a->addTo( edit ); |
363 | 363 | ||
364 | searchBar->hide(); | 364 | searchBar->hide(); |
365 | 365 | ||
366 | editor = new QpeEditor( this ); | 366 | editor = new QpeEditor( this ); |
367 | setCentralWidget( editor ); | 367 | setCentralWidget( editor ); |
368 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 368 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
369 | connect( editor, SIGNAL( textChanged() ), | 369 | connect( editor, SIGNAL( textChanged() ), |
370 | this, SLOT( editorChanged() ) ); | 370 | this, SLOT( editorChanged() ) ); |
371 | 371 | ||
372 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 372 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
373 | 373 | ||
374 | Config cfg("TextEdit"); | 374 | Config cfg("TextEdit"); |
375 | cfg. setGroup ( "Font" ); | 375 | cfg. setGroup ( "Font" ); |
376 | 376 | ||
377 | QFont defaultFont = editor-> font ( ); | 377 | QFont defaultFont = editor-> font ( ); |
378 | 378 | ||
379 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 379 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
380 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 380 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
381 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 381 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
382 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 382 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
383 | 383 | ||
384 | defaultFont = QFont ( family, size, weight, italic ); | 384 | defaultFont = QFont ( family, size, weight, italic ); |
385 | editor-> setFont ( defaultFont ); | 385 | editor-> setFont ( defaultFont ); |
386 | 386 | ||
387 | // updateCaption(); | 387 | // updateCaption(); |
388 | 388 | ||
389 | cfg.setGroup ( "View" ); | 389 | cfg.setGroup ( "View" ); |
390 | 390 | ||
391 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 391 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
392 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 392 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
393 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 393 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
394 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 394 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
395 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 395 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
396 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | 396 | featureAutoSave = cfg.readBoolEntry( "autosave", false); |
397 | 397 | ||
398 | if(useSearchBar) searchBarAction->setOn(true); | 398 | if(useSearchBar) searchBarAction->setOn(true); |
399 | if(promptExit) nAdvanced->setOn( true ); | 399 | if(promptExit) nAdvanced->setOn( true ); |
400 | if(openDesktop) desktopAction->setOn( true ); | 400 | if(openDesktop) desktopAction->setOn( true ); |
401 | if(filePerms) filePermAction->setOn( true ); | 401 | if(filePerms) filePermAction->setOn( true ); |
402 | if(startWithNew) nStart->setOn( true ); | 402 | if(startWithNew) nStart->setOn( true ); |
403 | if(featureAutoSave) nAutoSave->setOn(true); | 403 | if(featureAutoSave) nAutoSave->setOn(true); |
404 | 404 | ||
405 | // { | 405 | // { |
406 | // doTimer(true); | 406 | // doTimer(true); |
407 | // } | 407 | // } |
408 | 408 | ||
409 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 409 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
410 | wa-> setOn ( wrap ); | 410 | wa-> setOn ( wrap ); |
411 | setWordWrap ( wrap ); | 411 | setWordWrap ( wrap ); |
412 | 412 | ||
413 | ///////////////// | 413 | ///////////////// |
414 | if( qApp->argc() > 1) { | 414 | if( qApp->argc() > 1) { |
415 | currentFileName=qApp->argv()[1]; | 415 | currentFileName=qApp->argv()[1]; |
416 | 416 | ||
417 | QFileInfo fi(currentFileName); | 417 | QFileInfo fi(currentFileName); |
418 | 418 | ||
419 | if(fi.baseName().left(1) == "") { | 419 | if(fi.baseName().left(1) == "") { |
420 | openDotFile(currentFileName); | 420 | openDotFile(currentFileName); |
421 | } else { | 421 | } else { |
422 | openFile(currentFileName); | 422 | openFile(currentFileName); |
423 | } | 423 | } |
424 | } else { | 424 | } else { |
425 | edited1=false; | 425 | edited1=false; |
426 | openDotFile(""); | 426 | openDotFile(""); |
427 | } | 427 | } |
428 | 428 | ||
429 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 429 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
430 | } | 430 | } |
431 | 431 | ||
432 | TextEdit::~TextEdit() { | 432 | TextEdit::~TextEdit() { |
433 | qWarning("textedit d'tor"); | 433 | qWarning("textedit d'tor"); |
434 | delete editor; | 434 | delete editor; |
435 | } | 435 | } |
436 | 436 | ||
437 | void TextEdit::closeEvent(QCloseEvent *) { | 437 | void TextEdit::closeEvent(QCloseEvent *) { |
438 | if( edited1 && promptExit) | 438 | if( edited1 && promptExit) |
439 | { | 439 | { |
440 | switch( savePrompt() ) | 440 | switch( savePrompt() ) |
441 | { | 441 | { |
442 | case 1: | 442 | case 1: |
443 | { | 443 | { |
444 | saveAs(); | 444 | saveAs(); |
445 | qApp->quit(); | 445 | qApp->quit(); |
446 | } | 446 | } |
447 | break; | 447 | break; |
448 | 448 | ||
449 | case 2: | 449 | case 2: |
450 | { | 450 | { |
451 | qApp->quit(); | 451 | qApp->quit(); |
452 | } | 452 | } |
453 | break; | 453 | break; |
454 | 454 | ||
455 | case -1: | 455 | case -1: |
456 | break; | 456 | break; |
457 | }; | 457 | }; |
458 | } | 458 | } |
459 | else | 459 | else |
460 | qApp->quit(); | 460 | qApp->quit(); |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | void TextEdit::cleanUp() { | 464 | void TextEdit::cleanUp() { |
465 | 465 | ||
466 | Config cfg ( "TextEdit" ); | 466 | Config cfg ( "TextEdit" ); |
467 | cfg. setGroup ( "Font" ); | 467 | cfg. setGroup ( "Font" ); |
468 | QFont f = editor->font(); | 468 | QFont f = editor->font(); |
469 | cfg.writeEntry ( "Family", f. family ( )); | 469 | cfg.writeEntry ( "Family", f. family ( )); |
470 | cfg.writeEntry ( "Size", f. pointSize ( )); | 470 | cfg.writeEntry ( "Size", f. pointSize ( )); |
471 | cfg.writeEntry ( "Weight", f. weight ( )); | 471 | cfg.writeEntry ( "Weight", f. weight ( )); |
472 | cfg.writeEntry ( "Italic", f. italic ( )); | 472 | cfg.writeEntry ( "Italic", f. italic ( )); |
473 | 473 | ||
474 | cfg.setGroup ( "View" ); | 474 | cfg.setGroup ( "View" ); |
475 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 475 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
476 | cfg.writeEntry ( "FileView", viewSelection ); | 476 | cfg.writeEntry ( "FileView", viewSelection ); |
477 | 477 | ||
478 | cfg.writeEntry ( "PromptExit", promptExit ); | 478 | cfg.writeEntry ( "PromptExit", promptExit ); |
479 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 479 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
480 | cfg.writeEntry ( "FilePermissions", filePerms ); | 480 | cfg.writeEntry ( "FilePermissions", filePerms ); |
481 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 481 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
482 | cfg.writeEntry ( "startNew", startWithNew ); | 482 | cfg.writeEntry ( "startNew", startWithNew ); |
483 | 483 | ||
484 | } | 484 | } |
485 | 485 | ||
486 | 486 | ||
487 | void TextEdit::accept() { | 487 | void TextEdit::accept() { |
488 | if( edited1) | 488 | if( edited1) |
489 | saveAs(); | 489 | saveAs(); |
490 | qApp->quit(); | 490 | qApp->quit(); |
491 | } | 491 | } |
492 | 492 | ||
493 | void TextEdit::zoomIn() { | 493 | void TextEdit::zoomIn() { |
494 | setFontSize(editor->font().pointSize()+1,false); | 494 | setFontSize(editor->font().pointSize()+1,false); |
495 | } | 495 | } |
496 | 496 | ||
497 | void TextEdit::zoomOut() { | 497 | void TextEdit::zoomOut() { |
498 | setFontSize(editor->font().pointSize()-1,true); | 498 | setFontSize(editor->font().pointSize()-1,true); |
499 | } | 499 | } |
500 | 500 | ||
501 | 501 | ||
502 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 502 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
503 | int s=10; | 503 | int s=10; |
504 | for (int i=0; i<nfontsizes; i++) { | 504 | for (int i=0; i<nfontsizes; i++) { |
505 | if ( fontsize[i] == sz ) { | 505 | if ( fontsize[i] == sz ) { |
506 | s = sz; | 506 | s = sz; |
507 | break; | 507 | break; |
508 | } else if ( round_down_not_up ) { | 508 | } else if ( round_down_not_up ) { |
509 | if ( fontsize[i] < sz ) | 509 | if ( fontsize[i] < sz ) |
510 | s = fontsize[i]; | 510 | s = fontsize[i]; |
511 | } else { | 511 | } else { |
512 | if ( fontsize[i] > sz ) { | 512 | if ( fontsize[i] > sz ) { |
513 | s = fontsize[i]; | 513 | s = fontsize[i]; |
514 | break; | 514 | break; |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | QFont f = editor->font(); | 519 | QFont f = editor->font(); |
520 | f.setPointSize(s); | 520 | f.setPointSize(s); |
521 | editor->setFont(f); | 521 | editor->setFont(f); |
522 | 522 | ||
523 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 523 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
524 | zout->setEnabled(s != fontsize[0]); | 524 | zout->setEnabled(s != fontsize[0]); |
525 | } | 525 | } |
526 | 526 | ||
527 | void TextEdit::setBold(bool y) { | 527 | void TextEdit::setBold(bool y) { |
528 | QFont f = editor->font(); | 528 | QFont f = editor->font(); |
529 | f.setBold(y); | 529 | f.setBold(y); |
530 | editor->setFont(f); | 530 | editor->setFont(f); |
531 | } | 531 | } |
532 | 532 | ||
533 | void TextEdit::setItalic(bool y) { | 533 | void TextEdit::setItalic(bool y) { |
534 | QFont f = editor->font(); | 534 | QFont f = editor->font(); |
535 | f.setItalic(y); | 535 | f.setItalic(y); |
536 | editor->setFont(f); | 536 | editor->setFont(f); |
537 | } | 537 | } |
538 | 538 | ||
539 | void TextEdit::setWordWrap(bool y) { | 539 | void TextEdit::setWordWrap(bool y) { |
540 | bool state = editor->edited(); | 540 | bool state = editor->edited(); |
541 | QString captionStr = caption(); | 541 | QString captionStr = caption(); |
542 | bool b1 = edited1; | 542 | bool b1 = edited1; |
543 | bool b2 = edited; | 543 | bool b2 = edited; |
544 | 544 | ||
545 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 545 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
546 | editor->setEdited( state ); | 546 | editor->setEdited( state ); |
547 | edited1=b1; | 547 | edited1=b1; |
548 | edited=b2; | 548 | edited=b2; |
549 | setCaption(captionStr); | 549 | setCaption(captionStr); |
550 | } | 550 | } |
551 | 551 | ||
552 | void TextEdit::setSearchBar(bool b) { | 552 | void TextEdit::setSearchBar(bool b) { |
553 | useSearchBar=b; | 553 | useSearchBar=b; |
554 | Config cfg("TextEdit"); | 554 | Config cfg("TextEdit"); |
555 | cfg.setGroup("View"); | 555 | cfg.setGroup("View"); |
556 | cfg.writeEntry ( "SearchBar", b ); | 556 | cfg.writeEntry ( "SearchBar", b ); |
557 | searchBarAction->setOn(b); | 557 | searchBarAction->setOn(b); |
558 | if(b) | 558 | if(b) |
559 | searchBar->show(); | 559 | searchBar->show(); |
560 | else | 560 | else |
561 | searchBar->hide(); | 561 | searchBar->hide(); |
562 | editor->setFocus(); | 562 | editor->setFocus(); |
563 | } | 563 | } |
564 | 564 | ||
565 | void TextEdit::fileNew() { | 565 | void TextEdit::fileNew() { |
566 | // if( !bFromDocView ) { | 566 | // if( !bFromDocView ) { |
567 | // saveAs(); | 567 | // saveAs(); |
568 | // } | 568 | // } |
569 | newFile(DocLnk()); | 569 | newFile(DocLnk()); |
570 | } | 570 | } |
571 | 571 | ||
572 | void TextEdit::fileOpen() { | 572 | void TextEdit::fileOpen() { |
573 | Config cfg("TextEdit"); | 573 | Config cfg("TextEdit"); |
574 | cfg. setGroup ( "View" ); | 574 | cfg. setGroup ( "View" ); |
575 | QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); | 575 | QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); |
576 | QMap<QString, QStringList> map; | 576 | QMap<QString, QStringList> map; |
577 | map.insert(tr("All"), QStringList() ); | 577 | map.insert(tr("All"), QStringList() ); |
578 | QStringList text; | 578 | QStringList text; |
579 | text << "text/*"; | 579 | text << "text/*"; |
580 | map.insert(tr("Text"), text ); | 580 | map.insert(tr("Text"), text ); |
581 | text << "*"; | 581 | text << "*"; |
582 | map.insert(tr("All"), text ); | 582 | map.insert(tr("All"), text ); |
583 | QString str = OFileDialog::getOpenFileName( 2, | 583 | QString str = OFileDialog::getOpenFileName( 2, |
584 | dir , | 584 | dir , |
585 | QString::null, map); | 585 | QString::null, map); |
586 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) | 586 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) |
587 | { | 587 | { |
588 | cfg.writeEntry("LastOpenDirectory", QFileInfo(str).dirPath(false)); | 588 | cfg.writeEntry("LastOpenDirectory", QFileInfo(str).dirPath(false)); |
589 | openFile( str ); | 589 | openFile( str ); |
590 | } | 590 | } |
591 | else | 591 | else |
592 | updateCaption(); | 592 | updateCaption(); |
593 | } | 593 | } |
594 | 594 | ||
595 | void TextEdit::doSearchBar() { | 595 | void TextEdit::doSearchBar() { |
596 | if(!useSearchBar) | 596 | if(!useSearchBar) |
597 | searchBar->hide(); | 597 | searchBar->hide(); |
598 | else | 598 | else |
599 | searchBar->show(); | 599 | searchBar->show(); |
600 | } | 600 | } |
601 | 601 | ||
602 | #if 0 | 602 | #if 0 |
603 | void TextEdit::slotFind() { | 603 | void TextEdit::slotFind() { |
604 | FindDialog frmFind( tr("Text Editor"), this ); | 604 | FindDialog frmFind( tr("Text Editor"), this ); |
605 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 605 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
606 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 606 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
607 | 607 | ||
608 | //case sensitive, backwards, [category] | 608 | //case sensitive, backwards, [category] |
609 | 609 | ||
610 | connect( editor, SIGNAL(notFound()), | 610 | connect( editor, SIGNAL(notFound()), |
611 | &frmFind, SLOT(slotNotFound()) ); | 611 | &frmFind, SLOT(slotNotFound()) ); |
612 | connect( editor, SIGNAL(searchWrapped()), | 612 | connect( editor, SIGNAL(searchWrapped()), |
613 | &frmFind, SLOT(slotWrapAround()) ); | 613 | &frmFind, SLOT(slotWrapAround()) ); |
614 | 614 | ||
615 | frmFind.exec(); | 615 | frmFind.exec(); |
616 | 616 | ||
617 | 617 | ||
618 | } | 618 | } |
619 | #endif | 619 | #endif |
620 | 620 | ||
621 | void TextEdit::fileRevert() { | 621 | void TextEdit::fileRevert() { |
622 | clear(); | 622 | clear(); |
623 | fileOpen(); | 623 | fileOpen(); |
624 | } | 624 | } |
625 | 625 | ||
626 | void TextEdit::editCut() { | 626 | void TextEdit::editCut() { |
627 | #ifndef QT_NO_CLIPBOARD | 627 | #ifndef QT_NO_CLIPBOARD |
628 | editor->cut(); | 628 | editor->cut(); |
629 | #endif | 629 | #endif |
630 | } | 630 | } |
631 | 631 | ||
632 | void TextEdit::editCopy() { | 632 | void TextEdit::editCopy() { |
633 | #ifndef QT_NO_CLIPBOARD | 633 | #ifndef QT_NO_CLIPBOARD |
634 | editor->copy(); | 634 | editor->copy(); |
635 | #endif | 635 | #endif |
636 | } | 636 | } |
637 | 637 | ||
638 | void TextEdit::editPaste() { | 638 | void TextEdit::editPaste() { |
639 | #ifndef QT_NO_CLIPBOARD | 639 | #ifndef QT_NO_CLIPBOARD |
640 | editor->paste(); | 640 | editor->paste(); |
641 | #endif | 641 | #endif |
642 | } | 642 | } |
643 | 643 | ||
644 | void TextEdit::editFind() { | 644 | void TextEdit::editFind() { |
645 | searchBar->show(); | 645 | searchBar->show(); |
646 | searchEdit->setFocus(); | 646 | searchEdit->setFocus(); |
647 | } | 647 | } |
648 | 648 | ||
649 | void TextEdit::findNext() { | 649 | void TextEdit::findNext() { |
650 | editor->find( searchEdit->text(), false, false ); | 650 | editor->find( searchEdit->text(), false, false ); |
651 | 651 | ||
652 | } | 652 | } |
653 | 653 | ||
654 | void TextEdit::findClose() { | 654 | void TextEdit::findClose() { |
655 | searchBar->hide(); | 655 | searchBar->hide(); |
656 | } | 656 | } |
657 | 657 | ||
658 | void TextEdit::search() { | 658 | void TextEdit::search() { |
659 | editor->find( searchEdit->text(), false, false ); | 659 | editor->find( searchEdit->text(), false, false ); |
660 | } | 660 | } |
661 | 661 | ||
662 | void TextEdit::newFile( const DocLnk &f ) { | 662 | void TextEdit::newFile( const DocLnk &f ) { |
663 | DocLnk nf = f; | 663 | DocLnk nf = f; |
664 | nf.setType("text/plain"); | 664 | nf.setType("text/plain"); |
665 | clear(); | 665 | clear(); |
666 | setWState (WState_Reserved1 ); | 666 | setWState (WState_Reserved1 ); |
667 | editor->setFocus(); | 667 | editor->setFocus(); |
668 | doc = new DocLnk(nf); | 668 | doc = new DocLnk(nf); |
669 | currentFileName = "Unnamed"; | 669 | currentFileName = "Unnamed"; |
670 | qDebug("newFile "+currentFileName); | 670 | qDebug("newFile "+currentFileName); |
671 | updateCaption( currentFileName); | 671 | updateCaption( currentFileName); |
672 | // editor->setEdited( false); | 672 | // editor->setEdited( false); |
673 | } | 673 | } |
674 | 674 | ||
675 | void TextEdit::openDotFile( const QString &f ) { | 675 | void TextEdit::openDotFile( const QString &f ) { |
676 | if(!currentFileName.isEmpty()) { | 676 | if(!currentFileName.isEmpty()) { |
677 | currentFileName=f; | 677 | currentFileName=f; |
678 | 678 | ||
679 | qDebug("openFile dotfile " + currentFileName); | 679 | qDebug("openFile dotfile " + currentFileName); |
680 | QString txt; | 680 | QString txt; |
681 | QFile file(f); | 681 | QFile file(f); |
682 | file.open(IO_ReadWrite); | 682 | file.open(IO_ReadWrite); |
683 | QTextStream t(&file); | 683 | QTextStream t(&file); |
684 | while ( !t.atEnd()) { | 684 | while ( !t.atEnd()) { |
685 | txt+=t.readLine()+"\n"; | 685 | txt+=t.readLine()+"\n"; |
686 | } | 686 | } |
687 | editor->setText(txt); | 687 | editor->setText(txt); |
688 | editor->setEdited( false); | 688 | editor->setEdited( false); |
689 | edited1=false; | 689 | edited1=false; |
690 | edited=false; | 690 | edited=false; |
691 | 691 | ||
692 | 692 | ||
693 | } | 693 | } |
694 | updateCaption( currentFileName); | 694 | updateCaption( currentFileName); |
695 | } | 695 | } |
696 | 696 | ||
697 | void TextEdit::openFile( const QString &f ) { | 697 | void TextEdit::openFile( const QString &f ) { |
698 | qDebug("filename is "+ f); | 698 | qDebug("filename is "+ f); |
699 | QString filer; | 699 | QString filer; |
700 | QFileInfo fi( f); | 700 | QFileInfo fi( f); |
701 | // bFromDocView = true; | 701 | // bFromDocView = true; |
702 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { | 702 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { |
703 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 703 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
704 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> | 704 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> |
705 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 705 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
706 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 706 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
707 | case 0: | 707 | case 0: |
708 | filer = f; | 708 | filer = f; |
709 | break; | 709 | break; |
710 | case 1: | 710 | case 1: |
711 | DocLnk sf(f); | 711 | DocLnk sf(f); |
712 | filer = sf.file(); | 712 | filer = sf.file(); |
713 | break; | 713 | break; |
714 | } | 714 | } |
715 | } else if(fi.baseName().left(1) == "") { | 715 | } else if(fi.baseName().left(1) == "") { |
716 | currentFileName=f; | 716 | currentFileName=f; |
717 | openDotFile(currentFileName); | 717 | openDotFile(currentFileName); |
718 | } else { | 718 | } else { |
719 | DocLnk sf(f); | 719 | DocLnk sf(f); |
720 | filer = sf.file(); | 720 | filer = sf.file(); |
721 | if(filer.right(1) == "/") | 721 | if(filer.right(1) == "/") |
722 | filer = f; | 722 | filer = f; |
723 | 723 | ||
724 | DocLnk nf; | 724 | DocLnk nf; |
725 | nf.setType("text/plain"); | 725 | nf.setType("text/plain"); |
726 | nf.setFile(filer); | 726 | nf.setFile(filer); |
727 | currentFileName=filer; | 727 | currentFileName=filer; |
728 | 728 | ||
729 | nf.setName(fi.baseName()); | 729 | nf.setName(fi.baseName()); |
730 | openFile(nf); | 730 | openFile(nf); |
731 | 731 | ||
732 | qDebug("openFile string "+currentFileName); | 732 | qDebug("openFile string "+currentFileName); |
733 | 733 | ||
734 | } | 734 | } |
735 | showEditTools(); | 735 | showEditTools(); |
736 | // Show filename in caption | 736 | // Show filename in caption |
737 | QString name = filer; | 737 | QString name = filer; |
738 | int sep = name.findRev( '/' ); | 738 | int sep = name.findRev( '/' ); |
739 | if ( sep > 0 ) | 739 | if ( sep > 0 ) |
740 | name = name.mid( sep+1 ); | 740 | name = name.mid( sep+1 ); |
741 | updateCaption( name ); | 741 | updateCaption( name ); |
742 | } | 742 | } |
743 | 743 | ||
744 | void TextEdit::openFile( const DocLnk &f ) { | 744 | void TextEdit::openFile( const DocLnk &f ) { |
745 | // clear(); | 745 | // clear(); |
746 | // bFromDocView = true; | 746 | // bFromDocView = true; |
747 | FileManager fm; | 747 | FileManager fm; |
748 | QString txt; | 748 | QString txt; |
749 | currentFileName=f.file(); | 749 | currentFileName=f.file(); |
750 | qDebug("openFile doclnk " + currentFileName); | 750 | qDebug("openFile doclnk " + currentFileName); |
751 | if ( !fm.loadFile( f, txt ) ) { | 751 | if ( !fm.loadFile( f, txt ) ) { |
752 | // ####### could be a new file | 752 | // ####### could be a new file |
753 | qDebug( "Cannot open file" ); | 753 | qDebug( "Cannot open file" ); |
754 | } | 754 | } |
755 | // fileNew(); | 755 | // fileNew(); |
756 | if ( doc ) | 756 | if ( doc ) |
757 | delete doc; | 757 | delete doc; |
758 | doc = new DocLnk(f); | 758 | doc = new DocLnk(f); |
759 | editor->setText(txt); | 759 | editor->setText(txt); |
760 | editor->setEdited( false); | 760 | editor->setEdited( false); |
761 | edited1=false; | 761 | edited1=false; |
762 | edited=false; | 762 | edited=false; |
763 | 763 | ||
764 | doc->setName(currentFileName); | 764 | doc->setName(currentFileName); |
765 | updateCaption(); | 765 | updateCaption(); |
766 | setTimer(); | 766 | setTimer(); |
767 | } | 767 | } |
768 | 768 | ||
769 | void TextEdit::showEditTools() { | 769 | void TextEdit::showEditTools() { |
770 | menu->show(); | 770 | menu->show(); |
771 | editBar->show(); | 771 | editBar->show(); |
772 | if(!useSearchBar) | 772 | if(!useSearchBar) |
773 | searchBar->hide(); | 773 | searchBar->hide(); |
774 | else | 774 | else |
775 | searchBar->show(); | 775 | searchBar->show(); |
776 | setWState (WState_Reserved1 ); | 776 | setWState (WState_Reserved1 ); |
777 | } | 777 | } |
778 | 778 | ||
779 | /*! | 779 | /*! |
780 | unprompted save */ | 780 | unprompted save */ |
781 | bool TextEdit::save() { | 781 | bool TextEdit::save() { |
782 | qDebug("saveAsFile " + currentFileName); | 782 | qDebug("saveAsFile " + currentFileName); |
783 | if(currentFileName.isEmpty()) { | 783 | if(currentFileName.isEmpty()) { |
784 | saveAs(); | 784 | saveAs(); |
785 | return false; | 785 | return false; |
786 | } | 786 | } |
787 | 787 | ||
788 | QString file = doc->file(); | 788 | QString file = doc->file(); |
789 | qDebug("saver file "+file); | 789 | qDebug("saver file "+file); |
790 | QString name= doc->name(); | 790 | QString name= doc->name(); |
791 | qDebug("File named "+name); | 791 | qDebug("File named "+name); |
792 | QString rt = editor->text(); | 792 | QString rt = editor->text(); |
793 | if( !rt.isEmpty() ) { | 793 | if( !rt.isEmpty() ) { |
794 | if(name.isEmpty()) { | 794 | if(name.isEmpty()) { |
795 | saveAs(); | 795 | saveAs(); |
796 | } else { | 796 | } else { |
797 | currentFileName= name ; | 797 | currentFileName= name ; |
798 | qDebug("saveFile "+currentFileName); | 798 | qDebug("saveFile "+currentFileName); |
799 | 799 | ||
800 | struct stat buf; | 800 | struct stat buf; |
801 | mode_t mode; | 801 | mode_t mode; |
802 | stat(file.latin1(), &buf); | 802 | stat(file.latin1(), &buf); |
803 | mode = buf.st_mode; | 803 | mode = buf.st_mode; |
804 | 804 | ||
805 | if(!fileIs) { | 805 | if(!fileIs) { |
806 | doc->setName( name); | 806 | doc->setName( name); |
807 | FileManager fm; | 807 | FileManager fm; |
808 | if ( !fm.saveFile( *doc, rt ) ) { | 808 | if ( !fm.saveFile( *doc, rt ) ) { |
809 | return false; | 809 | return false; |
810 | } | 810 | } |
811 | } else { | 811 | } else { |
812 | qDebug("regular save file"); | 812 | qDebug("regular save file"); |
813 | QFile f(file); | 813 | QFile f(file); |
814 | if( f.open(IO_WriteOnly)) { | 814 | if( f.open(IO_WriteOnly)) { |
815 | QCString crt = rt.utf8(); | 815 | QCString crt = rt.utf8(); |
816 | f.writeBlock(crt,crt.length()); | 816 | f.writeBlock(crt,crt.length()); |
817 | } else { | 817 | } else { |
818 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 818 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
819 | return false; | 819 | return false; |
820 | } | 820 | } |
821 | 821 | ||
822 | } | 822 | } |
823 | editor->setEdited( false); | 823 | editor->setEdited( false); |
824 | edited1=false; | 824 | edited1=false; |
825 | edited=false; | 825 | edited=false; |
826 | if(caption().left(1)=="*") | 826 | if(caption().left(1)=="*") |
827 | setCaption(caption().right(caption().length()-1)); | 827 | setCaption(caption().right(caption().length()-1)); |
828 | 828 | ||
829 | 829 | ||
830 | chmod( file.latin1(), mode); | 830 | chmod( file.latin1(), mode); |
831 | } | 831 | } |
832 | return true; | 832 | return true; |
833 | } | 833 | } |
834 | return false; | 834 | return false; |
835 | } | 835 | } |
836 | 836 | ||
837 | /*! | 837 | /*! |
838 | prompted save */ | 838 | prompted save */ |
839 | bool TextEdit::saveAs() { | 839 | bool TextEdit::saveAs() { |
840 | 840 | ||
841 | if(caption() == tr("Text Editor")) | 841 | if(caption() == tr("Text Editor")) |
842 | return false; | 842 | return false; |
843 | qDebug("saveAsFile " + currentFileName); | 843 | qDebug("saveAsFile " + currentFileName); |
844 | // case of nothing to save... | 844 | // case of nothing to save... |
845 | // if ( !doc && !currentFileName.isEmpty()) { | 845 | // if ( !doc && !currentFileName.isEmpty()) { |
846 | // //|| !bFromDocView) | 846 | // //|| !bFromDocView) |
847 | // qDebug("no doc"); | 847 | // qDebug("no doc"); |
848 | // return true; | 848 | // return true; |
849 | // } | 849 | // } |
850 | // if ( !editor->edited() ) { | 850 | // if ( !editor->edited() ) { |
851 | // delete doc; | 851 | // delete doc; |
852 | // doc = 0; | 852 | // doc = 0; |
853 | // return true; | 853 | // return true; |
854 | // } | 854 | // } |
855 | 855 | ||
856 | QString rt = editor->text(); | 856 | QString rt = editor->text(); |
857 | qDebug(currentFileName); | 857 | qDebug(currentFileName); |
858 | 858 | ||
859 | if( currentFileName.isEmpty() | 859 | if( currentFileName.isEmpty() |
860 | || currentFileName == tr("Unnamed") | 860 | || currentFileName == tr("Unnamed") |
861 | || currentFileName == tr("Text Editor")) { | 861 | || currentFileName == tr("Text Editor")) { |
862 | qDebug("do silly TT filename thing"); | 862 | qDebug("do silly TT filename thing"); |
863 | // if ( doc && doc->name().isEmpty() ) { | 863 | // if ( doc && doc->name().isEmpty() ) { |
864 | QString pt = rt.simplifyWhiteSpace(); | 864 | QString pt = rt.simplifyWhiteSpace(); |
865 | int i = pt.find( ' ' ); | 865 | int i = pt.find( ' ' ); |
866 | QString docname = pt; | 866 | QString docname = pt; |
867 | if ( i > 0 ) | 867 | if ( i > 0 ) |
868 | docname = pt.left( i ); | 868 | docname = pt.left( i ); |
869 | // remove "." at the beginning | 869 | // remove "." at the beginning |
870 | while( docname.startsWith( "." ) ) | 870 | while( docname.startsWith( "." ) ) |
871 | docname = docname.mid( 1 ); | 871 | docname = docname.mid( 1 ); |
872 | docname.replace( QRegExp("/"), "_" ); | 872 | docname.replace( QRegExp("/"), "_" ); |
873 | // cut the length. filenames longer than that | 873 | // cut the length. filenames longer than that |
874 | //don't make sense and something goes wrong when they get too long. | 874 | //don't make sense and something goes wrong when they get too long. |
875 | if ( docname.length() > 40 ) | 875 | if ( docname.length() > 40 ) |
876 | docname = docname.left(40); | 876 | docname = docname.left(40); |
877 | if ( docname.isEmpty() ) | 877 | if ( docname.isEmpty() ) |
878 | docname = tr("Unnamed"); | 878 | docname = tr("Unnamed"); |
879 | if(doc) doc->setName(docname); | 879 | if(doc) doc->setName(docname); |
880 | currentFileName=docname; | 880 | currentFileName=docname; |
881 | // } | 881 | // } |
882 | // else | 882 | // else |
883 | // qDebug("hmmmmmm"); | 883 | // qDebug("hmmmmmm"); |
884 | } | 884 | } |
885 | 885 | ||
886 | 886 | ||
887 | QMap<QString, QStringList> map; | 887 | QMap<QString, QStringList> map; |
888 | map.insert(tr("All"), QStringList() ); | 888 | map.insert(tr("All"), QStringList() ); |
889 | QStringList text; | 889 | QStringList text; |
890 | text << "text/*"; | 890 | text << "text/*"; |
891 | map.insert(tr("Text"), text ); | 891 | map.insert(tr("Text"), text ); |
892 | text << "*"; | 892 | text << "*"; |
893 | map.insert(tr("All"), text ); | 893 | map.insert(tr("All"), text ); |
894 | 894 | ||
895 | QFileInfo cuFi( currentFileName); | 895 | QFileInfo cuFi( currentFileName); |
896 | QString filee = cuFi.fileName(); | 896 | QString filee = cuFi.fileName(); |
897 | QString dire = cuFi.dirPath(); | 897 | QString dire = cuFi.dirPath(); |
898 | if(dire==".") | 898 | if(dire==".") |
899 | dire = QPEApplication::documentDir(); | 899 | dire = QPEApplication::documentDir(); |
900 | QString str; | 900 | QString str; |
901 | if( !featureAutoSave) | 901 | if( !featureAutoSave) |
902 | { | 902 | { |
903 | str = OFileDialog::getSaveFileName( 2, | 903 | str = OFileDialog::getSaveFileName( 2, |
904 | dire, | 904 | dire, |
905 | filee, map); | 905 | filee, map); |
906 | } | 906 | } |
907 | else | 907 | else |
908 | str=currentFileName; | 908 | str=currentFileName; |
909 | if(!str.isEmpty()) { | 909 | if(!str.isEmpty()) { |
910 | QString fileNm=str; | 910 | QString fileNm=str; |
911 | 911 | ||
912 | qDebug("saving filename "+fileNm); | 912 | qDebug("saving filename "+fileNm); |
913 | QFileInfo fi(fileNm); | 913 | QFileInfo fi(fileNm); |
914 | currentFileName=fi.fileName(); | 914 | currentFileName=fi.fileName(); |
915 | if(doc) | 915 | if(doc) |
916 | // QString file = doc->file(); | 916 | // QString file = doc->file(); |
917 | // doc->removeFiles(); | 917 | // doc->removeFiles(); |
918 | delete doc; | 918 | delete doc; |
919 | DocLnk nf; | 919 | DocLnk nf; |
920 | nf.setType("text/plain"); | 920 | nf.setType("text/plain"); |
921 | nf.setFile( fileNm); | 921 | nf.setFile( fileNm); |
922 | doc = new DocLnk(nf); | 922 | doc = new DocLnk(nf); |
923 | // editor->setText(rt); | 923 | // editor->setText(rt); |
924 | qDebug("Saving file as "+currentFileName); | 924 | qDebug("Saving file as "+currentFileName); |
925 | doc->setName( currentFileName); | 925 | doc->setName( currentFileName); |
926 | updateCaption( currentFileName); | 926 | updateCaption( currentFileName); |
927 | 927 | ||
928 | FileManager fm; | 928 | FileManager fm; |
929 | if ( !fm.saveFile( *doc, rt ) ) { | 929 | if ( !fm.saveFile( *doc, rt ) ) { |
930 | return false; | 930 | return false; |
931 | } | 931 | } |
932 | 932 | ||
933 | if( filePerms ) { | 933 | if( filePerms ) { |
934 | filePermissions *filePerm; | 934 | filePermissions *filePerm; |
935 | filePerm = new filePermissions(this, | 935 | filePerm = new filePermissions(this, |
936 | tr("Permissions"),true, | 936 | tr("Permissions"),true, |
937 | 0,(const QString &)fileNm); | 937 | 0,(const QString &)fileNm); |
938 | filePerm->showMaximized(); | 938 | filePerm->showMaximized(); |
939 | filePerm->exec(); | 939 | filePerm->exec(); |
940 | 940 | ||
941 | if( filePerm) | 941 | if( filePerm) |
942 | delete filePerm; | 942 | delete filePerm; |
943 | } | 943 | } |
944 | // } | 944 | // } |
945 | editor->setEdited( false); | 945 | editor->setEdited( false); |
946 | edited1 = false; | 946 | edited1 = false; |
947 | edited = false; | 947 | edited = false; |
948 | if(caption().left(1)=="*") | 948 | if(caption().left(1)=="*") |
949 | setCaption(caption().right(caption().length()-1)); | 949 | setCaption(caption().right(caption().length()-1)); |
950 | 950 | ||
951 | return true; | 951 | return true; |
952 | } | 952 | } |
953 | qDebug("returning false"); | 953 | qDebug("returning false"); |
954 | return false; | 954 | return false; |
955 | } //end saveAs | 955 | } //end saveAs |
956 | 956 | ||
957 | void TextEdit::clear() { | 957 | void TextEdit::clear() { |
958 | delete doc; | 958 | delete doc; |
959 | doc = 0; | 959 | doc = 0; |
960 | editor->clear(); | 960 | editor->clear(); |
961 | } | 961 | } |
962 | 962 | ||
963 | void TextEdit::updateCaption( const QString &name ) { | 963 | void TextEdit::updateCaption( const QString &name ) { |
964 | 964 | ||
965 | if ( name.isEmpty() ) | 965 | if ( name.isEmpty() ) |
966 | setCaption( tr("Text Editor") ); | 966 | setCaption( tr("Text Editor") ); |
967 | else { | 967 | else { |
968 | QString s = name; | 968 | QString s = name; |
969 | if ( s.isNull() ) | 969 | if ( s.isNull() ) |
970 | s = doc->name(); | 970 | s = doc->name(); |
971 | if ( s.isEmpty() ) { | 971 | if ( s.isEmpty() ) { |
972 | s = tr( "Unnamed" ); | 972 | s = tr( "Unnamed" ); |
973 | currentFileName=s; | 973 | currentFileName=s; |
974 | } | 974 | } |
975 | // if(s.left(1) == "/") | 975 | // if(s.left(1) == "/") |
976 | // s = s.right(s.length()-1); | 976 | // s = s.right(s.length()-1); |
977 | setCaption( s + " - " + tr("Text Editor") ); | 977 | setCaption( s + " - " + tr("Text Editor") ); |
978 | } | 978 | } |
979 | } | 979 | } |
980 | 980 | ||
981 | void TextEdit::setDocument(const QString& fileref) { | 981 | void TextEdit::setDocument(const QString& fileref) { |
982 | if(fileref != "Unnamed") { | 982 | if(fileref != "Unnamed") { |
983 | currentFileName=fileref; | 983 | currentFileName=fileref; |
984 | qDebug("setDocument"); | 984 | qDebug("setDocument"); |
985 | QFileInfo fi(currentFileName); | 985 | QFileInfo fi(currentFileName); |
986 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 986 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
987 | if( (fi.baseName().left(1)).isEmpty() ) { | 987 | if( (fi.baseName().left(1)).isEmpty() ) { |
988 | openDotFile(currentFileName); | 988 | openDotFile(currentFileName); |
989 | 989 | ||
990 | } else { | 990 | } else { |
991 | qDebug("setDoc open"); | 991 | qDebug("setDoc open"); |
992 | bFromDocView = true; | 992 | bFromDocView = true; |
993 | openFile(fileref); | 993 | openFile(fileref); |
994 | editor->setEdited(true); | 994 | editor->setEdited(true); |
995 | edited1=false; | 995 | edited1=false; |
996 | edited=true; | 996 | edited=true; |
997 | // fromSetDocument=false; | 997 | // fromSetDocument=false; |
998 | // doSearchBar(); | 998 | // doSearchBar(); |
999 | } | 999 | } |
1000 | } | 1000 | } |
1001 | updateCaption( currentFileName); | 1001 | updateCaption( currentFileName); |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | void TextEdit::changeFont() { | 1004 | void TextEdit::changeFont() { |
1005 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1005 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1006 | d-> setCaption ( tr( "Choose font" )); | 1006 | d-> setCaption ( tr( "Choose font" )); |
1007 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1007 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1008 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1008 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1009 | lay-> addWidget ( ofs ); | 1009 | lay-> addWidget ( ofs ); |
1010 | ofs-> setSelectedFont ( editor-> font ( )); | 1010 | ofs-> setSelectedFont ( editor-> font ( )); |
1011 | 1011 | ||
1012 | d-> showMaximized ( ); | 1012 | d-> showMaximized ( ); |
1013 | if ( d-> exec ( ) == QDialog::Accepted ) | 1013 | if ( d-> exec ( ) == QDialog::Accepted ) |
1014 | editor-> setFont ( ofs-> selectedFont ( )); | 1014 | editor-> setFont ( ofs-> selectedFont ( )); |
1015 | delete d; | 1015 | delete d; |
1016 | 1016 | ||
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | void TextEdit::editDelete() { | 1019 | void TextEdit::editDelete() { |
1020 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1020 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1021 | tr("Do you really want<BR>to <B>delete</B> " | 1021 | tr("Do you really want<BR>to <B>delete</B> " |
1022 | "the current file\nfrom the disk?<BR>This is " | 1022 | "the current file\nfrom the disk?<BR>This is " |
1023 | "<B>irreversable!!</B>"), | 1023 | "<B>irreversable!!</B>"), |
1024 | tr("Yes"),tr("No"),0,0,1) ) { | 1024 | tr("Yes"),tr("No"),0,0,1) ) { |
1025 | case 0: | 1025 | case 0: |
1026 | if(doc) { | 1026 | if(doc) { |
1027 | doc->removeFiles(); | 1027 | doc->removeFiles(); |
1028 | clear(); | 1028 | clear(); |
1029 | setCaption( tr("Text Editor") ); | 1029 | setCaption( tr("Text Editor") ); |
1030 | } | 1030 | } |
1031 | break; | 1031 | break; |
1032 | case 1: | 1032 | case 1: |
1033 | // exit | 1033 | // exit |
1034 | break; | 1034 | break; |
1035 | }; | 1035 | }; |
1036 | } | 1036 | } |
1037 | 1037 | ||
1038 | void TextEdit::changeStartConfig( bool b ) { | 1038 | void TextEdit::changeStartConfig( bool b ) { |
1039 | startWithNew=b; | 1039 | startWithNew=b; |
1040 | Config cfg("TextEdit"); | 1040 | Config cfg("TextEdit"); |
1041 | cfg.setGroup("View"); | 1041 | cfg.setGroup("View"); |
1042 | cfg.writeEntry("startNew",b); | 1042 | cfg.writeEntry("startNew",b); |
1043 | update(); | 1043 | update(); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | void TextEdit::editorChanged() { | 1046 | void TextEdit::editorChanged() { |
1047 | // qDebug("editor changed"); | 1047 | // qDebug("editor changed"); |
1048 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1048 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1049 | setCaption( "*"+caption()); | 1049 | setCaption( "*"+caption()); |
1050 | edited1=true; | 1050 | edited1=true; |
1051 | } | 1051 | } |
1052 | edited=true; | 1052 | edited=true; |
1053 | } | 1053 | } |
1054 | 1054 | ||
1055 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1055 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1056 | qDebug("QCop "+msg); | 1056 | qDebug("QCop "+msg); |
1057 | if ( msg == "setDocument(QString)" ) { | 1057 | if ( msg == "setDocument(QString)" ) { |
1058 | qDebug("bugger all"); | 1058 | qDebug("bugger all"); |
1059 | 1059 | ||
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | void TextEdit::doAbout() { | 1064 | void TextEdit::doAbout() { |
1065 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1065 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1066 | "2000 Trolltech AS, and<BR>" | 1066 | "2000 Trolltech AS, and<BR>" |
1067 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1067 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1068 | "and is licensed under the GPL")); | 1068 | "and is licensed under the GPL")); |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | void TextEdit::doPrompt(bool b) { | 1071 | void TextEdit::doPrompt(bool b) { |
1072 | promptExit=b; | 1072 | promptExit=b; |
1073 | Config cfg("TextEdit"); | 1073 | Config cfg("TextEdit"); |
1074 | cfg.setGroup ( "View" ); | 1074 | cfg.setGroup ( "View" ); |
1075 | cfg.writeEntry ( "PromptExit", b); | 1075 | cfg.writeEntry ( "PromptExit", b); |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void TextEdit::doDesktop(bool b) { | 1078 | void TextEdit::doDesktop(bool b) { |
1079 | openDesktop=b; | 1079 | openDesktop=b; |
1080 | Config cfg("TextEdit"); | 1080 | Config cfg("TextEdit"); |
1081 | cfg.setGroup ( "View" ); | 1081 | cfg.setGroup ( "View" ); |
1082 | cfg.writeEntry ( "OpenDesktop", b); | 1082 | cfg.writeEntry ( "OpenDesktop", b); |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | void TextEdit::doFilePerms(bool b) { | 1085 | void TextEdit::doFilePerms(bool b) { |
1086 | filePerms=b; | 1086 | filePerms=b; |
1087 | Config cfg("TextEdit"); | 1087 | Config cfg("TextEdit"); |
1088 | cfg.setGroup ( "View" ); | 1088 | cfg.setGroup ( "View" ); |
1089 | cfg.writeEntry ( "FilePermissions", b); | 1089 | cfg.writeEntry ( "FilePermissions", b); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | void TextEdit::editPasteTimeDate() { | 1092 | void TextEdit::editPasteTimeDate() { |
1093 | #ifndef QT_NO_CLIPBOARD | 1093 | #ifndef QT_NO_CLIPBOARD |
1094 | QClipboard *cb = QApplication::clipboard(); | 1094 | QClipboard *cb = QApplication::clipboard(); |
1095 | QDateTime dt = QDateTime::currentDateTime(); | 1095 | QDateTime dt = QDateTime::currentDateTime(); |
1096 | cb->setText( dt.toString()); | 1096 | cb->setText( dt.toString()); |
1097 | editor->paste(); | 1097 | editor->paste(); |
1098 | #endif | 1098 | #endif |
1099 | } | 1099 | } |
1100 | 1100 | ||
1101 | int TextEdit::savePrompt() | 1101 | int TextEdit::savePrompt() |
1102 | { | 1102 | { |
1103 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1103 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1104 | (tr("Textedit detected\n" | 1104 | (tr("Textedit detected\n" |
1105 | "you have unsaved changes\n" | 1105 | "you have unsaved changes\n" |
1106 | "Go ahead and save?\n")), | 1106 | "Go ahead and save?\n")), |
1107 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1107 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1108 | { | 1108 | { |
1109 | case 0: | 1109 | case 0: |
1110 | { | 1110 | { |
1111 | return 1; | 1111 | return 1; |
1112 | } | 1112 | } |
1113 | break; | 1113 | break; |
1114 | 1114 | ||
1115 | case 1: | 1115 | case 1: |
1116 | { | 1116 | { |
1117 | return 2; | 1117 | return 2; |
1118 | } | 1118 | } |
1119 | break; | 1119 | break; |
1120 | 1120 | ||
1121 | case 2: | 1121 | case 2: |
1122 | { | 1122 | { |
1123 | return -1; | 1123 | return -1; |
1124 | } | 1124 | } |
1125 | break; | 1125 | break; |
1126 | }; | 1126 | }; |
1127 | 1127 | ||
1128 | return 0; | 1128 | return 0; |
1129 | } | 1129 | } |
1130 | 1130 | ||
1131 | void TextEdit::timerCrank() | 1131 | void TextEdit::timerCrank() |
1132 | { | 1132 | { |
1133 | if(featureAutoSave && edited1) | 1133 | if(featureAutoSave && edited1) |
1134 | { | 1134 | { |
1135 | if(currentFileName.isEmpty()) | 1135 | if(currentFileName.isEmpty()) |
1136 | { | 1136 | { |
1137 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | 1137 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1138 | saveAs(); | 1138 | saveAs(); |
1139 | } | 1139 | } |
1140 | else | 1140 | else |
1141 | { | 1141 | { |
1142 | // qDebug("autosave"); | 1142 | // qDebug("autosave"); |
1143 | save(); | 1143 | save(); |
1144 | } | 1144 | } |
1145 | setTimer(); | 1145 | setTimer(); |
1146 | } | 1146 | } |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | void TextEdit::doTimer(bool b) | 1149 | void TextEdit::doTimer(bool b) |
1150 | { | 1150 | { |
1151 | Config cfg("TextEdit"); | 1151 | Config cfg("TextEdit"); |
1152 | cfg.setGroup ( "View" ); | 1152 | cfg.setGroup ( "View" ); |
1153 | cfg.writeEntry ( "autosave", b); | 1153 | cfg.writeEntry ( "autosave", b); |
1154 | featureAutoSave = b; | 1154 | featureAutoSave = b; |
1155 | nAutoSave->setOn(b); | 1155 | nAutoSave->setOn(b); |
1156 | if(b) | 1156 | if(b) |
1157 | { | 1157 | { |
1158 | // qDebug("doTimer true"); | 1158 | // qDebug("doTimer true"); |
1159 | setTimer(); | 1159 | setTimer(); |
1160 | } | 1160 | } |
1161 | // else | 1161 | // else |
1162 | // qDebug("doTimer false"); | 1162 | // qDebug("doTimer false"); |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | void TextEdit::setTimer() | 1165 | void TextEdit::setTimer() |
1166 | { | 1166 | { |
1167 | if(featureAutoSave) | 1167 | if(featureAutoSave) |
1168 | { | 1168 | { |
1169 | // qDebug("setting autosave"); | 1169 | // qDebug("setting autosave"); |
1170 | QTimer *timer = new QTimer(this ); | 1170 | QTimer *timer = new QTimer(this ); |
1171 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1171 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1172 | timer->start( 300000, true); //5 minutes | 1172 | timer->start( 300000, true); //5 minutes |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | 1175 | ||
1176 | void TextEdit::gotoLine() { | 1176 | void TextEdit::gotoLine() { |
1177 | 1177 | if( editor->length() < 1) | |
1178 | return; | ||
1178 | QWidget *d = QApplication::desktop(); | 1179 | QWidget *d = QApplication::desktop(); |
1179 | gotoEdit = new QLineEdit( 0, "Goto line"); | 1180 | gotoEdit = new QLineEdit( 0, "Goto line"); |
1180 | 1181 | ||
1181 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); | 1182 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); |
1182 | gotoEdit->setFrame(true); | 1183 | gotoEdit->setFrame(true); |
1183 | gotoEdit->show(); | 1184 | gotoEdit->show(); |
1184 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | 1185 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); |
1185 | } | 1186 | } |
1186 | 1187 | ||
1187 | void TextEdit::doGoto() { | 1188 | void TextEdit::doGoto() { |
1188 | QString number = gotoEdit->text(); | 1189 | QString number = gotoEdit->text(); |
1189 | gotoEdit->hide(); | 1190 | gotoEdit->hide(); |
1191 | |||
1190 | if(gotoEdit) { | 1192 | if(gotoEdit) { |
1191 | delete gotoEdit; | 1193 | delete gotoEdit; |
1192 | gotoEdit = 0; | 1194 | gotoEdit = 0; |
1193 | } | 1195 | } |
1194 | 1196 | ||
1195 | bool ok; | 1197 | bool ok; |
1196 | int lineNumber = number.toInt(&ok, 10); | 1198 | int lineNumber = number.toInt(&ok, 10); |
1197 | if(editor->numLines() < lineNumber) | 1199 | if( editor->numLines() < lineNumber) |
1198 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | 1200 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); |
1199 | else | 1201 | else |
1200 | { | 1202 | { |
1201 | editor->setCursorPosition(lineNumber, 0, false); | 1203 | editor->setCursorPosition(lineNumber, 0, false); |
1202 | } | 1204 | } |
1203 | } | 1205 | } |