-rw-r--r-- | core/apps/textedit/textedit.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index bd0014a..f6a869a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -462,528 +462,529 @@ qDebug("cleanUp");// save(); | |||
462 | cfg.writeEntry( "FileView", viewSelection ); | 462 | cfg.writeEntry( "FileView", viewSelection ); |
463 | } | 463 | } |
464 | 464 | ||
465 | 465 | ||
466 | void TextEdit::accept() { | 466 | void TextEdit::accept() { |
467 | if( edited1) | 467 | if( edited1) |
468 | saveAs(); | 468 | saveAs(); |
469 | exit(0); | 469 | exit(0); |
470 | } | 470 | } |
471 | 471 | ||
472 | void TextEdit::zoomIn() { | 472 | void TextEdit::zoomIn() { |
473 | setFontSize(editor->font().pointSize()+1,FALSE); | 473 | setFontSize(editor->font().pointSize()+1,FALSE); |
474 | } | 474 | } |
475 | 475 | ||
476 | void TextEdit::zoomOut() { | 476 | void TextEdit::zoomOut() { |
477 | setFontSize(editor->font().pointSize()-1,TRUE); | 477 | setFontSize(editor->font().pointSize()-1,TRUE); |
478 | } | 478 | } |
479 | 479 | ||
480 | 480 | ||
481 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 481 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
482 | int s=10; | 482 | int s=10; |
483 | for (int i=0; i<nfontsizes; i++) { | 483 | for (int i=0; i<nfontsizes; i++) { |
484 | if ( fontsize[i] == sz ) { | 484 | if ( fontsize[i] == sz ) { |
485 | s = sz; | 485 | s = sz; |
486 | break; | 486 | break; |
487 | } else if ( round_down_not_up ) { | 487 | } else if ( round_down_not_up ) { |
488 | if ( fontsize[i] < sz ) | 488 | if ( fontsize[i] < sz ) |
489 | s = fontsize[i]; | 489 | s = fontsize[i]; |
490 | } else { | 490 | } else { |
491 | if ( fontsize[i] > sz ) { | 491 | if ( fontsize[i] > sz ) { |
492 | s = fontsize[i]; | 492 | s = fontsize[i]; |
493 | break; | 493 | break; |
494 | } | 494 | } |
495 | } | 495 | } |
496 | } | 496 | } |
497 | 497 | ||
498 | QFont f = editor->font(); | 498 | QFont f = editor->font(); |
499 | f.setPointSize(s); | 499 | f.setPointSize(s); |
500 | editor->setFont(f); | 500 | editor->setFont(f); |
501 | 501 | ||
502 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 502 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
503 | zout->setEnabled(s != fontsize[0]); | 503 | zout->setEnabled(s != fontsize[0]); |
504 | } | 504 | } |
505 | 505 | ||
506 | void TextEdit::setBold(bool y) { | 506 | void TextEdit::setBold(bool y) { |
507 | QFont f = editor->font(); | 507 | QFont f = editor->font(); |
508 | f.setBold(y); | 508 | f.setBold(y); |
509 | editor->setFont(f); | 509 | editor->setFont(f); |
510 | } | 510 | } |
511 | 511 | ||
512 | void TextEdit::setItalic(bool y) { | 512 | void TextEdit::setItalic(bool y) { |
513 | QFont f = editor->font(); | 513 | QFont f = editor->font(); |
514 | f.setItalic(y); | 514 | f.setItalic(y); |
515 | editor->setFont(f); | 515 | editor->setFont(f); |
516 | } | 516 | } |
517 | 517 | ||
518 | void TextEdit::setWordWrap(bool y) { | 518 | void TextEdit::setWordWrap(bool y) { |
519 | bool state = editor->edited(); | 519 | bool state = editor->edited(); |
520 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 520 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
521 | editor->setEdited( state ); | 521 | editor->setEdited( state ); |
522 | } | 522 | } |
523 | 523 | ||
524 | void TextEdit::fileNew() { | 524 | void TextEdit::fileNew() { |
525 | // if( !bFromDocView ) { | 525 | // if( !bFromDocView ) { |
526 | // saveAs(); | 526 | // saveAs(); |
527 | // } | 527 | // } |
528 | newFile(DocLnk()); | 528 | newFile(DocLnk()); |
529 | } | 529 | } |
530 | 530 | ||
531 | void TextEdit::fileOpen() { | 531 | void TextEdit::fileOpen() { |
532 | Config cfg("TextEdit"); | 532 | Config cfg("TextEdit"); |
533 | cfg.setGroup("View"); | 533 | cfg.setGroup("View"); |
534 | // bool b=FALSE; | 534 | // bool b=FALSE; |
535 | 535 | ||
536 | QMap<QString, QStringList> map; | 536 | QMap<QString, QStringList> map; |
537 | map.insert(tr("All"), QStringList() ); | 537 | map.insert(tr("All"), QStringList() ); |
538 | QStringList text; | 538 | QStringList text; |
539 | text << "text/*"; | 539 | text << "text/*"; |
540 | map.insert(tr("Text"), text ); | 540 | map.insert(tr("Text"), text ); |
541 | text << "*"; | 541 | text << "*"; |
542 | map.insert(tr("All"), text ); | 542 | map.insert(tr("All"), text ); |
543 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); | 543 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); |
544 | if(!str.isEmpty() ) | 544 | if(!str.isEmpty() ) |
545 | openFile( str ); | 545 | openFile( str ); |
546 | 546 | ||
547 | } | 547 | } |
548 | 548 | ||
549 | void TextEdit::doSearchBar() { | 549 | void TextEdit::doSearchBar() { |
550 | Config cfg("TextEdit"); | 550 | Config cfg("TextEdit"); |
551 | cfg.setGroup("View"); | 551 | cfg.setGroup("View"); |
552 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 552 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
553 | searchBar->hide(); | 553 | searchBar->hide(); |
554 | } | 554 | } |
555 | 555 | ||
556 | #if 0 | 556 | #if 0 |
557 | void TextEdit::slotFind() { | 557 | void TextEdit::slotFind() { |
558 | FindDialog frmFind( tr("Text Editor"), this ); | 558 | FindDialog frmFind( tr("Text Editor"), this ); |
559 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 559 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
560 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 560 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
561 | 561 | ||
562 | //case sensitive, backwards, [category] | 562 | //case sensitive, backwards, [category] |
563 | 563 | ||
564 | connect( editor, SIGNAL(notFound()), | 564 | connect( editor, SIGNAL(notFound()), |
565 | &frmFind, SLOT(slotNotFound()) ); | 565 | &frmFind, SLOT(slotNotFound()) ); |
566 | connect( editor, SIGNAL(searchWrapped()), | 566 | connect( editor, SIGNAL(searchWrapped()), |
567 | &frmFind, SLOT(slotWrapAround()) ); | 567 | &frmFind, SLOT(slotWrapAround()) ); |
568 | 568 | ||
569 | frmFind.exec(); | 569 | frmFind.exec(); |
570 | 570 | ||
571 | 571 | ||
572 | } | 572 | } |
573 | #endif | 573 | #endif |
574 | 574 | ||
575 | void TextEdit::fileRevert() { | 575 | void TextEdit::fileRevert() { |
576 | clear(); | 576 | clear(); |
577 | fileOpen(); | 577 | fileOpen(); |
578 | } | 578 | } |
579 | 579 | ||
580 | void TextEdit::editCut() { | 580 | void TextEdit::editCut() { |
581 | #ifndef QT_NO_CLIPBOARD | 581 | #ifndef QT_NO_CLIPBOARD |
582 | editor->cut(); | 582 | editor->cut(); |
583 | #endif | 583 | #endif |
584 | } | 584 | } |
585 | 585 | ||
586 | void TextEdit::editCopy() { | 586 | void TextEdit::editCopy() { |
587 | #ifndef QT_NO_CLIPBOARD | 587 | #ifndef QT_NO_CLIPBOARD |
588 | editor->copy(); | 588 | editor->copy(); |
589 | #endif | 589 | #endif |
590 | } | 590 | } |
591 | 591 | ||
592 | void TextEdit::editPaste() { | 592 | void TextEdit::editPaste() { |
593 | #ifndef QT_NO_CLIPBOARD | 593 | #ifndef QT_NO_CLIPBOARD |
594 | editor->paste(); | 594 | editor->paste(); |
595 | #endif | 595 | #endif |
596 | } | 596 | } |
597 | 597 | ||
598 | void TextEdit::editFind() { | 598 | void TextEdit::editFind() { |
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 | editor->find( searchEdit->text(), FALSE, FALSE ); | 609 | editor->find( searchEdit->text(), FALSE, FALSE ); |
610 | 610 | ||
611 | } | 611 | } |
612 | 612 | ||
613 | void TextEdit::findClose() { | 613 | void TextEdit::findClose() { |
614 | searchVisible = FALSE; | 614 | searchVisible = FALSE; |
615 | searchBar->hide(); | 615 | searchBar->hide(); |
616 | Config cfg("TextEdit"); | 616 | Config cfg("TextEdit"); |
617 | cfg.setGroup("View"); | 617 | cfg.setGroup("View"); |
618 | cfg.writeEntry("SearchBar","Closed"); | 618 | cfg.writeEntry("SearchBar","Closed"); |
619 | cfg.write(); | 619 | cfg.write(); |
620 | } | 620 | } |
621 | 621 | ||
622 | void TextEdit::search() { | 622 | void TextEdit::search() { |
623 | editor->find( searchEdit->text(), FALSE, FALSE ); | 623 | editor->find( searchEdit->text(), FALSE, FALSE ); |
624 | } | 624 | } |
625 | 625 | ||
626 | void TextEdit::newFile( const DocLnk &f ) { | 626 | void TextEdit::newFile( const DocLnk &f ) { |
627 | DocLnk nf = f; | 627 | DocLnk nf = f; |
628 | nf.setType("text/plain"); | 628 | nf.setType("text/plain"); |
629 | clear(); | 629 | clear(); |
630 | setWState (WState_Reserved1 ); | 630 | setWState (WState_Reserved1 ); |
631 | editor->setFocus(); | 631 | editor->setFocus(); |
632 | doc = new DocLnk(nf); | 632 | doc = new DocLnk(nf); |
633 | currentFileName = "Unnamed"; | 633 | currentFileName = "Unnamed"; |
634 | qDebug("newFile "+currentFileName); | 634 | qDebug("newFile "+currentFileName); |
635 | updateCaption( currentFileName); | 635 | updateCaption( currentFileName); |
636 | // editor->setEdited( FALSE); | 636 | // editor->setEdited( FALSE); |
637 | } | 637 | } |
638 | 638 | ||
639 | void TextEdit::openFile( const QString &f ) { | 639 | void TextEdit::openFile( const QString &f ) { |
640 | qDebug("filename is "+ f); | 640 | qDebug("filename is "+ f); |
641 | QString filer; | 641 | QString filer; |
642 | // bFromDocView = TRUE; | 642 | // bFromDocView = TRUE; |
643 | if(f.find(".desktop",0,TRUE) != -1 && useAdvancedFeatures) { | 643 | if(f.find(".desktop",0,TRUE) != -1 && useAdvancedFeatures) { |
644 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 644 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
645 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 645 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
646 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 646 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
647 | case 0: | 647 | case 0: |
648 | filer = f; | 648 | filer = f; |
649 | break; | 649 | break; |
650 | case 1: | 650 | case 1: |
651 | DocLnk sf(f); | 651 | DocLnk sf(f); |
652 | filer = sf.file(); | 652 | filer = sf.file(); |
653 | break; | 653 | break; |
654 | } | 654 | } |
655 | } else { | 655 | } else { |
656 | DocLnk sf(f); | 656 | DocLnk sf(f); |
657 | filer = sf.file(); | 657 | filer = sf.file(); |
658 | // filer = f; | 658 | // filer = f; |
659 | // fileIs = TRUE; | 659 | // fileIs = TRUE; |
660 | } | 660 | } |
661 | 661 | ||
662 | DocLnk nf; | 662 | DocLnk nf; |
663 | nf.setType("text/plain"); | 663 | nf.setType("text/plain"); |
664 | nf.setFile(filer); | 664 | nf.setFile(filer); |
665 | currentFileName=filer; | 665 | currentFileName=filer; |
666 | QFileInfo fi( currentFileName); | 666 | QFileInfo fi( currentFileName); |
667 | nf.setName(fi.baseName()); | 667 | nf.setName(fi.baseName()); |
668 | qDebug("openFile string "+currentFileName); | 668 | qDebug("openFile string "+currentFileName); |
669 | 669 | ||
670 | openFile(nf); | 670 | openFile(nf); |
671 | showEditTools(); | 671 | showEditTools(); |
672 | // Show filename in caption | 672 | // Show filename in caption |
673 | QString name = filer; | 673 | QString name = filer; |
674 | int sep = name.findRev( '/' ); | 674 | int sep = name.findRev( '/' ); |
675 | if ( sep > 0 ) | 675 | if ( sep > 0 ) |
676 | name = name.mid( sep+1 ); | 676 | name = name.mid( sep+1 ); |
677 | updateCaption( name ); | 677 | updateCaption( name ); |
678 | } | 678 | } |
679 | 679 | ||
680 | void TextEdit::openFile( const DocLnk &f ) { | 680 | void TextEdit::openFile( const DocLnk &f ) { |
681 | // clear(); | 681 | // clear(); |
682 | // bFromDocView = TRUE; | 682 | // bFromDocView = TRUE; |
683 | FileManager fm; | 683 | FileManager fm; |
684 | QString txt; | 684 | QString txt; |
685 | currentFileName=f.file(); | 685 | currentFileName=f.file(); |
686 | qDebug("openFile doclnk " + currentFileName); | 686 | qDebug("openFile doclnk " + currentFileName); |
687 | if ( !fm.loadFile( f, txt ) ) { | 687 | if ( !fm.loadFile( f, txt ) ) { |
688 | // ####### could be a new file | 688 | // ####### could be a new file |
689 | qDebug( "Cannot open file" ); | 689 | qDebug( "Cannot open file" ); |
690 | } | 690 | } |
691 | // fileNew(); | 691 | // fileNew(); |
692 | if ( doc ) | 692 | if ( doc ) |
693 | delete doc; | 693 | delete doc; |
694 | doc = new DocLnk(f); | 694 | doc = new DocLnk(f); |
695 | editor->setText(txt); | 695 | editor->setText(txt); |
696 | editor->setEdited( FALSE); | 696 | editor->setEdited( FALSE); |
697 | edited1=FALSE; | 697 | edited1=FALSE; |
698 | edited=FALSE; | 698 | edited=FALSE; |
699 | 699 | ||
700 | doc->setName(currentFileName); | 700 | doc->setName(currentFileName); |
701 | updateCaption(); | 701 | updateCaption(); |
702 | } | 702 | } |
703 | 703 | ||
704 | void TextEdit::showEditTools() { | 704 | void TextEdit::showEditTools() { |
705 | // if ( !doc ) | 705 | // if ( !doc ) |
706 | // close(); | 706 | // close(); |
707 | // clear(); | 707 | // clear(); |
708 | menu->show(); | 708 | menu->show(); |
709 | editBar->show(); | 709 | editBar->show(); |
710 | if ( searchVisible ) | 710 | if ( searchVisible ) |
711 | searchBar->show(); | 711 | searchBar->show(); |
712 | // updateCaption(); | 712 | // updateCaption(); |
713 | setWState (WState_Reserved1 ); | 713 | setWState (WState_Reserved1 ); |
714 | } | 714 | } |
715 | 715 | ||
716 | /*! | 716 | /*! |
717 | unprompted save */ | 717 | unprompted save */ |
718 | bool TextEdit::save() { | 718 | bool TextEdit::save() { |
719 | QString file = doc->file(); | 719 | QString file = doc->file(); |
720 | qDebug("saver file "+file); | 720 | qDebug("saver file "+file); |
721 | QString name= doc->name(); | 721 | QString name= doc->name(); |
722 | qDebug("File named "+name); | 722 | qDebug("File named "+name); |
723 | QString rt = editor->text(); | 723 | QString rt = editor->text(); |
724 | if( !rt.isEmpty() ) { | 724 | if( !rt.isEmpty() ) { |
725 | if(name.isEmpty()) { | 725 | if(name.isEmpty()) { |
726 | saveAs(); | 726 | saveAs(); |
727 | } else { | 727 | } else { |
728 | currentFileName= name ; | 728 | currentFileName= name ; |
729 | qDebug("saveFile "+currentFileName); | 729 | qDebug("saveFile "+currentFileName); |
730 | 730 | ||
731 | struct stat buf; | 731 | struct stat buf; |
732 | mode_t mode; | 732 | mode_t mode; |
733 | stat(file.latin1(), &buf); | 733 | stat(file.latin1(), &buf); |
734 | mode = buf.st_mode; | 734 | mode = buf.st_mode; |
735 | 735 | ||
736 | if(!fileIs) { | 736 | if(!fileIs) { |
737 | doc->setName( name); | 737 | doc->setName( name); |
738 | FileManager fm; | 738 | FileManager fm; |
739 | if ( !fm.saveFile( *doc, rt ) ) { | 739 | if ( !fm.saveFile( *doc, rt ) ) { |
740 | return false; | 740 | return false; |
741 | } | 741 | } |
742 | } else { | 742 | } else { |
743 | qDebug("regular save file"); | 743 | qDebug("regular save file"); |
744 | QFile f(file); | 744 | QFile f(file); |
745 | if( f.open(IO_WriteOnly)) { | 745 | if( f.open(IO_WriteOnly)) { |
746 | QCString crt = rt.utf8(); | 746 | QCString crt = rt.utf8(); |
747 | f.writeBlock(crt,crt.length()); | 747 | f.writeBlock(crt,crt.length()); |
748 | } else { | 748 | } else { |
749 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 749 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
750 | return false; | 750 | return false; |
751 | } | 751 | } |
752 | 752 | ||
753 | } | 753 | } |
754 | editor->setEdited( FALSE); | 754 | editor->setEdited( FALSE); |
755 | edited1=FALSE; | 755 | edited1=FALSE; |
756 | edited=FALSE; | 756 | edited=FALSE; |
757 | if(caption().left(1)=="*") | 757 | if(caption().left(1)=="*") |
758 | setCaption(caption().right(caption().length()-1)); | 758 | setCaption(caption().right(caption().length()-1)); |
759 | 759 | ||
760 | 760 | ||
761 | chmod( file.latin1(), mode); | 761 | chmod( file.latin1(), mode); |
762 | } | 762 | } |
763 | return true; | 763 | return true; |
764 | } | 764 | } |
765 | return false; | 765 | return false; |
766 | } | 766 | } |
767 | 767 | ||
768 | /*! | 768 | /*! |
769 | prompted save */ | 769 | prompted save */ |
770 | bool TextEdit::saveAs() { | 770 | bool TextEdit::saveAs() { |
771 | qDebug("saveAsFile "+currentFileName); | 771 | qDebug("saveAsFile "+currentFileName); |
772 | // case of nothing to save... | 772 | // case of nothing to save... |
773 | if ( !doc ) { | 773 | if ( !doc ) { |
774 | //|| !bFromDocView) | 774 | //|| !bFromDocView) |
775 | qDebug("no doc"); | 775 | qDebug("no doc"); |
776 | return true; | 776 | return true; |
777 | } | 777 | } |
778 | if ( !editor->edited() ) { | 778 | if ( !editor->edited() ) { |
779 | delete doc; | 779 | delete doc; |
780 | doc = 0; | 780 | doc = 0; |
781 | return true; | 781 | return true; |
782 | } | 782 | } |
783 | 783 | ||
784 | QString rt = editor->text(); | 784 | QString rt = editor->text(); |
785 | qDebug(currentFileName); | 785 | qDebug(currentFileName); |
786 | 786 | ||
787 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { | 787 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { |
788 | // qDebug("do silly TT filename thing"); | 788 | // qDebug("do silly TT filename thing"); |
789 | if ( doc->name().isEmpty() ) { | 789 | if ( doc->name().isEmpty() ) { |
790 | QString pt = rt.simplifyWhiteSpace(); | 790 | QString pt = rt.simplifyWhiteSpace(); |
791 | int i = pt.find( ' ' ); | 791 | int i = pt.find( ' ' ); |
792 | QString docname = pt; | 792 | QString docname = pt; |
793 | if ( i > 0 ) | 793 | if ( i > 0 ) |
794 | docname = pt.left( i ); | 794 | docname = pt.left( i ); |
795 | // remove "." at the beginning | 795 | // remove "." at the beginning |
796 | while( docname.startsWith( "." ) ) | 796 | while( docname.startsWith( "." ) ) |
797 | docname = docname.mid( 1 ); | 797 | docname = docname.mid( 1 ); |
798 | docname.replace( QRegExp("/"), "_" ); | 798 | docname.replace( QRegExp("/"), "_" ); |
799 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 799 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
800 | if ( docname.length() > 40 ) | 800 | if ( docname.length() > 40 ) |
801 | docname = docname.left(40); | 801 | docname = docname.left(40); |
802 | if ( docname.isEmpty() ) | 802 | if ( docname.isEmpty() ) |
803 | docname = tr("Unnamed"); | 803 | docname = tr("Unnamed"); |
804 | doc->setName(docname); | 804 | doc->setName(docname); |
805 | currentFileName=docname; | 805 | currentFileName=docname; |
806 | } | 806 | } |
807 | } | 807 | } |
808 | 808 | ||
809 | QMap<QString, QStringList> map; | 809 | QMap<QString, QStringList> map; |
810 | map.insert(tr("All"), QStringList() ); | 810 | map.insert(tr("All"), QStringList() ); |
811 | QStringList text; | 811 | QStringList text; |
812 | text << "text/*"; | 812 | text << "text/*"; |
813 | map.insert(tr("Text"), text ); | 813 | map.insert(tr("Text"), text ); |
814 | text << "*"; | 814 | text << "*"; |
815 | map.insert(tr("All"), text ); | 815 | map.insert(tr("All"), text ); |
816 | 816 | ||
817 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); | 817 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); |
818 | 818 | ||
819 | if(!str.isEmpty() ) { | 819 | if(!str.isEmpty() ) { |
820 | QString fileNm=str; | 820 | QString fileNm=str; |
821 | 821 | ||
822 | qDebug("saving filename "+fileNm); | 822 | qDebug("saving filename "+fileNm); |
823 | QFileInfo fi(fileNm); | 823 | QFileInfo fi(fileNm); |
824 | currentFileName=fi.fileName(); | 824 | currentFileName=fi.fileName(); |
825 | if(doc) { | 825 | if(doc) { |
826 | // QString file = doc->file(); | 826 | // QString file = doc->file(); |
827 | // doc->removeFiles(); | 827 | // doc->removeFiles(); |
828 | delete doc; | 828 | delete doc; |
829 | DocLnk nf; | 829 | DocLnk nf; |
830 | nf.setType("text/plain"); | 830 | nf.setType("text/plain"); |
831 | nf.setFile( fileNm); | 831 | nf.setFile( fileNm); |
832 | doc = new DocLnk(nf); | 832 | doc = new DocLnk(nf); |
833 | // editor->setText(rt); | 833 | // editor->setText(rt); |
834 | // qDebug("openFile doclnk "+currentFileName); | 834 | // qDebug("openFile doclnk "+currentFileName); |
835 | doc->setName( currentFileName); | 835 | doc->setName( currentFileName); |
836 | updateCaption( currentFileName); | 836 | updateCaption( currentFileName); |
837 | 837 | ||
838 | FileManager fm; | 838 | FileManager fm; |
839 | if ( !fm.saveFile( *doc, rt ) ) { | 839 | if ( !fm.saveFile( *doc, rt ) ) { |
840 | return false; | 840 | return false; |
841 | } | 841 | } |
842 | 842 | ||
843 | if( useAdvancedFeatures ) { | 843 | if( useAdvancedFeatures ) { |
844 | filePermissions *filePerm; | 844 | filePermissions *filePerm; |
845 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); | 845 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); |
846 | filePerm->showMaximized(); | ||
846 | filePerm->exec(); | 847 | filePerm->exec(); |
847 | 848 | ||
848 | if( filePerm) | 849 | if( filePerm) |
849 | delete filePerm; | 850 | delete filePerm; |
850 | } | 851 | } |
851 | } | 852 | } |
852 | editor->setEdited( false); | 853 | editor->setEdited( false); |
853 | edited1 = false; | 854 | edited1 = false; |
854 | edited = false; | 855 | edited = false; |
855 | if(caption().left(1)=="*") | 856 | if(caption().left(1)=="*") |
856 | setCaption(caption().right(caption().length()-1)); | 857 | setCaption(caption().right(caption().length()-1)); |
857 | 858 | ||
858 | return true; | 859 | return true; |
859 | } | 860 | } |
860 | qDebug("returning false"); | 861 | qDebug("returning false"); |
861 | return false; | 862 | return false; |
862 | } //end saveAs | 863 | } //end saveAs |
863 | 864 | ||
864 | void TextEdit::clear() { | 865 | void TextEdit::clear() { |
865 | delete doc; | 866 | delete doc; |
866 | doc = 0; | 867 | doc = 0; |
867 | editor->clear(); | 868 | editor->clear(); |
868 | } | 869 | } |
869 | 870 | ||
870 | void TextEdit::updateCaption( const QString &name ) { | 871 | void TextEdit::updateCaption( const QString &name ) { |
871 | if ( !doc ) | 872 | if ( !doc ) |
872 | setCaption( tr("Text Editor") ); | 873 | setCaption( tr("Text Editor") ); |
873 | else { | 874 | else { |
874 | QString s = name; | 875 | QString s = name; |
875 | if ( s.isNull() ) | 876 | if ( s.isNull() ) |
876 | s = doc->name(); | 877 | s = doc->name(); |
877 | if ( s.isEmpty() ) { | 878 | if ( s.isEmpty() ) { |
878 | s = tr( "Unnamed" ); | 879 | s = tr( "Unnamed" ); |
879 | currentFileName=s; | 880 | currentFileName=s; |
880 | } | 881 | } |
881 | if(s.left(1) == "/") | 882 | if(s.left(1) == "/") |
882 | s = s.right(s.length()-1); | 883 | s = s.right(s.length()-1); |
883 | setCaption( s + " - " + tr("Text Editor") ); | 884 | setCaption( s + " - " + tr("Text Editor") ); |
884 | } | 885 | } |
885 | } | 886 | } |
886 | 887 | ||
887 | void TextEdit::setDocument(const QString& fileref) { | 888 | void TextEdit::setDocument(const QString& fileref) { |
888 | bFromDocView = TRUE; | 889 | bFromDocView = TRUE; |
889 | openFile(fileref); | 890 | openFile(fileref); |
890 | editor->setEdited(TRUE); | 891 | editor->setEdited(TRUE); |
891 | edited1=FALSE; | 892 | edited1=FALSE; |
892 | edited=TRUE; | 893 | edited=TRUE; |
893 | doSearchBar(); | 894 | doSearchBar(); |
894 | } | 895 | } |
895 | 896 | ||
896 | void TextEdit::closeEvent( QCloseEvent *e ) { | 897 | void TextEdit::closeEvent( QCloseEvent *e ) { |
897 | bFromDocView = FALSE; | 898 | bFromDocView = FALSE; |
898 | e->accept(); | 899 | e->accept(); |
899 | } | 900 | } |
900 | 901 | ||
901 | void TextEdit::changeFont() { | 902 | void TextEdit::changeFont() { |
902 | FontDatabase fdb; | 903 | FontDatabase fdb; |
903 | QFont defaultFont=editor->font(); | 904 | QFont defaultFont=editor->font(); |
904 | QFontInfo fontInfo(defaultFont); | 905 | QFontInfo fontInfo(defaultFont); |
905 | Config cfg("TextEdit"); | 906 | Config cfg("TextEdit"); |
906 | cfg.setGroup("Font"); | 907 | cfg.setGroup("Font"); |
907 | QString family = cfg.readEntry("Family", fontInfo.family()); | 908 | QString family = cfg.readEntry("Family", fontInfo.family()); |
908 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 909 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
909 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 910 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
910 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 911 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
911 | 912 | ||
912 | defaultFont = fdb.font(family,style,i_size,charSet); | 913 | defaultFont = fdb.font(family,style,i_size,charSet); |
913 | 914 | ||
914 | FontDialog *fontDlg; | 915 | FontDialog *fontDlg; |
915 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); | 916 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); |
916 | 917 | ||
917 | fontDlg->exec(); | 918 | fontDlg->exec(); |
918 | 919 | ||
919 | QFont myFont=fontDlg->selectedFont; | 920 | QFont myFont=fontDlg->selectedFont; |
920 | editor->setFont( myFont); | 921 | editor->setFont( myFont); |
921 | delete fontDlg; | 922 | delete fontDlg; |
922 | 923 | ||
923 | } | 924 | } |
924 | 925 | ||
925 | void TextEdit::editDelete() { | 926 | void TextEdit::editDelete() { |
926 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want<BR>to <B>delete</B> the current file\nfrom the disk?<BR>This is <B>irreversable!!</B>"),tr("Yes"),tr("No"),0,0,1) ) { | 927 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want<BR>to <B>delete</B> the current file\nfrom the disk?<BR>This is <B>irreversable!!</B>"),tr("Yes"),tr("No"),0,0,1) ) { |
927 | case 0: | 928 | case 0: |
928 | if(doc) { | 929 | if(doc) { |
929 | doc->removeFiles(); | 930 | doc->removeFiles(); |
930 | clear(); | 931 | clear(); |
931 | setCaption( tr("Text Editor") ); | 932 | setCaption( tr("Text Editor") ); |
932 | } | 933 | } |
933 | break; | 934 | break; |
934 | case 1: | 935 | case 1: |
935 | // exit | 936 | // exit |
936 | break; | 937 | break; |
937 | }; | 938 | }; |
938 | } | 939 | } |
939 | 940 | ||
940 | void TextEdit::changeStartConfig( bool b ) { | 941 | void TextEdit::changeStartConfig( bool b ) { |
941 | 942 | ||
942 | Config cfg("TextEdit"); | 943 | Config cfg("TextEdit"); |
943 | cfg.setGroup("View"); | 944 | cfg.setGroup("View"); |
944 | if(b) { | 945 | if(b) { |
945 | qDebug("bool"); | 946 | qDebug("bool"); |
946 | cfg.writeEntry("startNew","TRUE"); | 947 | cfg.writeEntry("startNew","TRUE"); |
947 | } else { | 948 | } else { |
948 | cfg.writeEntry("startNew","FALSE"); | 949 | cfg.writeEntry("startNew","FALSE"); |
949 | } | 950 | } |
950 | update(); | 951 | update(); |
951 | } | 952 | } |
952 | 953 | ||
953 | void TextEdit::editorChanged() { | 954 | void TextEdit::editorChanged() { |
954 | if(editor->edited() && edited && !edited1) { | 955 | if(editor->edited() && edited && !edited1) { |
955 | setCaption( "*"+caption()); | 956 | setCaption( "*"+caption()); |
956 | edited1=TRUE; | 957 | edited1=TRUE; |
957 | } | 958 | } |
958 | edited=TRUE; | 959 | edited=TRUE; |
959 | } | 960 | } |
960 | 961 | ||
961 | void TextEdit::receive(const QCString&msg, const QByteArray&) { | 962 | void TextEdit::receive(const QCString&msg, const QByteArray&) { |
962 | qDebug("QCop "+msg); | 963 | qDebug("QCop "+msg); |
963 | if ( msg == "setDocument(QString)" ) { | 964 | if ( msg == "setDocument(QString)" ) { |
964 | qDebug("bugger all"); | 965 | qDebug("bugger all"); |
965 | } | 966 | } |
966 | 967 | ||
967 | } | 968 | } |
968 | void TextEdit::doAbout() { | 969 | void TextEdit::doAbout() { |
969 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 970 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
970 | "2000 Trolltech AS, and<BR>" | 971 | "2000 Trolltech AS, and<BR>" |
971 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 972 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
972 | "and is licensed under the GPL")); | 973 | "and is licensed under the GPL")); |
973 | } | 974 | } |
974 | 975 | ||
975 | void TextEdit::doAdvanced(bool b) { | 976 | void TextEdit::doAdvanced(bool b) { |
976 | useAdvancedFeatures=b; | 977 | useAdvancedFeatures=b; |
977 | Config cfg("TextEdit"); | 978 | Config cfg("TextEdit"); |
978 | cfg.setGroup("View"); | 979 | cfg.setGroup("View"); |
979 | cfg.writeEntry("AdvancedFeatures",b); | 980 | cfg.writeEntry("AdvancedFeatures",b); |
980 | } | 981 | } |
981 | 982 | ||
982 | void TextEdit::editPasteTimeDate() { | 983 | void TextEdit::editPasteTimeDate() { |
983 | #ifndef QT_NO_CLIPBOARD | 984 | #ifndef QT_NO_CLIPBOARD |
984 | QClipboard *cb = QApplication::clipboard(); | 985 | QClipboard *cb = QApplication::clipboard(); |
985 | QDateTime dt = QDateTime::currentDateTime(); | 986 | QDateTime dt = QDateTime::currentDateTime(); |
986 | cb->setText( dt.toString()); | 987 | cb->setText( dt.toString()); |
987 | editor->paste(); | 988 | editor->paste(); |
988 | #endif | 989 | #endif |
989 | } | 990 | } |