-rw-r--r-- | core/apps/textedit/textedit.cpp | 158 |
1 files changed, 67 insertions, 91 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 107695a..d61da2a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -354,26 +354,32 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
354 | 354 | ||
355 | font->insertSeparator(); | 355 | font->insertSeparator(); |
356 | 356 | ||
357 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 357 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
358 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 358 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
359 | nStart->setToggleAction(TRUE); | 359 | nStart->setToggleAction(TRUE); |
360 | nStart->addTo( font ); | 360 | nStart->addTo( font ); |
361 | 361 | ||
362 | nAdvanced = new QAction( tr("Advanced features"), QString::null, 0, this, 0 ); | 362 | nAdvanced = new QAction( tr("Advanced features"), QString::null, 0, this, 0 ); |
363 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doAdvanced(bool) ) ); | 363 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doAdvanced(bool) ) ); |
364 | nAdvanced->setToggleAction(TRUE); | 364 | nAdvanced->setToggleAction(TRUE); |
365 | nAdvanced->addTo( font ); | 365 | nAdvanced->addTo( font ); |
366 | if(cfg.readBoolEntry("AdvancedFeatures")) | 366 | |
367 | nAdvanced->setOn(TRUE); | 367 | if(cfg.readBoolEntry("AdvancedFeatures")) { |
368 | qDebug("using advanced features"); | ||
369 | useAdvancedFeatures = true; | ||
370 | nAdvanced->setOn(TRUE); | ||
371 | } else | ||
372 | useAdvancedFeatures = false; | ||
373 | |||
368 | font->insertSeparator(); | 374 | font->insertSeparator(); |
369 | 375 | ||
370 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 376 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
371 | 377 | ||
372 | mb->insertItem( tr( "File" ), file ); | 378 | mb->insertItem( tr( "File" ), file ); |
373 | mb->insertItem( tr( "Edit" ), edit ); | 379 | mb->insertItem( tr( "Edit" ), edit ); |
374 | mb->insertItem( tr( "View" ), font ); | 380 | mb->insertItem( tr( "View" ), font ); |
375 | 381 | ||
376 | searchBar = new QPEToolBar(this); | 382 | searchBar = new QPEToolBar(this); |
377 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 383 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
378 | 384 | ||
379 | searchBar->setHorizontalStretchable( TRUE ); | 385 | searchBar->setHorizontalStretchable( TRUE ); |
@@ -425,230 +431,214 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
425 | 431 | ||
426 | cfg.setGroup("View"); | 432 | cfg.setGroup("View"); |
427 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 433 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { |
428 | nStart->setOn(TRUE); | 434 | nStart->setOn(TRUE); |
429 | fileNew(); | 435 | fileNew(); |
430 | } else { | 436 | } else { |
431 | fileOpen(); | 437 | fileOpen(); |
432 | } | 438 | } |
433 | 439 | ||
434 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 440 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
435 | } | 441 | } |
436 | 442 | ||
437 | void TextEdit::cleanUp() | 443 | TextEdit::~TextEdit() { |
438 | { | 444 | } |
445 | |||
446 | void TextEdit::cleanUp() { | ||
439 | // save(); | 447 | // save(); |
440 | Config cfg("TextEdit"); | 448 | Config cfg("TextEdit"); |
441 | cfg.setGroup("View"); | 449 | cfg.setGroup("View"); |
442 | QFont f = editor->font(); | 450 | QFont f = editor->font(); |
443 | cfg.writeEntry("FontSize",f.pointSize()); | 451 | cfg.writeEntry("FontSize",f.pointSize()); |
444 | cfg.writeEntry("Bold",f.bold()); | 452 | cfg.writeEntry("Bold",f.bold()); |
445 | cfg.writeEntry("Italic",f.italic()); | 453 | cfg.writeEntry("Italic",f.italic()); |
446 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 454 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
447 | cfg.writeEntry( "FileView", viewSelection ); | 455 | cfg.writeEntry( "FileView", viewSelection ); |
448 | |||
449 | } | 456 | } |
450 | 457 | ||
451 | TextEdit::~TextEdit() | 458 | |
452 | { | 459 | void TextEdit::accept() { |
460 | if(edited1) | ||
461 | saveAs(); | ||
462 | exit(0); | ||
453 | } | 463 | } |
454 | 464 | ||
455 | void TextEdit::zoomIn() | 465 | void TextEdit::zoomIn() { |
456 | { | ||
457 | setFontSize(editor->font().pointSize()+1,FALSE); | 466 | setFontSize(editor->font().pointSize()+1,FALSE); |
458 | } | 467 | } |
459 | 468 | ||
460 | void TextEdit::zoomOut() | 469 | void TextEdit::zoomOut() { |
461 | { | ||
462 | setFontSize(editor->font().pointSize()-1,TRUE); | 470 | setFontSize(editor->font().pointSize()-1,TRUE); |
463 | } | 471 | } |
464 | 472 | ||
465 | 473 | ||
466 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 474 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
467 | { | ||
468 | int s=10; | 475 | int s=10; |
469 | for (int i=0; i<nfontsizes; i++) { | 476 | for (int i=0; i<nfontsizes; i++) { |
470 | if ( fontsize[i] == sz ) { | 477 | if ( fontsize[i] == sz ) { |
471 | s = sz; | 478 | s = sz; |
472 | break; | 479 | break; |
473 | } else if ( round_down_not_up ) { | 480 | } else if ( round_down_not_up ) { |
474 | if ( fontsize[i] < sz ) | 481 | if ( fontsize[i] < sz ) |
475 | s = fontsize[i]; | 482 | s = fontsize[i]; |
476 | } else { | 483 | } else { |
477 | if ( fontsize[i] > sz ) { | 484 | if ( fontsize[i] > sz ) { |
478 | s = fontsize[i]; | 485 | s = fontsize[i]; |
479 | break; | 486 | break; |
480 | } | 487 | } |
481 | } | 488 | } |
482 | } | 489 | } |
483 | 490 | ||
484 | QFont f = editor->font(); | 491 | QFont f = editor->font(); |
485 | f.setPointSize(s); | 492 | f.setPointSize(s); |
486 | editor->setFont(f); | 493 | editor->setFont(f); |
487 | 494 | ||
488 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 495 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
489 | zout->setEnabled(s != fontsize[0]); | 496 | zout->setEnabled(s != fontsize[0]); |
490 | } | 497 | } |
491 | 498 | ||
492 | void TextEdit::setBold(bool y) | 499 | void TextEdit::setBold(bool y) { |
493 | { | ||
494 | QFont f = editor->font(); | 500 | QFont f = editor->font(); |
495 | f.setBold(y); | 501 | f.setBold(y); |
496 | editor->setFont(f); | 502 | editor->setFont(f); |
497 | } | 503 | } |
498 | 504 | ||
499 | void TextEdit::setItalic(bool y) | 505 | void TextEdit::setItalic(bool y) { |
500 | { | ||
501 | QFont f = editor->font(); | 506 | QFont f = editor->font(); |
502 | f.setItalic(y); | 507 | f.setItalic(y); |
503 | editor->setFont(f); | 508 | editor->setFont(f); |
504 | } | 509 | } |
505 | 510 | ||
506 | void TextEdit::setWordWrap(bool y) | 511 | void TextEdit::setWordWrap(bool y) { |
507 | { | ||
508 | bool state = editor->edited(); | 512 | bool state = editor->edited(); |
509 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 513 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
510 | editor->setEdited( state ); | 514 | editor->setEdited( state ); |
511 | } | 515 | } |
512 | 516 | ||
513 | void TextEdit::fileNew() | 517 | void TextEdit::fileNew() { |
514 | { | ||
515 | // if( !bFromDocView ) { | 518 | // if( !bFromDocView ) { |
516 | // saveAs(); | 519 | // saveAs(); |
517 | // } | 520 | // } |
518 | newFile(DocLnk()); | 521 | newFile(DocLnk()); |
519 | } | 522 | } |
520 | 523 | ||
521 | void TextEdit::fileOpen() | 524 | void TextEdit::fileOpen() { |
522 | { | ||
523 | Config cfg("TextEdit"); | 525 | Config cfg("TextEdit"); |
524 | cfg.setGroup("View"); | 526 | cfg.setGroup("View"); |
525 | // bool b=FALSE; | 527 | // bool b=FALSE; |
526 | 528 | ||
527 | QMap<QString, QStringList> map; | 529 | QMap<QString, QStringList> map; |
528 | map.insert(tr("All"), QStringList() ); | 530 | map.insert(tr("All"), QStringList() ); |
529 | QStringList text; | 531 | QStringList text; |
530 | text << "text/*"; | 532 | text << "text/*"; |
531 | map.insert(tr("Text"), text ); | 533 | map.insert(tr("Text"), text ); |
532 | text << "*"; | 534 | text << "*"; |
533 | map.insert(tr("All"), text ); | 535 | map.insert(tr("All"), text ); |
534 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); | 536 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); |
535 | if(!str.isEmpty() ) | 537 | if(!str.isEmpty() ) |
536 | openFile( str ); | 538 | openFile( str ); |
537 | 539 | ||
538 | } | 540 | } |
539 | 541 | ||
540 | void TextEdit::doSearchBar() | 542 | void TextEdit::doSearchBar() { |
541 | { | ||
542 | Config cfg("TextEdit"); | 543 | Config cfg("TextEdit"); |
543 | cfg.setGroup("View"); | 544 | cfg.setGroup("View"); |
544 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 545 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
545 | searchBar->hide(); | 546 | searchBar->hide(); |
546 | } | 547 | } |
547 | 548 | ||
548 | #if 0 | 549 | #if 0 |
549 | void TextEdit::slotFind() | 550 | void TextEdit::slotFind() { |
550 | { | ||
551 | FindDialog frmFind( tr("Text Editor"), this ); | 551 | FindDialog frmFind( tr("Text Editor"), this ); |
552 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 552 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
553 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 553 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
554 | 554 | ||
555 | //case sensitive, backwards, [category] | 555 | //case sensitive, backwards, [category] |
556 | 556 | ||
557 | connect( editor, SIGNAL(notFound()), | 557 | connect( editor, SIGNAL(notFound()), |
558 | &frmFind, SLOT(slotNotFound()) ); | 558 | &frmFind, SLOT(slotNotFound()) ); |
559 | connect( editor, SIGNAL(searchWrapped()), | 559 | connect( editor, SIGNAL(searchWrapped()), |
560 | &frmFind, SLOT(slotWrapAround()) ); | 560 | &frmFind, SLOT(slotWrapAround()) ); |
561 | 561 | ||
562 | frmFind.exec(); | 562 | frmFind.exec(); |
563 | 563 | ||
564 | 564 | ||
565 | } | 565 | } |
566 | #endif | 566 | #endif |
567 | 567 | ||
568 | void TextEdit::fileRevert() | 568 | void TextEdit::fileRevert() { |
569 | { | ||
570 | clear(); | 569 | clear(); |
571 | fileOpen(); | 570 | fileOpen(); |
572 | } | 571 | } |
573 | 572 | ||
574 | void TextEdit::editCut() | 573 | void TextEdit::editCut() { |
575 | { | ||
576 | #ifndef QT_NO_CLIPBOARD | 574 | #ifndef QT_NO_CLIPBOARD |
577 | editor->cut(); | 575 | editor->cut(); |
578 | #endif | 576 | #endif |
579 | } | 577 | } |
580 | 578 | ||
581 | void TextEdit::editCopy() | 579 | void TextEdit::editCopy() { |
582 | { | ||
583 | #ifndef QT_NO_CLIPBOARD | 580 | #ifndef QT_NO_CLIPBOARD |
584 | editor->copy(); | 581 | editor->copy(); |
585 | #endif | 582 | #endif |
586 | } | 583 | } |
587 | 584 | ||
588 | void TextEdit::editPaste() | 585 | void TextEdit::editPaste() { |
589 | { | ||
590 | #ifndef QT_NO_CLIPBOARD | 586 | #ifndef QT_NO_CLIPBOARD |
591 | editor->paste(); | 587 | editor->paste(); |
592 | #endif | 588 | #endif |
593 | } | 589 | } |
594 | 590 | ||
595 | void TextEdit::editFind() | 591 | void TextEdit::editFind() { |
596 | { | ||
597 | searchBar->show(); | 592 | searchBar->show(); |
598 | searchVisible = TRUE; | 593 | searchVisible = TRUE; |
599 | searchEdit->setFocus(); | 594 | searchEdit->setFocus(); |
600 | Config cfg("TextEdit"); | 595 | Config cfg("TextEdit"); |
601 | cfg.setGroup("View"); | 596 | cfg.setGroup("View"); |
602 | cfg.writeEntry("SearchBar","Opened"); | 597 | cfg.writeEntry("SearchBar","Opened"); |
603 | 598 | ||
604 | } | 599 | } |
605 | 600 | ||
606 | void TextEdit::findNext() | 601 | void TextEdit::findNext() { |
607 | { | ||
608 | editor->find( searchEdit->text(), FALSE, FALSE ); | 602 | editor->find( searchEdit->text(), FALSE, FALSE ); |
609 | 603 | ||
610 | } | 604 | } |
611 | 605 | ||
612 | void TextEdit::findClose() | 606 | void TextEdit::findClose() { |
613 | { | ||
614 | searchVisible = FALSE; | 607 | searchVisible = FALSE; |
615 | searchBar->hide(); | 608 | searchBar->hide(); |
616 | Config cfg("TextEdit"); | 609 | Config cfg("TextEdit"); |
617 | cfg.setGroup("View"); | 610 | cfg.setGroup("View"); |
618 | cfg.writeEntry("SearchBar","Closed"); | 611 | cfg.writeEntry("SearchBar","Closed"); |
619 | cfg.write(); | 612 | cfg.write(); |
620 | } | 613 | } |
621 | 614 | ||
622 | void TextEdit::search() | 615 | void TextEdit::search() { |
623 | { | ||
624 | editor->find( searchEdit->text(), FALSE, FALSE ); | 616 | editor->find( searchEdit->text(), FALSE, FALSE ); |
625 | } | 617 | } |
626 | 618 | ||
627 | void TextEdit::newFile( const DocLnk &f ) | 619 | void TextEdit::newFile( const DocLnk &f ) { |
628 | { | ||
629 | DocLnk nf = f; | 620 | DocLnk nf = f; |
630 | nf.setType("text/plain"); | 621 | nf.setType("text/plain"); |
631 | clear(); | 622 | clear(); |
632 | setWState (WState_Reserved1 ); | 623 | setWState (WState_Reserved1 ); |
633 | editor->setFocus(); | 624 | editor->setFocus(); |
634 | doc = new DocLnk(nf); | 625 | doc = new DocLnk(nf); |
635 | currentFileName = "Unnamed"; | 626 | currentFileName = "Unnamed"; |
636 | qDebug("newFile "+currentFileName); | 627 | qDebug("newFile "+currentFileName); |
637 | updateCaption( currentFileName); | 628 | updateCaption( currentFileName); |
638 | // editor->setEdited( FALSE); | 629 | // editor->setEdited( FALSE); |
639 | } | 630 | } |
640 | 631 | ||
641 | void TextEdit::openFile( const QString &f ) | 632 | void TextEdit::openFile( const QString &f ) { |
642 | { | ||
643 | qDebug("filename is "+ f); | 633 | qDebug("filename is "+ f); |
644 | QString filer; | 634 | QString filer; |
645 | // bFromDocView = TRUE; | 635 | // bFromDocView = TRUE; |
646 | if(f.find(".desktop",0,TRUE) != -1 && useAdvancedFeatures) { | 636 | if(f.find(".desktop",0,TRUE) != -1 && useAdvancedFeatures) { |
647 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 637 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
648 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), | 638 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), |
649 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 639 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
650 | case 0: | 640 | case 0: |
651 | filer = f; | 641 | filer = f; |
652 | break; | 642 | break; |
653 | case 1: | 643 | case 1: |
654 | DocLnk sf(f); | 644 | DocLnk sf(f); |
@@ -669,66 +659,63 @@ void TextEdit::openFile( const QString &f ) | |||
669 | qDebug("openFile string "+currentFileName); | 659 | qDebug("openFile string "+currentFileName); |
670 | 660 | ||
671 | openFile(nf); | 661 | openFile(nf); |
672 | showEditTools(); | 662 | showEditTools(); |
673 | // Show filename in caption | 663 | // Show filename in caption |
674 | QString name = filer; | 664 | QString name = filer; |
675 | int sep = name.findRev( '/' ); | 665 | int sep = name.findRev( '/' ); |
676 | if ( sep > 0 ) | 666 | if ( sep > 0 ) |
677 | name = name.mid( sep+1 ); | 667 | name = name.mid( sep+1 ); |
678 | updateCaption( name ); | 668 | updateCaption( name ); |
679 | } | 669 | } |
680 | 670 | ||
681 | void TextEdit::openFile( const DocLnk &f ) | 671 | void TextEdit::openFile( const DocLnk &f ) { |
682 | { | ||
683 | // clear(); | 672 | // clear(); |
684 | // bFromDocView = TRUE; | 673 | // bFromDocView = TRUE; |
685 | FileManager fm; | 674 | FileManager fm; |
686 | QString txt; | 675 | QString txt; |
687 | currentFileName=f.file(); | 676 | currentFileName=f.file(); |
688 | qDebug("openFile doclnk " + currentFileName); | 677 | qDebug("openFile doclnk " + currentFileName); |
689 | if ( !fm.loadFile( f, txt ) ) { | 678 | if ( !fm.loadFile( f, txt ) ) { |
690 | // ####### could be a new file | 679 | // ####### could be a new file |
691 | qDebug( "Cannot open file" ); | 680 | qDebug( "Cannot open file" ); |
692 | } | 681 | } |
693 | // fileNew(); | 682 | // fileNew(); |
694 | if ( doc ) | 683 | if ( doc ) |
695 | delete doc; | 684 | delete doc; |
696 | doc = new DocLnk(f); | 685 | doc = new DocLnk(f); |
697 | editor->setText(txt); | 686 | editor->setText(txt); |
698 | editor->setEdited( FALSE); | 687 | editor->setEdited( FALSE); |
699 | edited1=FALSE; | 688 | edited1=FALSE; |
700 | edited=FALSE; | 689 | edited=FALSE; |
701 | 690 | ||
702 | doc->setName(currentFileName); | 691 | doc->setName(currentFileName); |
703 | updateCaption(); | 692 | updateCaption(); |
704 | } | 693 | } |
705 | 694 | ||
706 | void TextEdit::showEditTools() | 695 | void TextEdit::showEditTools() { |
707 | { | ||
708 | // if ( !doc ) | 696 | // if ( !doc ) |
709 | // close(); | 697 | // close(); |
710 | // clear(); | 698 | // clear(); |
711 | menu->show(); | 699 | menu->show(); |
712 | editBar->show(); | 700 | editBar->show(); |
713 | if ( searchVisible ) | 701 | if ( searchVisible ) |
714 | searchBar->show(); | 702 | searchBar->show(); |
715 | // updateCaption(); | 703 | // updateCaption(); |
716 | setWState (WState_Reserved1 ); | 704 | setWState (WState_Reserved1 ); |
717 | } | 705 | } |
718 | 706 | ||
719 | /*! | 707 | /*! |
720 | unprompted save */ | 708 | unprompted save */ |
721 | bool TextEdit::save() | 709 | bool TextEdit::save() { |
722 | { | ||
723 | QString file = doc->file(); | 710 | QString file = doc->file(); |
724 | qDebug("saver file "+file); | 711 | qDebug("saver file "+file); |
725 | QString name= doc->name(); | 712 | QString name= doc->name(); |
726 | qDebug("File named "+name); | 713 | qDebug("File named "+name); |
727 | QString rt = editor->text(); | 714 | QString rt = editor->text(); |
728 | if( !rt.isEmpty() ) { | 715 | if( !rt.isEmpty() ) { |
729 | if(name.isEmpty()) { | 716 | if(name.isEmpty()) { |
730 | saveAs(); | 717 | saveAs(); |
731 | } else { | 718 | } else { |
732 | currentFileName= name ; | 719 | currentFileName= name ; |
733 | qDebug("saveFile "+currentFileName); | 720 | qDebug("saveFile "+currentFileName); |
734 | 721 | ||
@@ -762,44 +749,43 @@ bool TextEdit::save() | |||
762 | setCaption(caption().right(caption().length()-1)); | 749 | setCaption(caption().right(caption().length()-1)); |
763 | 750 | ||
764 | 751 | ||
765 | chmod( file.latin1(), mode); | 752 | chmod( file.latin1(), mode); |
766 | } | 753 | } |
767 | return true; | 754 | return true; |
768 | } | 755 | } |
769 | return false; | 756 | return false; |
770 | } | 757 | } |
771 | 758 | ||
772 | /*! | 759 | /*! |
773 | prompted save */ | 760 | prompted save */ |
774 | bool TextEdit::saveAs() | 761 | bool TextEdit::saveAs() { |
775 | { | 762 | qDebug("saveAsFile "+currentFileName); |
776 | // qDebug("saveAsFile "+currentFileName); | 763 | // case of nothing to save... |
777 | // case of nothing to save... | 764 | if ( !doc ) { |
778 | if ( !doc )//|| !bFromDocView) | 765 | //|| !bFromDocView) |
779 | { | 766 | qDebug("no doc"); |
780 | qDebug("no doc"); | 767 | return true; |
781 | return true; | 768 | } |
782 | } | ||
783 | if ( !editor->edited() ) { | 769 | if ( !editor->edited() ) { |
784 | delete doc; | 770 | delete doc; |
785 | doc = 0; | 771 | doc = 0; |
786 | return true; | 772 | return true; |
787 | } | 773 | } |
788 | 774 | ||
789 | QString rt = editor->text(); | 775 | QString rt = editor->text(); |
790 | qDebug(currentFileName); | 776 | qDebug(currentFileName); |
791 | 777 | ||
792 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { | 778 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { |
793 | qDebug("do silly TT filename thing"); | 779 | // qDebug("do silly TT filename thing"); |
794 | if ( doc->name().isEmpty() ) { | 780 | if ( doc->name().isEmpty() ) { |
795 | QString pt = rt.simplifyWhiteSpace(); | 781 | QString pt = rt.simplifyWhiteSpace(); |
796 | int i = pt.find( ' ' ); | 782 | int i = pt.find( ' ' ); |
797 | QString docname = pt; | 783 | QString docname = pt; |
798 | if ( i > 0 ) | 784 | if ( i > 0 ) |
799 | docname = pt.left( i ); | 785 | docname = pt.left( i ); |
800 | // remove "." at the beginning | 786 | // remove "." at the beginning |
801 | while( docname.startsWith( "." ) ) | 787 | while( docname.startsWith( "." ) ) |
802 | docname = docname.mid( 1 ); | 788 | docname = docname.mid( 1 ); |
803 | docname.replace( QRegExp("/"), "_" ); | 789 | docname.replace( QRegExp("/"), "_" ); |
804 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 790 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
805 | if ( docname.length() > 40 ) | 791 | if ( docname.length() > 40 ) |
@@ -809,25 +795,27 @@ bool TextEdit::saveAs() | |||
809 | doc->setName(docname); | 795 | doc->setName(docname); |
810 | currentFileName=docname; | 796 | currentFileName=docname; |
811 | } | 797 | } |
812 | } | 798 | } |
813 | 799 | ||
814 | QMap<QString, QStringList> map; | 800 | QMap<QString, QStringList> map; |
815 | map.insert(tr("All"), QStringList() ); | 801 | map.insert(tr("All"), QStringList() ); |
816 | QStringList text; | 802 | QStringList text; |
817 | text << "text/*"; | 803 | text << "text/*"; |
818 | map.insert(tr("Text"), text ); | 804 | map.insert(tr("Text"), text ); |
819 | text << "*"; | 805 | text << "*"; |
820 | map.insert(tr("All"), text ); | 806 | map.insert(tr("All"), text ); |
807 | |||
821 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); | 808 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); |
809 | |||
822 | if(!str.isEmpty() ) { | 810 | if(!str.isEmpty() ) { |
823 | QString fileNm=str; | 811 | QString fileNm=str; |
824 | 812 | ||
825 | qDebug("saving filename "+fileNm); | 813 | qDebug("saving filename "+fileNm); |
826 | QFileInfo fi(fileNm); | 814 | QFileInfo fi(fileNm); |
827 | currentFileName=fi.fileName(); | 815 | currentFileName=fi.fileName(); |
828 | if(doc) { | 816 | if(doc) { |
829 | // QString file = doc->file(); | 817 | // QString file = doc->file(); |
830 | // doc->removeFiles(); | 818 | // doc->removeFiles(); |
831 | delete doc; | 819 | delete doc; |
832 | DocLnk nf; | 820 | DocLnk nf; |
833 | nf.setType("text/plain"); | 821 | nf.setType("text/plain"); |
@@ -839,114 +827,102 @@ bool TextEdit::saveAs() | |||
839 | updateCaption( currentFileName); | 827 | updateCaption( currentFileName); |
840 | 828 | ||
841 | FileManager fm; | 829 | FileManager fm; |
842 | if ( !fm.saveFile( *doc, rt ) ) { | 830 | if ( !fm.saveFile( *doc, rt ) ) { |
843 | return false; | 831 | return false; |
844 | } | 832 | } |
845 | 833 | ||
846 | if( useAdvancedFeatures ) { | 834 | if( useAdvancedFeatures ) { |
847 | filePermissions *filePerm; | 835 | filePermissions *filePerm; |
848 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); | 836 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); |
849 | filePerm->exec(); | 837 | filePerm->exec(); |
850 | 838 | ||
851 | if( filePerm) | 839 | if( filePerm) |
852 | delete filePerm; | 840 | delete filePerm; |
853 | } | 841 | } |
854 | } | 842 | } |
843 | editor->setEdited( false); | ||
844 | edited1 = false; | ||
845 | edited = false; | ||
846 | if(caption().left(1)=="*") | ||
847 | setCaption(caption().right(caption().length()-1)); | ||
848 | |||
849 | return true; | ||
855 | } | 850 | } |
856 | editor->setEdited(TRUE); | 851 | qDebug("returning false"); |
857 | edited1=FALSE; | 852 | return false; |
858 | edited=TRUE; | ||
859 | if(caption().left(1)=="*") | ||
860 | setCaption(caption().right(caption().length()-1)); | ||
861 | |||
862 | return true; | ||
863 | } //end saveAs | 853 | } //end saveAs |
864 | 854 | ||
865 | void TextEdit::clear() | 855 | void TextEdit::clear() { |
866 | { | ||
867 | delete doc; | 856 | delete doc; |
868 | doc = 0; | 857 | doc = 0; |
869 | editor->clear(); | 858 | editor->clear(); |
870 | } | 859 | } |
871 | 860 | ||
872 | void TextEdit::updateCaption( const QString &name ) | 861 | void TextEdit::updateCaption( const QString &name ) { |
873 | { | ||
874 | if ( !doc ) | 862 | if ( !doc ) |
875 | setCaption( tr("Text Editor") ); | 863 | setCaption( tr("Text Editor") ); |
876 | else { | 864 | else { |
877 | QString s = name; | 865 | QString s = name; |
878 | if ( s.isNull() ) | 866 | if ( s.isNull() ) |
879 | s = doc->name(); | 867 | s = doc->name(); |
880 | if ( s.isEmpty() ) { | 868 | if ( s.isEmpty() ) { |
881 | s = tr( "Unnamed" ); | 869 | s = tr( "Unnamed" ); |
882 | currentFileName=s; | 870 | currentFileName=s; |
883 | } | 871 | } |
884 | if(s.left(1) == "/") | 872 | if(s.left(1) == "/") |
885 | s = s.right(s.length()-1); | 873 | s = s.right(s.length()-1); |
886 | setCaption( s + " - " + tr("Text Editor") ); | 874 | setCaption( s + " - " + tr("Text Editor") ); |
887 | } | 875 | } |
888 | } | 876 | } |
889 | 877 | ||
890 | void TextEdit::setDocument(const QString& fileref) | 878 | void TextEdit::setDocument(const QString& fileref) { |
891 | { | ||
892 | bFromDocView = TRUE; | 879 | bFromDocView = TRUE; |
893 | openFile(fileref); | 880 | openFile(fileref); |
894 | editor->setEdited(TRUE); | 881 | editor->setEdited(TRUE); |
895 | edited1=FALSE; | 882 | edited1=FALSE; |
896 | edited=TRUE; | 883 | edited=TRUE; |
897 | doSearchBar(); | 884 | doSearchBar(); |
898 | } | 885 | } |
899 | 886 | ||
900 | void TextEdit::closeEvent( QCloseEvent *e ) | 887 | void TextEdit::closeEvent( QCloseEvent *e ) { |
901 | { | ||
902 | bFromDocView = FALSE; | 888 | bFromDocView = FALSE; |
903 | e->accept(); | 889 | e->accept(); |
904 | } | 890 | } |
905 | 891 | ||
906 | void TextEdit::accept() | ||
907 | { | ||
908 | //if(caption() !="Unnamed") | ||
909 | if(edited1) | ||
910 | saveAs(); | ||
911 | exit(0); | ||
912 | |||
913 | } | ||
914 | |||
915 | void TextEdit::changeFont() { | 892 | void TextEdit::changeFont() { |
916 | FontDatabase fdb; | 893 | FontDatabase fdb; |
917 | QFont defaultFont=editor->font(); | 894 | QFont defaultFont=editor->font(); |
918 | QFontInfo fontInfo(defaultFont); | 895 | QFontInfo fontInfo(defaultFont); |
919 | Config cfg("TextEdit"); | 896 | Config cfg("TextEdit"); |
920 | cfg.setGroup("Font"); | 897 | cfg.setGroup("Font"); |
921 | QString family = cfg.readEntry("Family", fontInfo.family()); | 898 | QString family = cfg.readEntry("Family", fontInfo.family()); |
922 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 899 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
923 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 900 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
924 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 901 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
925 | 902 | ||
926 | defaultFont = fdb.font(family,style,i_size,charSet); | 903 | defaultFont = fdb.font(family,style,i_size,charSet); |
927 | 904 | ||
928 | FontDialog *fontDlg; | 905 | FontDialog *fontDlg; |
929 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); | 906 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); |
930 | 907 | ||
931 | fontDlg->exec(); | 908 | fontDlg->exec(); |
932 | 909 | ||
933 | QFont myFont=fontDlg->selectedFont; | 910 | QFont myFont=fontDlg->selectedFont; |
934 | editor->setFont( myFont); | 911 | editor->setFont( myFont); |
935 | delete fontDlg; | 912 | delete fontDlg; |
936 | 913 | ||
937 | } | 914 | } |
938 | 915 | ||
939 | void TextEdit::editDelete() | 916 | void TextEdit::editDelete() { |
940 | { | ||
941 | 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) ) { | 917 | 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) ) { |
942 | case 0: | 918 | case 0: |
943 | if(doc) { | 919 | if(doc) { |
944 | doc->removeFiles(); | 920 | doc->removeFiles(); |
945 | clear(); | 921 | clear(); |
946 | setCaption( tr("Text Editor") ); | 922 | setCaption( tr("Text Editor") ); |
947 | } | 923 | } |
948 | break; | 924 | break; |
949 | case 1: | 925 | case 1: |
950 | // exit | 926 | // exit |
951 | break; | 927 | break; |
952 | }; | 928 | }; |