author | bipolar <bipolar> | 2002-03-06 00:58:32 (UTC) |
---|---|---|
committer | bipolar <bipolar> | 2002-03-06 00:58:32 (UTC) |
commit | 406bed0f501ea131ba31dbdecdde8c1fe8b15806 (patch) (unidiff) | |
tree | 11f375b25df3534e7d8ecd4120ee2df53a9791d3 | |
parent | fcb139a744cfe6c9521962595f15cd8369251c56 (diff) | |
download | opie-406bed0f501ea131ba31dbdecdde8c1fe8b15806.zip opie-406bed0f501ea131ba31dbdecdde8c1fe8b15806.tar.gz opie-406bed0f501ea131ba31dbdecdde8c1fe8b15806.tar.bz2 |
ljp: fixed setDocument opening the .desktop file and not the file it points too
-rw-r--r-- | core/apps/textedit/textedit.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index f138572..0f19da9 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -451,449 +451,452 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up) | |||
451 | } else if ( round_down_not_up ) { | 451 | } else if ( round_down_not_up ) { |
452 | if ( fontsize[i] < sz ) | 452 | if ( fontsize[i] < sz ) |
453 | s = fontsize[i]; | 453 | s = fontsize[i]; |
454 | } else { | 454 | } else { |
455 | if ( fontsize[i] > sz ) { | 455 | if ( fontsize[i] > sz ) { |
456 | s = fontsize[i]; | 456 | s = fontsize[i]; |
457 | break; | 457 | break; |
458 | } | 458 | } |
459 | } | 459 | } |
460 | } | 460 | } |
461 | 461 | ||
462 | QFont f = editor->font(); | 462 | QFont f = editor->font(); |
463 | f.setPointSize(s); | 463 | f.setPointSize(s); |
464 | editor->setFont(f); | 464 | editor->setFont(f); |
465 | 465 | ||
466 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 466 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
467 | zout->setEnabled(s != fontsize[0]); | 467 | zout->setEnabled(s != fontsize[0]); |
468 | } | 468 | } |
469 | 469 | ||
470 | void TextEdit::setBold(bool y) | 470 | void TextEdit::setBold(bool y) |
471 | { | 471 | { |
472 | QFont f = editor->font(); | 472 | QFont f = editor->font(); |
473 | f.setBold(y); | 473 | f.setBold(y); |
474 | editor->setFont(f); | 474 | editor->setFont(f); |
475 | } | 475 | } |
476 | 476 | ||
477 | void TextEdit::setItalic(bool y) | 477 | void TextEdit::setItalic(bool y) |
478 | { | 478 | { |
479 | QFont f = editor->font(); | 479 | QFont f = editor->font(); |
480 | f.setItalic(y); | 480 | f.setItalic(y); |
481 | editor->setFont(f); | 481 | editor->setFont(f); |
482 | } | 482 | } |
483 | 483 | ||
484 | void TextEdit::setWordWrap(bool y) | 484 | void TextEdit::setWordWrap(bool y) |
485 | { | 485 | { |
486 | bool state = editor->edited(); | 486 | bool state = editor->edited(); |
487 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 487 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
488 | editor->setEdited( state ); | 488 | editor->setEdited( state ); |
489 | } | 489 | } |
490 | 490 | ||
491 | void TextEdit::fileNew() | 491 | void TextEdit::fileNew() |
492 | { | 492 | { |
493 | if( !bFromDocView ) { | 493 | if( !bFromDocView ) { |
494 | saveAs(); | 494 | saveAs(); |
495 | } | 495 | } |
496 | newFile(DocLnk()); | 496 | newFile(DocLnk()); |
497 | } | 497 | } |
498 | 498 | ||
499 | void TextEdit::fileOpen() | 499 | void TextEdit::fileOpen() |
500 | { | 500 | { |
501 | // if ( !save() ) { | 501 | // if ( !save() ) { |
502 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 502 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
503 | // tr( "Text Editor was unable to\n" | 503 | // tr( "Text Editor was unable to\n" |
504 | // "save your changes.\n" | 504 | // "save your changes.\n" |
505 | // "Free some space and try again.\n" | 505 | // "Free some space and try again.\n" |
506 | // "\nContinue anyway?" ), | 506 | // "\nContinue anyway?" ), |
507 | // QMessageBox::Yes|QMessageBox::Escape, | 507 | // QMessageBox::Yes|QMessageBox::Escape, |
508 | // QMessageBox::No|QMessageBox::Default ) | 508 | // QMessageBox::No|QMessageBox::Default ) |
509 | // != QMessageBox::Yes ) | 509 | // != QMessageBox::Yes ) |
510 | // return; | 510 | // return; |
511 | // else { | 511 | // else { |
512 | // delete doc; | 512 | // delete doc; |
513 | // doc = 0; | 513 | // doc = 0; |
514 | // } | 514 | // } |
515 | // } | 515 | // } |
516 | menu->hide(); | 516 | menu->hide(); |
517 | editBar->hide(); | 517 | editBar->hide(); |
518 | searchBar->hide(); | 518 | searchBar->hide(); |
519 | clearWState (WState_Reserved1 ); | 519 | clearWState (WState_Reserved1 ); |
520 | editorStack->raiseWidget( fileSelector ); | 520 | editorStack->raiseWidget( fileSelector ); |
521 | fileSelector->reread(); | 521 | fileSelector->reread(); |
522 | updateCaption(); | 522 | updateCaption(); |
523 | } | 523 | } |
524 | 524 | ||
525 | void TextEdit::newFileOpen() | 525 | void TextEdit::newFileOpen() |
526 | { | 526 | { |
527 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); | 527 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); |
528 | if( browseForFiles->exec() != -1 ) { | 528 | if( browseForFiles->exec() != -1 ) { |
529 | QString selFile= browseForFiles->selectedFileName; | 529 | QString selFile= browseForFiles->selectedFileName; |
530 | QStringList fileList=browseForFiles->fileList; | 530 | QStringList fileList=browseForFiles->fileList; |
531 | qDebug(selFile); | 531 | qDebug(selFile); |
532 | QStringList::ConstIterator f; | 532 | QStringList::ConstIterator f; |
533 | QString fileTemp; | 533 | QString fileTemp; |
534 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 534 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
535 | fileTemp = *f; | 535 | fileTemp = *f; |
536 | fileTemp.right( fileTemp.length()-5); | 536 | fileTemp.right( fileTemp.length()-5); |
537 | QString fileName = fileTemp; | 537 | QString fileName = fileTemp; |
538 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 538 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
539 | currentFileName = fileName; | 539 | currentFileName = fileName; |
540 | qDebug("please open "+currentFileName); | 540 | qDebug("please open "+currentFileName); |
541 | openFile(fileName ); | 541 | openFile(fileName ); |
542 | } | 542 | } |
543 | } | 543 | } |
544 | } | 544 | } |
545 | delete browseForFiles; | 545 | delete browseForFiles; |
546 | editor->setEdited( true ); | 546 | editor->setEdited( true ); |
547 | } | 547 | } |
548 | 548 | ||
549 | #if 0 | 549 | #if 0 |
550 | void TextEdit::slotFind() | 550 | void TextEdit::slotFind() |
551 | { | 551 | { |
552 | FindDialog frmFind( "Text Editor", this ); | 552 | FindDialog frmFind( "Text Editor", this ); |
553 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 553 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
554 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 554 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
555 | 555 | ||
556 | //case sensitive, backwards, [category] | 556 | //case sensitive, backwards, [category] |
557 | 557 | ||
558 | connect( editor, SIGNAL(notFound()), | 558 | connect( editor, SIGNAL(notFound()), |
559 | &frmFind, SLOT(slotNotFound()) ); | 559 | &frmFind, SLOT(slotNotFound()) ); |
560 | connect( editor, SIGNAL(searchWrapped()), | 560 | connect( editor, SIGNAL(searchWrapped()), |
561 | &frmFind, SLOT(slotWrapAround()) ); | 561 | &frmFind, SLOT(slotWrapAround()) ); |
562 | 562 | ||
563 | frmFind.exec(); | 563 | frmFind.exec(); |
564 | 564 | ||
565 | 565 | ||
566 | } | 566 | } |
567 | #endif | 567 | #endif |
568 | 568 | ||
569 | void TextEdit::fileRevert() | 569 | void TextEdit::fileRevert() |
570 | { | 570 | { |
571 | clear(); | 571 | clear(); |
572 | fileOpen(); | 572 | fileOpen(); |
573 | } | 573 | } |
574 | 574 | ||
575 | void TextEdit::editCut() | 575 | void TextEdit::editCut() |
576 | { | 576 | { |
577 | #ifndef QT_NO_CLIPBOARD | 577 | #ifndef QT_NO_CLIPBOARD |
578 | editor->cut(); | 578 | editor->cut(); |
579 | #endif | 579 | #endif |
580 | } | 580 | } |
581 | 581 | ||
582 | void TextEdit::editCopy() | 582 | void TextEdit::editCopy() |
583 | { | 583 | { |
584 | #ifndef QT_NO_CLIPBOARD | 584 | #ifndef QT_NO_CLIPBOARD |
585 | editor->copy(); | 585 | editor->copy(); |
586 | #endif | 586 | #endif |
587 | } | 587 | } |
588 | 588 | ||
589 | void TextEdit::editPaste() | 589 | void TextEdit::editPaste() |
590 | { | 590 | { |
591 | #ifndef QT_NO_CLIPBOARD | 591 | #ifndef QT_NO_CLIPBOARD |
592 | editor->paste(); | 592 | editor->paste(); |
593 | #endif | 593 | #endif |
594 | } | 594 | } |
595 | 595 | ||
596 | void TextEdit::editFind() | 596 | void TextEdit::editFind() |
597 | { | 597 | { |
598 | searchBar->show(); | 598 | searchBar->show(); |
599 | searchVisible = TRUE; | 599 | searchVisible = TRUE; |
600 | searchEdit->setFocus(); | 600 | searchEdit->setFocus(); |
601 | } | 601 | } |
602 | 602 | ||
603 | void TextEdit::findNext() | 603 | void TextEdit::findNext() |
604 | { | 604 | { |
605 | editor->find( searchEdit->text(), FALSE, FALSE ); | 605 | editor->find( searchEdit->text(), FALSE, FALSE ); |
606 | 606 | ||
607 | } | 607 | } |
608 | 608 | ||
609 | void TextEdit::findClose() | 609 | void TextEdit::findClose() |
610 | { | 610 | { |
611 | searchVisible = FALSE; | 611 | searchVisible = FALSE; |
612 | searchBar->hide(); | 612 | searchBar->hide(); |
613 | } | 613 | } |
614 | 614 | ||
615 | void TextEdit::search() | 615 | void TextEdit::search() |
616 | { | 616 | { |
617 | editor->find( searchEdit->text(), FALSE, FALSE ); | 617 | editor->find( searchEdit->text(), FALSE, FALSE ); |
618 | } | 618 | } |
619 | 619 | ||
620 | void TextEdit::newFile( const DocLnk &f ) | 620 | void TextEdit::newFile( const DocLnk &f ) |
621 | { | 621 | { |
622 | DocLnk nf = f; | 622 | DocLnk nf = f; |
623 | nf.setType("text/plain"); | 623 | nf.setType("text/plain"); |
624 | clear(); | 624 | clear(); |
625 | editorStack->raiseWidget( editor ); | 625 | editorStack->raiseWidget( editor ); |
626 | setWState (WState_Reserved1 ); | 626 | setWState (WState_Reserved1 ); |
627 | editor->setFocus(); | 627 | editor->setFocus(); |
628 | doc = new DocLnk(nf); | 628 | doc = new DocLnk(nf); |
629 | qDebug("newFile "+currentFileName); | 629 | qDebug("newFile "+currentFileName); |
630 | updateCaption(currentFileName); | 630 | updateCaption(currentFileName); |
631 | } | 631 | } |
632 | 632 | ||
633 | void TextEdit::openFile( const QString &f ) | 633 | void TextEdit::openFile( const QString &f ) |
634 | { | 634 | { |
635 | bFromDocView = TRUE; | 635 | bFromDocView = TRUE; |
636 | DocLnk nf; | 636 | DocLnk nf; |
637 | nf.setType("text/plain"); | 637 | nf.setType("text/plain"); |
638 | nf.setFile(f); | 638 | nf.setFile(f); |
639 | currentFileName=f; | 639 | currentFileName=f; |
640 | QFileInfo fi( currentFileName); | 640 | QFileInfo fi( currentFileName); |
641 | nf.setName(fi.baseName()); | 641 | nf.setName(fi.baseName()); |
642 | qDebug("openFile string"+currentFileName); | 642 | qDebug("openFile string"+currentFileName); |
643 | 643 | ||
644 | openFile(nf); | 644 | openFile(nf); |
645 | showEditTools(); | 645 | showEditTools(); |
646 | // Show filename in caption | 646 | // Show filename in caption |
647 | QString name = f; | 647 | QString name = f; |
648 | int sep = name.findRev( '/' ); | 648 | int sep = name.findRev( '/' ); |
649 | if ( sep > 0 ) | 649 | if ( sep > 0 ) |
650 | name = name.mid( sep+1 ); | 650 | name = name.mid( sep+1 ); |
651 | updateCaption( name ); | 651 | updateCaption( name ); |
652 | } | 652 | } |
653 | 653 | ||
654 | void TextEdit::openFile( const DocLnk &f ) | 654 | void TextEdit::openFile( const DocLnk &f ) |
655 | { | 655 | { |
656 | // clear(); | 656 | // clear(); |
657 | bFromDocView = TRUE; | 657 | bFromDocView = TRUE; |
658 | FileManager fm; | 658 | FileManager fm; |
659 | QString txt; | 659 | QString txt; |
660 | currentFileName=f.name(); | 660 | currentFileName=f.name(); |
661 | qDebug("openFile doclnk " + currentFileName); | 661 | qDebug("openFile doclnk " + currentFileName); |
662 | if ( !fm.loadFile( f, txt ) ) { | 662 | if ( !fm.loadFile( f, txt ) ) { |
663 | // ####### could be a new file | 663 | // ####### could be a new file |
664 | qDebug( "Cannot open file" ); | 664 | qDebug( "Cannot open file" ); |
665 | 665 | ||
666 | //return; | 666 | //return; |
667 | } | 667 | } |
668 | 668 | ||
669 | fileNew(); | 669 | fileNew(); |
670 | if ( doc ) | 670 | if ( doc ) |
671 | delete doc; | 671 | delete doc; |
672 | doc = new DocLnk(f); | 672 | doc = new DocLnk(f); |
673 | editor->setText(txt); | 673 | editor->setText(txt); |
674 | editor->setEdited( false); | 674 | editor->setEdited( false); |
675 | qDebug("openFile doclnk "+currentFileName); | 675 | qDebug("openFile doclnk "+currentFileName); |
676 | doc->setName(currentFileName); | 676 | doc->setName(currentFileName); |
677 | updateCaption(); | 677 | updateCaption(); |
678 | } | 678 | } |
679 | 679 | ||
680 | void TextEdit::showEditTools() | 680 | void TextEdit::showEditTools() |
681 | { | 681 | { |
682 | // if ( !doc ) | 682 | // if ( !doc ) |
683 | // close(); | 683 | // close(); |
684 | // clear(); | 684 | // clear(); |
685 | fileSelector->hide(); | 685 | fileSelector->hide(); |
686 | menu->show(); | 686 | menu->show(); |
687 | editBar->show(); | 687 | editBar->show(); |
688 | if ( searchVisible ) | 688 | if ( searchVisible ) |
689 | searchBar->show(); | 689 | searchBar->show(); |
690 | // updateCaption(); | 690 | // updateCaption(); |
691 | editorStack->raiseWidget( editor ); | 691 | editorStack->raiseWidget( editor ); |
692 | setWState (WState_Reserved1 ); | 692 | setWState (WState_Reserved1 ); |
693 | } | 693 | } |
694 | 694 | ||
695 | /*! | 695 | /*! |
696 | unprompted save */ | 696 | unprompted save */ |
697 | bool TextEdit::save() | 697 | bool TextEdit::save() |
698 | { | 698 | { |
699 | QString file = doc->file(); | 699 | QString file = doc->file(); |
700 | QString name= doc->name(); | 700 | QString name= doc->name(); |
701 | 701 | ||
702 | QString rt = editor->text(); | 702 | QString rt = editor->text(); |
703 | currentFileName= name ; | 703 | currentFileName= name ; |
704 | qDebug("saveFile "+currentFileName); | 704 | qDebug("saveFile "+currentFileName); |
705 | 705 | ||
706 | struct stat buf; | 706 | struct stat buf; |
707 | mode_t mode; | 707 | mode_t mode; |
708 | stat(file.latin1(), &buf); | 708 | stat(file.latin1(), &buf); |
709 | mode = buf.st_mode; | 709 | mode = buf.st_mode; |
710 | 710 | ||
711 | doc->setName( name); | 711 | doc->setName( name); |
712 | FileManager fm; | 712 | FileManager fm; |
713 | if ( !fm.saveFile( *doc, rt ) ) { | 713 | if ( !fm.saveFile( *doc, rt ) ) { |
714 | return false; | 714 | return false; |
715 | } | 715 | } |
716 | editor->setEdited( false ); | 716 | editor->setEdited( false ); |
717 | 717 | ||
718 | chmod( file.latin1(), mode); | 718 | chmod( file.latin1(), mode); |
719 | return true; | 719 | return true; |
720 | } | 720 | } |
721 | 721 | ||
722 | /*! | 722 | /*! |
723 | prompted save */ | 723 | prompted save */ |
724 | bool TextEdit::saveAs() | 724 | bool TextEdit::saveAs() |
725 | { | 725 | { |
726 | // qDebug("saveAsFile "+currentFileName); | 726 | // qDebug("saveAsFile "+currentFileName); |
727 | 727 | ||
728 | // case of nothing to save... /// there's always something to save | 728 | // case of nothing to save... /// there's always something to save |
729 | // if ( !doc )//|| !bFromDocView) | 729 | // if ( !doc )//|| !bFromDocView) |
730 | // { | 730 | // { |
731 | // qDebug("no doc"); | 731 | // qDebug("no doc"); |
732 | // return true; | 732 | // return true; |
733 | // } | 733 | // } |
734 | if ( !editor->edited() ) { | 734 | if ( !editor->edited() ) { |
735 | delete doc; | 735 | delete doc; |
736 | doc = 0; | 736 | doc = 0; |
737 | return true; | 737 | return true; |
738 | } | 738 | } |
739 | 739 | ||
740 | QString rt = editor->text(); | 740 | QString rt = editor->text(); |
741 | qDebug(currentFileName); | 741 | qDebug(currentFileName); |
742 | 742 | ||
743 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 743 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
744 | qDebug("do silly TT filename thing"); | 744 | qDebug("do silly TT filename thing"); |
745 | if ( doc->name().isEmpty() ) { | 745 | if ( doc->name().isEmpty() ) { |
746 | QString pt = rt.simplifyWhiteSpace(); | 746 | QString pt = rt.simplifyWhiteSpace(); |
747 | int i = pt.find( ' ' ); | 747 | int i = pt.find( ' ' ); |
748 | QString docname = pt; | 748 | QString docname = pt; |
749 | if ( i > 0 ) | 749 | if ( i > 0 ) |
750 | docname = pt.left( i ); | 750 | docname = pt.left( i ); |
751 | // remove "." at the beginning | 751 | // remove "." at the beginning |
752 | while( docname.startsWith( "." ) ) | 752 | while( docname.startsWith( "." ) ) |
753 | docname = docname.mid( 1 ); | 753 | docname = docname.mid( 1 ); |
754 | docname.replace( QRegExp("/"), "_" ); | 754 | docname.replace( QRegExp("/"), "_" ); |
755 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 755 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
756 | if ( docname.length() > 40 ) | 756 | if ( docname.length() > 40 ) |
757 | docname = docname.left(40); | 757 | docname = docname.left(40); |
758 | if ( docname.isEmpty() ) | 758 | if ( docname.isEmpty() ) |
759 | docname = "Unnamed"; | 759 | docname = "Unnamed"; |
760 | doc->setName(docname); | 760 | doc->setName(docname); |
761 | currentFileName=docname; | 761 | currentFileName=docname; |
762 | } | 762 | } |
763 | } | 763 | } |
764 | 764 | ||
765 | 765 | ||
766 | fileSaveDlg=new fileSaver(this,"Save File",TRUE, 0, currentFileName); | 766 | fileSaveDlg=new fileSaver(this,"Save File",TRUE, 0, currentFileName); |
767 | qDebug("wanna save filename "+currentFileName); | 767 | qDebug("wanna save filename "+currentFileName); |
768 | fileSaveDlg->exec(); | 768 | fileSaveDlg->exec(); |
769 | if( fileSaveDlg->result() == 1 ) { | 769 | if( fileSaveDlg->result() == 1 ) { |
770 | QString fileNm=fileSaveDlg->selectedFileName; | 770 | QString fileNm=fileSaveDlg->selectedFileName; |
771 | qDebug("saving filename "+fileNm); | 771 | qDebug("saving filename "+fileNm); |
772 | QFileInfo fi(fileNm); | 772 | QFileInfo fi(fileNm); |
773 | currentFileName=fi.fileName(); | 773 | currentFileName=fi.fileName(); |
774 | if(doc) { | 774 | if(doc) { |
775 | qDebug("doclnk exists"); | 775 | qDebug("doclnk exists"); |
776 | // QString file = doc->file(); | 776 | // QString file = doc->file(); |
777 | // doc->removeFiles(); | 777 | // doc->removeFiles(); |
778 | delete doc; | 778 | delete doc; |
779 | DocLnk nf; | 779 | DocLnk nf; |
780 | nf.setType("text/plain"); | 780 | nf.setType("text/plain"); |
781 | nf.setFile( fileNm); | 781 | nf.setFile( fileNm); |
782 | doc = new DocLnk(nf); | 782 | doc = new DocLnk(nf); |
783 | // editor->setText(rt); | 783 | // editor->setText(rt); |
784 | qDebug("openFile doclnk "+currentFileName); | 784 | qDebug("openFile doclnk "+currentFileName); |
785 | doc->setName( currentFileName); | 785 | doc->setName( currentFileName); |
786 | updateCaption( currentFileName); | 786 | updateCaption( currentFileName); |
787 | 787 | ||
788 | FileManager fm; | 788 | FileManager fm; |
789 | if ( !fm.saveFile( *doc, rt ) ) { | 789 | if ( !fm.saveFile( *doc, rt ) ) { |
790 | return false; | 790 | return false; |
791 | } | 791 | } |
792 | if( fileSaveDlg->filePermCheck->isChecked() ) { | 792 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
793 | filePermissions *filePerm; | 793 | filePermissions *filePerm; |
794 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); | 794 | filePerm = new filePermissions(this, "Permissions",true,0,(const QString &)fileNm); |
795 | filePerm->exec(); | 795 | filePerm->exec(); |
796 | editor->setEdited( false ); | 796 | editor->setEdited( false ); |
797 | if( filePerm) | 797 | if( filePerm) |
798 | delete filePerm; | 798 | delete filePerm; |
799 | } | 799 | } |
800 | } | 800 | } |
801 | } | 801 | } |
802 | 802 | ||
803 | if(fileSaveDlg) | 803 | if(fileSaveDlg) |
804 | delete fileSaveDlg; | 804 | delete fileSaveDlg; |
805 | return true; | 805 | return true; |
806 | } | 806 | } |
807 | 807 | ||
808 | void TextEdit::clear() | 808 | void TextEdit::clear() |
809 | { | 809 | { |
810 | delete doc; | 810 | delete doc; |
811 | doc = 0; | 811 | doc = 0; |
812 | editor->clear(); | 812 | editor->clear(); |
813 | } | 813 | } |
814 | 814 | ||
815 | void TextEdit::updateCaption( const QString &name ) | 815 | void TextEdit::updateCaption( const QString &name ) |
816 | { | 816 | { |
817 | if ( !doc ) | 817 | if ( !doc ) |
818 | setCaption( tr("Text Editor") ); | 818 | setCaption( tr("Text Editor") ); |
819 | else { | 819 | else { |
820 | QString s = name; | 820 | QString s = name; |
821 | if ( s.isNull() ) | 821 | if ( s.isNull() ) |
822 | s = doc->name(); | 822 | s = doc->name(); |
823 | if ( s.isEmpty() ) { | 823 | if ( s.isEmpty() ) { |
824 | s = tr( "Unnamed" ); | 824 | s = tr( "Unnamed" ); |
825 | currentFileName=s; | 825 | currentFileName=s; |
826 | } | 826 | } |
827 | 827 | ||
828 | setCaption( s + " - " + tr("Text Editor") ); | 828 | setCaption( s + " - " + tr("Text Editor") ); |
829 | } | 829 | } |
830 | } | 830 | } |
831 | 831 | ||
832 | void TextEdit::setDocument(const QString& fileref) | 832 | void TextEdit::setDocument(const QString& fileref) |
833 | { | 833 | { |
834 | bFromDocView = TRUE; | 834 | bFromDocView = TRUE; |
835 | qDebug("setDocument "+fileref); | ||
836 | bFromDocView = TRUE; | ||
837 | if(fileref.find(".desktop",0,TRUE) == -1) { | ||
835 | openFile(fileref); | 838 | openFile(fileref); |
836 | // bFromDocView = TRUE; | 839 | } else { |
837 | // openFile(DocLnk(fileref)); | 840 | openFile(DocLnk(fileref)); |
838 | // showEditTools(); | 841 | } |
839 | } | 842 | } |
840 | 843 | ||
841 | void TextEdit::closeEvent( QCloseEvent *e ) | 844 | void TextEdit::closeEvent( QCloseEvent *e ) |
842 | { | 845 | { |
843 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 846 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
844 | e->ignore(); | 847 | e->ignore(); |
845 | repaint(); | 848 | repaint(); |
846 | // fileRevert(); | 849 | // fileRevert(); |
847 | 850 | ||
848 | } else { | 851 | } else { |
849 | bFromDocView = FALSE; | 852 | bFromDocView = FALSE; |
850 | e->accept(); | 853 | e->accept(); |
851 | } | 854 | } |
852 | } | 855 | } |
853 | 856 | ||
854 | void TextEdit::accept() | 857 | void TextEdit::accept() |
855 | { | 858 | { |
856 | save(); | 859 | save(); |
857 | close(); | 860 | close(); |
858 | // fileOpen(); //godamn thats obnoxious! lemme out!!! | 861 | // fileOpen(); //godamn thats obnoxious! lemme out!!! |
859 | } | 862 | } |
860 | 863 | ||
861 | void TextEdit::changeFont() { | 864 | void TextEdit::changeFont() { |
862 | FontDatabase fdb; | 865 | FontDatabase fdb; |
863 | QFont defaultFont=editor->font(); | 866 | QFont defaultFont=editor->font(); |
864 | QFontInfo fontInfo(defaultFont); | 867 | QFontInfo fontInfo(defaultFont); |
865 | Config cfg("TextEdit"); | 868 | Config cfg("TextEdit"); |
866 | cfg.setGroup("Font"); | 869 | cfg.setGroup("Font"); |
867 | QString family = cfg.readEntry("Family", fontInfo.family()); | 870 | QString family = cfg.readEntry("Family", fontInfo.family()); |
868 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 871 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
869 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 872 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
870 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 873 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
871 | 874 | ||
872 | defaultFont = fdb.font(family,style,i_size,charSet); | 875 | defaultFont = fdb.font(family,style,i_size,charSet); |
873 | 876 | ||
874 | FontDialog *fontDlg; | 877 | FontDialog *fontDlg; |
875 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 878 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
876 | 879 | ||
877 | fontDlg->exec(); | 880 | fontDlg->exec(); |
878 | 881 | ||
879 | QFont myFont=fontDlg->selectedFont; | 882 | QFont myFont=fontDlg->selectedFont; |
880 | editor->setFont( myFont); | 883 | editor->setFont( myFont); |
881 | delete fontDlg; | 884 | delete fontDlg; |
882 | 885 | ||
883 | } | 886 | } |
884 | 887 | ||
885 | void TextEdit::editDelete() | 888 | void TextEdit::editDelete() |
886 | { | 889 | { |
887 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 890 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
888 | case 0: | 891 | case 0: |
889 | if(doc) { | 892 | if(doc) { |
890 | doc->removeFiles(); | 893 | doc->removeFiles(); |
891 | clear(); | 894 | clear(); |
892 | setCaption( tr("Text Editor") ); | 895 | setCaption( tr("Text Editor") ); |
893 | } | 896 | } |
894 | break; | 897 | break; |
895 | case 1: | 898 | case 1: |
896 | // exit | 899 | // exit |
897 | break; | 900 | break; |
898 | }; | 901 | }; |
899 | } | 902 | } |