author | llornkcor <llornkcor> | 2002-06-29 00:51:23 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-06-29 00:51:23 (UTC) |
commit | a9e336965e1cccb41d3e9f5c31168c85cf4e7d36 (patch) (unidiff) | |
tree | bf902af67089de044833da378d1f491574ac4965 | |
parent | 9cc6f3de75b884f338f708ff03900b197f281802 (diff) | |
download | opie-a9e336965e1cccb41d3e9f5c31168c85cf4e7d36.zip opie-a9e336965e1cccb41d3e9f5c31168c85cf4e7d36.tar.gz opie-a9e336965e1cccb41d3e9f5c31168c85cf4e7d36.tar.bz2 |
on your way out, save dialog
-rw-r--r-- | core/apps/textedit/textedit.cpp | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index ea27e1b..40ea501 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -413,201 +413,201 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
413 | } | 413 | } |
414 | 414 | ||
415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
416 | } | 416 | } |
417 | 417 | ||
418 | void TextEdit::cleanUp() | 418 | void TextEdit::cleanUp() |
419 | { | 419 | { |
420 | // save(); | 420 | // save(); |
421 | Config cfg("TextEdit"); | 421 | Config cfg("TextEdit"); |
422 | cfg.setGroup("View"); | 422 | cfg.setGroup("View"); |
423 | QFont f = editor->font(); | 423 | QFont f = editor->font(); |
424 | cfg.writeEntry("FontSize",f.pointSize()); | 424 | cfg.writeEntry("FontSize",f.pointSize()); |
425 | cfg.writeEntry("Bold",f.bold()); | 425 | cfg.writeEntry("Bold",f.bold()); |
426 | cfg.writeEntry("Italic",f.italic()); | 426 | cfg.writeEntry("Italic",f.italic()); |
427 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 427 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
428 | cfg.writeEntry( "FileView", viewSelection ); | 428 | cfg.writeEntry( "FileView", viewSelection ); |
429 | 429 | ||
430 | } | 430 | } |
431 | 431 | ||
432 | TextEdit::~TextEdit() | 432 | TextEdit::~TextEdit() |
433 | { | 433 | { |
434 | } | 434 | } |
435 | 435 | ||
436 | void TextEdit::zoomIn() | 436 | void TextEdit::zoomIn() |
437 | { | 437 | { |
438 | setFontSize(editor->font().pointSize()+1,FALSE); | 438 | setFontSize(editor->font().pointSize()+1,FALSE); |
439 | } | 439 | } |
440 | 440 | ||
441 | void TextEdit::zoomOut() | 441 | void TextEdit::zoomOut() |
442 | { | 442 | { |
443 | setFontSize(editor->font().pointSize()-1,TRUE); | 443 | setFontSize(editor->font().pointSize()-1,TRUE); |
444 | } | 444 | } |
445 | 445 | ||
446 | 446 | ||
447 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 447 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
448 | { | 448 | { |
449 | int s=10; | 449 | int s=10; |
450 | for (int i=0; i<nfontsizes; i++) { | 450 | for (int i=0; i<nfontsizes; i++) { |
451 | if ( fontsize[i] == sz ) { | 451 | if ( fontsize[i] == sz ) { |
452 | s = sz; | 452 | s = sz; |
453 | break; | 453 | break; |
454 | } else if ( round_down_not_up ) { | 454 | } else if ( round_down_not_up ) { |
455 | if ( fontsize[i] < sz ) | 455 | if ( fontsize[i] < sz ) |
456 | s = fontsize[i]; | 456 | s = fontsize[i]; |
457 | } else { | 457 | } else { |
458 | if ( fontsize[i] > sz ) { | 458 | if ( fontsize[i] > sz ) { |
459 | s = fontsize[i]; | 459 | s = fontsize[i]; |
460 | break; | 460 | break; |
461 | } | 461 | } |
462 | } | 462 | } |
463 | } | 463 | } |
464 | 464 | ||
465 | QFont f = editor->font(); | 465 | QFont f = editor->font(); |
466 | f.setPointSize(s); | 466 | f.setPointSize(s); |
467 | editor->setFont(f); | 467 | editor->setFont(f); |
468 | 468 | ||
469 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 469 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
470 | zout->setEnabled(s != fontsize[0]); | 470 | zout->setEnabled(s != fontsize[0]); |
471 | } | 471 | } |
472 | 472 | ||
473 | void TextEdit::setBold(bool y) | 473 | void TextEdit::setBold(bool y) |
474 | { | 474 | { |
475 | QFont f = editor->font(); | 475 | QFont f = editor->font(); |
476 | f.setBold(y); | 476 | f.setBold(y); |
477 | editor->setFont(f); | 477 | editor->setFont(f); |
478 | } | 478 | } |
479 | 479 | ||
480 | void TextEdit::setItalic(bool y) | 480 | void TextEdit::setItalic(bool y) |
481 | { | 481 | { |
482 | QFont f = editor->font(); | 482 | QFont f = editor->font(); |
483 | f.setItalic(y); | 483 | f.setItalic(y); |
484 | editor->setFont(f); | 484 | editor->setFont(f); |
485 | } | 485 | } |
486 | 486 | ||
487 | void TextEdit::setWordWrap(bool y) | 487 | void TextEdit::setWordWrap(bool y) |
488 | { | 488 | { |
489 | bool state = editor->edited(); | 489 | bool state = editor->edited(); |
490 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 490 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
491 | editor->setEdited( state ); | 491 | editor->setEdited( state ); |
492 | } | 492 | } |
493 | 493 | ||
494 | void TextEdit::fileNew() | 494 | void TextEdit::fileNew() |
495 | { | 495 | { |
496 | // if( !bFromDocView ) { | 496 | // if( !bFromDocView ) { |
497 | // saveAs(); | 497 | // saveAs(); |
498 | // } | 498 | // } |
499 | newFile(DocLnk()); | 499 | newFile(DocLnk()); |
500 | } | 500 | } |
501 | 501 | ||
502 | void TextEdit::fileOpen() | 502 | void TextEdit::fileOpen() |
503 | { | 503 | { |
504 | Config cfg("TextEdit"); | 504 | Config cfg("TextEdit"); |
505 | cfg.setGroup("View"); | 505 | cfg.setGroup("View"); |
506 | bool b=FALSE; | 506 | bool b=FALSE; |
507 | 507 | ||
508 | QMap<QString, QStringList> map; | 508 | QMap<QString, QStringList> map; |
509 | map.insert(tr("All"), QStringList() ); | 509 | map.insert(tr("All"), QStringList() ); |
510 | QStringList text; | 510 | QStringList text; |
511 | text << "text/*"; | 511 | text << "text/*"; |
512 | map.insert(tr("Text"), text ); | 512 | map.insert(tr("Text"), text ); |
513 | text << "*"; | 513 | text << "*"; |
514 | map.insert(tr("All"), text ); | 514 | map.insert(tr("All"), text ); |
515 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); | 515 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); |
516 | if(!str.isEmpty() ) | 516 | if(!str.isEmpty() ) |
517 | openFile( str ); | 517 | openFile( str ); |
518 | 518 | ||
519 | } | 519 | } |
520 | 520 | ||
521 | void TextEdit::doSearchBar() | 521 | void TextEdit::doSearchBar() |
522 | { | 522 | { |
523 | Config cfg("TextEdit"); | 523 | Config cfg("TextEdit"); |
524 | cfg.setGroup("View"); | 524 | cfg.setGroup("View"); |
525 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 525 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
526 | searchBar->hide(); | 526 | searchBar->hide(); |
527 | } | 527 | } |
528 | 528 | ||
529 | #if 0 | 529 | #if 0 |
530 | void TextEdit::slotFind() | 530 | void TextEdit::slotFind() |
531 | { | 531 | { |
532 | FindDialog frmFind( tr("Text Editor"), this ); | 532 | FindDialog frmFind( tr("Text Editor"), this ); |
533 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 533 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
534 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 534 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
535 | 535 | ||
536 | //case sensitive, backwards, [category] | 536 | //case sensitive, backwards, [category] |
537 | 537 | ||
538 | connect( editor, SIGNAL(notFound()), | 538 | connect( editor, SIGNAL(notFound()), |
539 | &frmFind, SLOT(slotNotFound()) ); | 539 | &frmFind, SLOT(slotNotFound()) ); |
540 | connect( editor, SIGNAL(searchWrapped()), | 540 | connect( editor, SIGNAL(searchWrapped()), |
541 | &frmFind, SLOT(slotWrapAround()) ); | 541 | &frmFind, SLOT(slotWrapAround()) ); |
542 | 542 | ||
543 | frmFind.exec(); | 543 | frmFind.exec(); |
544 | 544 | ||
545 | 545 | ||
546 | } | 546 | } |
547 | #endif | 547 | #endif |
548 | 548 | ||
549 | void TextEdit::fileRevert() | 549 | void TextEdit::fileRevert() |
550 | { | 550 | { |
551 | clear(); | 551 | clear(); |
552 | fileOpen(); | 552 | fileOpen(); |
553 | } | 553 | } |
554 | 554 | ||
555 | void TextEdit::editCut() | 555 | void TextEdit::editCut() |
556 | { | 556 | { |
557 | #ifndef QT_NO_CLIPBOARD | 557 | #ifndef QT_NO_CLIPBOARD |
558 | editor->cut(); | 558 | editor->cut(); |
559 | #endif | 559 | #endif |
560 | } | 560 | } |
561 | 561 | ||
562 | void TextEdit::editCopy() | 562 | void TextEdit::editCopy() |
563 | { | 563 | { |
564 | #ifndef QT_NO_CLIPBOARD | 564 | #ifndef QT_NO_CLIPBOARD |
565 | editor->copy(); | 565 | editor->copy(); |
566 | #endif | 566 | #endif |
567 | } | 567 | } |
568 | 568 | ||
569 | void TextEdit::editPaste() | 569 | void TextEdit::editPaste() |
570 | { | 570 | { |
571 | #ifndef QT_NO_CLIPBOARD | 571 | #ifndef QT_NO_CLIPBOARD |
572 | editor->paste(); | 572 | editor->paste(); |
573 | #endif | 573 | #endif |
574 | } | 574 | } |
575 | 575 | ||
576 | void TextEdit::editFind() | 576 | void TextEdit::editFind() |
577 | { | 577 | { |
578 | searchBar->show(); | 578 | searchBar->show(); |
579 | searchVisible = TRUE; | 579 | searchVisible = TRUE; |
580 | searchEdit->setFocus(); | 580 | searchEdit->setFocus(); |
581 | Config cfg("TextEdit"); | 581 | Config cfg("TextEdit"); |
582 | cfg.setGroup("View"); | 582 | cfg.setGroup("View"); |
583 | cfg.writeEntry("SearchBar","Opened"); | 583 | cfg.writeEntry("SearchBar","Opened"); |
584 | 584 | ||
585 | } | 585 | } |
586 | 586 | ||
587 | void TextEdit::findNext() | 587 | void TextEdit::findNext() |
588 | { | 588 | { |
589 | editor->find( searchEdit->text(), FALSE, FALSE ); | 589 | editor->find( searchEdit->text(), FALSE, FALSE ); |
590 | 590 | ||
591 | } | 591 | } |
592 | 592 | ||
593 | void TextEdit::findClose() | 593 | void TextEdit::findClose() |
594 | { | 594 | { |
595 | searchVisible = FALSE; | 595 | searchVisible = FALSE; |
596 | searchBar->hide(); | 596 | searchBar->hide(); |
597 | Config cfg("TextEdit"); | 597 | Config cfg("TextEdit"); |
598 | cfg.setGroup("View"); | 598 | cfg.setGroup("View"); |
599 | cfg.writeEntry("SearchBar","Closed"); | 599 | cfg.writeEntry("SearchBar","Closed"); |
600 | cfg.write(); | 600 | cfg.write(); |
601 | } | 601 | } |
602 | 602 | ||
603 | void TextEdit::search() | 603 | void TextEdit::search() |
604 | { | 604 | { |
605 | editor->find( searchEdit->text(), FALSE, FALSE ); | 605 | editor->find( searchEdit->text(), FALSE, FALSE ); |
606 | } | 606 | } |
607 | 607 | ||
608 | void TextEdit::newFile( const DocLnk &f ) | 608 | void TextEdit::newFile( const DocLnk &f ) |
609 | { | 609 | { |
610 | DocLnk nf = f; | 610 | DocLnk nf = f; |
611 | nf.setType("text/plain"); | 611 | nf.setType("text/plain"); |
612 | clear(); | 612 | clear(); |
613 | setWState (WState_Reserved1 ); | 613 | setWState (WState_Reserved1 ); |
@@ -699,238 +699,247 @@ void TextEdit::showEditTools() | |||
699 | 699 | ||
700 | /*! | 700 | /*! |
701 | unprompted save */ | 701 | unprompted save */ |
702 | bool TextEdit::save() | 702 | bool TextEdit::save() |
703 | { | 703 | { |
704 | QString file = doc->file(); | 704 | QString file = doc->file(); |
705 | qDebug("saver file "+file); | 705 | qDebug("saver file "+file); |
706 | QString name= doc->name(); | 706 | QString name= doc->name(); |
707 | qDebug("File named "+name); | 707 | qDebug("File named "+name); |
708 | QString rt = editor->text(); | 708 | QString rt = editor->text(); |
709 | if( !rt.isEmpty() ) { | 709 | if( !rt.isEmpty() ) { |
710 | if(name.isEmpty()) { | 710 | if(name.isEmpty()) { |
711 | saveAs(); | 711 | saveAs(); |
712 | } else { | 712 | } else { |
713 | currentFileName= name ; | 713 | currentFileName= name ; |
714 | qDebug("saveFile "+currentFileName); | 714 | qDebug("saveFile "+currentFileName); |
715 | 715 | ||
716 | struct stat buf; | 716 | struct stat buf; |
717 | mode_t mode; | 717 | mode_t mode; |
718 | stat(file.latin1(), &buf); | 718 | stat(file.latin1(), &buf); |
719 | mode = buf.st_mode; | 719 | mode = buf.st_mode; |
720 | 720 | ||
721 | if(!fileIs) { | 721 | if(!fileIs) { |
722 | doc->setName( name); | 722 | doc->setName( name); |
723 | FileManager fm; | 723 | FileManager fm; |
724 | if ( !fm.saveFile( *doc, rt ) ) { | 724 | if ( !fm.saveFile( *doc, rt ) ) { |
725 | return false; | 725 | return false; |
726 | } | 726 | } |
727 | } else { | 727 | } else { |
728 | qDebug("regular save file"); | 728 | qDebug("regular save file"); |
729 | QFile f(file); | 729 | QFile f(file); |
730 | if( f.open(IO_WriteOnly)) { | 730 | if( f.open(IO_WriteOnly)) { |
731 | QCString crt = rt.utf8(); | 731 | QCString crt = rt.utf8(); |
732 | f.writeBlock(crt,crt.length()); | 732 | f.writeBlock(crt,crt.length()); |
733 | } else { | 733 | } else { |
734 | QMessageBox::message("Text Edit","Write Failed"); | 734 | QMessageBox::message("Text Edit","Write Failed"); |
735 | return false; | 735 | return false; |
736 | } | 736 | } |
737 | 737 | ||
738 | } | 738 | } |
739 | editor->setEdited( FALSE); | 739 | editor->setEdited( FALSE); |
740 | edited1=FALSE; | 740 | edited1=FALSE; |
741 | edited=FALSE; | 741 | edited=FALSE; |
742 | if(caption().left(1)=="*") | 742 | if(caption().left(1)=="*") |
743 | setCaption(caption().right(caption().length()-1)); | 743 | setCaption(caption().right(caption().length()-1)); |
744 | 744 | ||
745 | 745 | ||
746 | chmod( file.latin1(), mode); | 746 | chmod( file.latin1(), mode); |
747 | } | 747 | } |
748 | return true; | 748 | return true; |
749 | } | 749 | } |
750 | return false; | 750 | return false; |
751 | } | 751 | } |
752 | 752 | ||
753 | /*! | 753 | /*! |
754 | prompted save */ | 754 | prompted save */ |
755 | bool TextEdit::saveAs() | 755 | bool TextEdit::saveAs() |
756 | { | 756 | { |
757 | // qDebug("saveAsFile "+currentFileName); | 757 | // qDebug("saveAsFile "+currentFileName); |
758 | // case of nothing to save... | 758 | // case of nothing to save... |
759 | if ( !doc )//|| !bFromDocView) | 759 | if ( !doc )//|| !bFromDocView) |
760 | { | 760 | { |
761 | qDebug("no doc"); | 761 | qDebug("no doc"); |
762 | return true; | 762 | return true; |
763 | } | 763 | } |
764 | if ( !editor->edited() ) { | 764 | if ( !editor->edited() ) { |
765 | delete doc; | 765 | delete doc; |
766 | doc = 0; | 766 | doc = 0; |
767 | return true; | 767 | return true; |
768 | } | 768 | } |
769 | 769 | ||
770 | QString rt = editor->text(); | 770 | QString rt = editor->text(); |
771 | qDebug(currentFileName); | 771 | qDebug(currentFileName); |
772 | 772 | ||
773 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { | 773 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { |
774 | qDebug("do silly TT filename thing"); | 774 | qDebug("do silly TT filename thing"); |
775 | if ( doc->name().isEmpty() ) { | 775 | if ( doc->name().isEmpty() ) { |
776 | QString pt = rt.simplifyWhiteSpace(); | 776 | QString pt = rt.simplifyWhiteSpace(); |
777 | int i = pt.find( ' ' ); | 777 | int i = pt.find( ' ' ); |
778 | QString docname = pt; | 778 | QString docname = pt; |
779 | if ( i > 0 ) | 779 | if ( i > 0 ) |
780 | docname = pt.left( i ); | 780 | docname = pt.left( i ); |
781 | // remove "." at the beginning | 781 | // remove "." at the beginning |
782 | while( docname.startsWith( "." ) ) | 782 | while( docname.startsWith( "." ) ) |
783 | docname = docname.mid( 1 ); | 783 | docname = docname.mid( 1 ); |
784 | docname.replace( QRegExp("/"), "_" ); | 784 | docname.replace( QRegExp("/"), "_" ); |
785 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 785 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
786 | if ( docname.length() > 40 ) | 786 | if ( docname.length() > 40 ) |
787 | docname = docname.left(40); | 787 | docname = docname.left(40); |
788 | if ( docname.isEmpty() ) | 788 | if ( docname.isEmpty() ) |
789 | docname = tr("Unnamed"); | 789 | docname = tr("Unnamed"); |
790 | doc->setName(docname); | 790 | doc->setName(docname); |
791 | currentFileName=docname; | 791 | currentFileName=docname; |
792 | } | 792 | } |
793 | } | 793 | } |
794 | 794 | ||
795 | 795 | /* | |
796 | // QString str = OFileDialog::getSaveFileName( 2,"/");//,"", "*", this ); | 796 | QMap<QString, QStringList> map; |
797 | // if(!str.isEmpty() ) { | 797 | map.insert(tr("All"), QStringList() ); |
798 | // openFile( str ); | 798 | QStringList text; |
799 | 799 | text << "text/*"; | |
800 | fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); | 800 | map.insert(tr("Text"), text ); |
801 | qDebug("wanna save filename "+currentFileName); | 801 | text << "*"; |
802 | fileSaveDlg->exec(); | 802 | map.insert(tr("All"), text ); |
803 | if( fileSaveDlg->result() == 1 ) { | 803 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); |
804 | if(!str.isEmpty() ) { | ||
805 | QString fileNm=str; | ||
806 | */ | ||
807 | |||
808 | fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); | ||
809 | qDebug("wanna save filename "+currentFileName); | ||
810 | fileSaveDlg->exec(); | ||
811 | if( fileSaveDlg->result() == 1 ) { | ||
804 | QString fileNm=fileSaveDlg->selectedFileName; | 812 | QString fileNm=fileSaveDlg->selectedFileName; |
805 | // QString fileNm=srt; | 813 | |
814 | |||
806 | qDebug("saving filename "+fileNm); | 815 | qDebug("saving filename "+fileNm); |
807 | QFileInfo fi(fileNm); | 816 | QFileInfo fi(fileNm); |
808 | currentFileName=fi.fileName(); | 817 | currentFileName=fi.fileName(); |
809 | if(doc) { | 818 | if(doc) { |
810 | // QString file = doc->file(); | 819 | // QString file = doc->file(); |
811 | // doc->removeFiles(); | 820 | // doc->removeFiles(); |
812 | delete doc; | 821 | delete doc; |
813 | DocLnk nf; | 822 | DocLnk nf; |
814 | nf.setType("text/plain"); | 823 | nf.setType("text/plain"); |
815 | nf.setFile( fileNm); | 824 | nf.setFile( fileNm); |
816 | doc = new DocLnk(nf); | 825 | doc = new DocLnk(nf); |
817 | // editor->setText(rt); | 826 | // editor->setText(rt); |
818 | // qDebug("openFile doclnk "+currentFileName); | 827 | // qDebug("openFile doclnk "+currentFileName); |
819 | doc->setName( currentFileName); | 828 | doc->setName( currentFileName); |
820 | updateCaption( currentFileName); | 829 | updateCaption( currentFileName); |
821 | 830 | ||
822 | FileManager fm; | 831 | FileManager fm; |
823 | if ( !fm.saveFile( *doc, rt ) ) { | 832 | if ( !fm.saveFile( *doc, rt ) ) { |
824 | return false; | 833 | return false; |
825 | } | 834 | } |
826 | if( fileSaveDlg->filePermCheck->isChecked() ) { | 835 | if( fileSaveDlg->filePermCheck->isChecked() ) { |
827 | filePermissions *filePerm; | 836 | filePermissions *filePerm; |
828 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); | 837 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); |
829 | filePerm->exec(); | 838 | filePerm->exec(); |
830 | 839 | ||
831 | if( filePerm) | 840 | if( filePerm) |
832 | delete filePerm; | 841 | delete filePerm; |
833 | } | 842 | } |
834 | } | 843 | } |
835 | } | 844 | } |
836 | editor->setEdited(TRUE); | 845 | editor->setEdited(TRUE); |
837 | edited1=FALSE; | 846 | edited1=FALSE; |
838 | edited=TRUE; | 847 | edited=TRUE; |
839 | if(caption().left(1)=="*") | 848 | if(caption().left(1)=="*") |
840 | setCaption(caption().right(caption().length()-1)); | 849 | setCaption(caption().right(caption().length()-1)); |
841 | 850 | ||
842 | if(fileSaveDlg) | 851 | if(fileSaveDlg) |
843 | delete fileSaveDlg; | 852 | delete fileSaveDlg; |
844 | return true; | 853 | return true; |
845 | } //end saveAs | 854 | } //end saveAs |
846 | 855 | ||
847 | void TextEdit::clear() | 856 | void TextEdit::clear() |
848 | { | 857 | { |
849 | delete doc; | 858 | delete doc; |
850 | doc = 0; | 859 | doc = 0; |
851 | editor->clear(); | 860 | editor->clear(); |
852 | } | 861 | } |
853 | 862 | ||
854 | void TextEdit::updateCaption( const QString &name ) | 863 | void TextEdit::updateCaption( const QString &name ) |
855 | { | 864 | { |
856 | if ( !doc ) | 865 | if ( !doc ) |
857 | setCaption( tr("Text Editor") ); | 866 | setCaption( tr("Text Editor") ); |
858 | else { | 867 | else { |
859 | QString s = name; | 868 | QString s = name; |
860 | if ( s.isNull() ) | 869 | if ( s.isNull() ) |
861 | s = doc->name(); | 870 | s = doc->name(); |
862 | if ( s.isEmpty() ) { | 871 | if ( s.isEmpty() ) { |
863 | s = tr( "Unnamed" ); | 872 | s = tr( "Unnamed" ); |
864 | currentFileName=s; | 873 | currentFileName=s; |
865 | } | 874 | } |
866 | if(s.left(1) == "/") | 875 | if(s.left(1) == "/") |
867 | s = s.right(s.length()-1); | 876 | s = s.right(s.length()-1); |
868 | setCaption( s + " - " + tr("Text Editor") ); | 877 | setCaption( s + " - " + tr("Text Editor") ); |
869 | } | 878 | } |
870 | } | 879 | } |
871 | 880 | ||
872 | void TextEdit::setDocument(const QString& fileref) | 881 | void TextEdit::setDocument(const QString& fileref) |
873 | { | 882 | { |
874 | bFromDocView = TRUE; | 883 | bFromDocView = TRUE; |
875 | openFile(fileref); | 884 | openFile(fileref); |
876 | editor->setEdited(TRUE); | 885 | editor->setEdited(TRUE); |
877 | edited1=FALSE; | 886 | edited1=FALSE; |
878 | edited=TRUE; | 887 | edited=TRUE; |
879 | doSearchBar(); | 888 | doSearchBar(); |
880 | } | 889 | } |
881 | 890 | ||
882 | void TextEdit::closeEvent( QCloseEvent *e ) | 891 | void TextEdit::closeEvent( QCloseEvent *e ) |
883 | { | 892 | { |
884 | bFromDocView = FALSE; | 893 | bFromDocView = FALSE; |
885 | e->accept(); | 894 | e->accept(); |
886 | } | 895 | } |
887 | 896 | ||
888 | void TextEdit::accept() | 897 | void TextEdit::accept() |
889 | { | 898 | { |
890 | //if(caption() !="Unnamed") | 899 | //if(caption() !="Unnamed") |
891 | if(edited1) | 900 | if(edited1) |
892 | saveAs(); | 901 | saveAs(); |
893 | exit(0); | 902 | exit(0); |
894 | 903 | ||
895 | } | 904 | } |
896 | 905 | ||
897 | void TextEdit::changeFont() { | 906 | void TextEdit::changeFont() { |
898 | FontDatabase fdb; | 907 | FontDatabase fdb; |
899 | QFont defaultFont=editor->font(); | 908 | QFont defaultFont=editor->font(); |
900 | QFontInfo fontInfo(defaultFont); | 909 | QFontInfo fontInfo(defaultFont); |
901 | Config cfg("TextEdit"); | 910 | Config cfg("TextEdit"); |
902 | cfg.setGroup("Font"); | 911 | cfg.setGroup("Font"); |
903 | QString family = cfg.readEntry("Family", fontInfo.family()); | 912 | QString family = cfg.readEntry("Family", fontInfo.family()); |
904 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 913 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
905 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 914 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
906 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 915 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
907 | 916 | ||
908 | defaultFont = fdb.font(family,style,i_size,charSet); | 917 | defaultFont = fdb.font(family,style,i_size,charSet); |
909 | 918 | ||
910 | FontDialog *fontDlg; | 919 | FontDialog *fontDlg; |
911 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); | 920 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); |
912 | 921 | ||
913 | fontDlg->exec(); | 922 | fontDlg->exec(); |
914 | 923 | ||
915 | QFont myFont=fontDlg->selectedFont; | 924 | QFont myFont=fontDlg->selectedFont; |
916 | editor->setFont( myFont); | 925 | editor->setFont( myFont); |
917 | delete fontDlg; | 926 | delete fontDlg; |
918 | 927 | ||
919 | } | 928 | } |
920 | 929 | ||
921 | void TextEdit::editDelete() | 930 | void TextEdit::editDelete() |
922 | { | 931 | { |
923 | 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) ) { | 932 | 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) ) { |
924 | case 0: | 933 | case 0: |
925 | if(doc) { | 934 | if(doc) { |
926 | doc->removeFiles(); | 935 | doc->removeFiles(); |
927 | clear(); | 936 | clear(); |
928 | setCaption( tr("Text Editor") ); | 937 | setCaption( tr("Text Editor") ); |
929 | } | 938 | } |
930 | break; | 939 | break; |
931 | case 1: | 940 | case 1: |
932 | // exit | 941 | // exit |
933 | break; | 942 | break; |
934 | }; | 943 | }; |
935 | } | 944 | } |
936 | 945 | ||