author | llornkcor <llornkcor> | 2004-10-18 09:18:50 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2004-10-18 09:18:50 (UTC) |
commit | b4a613303322cd557915baa621d4a1cef749af59 (patch) (unidiff) | |
tree | 2bb7ba0e89ce00d0ccb408a69ae79b5c38af6b0e | |
parent | e95fcb09fc069a83b3c10c19c081873daba49831 (diff) | |
download | opie-b4a613303322cd557915baa621d4a1cef749af59.zip opie-b4a613303322cd557915baa621d4a1cef749af59.tar.gz opie-b4a613303322cd557915baa621d4a1cef749af59.tar.bz2 |
change doclnk handling
-rw-r--r-- | core/apps/textedit/textedit.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 571df27..cabeb20 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -599,521 +599,522 @@ void TextEdit::slotFind() { | |||
599 | frmFind.exec(); | 599 | frmFind.exec(); |
600 | 600 | ||
601 | 601 | ||
602 | } | 602 | } |
603 | #endif | 603 | #endif |
604 | 604 | ||
605 | void TextEdit::fileRevert() { | 605 | void TextEdit::fileRevert() { |
606 | clear(); | 606 | clear(); |
607 | fileOpen(); | 607 | fileOpen(); |
608 | } | 608 | } |
609 | 609 | ||
610 | void TextEdit::editCut() { | 610 | void TextEdit::editCut() { |
611 | #ifndef QT_NO_CLIPBOARD | 611 | #ifndef QT_NO_CLIPBOARD |
612 | editor->cut(); | 612 | editor->cut(); |
613 | #endif | 613 | #endif |
614 | } | 614 | } |
615 | 615 | ||
616 | void TextEdit::editCopy() { | 616 | void TextEdit::editCopy() { |
617 | #ifndef QT_NO_CLIPBOARD | 617 | #ifndef QT_NO_CLIPBOARD |
618 | editor->copy(); | 618 | editor->copy(); |
619 | #endif | 619 | #endif |
620 | } | 620 | } |
621 | 621 | ||
622 | void TextEdit::editPaste() { | 622 | void TextEdit::editPaste() { |
623 | #ifndef QT_NO_CLIPBOARD | 623 | #ifndef QT_NO_CLIPBOARD |
624 | editor->paste(); | 624 | editor->paste(); |
625 | #endif | 625 | #endif |
626 | } | 626 | } |
627 | 627 | ||
628 | void TextEdit::editFind() { | 628 | void TextEdit::editFind() { |
629 | searchBar->show(); | 629 | searchBar->show(); |
630 | searchEdit->setFocus(); | 630 | searchEdit->setFocus(); |
631 | } | 631 | } |
632 | 632 | ||
633 | void TextEdit::findNext() { | 633 | void TextEdit::findNext() { |
634 | editor->find( searchEdit->text(), false, false ); | 634 | editor->find( searchEdit->text(), false, false ); |
635 | 635 | ||
636 | } | 636 | } |
637 | 637 | ||
638 | void TextEdit::findClose() { | 638 | void TextEdit::findClose() { |
639 | searchBar->hide(); | 639 | searchBar->hide(); |
640 | } | 640 | } |
641 | 641 | ||
642 | void TextEdit::search() { | 642 | void TextEdit::search() { |
643 | editor->find( searchEdit->text(), false, false ); | 643 | editor->find( searchEdit->text(), false, false ); |
644 | } | 644 | } |
645 | 645 | ||
646 | void TextEdit::newFile( const DocLnk &f ) { | 646 | void TextEdit::newFile( const DocLnk &f ) { |
647 | DocLnk nf = f; | 647 | DocLnk nf = f; |
648 | nf.setType("text/plain"); | 648 | nf.setType("text/plain"); |
649 | clear(); | 649 | clear(); |
650 | setWState (WState_Reserved1 ); | 650 | setWState (WState_Reserved1 ); |
651 | editor->setFocus(); | 651 | editor->setFocus(); |
652 | doc = new DocLnk(nf); | 652 | doc = new DocLnk(nf); |
653 | currentFileName = "Unnamed"; | 653 | currentFileName = "Unnamed"; |
654 | odebug << "newFile "+currentFileName << oendl; | 654 | odebug << "newFile "+currentFileName << oendl; |
655 | updateCaption( currentFileName); | 655 | updateCaption( currentFileName); |
656 | // editor->setEdited( false); | 656 | // editor->setEdited( false); |
657 | } | 657 | } |
658 | 658 | ||
659 | void TextEdit::openDotFile( const QString &f ) { | 659 | void TextEdit::openDotFile( const QString &f ) { |
660 | if(!currentFileName.isEmpty()) { | 660 | if(!currentFileName.isEmpty()) { |
661 | currentFileName=f; | 661 | currentFileName=f; |
662 | 662 | ||
663 | odebug << "openFile dotfile " + currentFileName << oendl; | 663 | odebug << "openFile dotfile " + currentFileName << oendl; |
664 | QString txt; | 664 | QString txt; |
665 | QFile file(f); | 665 | QFile file(f); |
666 | file.open(IO_ReadWrite); | 666 | file.open(IO_ReadWrite); |
667 | QTextStream t(&file); | 667 | QTextStream t(&file); |
668 | while ( !t.atEnd()) { | 668 | while ( !t.atEnd()) { |
669 | txt+=t.readLine()+"\n"; | 669 | txt+=t.readLine()+"\n"; |
670 | } | 670 | } |
671 | editor->setText(txt); | 671 | editor->setText(txt); |
672 | editor->setEdited( false); | 672 | editor->setEdited( false); |
673 | edited1=false; | 673 | edited1=false; |
674 | edited=false; | 674 | edited=false; |
675 | 675 | ||
676 | 676 | ||
677 | } | 677 | } |
678 | updateCaption( currentFileName); | 678 | updateCaption( currentFileName); |
679 | } | 679 | } |
680 | 680 | ||
681 | void TextEdit::openFile( const QString &f ) { | 681 | void TextEdit::openFile( const QString &f ) { |
682 | odebug << "filename is "+ f << oendl; | 682 | odebug << "filename is "+ f << oendl; |
683 | QString filer; | 683 | QString filer; |
684 | QFileInfo fi( f); | 684 | QFileInfo fi( f); |
685 | // bFromDocView = true; | 685 | // bFromDocView = true; |
686 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 686 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
687 | { | 687 | { |
688 | 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) ) | 688 | 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) ) |
689 | { | 689 | { |
690 | case 0: //desktop | 690 | case 0: //desktop |
691 | filer = f; | 691 | filer = f; |
692 | break; | 692 | break; |
693 | case 1: //linked | 693 | case 1: //linked |
694 | DocLnk sf(f); | 694 | DocLnk sf(f); |
695 | filer = sf.file(); | 695 | filer = sf.file(); |
696 | break; | 696 | break; |
697 | }; | 697 | }; |
698 | } | 698 | } |
699 | else if(fi.baseName().left(1) == "") | 699 | else if(fi.baseName().left(1) == "") |
700 | { | 700 | { |
701 | odebug << "opening dotfile" << oendl; | 701 | odebug << "opening dotfile" << oendl; |
702 | currentFileName=f; | 702 | currentFileName=f; |
703 | openDotFile(currentFileName); | 703 | openDotFile(currentFileName); |
704 | return; | 704 | return; |
705 | } | 705 | } |
706 | /* | 706 | /* |
707 | * The problem is a file where Config(f).isValid() and it does not | 707 | * The problem is a file where Config(f).isValid() and it does not |
708 | * end with .desktop will be treated as desktop file | 708 | * end with .desktop will be treated as desktop file |
709 | */ | 709 | */ |
710 | else if (f.find(".desktop",0,true) != -1 ) | 710 | else if (f.find(".desktop",0,true) != -1 ) |
711 | { | 711 | { |
712 | DocLnk sf(f); | 712 | DocLnk sf(f); |
713 | filer = sf.file(); | 713 | filer = sf.file(); |
714 | if(filer.right(1) == "/") | 714 | if(filer.right(1) == "/") |
715 | filer = f; | 715 | filer = f; |
716 | 716 | ||
717 | } | 717 | } |
718 | else | 718 | else |
719 | filer = f; | 719 | filer = f; |
720 | 720 | ||
721 | DocLnk nf; | 721 | DocLnk nf; |
722 | nf.setType("text/plain"); | 722 | nf.setType("text/plain"); |
723 | nf.setFile(filer); | 723 | nf.setFile(filer); |
724 | currentFileName=filer; | 724 | currentFileName=filer; |
725 | 725 | ||
726 | nf.setName(fi.baseName()); | 726 | nf.setName(fi.baseName()); |
727 | openFile(nf); | 727 | openFile(nf); |
728 | 728 | ||
729 | odebug << "openFile string "+currentFileName << oendl; | 729 | odebug << "openFile string "+currentFileName << oendl; |
730 | 730 | ||
731 | showEditTools(); | 731 | showEditTools(); |
732 | // Show filename in caption | 732 | // Show filename in caption |
733 | QString name = filer; | 733 | QString name = filer; |
734 | int sep = name.findRev( '/' ); | 734 | int sep = name.findRev( '/' ); |
735 | if ( sep > 0 ) | 735 | if ( sep > 0 ) |
736 | name = name.mid( sep+1 ); | 736 | name = name.mid( sep+1 ); |
737 | updateCaption( name ); | 737 | updateCaption( name ); |
738 | } | 738 | } |
739 | 739 | ||
740 | void TextEdit::openFile( const DocLnk &f ) { | 740 | void TextEdit::openFile( const DocLnk &f ) { |
741 | // clear(); | 741 | // clear(); |
742 | // bFromDocView = true; | 742 | // bFromDocView = true; |
743 | FileManager fm; | 743 | FileManager fm; |
744 | QString txt; | 744 | QString txt; |
745 | currentFileName=f.file(); | 745 | currentFileName=f.file(); |
746 | odebug << "openFile doclnk " + currentFileName << oendl; | 746 | odebug << "openFile doclnk " + currentFileName << oendl; |
747 | if ( !fm.loadFile( f, txt ) ) { | 747 | if ( !fm.loadFile( f, txt ) ) { |
748 | // ####### could be a new file | 748 | // ####### could be a new file |
749 | odebug << "Cannot open file" << oendl; | 749 | odebug << "Cannot open file" << oendl; |
750 | } | 750 | } |
751 | // fileNew(); | 751 | // fileNew(); |
752 | if ( doc ) | 752 | if ( doc ) |
753 | delete doc; | 753 | delete doc; |
754 | doc = new DocLnk(f); | 754 | doc = new DocLnk(f); |
755 | editor->setText(txt); | 755 | editor->setText(txt); |
756 | editor->setEdited( false); | 756 | editor->setEdited( false); |
757 | edited1=false; | 757 | edited1=false; |
758 | edited=false; | 758 | edited=false; |
759 | 759 | ||
760 | doc->setName(currentFileName); | 760 | doc->setName(currentFileName); |
761 | updateCaption(); | 761 | updateCaption(); |
762 | setTimer(); | 762 | setTimer(); |
763 | } | 763 | } |
764 | 764 | ||
765 | void TextEdit::showEditTools() { | 765 | void TextEdit::showEditTools() { |
766 | menu->show(); | 766 | menu->show(); |
767 | editBar->show(); | 767 | editBar->show(); |
768 | if(!useSearchBar) | 768 | if(!useSearchBar) |
769 | searchBar->hide(); | 769 | searchBar->hide(); |
770 | else | 770 | else |
771 | searchBar->show(); | 771 | searchBar->show(); |
772 | setWState (WState_Reserved1 ); | 772 | setWState (WState_Reserved1 ); |
773 | } | 773 | } |
774 | 774 | ||
775 | /*! | 775 | /*! |
776 | unprompted save */ | 776 | unprompted save */ |
777 | bool TextEdit::save() { | 777 | bool TextEdit::save() { |
778 | QString name, file; | 778 | QString name, file; |
779 | odebug << "saveAsFile " + currentFileName << oendl; | 779 | odebug << "saveAsFile " + currentFileName << oendl; |
780 | if(currentFileName.isEmpty()) { | 780 | if(currentFileName.isEmpty()) { |
781 | saveAs(); | 781 | saveAs(); |
782 | return false; | 782 | return false; |
783 | } | 783 | } |
784 | name = currentFileName; | 784 | name = currentFileName; |
785 | if(doc) { | 785 | if(doc) { |
786 | file = doc->file(); | 786 | file = doc->file(); |
787 | odebug << "saver file "+file << oendl; | 787 | odebug << "saver file "+file << oendl; |
788 | name = doc->name(); | 788 | name = doc->name(); |
789 | odebug << "File named "+name << oendl; | 789 | odebug << "File named "+name << oendl; |
790 | } else { | 790 | } else { |
791 | name = file = currentFileName; | 791 | file = currentFileName; |
792 | name = QFileInfo(currentFileName).baseName(); | ||
792 | } | 793 | } |
793 | 794 | ||
794 | QString rt = editor->text(); | 795 | QString rt = editor->text(); |
795 | if( !rt.isEmpty() ) { | 796 | if( !rt.isEmpty() ) { |
796 | if(name.isEmpty()) { | 797 | if(name.isEmpty()) { |
797 | saveAs(); | 798 | saveAs(); |
798 | } else { | 799 | } else { |
799 | currentFileName = name; | 800 | currentFileName = name; |
800 | odebug << "saveFile "+currentFileName << oendl; | 801 | odebug << "saveFile "+currentFileName << oendl; |
801 | 802 | ||
802 | struct stat buf; | 803 | struct stat buf; |
803 | mode_t mode; | 804 | mode_t mode; |
804 | stat(file.latin1(), &buf); | 805 | stat(file.latin1(), &buf); |
805 | mode = buf.st_mode; | 806 | mode = buf.st_mode; |
806 | 807 | ||
807 | if(!fileIs) { | 808 | if(!fileIs) { |
808 | doc->setName( name); | 809 | doc->setName( name); |
809 | FileManager fm; | 810 | FileManager fm; |
810 | if ( !fm.saveFile( *doc, rt ) ) { | 811 | if ( !fm.saveFile( *doc, rt ) ) { |
811 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 812 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
812 | return false; | 813 | return false; |
813 | } | 814 | } |
814 | } else { | 815 | } else { |
815 | odebug << "regular save file" << oendl; | 816 | odebug << "regular save file" << oendl; |
816 | QFile f(file); | 817 | QFile f(file); |
817 | if( f.open(IO_WriteOnly)) { | 818 | if( f.open(IO_WriteOnly)) { |
818 | QCString crt = rt.utf8(); | 819 | QCString crt = rt.utf8(); |
819 | f.writeBlock(crt,crt.length()); | 820 | f.writeBlock(crt,crt.length()); |
820 | } else { | 821 | } else { |
821 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 822 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
822 | return false; | 823 | return false; |
823 | } | 824 | } |
824 | 825 | ||
825 | } | 826 | } |
826 | editor->setEdited( false); | 827 | editor->setEdited( false); |
827 | edited1=false; | 828 | edited1=false; |
828 | edited=false; | 829 | edited=false; |
829 | if(caption().left(1)=="*") | 830 | if(caption().left(1)=="*") |
830 | setCaption(caption().right(caption().length()-1)); | 831 | setCaption(caption().right(caption().length()-1)); |
831 | 832 | ||
832 | 833 | ||
833 | chmod( file.latin1(), mode); | 834 | chmod( file.latin1(), mode); |
834 | } | 835 | } |
835 | return true; | 836 | return true; |
836 | } | 837 | } |
837 | return false; | 838 | return false; |
838 | } | 839 | } |
839 | 840 | ||
840 | /*! | 841 | /*! |
841 | prompted save */ | 842 | prompted save */ |
842 | bool TextEdit::saveAs() { | 843 | bool TextEdit::saveAs() { |
843 | 844 | ||
844 | if(caption() == tr("Text Editor")) | 845 | if(caption() == tr("Text Editor")) |
845 | return false; | 846 | return false; |
846 | odebug << "saveAsFile " + currentFileName << oendl; | 847 | odebug << "saveAsFile " + currentFileName << oendl; |
847 | // case of nothing to save... | 848 | // case of nothing to save... |
848 | // if ( !doc && !currentFileName.isEmpty()) { | 849 | // if ( !doc && !currentFileName.isEmpty()) { |
849 | // //|| !bFromDocView) | 850 | // //|| !bFromDocView) |
850 | // odebug << "no doc" << oendl; | 851 | // odebug << "no doc" << oendl; |
851 | // return true; | 852 | // return true; |
852 | // } | 853 | // } |
853 | // if ( !editor->edited() ) { | 854 | // if ( !editor->edited() ) { |
854 | // delete doc; | 855 | // delete doc; |
855 | // doc = 0; | 856 | // doc = 0; |
856 | // return true; | 857 | // return true; |
857 | // } | 858 | // } |
858 | 859 | ||
859 | QString rt = editor->text(); | 860 | QString rt = editor->text(); |
860 | odebug << currentFileName << oendl; | 861 | odebug << currentFileName << oendl; |
861 | 862 | ||
862 | if( currentFileName.isEmpty() | 863 | if( currentFileName.isEmpty() |
863 | || currentFileName == tr("Unnamed") | 864 | || currentFileName == tr("Unnamed") |
864 | || currentFileName == tr("Text Editor")) { | 865 | || currentFileName == tr("Text Editor")) { |
865 | odebug << "do silly TT filename thing" << oendl; | 866 | odebug << "do silly TT filename thing" << oendl; |
866 | // if ( doc && doc->name().isEmpty() ) { | 867 | // if ( doc && doc->name().isEmpty() ) { |
867 | QString pt = rt.simplifyWhiteSpace(); | 868 | QString pt = rt.simplifyWhiteSpace(); |
868 | int i = pt.find( ' ' ); | 869 | int i = pt.find( ' ' ); |
869 | QString docname = pt; | 870 | QString docname = pt; |
870 | if ( i > 0 ) | 871 | if ( i > 0 ) |
871 | docname = pt.left( i ); | 872 | docname = pt.left( i ); |
872 | // remove "." at the beginning | 873 | // remove "." at the beginning |
873 | while( docname.startsWith( "." ) ) | 874 | while( docname.startsWith( "." ) ) |
874 | docname = docname.mid( 1 ); | 875 | docname = docname.mid( 1 ); |
875 | docname.replace( QRegExp("/"), "_" ); | 876 | docname.replace( QRegExp("/"), "_" ); |
876 | // cut the length. filenames longer than that | 877 | // cut the length. filenames longer than that |
877 | //don't make sense and something goes wrong when they get too long. | 878 | //don't make sense and something goes wrong when they get too long. |
878 | if ( docname.length() > 40 ) | 879 | if ( docname.length() > 40 ) |
879 | docname = docname.left(40); | 880 | docname = docname.left(40); |
880 | if ( docname.isEmpty() ) | 881 | if ( docname.isEmpty() ) |
881 | docname = tr("Unnamed"); | 882 | docname = tr("Unnamed"); |
882 | if(doc) doc->setName(docname); | 883 | if(doc) doc->setName(docname); |
883 | currentFileName=docname; | 884 | currentFileName=docname; |
884 | // } | 885 | // } |
885 | // else | 886 | // else |
886 | // odebug << "hmmmmmm" << oendl; | 887 | // odebug << "hmmmmmm" << oendl; |
887 | } | 888 | } |
888 | 889 | ||
889 | 890 | ||
890 | QMap<QString, QStringList> map; | 891 | QMap<QString, QStringList> map; |
891 | map.insert(tr("All"), QStringList() ); | 892 | map.insert(tr("All"), QStringList() ); |
892 | QStringList text; | 893 | QStringList text; |
893 | text << "text/*"; | 894 | text << "text/*"; |
894 | map.insert(tr("Text"), text ); | 895 | map.insert(tr("Text"), text ); |
895 | text << "*"; | 896 | text << "*"; |
896 | map.insert(tr("All"), text ); | 897 | map.insert(tr("All"), text ); |
897 | 898 | ||
898 | QFileInfo cuFi( currentFileName); | 899 | QFileInfo cuFi( currentFileName); |
899 | QString filee = cuFi.fileName(); | 900 | QString filee = cuFi.fileName(); |
900 | QString dire = cuFi.dirPath(); | 901 | QString dire = cuFi.dirPath(); |
901 | if(dire==".") | 902 | if(dire==".") |
902 | dire = QPEApplication::documentDir(); | 903 | dire = QPEApplication::documentDir(); |
903 | QString str; | 904 | QString str; |
904 | if( !featureAutoSave) { | 905 | if( !featureAutoSave) { |
905 | str = OFileDialog::getSaveFileName( 2, | 906 | str = OFileDialog::getSaveFileName( 2, |
906 | dire, | 907 | dire, |
907 | filee, map); | 908 | filee, map); |
908 | } else | 909 | } else |
909 | str=currentFileName; | 910 | str=currentFileName; |
910 | 911 | ||
911 | if(!str.isEmpty()) { | 912 | if(!str.isEmpty()) { |
912 | QString fileNm=str; | 913 | QString fileNm=str; |
913 | 914 | ||
914 | odebug << "saving filename "+fileNm << oendl; | 915 | odebug << "saving filename "+fileNm << oendl; |
915 | QFileInfo fi(fileNm); | 916 | QFileInfo fi(fileNm); |
916 | currentFileName=fi.fileName(); | 917 | currentFileName=fi.fileName(); |
917 | if(doc) | 918 | if(doc) |
918 | // QString file = doc->file(); | 919 | // QString file = doc->file(); |
919 | // doc->removeFiles(); | 920 | // doc->removeFiles(); |
920 | delete doc; | 921 | delete doc; |
921 | DocLnk nf; | 922 | DocLnk nf; |
922 | nf.setType("text/plain"); | 923 | nf.setType("text/plain"); |
923 | nf.setFile( fileNm); | 924 | nf.setFile( fileNm); |
924 | doc = new DocLnk(nf); | 925 | doc = new DocLnk(nf); |
925 | // editor->setText(rt); | 926 | // editor->setText(rt); |
926 | odebug << "Saving file as "+currentFileName << oendl; | 927 | odebug << "Saving file as "+currentFileName << oendl; |
927 | doc->setName( currentFileName); | 928 | doc->setName( fi.baseName() /*currentFileName*/); |
928 | updateCaption( currentFileName); | 929 | updateCaption( currentFileName); |
929 | 930 | ||
930 | FileManager fm; | 931 | FileManager fm; |
931 | if ( !fm.saveFile( *doc, rt ) ) { | 932 | if ( !fm.saveFile( *doc, rt ) ) { |
932 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 933 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
933 | return false; | 934 | return false; |
934 | } | 935 | } |
935 | 936 | ||
936 | if( filePerms ) { | 937 | if( filePerms ) { |
937 | filePermissions *filePerm; | 938 | filePermissions *filePerm; |
938 | filePerm = new filePermissions(this, | 939 | filePerm = new filePermissions(this, |
939 | tr("Permissions"),true, | 940 | tr("Permissions"),true, |
940 | 0,(const QString &)fileNm); | 941 | 0,(const QString &)fileNm); |
941 | QPEApplication::execDialog( filePerm ); | 942 | QPEApplication::execDialog( filePerm ); |
942 | 943 | ||
943 | if( filePerm) | 944 | if( filePerm) |
944 | delete filePerm; | 945 | delete filePerm; |
945 | } | 946 | } |
946 | // } | 947 | // } |
947 | editor->setEdited( false); | 948 | editor->setEdited( false); |
948 | edited1 = false; | 949 | edited1 = false; |
949 | edited = false; | 950 | edited = false; |
950 | if(caption().left(1)=="*") | 951 | if(caption().left(1)=="*") |
951 | setCaption(caption().right(caption().length()-1)); | 952 | setCaption(caption().right(caption().length()-1)); |
952 | 953 | ||
953 | return true; | 954 | return true; |
954 | } | 955 | } |
955 | odebug << "returning false" << oendl; | 956 | odebug << "returning false" << oendl; |
956 | currentFileName = ""; | 957 | currentFileName = ""; |
957 | return false; | 958 | return false; |
958 | } //end saveAs | 959 | } //end saveAs |
959 | 960 | ||
960 | void TextEdit::clear() { | 961 | void TextEdit::clear() { |
961 | delete doc; | 962 | delete doc; |
962 | doc = 0; | 963 | doc = 0; |
963 | editor->clear(); | 964 | editor->clear(); |
964 | } | 965 | } |
965 | 966 | ||
966 | void TextEdit::updateCaption( const QString &name ) { | 967 | void TextEdit::updateCaption( const QString &name ) { |
967 | 968 | ||
968 | if ( name.isEmpty() ) | 969 | if ( name.isEmpty() ) |
969 | setCaption( tr("Text Editor") ); | 970 | setCaption( tr("Text Editor") ); |
970 | else { | 971 | else { |
971 | QString s = name; | 972 | QString s = name; |
972 | if ( s.isNull() ) | 973 | if ( s.isNull() ) |
973 | s = doc->name(); | 974 | s = doc->name(); |
974 | if ( s.isEmpty() ) { | 975 | if ( s.isEmpty() ) { |
975 | s = tr( "Unnamed" ); | 976 | s = tr( "Unnamed" ); |
976 | currentFileName=s; | 977 | currentFileName=s; |
977 | } | 978 | } |
978 | // if(s.left(1) == "/") | 979 | // if(s.left(1) == "/") |
979 | // s = s.right(s.length()-1); | 980 | // s = s.right(s.length()-1); |
980 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 981 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
981 | } | 982 | } |
982 | } | 983 | } |
983 | 984 | ||
984 | void TextEdit::setDocument(const QString& fileref) { | 985 | void TextEdit::setDocument(const QString& fileref) { |
985 | if(fileref != "Unnamed") { | 986 | if(fileref != "Unnamed") { |
986 | currentFileName=fileref; | 987 | currentFileName=fileref; |
987 | odebug << "setDocument" << oendl; | 988 | odebug << "setDocument" << oendl; |
988 | QFileInfo fi(currentFileName); | 989 | QFileInfo fi(currentFileName); |
989 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; | 990 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; |
990 | if( (fi.baseName().left(1)).isEmpty() ) { | 991 | if( (fi.baseName().left(1)).isEmpty() ) { |
991 | openDotFile(currentFileName); | 992 | openDotFile(currentFileName); |
992 | 993 | ||
993 | } else { | 994 | } else { |
994 | odebug << "setDoc open" << oendl; | 995 | odebug << "setDoc open" << oendl; |
995 | bFromDocView = true; | 996 | bFromDocView = true; |
996 | openFile(fileref); | 997 | openFile(fileref); |
997 | editor->setEdited(true); | 998 | editor->setEdited(true); |
998 | edited1=false; | 999 | edited1=false; |
999 | edited=true; | 1000 | edited=true; |
1000 | // fromSetDocument=false; | 1001 | // fromSetDocument=false; |
1001 | // doSearchBar(); | 1002 | // doSearchBar(); |
1002 | } | 1003 | } |
1003 | } | 1004 | } |
1004 | updateCaption( currentFileName); | 1005 | updateCaption( currentFileName); |
1005 | } | 1006 | } |
1006 | 1007 | ||
1007 | void TextEdit::changeFont() { | 1008 | void TextEdit::changeFont() { |
1008 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1009 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1009 | d-> setCaption ( tr( "Choose font" )); | 1010 | d-> setCaption ( tr( "Choose font" )); |
1010 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1011 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1011 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1012 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1012 | lay-> addWidget ( ofs ); | 1013 | lay-> addWidget ( ofs ); |
1013 | ofs-> setSelectedFont ( editor-> font ( )); | 1014 | ofs-> setSelectedFont ( editor-> font ( )); |
1014 | 1015 | ||
1015 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) | 1016 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) |
1016 | editor-> setFont ( ofs-> selectedFont ( )); | 1017 | editor-> setFont ( ofs-> selectedFont ( )); |
1017 | delete d; | 1018 | delete d; |
1018 | 1019 | ||
1019 | } | 1020 | } |
1020 | 1021 | ||
1021 | void TextEdit::editDelete() { | 1022 | void TextEdit::editDelete() { |
1022 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1023 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1023 | tr("Do you really want<BR>to <B>delete</B> " | 1024 | tr("Do you really want<BR>to <B>delete</B> " |
1024 | "the current file\nfrom the disk?<BR>This is " | 1025 | "the current file\nfrom the disk?<BR>This is " |
1025 | "<B>irreversable!</B>"), | 1026 | "<B>irreversable!</B>"), |
1026 | tr("Yes"),tr("No"),0,0,1) ) { | 1027 | tr("Yes"),tr("No"),0,0,1) ) { |
1027 | case 0: | 1028 | case 0: |
1028 | if(doc) { | 1029 | if(doc) { |
1029 | doc->removeFiles(); | 1030 | doc->removeFiles(); |
1030 | clear(); | 1031 | clear(); |
1031 | setCaption( tr("Text Editor") ); | 1032 | setCaption( tr("Text Editor") ); |
1032 | } | 1033 | } |
1033 | break; | 1034 | break; |
1034 | case 1: | 1035 | case 1: |
1035 | // exit | 1036 | // exit |
1036 | break; | 1037 | break; |
1037 | }; | 1038 | }; |
1038 | } | 1039 | } |
1039 | 1040 | ||
1040 | void TextEdit::changeStartConfig( bool b ) { | 1041 | void TextEdit::changeStartConfig( bool b ) { |
1041 | startWithNew=b; | 1042 | startWithNew=b; |
1042 | Config cfg("TextEdit"); | 1043 | Config cfg("TextEdit"); |
1043 | cfg.setGroup("View"); | 1044 | cfg.setGroup("View"); |
1044 | cfg.writeEntry("startNew",b); | 1045 | cfg.writeEntry("startNew",b); |
1045 | update(); | 1046 | update(); |
1046 | } | 1047 | } |
1047 | 1048 | ||
1048 | void TextEdit::editorChanged() { | 1049 | void TextEdit::editorChanged() { |
1049 | // odebug << "editor changed" << oendl; | 1050 | // odebug << "editor changed" << oendl; |
1050 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1051 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1051 | setCaption( "*"+caption()); | 1052 | setCaption( "*"+caption()); |
1052 | edited1=true; | 1053 | edited1=true; |
1053 | } | 1054 | } |
1054 | edited=true; | 1055 | edited=true; |
1055 | } | 1056 | } |
1056 | 1057 | ||
1057 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1058 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1058 | odebug << "QCop "+msg << oendl; | 1059 | odebug << "QCop "+msg << oendl; |
1059 | if ( msg == "setDocument(QString)" ) { | 1060 | if ( msg == "setDocument(QString)" ) { |
1060 | odebug << "bugger all" << oendl; | 1061 | odebug << "bugger all" << oendl; |
1061 | 1062 | ||
1062 | } | 1063 | } |
1063 | 1064 | ||
1064 | } | 1065 | } |
1065 | 1066 | ||
1066 | void TextEdit::doAbout() { | 1067 | void TextEdit::doAbout() { |
1067 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1068 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1068 | "2000 Trolltech AS, and<BR>" | 1069 | "2000 Trolltech AS, and<BR>" |
1069 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1070 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1070 | "and is licensed under the GPL")); | 1071 | "and is licensed under the GPL")); |
1071 | } | 1072 | } |
1072 | 1073 | ||
1073 | void TextEdit::doPrompt(bool b) { | 1074 | void TextEdit::doPrompt(bool b) { |
1074 | promptExit=b; | 1075 | promptExit=b; |
1075 | Config cfg("TextEdit"); | 1076 | Config cfg("TextEdit"); |
1076 | cfg.setGroup ( "View" ); | 1077 | cfg.setGroup ( "View" ); |
1077 | cfg.writeEntry ( "PromptExit", b); | 1078 | cfg.writeEntry ( "PromptExit", b); |
1078 | } | 1079 | } |
1079 | 1080 | ||
1080 | void TextEdit::doDesktop(bool b) { | 1081 | void TextEdit::doDesktop(bool b) { |
1081 | openDesktop=b; | 1082 | openDesktop=b; |
1082 | Config cfg("TextEdit"); | 1083 | Config cfg("TextEdit"); |
1083 | cfg.setGroup ( "View" ); | 1084 | cfg.setGroup ( "View" ); |
1084 | cfg.writeEntry ( "OpenDesktop", b); | 1085 | cfg.writeEntry ( "OpenDesktop", b); |
1085 | } | 1086 | } |
1086 | 1087 | ||
1087 | void TextEdit::doFilePerms(bool b) { | 1088 | void TextEdit::doFilePerms(bool b) { |
1088 | filePerms=b; | 1089 | filePerms=b; |
1089 | Config cfg("TextEdit"); | 1090 | Config cfg("TextEdit"); |
1090 | cfg.setGroup ( "View" ); | 1091 | cfg.setGroup ( "View" ); |
1091 | cfg.writeEntry ( "FilePermissions", b); | 1092 | cfg.writeEntry ( "FilePermissions", b); |
1092 | } | 1093 | } |
1093 | 1094 | ||
1094 | void TextEdit::editPasteTimeDate() { | 1095 | void TextEdit::editPasteTimeDate() { |
1095 | #ifndef QT_NO_CLIPBOARD | 1096 | #ifndef QT_NO_CLIPBOARD |
1096 | QClipboard *cb = QApplication::clipboard(); | 1097 | QClipboard *cb = QApplication::clipboard(); |
1097 | QDateTime dt = QDateTime::currentDateTime(); | 1098 | QDateTime dt = QDateTime::currentDateTime(); |
1098 | cb->setText( dt.toString()); | 1099 | cb->setText( dt.toString()); |
1099 | editor->paste(); | 1100 | editor->paste(); |
1100 | #endif | 1101 | #endif |
1101 | } | 1102 | } |
1102 | 1103 | ||
1103 | int TextEdit::savePrompt() | 1104 | int TextEdit::savePrompt() |
1104 | { | 1105 | { |
1105 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1106 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1106 | (tr("Textedit detected\n" | 1107 | (tr("Textedit detected\n" |
1107 | "you have unsaved changes\n" | 1108 | "you have unsaved changes\n" |
1108 | "Go ahead and save?\n")), | 1109 | "Go ahead and save?\n")), |
1109 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1110 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1110 | { | 1111 | { |
1111 | case 0: | 1112 | case 0: |
1112 | { | 1113 | { |
1113 | return 1; | 1114 | return 1; |
1114 | } | 1115 | } |
1115 | break; | 1116 | break; |
1116 | 1117 | ||
1117 | case 1: | 1118 | case 1: |
1118 | { | 1119 | { |
1119 | return 2; | 1120 | return 2; |