-rw-r--r-- | core/apps/textedit/textedit.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index f99f259..c1f74bb 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -506,495 +506,496 @@ void TextEdit::fileOpen() | |||
506 | { | 506 | { |
507 | Config cfg("TextEdit"); | 507 | Config cfg("TextEdit"); |
508 | cfg.setGroup("View"); | 508 | cfg.setGroup("View"); |
509 | bool b=FALSE; | 509 | bool b=FALSE; |
510 | // if(cfg.readEntry("useOldFileDialog") == "TRUE") | 510 | // if(cfg.readEntry("useOldFileDialog") == "TRUE") |
511 | // b=TRUE; | 511 | // b=TRUE; |
512 | // if(!b) { | 512 | // if(!b) { |
513 | QString str = OFileDialog::getOpenFileName( 2,"/");//,"", "*", this ); | 513 | QString str = OFileDialog::getOpenFileName( 2,"/");//,"", "*", this ); |
514 | if(!str.isEmpty() ) | 514 | if(!str.isEmpty() ) |
515 | openFile( str ); | 515 | openFile( str ); |
516 | // } else { | 516 | // } else { |
517 | // QString str; | 517 | // QString str; |
518 | // browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "*"); // | 518 | // browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "*"); // |
519 | // browseForFiles->setFileView( viewSelection ); | 519 | // browseForFiles->setFileView( viewSelection ); |
520 | // browseForFiles->showMaximized(); | 520 | // browseForFiles->showMaximized(); |
521 | // // if( result != -1 ) | 521 | // // if( result != -1 ) |
522 | 522 | ||
523 | // if( browseForFiles->exec() != -1 ) { | 523 | // if( browseForFiles->exec() != -1 ) { |
524 | // QString selFile = browseForFiles->selectedFileName; | 524 | // QString selFile = browseForFiles->selectedFileName; |
525 | // QStringList fileList = browseForFiles->fileList; | 525 | // QStringList fileList = browseForFiles->fileList; |
526 | // qDebug(selFile); | 526 | // qDebug(selFile); |
527 | // QStringList::ConstIterator f; | 527 | // QStringList::ConstIterator f; |
528 | // QString fileTemp; | 528 | // QString fileTemp; |
529 | // for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 529 | // for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
530 | // fileTemp = *f; | 530 | // fileTemp = *f; |
531 | // fileTemp.right( fileTemp.length()-5); | 531 | // fileTemp.right( fileTemp.length()-5); |
532 | // QString fileName = fileTemp; | 532 | // QString fileName = fileTemp; |
533 | // if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 533 | // if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
534 | // currentFileName = fileName; | 534 | // currentFileName = fileName; |
535 | // qDebug("please open "+currentFileName); | 535 | // qDebug("please open "+currentFileName); |
536 | // openFile(currentFileName ); | 536 | // openFile(currentFileName ); |
537 | // } | 537 | // } |
538 | // } | 538 | // } |
539 | // viewSelection = browseForFiles->SelectionCombo->currentItem(); | 539 | // viewSelection = browseForFiles->SelectionCombo->currentItem(); |
540 | // } | 540 | // } |
541 | // delete browseForFiles; | 541 | // delete browseForFiles; |
542 | // editor->setEdited( FALSE); | 542 | // editor->setEdited( FALSE); |
543 | // edited1=FALSE; | 543 | // edited1=FALSE; |
544 | // edited=FALSE; | 544 | // edited=FALSE; |
545 | // if(caption().left(1)=="*") | 545 | // if(caption().left(1)=="*") |
546 | // setCaption(caption().right(caption().length()-1)); | 546 | // setCaption(caption().right(caption().length()-1)); |
547 | // doSearchBar(); | 547 | // doSearchBar(); |
548 | // } | 548 | // } |
549 | 549 | ||
550 | } | 550 | } |
551 | 551 | ||
552 | void TextEdit::doSearchBar() | 552 | void TextEdit::doSearchBar() |
553 | { | 553 | { |
554 | Config cfg("TextEdit"); | 554 | Config cfg("TextEdit"); |
555 | cfg.setGroup("View"); | 555 | cfg.setGroup("View"); |
556 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 556 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
557 | searchBar->hide(); | 557 | searchBar->hide(); |
558 | } | 558 | } |
559 | 559 | ||
560 | #if 0 | 560 | #if 0 |
561 | void TextEdit::slotFind() | 561 | void TextEdit::slotFind() |
562 | { | 562 | { |
563 | FindDialog frmFind( tr("Text Editor"), this ); | 563 | FindDialog frmFind( tr("Text Editor"), this ); |
564 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 564 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
565 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 565 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
566 | 566 | ||
567 | //case sensitive, backwards, [category] | 567 | //case sensitive, backwards, [category] |
568 | 568 | ||
569 | connect( editor, SIGNAL(notFound()), | 569 | connect( editor, SIGNAL(notFound()), |
570 | &frmFind, SLOT(slotNotFound()) ); | 570 | &frmFind, SLOT(slotNotFound()) ); |
571 | connect( editor, SIGNAL(searchWrapped()), | 571 | connect( editor, SIGNAL(searchWrapped()), |
572 | &frmFind, SLOT(slotWrapAround()) ); | 572 | &frmFind, SLOT(slotWrapAround()) ); |
573 | 573 | ||
574 | frmFind.exec(); | 574 | frmFind.exec(); |
575 | 575 | ||
576 | 576 | ||
577 | } | 577 | } |
578 | #endif | 578 | #endif |
579 | 579 | ||
580 | void TextEdit::fileRevert() | 580 | void TextEdit::fileRevert() |
581 | { | 581 | { |
582 | clear(); | 582 | clear(); |
583 | fileOpen(); | 583 | fileOpen(); |
584 | } | 584 | } |
585 | 585 | ||
586 | void TextEdit::editCut() | 586 | void TextEdit::editCut() |
587 | { | 587 | { |
588 | #ifndef QT_NO_CLIPBOARD | 588 | #ifndef QT_NO_CLIPBOARD |
589 | editor->cut(); | 589 | editor->cut(); |
590 | #endif | 590 | #endif |
591 | } | 591 | } |
592 | 592 | ||
593 | void TextEdit::editCopy() | 593 | void TextEdit::editCopy() |
594 | { | 594 | { |
595 | #ifndef QT_NO_CLIPBOARD | 595 | #ifndef QT_NO_CLIPBOARD |
596 | editor->copy(); | 596 | editor->copy(); |
597 | #endif | 597 | #endif |
598 | } | 598 | } |
599 | 599 | ||
600 | void TextEdit::editPaste() | 600 | void TextEdit::editPaste() |
601 | { | 601 | { |
602 | #ifndef QT_NO_CLIPBOARD | 602 | #ifndef QT_NO_CLIPBOARD |
603 | editor->paste(); | 603 | editor->paste(); |
604 | #endif | 604 | #endif |
605 | } | 605 | } |
606 | 606 | ||
607 | void TextEdit::editFind() | 607 | void TextEdit::editFind() |
608 | { | 608 | { |
609 | searchBar->show(); | 609 | searchBar->show(); |
610 | searchVisible = TRUE; | 610 | searchVisible = TRUE; |
611 | searchEdit->setFocus(); | 611 | searchEdit->setFocus(); |
612 | Config cfg("TextEdit"); | 612 | Config cfg("TextEdit"); |
613 | cfg.setGroup("View"); | 613 | cfg.setGroup("View"); |
614 | cfg.writeEntry("SearchBar","Opened"); | 614 | cfg.writeEntry("SearchBar","Opened"); |
615 | 615 | ||
616 | } | 616 | } |
617 | 617 | ||
618 | void TextEdit::findNext() | 618 | void TextEdit::findNext() |
619 | { | 619 | { |
620 | editor->find( searchEdit->text(), FALSE, FALSE ); | 620 | editor->find( searchEdit->text(), FALSE, FALSE ); |
621 | 621 | ||
622 | } | 622 | } |
623 | 623 | ||
624 | void TextEdit::findClose() | 624 | void TextEdit::findClose() |
625 | { | 625 | { |
626 | searchVisible = FALSE; | 626 | searchVisible = FALSE; |
627 | searchBar->hide(); | 627 | searchBar->hide(); |
628 | Config cfg("TextEdit"); | 628 | Config cfg("TextEdit"); |
629 | cfg.setGroup("View"); | 629 | cfg.setGroup("View"); |
630 | cfg.writeEntry("SearchBar","Closed"); | 630 | cfg.writeEntry("SearchBar","Closed"); |
631 | cfg.write(); | 631 | cfg.write(); |
632 | } | 632 | } |
633 | 633 | ||
634 | void TextEdit::search() | 634 | void TextEdit::search() |
635 | { | 635 | { |
636 | editor->find( searchEdit->text(), FALSE, FALSE ); | 636 | editor->find( searchEdit->text(), FALSE, FALSE ); |
637 | } | 637 | } |
638 | 638 | ||
639 | void TextEdit::newFile( const DocLnk &f ) | 639 | void TextEdit::newFile( const DocLnk &f ) |
640 | { | 640 | { |
641 | DocLnk nf = f; | 641 | DocLnk nf = f; |
642 | nf.setType("text/plain"); | 642 | nf.setType("text/plain"); |
643 | clear(); | 643 | clear(); |
644 | setWState (WState_Reserved1 ); | 644 | setWState (WState_Reserved1 ); |
645 | editor->setFocus(); | 645 | editor->setFocus(); |
646 | doc = new DocLnk(nf); | 646 | doc = new DocLnk(nf); |
647 | currentFileName = "Unnamed"; | 647 | currentFileName = "Unnamed"; |
648 | qDebug("newFile "+currentFileName); | 648 | qDebug("newFile "+currentFileName); |
649 | updateCaption( currentFileName); | 649 | updateCaption( currentFileName); |
650 | // editor->setEdited( FALSE); | 650 | // editor->setEdited( FALSE); |
651 | } | 651 | } |
652 | 652 | ||
653 | void TextEdit::openFile( const QString &f ) | 653 | void TextEdit::openFile( const QString &f ) |
654 | { | 654 | { |
655 | qDebug("filename is "+ f); | 655 | qDebug("filename is "+ f); |
656 | QString filer; | 656 | QString filer; |
657 | // bFromDocView = TRUE; | 657 | // bFromDocView = TRUE; |
658 | if(f.find(".desktop",0,TRUE) != -1) { | 658 | if(f.find(".desktop",0,TRUE) != -1) { |
659 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 659 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
660 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), | 660 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), |
661 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 661 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
662 | case 0: | 662 | case 0: |
663 | filer = f; | 663 | filer = f; |
664 | break; | 664 | break; |
665 | case 1: | 665 | case 1: |
666 | DocLnk sf(f); | 666 | DocLnk sf(f); |
667 | filer = sf.file(); | 667 | filer = sf.file(); |
668 | break; | 668 | break; |
669 | } | 669 | } |
670 | } else { | 670 | } else { |
671 | filer = f; | 671 | filer = f; |
672 | fileIs = TRUE; | 672 | fileIs = TRUE; |
673 | } | 673 | } |
674 | 674 | ||
675 | DocLnk nf; | 675 | DocLnk nf; |
676 | nf.setType("text/plain"); | 676 | nf.setType("text/plain"); |
677 | nf.setFile(filer); | 677 | nf.setFile(filer); |
678 | currentFileName=filer; | 678 | currentFileName=filer; |
679 | QFileInfo fi( currentFileName); | 679 | QFileInfo fi( currentFileName); |
680 | nf.setName(fi.baseName()); | 680 | nf.setName(fi.baseName()); |
681 | qDebug("openFile string "+currentFileName); | 681 | qDebug("openFile string "+currentFileName); |
682 | 682 | ||
683 | openFile(nf); | 683 | openFile(nf); |
684 | showEditTools(); | 684 | showEditTools(); |
685 | // Show filename in caption | 685 | // Show filename in caption |
686 | QString name = filer; | 686 | QString name = filer; |
687 | int sep = name.findRev( '/' ); | 687 | int sep = name.findRev( '/' ); |
688 | if ( sep > 0 ) | 688 | if ( sep > 0 ) |
689 | name = name.mid( sep+1 ); | 689 | name = name.mid( sep+1 ); |
690 | updateCaption( name ); | 690 | updateCaption( name ); |
691 | } | 691 | } |
692 | 692 | ||
693 | void TextEdit::openFile( const DocLnk &f ) | 693 | void TextEdit::openFile( const DocLnk &f ) |
694 | { | 694 | { |
695 | // clear(); | 695 | // clear(); |
696 | // bFromDocView = TRUE; | 696 | // bFromDocView = TRUE; |
697 | FileManager fm; | 697 | FileManager fm; |
698 | QString txt; | 698 | QString txt; |
699 | currentFileName=f.file(); | 699 | currentFileName=f.file(); |
700 | qDebug("openFile doclnk " + currentFileName); | 700 | qDebug("openFile doclnk " + currentFileName); |
701 | if ( !fm.loadFile( f, txt ) ) { | 701 | if ( !fm.loadFile( f, txt ) ) { |
702 | // ####### could be a new file | 702 | // ####### could be a new file |
703 | qDebug( "Cannot open file" ); | 703 | qDebug( "Cannot open file" ); |
704 | } | 704 | } |
705 | // fileNew(); | 705 | // fileNew(); |
706 | if ( doc ) | 706 | if ( doc ) |
707 | delete doc; | 707 | delete doc; |
708 | doc = new DocLnk(f); | 708 | doc = new DocLnk(f); |
709 | editor->setText(txt); | 709 | editor->setText(txt); |
710 | editor->setEdited( FALSE); | 710 | editor->setEdited( FALSE); |
711 | edited1=FALSE; | 711 | edited1=FALSE; |
712 | edited=FALSE; | 712 | edited=FALSE; |
713 | 713 | ||
714 | doc->setName(currentFileName); | 714 | doc->setName(currentFileName); |
715 | updateCaption(); | 715 | updateCaption(); |
716 | } | 716 | } |
717 | 717 | ||
718 | void TextEdit::showEditTools() | 718 | void TextEdit::showEditTools() |
719 | { | 719 | { |
720 | // if ( !doc ) | 720 | // if ( !doc ) |
721 | // close(); | 721 | // close(); |
722 | // clear(); | 722 | // clear(); |
723 | menu->show(); | 723 | menu->show(); |
724 | editBar->show(); | 724 | editBar->show(); |
725 | if ( searchVisible ) | 725 | if ( searchVisible ) |
726 | searchBar->show(); | 726 | searchBar->show(); |
727 | // updateCaption(); | 727 | // updateCaption(); |
728 | setWState (WState_Reserved1 ); | 728 | setWState (WState_Reserved1 ); |
729 | } | 729 | } |
730 | 730 | ||
731 | /*! | 731 | /*! |
732 | unprompted save */ | 732 | unprompted save */ |
733 | bool TextEdit::save() | 733 | bool TextEdit::save() |
734 | { | 734 | { |
735 | QString file = doc->file(); | 735 | QString file = doc->file(); |
736 | qDebug("saver file "+file); | 736 | qDebug("saver file "+file); |
737 | QString name= doc->name(); | 737 | QString name= doc->name(); |
738 | qDebug("File named "+name); | 738 | qDebug("File named "+name); |
739 | QString rt = editor->text(); | 739 | QString rt = editor->text(); |
740 | if( !rt.isEmpty() ) { | 740 | if( !rt.isEmpty() ) { |
741 | if(name.isEmpty()) { | 741 | if(name.isEmpty()) { |
742 | saveAs(); | 742 | saveAs(); |
743 | } else { | 743 | } else { |
744 | currentFileName= name ; | 744 | currentFileName= name ; |
745 | qDebug("saveFile "+currentFileName); | 745 | qDebug("saveFile "+currentFileName); |
746 | 746 | ||
747 | struct stat buf; | 747 | struct stat buf; |
748 | mode_t mode; | 748 | mode_t mode; |
749 | stat(file.latin1(), &buf); | 749 | stat(file.latin1(), &buf); |
750 | mode = buf.st_mode; | 750 | mode = buf.st_mode; |
751 | 751 | ||
752 | if(!fileIs) { | 752 | if(!fileIs) { |
753 | doc->setName( name); | 753 | doc->setName( name); |
754 | FileManager fm; | 754 | FileManager fm; |
755 | if ( !fm.saveFile( *doc, rt ) ) { | 755 | if ( !fm.saveFile( *doc, rt ) ) { |
756 | return false; | 756 | return false; |
757 | } | 757 | } |
758 | } else { | 758 | } else { |
759 | qDebug("regular save file"); | 759 | qDebug("regular save file"); |
760 | QFile f(file); | 760 | QFile f(file); |
761 | if( f.open(IO_WriteOnly)) { | 761 | if( f.open(IO_WriteOnly)) { |
762 | f.writeBlock(rt,rt.length()); | 762 | QCString crt = rt.utf8(); |
763 | f.writeBlock(crt,crt.length()); | ||
763 | } else { | 764 | } else { |
764 | QMessageBox::message("Text Edit","Write Failed"); | 765 | QMessageBox::message("Text Edit","Write Failed"); |
765 | return false; | 766 | return false; |
766 | } | 767 | } |
767 | 768 | ||
768 | } | 769 | } |
769 | editor->setEdited( FALSE); | 770 | editor->setEdited( FALSE); |
770 | edited1=FALSE; | 771 | edited1=FALSE; |
771 | edited=FALSE; | 772 | edited=FALSE; |
772 | if(caption().left(1)=="*") | 773 | if(caption().left(1)=="*") |
773 | setCaption(caption().right(caption().length()-1)); | 774 | setCaption(caption().right(caption().length()-1)); |
774 | 775 | ||
775 | 776 | ||
776 | chmod( file.latin1(), mode); | 777 | chmod( file.latin1(), mode); |
777 | } | 778 | } |
778 | return true; | 779 | return true; |
779 | } | 780 | } |
780 | return false; | 781 | return false; |
781 | } | 782 | } |
782 | 783 | ||
783 | /*! | 784 | /*! |
784 | prompted save */ | 785 | prompted save */ |
785 | bool TextEdit::saveAs() | 786 | bool TextEdit::saveAs() |
786 | { | 787 | { |
787 | // qDebug("saveAsFile "+currentFileName); | 788 | // qDebug("saveAsFile "+currentFileName); |
788 | // case of nothing to save... | 789 | // case of nothing to save... |
789 | if ( !doc )//|| !bFromDocView) | 790 | if ( !doc )//|| !bFromDocView) |
790 | { | 791 | { |
791 | qDebug("no doc"); | 792 | qDebug("no doc"); |
792 | return true; | 793 | return true; |
793 | } | 794 | } |
794 | if ( !editor->edited() ) { | 795 | if ( !editor->edited() ) { |
795 | delete doc; | 796 | delete doc; |
796 | doc = 0; | 797 | doc = 0; |
797 | return true; | 798 | return true; |
798 | } | 799 | } |
799 | 800 | ||
800 | QString rt = editor->text(); | 801 | QString rt = editor->text(); |
801 | qDebug(currentFileName); | 802 | qDebug(currentFileName); |
802 | 803 | ||
803 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { | 804 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { |
804 | qDebug("do silly TT filename thing"); | 805 | qDebug("do silly TT filename thing"); |
805 | if ( doc->name().isEmpty() ) { | 806 | if ( doc->name().isEmpty() ) { |
806 | QString pt = rt.simplifyWhiteSpace(); | 807 | QString pt = rt.simplifyWhiteSpace(); |
807 | int i = pt.find( ' ' ); | 808 | int i = pt.find( ' ' ); |
808 | QString docname = pt; | 809 | QString docname = pt; |
809 | if ( i > 0 ) | 810 | if ( i > 0 ) |
810 | docname = pt.left( i ); | 811 | docname = pt.left( i ); |
811 | // remove "." at the beginning | 812 | // remove "." at the beginning |
812 | while( docname.startsWith( "." ) ) | 813 | while( docname.startsWith( "." ) ) |
813 | docname = docname.mid( 1 ); | 814 | docname = docname.mid( 1 ); |
814 | docname.replace( QRegExp("/"), "_" ); | 815 | docname.replace( QRegExp("/"), "_" ); |
815 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 816 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
816 | if ( docname.length() > 40 ) | 817 | if ( docname.length() > 40 ) |
817 | docname = docname.left(40); | 818 | docname = docname.left(40); |
818 | if ( docname.isEmpty() ) | 819 | if ( docname.isEmpty() ) |
819 | docname = tr("Unnamed"); | 820 | docname = tr("Unnamed"); |
820 | doc->setName(docname); | 821 | doc->setName(docname); |
821 | currentFileName=docname; | 822 | currentFileName=docname; |
822 | } | 823 | } |
823 | } | 824 | } |
824 | 825 | ||
825 | 826 | ||
826 | // QString str = OFileDialog::getSaveFileName( 2,"/");//,"", "*", this ); | 827 | // QString str = OFileDialog::getSaveFileName( 2,"/");//,"", "*", this ); |
827 | // if(!str.isEmpty() ) { | 828 | // if(!str.isEmpty() ) { |
828 | // openFile( str ); | 829 | // openFile( str ); |
829 | 830 | ||
830 | fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); | 831 | fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); |
831 | qDebug("wanna save filename "+currentFileName); | 832 | qDebug("wanna save filename "+currentFileName); |
832 | fileSaveDlg->exec(); | 833 | fileSaveDlg->exec(); |
833 | if( fileSaveDlg->result() == 1 ) { | 834 | if( fileSaveDlg->result() == 1 ) { |
834 | QString fileNm=fileSaveDlg->selectedFileName; | 835 | QString fileNm=fileSaveDlg->selectedFileName; |
835 | // QString fileNm=srt; | 836 | // QString fileNm=srt; |
836 | qDebug("saving filename "+fileNm); | 837 | qDebug("saving filename "+fileNm); |
837 | QFileInfo fi(fileNm); | 838 | QFileInfo fi(fileNm); |
838 | currentFileName=fi.fileName(); | 839 | currentFileName=fi.fileName(); |
839 | if(doc) { | 840 | if(doc) { |
840 | // QString file = doc->file(); | 841 | // QString file = doc->file(); |
841 | // doc->removeFiles(); | 842 | // doc->removeFiles(); |
842 | delete doc; | 843 | delete doc; |
843 | DocLnk nf; | 844 | DocLnk nf; |
844 | nf.setType("text/plain"); | 845 | nf.setType("text/plain"); |
845 | nf.setFile( fileNm); | 846 | nf.setFile( fileNm); |
846 | doc = new DocLnk(nf); | 847 | doc = new DocLnk(nf); |
847 | // editor->setText(rt); | 848 | // editor->setText(rt); |
848 | // qDebug("openFile doclnk "+currentFileName); | 849 | // qDebug("openFile doclnk "+currentFileName); |
849 | doc->setName( currentFileName); | 850 | doc->setName( currentFileName); |
850 | updateCaption( currentFileName); | 851 | updateCaption( currentFileName); |
851 | 852 | ||
852 | FileManager fm; | 853 | FileManager fm; |
853 | if ( !fm.saveFile( *doc, rt ) ) { | 854 | if ( !fm.saveFile( *doc, rt ) ) { |
854 | return false; | 855 | return false; |
855 | } | 856 | } |
856 | if( fileSaveDlg->filePermCheck->isChecked() ) { | 857 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
857 | filePermissions *filePerm; | 858 | filePermissions *filePerm; |
858 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); | 859 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); |
859 | filePerm->exec(); | 860 | filePerm->exec(); |
860 | 861 | ||
861 | if( filePerm) | 862 | if( filePerm) |
862 | delete filePerm; | 863 | delete filePerm; |
863 | } | 864 | } |
864 | } | 865 | } |
865 | } | 866 | } |
866 | editor->setEdited(TRUE); | 867 | editor->setEdited(TRUE); |
867 | edited1=FALSE; | 868 | edited1=FALSE; |
868 | edited=TRUE; | 869 | edited=TRUE; |
869 | if(caption().left(1)=="*") | 870 | if(caption().left(1)=="*") |
870 | setCaption(caption().right(caption().length()-1)); | 871 | setCaption(caption().right(caption().length()-1)); |
871 | 872 | ||
872 | if(fileSaveDlg) | 873 | if(fileSaveDlg) |
873 | delete fileSaveDlg; | 874 | delete fileSaveDlg; |
874 | return true; | 875 | return true; |
875 | } //end saveAs | 876 | } //end saveAs |
876 | 877 | ||
877 | void TextEdit::clear() | 878 | void TextEdit::clear() |
878 | { | 879 | { |
879 | delete doc; | 880 | delete doc; |
880 | doc = 0; | 881 | doc = 0; |
881 | editor->clear(); | 882 | editor->clear(); |
882 | } | 883 | } |
883 | 884 | ||
884 | void TextEdit::updateCaption( const QString &name ) | 885 | void TextEdit::updateCaption( const QString &name ) |
885 | { | 886 | { |
886 | if ( !doc ) | 887 | if ( !doc ) |
887 | setCaption( tr("Text Editor") ); | 888 | setCaption( tr("Text Editor") ); |
888 | else { | 889 | else { |
889 | QString s = name; | 890 | QString s = name; |
890 | if ( s.isNull() ) | 891 | if ( s.isNull() ) |
891 | s = doc->name(); | 892 | s = doc->name(); |
892 | if ( s.isEmpty() ) { | 893 | if ( s.isEmpty() ) { |
893 | s = tr( "Unnamed" ); | 894 | s = tr( "Unnamed" ); |
894 | currentFileName=s; | 895 | currentFileName=s; |
895 | } | 896 | } |
896 | if(s.left(1) == "/") | 897 | if(s.left(1) == "/") |
897 | s = s.right(s.length()-1); | 898 | s = s.right(s.length()-1); |
898 | setCaption( s + " - " + tr("Text Editor") ); | 899 | setCaption( s + " - " + tr("Text Editor") ); |
899 | } | 900 | } |
900 | } | 901 | } |
901 | 902 | ||
902 | void TextEdit::setDocument(const QString& fileref) | 903 | void TextEdit::setDocument(const QString& fileref) |
903 | { | 904 | { |
904 | bFromDocView = TRUE; | 905 | bFromDocView = TRUE; |
905 | openFile(fileref); | 906 | openFile(fileref); |
906 | editor->setEdited(TRUE); | 907 | editor->setEdited(TRUE); |
907 | edited1=FALSE; | 908 | edited1=FALSE; |
908 | edited=TRUE; | 909 | edited=TRUE; |
909 | doSearchBar(); | 910 | doSearchBar(); |
910 | } | 911 | } |
911 | 912 | ||
912 | void TextEdit::closeEvent( QCloseEvent *e ) | 913 | void TextEdit::closeEvent( QCloseEvent *e ) |
913 | { | 914 | { |
914 | bFromDocView = FALSE; | 915 | bFromDocView = FALSE; |
915 | e->accept(); | 916 | e->accept(); |
916 | } | 917 | } |
917 | 918 | ||
918 | void TextEdit::accept() | 919 | void TextEdit::accept() |
919 | { | 920 | { |
920 | //if(caption() !="Unnamed") | 921 | //if(caption() !="Unnamed") |
921 | if(edited1) | 922 | if(edited1) |
922 | saveAs(); | 923 | saveAs(); |
923 | exit(0); | 924 | exit(0); |
924 | 925 | ||
925 | } | 926 | } |
926 | 927 | ||
927 | void TextEdit::changeFont() { | 928 | void TextEdit::changeFont() { |
928 | FontDatabase fdb; | 929 | FontDatabase fdb; |
929 | QFont defaultFont=editor->font(); | 930 | QFont defaultFont=editor->font(); |
930 | QFontInfo fontInfo(defaultFont); | 931 | QFontInfo fontInfo(defaultFont); |
931 | Config cfg("TextEdit"); | 932 | Config cfg("TextEdit"); |
932 | cfg.setGroup("Font"); | 933 | cfg.setGroup("Font"); |
933 | QString family = cfg.readEntry("Family", fontInfo.family()); | 934 | QString family = cfg.readEntry("Family", fontInfo.family()); |
934 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 935 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
935 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 936 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
936 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 937 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
937 | 938 | ||
938 | defaultFont = fdb.font(family,style,i_size,charSet); | 939 | defaultFont = fdb.font(family,style,i_size,charSet); |
939 | 940 | ||
940 | FontDialog *fontDlg; | 941 | FontDialog *fontDlg; |
941 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); | 942 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); |
942 | 943 | ||
943 | fontDlg->exec(); | 944 | fontDlg->exec(); |
944 | 945 | ||
945 | QFont myFont=fontDlg->selectedFont; | 946 | QFont myFont=fontDlg->selectedFont; |
946 | editor->setFont( myFont); | 947 | editor->setFont( myFont); |
947 | delete fontDlg; | 948 | delete fontDlg; |
948 | 949 | ||
949 | } | 950 | } |
950 | 951 | ||
951 | void TextEdit::editDelete() | 952 | void TextEdit::editDelete() |
952 | { | 953 | { |
953 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) { | 954 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) { |
954 | case 0: | 955 | case 0: |
955 | if(doc) { | 956 | if(doc) { |
956 | doc->removeFiles(); | 957 | doc->removeFiles(); |
957 | clear(); | 958 | clear(); |
958 | setCaption( tr("Text Editor") ); | 959 | setCaption( tr("Text Editor") ); |
959 | } | 960 | } |
960 | break; | 961 | break; |
961 | case 1: | 962 | case 1: |
962 | // exit | 963 | // exit |
963 | break; | 964 | break; |
964 | }; | 965 | }; |
965 | } | 966 | } |
966 | 967 | ||
967 | void TextEdit::changeStartConfig( bool b ) { | 968 | void TextEdit::changeStartConfig( bool b ) { |
968 | 969 | ||
969 | Config cfg("TextEdit"); | 970 | Config cfg("TextEdit"); |
970 | cfg.setGroup("View"); | 971 | cfg.setGroup("View"); |
971 | if(b) { | 972 | if(b) { |
972 | qDebug("bool"); | 973 | qDebug("bool"); |
973 | cfg.writeEntry("startNew","TRUE"); | 974 | cfg.writeEntry("startNew","TRUE"); |
974 | } else { | 975 | } else { |
975 | cfg.writeEntry("startNew","FALSE"); | 976 | cfg.writeEntry("startNew","FALSE"); |
976 | } | 977 | } |
977 | update(); | 978 | update(); |
978 | } | 979 | } |
979 | 980 | ||
980 | void TextEdit::editorChanged() { | 981 | void TextEdit::editorChanged() { |
981 | if(editor->edited() && edited && !edited1) { | 982 | if(editor->edited() && edited && !edited1) { |
982 | setCaption( "*"+caption()); | 983 | setCaption( "*"+caption()); |
983 | edited1=TRUE; | 984 | edited1=TRUE; |
984 | } | 985 | } |
985 | edited=TRUE; | 986 | edited=TRUE; |
986 | } | 987 | } |
987 | 988 | ||
988 | void TextEdit::receive(const QCString&msg, const QByteArray&) { | 989 | void TextEdit::receive(const QCString&msg, const QByteArray&) { |
989 | qDebug("QCop "+msg); | 990 | qDebug("QCop "+msg); |
990 | if ( msg == "setDocument(QString)" ) { | 991 | if ( msg == "setDocument(QString)" ) { |
991 | qDebug("bugger all"); | 992 | qDebug("bugger all"); |
992 | } | 993 | } |
993 | 994 | ||
994 | } | 995 | } |
995 | void TextEdit::doAbout() { | 996 | void TextEdit::doAbout() { |
996 | QMessageBox::about(0,"Text Edit","Text Edit is copyright\n" | 997 | QMessageBox::about(0,"Text Edit","Text Edit is copyright\n" |
997 | "2000 Trolltech AS, and\n" | 998 | "2000 Trolltech AS, and\n" |
998 | "2002 by L.J.Potter \nljp@llornkcor.com\n" | 999 | "2002 by L.J.Potter \nljp@llornkcor.com\n" |
999 | "and is licensed under the GPL"); | 1000 | "and is licensed under the GPL"); |
1000 | } | 1001 | } |