-rw-r--r-- | core/apps/textedit/textedit.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index af427ac..bd7cfb6 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -460,324 +460,331 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
460 | } | 460 | } |
461 | 461 | ||
462 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 462 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
463 | // setCaption(tr("Text Editor")); | 463 | // setCaption(tr("Text Editor")); |
464 | } | 464 | } |
465 | 465 | ||
466 | TextEdit::~TextEdit() { | 466 | TextEdit::~TextEdit() { |
467 | // qDebug("destr"); | 467 | // qDebug("destr"); |
468 | } | 468 | } |
469 | 469 | ||
470 | void TextEdit::closeEvent(QCloseEvent *) { | 470 | void TextEdit::closeEvent(QCloseEvent *) { |
471 | // qDebug("closing here"); | 471 | // qDebug("closing here"); |
472 | if( edited1 && promptExit) | 472 | if( edited1 && promptExit) |
473 | saveAs(); | 473 | saveAs(); |
474 | qApp->quit(); | 474 | qApp->quit(); |
475 | } | 475 | } |
476 | 476 | ||
477 | void TextEdit::cleanUp() { | 477 | void TextEdit::cleanUp() { |
478 | // qDebug("cleanUp");// save(); | 478 | // qDebug("cleanUp");// save(); |
479 | 479 | ||
480 | Config cfg ( "TextEdit" ); | 480 | Config cfg ( "TextEdit" ); |
481 | cfg. setGroup ( "Font" ); | 481 | cfg. setGroup ( "Font" ); |
482 | QFont f = editor->font(); | 482 | QFont f = editor->font(); |
483 | cfg.writeEntry ( "Family", f. family ( )); | 483 | cfg.writeEntry ( "Family", f. family ( )); |
484 | cfg.writeEntry ( "Size", f. pointSize ( )); | 484 | cfg.writeEntry ( "Size", f. pointSize ( )); |
485 | cfg.writeEntry ( "Weight", f. weight ( )); | 485 | cfg.writeEntry ( "Weight", f. weight ( )); |
486 | cfg.writeEntry ( "Italic", f. italic ( )); | 486 | cfg.writeEntry ( "Italic", f. italic ( )); |
487 | 487 | ||
488 | cfg.setGroup ( "View" ); | 488 | cfg.setGroup ( "View" ); |
489 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 489 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
490 | cfg.writeEntry ( "FileView", viewSelection ); | 490 | cfg.writeEntry ( "FileView", viewSelection ); |
491 | 491 | ||
492 | cfg.writeEntry ( "PromptExit", promptExit ); | 492 | cfg.writeEntry ( "PromptExit", promptExit ); |
493 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 493 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
494 | cfg.writeEntry ( "FilePermissions", filePerms ); | 494 | cfg.writeEntry ( "FilePermissions", filePerms ); |
495 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 495 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
496 | cfg.writeEntry ( "startNew", startWithNew ); | 496 | cfg.writeEntry ( "startNew", startWithNew ); |
497 | 497 | ||
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | void TextEdit::accept() { | 501 | void TextEdit::accept() { |
502 | // qDebug("accept"); | 502 | // qDebug("accept"); |
503 | if( edited1) | 503 | if( edited1) |
504 | saveAs(); | 504 | saveAs(); |
505 | qApp->quit(); | 505 | qApp->quit(); |
506 | } | 506 | } |
507 | 507 | ||
508 | void TextEdit::zoomIn() { | 508 | void TextEdit::zoomIn() { |
509 | setFontSize(editor->font().pointSize()+1,false); | 509 | setFontSize(editor->font().pointSize()+1,false); |
510 | } | 510 | } |
511 | 511 | ||
512 | void TextEdit::zoomOut() { | 512 | void TextEdit::zoomOut() { |
513 | setFontSize(editor->font().pointSize()-1,true); | 513 | setFontSize(editor->font().pointSize()-1,true); |
514 | } | 514 | } |
515 | 515 | ||
516 | 516 | ||
517 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 517 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
518 | int s=10; | 518 | int s=10; |
519 | for (int i=0; i<nfontsizes; i++) { | 519 | for (int i=0; i<nfontsizes; i++) { |
520 | if ( fontsize[i] == sz ) { | 520 | if ( fontsize[i] == sz ) { |
521 | s = sz; | 521 | s = sz; |
522 | break; | 522 | break; |
523 | } else if ( round_down_not_up ) { | 523 | } else if ( round_down_not_up ) { |
524 | if ( fontsize[i] < sz ) | 524 | if ( fontsize[i] < sz ) |
525 | s = fontsize[i]; | 525 | s = fontsize[i]; |
526 | } else { | 526 | } else { |
527 | if ( fontsize[i] > sz ) { | 527 | if ( fontsize[i] > sz ) { |
528 | s = fontsize[i]; | 528 | s = fontsize[i]; |
529 | break; | 529 | break; |
530 | } | 530 | } |
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | QFont f = editor->font(); | 534 | QFont f = editor->font(); |
535 | f.setPointSize(s); | 535 | f.setPointSize(s); |
536 | editor->setFont(f); | 536 | editor->setFont(f); |
537 | 537 | ||
538 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 538 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
539 | zout->setEnabled(s != fontsize[0]); | 539 | zout->setEnabled(s != fontsize[0]); |
540 | } | 540 | } |
541 | 541 | ||
542 | void TextEdit::setBold(bool y) { | 542 | void TextEdit::setBold(bool y) { |
543 | QFont f = editor->font(); | 543 | QFont f = editor->font(); |
544 | f.setBold(y); | 544 | f.setBold(y); |
545 | editor->setFont(f); | 545 | editor->setFont(f); |
546 | } | 546 | } |
547 | 547 | ||
548 | void TextEdit::setItalic(bool y) { | 548 | void TextEdit::setItalic(bool y) { |
549 | QFont f = editor->font(); | 549 | QFont f = editor->font(); |
550 | f.setItalic(y); | 550 | f.setItalic(y); |
551 | editor->setFont(f); | 551 | editor->setFont(f); |
552 | } | 552 | } |
553 | 553 | ||
554 | void TextEdit::setWordWrap(bool y) { | 554 | void TextEdit::setWordWrap(bool y) { |
555 | bool state = editor->edited(); | 555 | bool state = editor->edited(); |
556 | QString captionStr = caption(); | ||
557 | bool b1 = edited1; | ||
558 | bool b2 = edited; | ||
559 | |||
556 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 560 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
557 | editor->setEdited( state ); | 561 | editor->setEdited( state ); |
562 | edited1=b1; | ||
563 | edited=b2; | ||
564 | setCaption(captionStr); | ||
558 | } | 565 | } |
559 | 566 | ||
560 | void TextEdit::setSearchBar(bool b) { | 567 | void TextEdit::setSearchBar(bool b) { |
561 | useSearchBar=b; | 568 | useSearchBar=b; |
562 | Config cfg("TextEdit"); | 569 | Config cfg("TextEdit"); |
563 | cfg.setGroup("View"); | 570 | cfg.setGroup("View"); |
564 | cfg.writeEntry ( "SearchBar", b ); | 571 | cfg.writeEntry ( "SearchBar", b ); |
565 | searchBarAction->setOn(b); | 572 | searchBarAction->setOn(b); |
566 | if(b) | 573 | if(b) |
567 | searchBar->show(); | 574 | searchBar->show(); |
568 | else | 575 | else |
569 | searchBar->hide(); | 576 | searchBar->hide(); |
570 | editor->setFocus(); | 577 | editor->setFocus(); |
571 | } | 578 | } |
572 | 579 | ||
573 | void TextEdit::fileNew() { | 580 | void TextEdit::fileNew() { |
574 | // if( !bFromDocView ) { | 581 | // if( !bFromDocView ) { |
575 | // saveAs(); | 582 | // saveAs(); |
576 | // } | 583 | // } |
577 | newFile(DocLnk()); | 584 | newFile(DocLnk()); |
578 | } | 585 | } |
579 | 586 | ||
580 | void TextEdit::fileOpen() { | 587 | void TextEdit::fileOpen() { |
581 | QMap<QString, QStringList> map; | 588 | QMap<QString, QStringList> map; |
582 | map.insert(tr("All"), QStringList() ); | 589 | map.insert(tr("All"), QStringList() ); |
583 | QStringList text; | 590 | QStringList text; |
584 | text << "text/*"; | 591 | text << "text/*"; |
585 | map.insert(tr("Text"), text ); | 592 | map.insert(tr("Text"), text ); |
586 | text << "*"; | 593 | text << "*"; |
587 | map.insert(tr("All"), text ); | 594 | map.insert(tr("All"), text ); |
588 | QString str = OFileDialog::getOpenFileName( 2, | 595 | QString str = OFileDialog::getOpenFileName( 2, |
589 | QPEApplication::documentDir(), | 596 | QPEApplication::documentDir(), |
590 | QString::null, map); | 597 | QString::null, map); |
591 | if( QFile(str).exists()) | 598 | if( QFile(str).exists()) |
592 | openFile( str ); | 599 | openFile( str ); |
593 | else | 600 | else |
594 | updateCaption(); | 601 | updateCaption(); |
595 | } | 602 | } |
596 | 603 | ||
597 | void TextEdit::doSearchBar() { | 604 | void TextEdit::doSearchBar() { |
598 | if(!useSearchBar) | 605 | if(!useSearchBar) |
599 | searchBar->hide(); | 606 | searchBar->hide(); |
600 | else | 607 | else |
601 | searchBar->show(); | 608 | searchBar->show(); |
602 | } | 609 | } |
603 | 610 | ||
604 | #if 0 | 611 | #if 0 |
605 | void TextEdit::slotFind() { | 612 | void TextEdit::slotFind() { |
606 | FindDialog frmFind( tr("Text Editor"), this ); | 613 | FindDialog frmFind( tr("Text Editor"), this ); |
607 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 614 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
608 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 615 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
609 | 616 | ||
610 | //case sensitive, backwards, [category] | 617 | //case sensitive, backwards, [category] |
611 | 618 | ||
612 | connect( editor, SIGNAL(notFound()), | 619 | connect( editor, SIGNAL(notFound()), |
613 | &frmFind, SLOT(slotNotFound()) ); | 620 | &frmFind, SLOT(slotNotFound()) ); |
614 | connect( editor, SIGNAL(searchWrapped()), | 621 | connect( editor, SIGNAL(searchWrapped()), |
615 | &frmFind, SLOT(slotWrapAround()) ); | 622 | &frmFind, SLOT(slotWrapAround()) ); |
616 | 623 | ||
617 | frmFind.exec(); | 624 | frmFind.exec(); |
618 | 625 | ||
619 | 626 | ||
620 | } | 627 | } |
621 | #endif | 628 | #endif |
622 | 629 | ||
623 | void TextEdit::fileRevert() { | 630 | void TextEdit::fileRevert() { |
624 | clear(); | 631 | clear(); |
625 | fileOpen(); | 632 | fileOpen(); |
626 | } | 633 | } |
627 | 634 | ||
628 | void TextEdit::editCut() { | 635 | void TextEdit::editCut() { |
629 | #ifndef QT_NO_CLIPBOARD | 636 | #ifndef QT_NO_CLIPBOARD |
630 | editor->cut(); | 637 | editor->cut(); |
631 | #endif | 638 | #endif |
632 | } | 639 | } |
633 | 640 | ||
634 | void TextEdit::editCopy() { | 641 | void TextEdit::editCopy() { |
635 | #ifndef QT_NO_CLIPBOARD | 642 | #ifndef QT_NO_CLIPBOARD |
636 | editor->copy(); | 643 | editor->copy(); |
637 | #endif | 644 | #endif |
638 | } | 645 | } |
639 | 646 | ||
640 | void TextEdit::editPaste() { | 647 | void TextEdit::editPaste() { |
641 | #ifndef QT_NO_CLIPBOARD | 648 | #ifndef QT_NO_CLIPBOARD |
642 | editor->paste(); | 649 | editor->paste(); |
643 | #endif | 650 | #endif |
644 | } | 651 | } |
645 | 652 | ||
646 | void TextEdit::editFind() { | 653 | void TextEdit::editFind() { |
647 | searchBar->show(); | 654 | searchBar->show(); |
648 | searchEdit->setFocus(); | 655 | searchEdit->setFocus(); |
649 | } | 656 | } |
650 | 657 | ||
651 | void TextEdit::findNext() { | 658 | void TextEdit::findNext() { |
652 | editor->find( searchEdit->text(), false, false ); | 659 | editor->find( searchEdit->text(), false, false ); |
653 | 660 | ||
654 | } | 661 | } |
655 | 662 | ||
656 | void TextEdit::findClose() { | 663 | void TextEdit::findClose() { |
657 | searchBar->hide(); | 664 | searchBar->hide(); |
658 | } | 665 | } |
659 | 666 | ||
660 | void TextEdit::search() { | 667 | void TextEdit::search() { |
661 | editor->find( searchEdit->text(), false, false ); | 668 | editor->find( searchEdit->text(), false, false ); |
662 | } | 669 | } |
663 | 670 | ||
664 | void TextEdit::newFile( const DocLnk &f ) { | 671 | void TextEdit::newFile( const DocLnk &f ) { |
665 | DocLnk nf = f; | 672 | DocLnk nf = f; |
666 | nf.setType("text/plain"); | 673 | nf.setType("text/plain"); |
667 | clear(); | 674 | clear(); |
668 | setWState (WState_Reserved1 ); | 675 | setWState (WState_Reserved1 ); |
669 | editor->setFocus(); | 676 | editor->setFocus(); |
670 | doc = new DocLnk(nf); | 677 | doc = new DocLnk(nf); |
671 | currentFileName = "Unnamed"; | 678 | currentFileName = "Unnamed"; |
672 | qDebug("newFile "+currentFileName); | 679 | qDebug("newFile "+currentFileName); |
673 | updateCaption( currentFileName); | 680 | updateCaption( currentFileName); |
674 | // editor->setEdited( false); | 681 | // editor->setEdited( false); |
675 | } | 682 | } |
676 | 683 | ||
677 | void TextEdit::openDotFile( const QString &f ) { | 684 | void TextEdit::openDotFile( const QString &f ) { |
678 | if(!currentFileName.isEmpty()) { | 685 | if(!currentFileName.isEmpty()) { |
679 | currentFileName=f; | 686 | currentFileName=f; |
680 | 687 | ||
681 | qDebug("openFile dotfile " + currentFileName); | 688 | qDebug("openFile dotfile " + currentFileName); |
682 | QString txt; | 689 | QString txt; |
683 | QFile file(f); | 690 | QFile file(f); |
684 | file.open(IO_ReadWrite); | 691 | file.open(IO_ReadWrite); |
685 | QTextStream t(&file); | 692 | QTextStream t(&file); |
686 | while ( !t.atEnd()) { | 693 | while ( !t.atEnd()) { |
687 | txt+=t.readLine(); | 694 | txt+=t.readLine()+"\n"; |
688 | } | 695 | } |
689 | editor->setText(txt); | 696 | editor->setText(txt); |
690 | editor->setEdited( false); | 697 | editor->setEdited( false); |
691 | edited1=false; | 698 | edited1=false; |
692 | edited=false; | 699 | edited=false; |
693 | 700 | ||
694 | 701 | ||
695 | } | 702 | } |
696 | updateCaption( currentFileName); | 703 | updateCaption( currentFileName); |
697 | } | 704 | } |
698 | 705 | ||
699 | void TextEdit::openFile( const QString &f ) { | 706 | void TextEdit::openFile( const QString &f ) { |
700 | qDebug("filename is "+ f); | 707 | qDebug("filename is "+ f); |
701 | QString filer; | 708 | QString filer; |
702 | QFileInfo fi( f); | 709 | QFileInfo fi( f); |
703 | // bFromDocView = true; | 710 | // bFromDocView = true; |
704 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { | 711 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) { |
705 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 712 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
706 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> | 713 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> |
707 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 714 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
708 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 715 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
709 | case 0: | 716 | case 0: |
710 | filer = f; | 717 | filer = f; |
711 | break; | 718 | break; |
712 | case 1: | 719 | case 1: |
713 | DocLnk sf(f); | 720 | DocLnk sf(f); |
714 | filer = sf.file(); | 721 | filer = sf.file(); |
715 | break; | 722 | break; |
716 | } | 723 | } |
717 | } else if(fi.baseName().left(1) == "") { | 724 | } else if(fi.baseName().left(1) == "") { |
718 | currentFileName=f; | 725 | currentFileName=f; |
719 | openDotFile(currentFileName); | 726 | openDotFile(currentFileName); |
720 | } else { | 727 | } else { |
721 | DocLnk sf(f); | 728 | DocLnk sf(f); |
722 | filer = sf.file(); | 729 | filer = sf.file(); |
723 | if(filer.right(1) == "/") | 730 | if(filer.right(1) == "/") |
724 | filer = f; | 731 | filer = f; |
725 | } | 732 | } |
726 | 733 | ||
727 | DocLnk nf; | 734 | DocLnk nf; |
728 | nf.setType("text/plain"); | 735 | nf.setType("text/plain"); |
729 | nf.setFile(filer); | 736 | nf.setFile(filer); |
730 | currentFileName=filer; | 737 | currentFileName=filer; |
731 | 738 | ||
732 | nf.setName(fi.baseName()); | 739 | nf.setName(fi.baseName()); |
733 | openFile(nf); | 740 | openFile(nf); |
734 | 741 | ||
735 | qDebug("openFile string "+currentFileName); | 742 | qDebug("openFile string "+currentFileName); |
736 | 743 | ||
737 | showEditTools(); | 744 | showEditTools(); |
738 | // Show filename in caption | 745 | // Show filename in caption |
739 | QString name = filer; | 746 | QString name = filer; |
740 | int sep = name.findRev( '/' ); | 747 | int sep = name.findRev( '/' ); |
741 | if ( sep > 0 ) | 748 | if ( sep > 0 ) |
742 | name = name.mid( sep+1 ); | 749 | name = name.mid( sep+1 ); |
743 | updateCaption( name ); | 750 | updateCaption( name ); |
744 | } | 751 | } |
745 | 752 | ||
746 | void TextEdit::openFile( const DocLnk &f ) { | 753 | void TextEdit::openFile( const DocLnk &f ) { |
747 | // clear(); | 754 | // clear(); |
748 | // bFromDocView = true; | 755 | // bFromDocView = true; |
749 | FileManager fm; | 756 | FileManager fm; |
750 | QString txt; | 757 | QString txt; |
751 | currentFileName=f.file(); | 758 | currentFileName=f.file(); |
752 | qDebug("openFile doclnk " + currentFileName); | 759 | qDebug("openFile doclnk " + currentFileName); |
753 | if ( !fm.loadFile( f, txt ) ) { | 760 | if ( !fm.loadFile( f, txt ) ) { |
754 | // ####### could be a new file | 761 | // ####### could be a new file |
755 | qDebug( "Cannot open file" ); | 762 | qDebug( "Cannot open file" ); |
756 | } | 763 | } |
757 | // fileNew(); | 764 | // fileNew(); |
758 | if ( doc ) | 765 | if ( doc ) |
759 | delete doc; | 766 | delete doc; |
760 | doc = new DocLnk(f); | 767 | doc = new DocLnk(f); |
761 | editor->setText(txt); | 768 | editor->setText(txt); |
762 | editor->setEdited( false); | 769 | editor->setEdited( false); |
763 | edited1=false; | 770 | edited1=false; |
764 | edited=false; | 771 | edited=false; |
765 | 772 | ||
766 | doc->setName(currentFileName); | 773 | doc->setName(currentFileName); |
767 | updateCaption(); | 774 | updateCaption(); |
768 | } | 775 | } |
769 | 776 | ||
770 | void TextEdit::showEditTools() { | 777 | void TextEdit::showEditTools() { |
771 | menu->show(); | 778 | menu->show(); |
772 | editBar->show(); | 779 | editBar->show(); |
773 | if(!useSearchBar) | 780 | if(!useSearchBar) |
774 | searchBar->hide(); | 781 | searchBar->hide(); |
775 | else | 782 | else |
776 | searchBar->show(); | 783 | searchBar->show(); |
777 | setWState (WState_Reserved1 ); | 784 | setWState (WState_Reserved1 ); |
778 | } | 785 | } |
779 | 786 | ||
780 | /*! | 787 | /*! |
781 | unprompted save */ | 788 | unprompted save */ |
782 | bool TextEdit::save() { | 789 | bool TextEdit::save() { |
783 | QString file = doc->file(); | 790 | QString file = doc->file(); |