summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp5
1 files changed, 1 insertions, 4 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 21bf4b3..6f96574 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -509,388 +509,385 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up) {
509 if ( fontsize[i] > sz ) { 509 if ( fontsize[i] > sz ) {
510 s = fontsize[i]; 510 s = fontsize[i];
511 break; 511 break;
512 } 512 }
513 } 513 }
514 } 514 }
515 515
516 QFont f = editor->font(); 516 QFont f = editor->font();
517 f.setPointSize(s); 517 f.setPointSize(s);
518 editor->setFont(f); 518 editor->setFont(f);
519 519
520 zin->setEnabled(s != fontsize[nfontsizes-1]); 520 zin->setEnabled(s != fontsize[nfontsizes-1]);
521 zout->setEnabled(s != fontsize[0]); 521 zout->setEnabled(s != fontsize[0]);
522} 522}
523 523
524void TextEdit::setBold(bool y) { 524void TextEdit::setBold(bool y) {
525 QFont f = editor->font(); 525 QFont f = editor->font();
526 f.setBold(y); 526 f.setBold(y);
527 editor->setFont(f); 527 editor->setFont(f);
528} 528}
529 529
530void TextEdit::setItalic(bool y) { 530void TextEdit::setItalic(bool y) {
531 QFont f = editor->font(); 531 QFont f = editor->font();
532 f.setItalic(y); 532 f.setItalic(y);
533 editor->setFont(f); 533 editor->setFont(f);
534} 534}
535 535
536void TextEdit::setWordWrap(bool y) { 536void TextEdit::setWordWrap(bool y) {
537 bool state = editor->edited(); 537 bool state = editor->edited();
538 QString captionStr = caption(); 538 QString captionStr = caption();
539 bool b1 = edited1; 539 bool b1 = edited1;
540 bool b2 = edited; 540 bool b2 = edited;
541 541
542 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 542 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
543 editor->setEdited( state ); 543 editor->setEdited( state );
544 edited1=b1; 544 edited1=b1;
545 edited=b2; 545 edited=b2;
546 setCaption(captionStr); 546 setCaption(captionStr);
547} 547}
548 548
549void TextEdit::setSearchBar(bool b) { 549void TextEdit::setSearchBar(bool b) {
550 useSearchBar=b; 550 useSearchBar=b;
551 Config cfg("TextEdit"); 551 Config cfg("TextEdit");
552 cfg.setGroup("View"); 552 cfg.setGroup("View");
553 cfg.writeEntry ( "SearchBar", b ); 553 cfg.writeEntry ( "SearchBar", b );
554 searchBarAction->setOn(b); 554 searchBarAction->setOn(b);
555 if(b) 555 if(b)
556 searchBar->show(); 556 searchBar->show();
557 else 557 else
558 searchBar->hide(); 558 searchBar->hide();
559 editor->setFocus(); 559 editor->setFocus();
560} 560}
561 561
562void TextEdit::fileNew() { 562void TextEdit::fileNew() {
563// if( !bFromDocView ) { 563// if( !bFromDocView ) {
564// saveAs(); 564// saveAs();
565// } 565// }
566 newFile(DocLnk()); 566 newFile(DocLnk());
567} 567}
568 568
569void TextEdit::fileOpen() { 569void TextEdit::fileOpen() {
570 Config cfg("TextEdit"); 570 Config cfg("TextEdit");
571 cfg. setGroup ( "View" ); 571 cfg. setGroup ( "View" );
572 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir()); 572 QString dir = cfg.readEntry("LastOpenDirectory", QPEApplication::documentDir());
573 QMap<QString, QStringList> map; 573 QMap<QString, QStringList> map;
574 map.insert(tr("All"), QStringList() ); 574 map.insert(tr("All"), QStringList() );
575 QStringList text; 575 QStringList text;
576 text << "text/*"; 576 text << "text/*";
577 map.insert(tr("Text"), text ); 577 map.insert(tr("Text"), text );
578 text << "*"; 578 text << "*";
579 map.insert(tr("All"), text ); 579 map.insert(tr("All"), text );
580 QString str = OFileDialog::getOpenFileName( 2, 580 QString str = OFileDialog::getOpenFileName( 2,
581 dir , 581 dir ,
582 QString::null, map); 582 QString::null, map);
583 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) 583 if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() )
584 { 584 {
585 cfg.writeEntry("LastOpenDirectory", QFileInfo(str).dirPath(false)); 585 cfg.writeEntry("LastOpenDirectory", QFileInfo(str).dirPath(false));
586 openFile( str ); 586 openFile( str );
587 } 587 }
588 else 588 else
589 updateCaption(); 589 updateCaption();
590} 590}
591 591
592void TextEdit::doSearchBar() { 592void TextEdit::doSearchBar() {
593 if(!useSearchBar) 593 if(!useSearchBar)
594 searchBar->hide(); 594 searchBar->hide();
595 else 595 else
596 searchBar->show(); 596 searchBar->show();
597} 597}
598 598
599#if 0 599#if 0
600void TextEdit::slotFind() { 600void TextEdit::slotFind() {
601 FindDialog frmFind( tr("Text Editor"), this ); 601 FindDialog frmFind( tr("Text Editor"), this );
602 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 602 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
603 editor, SLOT(slotDoFind( const QString&,bool,bool))); 603 editor, SLOT(slotDoFind( const QString&,bool,bool)));
604 604
605 //case sensitive, backwards, [category] 605 //case sensitive, backwards, [category]
606 606
607 connect( editor, SIGNAL(notFound()), 607 connect( editor, SIGNAL(notFound()),
608 &frmFind, SLOT(slotNotFound()) ); 608 &frmFind, SLOT(slotNotFound()) );
609 connect( editor, SIGNAL(searchWrapped()), 609 connect( editor, SIGNAL(searchWrapped()),
610 &frmFind, SLOT(slotWrapAround()) ); 610 &frmFind, SLOT(slotWrapAround()) );
611 611
612 frmFind.exec(); 612 frmFind.exec();
613 613
614 614
615} 615}
616#endif 616#endif
617 617
618void TextEdit::fileRevert() { 618void TextEdit::fileRevert() {
619 clear(); 619 clear();
620 fileOpen(); 620 fileOpen();
621} 621}
622 622
623void TextEdit::editCut() { 623void TextEdit::editCut() {
624#ifndef QT_NO_CLIPBOARD 624#ifndef QT_NO_CLIPBOARD
625 editor->cut(); 625 editor->cut();
626#endif 626#endif
627} 627}
628 628
629void TextEdit::editCopy() { 629void TextEdit::editCopy() {
630#ifndef QT_NO_CLIPBOARD 630#ifndef QT_NO_CLIPBOARD
631 editor->copy(); 631 editor->copy();
632#endif 632#endif
633} 633}
634 634
635void TextEdit::editPaste() { 635void TextEdit::editPaste() {
636#ifndef QT_NO_CLIPBOARD 636#ifndef QT_NO_CLIPBOARD
637 editor->paste(); 637 editor->paste();
638#endif 638#endif
639} 639}
640 640
641void TextEdit::editFind() { 641void TextEdit::editFind() {
642 searchBar->show(); 642 searchBar->show();
643 searchEdit->setFocus(); 643 searchEdit->setFocus();
644} 644}
645 645
646void TextEdit::findNext() { 646void TextEdit::findNext() {
647 editor->find( searchEdit->text(), false, false ); 647 editor->find( searchEdit->text(), false, false );
648 648
649} 649}
650 650
651void TextEdit::findClose() { 651void TextEdit::findClose() {
652 searchBar->hide(); 652 searchBar->hide();
653} 653}
654 654
655void TextEdit::search() { 655void TextEdit::search() {
656 editor->find( searchEdit->text(), false, false ); 656 editor->find( searchEdit->text(), false, false );
657} 657}
658 658
659void TextEdit::newFile( const DocLnk &f ) { 659void TextEdit::newFile( const DocLnk &f ) {
660 DocLnk nf = f; 660 DocLnk nf = f;
661 nf.setType("text/plain"); 661 nf.setType("text/plain");
662 clear(); 662 clear();
663 setWState (WState_Reserved1 ); 663 setWState (WState_Reserved1 );
664 editor->setFocus(); 664 editor->setFocus();
665 doc = new DocLnk(nf); 665 doc = new DocLnk(nf);
666 currentFileName = "Unnamed"; 666 currentFileName = "Unnamed";
667 qDebug("newFile "+currentFileName); 667 qDebug("newFile "+currentFileName);
668 updateCaption( currentFileName); 668 updateCaption( currentFileName);
669// editor->setEdited( false); 669// editor->setEdited( false);
670} 670}
671 671
672void TextEdit::openDotFile( const QString &f ) { 672void TextEdit::openDotFile( const QString &f ) {
673 if(!currentFileName.isEmpty()) { 673 if(!currentFileName.isEmpty()) {
674 currentFileName=f; 674 currentFileName=f;
675 675
676 qDebug("openFile dotfile " + currentFileName); 676 qDebug("openFile dotfile " + currentFileName);
677 QString txt; 677 QString txt;
678 QFile file(f); 678 QFile file(f);
679 file.open(IO_ReadWrite); 679 file.open(IO_ReadWrite);
680 QTextStream t(&file); 680 QTextStream t(&file);
681 while ( !t.atEnd()) { 681 while ( !t.atEnd()) {
682 txt+=t.readLine()+"\n"; 682 txt+=t.readLine()+"\n";
683 } 683 }
684 editor->setText(txt); 684 editor->setText(txt);
685 editor->setEdited( false); 685 editor->setEdited( false);
686 edited1=false; 686 edited1=false;
687 edited=false; 687 edited=false;
688 688
689 689
690 } 690 }
691 updateCaption( currentFileName); 691 updateCaption( currentFileName);
692} 692}
693 693
694void TextEdit::openFile( const QString &f ) { 694void TextEdit::openFile( const QString &f ) {
695 qDebug("filename is "+ f); 695 qDebug("filename is "+ f);
696 QString filer; 696 QString filer;
697 QFileInfo fi( f); 697 QFileInfo fi( f);
698// bFromDocView = true; 698// bFromDocView = true;
699 if(f.find(".desktop",0,true) != -1 && !openDesktop ) 699 if(f.find(".desktop",0,true) != -1 && !openDesktop )
700 { 700 {
701 switch ( QMessageBox::warning(this,tr("Text Editor"), 701 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) )
702 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
703file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
704 tr(".desktop File"),tr("Linked Document"),0,1,1) )
705 { 702 {
706 case 0: //desktop 703 case 0: //desktop
707 filer = f; 704 filer = f;
708 break; 705 break;
709 case 1: //linked 706 case 1: //linked
710 DocLnk sf(f); 707 DocLnk sf(f);
711 filer = sf.file(); 708 filer = sf.file();
712 break; 709 break;
713 }; 710 };
714 } 711 }
715 else if(fi.baseName().left(1) == "") 712 else if(fi.baseName().left(1) == "")
716 { 713 {
717 qDebug("opening dotfile"); 714 qDebug("opening dotfile");
718 currentFileName=f; 715 currentFileName=f;
719 openDotFile(currentFileName); 716 openDotFile(currentFileName);
720 return; 717 return;
721 } 718 }
722 else 719 else
723 { 720 {
724 DocLnk sf(f); 721 DocLnk sf(f);
725 filer = sf.file(); 722 filer = sf.file();
726 if(filer.right(1) == "/") 723 if(filer.right(1) == "/")
727 filer = f; 724 filer = f;
728 } 725 }
729 726
730 DocLnk nf; 727 DocLnk nf;
731 nf.setType("text/plain"); 728 nf.setType("text/plain");
732 nf.setFile(filer); 729 nf.setFile(filer);
733 currentFileName=filer; 730 currentFileName=filer;
734 731
735 nf.setName(fi.baseName()); 732 nf.setName(fi.baseName());
736 openFile(nf); 733 openFile(nf);
737 734
738 qDebug("openFile string "+currentFileName); 735 qDebug("openFile string "+currentFileName);
739 736
740 showEditTools(); 737 showEditTools();
741 // Show filename in caption 738 // Show filename in caption
742 QString name = filer; 739 QString name = filer;
743 int sep = name.findRev( '/' ); 740 int sep = name.findRev( '/' );
744 if ( sep > 0 ) 741 if ( sep > 0 )
745 name = name.mid( sep+1 ); 742 name = name.mid( sep+1 );
746 updateCaption( name ); 743 updateCaption( name );
747} 744}
748 745
749void TextEdit::openFile( const DocLnk &f ) { 746void TextEdit::openFile( const DocLnk &f ) {
750// clear(); 747// clear();
751// bFromDocView = true; 748// bFromDocView = true;
752 FileManager fm; 749 FileManager fm;
753 QString txt; 750 QString txt;
754 currentFileName=f.file(); 751 currentFileName=f.file();
755 qDebug("openFile doclnk " + currentFileName); 752 qDebug("openFile doclnk " + currentFileName);
756 if ( !fm.loadFile( f, txt ) ) { 753 if ( !fm.loadFile( f, txt ) ) {
757 // ####### could be a new file 754 // ####### could be a new file
758 qDebug( "Cannot open file" ); 755 qDebug( "Cannot open file" );
759 } 756 }
760// fileNew(); 757// fileNew();
761 if ( doc ) 758 if ( doc )
762 delete doc; 759 delete doc;
763 doc = new DocLnk(f); 760 doc = new DocLnk(f);
764 editor->setText(txt); 761 editor->setText(txt);
765 editor->setEdited( false); 762 editor->setEdited( false);
766 edited1=false; 763 edited1=false;
767 edited=false; 764 edited=false;
768 765
769 doc->setName(currentFileName); 766 doc->setName(currentFileName);
770 updateCaption(); 767 updateCaption();
771 setTimer(); 768 setTimer();
772} 769}
773 770
774void TextEdit::showEditTools() { 771void TextEdit::showEditTools() {
775 menu->show(); 772 menu->show();
776 editBar->show(); 773 editBar->show();
777 if(!useSearchBar) 774 if(!useSearchBar)
778 searchBar->hide(); 775 searchBar->hide();
779 else 776 else
780 searchBar->show(); 777 searchBar->show();
781 setWState (WState_Reserved1 ); 778 setWState (WState_Reserved1 );
782} 779}
783 780
784/*! 781/*!
785 unprompted save */ 782 unprompted save */
786bool TextEdit::save() { 783bool TextEdit::save() {
787 qDebug("saveAsFile " + currentFileName); 784 qDebug("saveAsFile " + currentFileName);
788 if(currentFileName.isEmpty()) { 785 if(currentFileName.isEmpty()) {
789 saveAs(); 786 saveAs();
790 return false; 787 return false;
791 } 788 }
792 789
793 QString file = doc->file(); 790 QString file = doc->file();
794 qDebug("saver file "+file); 791 qDebug("saver file "+file);
795 QString name= doc->name(); 792 QString name= doc->name();
796 qDebug("File named "+name); 793 qDebug("File named "+name);
797 QString rt = editor->text(); 794 QString rt = editor->text();
798 if( !rt.isEmpty() ) { 795 if( !rt.isEmpty() ) {
799 if(name.isEmpty()) { 796 if(name.isEmpty()) {
800 saveAs(); 797 saveAs();
801 } else { 798 } else {
802 currentFileName= name ; 799 currentFileName= name ;
803 qDebug("saveFile "+currentFileName); 800 qDebug("saveFile "+currentFileName);
804 801
805 struct stat buf; 802 struct stat buf;
806 mode_t mode; 803 mode_t mode;
807 stat(file.latin1(), &buf); 804 stat(file.latin1(), &buf);
808 mode = buf.st_mode; 805 mode = buf.st_mode;
809 806
810 if(!fileIs) { 807 if(!fileIs) {
811 doc->setName( name); 808 doc->setName( name);
812 FileManager fm; 809 FileManager fm;
813 if ( !fm.saveFile( *doc, rt ) ) { 810 if ( !fm.saveFile( *doc, rt ) ) {
814 return false; 811 return false;
815 } 812 }
816 } else { 813 } else {
817 qDebug("regular save file"); 814 qDebug("regular save file");
818 QFile f(file); 815 QFile f(file);
819 if( f.open(IO_WriteOnly)) { 816 if( f.open(IO_WriteOnly)) {
820 QCString crt = rt.utf8(); 817 QCString crt = rt.utf8();
821 f.writeBlock(crt,crt.length()); 818 f.writeBlock(crt,crt.length());
822 } else { 819 } else {
823 QMessageBox::message(tr("Text Edit"),tr("Write Failed")); 820 QMessageBox::message(tr("Text Edit"),tr("Write Failed"));
824 return false; 821 return false;
825 } 822 }
826 823
827 } 824 }
828 editor->setEdited( false); 825 editor->setEdited( false);
829 edited1=false; 826 edited1=false;
830 edited=false; 827 edited=false;
831 if(caption().left(1)=="*") 828 if(caption().left(1)=="*")
832 setCaption(caption().right(caption().length()-1)); 829 setCaption(caption().right(caption().length()-1));
833 830
834 831
835 chmod( file.latin1(), mode); 832 chmod( file.latin1(), mode);
836 } 833 }
837 return true; 834 return true;
838 } 835 }
839 return false; 836 return false;
840} 837}
841 838
842/*! 839/*!
843 prompted save */ 840 prompted save */
844bool TextEdit::saveAs() { 841bool TextEdit::saveAs() {
845 842
846 if(caption() == tr("Text Editor")) 843 if(caption() == tr("Text Editor"))
847 return false; 844 return false;
848 qDebug("saveAsFile " + currentFileName); 845 qDebug("saveAsFile " + currentFileName);
849 // case of nothing to save... 846 // case of nothing to save...
850// if ( !doc && !currentFileName.isEmpty()) { 847// if ( !doc && !currentFileName.isEmpty()) {
851// //|| !bFromDocView) 848// //|| !bFromDocView)
852// qDebug("no doc"); 849// qDebug("no doc");
853// return true; 850// return true;
854// } 851// }
855// if ( !editor->edited() ) { 852// if ( !editor->edited() ) {
856// delete doc; 853// delete doc;
857// doc = 0; 854// doc = 0;
858// return true; 855// return true;
859// } 856// }
860 857
861 QString rt = editor->text(); 858 QString rt = editor->text();
862 qDebug(currentFileName); 859 qDebug(currentFileName);
863 860
864 if( currentFileName.isEmpty() 861 if( currentFileName.isEmpty()
865 || currentFileName == tr("Unnamed") 862 || currentFileName == tr("Unnamed")
866 || currentFileName == tr("Text Editor")) { 863 || currentFileName == tr("Text Editor")) {
867 qDebug("do silly TT filename thing"); 864 qDebug("do silly TT filename thing");
868// if ( doc && doc->name().isEmpty() ) { 865// if ( doc && doc->name().isEmpty() ) {
869 QString pt = rt.simplifyWhiteSpace(); 866 QString pt = rt.simplifyWhiteSpace();
870 int i = pt.find( ' ' ); 867 int i = pt.find( ' ' );
871 QString docname = pt; 868 QString docname = pt;
872 if ( i > 0 ) 869 if ( i > 0 )
873 docname = pt.left( i ); 870 docname = pt.left( i );
874 // remove "." at the beginning 871 // remove "." at the beginning
875 while( docname.startsWith( "." ) ) 872 while( docname.startsWith( "." ) )
876 docname = docname.mid( 1 ); 873 docname = docname.mid( 1 );
877 docname.replace( QRegExp("/"), "_" ); 874 docname.replace( QRegExp("/"), "_" );
878 // cut the length. filenames longer than that 875 // cut the length. filenames longer than that
879 //don't make sense and something goes wrong when they get too long. 876 //don't make sense and something goes wrong when they get too long.
880 if ( docname.length() > 40 ) 877 if ( docname.length() > 40 )
881 docname = docname.left(40); 878 docname = docname.left(40);
882 if ( docname.isEmpty() ) 879 if ( docname.isEmpty() )
883 docname = tr("Unnamed"); 880 docname = tr("Unnamed");
884 if(doc) doc->setName(docname); 881 if(doc) doc->setName(docname);
885 currentFileName=docname; 882 currentFileName=docname;
886// } 883// }
887// else 884// else
888// qDebug("hmmmmmm"); 885// qDebug("hmmmmmm");
889 } 886 }
890 887
891 888
892 QMap<QString, QStringList> map; 889 QMap<QString, QStringList> map;
893 map.insert(tr("All"), QStringList() ); 890 map.insert(tr("All"), QStringList() );
894 QStringList text; 891 QStringList text;
895 text << "text/*"; 892 text << "text/*";
896 map.insert(tr("Text"), text ); 893 map.insert(tr("Text"), text );