author | zecke <zecke> | 2003-12-06 11:48:47 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-12-06 11:48:47 (UTC) |
commit | 72336536db05459e3802b3be5032e55607985d0c (patch) (unidiff) | |
tree | 6920e4d51efa0b5dd6977e536575c45c1bf785b4 | |
parent | faaeb2cd28b47d79e9644e770622d141d315c195 (diff) | |
download | opie-72336536db05459e3802b3be5032e55607985d0c.zip opie-72336536db05459e3802b3be5032e55607985d0c.tar.gz opie-72336536db05459e3802b3be5032e55607985d0c.tar.bz2 |
quirk for opening renamed desktop files...
-rw-r--r-- | core/apps/textedit/textedit.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 1c95a97..b875228 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -589,263 +589,270 @@ void TextEdit::fileOpen() { | |||
589 | 589 | ||
590 | void TextEdit::doSearchBar() { | 590 | void TextEdit::doSearchBar() { |
591 | if(!useSearchBar) | 591 | if(!useSearchBar) |
592 | searchBar->hide(); | 592 | searchBar->hide(); |
593 | else | 593 | else |
594 | searchBar->show(); | 594 | searchBar->show(); |
595 | } | 595 | } |
596 | 596 | ||
597 | #if 0 | 597 | #if 0 |
598 | void TextEdit::slotFind() { | 598 | void TextEdit::slotFind() { |
599 | FindDialog frmFind( tr("Text Editor"), this ); | 599 | FindDialog frmFind( tr("Text Editor"), this ); |
600 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 600 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
601 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 601 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
602 | 602 | ||
603 | //case sensitive, backwards, [category] | 603 | //case sensitive, backwards, [category] |
604 | 604 | ||
605 | connect( editor, SIGNAL(notFound()), | 605 | connect( editor, SIGNAL(notFound()), |
606 | &frmFind, SLOT(slotNotFound()) ); | 606 | &frmFind, SLOT(slotNotFound()) ); |
607 | connect( editor, SIGNAL(searchWrapped()), | 607 | connect( editor, SIGNAL(searchWrapped()), |
608 | &frmFind, SLOT(slotWrapAround()) ); | 608 | &frmFind, SLOT(slotWrapAround()) ); |
609 | 609 | ||
610 | frmFind.exec(); | 610 | frmFind.exec(); |
611 | 611 | ||
612 | 612 | ||
613 | } | 613 | } |
614 | #endif | 614 | #endif |
615 | 615 | ||
616 | void TextEdit::fileRevert() { | 616 | void TextEdit::fileRevert() { |
617 | clear(); | 617 | clear(); |
618 | fileOpen(); | 618 | fileOpen(); |
619 | } | 619 | } |
620 | 620 | ||
621 | void TextEdit::editCut() { | 621 | void TextEdit::editCut() { |
622 | #ifndef QT_NO_CLIPBOARD | 622 | #ifndef QT_NO_CLIPBOARD |
623 | editor->cut(); | 623 | editor->cut(); |
624 | #endif | 624 | #endif |
625 | } | 625 | } |
626 | 626 | ||
627 | void TextEdit::editCopy() { | 627 | void TextEdit::editCopy() { |
628 | #ifndef QT_NO_CLIPBOARD | 628 | #ifndef QT_NO_CLIPBOARD |
629 | editor->copy(); | 629 | editor->copy(); |
630 | #endif | 630 | #endif |
631 | } | 631 | } |
632 | 632 | ||
633 | void TextEdit::editPaste() { | 633 | void TextEdit::editPaste() { |
634 | #ifndef QT_NO_CLIPBOARD | 634 | #ifndef QT_NO_CLIPBOARD |
635 | editor->paste(); | 635 | editor->paste(); |
636 | #endif | 636 | #endif |
637 | } | 637 | } |
638 | 638 | ||
639 | void TextEdit::editFind() { | 639 | void TextEdit::editFind() { |
640 | searchBar->show(); | 640 | searchBar->show(); |
641 | searchEdit->setFocus(); | 641 | searchEdit->setFocus(); |
642 | } | 642 | } |
643 | 643 | ||
644 | void TextEdit::findNext() { | 644 | void TextEdit::findNext() { |
645 | editor->find( searchEdit->text(), false, false ); | 645 | editor->find( searchEdit->text(), false, false ); |
646 | 646 | ||
647 | } | 647 | } |
648 | 648 | ||
649 | void TextEdit::findClose() { | 649 | void TextEdit::findClose() { |
650 | searchBar->hide(); | 650 | searchBar->hide(); |
651 | } | 651 | } |
652 | 652 | ||
653 | void TextEdit::search() { | 653 | void TextEdit::search() { |
654 | editor->find( searchEdit->text(), false, false ); | 654 | editor->find( searchEdit->text(), false, false ); |
655 | } | 655 | } |
656 | 656 | ||
657 | void TextEdit::newFile( const DocLnk &f ) { | 657 | void TextEdit::newFile( const DocLnk &f ) { |
658 | DocLnk nf = f; | 658 | DocLnk nf = f; |
659 | nf.setType("text/plain"); | 659 | nf.setType("text/plain"); |
660 | clear(); | 660 | clear(); |
661 | setWState (WState_Reserved1 ); | 661 | setWState (WState_Reserved1 ); |
662 | editor->setFocus(); | 662 | editor->setFocus(); |
663 | doc = new DocLnk(nf); | 663 | doc = new DocLnk(nf); |
664 | currentFileName = "Unnamed"; | 664 | currentFileName = "Unnamed"; |
665 | qDebug("newFile "+currentFileName); | 665 | qDebug("newFile "+currentFileName); |
666 | updateCaption( currentFileName); | 666 | updateCaption( currentFileName); |
667 | // editor->setEdited( false); | 667 | // editor->setEdited( false); |
668 | } | 668 | } |
669 | 669 | ||
670 | void TextEdit::openDotFile( const QString &f ) { | 670 | void TextEdit::openDotFile( const QString &f ) { |
671 | if(!currentFileName.isEmpty()) { | 671 | if(!currentFileName.isEmpty()) { |
672 | currentFileName=f; | 672 | currentFileName=f; |
673 | 673 | ||
674 | qDebug("openFile dotfile " + currentFileName); | 674 | qDebug("openFile dotfile " + currentFileName); |
675 | QString txt; | 675 | QString txt; |
676 | QFile file(f); | 676 | QFile file(f); |
677 | file.open(IO_ReadWrite); | 677 | file.open(IO_ReadWrite); |
678 | QTextStream t(&file); | 678 | QTextStream t(&file); |
679 | while ( !t.atEnd()) { | 679 | while ( !t.atEnd()) { |
680 | txt+=t.readLine()+"\n"; | 680 | txt+=t.readLine()+"\n"; |
681 | } | 681 | } |
682 | editor->setText(txt); | 682 | editor->setText(txt); |
683 | editor->setEdited( false); | 683 | editor->setEdited( false); |
684 | edited1=false; | 684 | edited1=false; |
685 | edited=false; | 685 | edited=false; |
686 | 686 | ||
687 | 687 | ||
688 | } | 688 | } |
689 | updateCaption( currentFileName); | 689 | updateCaption( currentFileName); |
690 | } | 690 | } |
691 | 691 | ||
692 | void TextEdit::openFile( const QString &f ) { | 692 | void TextEdit::openFile( const QString &f ) { |
693 | qDebug("filename is "+ f); | 693 | qDebug("filename is "+ f); |
694 | QString filer; | 694 | QString filer; |
695 | QFileInfo fi( f); | 695 | QFileInfo fi( f); |
696 | // bFromDocView = true; | 696 | // bFromDocView = true; |
697 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 697 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
698 | { | 698 | { |
699 | 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) ) | 699 | 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) ) |
700 | { | 700 | { |
701 | case 0: //desktop | 701 | case 0: //desktop |
702 | filer = f; | 702 | filer = f; |
703 | break; | 703 | break; |
704 | case 1: //linked | 704 | case 1: //linked |
705 | DocLnk sf(f); | 705 | DocLnk sf(f); |
706 | filer = sf.file(); | 706 | filer = sf.file(); |
707 | break; | 707 | break; |
708 | }; | 708 | }; |
709 | } | 709 | } |
710 | else if(fi.baseName().left(1) == "") | 710 | else if(fi.baseName().left(1) == "") |
711 | { | 711 | { |
712 | qDebug("opening dotfile"); | 712 | qDebug("opening dotfile"); |
713 | currentFileName=f; | 713 | currentFileName=f; |
714 | openDotFile(currentFileName); | 714 | openDotFile(currentFileName); |
715 | return; | 715 | return; |
716 | } | 716 | } |
717 | else | 717 | /* |
718 | * The problem is a file where Config(f).isValid() and it does not | ||
719 | * end with .desktop will be treated as desktop file | ||
720 | */ | ||
721 | else if (f.find(".desktop",0,true) != -1 ) | ||
718 | { | 722 | { |
719 | DocLnk sf(f); | 723 | DocLnk sf(f); |
720 | filer = sf.file(); | 724 | filer = sf.file(); |
721 | if(filer.right(1) == "/") | 725 | if(filer.right(1) == "/") |
722 | filer = f; | 726 | filer = f; |
727 | |||
723 | } | 728 | } |
729 | else | ||
730 | filer = f; | ||
724 | 731 | ||
725 | DocLnk nf; | 732 | DocLnk nf; |
726 | nf.setType("text/plain"); | 733 | nf.setType("text/plain"); |
727 | nf.setFile(filer); | 734 | nf.setFile(filer); |
728 | currentFileName=filer; | 735 | currentFileName=filer; |
729 | 736 | ||
730 | nf.setName(fi.baseName()); | 737 | nf.setName(fi.baseName()); |
731 | openFile(nf); | 738 | openFile(nf); |
732 | 739 | ||
733 | qDebug("openFile string "+currentFileName); | 740 | qDebug("openFile string "+currentFileName); |
734 | 741 | ||
735 | showEditTools(); | 742 | showEditTools(); |
736 | // Show filename in caption | 743 | // Show filename in caption |
737 | QString name = filer; | 744 | QString name = filer; |
738 | int sep = name.findRev( '/' ); | 745 | int sep = name.findRev( '/' ); |
739 | if ( sep > 0 ) | 746 | if ( sep > 0 ) |
740 | name = name.mid( sep+1 ); | 747 | name = name.mid( sep+1 ); |
741 | updateCaption( name ); | 748 | updateCaption( name ); |
742 | } | 749 | } |
743 | 750 | ||
744 | void TextEdit::openFile( const DocLnk &f ) { | 751 | void TextEdit::openFile( const DocLnk &f ) { |
745 | // clear(); | 752 | // clear(); |
746 | // bFromDocView = true; | 753 | // bFromDocView = true; |
747 | FileManager fm; | 754 | FileManager fm; |
748 | QString txt; | 755 | QString txt; |
749 | currentFileName=f.file(); | 756 | currentFileName=f.file(); |
750 | qDebug("openFile doclnk " + currentFileName); | 757 | qDebug("openFile doclnk " + currentFileName); |
751 | if ( !fm.loadFile( f, txt ) ) { | 758 | if ( !fm.loadFile( f, txt ) ) { |
752 | // ####### could be a new file | 759 | // ####### could be a new file |
753 | qDebug( "Cannot open file" ); | 760 | qDebug( "Cannot open file" ); |
754 | } | 761 | } |
755 | // fileNew(); | 762 | // fileNew(); |
756 | if ( doc ) | 763 | if ( doc ) |
757 | delete doc; | 764 | delete doc; |
758 | doc = new DocLnk(f); | 765 | doc = new DocLnk(f); |
759 | editor->setText(txt); | 766 | editor->setText(txt); |
760 | editor->setEdited( false); | 767 | editor->setEdited( false); |
761 | edited1=false; | 768 | edited1=false; |
762 | edited=false; | 769 | edited=false; |
763 | 770 | ||
764 | doc->setName(currentFileName); | 771 | doc->setName(currentFileName); |
765 | updateCaption(); | 772 | updateCaption(); |
766 | setTimer(); | 773 | setTimer(); |
767 | } | 774 | } |
768 | 775 | ||
769 | void TextEdit::showEditTools() { | 776 | void TextEdit::showEditTools() { |
770 | menu->show(); | 777 | menu->show(); |
771 | editBar->show(); | 778 | editBar->show(); |
772 | if(!useSearchBar) | 779 | if(!useSearchBar) |
773 | searchBar->hide(); | 780 | searchBar->hide(); |
774 | else | 781 | else |
775 | searchBar->show(); | 782 | searchBar->show(); |
776 | setWState (WState_Reserved1 ); | 783 | setWState (WState_Reserved1 ); |
777 | } | 784 | } |
778 | 785 | ||
779 | /*! | 786 | /*! |
780 | unprompted save */ | 787 | unprompted save */ |
781 | bool TextEdit::save() { | 788 | bool TextEdit::save() { |
782 | qDebug("saveAsFile " + currentFileName); | 789 | qDebug("saveAsFile " + currentFileName); |
783 | if(currentFileName.isEmpty()) { | 790 | if(currentFileName.isEmpty()) { |
784 | saveAs(); | 791 | saveAs(); |
785 | return false; | 792 | return false; |
786 | } | 793 | } |
787 | 794 | ||
788 | QString file = doc->file(); | 795 | QString file = doc->file(); |
789 | qDebug("saver file "+file); | 796 | qDebug("saver file "+file); |
790 | QString name= doc->name(); | 797 | QString name= doc->name(); |
791 | qDebug("File named "+name); | 798 | qDebug("File named "+name); |
792 | QString rt = editor->text(); | 799 | QString rt = editor->text(); |
793 | if( !rt.isEmpty() ) { | 800 | if( !rt.isEmpty() ) { |
794 | if(name.isEmpty()) { | 801 | if(name.isEmpty()) { |
795 | saveAs(); | 802 | saveAs(); |
796 | } else { | 803 | } else { |
797 | currentFileName= name ; | 804 | currentFileName= name ; |
798 | qDebug("saveFile "+currentFileName); | 805 | qDebug("saveFile "+currentFileName); |
799 | 806 | ||
800 | struct stat buf; | 807 | struct stat buf; |
801 | mode_t mode; | 808 | mode_t mode; |
802 | stat(file.latin1(), &buf); | 809 | stat(file.latin1(), &buf); |
803 | mode = buf.st_mode; | 810 | mode = buf.st_mode; |
804 | 811 | ||
805 | if(!fileIs) { | 812 | if(!fileIs) { |
806 | doc->setName( name); | 813 | doc->setName( name); |
807 | FileManager fm; | 814 | FileManager fm; |
808 | if ( !fm.saveFile( *doc, rt ) ) { | 815 | if ( !fm.saveFile( *doc, rt ) ) { |
809 | return false; | 816 | return false; |
810 | } | 817 | } |
811 | } else { | 818 | } else { |
812 | qDebug("regular save file"); | 819 | qDebug("regular save file"); |
813 | QFile f(file); | 820 | QFile f(file); |
814 | if( f.open(IO_WriteOnly)) { | 821 | if( f.open(IO_WriteOnly)) { |
815 | QCString crt = rt.utf8(); | 822 | QCString crt = rt.utf8(); |
816 | f.writeBlock(crt,crt.length()); | 823 | f.writeBlock(crt,crt.length()); |
817 | } else { | 824 | } else { |
818 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 825 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
819 | return false; | 826 | return false; |
820 | } | 827 | } |
821 | 828 | ||
822 | } | 829 | } |
823 | editor->setEdited( false); | 830 | editor->setEdited( false); |
824 | edited1=false; | 831 | edited1=false; |
825 | edited=false; | 832 | edited=false; |
826 | if(caption().left(1)=="*") | 833 | if(caption().left(1)=="*") |
827 | setCaption(caption().right(caption().length()-1)); | 834 | setCaption(caption().right(caption().length()-1)); |
828 | 835 | ||
829 | 836 | ||
830 | chmod( file.latin1(), mode); | 837 | chmod( file.latin1(), mode); |
831 | } | 838 | } |
832 | return true; | 839 | return true; |
833 | } | 840 | } |
834 | return false; | 841 | return false; |
835 | } | 842 | } |
836 | 843 | ||
837 | /*! | 844 | /*! |
838 | prompted save */ | 845 | prompted save */ |
839 | bool TextEdit::saveAs() { | 846 | bool TextEdit::saveAs() { |
840 | 847 | ||
841 | if(caption() == tr("Text Editor")) | 848 | if(caption() == tr("Text Editor")) |
842 | return false; | 849 | return false; |
843 | qDebug("saveAsFile " + currentFileName); | 850 | qDebug("saveAsFile " + currentFileName); |
844 | // case of nothing to save... | 851 | // case of nothing to save... |
845 | // if ( !doc && !currentFileName.isEmpty()) { | 852 | // if ( !doc && !currentFileName.isEmpty()) { |
846 | // //|| !bFromDocView) | 853 | // //|| !bFromDocView) |
847 | // qDebug("no doc"); | 854 | // qDebug("no doc"); |
848 | // return true; | 855 | // return true; |
849 | // } | 856 | // } |
850 | // if ( !editor->edited() ) { | 857 | // if ( !editor->edited() ) { |
851 | // delete doc; | 858 | // delete doc; |