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