author | llornkcor <llornkcor> | 2002-02-19 01:16:12 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-19 01:16:12 (UTC) |
commit | 05ed9bc7fbd667815e2e3ec608773d19bfd294d2 (patch) (unidiff) | |
tree | 8e32c372231178e96848ba2267195525dd49aaef | |
parent | 2308c4db692821721bbe82f93fd60f275f4cccdc (diff) | |
download | opie-05ed9bc7fbd667815e2e3ec608773d19bfd294d2.zip opie-05ed9bc7fbd667815e2e3ec608773d19bfd294d2.tar.gz opie-05ed9bc7fbd667815e2e3ec608773d19bfd294d2.tar.bz2 |
fixed bug in save (unprompted) saving a new unnamed file...
-rw-r--r-- | core/apps/textedit/textedit.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index e41c69d..2f59ede 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -309,566 +309,569 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
309 | defb = cfg.readBoolEntry("Bold",FALSE); | 309 | defb = cfg.readBoolEntry("Bold",FALSE); |
310 | defi = cfg.readBoolEntry("Italic",FALSE); | 310 | defi = cfg.readBoolEntry("Italic",FALSE); |
311 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 311 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
312 | 312 | ||
313 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 313 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
314 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 314 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
315 | zin->addTo( font ); | 315 | zin->addTo( font ); |
316 | 316 | ||
317 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 317 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
318 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 318 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
319 | zout->addTo( font ); | 319 | zout->addTo( font ); |
320 | 320 | ||
321 | font->insertSeparator(); | 321 | font->insertSeparator(); |
322 | 322 | ||
323 | #if 0 | 323 | #if 0 |
324 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 324 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
325 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 325 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
326 | ba->setToggleAction(TRUE); | 326 | ba->setToggleAction(TRUE); |
327 | ba->addTo( font ); | 327 | ba->addTo( font ); |
328 | 328 | ||
329 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 329 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
330 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 330 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
331 | ia->setToggleAction(TRUE); | 331 | ia->setToggleAction(TRUE); |
332 | ia->addTo( font ); | 332 | ia->addTo( font ); |
333 | 333 | ||
334 | ba->setOn(defb); | 334 | ba->setOn(defb); |
335 | ia->setOn(defi); | 335 | ia->setOn(defi); |
336 | 336 | ||
337 | font->insertSeparator(); | 337 | font->insertSeparator(); |
338 | #endif | 338 | #endif |
339 | 339 | ||
340 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 340 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
341 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 341 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
342 | wa->setToggleAction(TRUE); | 342 | wa->setToggleAction(TRUE); |
343 | wa->addTo( font ); | 343 | wa->addTo( font ); |
344 | 344 | ||
345 | font->insertSeparator(); | 345 | font->insertSeparator(); |
346 | font->insertItem("Font", this, SLOT(changeFont()) ); | 346 | font->insertItem("Font", this, SLOT(changeFont()) ); |
347 | 347 | ||
348 | mb->insertItem( tr( "File" ), file ); | 348 | mb->insertItem( tr( "File" ), file ); |
349 | mb->insertItem( tr( "Edit" ), edit ); | 349 | mb->insertItem( tr( "Edit" ), edit ); |
350 | mb->insertItem( tr( "View" ), font ); | 350 | mb->insertItem( tr( "View" ), font ); |
351 | 351 | ||
352 | searchBar = new QPEToolBar(this); | 352 | searchBar = new QPEToolBar(this); |
353 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 353 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
354 | 354 | ||
355 | searchBar->setHorizontalStretchable( TRUE ); | 355 | searchBar->setHorizontalStretchable( TRUE ); |
356 | 356 | ||
357 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 357 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
358 | searchBar->setStretchableWidget( searchEdit ); | 358 | searchBar->setStretchableWidget( searchEdit ); |
359 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 359 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
360 | this, SLOT( search() ) ); | 360 | this, SLOT( search() ) ); |
361 | 361 | ||
362 | 362 | ||
363 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 363 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
364 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 364 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
365 | a->addTo( searchBar ); | 365 | a->addTo( searchBar ); |
366 | a->addTo( edit ); | 366 | a->addTo( edit ); |
367 | 367 | ||
368 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 368 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
369 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 369 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
370 | a->addTo( searchBar ); | 370 | a->addTo( searchBar ); |
371 | 371 | ||
372 | edit->insertSeparator(); | 372 | edit->insertSeparator(); |
373 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "delete" ), QString::null, 0, this, 0 ); | 373 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "delete" ), QString::null, 0, this, 0 ); |
374 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 374 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
375 | a->addTo( edit ); | 375 | a->addTo( edit ); |
376 | 376 | ||
377 | searchBar->hide(); | 377 | searchBar->hide(); |
378 | 378 | ||
379 | editorStack = new QWidgetStack( this ); | 379 | editorStack = new QWidgetStack( this ); |
380 | setCentralWidget( editorStack ); | 380 | setCentralWidget( editorStack ); |
381 | 381 | ||
382 | searchVisible = FALSE; | 382 | searchVisible = FALSE; |
383 | 383 | ||
384 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | 384 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
385 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 385 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
386 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 386 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
387 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 387 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
388 | // fileOpen(); | 388 | // fileOpen(); |
389 | 389 | ||
390 | editor = new QpeEditor( editorStack ); | 390 | editor = new QpeEditor( editorStack ); |
391 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 391 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
392 | editorStack->addWidget( editor, get_unique_id() ); | 392 | editorStack->addWidget( editor, get_unique_id() ); |
393 | 393 | ||
394 | resize( 200, 300 ); | 394 | resize( 200, 300 ); |
395 | 395 | ||
396 | // setFontSize(defsize,TRUE); | 396 | // setFontSize(defsize,TRUE); |
397 | FontDatabase fdb; | 397 | FontDatabase fdb; |
398 | QFont defaultFont=editor->font(); | 398 | QFont defaultFont=editor->font(); |
399 | QFontInfo fontInfo(defaultFont); | 399 | QFontInfo fontInfo(defaultFont); |
400 | 400 | ||
401 | cfg.setGroup("Font"); | 401 | cfg.setGroup("Font"); |
402 | QString family = cfg.readEntry("Family", fontInfo.family()); | 402 | QString family = cfg.readEntry("Family", fontInfo.family()); |
403 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 403 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
404 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 404 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
405 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 405 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
406 | 406 | ||
407 | defaultFont = fdb.font(family,style,i_size,charSet); | 407 | defaultFont = fdb.font(family,style,i_size,charSet); |
408 | editor->setFont( defaultFont); | 408 | editor->setFont( defaultFont); |
409 | 409 | ||
410 | wa->setOn(wrap); | 410 | wa->setOn(wrap); |
411 | updateCaption(); | 411 | updateCaption(); |
412 | 412 | ||
413 | fileNew(); | 413 | fileNew(); |
414 | } | 414 | } |
415 | 415 | ||
416 | TextEdit::~TextEdit() | 416 | TextEdit::~TextEdit() |
417 | { | 417 | { |
418 | // saveAs(); | 418 | // saveAs(); |
419 | 419 | ||
420 | Config cfg("TextEdit"); | 420 | Config cfg("TextEdit"); |
421 | cfg.setGroup("View"); | 421 | cfg.setGroup("View"); |
422 | QFont f = editor->font(); | 422 | QFont f = editor->font(); |
423 | cfg.writeEntry("FontSize",f.pointSize()); | 423 | cfg.writeEntry("FontSize",f.pointSize()); |
424 | cfg.writeEntry("Bold",f.bold()); | 424 | cfg.writeEntry("Bold",f.bold()); |
425 | cfg.writeEntry("Italic",f.italic()); | 425 | cfg.writeEntry("Italic",f.italic()); |
426 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 426 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
427 | } | 427 | } |
428 | 428 | ||
429 | void TextEdit::zoomIn() | 429 | void TextEdit::zoomIn() |
430 | { | 430 | { |
431 | setFontSize(editor->font().pointSize()+1,FALSE); | 431 | setFontSize(editor->font().pointSize()+1,FALSE); |
432 | } | 432 | } |
433 | 433 | ||
434 | void TextEdit::zoomOut() | 434 | void TextEdit::zoomOut() |
435 | { | 435 | { |
436 | setFontSize(editor->font().pointSize()-1,TRUE); | 436 | setFontSize(editor->font().pointSize()-1,TRUE); |
437 | } | 437 | } |
438 | 438 | ||
439 | 439 | ||
440 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 440 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
441 | { | 441 | { |
442 | int s=10; | 442 | int s=10; |
443 | for (int i=0; i<nfontsizes; i++) { | 443 | for (int i=0; i<nfontsizes; i++) { |
444 | if ( fontsize[i] == sz ) { | 444 | if ( fontsize[i] == sz ) { |
445 | s = sz; | 445 | s = sz; |
446 | break; | 446 | break; |
447 | } else if ( round_down_not_up ) { | 447 | } else if ( round_down_not_up ) { |
448 | if ( fontsize[i] < sz ) | 448 | if ( fontsize[i] < sz ) |
449 | s = fontsize[i]; | 449 | s = fontsize[i]; |
450 | } else { | 450 | } else { |
451 | if ( fontsize[i] > sz ) { | 451 | if ( fontsize[i] > sz ) { |
452 | s = fontsize[i]; | 452 | s = fontsize[i]; |
453 | break; | 453 | break; |
454 | } | 454 | } |
455 | } | 455 | } |
456 | } | 456 | } |
457 | 457 | ||
458 | QFont f = editor->font(); | 458 | QFont f = editor->font(); |
459 | f.setPointSize(s); | 459 | f.setPointSize(s); |
460 | editor->setFont(f); | 460 | editor->setFont(f); |
461 | 461 | ||
462 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 462 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
463 | zout->setEnabled(s != fontsize[0]); | 463 | zout->setEnabled(s != fontsize[0]); |
464 | } | 464 | } |
465 | 465 | ||
466 | void TextEdit::setBold(bool y) | 466 | void TextEdit::setBold(bool y) |
467 | { | 467 | { |
468 | QFont f = editor->font(); | 468 | QFont f = editor->font(); |
469 | f.setBold(y); | 469 | f.setBold(y); |
470 | editor->setFont(f); | 470 | editor->setFont(f); |
471 | } | 471 | } |
472 | 472 | ||
473 | void TextEdit::setItalic(bool y) | 473 | void TextEdit::setItalic(bool y) |
474 | { | 474 | { |
475 | QFont f = editor->font(); | 475 | QFont f = editor->font(); |
476 | f.setItalic(y); | 476 | f.setItalic(y); |
477 | editor->setFont(f); | 477 | editor->setFont(f); |
478 | } | 478 | } |
479 | 479 | ||
480 | void TextEdit::setWordWrap(bool y) | 480 | void TextEdit::setWordWrap(bool y) |
481 | { | 481 | { |
482 | bool state = editor->edited(); | 482 | bool state = editor->edited(); |
483 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 483 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
484 | editor->setEdited( state ); | 484 | editor->setEdited( state ); |
485 | } | 485 | } |
486 | 486 | ||
487 | void TextEdit::fileNew() | 487 | void TextEdit::fileNew() |
488 | { | 488 | { |
489 | if( !bFromDocView ) { | 489 | if( !bFromDocView ) { |
490 | saveAs(); | 490 | saveAs(); |
491 | } | 491 | } |
492 | newFile(DocLnk()); | 492 | newFile(DocLnk()); |
493 | } | 493 | } |
494 | 494 | ||
495 | void TextEdit::fileOpen() | 495 | void TextEdit::fileOpen() |
496 | { | 496 | { |
497 | // if ( !save() ) { | 497 | // if ( !save() ) { |
498 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 498 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
499 | // tr( "Text Editor was unable to\n" | 499 | // tr( "Text Editor was unable to\n" |
500 | // "save your changes.\n" | 500 | // "save your changes.\n" |
501 | // "Free some space and try again.\n" | 501 | // "Free some space and try again.\n" |
502 | // "\nContinue anyway?" ), | 502 | // "\nContinue anyway?" ), |
503 | // QMessageBox::Yes|QMessageBox::Escape, | 503 | // QMessageBox::Yes|QMessageBox::Escape, |
504 | // QMessageBox::No|QMessageBox::Default ) | 504 | // QMessageBox::No|QMessageBox::Default ) |
505 | // != QMessageBox::Yes ) | 505 | // != QMessageBox::Yes ) |
506 | // return; | 506 | // return; |
507 | // else { | 507 | // else { |
508 | // delete doc; | 508 | // delete doc; |
509 | // doc = 0; | 509 | // doc = 0; |
510 | // } | 510 | // } |
511 | // } | 511 | // } |
512 | menu->hide(); | 512 | menu->hide(); |
513 | editBar->hide(); | 513 | editBar->hide(); |
514 | searchBar->hide(); | 514 | searchBar->hide(); |
515 | clearWState (WState_Reserved1 ); | 515 | clearWState (WState_Reserved1 ); |
516 | editorStack->raiseWidget( fileSelector ); | 516 | editorStack->raiseWidget( fileSelector ); |
517 | fileSelector->reread(); | 517 | fileSelector->reread(); |
518 | updateCaption(); | 518 | updateCaption(); |
519 | } | 519 | } |
520 | 520 | ||
521 | void TextEdit::newFileOpen() | 521 | void TextEdit::newFileOpen() |
522 | { | 522 | { |
523 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); | 523 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); |
524 | if( browseForFiles->exec() != -1 ) { | 524 | if( browseForFiles->exec() != -1 ) { |
525 | QString selFile= browseForFiles->selectedFileName; | 525 | QString selFile= browseForFiles->selectedFileName; |
526 | QStringList fileList=browseForFiles->fileList; | 526 | QStringList fileList=browseForFiles->fileList; |
527 | qDebug(selFile); | 527 | qDebug(selFile); |
528 | QStringList::ConstIterator f; | 528 | QStringList::ConstIterator f; |
529 | QString fileTemp; | 529 | QString fileTemp; |
530 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 530 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
531 | fileTemp = *f; | 531 | fileTemp = *f; |
532 | fileTemp.right( fileTemp.length()-5); | 532 | fileTemp.right( fileTemp.length()-5); |
533 | QString fileName = fileTemp; | 533 | QString fileName = fileTemp; |
534 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 534 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
535 | currentFileName = fileName; | 535 | currentFileName = fileName; |
536 | // qDebug("please open "+currentFileName); | 536 | // qDebug("please open "+currentFileName); |
537 | openFile(fileName ); | 537 | openFile(fileName ); |
538 | } | 538 | } |
539 | } | 539 | } |
540 | } | 540 | } |
541 | delete browseForFiles; | 541 | delete browseForFiles; |
542 | editor->setEdited( true ); | 542 | editor->setEdited( true ); |
543 | } | 543 | } |
544 | 544 | ||
545 | #if 0 | 545 | #if 0 |
546 | void TextEdit::slotFind() | 546 | void TextEdit::slotFind() |
547 | { | 547 | { |
548 | FindDialog frmFind( "Text Editor", this ); | 548 | FindDialog frmFind( "Text Editor", this ); |
549 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 549 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
550 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 550 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
551 | 551 | ||
552 | //case sensitive, backwards, [category] | 552 | //case sensitive, backwards, [category] |
553 | 553 | ||
554 | connect( editor, SIGNAL(notFound()), | 554 | connect( editor, SIGNAL(notFound()), |
555 | &frmFind, SLOT(slotNotFound()) ); | 555 | &frmFind, SLOT(slotNotFound()) ); |
556 | connect( editor, SIGNAL(searchWrapped()), | 556 | connect( editor, SIGNAL(searchWrapped()), |
557 | &frmFind, SLOT(slotWrapAround()) ); | 557 | &frmFind, SLOT(slotWrapAround()) ); |
558 | 558 | ||
559 | frmFind.exec(); | 559 | frmFind.exec(); |
560 | 560 | ||
561 | 561 | ||
562 | } | 562 | } |
563 | #endif | 563 | #endif |
564 | 564 | ||
565 | void TextEdit::fileRevert() | 565 | void TextEdit::fileRevert() |
566 | { | 566 | { |
567 | clear(); | 567 | clear(); |
568 | fileOpen(); | 568 | fileOpen(); |
569 | } | 569 | } |
570 | 570 | ||
571 | void TextEdit::editCut() | 571 | void TextEdit::editCut() |
572 | { | 572 | { |
573 | #ifndef QT_NO_CLIPBOARD | 573 | #ifndef QT_NO_CLIPBOARD |
574 | editor->cut(); | 574 | editor->cut(); |
575 | #endif | 575 | #endif |
576 | } | 576 | } |
577 | 577 | ||
578 | void TextEdit::editCopy() | 578 | void TextEdit::editCopy() |
579 | { | 579 | { |
580 | #ifndef QT_NO_CLIPBOARD | 580 | #ifndef QT_NO_CLIPBOARD |
581 | editor->copy(); | 581 | editor->copy(); |
582 | #endif | 582 | #endif |
583 | } | 583 | } |
584 | 584 | ||
585 | void TextEdit::editPaste() | 585 | void TextEdit::editPaste() |
586 | { | 586 | { |
587 | #ifndef QT_NO_CLIPBOARD | 587 | #ifndef QT_NO_CLIPBOARD |
588 | editor->paste(); | 588 | editor->paste(); |
589 | #endif | 589 | #endif |
590 | } | 590 | } |
591 | 591 | ||
592 | void TextEdit::editFind() | 592 | void TextEdit::editFind() |
593 | { | 593 | { |
594 | searchBar->show(); | 594 | searchBar->show(); |
595 | searchVisible = TRUE; | 595 | searchVisible = TRUE; |
596 | searchEdit->setFocus(); | 596 | searchEdit->setFocus(); |
597 | } | 597 | } |
598 | 598 | ||
599 | void TextEdit::findNext() | 599 | void TextEdit::findNext() |
600 | { | 600 | { |
601 | editor->find( searchEdit->text(), FALSE, FALSE ); | 601 | editor->find( searchEdit->text(), FALSE, FALSE ); |
602 | 602 | ||
603 | } | 603 | } |
604 | 604 | ||
605 | void TextEdit::findClose() | 605 | void TextEdit::findClose() |
606 | { | 606 | { |
607 | searchVisible = FALSE; | 607 | searchVisible = FALSE; |
608 | searchBar->hide(); | 608 | searchBar->hide(); |
609 | } | 609 | } |
610 | 610 | ||
611 | void TextEdit::search() | 611 | void TextEdit::search() |
612 | { | 612 | { |
613 | editor->find( searchEdit->text(), FALSE, FALSE ); | 613 | editor->find( searchEdit->text(), FALSE, FALSE ); |
614 | } | 614 | } |
615 | 615 | ||
616 | void TextEdit::newFile( const DocLnk &f ) | 616 | void TextEdit::newFile( const DocLnk &f ) |
617 | { | 617 | { |
618 | DocLnk nf = f; | 618 | DocLnk nf = f; |
619 | nf.setType("text/plain"); | 619 | nf.setType("text/plain"); |
620 | clear(); | 620 | clear(); |
621 | editorStack->raiseWidget( editor ); | 621 | editorStack->raiseWidget( editor ); |
622 | setWState (WState_Reserved1 ); | 622 | setWState (WState_Reserved1 ); |
623 | editor->setFocus(); | 623 | editor->setFocus(); |
624 | doc = new DocLnk(nf); | 624 | doc = new DocLnk(nf); |
625 | qDebug("newFile "+currentFileName); | 625 | qDebug("newFile "+currentFileName); |
626 | updateCaption(currentFileName); | 626 | updateCaption(currentFileName); |
627 | } | 627 | } |
628 | 628 | ||
629 | void TextEdit::openFile( const QString &f ) | 629 | void TextEdit::openFile( const QString &f ) |
630 | { | 630 | { |
631 | bFromDocView = TRUE; | 631 | bFromDocView = TRUE; |
632 | DocLnk nf; | 632 | DocLnk nf; |
633 | nf.setType("text/plain"); | 633 | nf.setType("text/plain"); |
634 | nf.setFile(f); | 634 | nf.setFile(f); |
635 | currentFileName=f; | 635 | currentFileName=f; |
636 | qDebug("openFile string"+currentFileName); | 636 | qDebug("openFile string"+currentFileName); |
637 | 637 | ||
638 | openFile(nf); | 638 | openFile(nf); |
639 | showEditTools(); | 639 | showEditTools(); |
640 | // Show filename in caption | 640 | // Show filename in caption |
641 | QString name = f; | 641 | QString name = f; |
642 | int sep = name.findRev( '/' ); | 642 | int sep = name.findRev( '/' ); |
643 | if ( sep > 0 ) | 643 | if ( sep > 0 ) |
644 | name = name.mid( sep+1 ); | 644 | name = name.mid( sep+1 ); |
645 | updateCaption( name ); | 645 | updateCaption( name ); |
646 | } | 646 | } |
647 | 647 | ||
648 | void TextEdit::openFile( const DocLnk &f ) | 648 | void TextEdit::openFile( const DocLnk &f ) |
649 | { | 649 | { |
650 | // clear(); | 650 | // clear(); |
651 | bFromDocView = TRUE; | 651 | bFromDocView = TRUE; |
652 | FileManager fm; | 652 | FileManager fm; |
653 | QString txt; | 653 | QString txt; |
654 | currentFileName=f.name(); | 654 | currentFileName=f.name(); |
655 | qDebug("openFile doclnk " + currentFileName); | 655 | qDebug("openFile doclnk " + currentFileName); |
656 | if ( !fm.loadFile( f, txt ) ) { | 656 | if ( !fm.loadFile( f, txt ) ) { |
657 | // ####### could be a new file | 657 | // ####### could be a new file |
658 | qDebug( "Cannot open file" ); | 658 | qDebug( "Cannot open file" ); |
659 | 659 | ||
660 | //return; | 660 | //return; |
661 | } | 661 | } |
662 | 662 | ||
663 | fileNew(); | 663 | fileNew(); |
664 | if ( doc ) | 664 | if ( doc ) |
665 | delete doc; | 665 | delete doc; |
666 | doc = new DocLnk(f); | 666 | doc = new DocLnk(f); |
667 | editor->setText(txt); | 667 | editor->setText(txt); |
668 | editor->setEdited( false); | 668 | editor->setEdited( false); |
669 | qDebug("openFile doclnk "+currentFileName); | 669 | qDebug("openFile doclnk "+currentFileName); |
670 | doc->setName(currentFileName); | 670 | doc->setName(currentFileName); |
671 | updateCaption(); | 671 | updateCaption(); |
672 | } | 672 | } |
673 | 673 | ||
674 | void TextEdit::showEditTools() | 674 | void TextEdit::showEditTools() |
675 | { | 675 | { |
676 | // if ( !doc ) | 676 | // if ( !doc ) |
677 | // close(); | 677 | // close(); |
678 | // clear(); | 678 | // clear(); |
679 | fileSelector->hide(); | 679 | fileSelector->hide(); |
680 | menu->show(); | 680 | menu->show(); |
681 | editBar->show(); | 681 | editBar->show(); |
682 | if ( searchVisible ) | 682 | if ( searchVisible ) |
683 | searchBar->show(); | 683 | searchBar->show(); |
684 | // updateCaption(); | 684 | // updateCaption(); |
685 | editorStack->raiseWidget( editor ); | 685 | editorStack->raiseWidget( editor ); |
686 | setWState (WState_Reserved1 ); | 686 | setWState (WState_Reserved1 ); |
687 | } | 687 | } |
688 | 688 | ||
689 | /*! | 689 | /*! |
690 | unprompted save */ | 690 | unprompted save */ |
691 | bool TextEdit::save() | 691 | bool TextEdit::save() |
692 | { | 692 | { |
693 | qDebug("saveFile "+currentFileName); | 693 | QString file = doc->file(); |
694 | 694 | QString name= doc->name(); | |
695 | QString rt = editor->text(); | 695 | QString rt = editor->text(); |
696 | doc->setName( currentFileName); | 696 | currentFileName= file ; |
697 | qDebug("saveFile "+currentFileName); | ||
698 | |||
699 | doc->setName( name); | ||
697 | FileManager fm; | 700 | FileManager fm; |
698 | if ( !fm.saveFile( *doc, rt ) ) { | 701 | if ( !fm.saveFile( *doc, rt ) ) { |
699 | return false; | 702 | return false; |
700 | } | 703 | } |
701 | // if(doc) | 704 | // if(doc) |
702 | // delete doc; | 705 | // delete doc; |
703 | // doc = 0; | 706 | // doc = 0; |
704 | editor->setEdited( false ); | 707 | editor->setEdited( false ); |
705 | return true; | 708 | return true; |
706 | } | 709 | } |
707 | 710 | ||
708 | /*! | 711 | /*! |
709 | prompted save */ | 712 | prompted save */ |
710 | bool TextEdit::saveAs() | 713 | bool TextEdit::saveAs() |
711 | { | 714 | { |
712 | qDebug("saveAsFile "+currentFileName); | 715 | qDebug("saveAsFile "+currentFileName); |
713 | 716 | ||
714 | // case of nothing to save... /// there's always something to save | 717 | // case of nothing to save... /// there's always something to save |
715 | // if ( !doc )//|| !bFromDocView) | 718 | // if ( !doc )//|| !bFromDocView) |
716 | // { | 719 | // { |
717 | // qDebug("no doc"); | 720 | // qDebug("no doc"); |
718 | // return true; | 721 | // return true; |
719 | // } | 722 | // } |
720 | if ( !editor->edited() ) { | 723 | if ( !editor->edited() ) { |
721 | delete doc; | 724 | delete doc; |
722 | doc = 0; | 725 | doc = 0; |
723 | return true; | 726 | return true; |
724 | } | 727 | } |
725 | 728 | ||
726 | QString rt = editor->text(); | 729 | QString rt = editor->text(); |
727 | qDebug(currentFileName); | 730 | qDebug(currentFileName); |
728 | 731 | ||
729 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 732 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
730 | qDebug("do silly TT filename thing"); | 733 | qDebug("do silly TT filename thing"); |
731 | if ( doc->name().isEmpty() ) { | 734 | if ( doc->name().isEmpty() ) { |
732 | QString pt = rt.simplifyWhiteSpace(); | 735 | QString pt = rt.simplifyWhiteSpace(); |
733 | int i = pt.find( ' ' ); | 736 | int i = pt.find( ' ' ); |
734 | QString docname = pt; | 737 | QString docname = pt; |
735 | if ( i > 0 ) | 738 | if ( i > 0 ) |
736 | docname = pt.left( i ); | 739 | docname = pt.left( i ); |
737 | // remove "." at the beginning | 740 | // remove "." at the beginning |
738 | while( docname.startsWith( "." ) ) | 741 | while( docname.startsWith( "." ) ) |
739 | docname = docname.mid( 1 ); | 742 | docname = docname.mid( 1 ); |
740 | docname.replace( QRegExp("/"), "_" ); | 743 | docname.replace( QRegExp("/"), "_" ); |
741 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 744 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
742 | if ( docname.length() > 40 ) | 745 | if ( docname.length() > 40 ) |
743 | docname = docname.left(40); | 746 | docname = docname.left(40); |
744 | if ( docname.isEmpty() ) | 747 | if ( docname.isEmpty() ) |
745 | docname = "Unnamed"; | 748 | docname = "Unnamed"; |
746 | doc->setName(docname); | 749 | doc->setName(docname); |
747 | currentFileName=docname; | 750 | currentFileName=docname; |
748 | } | 751 | } |
749 | } | 752 | } |
750 | 753 | ||
751 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | 754 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); |
752 | qDebug("wanna save filename "+currentFileName); | 755 | qDebug("wanna save filename "+currentFileName); |
753 | fileSaveDlg->exec(); | 756 | fileSaveDlg->exec(); |
754 | if( fileSaveDlg->result() == 1 ) { | 757 | if( fileSaveDlg->result() == 1 ) { |
755 | QString fileNm=fileSaveDlg->selectedFileName; | 758 | QString fileNm=fileSaveDlg->selectedFileName; |
756 | qDebug("saving filename "+fileNm); | 759 | qDebug("saving filename "+fileNm); |
757 | QFileInfo fi(fileNm); | 760 | QFileInfo fi(fileNm); |
758 | currentFileName=fi.fileName(); | 761 | currentFileName=fi.fileName(); |
759 | if(doc) { | 762 | if(doc) { |
760 | qDebug("doclnk exists"); | 763 | qDebug("doclnk exists"); |
761 | // QString file = doc->file(); | 764 | // QString file = doc->file(); |
762 | // doc->removeFiles(); | 765 | // doc->removeFiles(); |
763 | delete doc; | 766 | delete doc; |
764 | DocLnk nf; | 767 | DocLnk nf; |
765 | nf.setType("text/plain"); | 768 | nf.setType("text/plain"); |
766 | nf.setFile( fileNm); | 769 | nf.setFile( fileNm); |
767 | doc = new DocLnk(nf); | 770 | doc = new DocLnk(nf); |
768 | // editor->setText(rt); | 771 | // editor->setText(rt); |
769 | qDebug("openFile doclnk "+currentFileName); | 772 | qDebug("openFile doclnk "+currentFileName); |
770 | } | 773 | } |
771 | doc->setName( currentFileName); | 774 | doc->setName( currentFileName); |
772 | updateCaption( currentFileName); | 775 | updateCaption( currentFileName); |
773 | 776 | ||
774 | FileManager fm; | 777 | FileManager fm; |
775 | if ( !fm.saveFile( *doc, rt ) ) { | 778 | if ( !fm.saveFile( *doc, rt ) ) { |
776 | return false; | 779 | return false; |
777 | } | 780 | } |
778 | // delete doc; | 781 | // delete doc; |
779 | // doc = 0; | 782 | // doc = 0; |
780 | editor->setEdited( false ); | 783 | editor->setEdited( false ); |
781 | } | 784 | } |
782 | if(fileSaveDlg) | 785 | if(fileSaveDlg) |
783 | delete fileSaveDlg; | 786 | delete fileSaveDlg; |
784 | return true; | 787 | return true; |
785 | } | 788 | } |
786 | 789 | ||
787 | void TextEdit::clear() | 790 | void TextEdit::clear() |
788 | { | 791 | { |
789 | delete doc; | 792 | delete doc; |
790 | doc = 0; | 793 | doc = 0; |
791 | editor->clear(); | 794 | editor->clear(); |
792 | } | 795 | } |
793 | 796 | ||
794 | void TextEdit::updateCaption( const QString &name ) | 797 | void TextEdit::updateCaption( const QString &name ) |
795 | { | 798 | { |
796 | if ( !doc ) | 799 | if ( !doc ) |
797 | setCaption( tr("Text Editor") ); | 800 | setCaption( tr("Text Editor") ); |
798 | else { | 801 | else { |
799 | QString s = name; | 802 | QString s = name; |
800 | if ( s.isNull() ) | 803 | if ( s.isNull() ) |
801 | s = doc->name(); | 804 | s = doc->name(); |
802 | if ( s.isEmpty() ) { | 805 | if ( s.isEmpty() ) { |
803 | s = tr( "Unnamed" ); | 806 | s = tr( "Unnamed" ); |
804 | currentFileName=s; | 807 | currentFileName=s; |
805 | } | 808 | } |
806 | 809 | ||
807 | setCaption( s + " - " + tr("Text Editor") ); | 810 | setCaption( s + " - " + tr("Text Editor") ); |
808 | } | 811 | } |
809 | } | 812 | } |
810 | 813 | ||
811 | void TextEdit::setDocument(const QString& fileref) | 814 | void TextEdit::setDocument(const QString& fileref) |
812 | { | 815 | { |
813 | bFromDocView = TRUE; | 816 | bFromDocView = TRUE; |
814 | openFile(DocLnk(fileref)); | 817 | openFile(DocLnk(fileref)); |
815 | // showEditTools(); | 818 | // showEditTools(); |
816 | } | 819 | } |
817 | 820 | ||
818 | void TextEdit::closeEvent( QCloseEvent *e ) | 821 | void TextEdit::closeEvent( QCloseEvent *e ) |
819 | { | 822 | { |
820 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 823 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
821 | e->ignore(); | 824 | e->ignore(); |
822 | repaint(); | 825 | repaint(); |
823 | // fileRevert(); | 826 | // fileRevert(); |
824 | 827 | ||
825 | } else { | 828 | } else { |
826 | bFromDocView = FALSE; | 829 | bFromDocView = FALSE; |
827 | e->accept(); | 830 | e->accept(); |
828 | } | 831 | } |
829 | } | 832 | } |
830 | 833 | ||
831 | void TextEdit::accept() | 834 | void TextEdit::accept() |
832 | { | 835 | { |
833 | close(); | 836 | close(); |
834 | // fileOpen(); //godamn thats obnoxious! lemme out!!! | 837 | // fileOpen(); //godamn thats obnoxious! lemme out!!! |
835 | } | 838 | } |
836 | 839 | ||
837 | void TextEdit::changeFont() { | 840 | void TextEdit::changeFont() { |
838 | FontDatabase fdb; | 841 | FontDatabase fdb; |
839 | QFont defaultFont=editor->font(); | 842 | QFont defaultFont=editor->font(); |
840 | QFontInfo fontInfo(defaultFont); | 843 | QFontInfo fontInfo(defaultFont); |
841 | Config cfg("TextEdit"); | 844 | Config cfg("TextEdit"); |
842 | cfg.setGroup("Font"); | 845 | cfg.setGroup("Font"); |
843 | QString family = cfg.readEntry("Family", fontInfo.family()); | 846 | QString family = cfg.readEntry("Family", fontInfo.family()); |
844 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 847 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
845 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 848 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
846 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 849 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
847 | 850 | ||
848 | defaultFont = fdb.font(family,style,i_size,charSet); | 851 | defaultFont = fdb.font(family,style,i_size,charSet); |
849 | 852 | ||
850 | FontDialog *fontDlg; | 853 | FontDialog *fontDlg; |
851 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 854 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
852 | 855 | ||
853 | fontDlg->exec(); | 856 | fontDlg->exec(); |
854 | 857 | ||
855 | QFont myFont=fontDlg->selectedFont; | 858 | QFont myFont=fontDlg->selectedFont; |
856 | editor->setFont( myFont); | 859 | editor->setFont( myFont); |
857 | delete fontDlg; | 860 | delete fontDlg; |
858 | 861 | ||
859 | } | 862 | } |
860 | 863 | ||
861 | void TextEdit::editDelete() | 864 | void TextEdit::editDelete() |
862 | { | 865 | { |
863 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 866 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
864 | case 0: | 867 | case 0: |
865 | if(doc) { | 868 | if(doc) { |
866 | doc->removeFiles(); | 869 | doc->removeFiles(); |
867 | clear(); | 870 | clear(); |
868 | } | 871 | } |
869 | break; | 872 | break; |
870 | case 1: | 873 | case 1: |
871 | // exit | 874 | // exit |
872 | break; | 875 | break; |
873 | }; | 876 | }; |
874 | } | 877 | } |