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