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