author | llornkcor <llornkcor> | 2002-02-18 15:02:33 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-18 15:02:33 (UTC) |
commit | a6266fb220a61c4904e24ebf31eeefab34362e59 (patch) (unidiff) | |
tree | ab1da9da25c4b5118935bc981fca62a8c72b6810 | |
parent | 00f89d28e669140eb50f1f220c389f88fba1105c (diff) | |
download | opie-a6266fb220a61c4904e24ebf31eeefab34362e59.zip opie-a6266fb220a61c4904e24ebf31eeefab34362e59.tar.gz opie-a6266fb220a61c4904e24ebf31eeefab34362e59.tar.bz2 |
added Save As (prompt user) and moved save (no prompt) functions there
-rw-r--r-- | core/apps/textedit/textedit.cpp | 23 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 2 |
2 files changed, 23 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 429c195..834971a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -230,96 +230,100 @@ static int get_unique_id() | |||
230 | } | 230 | } |
231 | 231 | ||
232 | static const int nfontsizes = 6; | 232 | static const int nfontsizes = 6; |
233 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 233 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
234 | 234 | ||
235 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 235 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
236 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 236 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) |
237 | { | 237 | { |
238 | doc = 0; | 238 | doc = 0; |
239 | 239 | ||
240 | setToolBarsMovable( FALSE ); | 240 | setToolBarsMovable( FALSE ); |
241 | 241 | ||
242 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 242 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
243 | 243 | ||
244 | QPEToolBar *bar = new QPEToolBar( this ); | 244 | QPEToolBar *bar = new QPEToolBar( this ); |
245 | bar->setHorizontalStretchable( TRUE ); | 245 | bar->setHorizontalStretchable( TRUE ); |
246 | menu = bar; | 246 | menu = bar; |
247 | 247 | ||
248 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 248 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
249 | QPopupMenu *file = new QPopupMenu( this ); | 249 | QPopupMenu *file = new QPopupMenu( this ); |
250 | QPopupMenu *edit = new QPopupMenu( this ); | 250 | QPopupMenu *edit = new QPopupMenu( this ); |
251 | QPopupMenu *font = new QPopupMenu( this ); | 251 | QPopupMenu *font = new QPopupMenu( this ); |
252 | 252 | ||
253 | bar = new QPEToolBar( this ); | 253 | bar = new QPEToolBar( this ); |
254 | editBar = bar; | 254 | editBar = bar; |
255 | 255 | ||
256 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); | 256 | QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); |
257 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); | 257 | connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); |
258 | a->addTo( bar ); | 258 | a->addTo( bar ); |
259 | a->addTo( file ); | 259 | a->addTo( file ); |
260 | 260 | ||
261 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 261 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
263 | // a->addTo( bar ); | 263 | // a->addTo( bar ); |
264 | a->addTo( file ); | 264 | a->addTo( file ); |
265 | 265 | ||
266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | 267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); |
268 | a->addTo( bar ); | 268 | a->addTo( bar ); |
269 | a->addTo( file ); | 269 | a->addTo( file ); |
270 | 270 | ||
271 | // | 271 | // |
272 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 272 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
273 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 273 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
274 | // a->addTo( bar ); | 274 | // a->addTo( bar ); |
275 | file->insertSeparator(); | 275 | file->insertSeparator(); |
276 | a->addTo( file ); | 276 | a->addTo( file ); |
277 | 277 | ||
278 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | ||
279 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | ||
280 | a->addTo( file ); | ||
281 | |||
278 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 282 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
279 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 283 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
280 | a->addTo( editBar ); | 284 | a->addTo( editBar ); |
281 | a->addTo( edit ); | 285 | a->addTo( edit ); |
282 | 286 | ||
283 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 287 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
284 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 288 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
285 | a->addTo( editBar ); | 289 | a->addTo( editBar ); |
286 | a->addTo( edit ); | 290 | a->addTo( edit ); |
287 | 291 | ||
288 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 292 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
289 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 293 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
290 | a->addTo( editBar ); | 294 | a->addTo( editBar ); |
291 | a->addTo( edit ); | 295 | a->addTo( edit ); |
292 | 296 | ||
293 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 297 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
294 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 298 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
295 | edit->insertSeparator(); | 299 | edit->insertSeparator(); |
296 | a->addTo( bar ); | 300 | a->addTo( bar ); |
297 | a->addTo( edit ); | 301 | a->addTo( edit ); |
298 | 302 | ||
299 | int defsize; | 303 | int defsize; |
300 | bool defb, defi, wrap; | 304 | bool defb, defi, wrap; |
301 | 305 | ||
302 | Config cfg("TextEdit"); | 306 | Config cfg("TextEdit"); |
303 | cfg.setGroup("View"); | 307 | cfg.setGroup("View"); |
304 | defsize = cfg.readNumEntry("FontSize",10); | 308 | defsize = cfg.readNumEntry("FontSize",10); |
305 | defb = cfg.readBoolEntry("Bold",FALSE); | 309 | defb = cfg.readBoolEntry("Bold",FALSE); |
306 | defi = cfg.readBoolEntry("Italic",FALSE); | 310 | defi = cfg.readBoolEntry("Italic",FALSE); |
307 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 311 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
308 | 312 | ||
309 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 313 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
310 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 314 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
311 | zin->addTo( font ); | 315 | zin->addTo( font ); |
312 | 316 | ||
313 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 317 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
314 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 318 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
315 | zout->addTo( font ); | 319 | zout->addTo( font ); |
316 | 320 | ||
317 | font->insertSeparator(); | 321 | font->insertSeparator(); |
318 | 322 | ||
319 | #if 0 | 323 | #if 0 |
320 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 324 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
321 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 325 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
322 | ba->setToggleAction(TRUE); | 326 | ba->setToggleAction(TRUE); |
323 | ba->addTo( font ); | 327 | ba->addTo( font ); |
324 | 328 | ||
325 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 329 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
@@ -369,169 +373,169 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
369 | 373 | ||
370 | editorStack = new QWidgetStack( this ); | 374 | editorStack = new QWidgetStack( this ); |
371 | setCentralWidget( editorStack ); | 375 | setCentralWidget( editorStack ); |
372 | 376 | ||
373 | searchVisible = FALSE; | 377 | searchVisible = FALSE; |
374 | 378 | ||
375 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | 379 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
376 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 380 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
377 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 381 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
378 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 382 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
379 | // fileOpen(); | 383 | // fileOpen(); |
380 | 384 | ||
381 | editor = new QpeEditor( editorStack ); | 385 | editor = new QpeEditor( editorStack ); |
382 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 386 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
383 | editorStack->addWidget( editor, get_unique_id() ); | 387 | editorStack->addWidget( editor, get_unique_id() ); |
384 | 388 | ||
385 | resize( 200, 300 ); | 389 | resize( 200, 300 ); |
386 | 390 | ||
387 | // setFontSize(defsize,TRUE); | 391 | // setFontSize(defsize,TRUE); |
388 | FontDatabase fdb; | 392 | FontDatabase fdb; |
389 | QFont defaultFont=editor->font(); | 393 | QFont defaultFont=editor->font(); |
390 | QFontInfo fontInfo(defaultFont); | 394 | QFontInfo fontInfo(defaultFont); |
391 | 395 | ||
392 | cfg.setGroup("Font"); | 396 | cfg.setGroup("Font"); |
393 | QString family = cfg.readEntry("Family", fontInfo.family()); | 397 | QString family = cfg.readEntry("Family", fontInfo.family()); |
394 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 398 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
395 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 399 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
396 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 400 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
397 | 401 | ||
398 | defaultFont = fdb.font(family,style,i_size,charSet); | 402 | defaultFont = fdb.font(family,style,i_size,charSet); |
399 | editor->setFont( defaultFont); | 403 | editor->setFont( defaultFont); |
400 | 404 | ||
401 | wa->setOn(wrap); | 405 | wa->setOn(wrap); |
402 | updateCaption(); | 406 | updateCaption(); |
403 | if( qApp->argc() > 1 ) { | 407 | if( qApp->argc() > 1 ) { |
404 | for (int i=1;i< qApp->argc();i++) { | 408 | for (int i=1;i< qApp->argc();i++) { |
405 | QString tmp; | 409 | QString tmp; |
406 | currentFileName = tmp.sprintf("%s",qApp->argv()[i]); | 410 | currentFileName = tmp.sprintf("%s",qApp->argv()[i]); |
407 | qDebug(currentFileName); | 411 | qDebug(currentFileName); |
408 | setDocument( currentFileName ); | 412 | setDocument( currentFileName ); |
409 | } | 413 | } |
410 | } | 414 | } |
411 | else | 415 | else |
412 | fileNew(); | 416 | fileNew(); |
413 | } | 417 | } |
414 | 418 | ||
415 | TextEdit::~TextEdit() | 419 | TextEdit::~TextEdit() |
416 | { | 420 | { |
417 | save(); | 421 | saveAs(); |
418 | 422 | ||
419 | Config cfg("TextEdit"); | 423 | Config cfg("TextEdit"); |
420 | cfg.setGroup("View"); | 424 | cfg.setGroup("View"); |
421 | QFont f = editor->font(); | 425 | QFont f = editor->font(); |
422 | cfg.writeEntry("FontSize",f.pointSize()); | 426 | cfg.writeEntry("FontSize",f.pointSize()); |
423 | cfg.writeEntry("Bold",f.bold()); | 427 | cfg.writeEntry("Bold",f.bold()); |
424 | cfg.writeEntry("Italic",f.italic()); | 428 | cfg.writeEntry("Italic",f.italic()); |
425 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 429 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
426 | } | 430 | } |
427 | 431 | ||
428 | void TextEdit::zoomIn() | 432 | void TextEdit::zoomIn() |
429 | { | 433 | { |
430 | setFontSize(editor->font().pointSize()+1,FALSE); | 434 | setFontSize(editor->font().pointSize()+1,FALSE); |
431 | } | 435 | } |
432 | 436 | ||
433 | void TextEdit::zoomOut() | 437 | void TextEdit::zoomOut() |
434 | { | 438 | { |
435 | setFontSize(editor->font().pointSize()-1,TRUE); | 439 | setFontSize(editor->font().pointSize()-1,TRUE); |
436 | } | 440 | } |
437 | 441 | ||
438 | 442 | ||
439 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 443 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
440 | { | 444 | { |
441 | int s=10; | 445 | int s=10; |
442 | for (int i=0; i<nfontsizes; i++) { | 446 | for (int i=0; i<nfontsizes; i++) { |
443 | if ( fontsize[i] == sz ) { | 447 | if ( fontsize[i] == sz ) { |
444 | s = sz; | 448 | s = sz; |
445 | break; | 449 | break; |
446 | } else if ( round_down_not_up ) { | 450 | } else if ( round_down_not_up ) { |
447 | if ( fontsize[i] < sz ) | 451 | if ( fontsize[i] < sz ) |
448 | s = fontsize[i]; | 452 | s = fontsize[i]; |
449 | } else { | 453 | } else { |
450 | if ( fontsize[i] > sz ) { | 454 | if ( fontsize[i] > sz ) { |
451 | s = fontsize[i]; | 455 | s = fontsize[i]; |
452 | break; | 456 | break; |
453 | } | 457 | } |
454 | } | 458 | } |
455 | } | 459 | } |
456 | 460 | ||
457 | QFont f = editor->font(); | 461 | QFont f = editor->font(); |
458 | f.setPointSize(s); | 462 | f.setPointSize(s); |
459 | editor->setFont(f); | 463 | editor->setFont(f); |
460 | 464 | ||
461 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 465 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
462 | zout->setEnabled(s != fontsize[0]); | 466 | zout->setEnabled(s != fontsize[0]); |
463 | } | 467 | } |
464 | 468 | ||
465 | void TextEdit::setBold(bool y) | 469 | void TextEdit::setBold(bool y) |
466 | { | 470 | { |
467 | QFont f = editor->font(); | 471 | QFont f = editor->font(); |
468 | f.setBold(y); | 472 | f.setBold(y); |
469 | editor->setFont(f); | 473 | editor->setFont(f); |
470 | } | 474 | } |
471 | 475 | ||
472 | void TextEdit::setItalic(bool y) | 476 | void TextEdit::setItalic(bool y) |
473 | { | 477 | { |
474 | QFont f = editor->font(); | 478 | QFont f = editor->font(); |
475 | f.setItalic(y); | 479 | f.setItalic(y); |
476 | editor->setFont(f); | 480 | editor->setFont(f); |
477 | } | 481 | } |
478 | 482 | ||
479 | void TextEdit::setWordWrap(bool y) | 483 | void TextEdit::setWordWrap(bool y) |
480 | { | 484 | { |
481 | bool state = editor->edited(); | 485 | bool state = editor->edited(); |
482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 486 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
483 | editor->setEdited( state ); | 487 | editor->setEdited( state ); |
484 | } | 488 | } |
485 | 489 | ||
486 | void TextEdit::fileNew() | 490 | void TextEdit::fileNew() |
487 | { | 491 | { |
488 | if( !bFromDocView ) { | 492 | if( !bFromDocView ) { |
489 | save(); | 493 | saveAs(); |
490 | } | 494 | } |
491 | newFile(DocLnk()); | 495 | newFile(DocLnk()); |
492 | } | 496 | } |
493 | 497 | ||
494 | void TextEdit::fileOpen() | 498 | void TextEdit::fileOpen() |
495 | { | 499 | { |
496 | // if ( !save() ) { | 500 | // if ( !save() ) { |
497 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 501 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
498 | // tr( "Text Editor was unable to\n" | 502 | // tr( "Text Editor was unable to\n" |
499 | // "save your changes.\n" | 503 | // "save your changes.\n" |
500 | // "Free some space and try again.\n" | 504 | // "Free some space and try again.\n" |
501 | // "\nContinue anyway?" ), | 505 | // "\nContinue anyway?" ), |
502 | // QMessageBox::Yes|QMessageBox::Escape, | 506 | // QMessageBox::Yes|QMessageBox::Escape, |
503 | // QMessageBox::No|QMessageBox::Default ) | 507 | // QMessageBox::No|QMessageBox::Default ) |
504 | // != QMessageBox::Yes ) | 508 | // != QMessageBox::Yes ) |
505 | // return; | 509 | // return; |
506 | // else { | 510 | // else { |
507 | // delete doc; | 511 | // delete doc; |
508 | // doc = 0; | 512 | // doc = 0; |
509 | // } | 513 | // } |
510 | // } | 514 | // } |
511 | menu->hide(); | 515 | menu->hide(); |
512 | editBar->hide(); | 516 | editBar->hide(); |
513 | searchBar->hide(); | 517 | searchBar->hide(); |
514 | clearWState (WState_Reserved1 ); | 518 | clearWState (WState_Reserved1 ); |
515 | editorStack->raiseWidget( fileSelector ); | 519 | editorStack->raiseWidget( fileSelector ); |
516 | fileSelector->reread(); | 520 | fileSelector->reread(); |
517 | updateCaption(currentFileName); | 521 | updateCaption(currentFileName); |
518 | } | 522 | } |
519 | 523 | ||
520 | void TextEdit::newFileOpen() | 524 | void TextEdit::newFileOpen() |
521 | { | 525 | { |
522 | fileBrowser *browseForFiles; | 526 | fileBrowser *browseForFiles; |
523 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); | 527 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); |
524 | if( browseForFiles->exec()!= 0 ) { | 528 | if( browseForFiles->exec()!= 0 ) { |
525 | QString selFile= browseForFiles->selectedFileName; | 529 | QString selFile= browseForFiles->selectedFileName; |
526 | QStringList fileList=browseForFiles->fileList; | 530 | QStringList fileList=browseForFiles->fileList; |
527 | qDebug(selFile); | 531 | qDebug(selFile); |
528 | QStringList::ConstIterator f; | 532 | QStringList::ConstIterator f; |
529 | QString fileTemp; | 533 | QString fileTemp; |
530 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 534 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
531 | fileTemp = *f; | 535 | fileTemp = *f; |
532 | fileTemp.right( fileTemp.length()-5); | 536 | fileTemp.right( fileTemp.length()-5); |
533 | QString fileName = fileTemp; | 537 | QString fileName = fileTemp; |
534 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 538 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
535 | currentFileName = fileName; | 539 | currentFileName = fileName; |
536 | // qDebug("please open "+currentFileName); | 540 | // qDebug("please open "+currentFileName); |
537 | openFile(fileName ); | 541 | openFile(fileName ); |
@@ -635,96 +639,111 @@ void TextEdit::openFile( const QString &f ) | |||
635 | showEditTools(); | 639 | showEditTools(); |
636 | // Show filename in caption | 640 | // Show filename in caption |
637 | QString name = f; | 641 | QString name = f; |
638 | int sep = name.findRev( '/' ); | 642 | int sep = name.findRev( '/' ); |
639 | if ( sep > 0 ) | 643 | if ( sep > 0 ) |
640 | name = name.mid( sep+1 ); | 644 | name = name.mid( sep+1 ); |
641 | updateCaption( name ); | 645 | updateCaption( name ); |
642 | } | 646 | } |
643 | 647 | ||
644 | void TextEdit::openFile( const DocLnk &f ) | 648 | void TextEdit::openFile( const DocLnk &f ) |
645 | { | 649 | { |
646 | // clear(); | 650 | // clear(); |
647 | bFromDocView = TRUE; | 651 | bFromDocView = TRUE; |
648 | FileManager fm; | 652 | FileManager fm; |
649 | QString txt; | 653 | QString txt; |
650 | if ( !fm.loadFile( f, txt ) ) { | 654 | if ( !fm.loadFile( f, txt ) ) { |
651 | // ####### could be a new file | 655 | // ####### could be a new file |
652 | qDebug( "Cannot open file" ); | 656 | qDebug( "Cannot open file" ); |
653 | 657 | ||
654 | //return; | 658 | //return; |
655 | } | 659 | } |
656 | 660 | ||
657 | fileNew(); | 661 | fileNew(); |
658 | if ( doc ) | 662 | if ( doc ) |
659 | delete doc; | 663 | delete doc; |
660 | doc = new DocLnk(f); | 664 | doc = new DocLnk(f); |
661 | editor->setText(txt); | 665 | editor->setText(txt); |
662 | editor->setEdited(FALSE); | 666 | editor->setEdited(FALSE); |
663 | updateCaption(currentFileName); | 667 | updateCaption(currentFileName); |
664 | } | 668 | } |
665 | 669 | ||
666 | void TextEdit::showEditTools() | 670 | void TextEdit::showEditTools() |
667 | { | 671 | { |
668 | // if ( !doc ) | 672 | // if ( !doc ) |
669 | // close(); | 673 | // close(); |
670 | // clear(); | 674 | // clear(); |
671 | fileSelector->hide(); | 675 | fileSelector->hide(); |
672 | menu->show(); | 676 | menu->show(); |
673 | editBar->show(); | 677 | editBar->show(); |
674 | if ( searchVisible ) | 678 | if ( searchVisible ) |
675 | searchBar->show(); | 679 | searchBar->show(); |
676 | // updateCaption(); | 680 | // updateCaption(); |
677 | editorStack->raiseWidget( editor ); | 681 | editorStack->raiseWidget( editor ); |
678 | setWState (WState_Reserved1 ); | 682 | setWState (WState_Reserved1 ); |
679 | } | 683 | } |
680 | 684 | ||
681 | bool TextEdit::save() | 685 | bool TextEdit::save() |
682 | { | 686 | { |
687 | QString rt = editor->text(); | ||
688 | doc->setName( currentFileName); | ||
689 | FileManager fm; | ||
690 | if ( !fm.saveFile( *doc, rt ) ) { | ||
691 | return false; | ||
692 | } | ||
693 | delete doc; | ||
694 | doc = 0; | ||
695 | editor->setEdited( false ); | ||
696 | return true; | ||
697 | |||
698 | } | ||
699 | |||
700 | bool TextEdit::saveAs() | ||
701 | { | ||
683 | // case of nothing to save... | 702 | // case of nothing to save... |
684 | if ( !doc || !bFromDocView) | 703 | if ( !doc || !bFromDocView) |
685 | return true; | 704 | return true; |
686 | if ( !editor->edited() ) { | 705 | if ( !editor->edited() ) { |
687 | delete doc; | 706 | delete doc; |
688 | doc = 0; | 707 | doc = 0; |
689 | return true; | 708 | return true; |
690 | } | 709 | } |
691 | 710 | ||
692 | QString rt = editor->text(); | 711 | QString rt = editor->text(); |
693 | qDebug(currentFileName); | 712 | qDebug(currentFileName); |
694 | 713 | ||
695 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 714 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
696 | 715 | ||
697 | if ( doc->name().isEmpty() ) { | 716 | if ( doc->name().isEmpty() ) { |
698 | QString pt = rt.simplifyWhiteSpace(); | 717 | QString pt = rt.simplifyWhiteSpace(); |
699 | int i = pt.find( ' ' ); | 718 | int i = pt.find( ' ' ); |
700 | QString docname = pt; | 719 | QString docname = pt; |
701 | if ( i > 0 ) | 720 | if ( i > 0 ) |
702 | docname = pt.left( i ); | 721 | docname = pt.left( i ); |
703 | // remove "." at the beginning | 722 | // remove "." at the beginning |
704 | while( docname.startsWith( "." ) ) | 723 | while( docname.startsWith( "." ) ) |
705 | docname = docname.mid( 1 ); | 724 | docname = docname.mid( 1 ); |
706 | docname.replace( QRegExp("/"), "_" ); | 725 | docname.replace( QRegExp("/"), "_" ); |
707 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 726 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
708 | if ( docname.length() > 40 ) | 727 | if ( docname.length() > 40 ) |
709 | docname = docname.left(40); | 728 | docname = docname.left(40); |
710 | if ( docname.isEmpty() ) | 729 | if ( docname.isEmpty() ) |
711 | docname = "Empty Text"; | 730 | docname = "Empty Text"; |
712 | doc->setName(docname); | 731 | doc->setName(docname); |
713 | currentFileName=docname; | 732 | currentFileName=docname; |
714 | } | 733 | } |
715 | } | 734 | } |
716 | 735 | ||
717 | fileSaver *fileSaveDlg; | 736 | fileSaver *fileSaveDlg; |
718 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | 737 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); |
719 | if( fileSaveDlg->exec() != 0 ) { | 738 | if( fileSaveDlg->exec() != 0 ) { |
720 | QString fileNm=fileSaveDlg->selectedFileName; | 739 | QString fileNm=fileSaveDlg->selectedFileName; |
721 | qDebug("save filename "+fileNm); | 740 | qDebug("save filename "+fileNm); |
722 | doc->setName(fileNm); | 741 | doc->setName(fileNm); |
723 | updateCaption(fileNm); | 742 | updateCaption(fileNm); |
724 | } | 743 | } |
725 | delete fileSaveDlg; | 744 | delete fileSaveDlg; |
726 | 745 | ||
727 | FileManager fm; | 746 | FileManager fm; |
728 | if ( !fm.saveFile( *doc, rt ) ) { | 747 | if ( !fm.saveFile( *doc, rt ) ) { |
729 | return false; | 748 | return false; |
730 | } | 749 | } |
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 4bfb260..f9eb241 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -16,90 +16,92 @@ | |||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 | 20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 |
21 | 21 | ||
22 | #ifndef TEXTEDIT_H | 22 | #ifndef TEXTEDIT_H |
23 | #define TEXTEDIT_H | 23 | #define TEXTEDIT_H |
24 | 24 | ||
25 | #define QTEXTEDIT_OPEN_API | 25 | #define QTEXTEDIT_OPEN_API |
26 | 26 | ||
27 | #include <qpe/filemanager.h> | 27 | #include <qpe/filemanager.h> |
28 | 28 | ||
29 | #include <qmainwindow.h> | 29 | #include <qmainwindow.h> |
30 | #include <qmultilineedit.h> | 30 | #include <qmultilineedit.h> |
31 | #include <qlist.h> | 31 | #include <qlist.h> |
32 | #include <qmap.h> | 32 | #include <qmap.h> |
33 | 33 | ||
34 | class QWidgetStack; | 34 | class QWidgetStack; |
35 | class QToolButton; | 35 | class QToolButton; |
36 | class QPopupMenu; | 36 | class QPopupMenu; |
37 | class QToolBar; | 37 | class QToolBar; |
38 | class QLineEdit; | 38 | class QLineEdit; |
39 | class QAction; | 39 | class QAction; |
40 | class FileSelector; | 40 | class FileSelector; |
41 | class QpeEditor; | 41 | class QpeEditor; |
42 | 42 | ||
43 | class TextEdit : public QMainWindow | 43 | class TextEdit : public QMainWindow |
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | 46 | ||
47 | public: | 47 | public: |
48 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 48 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
49 | ~TextEdit(); | 49 | ~TextEdit(); |
50 | 50 | ||
51 | void openFile( const QString & ); | 51 | void openFile( const QString & ); |
52 | 52 | ||
53 | protected: | 53 | protected: |
54 | void closeEvent( QCloseEvent *e ); | 54 | void closeEvent( QCloseEvent *e ); |
55 | 55 | ||
56 | private slots: | 56 | private slots: |
57 | void setDocument(const QString&); | 57 | void setDocument(const QString&); |
58 | void changeFont(); | 58 | void changeFont(); |
59 | void fileNew(); | 59 | void fileNew(); |
60 | void fileRevert(); | 60 | void fileRevert(); |
61 | void fileOpen(); | 61 | void fileOpen(); |
62 | void newFileOpen(); | 62 | void newFileOpen(); |
63 | bool save(); | 63 | bool save(); |
64 | bool saveAs(); | ||
65 | |||
64 | 66 | ||
65 | void editCut(); | 67 | void editCut(); |
66 | void editCopy(); | 68 | void editCopy(); |
67 | void editPaste(); | 69 | void editPaste(); |
68 | void editFind(); | 70 | void editFind(); |
69 | 71 | ||
70 | void findNext(); | 72 | void findNext(); |
71 | void findClose(); | 73 | void findClose(); |
72 | 74 | ||
73 | void search(); | 75 | void search(); |
74 | void accept(); | 76 | void accept(); |
75 | 77 | ||
76 | void newFile( const DocLnk & ); | 78 | void newFile( const DocLnk & ); |
77 | void openFile( const DocLnk & ); | 79 | void openFile( const DocLnk & ); |
78 | void showEditTools(); | 80 | void showEditTools(); |
79 | 81 | ||
80 | void zoomIn(); | 82 | void zoomIn(); |
81 | void zoomOut(); | 83 | void zoomOut(); |
82 | void setBold(bool y); | 84 | void setBold(bool y); |
83 | void setItalic(bool y); | 85 | void setItalic(bool y); |
84 | void setWordWrap(bool y); | 86 | void setWordWrap(bool y); |
85 | 87 | ||
86 | private: | 88 | private: |
87 | void colorChanged( const QColor &c ); | 89 | void colorChanged( const QColor &c ); |
88 | void clear(); | 90 | void clear(); |
89 | void updateCaption( const QString &name=QString::null ); | 91 | void updateCaption( const QString &name=QString::null ); |
90 | void setFontSize(int sz, bool round_down_not_up); | 92 | void setFontSize(int sz, bool round_down_not_up); |
91 | 93 | ||
92 | private: | 94 | private: |
93 | QWidgetStack *editorStack; | 95 | QWidgetStack *editorStack; |
94 | FileSelector *fileSelector; | 96 | FileSelector *fileSelector; |
95 | QpeEditor* editor; | 97 | QpeEditor* editor; |
96 | QToolBar *menu, *editBar, *searchBar; | 98 | QToolBar *menu, *editBar, *searchBar; |
97 | QLineEdit *searchEdit; | 99 | QLineEdit *searchEdit; |
98 | DocLnk *doc; | 100 | DocLnk *doc; |
99 | bool searchVisible; | 101 | bool searchVisible; |
100 | bool bFromDocView; | 102 | bool bFromDocView; |
101 | QAction *zin, *zout; | 103 | QAction *zin, *zout; |
102 | QString currentFileName; | 104 | QString currentFileName; |
103 | }; | 105 | }; |
104 | 106 | ||
105 | #endif | 107 | #endif |