Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 4bbc62b..1c81a55 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -597,435 +597,432 @@ void TextEdit::slotFind() { | |||
597 | 597 | ||
598 | connect( editor, SIGNAL(notFound()), | 598 | connect( editor, SIGNAL(notFound()), |
599 | &frmFind, SLOT(slotNotFound()) ); | 599 | &frmFind, SLOT(slotNotFound()) ); |
600 | connect( editor, SIGNAL(searchWrapped()), | 600 | connect( editor, SIGNAL(searchWrapped()), |
601 | &frmFind, SLOT(slotWrapAround()) ); | 601 | &frmFind, SLOT(slotWrapAround()) ); |
602 | 602 | ||
603 | frmFind.exec(); | 603 | frmFind.exec(); |
604 | 604 | ||
605 | 605 | ||
606 | } | 606 | } |
607 | #endif | 607 | #endif |
608 | 608 | ||
609 | void TextEdit::fileRevert() { | 609 | void TextEdit::fileRevert() { |
610 | clear(); | 610 | clear(); |
611 | fileOpen(); | 611 | fileOpen(); |
612 | } | 612 | } |
613 | 613 | ||
614 | void TextEdit::editCut() { | 614 | void TextEdit::editCut() { |
615 | #ifndef QT_NO_CLIPBOARD | 615 | #ifndef QT_NO_CLIPBOARD |
616 | editor->cut(); | 616 | editor->cut(); |
617 | #endif | 617 | #endif |
618 | } | 618 | } |
619 | 619 | ||
620 | void TextEdit::editCopy() { | 620 | void TextEdit::editCopy() { |
621 | #ifndef QT_NO_CLIPBOARD | 621 | #ifndef QT_NO_CLIPBOARD |
622 | editor->copy(); | 622 | editor->copy(); |
623 | #endif | 623 | #endif |
624 | } | 624 | } |
625 | 625 | ||
626 | void TextEdit::editPaste() { | 626 | void TextEdit::editPaste() { |
627 | #ifndef QT_NO_CLIPBOARD | 627 | #ifndef QT_NO_CLIPBOARD |
628 | editor->paste(); | 628 | editor->paste(); |
629 | #endif | 629 | #endif |
630 | } | 630 | } |
631 | 631 | ||
632 | void TextEdit::editFind() { | 632 | void TextEdit::editFind() { |
633 | searchBar->show(); | 633 | searchBar->show(); |
634 | searchEdit->setFocus(); | 634 | searchEdit->setFocus(); |
635 | } | 635 | } |
636 | 636 | ||
637 | void TextEdit::findNext() { | 637 | void TextEdit::findNext() { |
638 | editor->find( searchEdit->text(), false, false ); | 638 | editor->find( searchEdit->text(), false, false ); |
639 | 639 | ||
640 | } | 640 | } |
641 | 641 | ||
642 | void TextEdit::findClose() { | 642 | void TextEdit::findClose() { |
643 | searchBar->hide(); | 643 | searchBar->hide(); |
644 | } | 644 | } |
645 | 645 | ||
646 | void TextEdit::search() { | 646 | void TextEdit::search() { |
647 | editor->find( searchEdit->text(), false, false ); | 647 | editor->find( searchEdit->text(), false, false ); |
648 | } | 648 | } |
649 | 649 | ||
650 | void TextEdit::newFile( const DocLnk &f ) { | 650 | void TextEdit::newFile( const DocLnk &f ) { |
651 | DocLnk nf = f; | 651 | DocLnk nf = f; |
652 | nf.setType("text/plain"); | 652 | nf.setType("text/plain"); |
653 | clear(); | 653 | clear(); |
654 | setWState (WState_Reserved1 ); | 654 | setWState (WState_Reserved1 ); |
655 | editor->setFocus(); | 655 | editor->setFocus(); |
656 | doc = new DocLnk(nf); | 656 | doc = new DocLnk(nf); |
657 | currentFileName = "Unnamed"; | 657 | currentFileName = "Unnamed"; |
658 | odebug << "newFile "+currentFileName << oendl; | 658 | odebug << "newFile "+currentFileName << oendl; |
659 | updateCaption( currentFileName); | 659 | updateCaption( currentFileName); |
660 | // editor->setEdited( false); | 660 | // editor->setEdited( false); |
661 | } | 661 | } |
662 | 662 | ||
663 | void TextEdit::openDotFile( const QString &f ) { | 663 | void TextEdit::openDotFile( const QString &f ) { |
664 | if(!currentFileName.isEmpty()) { | 664 | if(!currentFileName.isEmpty()) { |
665 | currentFileName=f; | 665 | currentFileName=f; |
666 | 666 | ||
667 | odebug << "openFile dotfile " + currentFileName << oendl; | 667 | odebug << "openFile dotfile " + currentFileName << oendl; |
668 | QString txt; | 668 | QString txt; |
669 | QFile file(f); | 669 | QFile file(f); |
670 | if (!file.open(IO_ReadWrite)) | 670 | if (!file.open(IO_ReadWrite)) |
671 | owarn << "Failed to open file " << file.name() << oendl; | 671 | owarn << "Failed to open file " << file.name() << oendl; |
672 | else { | 672 | else { |
673 | QTextStream t(&file); | 673 | QTextStream t(&file); |
674 | while ( !t.atEnd()) { | 674 | while ( !t.atEnd()) { |
675 | txt+=t.readLine()+"\n"; | 675 | txt+=t.readLine()+"\n"; |
676 | } | 676 | } |
677 | editor->setText(txt); | 677 | editor->setText(txt); |
678 | editor->setEdited( false); | 678 | editor->setEdited( false); |
679 | edited1=false; | 679 | edited1=false; |
680 | edited=false; | 680 | edited=false; |
681 | } | 681 | } |
682 | } | 682 | } |
683 | updateCaption( currentFileName); | 683 | updateCaption( currentFileName); |
684 | } | 684 | } |
685 | 685 | ||
686 | void TextEdit::openFile( const QString &f ) { | 686 | void TextEdit::openFile( const QString &f ) { |
687 | odebug << "filename is "+ f << oendl; | 687 | odebug << "filename is "+ f << oendl; |
688 | QString filer; | 688 | QString filer; |
689 | QFileInfo fi( f); | 689 | QFileInfo fi( f); |
690 | // bFromDocView = true; | 690 | // bFromDocView = true; |
691 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 691 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
692 | { | 692 | { |
693 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) | 693 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) |
694 | { | 694 | { |
695 | case 0: //desktop | 695 | case 0: //desktop |
696 | filer = f; | 696 | filer = f; |
697 | break; | 697 | break; |
698 | case 1: //linked | 698 | case 1: //linked |
699 | DocLnk sf(f); | 699 | DocLnk sf(f); |
700 | filer = sf.file(); | 700 | filer = sf.file(); |
701 | break; | 701 | break; |
702 | }; | 702 | }; |
703 | } | 703 | } |
704 | else if(fi.baseName().left(1) == "") | 704 | else if(fi.baseName().left(1) == "") |
705 | { | 705 | { |
706 | odebug << "opening dotfile" << oendl; | 706 | odebug << "opening dotfile" << oendl; |
707 | currentFileName=f; | 707 | currentFileName=f; |
708 | openDotFile(currentFileName); | 708 | openDotFile(currentFileName); |
709 | return; | 709 | return; |
710 | } | 710 | } |
711 | /* | 711 | /* |
712 | * The problem is a file where Config(f).isValid() and it does not | 712 | * The problem is a file where Config(f).isValid() and it does not |
713 | * end with .desktop will be treated as desktop file | 713 | * end with .desktop will be treated as desktop file |
714 | */ | 714 | */ |
715 | else if (f.find(".desktop",0,true) != -1 ) | 715 | else if (f.find(".desktop",0,true) != -1 ) |
716 | { | 716 | { |
717 | DocLnk sf(f); | 717 | DocLnk sf(f); |
718 | filer = sf.file(); | 718 | filer = sf.file(); |
719 | if(filer.right(1) == "/") | 719 | if(filer.right(1) == "/") |
720 | filer = f; | 720 | filer = f; |
721 | 721 | ||
722 | } | 722 | } |
723 | else | 723 | else |
724 | filer = f; | 724 | filer = f; |
725 | 725 | ||
726 | DocLnk nf; | 726 | DocLnk nf; |
727 | nf.setType("text/plain"); | 727 | nf.setType("text/plain"); |
728 | nf.setFile(filer); | 728 | nf.setFile(filer); |
729 | currentFileName=filer; | 729 | currentFileName=filer; |
730 | 730 | ||
731 | nf.setName(fi.baseName()); | 731 | nf.setName(fi.baseName()); |
732 | openFile(nf); | 732 | openFile(nf); |
733 | 733 | ||
734 | odebug << "openFile string "+currentFileName << oendl; | 734 | odebug << "openFile string "+currentFileName << oendl; |
735 | 735 | ||
736 | showEditTools(); | 736 | showEditTools(); |
737 | // Show filename in caption | 737 | // Show filename in caption |
738 | QString name = filer; | 738 | QString name = filer; |
739 | int sep = name.findRev( '/' ); | 739 | int sep = name.findRev( '/' ); |
740 | if ( sep > 0 ) | 740 | if ( sep > 0 ) |
741 | name = name.mid( sep+1 ); | 741 | name = name.mid( sep+1 ); |
742 | updateCaption( name ); | 742 | updateCaption( name ); |
743 | } | 743 | } |
744 | 744 | ||
745 | void TextEdit::openFile( const DocLnk &f ) { | 745 | void TextEdit::openFile( const DocLnk &f ) { |
746 | // clear(); | 746 | // clear(); |
747 | // bFromDocView = true; | 747 | // bFromDocView = true; |
748 | FileManager fm; | 748 | FileManager fm; |
749 | QString txt; | 749 | QString txt; |
750 | currentFileName=f.file(); | 750 | currentFileName=f.file(); |
751 | odebug << "openFile doclnk " + currentFileName << oendl; | 751 | odebug << "openFile doclnk " + currentFileName << oendl; |
752 | if ( !fm.loadFile( f, txt ) ) { | 752 | if ( !fm.loadFile( f, txt ) ) { |
753 | // ####### could be a new file | 753 | // ####### could be a new file |
754 | odebug << "Cannot open file" << oendl; | 754 | odebug << "Cannot open file" << oendl; |
755 | } | 755 | } |
756 | // fileNew(); | 756 | // fileNew(); |
757 | if ( doc ) | 757 | if ( doc ) |
758 | delete doc; | 758 | delete doc; |
759 | doc = new DocLnk(f); | 759 | doc = new DocLnk(f); |
760 | editor->setText(txt); | 760 | editor->setText(txt); |
761 | editor->setEdited( false); | 761 | editor->setEdited( false); |
762 | edited1=false; | 762 | edited1=false; |
763 | edited=false; | 763 | edited=false; |
764 | 764 | ||
765 | doc->setName(currentFileName); | 765 | doc->setName(currentFileName); |
766 | updateCaption(); | 766 | updateCaption(); |
767 | setTimer(); | 767 | setTimer(); |
768 | } | 768 | } |
769 | 769 | ||
770 | void TextEdit::showEditTools() { | 770 | void TextEdit::showEditTools() { |
771 | menu->show(); | 771 | menu->show(); |
772 | editBar->show(); | 772 | editBar->show(); |
773 | if(!useSearchBar) | 773 | if(!useSearchBar) |
774 | searchBar->hide(); | 774 | searchBar->hide(); |
775 | else | 775 | else |
776 | searchBar->show(); | 776 | searchBar->show(); |
777 | setWState (WState_Reserved1 ); | 777 | setWState (WState_Reserved1 ); |
778 | } | 778 | } |
779 | 779 | ||
780 | /*! | 780 | /*! |
781 | unprompted save */ | 781 | unprompted save */ |
782 | bool TextEdit::save() { | 782 | bool TextEdit::save() { |
783 | QString name, file; | 783 | QString name, file; |
784 | odebug << "saveAsFile " + currentFileName << oendl; | 784 | odebug << "saveAsFile " + currentFileName << oendl; |
785 | if(currentFileName.isEmpty()) { | 785 | if(currentFileName.isEmpty()) { |
786 | saveAs(); | 786 | saveAs(); |
787 | return false; | 787 | return false; |
788 | } | 788 | } |
789 | name = currentFileName; | ||
790 | if(doc) { | 789 | if(doc) { |
791 | file = doc->file(); | 790 | file = doc->file(); |
792 | odebug << "saver file "+file << oendl; | 791 | odebug << "saver file "+file << oendl; |
793 | name = doc->name(); | 792 | name = doc->name(); |
794 | odebug << "File named "+name << oendl; | 793 | odebug << "File named "+name << oendl; |
795 | } else { | 794 | } else { |
796 | file = currentFileName; | 795 | file = currentFileName; |
797 | name = QFileInfo(currentFileName).baseName(); | 796 | name = QFileInfo(currentFileName).baseName(); |
798 | } | 797 | } |
799 | 798 | ||
800 | QString rt = editor->text(); | 799 | QString rt = editor->text(); |
801 | if( !rt.isEmpty() ) { | 800 | if( !rt.isEmpty() ) { |
802 | if(name.isEmpty()) { | 801 | if(name.isEmpty()) { |
803 | saveAs(); | 802 | saveAs(); |
804 | } else { | 803 | } else { |
805 | currentFileName = name; | 804 | currentFileName = name; |
806 | odebug << "saveFile "+currentFileName << oendl; | 805 | odebug << "saveFile "+currentFileName << oendl; |
807 | 806 | ||
808 | struct stat buf; | 807 | struct stat buf; |
809 | mode_t mode; | 808 | mode_t mode; |
810 | stat(file.latin1(), &buf); | 809 | QFile f(file); |
810 | fstat(f.handle(), &buf); | ||
811 | mode = buf.st_mode; | 811 | mode = buf.st_mode; |
812 | 812 | ||
813 | if(!fileIs) { | 813 | if(!fileIs) { |
814 | doc->setName( name); | 814 | doc->setName( name); |
815 | FileManager fm; | 815 | FileManager fm; |
816 | if ( !fm.saveFile( *doc, rt ) ) { | 816 | if ( !fm.saveFile( *doc, rt ) ) { |
817 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 817 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
818 | return false; | 818 | return false; |
819 | } | 819 | } |
820 | } else { | 820 | } else { |
821 | odebug << "regular save file" << oendl; | 821 | odebug << "regular save file" << oendl; |
822 | QFile f(file); | ||
823 | if( f.open(IO_WriteOnly)) { | 822 | if( f.open(IO_WriteOnly)) { |
824 | QCString crt = rt.utf8(); | 823 | QCString crt = rt.utf8(); |
825 | f.writeBlock(crt,crt.length()); | 824 | f.writeBlock(crt,crt.length()); |
826 | } else { | 825 | } else { |
827 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 826 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
828 | return false; | 827 | return false; |
829 | } | 828 | } |
830 | |||
831 | } | 829 | } |
832 | editor->setEdited( false); | 830 | editor->setEdited( false); |
833 | edited1=false; | 831 | edited1=false; |
834 | edited=false; | 832 | edited=false; |
835 | if(caption().left(1)=="*") | 833 | if(caption().left(1)=="*") |
836 | setCaption(caption().right(caption().length()-1)); | 834 | setCaption(caption().right(caption().length()-1)); |
837 | 835 | ||
838 | 836 | fchmod( f.handle(), mode); | |
839 | chmod( file.latin1(), mode); | ||
840 | } | 837 | } |
841 | return true; | 838 | return true; |
842 | } | 839 | } |
843 | return false; | 840 | return false; |
844 | } | 841 | } |
845 | 842 | ||
846 | /*! | 843 | /*! |
847 | prompted save */ | 844 | prompted save */ |
848 | bool TextEdit::saveAs() { | 845 | bool TextEdit::saveAs() { |
849 | 846 | ||
850 | if(caption() == tr("Text Editor")) | 847 | if(caption() == tr("Text Editor")) |
851 | return false; | 848 | return false; |
852 | odebug << "saveAsFile " + currentFileName << oendl; | 849 | odebug << "saveAsFile " + currentFileName << oendl; |
853 | 850 | ||
854 | QString rt = editor->text(); | 851 | QString rt = editor->text(); |
855 | odebug << currentFileName << oendl; | 852 | odebug << currentFileName << oendl; |
856 | 853 | ||
857 | if( currentFileName.isEmpty() | 854 | if( currentFileName.isEmpty() |
858 | || currentFileName == tr("Unnamed") | 855 | || currentFileName == tr("Unnamed") |
859 | || currentFileName == tr("Text Editor")) | 856 | || currentFileName == tr("Text Editor")) |
860 | { | 857 | { |
861 | odebug << "do silly TT filename thing" << oendl; | 858 | odebug << "do silly TT filename thing" << oendl; |
862 | QString pt = rt.simplifyWhiteSpace(); | 859 | QString pt = rt.simplifyWhiteSpace(); |
863 | int i = pt.find( ' ' ); | 860 | int i = pt.find( ' ' ); |
864 | QString docname = pt; | 861 | QString docname = pt; |
865 | if ( i > 0 ) docname = pt.left( i ); | 862 | if ( i > 0 ) docname = pt.left( i ); |
866 | 863 | ||
867 | while( docname.startsWith( "." ) ) | 864 | while( docname.startsWith( "." ) ) |
868 | docname = docname.mid( 1 ); | 865 | docname = docname.mid( 1 ); |
869 | docname.replace( QRegExp("/"), "_" ); | 866 | docname.replace( QRegExp("/"), "_" ); |
870 | // Cut the length. Filenames longer than 40 are not helpful | 867 | // Cut the length. Filenames longer than 40 are not helpful |
871 | // and something goes wrong when they get too long. | 868 | // and something goes wrong when they get too long. |
872 | if ( docname.length() > 40 ) docname = docname.left(40); | 869 | if ( docname.length() > 40 ) docname = docname.left(40); |
873 | 870 | ||
874 | if ( docname.isEmpty() ) docname = tr("Unnamed"); | 871 | if ( docname.isEmpty() ) docname = tr("Unnamed"); |
875 | 872 | ||
876 | if(doc) doc->setName(docname); | 873 | if(doc) doc->setName(docname); |
877 | 874 | ||
878 | currentFileName=docname; | 875 | currentFileName=docname; |
879 | } | 876 | } |
880 | 877 | ||
881 | 878 | ||
882 | QMap<QString, QStringList> map; | 879 | QMap<QString, QStringList> map; |
883 | map.insert(tr("All"), QStringList() ); | 880 | map.insert(tr("All"), QStringList() ); |
884 | QStringList text; | 881 | QStringList text; |
885 | text << "text/*"; | 882 | text << "text/*"; |
886 | map.insert(tr("Text"), text ); | 883 | map.insert(tr("Text"), text ); |
887 | text << "*"; | 884 | text << "*"; |
888 | map.insert(tr("All"), text ); | 885 | map.insert(tr("All"), text ); |
889 | 886 | ||
890 | QFileInfo cuFi( currentFileName); | 887 | QFileInfo cuFi( currentFileName); |
891 | QString filee = cuFi.fileName(); | 888 | QString filee = cuFi.fileName(); |
892 | QString dire = cuFi.dirPath(); | 889 | QString dire = cuFi.dirPath(); |
893 | if(dire==".") | 890 | if(dire==".") |
894 | dire = QPEApplication::documentDir(); | 891 | dire = QPEApplication::documentDir(); |
895 | 892 | ||
896 | QString str; | 893 | QString str; |
897 | if( !featureAutoSave) { | 894 | if( !featureAutoSave) { |
898 | str = OFileDialog::getSaveFileName( 2, dire, filee, map); | 895 | str = OFileDialog::getSaveFileName( 2, dire, filee, map); |
899 | } else | 896 | } else |
900 | str = currentFileName; | 897 | str = currentFileName; |
901 | 898 | ||
902 | if(!str.isEmpty()) { | 899 | if(!str.isEmpty()) { |
903 | QString fileNm=str; | 900 | QString fileNm=str; |
904 | 901 | ||
905 | odebug << "saving filename "+fileNm << oendl; | 902 | odebug << "saving filename "+fileNm << oendl; |
906 | QFileInfo fi(fileNm); | 903 | QFileInfo fi(fileNm); |
907 | currentFileName=fi.fileName(); | 904 | currentFileName=fi.fileName(); |
908 | if(doc) | 905 | if(doc) |
909 | delete doc; | 906 | delete doc; |
910 | 907 | ||
911 | DocLnk nf; | 908 | DocLnk nf; |
912 | nf.setType("text/plain"); | 909 | nf.setType("text/plain"); |
913 | nf.setFile( fileNm); | 910 | nf.setFile( fileNm); |
914 | doc = new DocLnk(nf); | 911 | doc = new DocLnk(nf); |
915 | odebug << "Saving file as "+currentFileName << oendl; | 912 | odebug << "Saving file as "+currentFileName << oendl; |
916 | doc->setName( fi.baseName() ); | 913 | doc->setName( fi.baseName() ); |
917 | updateCaption( currentFileName); | 914 | updateCaption( currentFileName); |
918 | 915 | ||
919 | FileManager fm; | 916 | FileManager fm; |
920 | if ( !fm.saveFile( *doc, rt ) ) { | 917 | if ( !fm.saveFile( *doc, rt ) ) { |
921 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 918 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
922 | return false; | 919 | return false; |
923 | } | 920 | } |
924 | 921 | ||
925 | if( filePerms ) { | 922 | if( filePerms ) { |
926 | filePermissions *filePerm; | 923 | filePermissions *filePerm; |
927 | filePerm = new filePermissions(this, tr("Permissions"),true, 0, | 924 | filePerm = new filePermissions(this, tr("Permissions"),true, 0, |
928 | (const QString &)fileNm); | 925 | (const QString &)fileNm); |
929 | QPEApplication::execDialog( filePerm ); | 926 | QPEApplication::execDialog( filePerm ); |
930 | 927 | ||
931 | delete filePerm; | 928 | delete filePerm; |
932 | } | 929 | } |
933 | editor->setEdited( false); | 930 | editor->setEdited( false); |
934 | edited1 = false; | 931 | edited1 = false; |
935 | edited = false; | 932 | edited = false; |
936 | if(caption().left(1)=="*") | 933 | if(caption().left(1)=="*") |
937 | setCaption(caption().right(caption().length()-1)); | 934 | setCaption(caption().right(caption().length()-1)); |
938 | 935 | ||
939 | return true; | 936 | return true; |
940 | } | 937 | } |
941 | odebug << "returning false" << oendl; | 938 | odebug << "returning false" << oendl; |
942 | currentFileName = ""; | 939 | currentFileName = ""; |
943 | return false; | 940 | return false; |
944 | } //end saveAs | 941 | } //end saveAs |
945 | 942 | ||
946 | void TextEdit::clear() { | 943 | void TextEdit::clear() { |
947 | delete doc; | 944 | delete doc; |
948 | doc = 0; | 945 | doc = 0; |
949 | editor->clear(); | 946 | editor->clear(); |
950 | } | 947 | } |
951 | 948 | ||
952 | void TextEdit::updateCaption( const QString &name ) { | 949 | void TextEdit::updateCaption( const QString &name ) { |
953 | 950 | ||
954 | if ( name.isEmpty() ) | 951 | if ( name.isEmpty() ) |
955 | setCaption( tr("Text Editor") ); | 952 | setCaption( tr("Text Editor") ); |
956 | else { | 953 | else { |
957 | QString s = name; | 954 | QString s = name; |
958 | if ( s.isNull() ) | 955 | if ( s.isNull() ) |
959 | s = doc->name(); | 956 | s = doc->name(); |
960 | if ( s.isEmpty() ) { | 957 | if ( s.isEmpty() ) { |
961 | s = tr( "Unnamed" ); | 958 | s = tr( "Unnamed" ); |
962 | currentFileName=s; | 959 | currentFileName=s; |
963 | } | 960 | } |
964 | // if(s.left(1) == "/") | 961 | // if(s.left(1) == "/") |
965 | // s = s.right(s.length()-1); | 962 | // s = s.right(s.length()-1); |
966 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 963 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
967 | } | 964 | } |
968 | } | 965 | } |
969 | 966 | ||
970 | void TextEdit::setDocument(const QString& fileref) { | 967 | void TextEdit::setDocument(const QString& fileref) { |
971 | if(fileref != "Unnamed") { | 968 | if(fileref != "Unnamed") { |
972 | currentFileName=fileref; | 969 | currentFileName=fileref; |
973 | odebug << "setDocument" << oendl; | 970 | odebug << "setDocument" << oendl; |
974 | QFileInfo fi(currentFileName); | 971 | QFileInfo fi(currentFileName); |
975 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; | 972 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; |
976 | if( (fi.baseName().left(1)).isEmpty() ) { | 973 | if( (fi.baseName().left(1)).isEmpty() ) { |
977 | openDotFile(currentFileName); | 974 | openDotFile(currentFileName); |
978 | 975 | ||
979 | } else { | 976 | } else { |
980 | odebug << "setDoc open" << oendl; | 977 | odebug << "setDoc open" << oendl; |
981 | bFromDocView = true; | 978 | bFromDocView = true; |
982 | openFile(fileref); | 979 | openFile(fileref); |
983 | editor->setEdited(true); | 980 | editor->setEdited(true); |
984 | edited1=false; | 981 | edited1=false; |
985 | edited=true; | 982 | edited=true; |
986 | // fromSetDocument=false; | 983 | // fromSetDocument=false; |
987 | // doSearchBar(); | 984 | // doSearchBar(); |
988 | } | 985 | } |
989 | } | 986 | } |
990 | updateCaption( currentFileName); | 987 | updateCaption( currentFileName); |
991 | } | 988 | } |
992 | 989 | ||
993 | void TextEdit::changeFont() { | 990 | void TextEdit::changeFont() { |
994 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 991 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
995 | d-> setCaption ( tr( "Choose font" )); | 992 | d-> setCaption ( tr( "Choose font" )); |
996 | QBoxLayout *lay = new QVBoxLayout ( d ); | 993 | QBoxLayout *lay = new QVBoxLayout ( d ); |
997 | OFontSelector *ofs = new OFontSelector ( true, d ); | 994 | OFontSelector *ofs = new OFontSelector ( true, d ); |
998 | lay-> addWidget ( ofs ); | 995 | lay-> addWidget ( ofs ); |
999 | ofs-> setSelectedFont ( editor-> font ( )); | 996 | ofs-> setSelectedFont ( editor-> font ( )); |
1000 | 997 | ||
1001 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) | 998 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) |
1002 | editor-> setFont ( ofs-> selectedFont ( )); | 999 | editor-> setFont ( ofs-> selectedFont ( )); |
1003 | delete d; | 1000 | delete d; |
1004 | 1001 | ||
1005 | } | 1002 | } |
1006 | 1003 | ||
1007 | void TextEdit::editDelete() { | 1004 | void TextEdit::editDelete() { |
1008 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1005 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1009 | tr("Do you really want<BR>to <B>delete</B> " | 1006 | tr("Do you really want<BR>to <B>delete</B> " |
1010 | "the current file\nfrom the disk?<BR>This is " | 1007 | "the current file\nfrom the disk?<BR>This is " |
1011 | "<B>irreversable!</B>"), | 1008 | "<B>irreversable!</B>"), |
1012 | tr("Yes"),tr("No"),0,0,1) ) { | 1009 | tr("Yes"),tr("No"),0,0,1) ) { |
1013 | case 0: | 1010 | case 0: |
1014 | if(doc) { | 1011 | if(doc) { |
1015 | doc->removeFiles(); | 1012 | doc->removeFiles(); |
1016 | clear(); | 1013 | clear(); |
1017 | setCaption( tr("Text Editor") ); | 1014 | setCaption( tr("Text Editor") ); |
1018 | } | 1015 | } |
1019 | break; | 1016 | break; |
1020 | case 1: | 1017 | case 1: |
1021 | // exit | 1018 | // exit |
1022 | break; | 1019 | break; |
1023 | }; | 1020 | }; |
1024 | } | 1021 | } |
1025 | 1022 | ||
1026 | void TextEdit::changeStartConfig( bool b ) { | 1023 | void TextEdit::changeStartConfig( bool b ) { |
1027 | startWithNew=b; | 1024 | startWithNew=b; |
1028 | Config cfg("TextEdit"); | 1025 | Config cfg("TextEdit"); |
1029 | cfg.setGroup("View"); | 1026 | cfg.setGroup("View"); |
1030 | cfg.writeEntry("startNew",b); | 1027 | cfg.writeEntry("startNew",b); |
1031 | update(); | 1028 | update(); |