author | llornkcor <llornkcor> | 2002-04-14 21:40:33 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-14 21:40:33 (UTC) |
commit | f519bc8b0dd5e1f183b8eb2b0c7f59787afe130c (patch) (unidiff) | |
tree | 137200abe04002cbcd27176352ab2f5ec0d4f636 | |
parent | 9c779ca27c9e44c2bae69892d060e628e5ea5bd3 (diff) | |
download | opie-f519bc8b0dd5e1f183b8eb2b0c7f59787afe130c.zip opie-f519bc8b0dd5e1f183b8eb2b0c7f59787afe130c.tar.gz opie-f519bc8b0dd5e1f183b8eb2b0c7f59787afe130c.tar.bz2 |
fixed trying to open .desktop files- give user a choice: .desktop or file linked too
-rw-r--r-- | core/apps/textedit/textedit.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index cc3ccbc..834bd8c 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -597,110 +597,124 @@ void TextEdit::editPaste() | |||
597 | void TextEdit::editFind() | 597 | void TextEdit::editFind() |
598 | { | 598 | { |
599 | searchBar->show(); | 599 | searchBar->show(); |
600 | searchVisible = TRUE; | 600 | searchVisible = TRUE; |
601 | searchEdit->setFocus(); | 601 | searchEdit->setFocus(); |
602 | Config cfg("TextEdit"); | 602 | Config cfg("TextEdit"); |
603 | cfg.setGroup("View"); | 603 | cfg.setGroup("View"); |
604 | cfg.writeEntry("SearchBar","Opened"); | 604 | cfg.writeEntry("SearchBar","Opened"); |
605 | 605 | ||
606 | } | 606 | } |
607 | 607 | ||
608 | void TextEdit::findNext() | 608 | void TextEdit::findNext() |
609 | { | 609 | { |
610 | editor->find( searchEdit->text(), FALSE, FALSE ); | 610 | editor->find( searchEdit->text(), FALSE, FALSE ); |
611 | 611 | ||
612 | } | 612 | } |
613 | 613 | ||
614 | void TextEdit::findClose() | 614 | void TextEdit::findClose() |
615 | { | 615 | { |
616 | searchVisible = FALSE; | 616 | searchVisible = FALSE; |
617 | searchBar->hide(); | 617 | searchBar->hide(); |
618 | Config cfg("TextEdit"); | 618 | Config cfg("TextEdit"); |
619 | cfg.setGroup("View"); | 619 | cfg.setGroup("View"); |
620 | cfg.writeEntry("SearchBar","Closed"); | 620 | cfg.writeEntry("SearchBar","Closed"); |
621 | cfg.write(); | 621 | cfg.write(); |
622 | } | 622 | } |
623 | 623 | ||
624 | void TextEdit::search() | 624 | void TextEdit::search() |
625 | { | 625 | { |
626 | editor->find( searchEdit->text(), FALSE, FALSE ); | 626 | editor->find( searchEdit->text(), FALSE, FALSE ); |
627 | } | 627 | } |
628 | 628 | ||
629 | void TextEdit::newFile( const DocLnk &f ) | 629 | void TextEdit::newFile( const DocLnk &f ) |
630 | { | 630 | { |
631 | DocLnk nf = f; | 631 | DocLnk nf = f; |
632 | nf.setType("text/plain"); | 632 | nf.setType("text/plain"); |
633 | clear(); | 633 | clear(); |
634 | setWState (WState_Reserved1 ); | 634 | setWState (WState_Reserved1 ); |
635 | editor->setFocus(); | 635 | editor->setFocus(); |
636 | doc = new DocLnk(nf); | 636 | doc = new DocLnk(nf); |
637 | currentFileName = "Unnamed"; | 637 | currentFileName = "Unnamed"; |
638 | qDebug("newFile "+currentFileName); | 638 | qDebug("newFile "+currentFileName); |
639 | updateCaption( currentFileName); | 639 | updateCaption( currentFileName); |
640 | // editor->setEdited( FALSE); | 640 | // editor->setEdited( FALSE); |
641 | } | 641 | } |
642 | 642 | ||
643 | void TextEdit::openFile( const QString &f ) | 643 | void TextEdit::openFile( const QString &f ) |
644 | { | 644 | { |
645 | 645 | qDebug("filename is "+ f); | |
646 | QString filer; | ||
646 | // bFromDocView = TRUE; | 647 | // bFromDocView = TRUE; |
648 | if(f.find(".desktop",0,TRUE)) { | ||
649 | switch ( QMessageBox::warning(this,tr("Text Editor"), | ||
650 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), | ||
651 | tr(".desktop File"),tr("Link"),0,0,1) ) { | ||
652 | case 0: | ||
653 | filer = f; | ||
654 | break; | ||
655 | case 1: | ||
656 | DocLnk sf(f); | ||
657 | filer = sf.file(); | ||
658 | break; | ||
659 | } | ||
660 | } | ||
647 | DocLnk nf; | 661 | DocLnk nf; |
648 | nf.setType("text/plain"); | 662 | nf.setType("text/plain"); |
649 | nf.setFile(f); | 663 | nf.setFile(filer); |
650 | currentFileName=f; | 664 | currentFileName=filer; |
651 | QFileInfo fi( currentFileName); | 665 | QFileInfo fi( currentFileName); |
652 | nf.setName(fi.baseName()); | 666 | nf.setName(fi.baseName()); |
653 | qDebug("openFile string"+currentFileName); | 667 | qDebug("openFile string "+currentFileName); |
654 | 668 | ||
655 | openFile(nf); | 669 | openFile(nf); |
656 | showEditTools(); | 670 | showEditTools(); |
657 | // Show filename in caption | 671 | // Show filename in caption |
658 | QString name = f; | 672 | QString name = filer; |
659 | int sep = name.findRev( '/' ); | 673 | int sep = name.findRev( '/' ); |
660 | if ( sep > 0 ) | 674 | if ( sep > 0 ) |
661 | name = name.mid( sep+1 ); | 675 | name = name.mid( sep+1 ); |
662 | updateCaption( name ); | 676 | updateCaption( name ); |
663 | } | 677 | } |
664 | 678 | ||
665 | void TextEdit::openFile( const DocLnk &f ) | 679 | void TextEdit::openFile( const DocLnk &f ) |
666 | { | 680 | { |
667 | // clear(); | 681 | // clear(); |
668 | // bFromDocView = TRUE; | 682 | // bFromDocView = TRUE; |
669 | FileManager fm; | 683 | FileManager fm; |
670 | QString txt; | 684 | QString txt; |
671 | currentFileName=f.name(); | 685 | currentFileName=f.name(); |
672 | qDebug("openFile doclnk " + currentFileName); | 686 | qDebug("openFile doclnk " + currentFileName); |
673 | if ( !fm.loadFile( f, txt ) ) { | 687 | if ( !fm.loadFile( f, txt ) ) { |
674 | // ####### could be a new file | 688 | // ####### could be a new file |
675 | qDebug( "Cannot open file" ); | 689 | qDebug( "Cannot open file" ); |
676 | } | 690 | } |
677 | // fileNew(); | 691 | // fileNew(); |
678 | if ( doc ) | 692 | if ( doc ) |
679 | delete doc; | 693 | delete doc; |
680 | doc = new DocLnk(f); | 694 | doc = new DocLnk(f); |
681 | editor->setText(txt); | 695 | editor->setText(txt); |
682 | editor->setEdited( FALSE); | 696 | editor->setEdited( FALSE); |
683 | edited1=FALSE; | 697 | edited1=FALSE; |
684 | edited=FALSE; | 698 | edited=FALSE; |
685 | 699 | ||
686 | doc->setName(currentFileName); | 700 | doc->setName(currentFileName); |
687 | updateCaption(); | 701 | updateCaption(); |
688 | } | 702 | } |
689 | 703 | ||
690 | void TextEdit::showEditTools() | 704 | void TextEdit::showEditTools() |
691 | { | 705 | { |
692 | // if ( !doc ) | 706 | // if ( !doc ) |
693 | // close(); | 707 | // close(); |
694 | // clear(); | 708 | // clear(); |
695 | menu->show(); | 709 | menu->show(); |
696 | editBar->show(); | 710 | editBar->show(); |
697 | if ( searchVisible ) | 711 | if ( searchVisible ) |
698 | searchBar->show(); | 712 | searchBar->show(); |
699 | // updateCaption(); | 713 | // updateCaption(); |
700 | setWState (WState_Reserved1 ); | 714 | setWState (WState_Reserved1 ); |
701 | } | 715 | } |
702 | 716 | ||
703 | /*! | 717 | /*! |
704 | unprompted save */ | 718 | unprompted save */ |
705 | bool TextEdit::save() | 719 | bool TextEdit::save() |
706 | { | 720 | { |
@@ -812,102 +826,97 @@ bool TextEdit::saveAs() | |||
812 | filePermissions *filePerm; | 826 | filePermissions *filePerm; |
813 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); | 827 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); |
814 | filePerm->exec(); | 828 | filePerm->exec(); |
815 | 829 | ||
816 | if( filePerm) | 830 | if( filePerm) |
817 | delete filePerm; | 831 | delete filePerm; |
818 | } | 832 | } |
819 | } | 833 | } |
820 | } | 834 | } |
821 | editor->setEdited(TRUE); | 835 | editor->setEdited(TRUE); |
822 | edited1=FALSE; | 836 | edited1=FALSE; |
823 | edited=TRUE; | 837 | edited=TRUE; |
824 | if(caption().left(1)=="*") | 838 | if(caption().left(1)=="*") |
825 | setCaption(caption().right(caption().length()-1)); | 839 | setCaption(caption().right(caption().length()-1)); |
826 | 840 | ||
827 | if(fileSaveDlg) | 841 | if(fileSaveDlg) |
828 | delete fileSaveDlg; | 842 | delete fileSaveDlg; |
829 | return true; | 843 | return true; |
830 | } //end saveAs | 844 | } //end saveAs |
831 | 845 | ||
832 | void TextEdit::clear() | 846 | void TextEdit::clear() |
833 | { | 847 | { |
834 | delete doc; | 848 | delete doc; |
835 | doc = 0; | 849 | doc = 0; |
836 | editor->clear(); | 850 | editor->clear(); |
837 | } | 851 | } |
838 | 852 | ||
839 | void TextEdit::updateCaption( const QString &name ) | 853 | void TextEdit::updateCaption( const QString &name ) |
840 | { | 854 | { |
841 | if ( !doc ) | 855 | if ( !doc ) |
842 | setCaption( tr("Text Editor") ); | 856 | setCaption( tr("Text Editor") ); |
843 | else { | 857 | else { |
844 | QString s = name; | 858 | QString s = name; |
845 | if ( s.isNull() ) | 859 | if ( s.isNull() ) |
846 | s = doc->name(); | 860 | s = doc->name(); |
847 | if ( s.isEmpty() ) { | 861 | if ( s.isEmpty() ) { |
848 | s = tr( "Unnamed" ); | 862 | s = tr( "Unnamed" ); |
849 | currentFileName=s; | 863 | currentFileName=s; |
850 | } | 864 | } |
851 | if(s.left(1) == "/") | 865 | if(s.left(1) == "/") |
852 | s = s.right(s.length()-1); | 866 | s = s.right(s.length()-1); |
853 | setCaption( s + " - " + tr("Text Editor") ); | 867 | setCaption( s + " - " + tr("Text Editor") ); |
854 | } | 868 | } |
855 | } | 869 | } |
856 | 870 | ||
857 | void TextEdit::setDocument(const QString& fileref) | 871 | void TextEdit::setDocument(const QString& fileref) |
858 | { | 872 | { |
859 | bFromDocView = TRUE; | 873 | bFromDocView = TRUE; |
860 | if(fileref.find(".desktop",0,TRUE) == -1) { | 874 | openFile(fileref); |
861 | openFile(fileref); | ||
862 | } else { | ||
863 | qDebug("is desktop file"); | ||
864 | openFile(DocLnk(fileref)); | ||
865 | } | ||
866 | editor->setEdited(TRUE); | 875 | editor->setEdited(TRUE); |
867 | edited1=FALSE; | 876 | edited1=FALSE; |
868 | edited=TRUE; | 877 | edited=TRUE; |
869 | doSearchBar(); | 878 | doSearchBar(); |
870 | } | 879 | } |
871 | 880 | ||
872 | void TextEdit::closeEvent( QCloseEvent *e ) | 881 | void TextEdit::closeEvent( QCloseEvent *e ) |
873 | { | 882 | { |
874 | bFromDocView = FALSE; | 883 | bFromDocView = FALSE; |
875 | e->accept(); | 884 | e->accept(); |
876 | } | 885 | } |
877 | 886 | ||
878 | void TextEdit::accept() | 887 | void TextEdit::accept() |
879 | { | 888 | { |
880 | //if(caption() !="Unnamed") | 889 | //if(caption() !="Unnamed") |
881 | if(edited1) | 890 | if(edited1) |
882 | saveAs(); | 891 | saveAs(); |
883 | exit(0); | 892 | exit(0); |
884 | 893 | ||
885 | } | 894 | } |
886 | 895 | ||
887 | void TextEdit::changeFont() { | 896 | void TextEdit::changeFont() { |
888 | FontDatabase fdb; | 897 | FontDatabase fdb; |
889 | QFont defaultFont=editor->font(); | 898 | QFont defaultFont=editor->font(); |
890 | QFontInfo fontInfo(defaultFont); | 899 | QFontInfo fontInfo(defaultFont); |
891 | Config cfg("TextEdit"); | 900 | Config cfg("TextEdit"); |
892 | cfg.setGroup("Font"); | 901 | cfg.setGroup("Font"); |
893 | QString family = cfg.readEntry("Family", fontInfo.family()); | 902 | QString family = cfg.readEntry("Family", fontInfo.family()); |
894 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 903 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
895 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 904 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
896 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 905 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
897 | 906 | ||
898 | defaultFont = fdb.font(family,style,i_size,charSet); | 907 | defaultFont = fdb.font(family,style,i_size,charSet); |
899 | 908 | ||
900 | FontDialog *fontDlg; | 909 | FontDialog *fontDlg; |
901 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); | 910 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); |
902 | 911 | ||
903 | fontDlg->exec(); | 912 | fontDlg->exec(); |
904 | 913 | ||
905 | QFont myFont=fontDlg->selectedFont; | 914 | QFont myFont=fontDlg->selectedFont; |
906 | editor->setFont( myFont); | 915 | editor->setFont( myFont); |
907 | delete fontDlg; | 916 | delete fontDlg; |
908 | 917 | ||
909 | } | 918 | } |
910 | 919 | ||
911 | void TextEdit::editDelete() | 920 | void TextEdit::editDelete() |
912 | { | 921 | { |
913 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) { | 922 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) { |