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