-rw-r--r-- | core/apps/textedit/textedit.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 086fdb6..1d0df6a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -394,807 +394,813 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
394 | 394 | ||
395 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 395 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
396 | wa-> setOn ( wrap ); | 396 | wa-> setOn ( wrap ); |
397 | setWordWrap ( wrap ); | 397 | setWordWrap ( wrap ); |
398 | 398 | ||
399 | ///////////////// | 399 | ///////////////// |
400 | if( qApp->argc() > 1) { | 400 | if( qApp->argc() > 1) { |
401 | currentFileName=qApp->argv()[1]; | 401 | currentFileName=qApp->argv()[1]; |
402 | 402 | ||
403 | QFileInfo fi(currentFileName); | 403 | QFileInfo fi(currentFileName); |
404 | 404 | ||
405 | if(fi.baseName().left(1) == "") { | 405 | if(fi.baseName().left(1) == "") { |
406 | openDotFile(currentFileName); | 406 | openDotFile(currentFileName); |
407 | } else { | 407 | } else { |
408 | openFile(currentFileName); | 408 | openFile(currentFileName); |
409 | } | 409 | } |
410 | } else { | 410 | } else { |
411 | edited1=false; | 411 | edited1=false; |
412 | openDotFile(""); | 412 | openDotFile(""); |
413 | } | 413 | } |
414 | 414 | ||
415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
416 | } | 416 | } |
417 | 417 | ||
418 | TextEdit::~TextEdit() { | 418 | TextEdit::~TextEdit() { |
419 | owarn << "textedit d'tor" << oendl; | 419 | owarn << "textedit d'tor" << oendl; |
420 | delete editor; | 420 | delete editor; |
421 | } | 421 | } |
422 | 422 | ||
423 | void TextEdit::closeEvent(QCloseEvent *) { | 423 | void TextEdit::closeEvent(QCloseEvent *) { |
424 | if( edited1 && promptExit) | 424 | if( edited1 && promptExit) |
425 | { | 425 | { |
426 | switch( savePrompt() ) | 426 | switch( savePrompt() ) |
427 | { | 427 | { |
428 | case 1: | 428 | case 1: |
429 | { | 429 | { |
430 | saveAs(); | 430 | saveAs(); |
431 | qApp->quit(); | 431 | qApp->quit(); |
432 | } | 432 | } |
433 | break; | 433 | break; |
434 | 434 | ||
435 | case 2: | 435 | case 2: |
436 | { | 436 | { |
437 | qApp->quit(); | 437 | qApp->quit(); |
438 | } | 438 | } |
439 | break; | 439 | break; |
440 | 440 | ||
441 | case -1: | 441 | case -1: |
442 | break; | 442 | break; |
443 | }; | 443 | }; |
444 | } | 444 | } |
445 | else | 445 | else |
446 | qApp->quit(); | 446 | qApp->quit(); |
447 | 447 | ||
448 | } | 448 | } |
449 | 449 | ||
450 | void TextEdit::cleanUp() { | 450 | void TextEdit::cleanUp() { |
451 | 451 | ||
452 | Config cfg ( "TextEdit" ); | 452 | Config cfg ( "TextEdit" ); |
453 | cfg. setGroup ( "Font" ); | 453 | cfg. setGroup ( "Font" ); |
454 | QFont f = editor->font(); | 454 | QFont f = editor->font(); |
455 | cfg.writeEntry ( "Family", f. family ( )); | 455 | cfg.writeEntry ( "Family", f. family ( )); |
456 | cfg.writeEntry ( "Size", f. pointSize ( )); | 456 | cfg.writeEntry ( "Size", f. pointSize ( )); |
457 | cfg.writeEntry ( "Weight", f. weight ( )); | 457 | cfg.writeEntry ( "Weight", f. weight ( )); |
458 | cfg.writeEntry ( "Italic", f. italic ( )); | 458 | cfg.writeEntry ( "Italic", f. italic ( )); |
459 | 459 | ||
460 | cfg.setGroup ( "View" ); | 460 | cfg.setGroup ( "View" ); |
461 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 461 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
462 | cfg.writeEntry ( "FileView", viewSelection ); | 462 | cfg.writeEntry ( "FileView", viewSelection ); |
463 | 463 | ||
464 | cfg.writeEntry ( "PromptExit", promptExit ); | 464 | cfg.writeEntry ( "PromptExit", promptExit ); |
465 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 465 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
466 | cfg.writeEntry ( "FilePermissions", filePerms ); | 466 | cfg.writeEntry ( "FilePermissions", filePerms ); |
467 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 467 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
468 | cfg.writeEntry ( "startNew", startWithNew ); | 468 | cfg.writeEntry ( "startNew", startWithNew ); |
469 | 469 | ||
470 | } | 470 | } |
471 | 471 | ||
472 | 472 | ||
473 | void TextEdit::accept() { | 473 | void TextEdit::accept() { |
474 | if( edited1) | 474 | if( edited1) |
475 | saveAs(); | 475 | saveAs(); |
476 | qApp->quit(); | 476 | qApp->quit(); |
477 | } | 477 | } |
478 | 478 | ||
479 | void TextEdit::zoomIn() { | 479 | void TextEdit::zoomIn() { |
480 | setFontSize(editor->font().pointSize()+1,false); | 480 | setFontSize(editor->font().pointSize()+1,false); |
481 | } | 481 | } |
482 | 482 | ||
483 | void TextEdit::zoomOut() { | 483 | void TextEdit::zoomOut() { |
484 | setFontSize(editor->font().pointSize()-1,true); | 484 | setFontSize(editor->font().pointSize()-1,true); |
485 | } | 485 | } |
486 | 486 | ||
487 | 487 | ||
488 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 488 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
489 | int s=10; | 489 | int s=10; |
490 | for (int i=0; i<nfontsizes; i++) { | 490 | for (int i=0; i<nfontsizes; i++) { |
491 | if ( fontsize[i] == sz ) { | 491 | if ( fontsize[i] == sz ) { |
492 | s = sz; | 492 | s = sz; |
493 | break; | 493 | break; |
494 | } else if ( round_down_not_up ) { | 494 | } else if ( round_down_not_up ) { |
495 | if ( fontsize[i] < sz ) | 495 | if ( fontsize[i] < sz ) |
496 | s = fontsize[i]; | 496 | s = fontsize[i]; |
497 | } else { | 497 | } else { |
498 | if ( fontsize[i] > sz ) { | 498 | if ( fontsize[i] > sz ) { |
499 | s = fontsize[i]; | 499 | s = fontsize[i]; |
500 | break; | 500 | break; |
501 | } | 501 | } |
502 | } | 502 | } |
503 | } | 503 | } |
504 | 504 | ||
505 | QFont f = editor->font(); | 505 | QFont f = editor->font(); |
506 | f.setPointSize(s); | 506 | f.setPointSize(s); |
507 | editor->setFont(f); | 507 | editor->setFont(f); |
508 | 508 | ||
509 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 509 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
510 | zout->setEnabled(s != fontsize[0]); | 510 | zout->setEnabled(s != fontsize[0]); |
511 | } | 511 | } |
512 | 512 | ||
513 | void TextEdit::setBold(bool y) { | 513 | void TextEdit::setBold(bool y) { |
514 | QFont f = editor->font(); | 514 | QFont f = editor->font(); |
515 | f.setBold(y); | 515 | f.setBold(y); |
516 | editor->setFont(f); | 516 | editor->setFont(f); |
517 | } | 517 | } |
518 | 518 | ||
519 | void TextEdit::setItalic(bool y) { | 519 | void TextEdit::setItalic(bool y) { |
520 | QFont f = editor->font(); | 520 | QFont f = editor->font(); |
521 | f.setItalic(y); | 521 | f.setItalic(y); |
522 | editor->setFont(f); | 522 | editor->setFont(f); |
523 | } | 523 | } |
524 | 524 | ||
525 | void TextEdit::setWordWrap(bool y) { | 525 | void TextEdit::setWordWrap(bool y) { |
526 | bool state = editor->edited(); | 526 | bool state = editor->edited(); |
527 | QString captionStr = caption(); | 527 | QString captionStr = caption(); |
528 | bool b1 = edited1; | 528 | bool b1 = edited1; |
529 | bool b2 = edited; | 529 | bool b2 = edited; |
530 | 530 | ||
531 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 531 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
532 | editor->setEdited( state ); | 532 | editor->setEdited( state ); |
533 | edited1=b1; | 533 | edited1=b1; |
534 | edited=b2; | 534 | edited=b2; |
535 | setCaption(captionStr); | 535 | setCaption(captionStr); |
536 | } | 536 | } |
537 | 537 | ||
538 | void TextEdit::setSearchBar(bool b) { | 538 | void TextEdit::setSearchBar(bool b) { |
539 | useSearchBar=b; | 539 | useSearchBar=b; |
540 | Config cfg("TextEdit"); | 540 | Config cfg("TextEdit"); |
541 | cfg.setGroup("View"); | 541 | cfg.setGroup("View"); |
542 | cfg.writeEntry ( "SearchBar", b ); | 542 | cfg.writeEntry ( "SearchBar", b ); |
543 | searchBarAction->setOn(b); | 543 | searchBarAction->setOn(b); |
544 | if(b) | 544 | if(b) |
545 | searchBar->show(); | 545 | searchBar->show(); |
546 | else | 546 | else |
547 | searchBar->hide(); | 547 | searchBar->hide(); |
548 | editor->setFocus(); | 548 | editor->setFocus(); |
549 | } | 549 | } |
550 | 550 | ||
551 | void TextEdit::fileNew() { | 551 | void TextEdit::fileNew() { |
552 | // if( !bFromDocView ) { | 552 | // if( !bFromDocView ) { |
553 | // saveAs(); | 553 | // saveAs(); |
554 | // } | 554 | // } |
555 | newFile(DocLnk()); | 555 | newFile(DocLnk()); |
556 | } | 556 | } |
557 | 557 | ||
558 | void TextEdit::fileOpen() { | 558 | void TextEdit::fileOpen() { |
559 | Config cfg("TextEdit"); | 559 | Config cfg("TextEdit"); |
560 | cfg. setGroup ( "View" ); | 560 | cfg. setGroup ( "View" ); |
561 | QMap<QString, QStringList> map; | 561 | QMap<QString, QStringList> map; |
562 | map.insert(tr("All"), QStringList() ); | 562 | map.insert(tr("All"), QStringList() ); |
563 | QStringList text; | 563 | QStringList text; |
564 | text << "text/*"; | 564 | text << "text/*"; |
565 | map.insert(tr("Text"), text ); | 565 | map.insert(tr("Text"), text ); |
566 | text << "*"; | 566 | text << "*"; |
567 | map.insert(tr("All"), text ); | 567 | map.insert(tr("All"), text ); |
568 | QString str = OFileDialog::getOpenFileName( 2, | 568 | QString str = OFileDialog::getOpenFileName( 2, |
569 | QString::null , | 569 | QString::null , |
570 | QString::null, map); | 570 | QString::null, map); |
571 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) | 571 | if( !str.isEmpty() && QFile(str).exists() && !QFileInfo(str).isDir() ) |
572 | { | 572 | { |
573 | openFile( str ); | 573 | openFile( str ); |
574 | } | 574 | } |
575 | else | 575 | else |
576 | updateCaption(); | 576 | updateCaption(); |
577 | } | 577 | } |
578 | 578 | ||
579 | void TextEdit::doSearchBar() { | 579 | void TextEdit::doSearchBar() { |
580 | if(!useSearchBar) | 580 | if(!useSearchBar) |
581 | searchBar->hide(); | 581 | searchBar->hide(); |
582 | else | 582 | else |
583 | searchBar->show(); | 583 | searchBar->show(); |
584 | } | 584 | } |
585 | 585 | ||
586 | #if 0 | 586 | #if 0 |
587 | void TextEdit::slotFind() { | 587 | void TextEdit::slotFind() { |
588 | FindDialog frmFind( tr("Text Editor"), this ); | 588 | FindDialog frmFind( tr("Text Editor"), this ); |
589 | connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), | 589 | connect( &frmFind, SIGNAL(signalFindClicked(const QString&,bool,bool,int)), |
590 | editor, SLOT(slotDoFind(const QString&,bool,bool))); | 590 | editor, SLOT(slotDoFind(const QString&,bool,bool))); |
591 | 591 | ||
592 | //case sensitive, backwards, [category] | 592 | //case sensitive, backwards, [category] |
593 | 593 | ||
594 | connect( editor, SIGNAL(notFound()), | 594 | connect( editor, SIGNAL(notFound()), |
595 | &frmFind, SLOT(slotNotFound()) ); | 595 | &frmFind, SLOT(slotNotFound()) ); |
596 | connect( editor, SIGNAL(searchWrapped()), | 596 | connect( editor, SIGNAL(searchWrapped()), |
597 | &frmFind, SLOT(slotWrapAround()) ); | 597 | &frmFind, SLOT(slotWrapAround()) ); |
598 | 598 | ||
599 | frmFind.exec(); | 599 | frmFind.exec(); |
600 | 600 | ||
601 | 601 | ||
602 | } | 602 | } |
603 | #endif | 603 | #endif |
604 | 604 | ||
605 | void TextEdit::fileRevert() { | 605 | void TextEdit::fileRevert() { |
606 | clear(); | 606 | clear(); |
607 | fileOpen(); | 607 | fileOpen(); |
608 | } | 608 | } |
609 | 609 | ||
610 | void TextEdit::editCut() { | 610 | void TextEdit::editCut() { |
611 | #ifndef QT_NO_CLIPBOARD | 611 | #ifndef QT_NO_CLIPBOARD |
612 | editor->cut(); | 612 | editor->cut(); |
613 | #endif | 613 | #endif |
614 | } | 614 | } |
615 | 615 | ||
616 | void TextEdit::editCopy() { | 616 | void TextEdit::editCopy() { |
617 | #ifndef QT_NO_CLIPBOARD | 617 | #ifndef QT_NO_CLIPBOARD |
618 | editor->copy(); | 618 | editor->copy(); |
619 | #endif | 619 | #endif |
620 | } | 620 | } |
621 | 621 | ||
622 | void TextEdit::editPaste() { | 622 | void TextEdit::editPaste() { |
623 | #ifndef QT_NO_CLIPBOARD | 623 | #ifndef QT_NO_CLIPBOARD |
624 | editor->paste(); | 624 | editor->paste(); |
625 | #endif | 625 | #endif |
626 | } | 626 | } |
627 | 627 | ||
628 | void TextEdit::editFind() { | 628 | void TextEdit::editFind() { |
629 | searchBar->show(); | 629 | searchBar->show(); |
630 | searchEdit->setFocus(); | 630 | searchEdit->setFocus(); |
631 | } | 631 | } |
632 | 632 | ||
633 | void TextEdit::findNext() { | 633 | void TextEdit::findNext() { |
634 | editor->find( searchEdit->text(), false, false ); | 634 | editor->find( searchEdit->text(), false, false ); |
635 | 635 | ||
636 | } | 636 | } |
637 | 637 | ||
638 | void TextEdit::findClose() { | 638 | void TextEdit::findClose() { |
639 | searchBar->hide(); | 639 | searchBar->hide(); |
640 | } | 640 | } |
641 | 641 | ||
642 | void TextEdit::search() { | 642 | void TextEdit::search() { |
643 | editor->find( searchEdit->text(), false, false ); | 643 | editor->find( searchEdit->text(), false, false ); |
644 | } | 644 | } |
645 | 645 | ||
646 | void TextEdit::newFile( const DocLnk &f ) { | 646 | void TextEdit::newFile( const DocLnk &f ) { |
647 | DocLnk nf = f; | 647 | DocLnk nf = f; |
648 | nf.setType("text/plain"); | 648 | nf.setType("text/plain"); |
649 | clear(); | 649 | clear(); |
650 | setWState (WState_Reserved1 ); | 650 | setWState (WState_Reserved1 ); |
651 | editor->setFocus(); | 651 | editor->setFocus(); |
652 | doc = new DocLnk(nf); | 652 | doc = new DocLnk(nf); |
653 | currentFileName = "Unnamed"; | 653 | currentFileName = "Unnamed"; |
654 | odebug << "newFile "+currentFileName << oendl; | 654 | odebug << "newFile "+currentFileName << oendl; |
655 | updateCaption( currentFileName); | 655 | updateCaption( currentFileName); |
656 | // editor->setEdited( false); | 656 | // editor->setEdited( false); |
657 | } | 657 | } |
658 | 658 | ||
659 | void TextEdit::openDotFile( const QString &f ) { | 659 | void TextEdit::openDotFile( const QString &f ) { |
660 | if(!currentFileName.isEmpty()) { | 660 | if(!currentFileName.isEmpty()) { |
661 | currentFileName=f; | 661 | currentFileName=f; |
662 | 662 | ||
663 | odebug << "openFile dotfile " + currentFileName << oendl; | 663 | odebug << "openFile dotfile " + currentFileName << oendl; |
664 | QString txt; | 664 | QString txt; |
665 | QFile file(f); | 665 | QFile file(f); |
666 | file.open(IO_ReadWrite); | 666 | file.open(IO_ReadWrite); |
667 | QTextStream t(&file); | 667 | QTextStream t(&file); |
668 | while ( !t.atEnd()) { | 668 | while ( !t.atEnd()) { |
669 | txt+=t.readLine()+"\n"; | 669 | txt+=t.readLine()+"\n"; |
670 | } | 670 | } |
671 | editor->setText(txt); | 671 | editor->setText(txt); |
672 | editor->setEdited( false); | 672 | editor->setEdited( false); |
673 | edited1=false; | 673 | edited1=false; |
674 | edited=false; | 674 | edited=false; |
675 | 675 | ||
676 | 676 | ||
677 | } | 677 | } |
678 | updateCaption( currentFileName); | 678 | updateCaption( currentFileName); |
679 | } | 679 | } |
680 | 680 | ||
681 | void TextEdit::openFile( const QString &f ) { | 681 | void TextEdit::openFile( const QString &f ) { |
682 | odebug << "filename is "+ f << oendl; | 682 | odebug << "filename is "+ f << oendl; |
683 | QString filer; | 683 | QString filer; |
684 | QFileInfo fi( f); | 684 | QFileInfo fi( f); |
685 | // bFromDocView = true; | 685 | // bFromDocView = true; |
686 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) | 686 | if(f.find(".desktop",0,true) != -1 && !openDesktop ) |
687 | { | 687 | { |
688 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) | 688 | switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Text Editor has detected<BR>you selected a <B>.desktop</B>file.<BR>Open<B>.desktop</B> file or <B>linked</B> file?"),tr(".desktop File"),tr("Linked Document"),0,1,1) ) |
689 | { | 689 | { |
690 | case 0: //desktop | 690 | case 0: //desktop |
691 | filer = f; | 691 | filer = f; |
692 | break; | 692 | break; |
693 | case 1: //linked | 693 | case 1: //linked |
694 | DocLnk sf(f); | 694 | DocLnk sf(f); |
695 | filer = sf.file(); | 695 | filer = sf.file(); |
696 | break; | 696 | break; |
697 | }; | 697 | }; |
698 | } | 698 | } |
699 | else if(fi.baseName().left(1) == "") | 699 | else if(fi.baseName().left(1) == "") |
700 | { | 700 | { |
701 | odebug << "opening dotfile" << oendl; | 701 | odebug << "opening dotfile" << oendl; |
702 | currentFileName=f; | 702 | currentFileName=f; |
703 | openDotFile(currentFileName); | 703 | openDotFile(currentFileName); |
704 | return; | 704 | return; |
705 | } | 705 | } |
706 | /* | 706 | /* |
707 | * The problem is a file where Config(f).isValid() and it does not | 707 | * The problem is a file where Config(f).isValid() and it does not |
708 | * end with .desktop will be treated as desktop file | 708 | * end with .desktop will be treated as desktop file |
709 | */ | 709 | */ |
710 | else if (f.find(".desktop",0,true) != -1 ) | 710 | else if (f.find(".desktop",0,true) != -1 ) |
711 | { | 711 | { |
712 | DocLnk sf(f); | 712 | DocLnk sf(f); |
713 | filer = sf.file(); | 713 | filer = sf.file(); |
714 | if(filer.right(1) == "/") | 714 | if(filer.right(1) == "/") |
715 | filer = f; | 715 | filer = f; |
716 | 716 | ||
717 | } | 717 | } |
718 | else | 718 | else |
719 | filer = f; | 719 | filer = f; |
720 | 720 | ||
721 | DocLnk nf; | 721 | DocLnk nf; |
722 | nf.setType("text/plain"); | 722 | nf.setType("text/plain"); |
723 | nf.setFile(filer); | 723 | nf.setFile(filer); |
724 | currentFileName=filer; | 724 | currentFileName=filer; |
725 | 725 | ||
726 | nf.setName(fi.baseName()); | 726 | nf.setName(fi.baseName()); |
727 | openFile(nf); | 727 | openFile(nf); |
728 | 728 | ||
729 | odebug << "openFile string "+currentFileName << oendl; | 729 | odebug << "openFile string "+currentFileName << oendl; |
730 | 730 | ||
731 | showEditTools(); | 731 | showEditTools(); |
732 | // Show filename in caption | 732 | // Show filename in caption |
733 | QString name = filer; | 733 | QString name = filer; |
734 | int sep = name.findRev( '/' ); | 734 | int sep = name.findRev( '/' ); |
735 | if ( sep > 0 ) | 735 | if ( sep > 0 ) |
736 | name = name.mid( sep+1 ); | 736 | name = name.mid( sep+1 ); |
737 | updateCaption( name ); | 737 | updateCaption( name ); |
738 | } | 738 | } |
739 | 739 | ||
740 | void TextEdit::openFile( const DocLnk &f ) { | 740 | void TextEdit::openFile( const DocLnk &f ) { |
741 | // clear(); | 741 | // clear(); |
742 | // bFromDocView = true; | 742 | // bFromDocView = true; |
743 | FileManager fm; | 743 | FileManager fm; |
744 | QString txt; | 744 | QString txt; |
745 | currentFileName=f.file(); | 745 | currentFileName=f.file(); |
746 | odebug << "openFile doclnk " + currentFileName << oendl; | 746 | odebug << "openFile doclnk " + currentFileName << oendl; |
747 | if ( !fm.loadFile( f, txt ) ) { | 747 | if ( !fm.loadFile( f, txt ) ) { |
748 | // ####### could be a new file | 748 | // ####### could be a new file |
749 | odebug << "Cannot open file" << oendl; | 749 | odebug << "Cannot open file" << oendl; |
750 | } | 750 | } |
751 | // fileNew(); | 751 | // fileNew(); |
752 | if ( doc ) | 752 | if ( doc ) |
753 | delete doc; | 753 | delete doc; |
754 | doc = new DocLnk(f); | 754 | doc = new DocLnk(f); |
755 | editor->setText(txt); | 755 | editor->setText(txt); |
756 | editor->setEdited( false); | 756 | editor->setEdited( false); |
757 | edited1=false; | 757 | edited1=false; |
758 | edited=false; | 758 | edited=false; |
759 | 759 | ||
760 | doc->setName(currentFileName); | 760 | doc->setName(currentFileName); |
761 | updateCaption(); | 761 | updateCaption(); |
762 | setTimer(); | 762 | setTimer(); |
763 | } | 763 | } |
764 | 764 | ||
765 | void TextEdit::showEditTools() { | 765 | void TextEdit::showEditTools() { |
766 | menu->show(); | 766 | menu->show(); |
767 | editBar->show(); | 767 | editBar->show(); |
768 | if(!useSearchBar) | 768 | if(!useSearchBar) |
769 | searchBar->hide(); | 769 | searchBar->hide(); |
770 | else | 770 | else |
771 | searchBar->show(); | 771 | searchBar->show(); |
772 | setWState (WState_Reserved1 ); | 772 | setWState (WState_Reserved1 ); |
773 | } | 773 | } |
774 | 774 | ||
775 | /*! | 775 | /*! |
776 | unprompted save */ | 776 | unprompted save */ |
777 | bool TextEdit::save() { | 777 | bool TextEdit::save() { |
778 | QString name, file; | ||
778 | odebug << "saveAsFile " + currentFileName << oendl; | 779 | odebug << "saveAsFile " + currentFileName << oendl; |
779 | if(currentFileName.isEmpty()) { | 780 | if(currentFileName.isEmpty()) { |
780 | saveAs(); | 781 | saveAs(); |
781 | return false; | 782 | return false; |
782 | } | 783 | } |
783 | 784 | name = currentFileName; | |
784 | QString file = doc->file(); | 785 | if(doc) { |
785 | odebug << "saver file "+file << oendl; | 786 | file = doc->file(); |
786 | QString name= doc->name(); | 787 | odebug << "saver file "+file << oendl; |
787 | odebug << "File named "+name << oendl; | 788 | name = doc->name(); |
789 | odebug << "File named "+name << oendl; | ||
790 | } else { | ||
791 | name = file = currentFileName; | ||
792 | } | ||
793 | |||
788 | QString rt = editor->text(); | 794 | QString rt = editor->text(); |
789 | if( !rt.isEmpty() ) { | 795 | if( !rt.isEmpty() ) { |
790 | if(name.isEmpty()) { | 796 | if(name.isEmpty()) { |
791 | saveAs(); | 797 | saveAs(); |
792 | } else { | 798 | } else { |
793 | currentFileName= name ; | 799 | currentFileName = name; |
794 | odebug << "saveFile "+currentFileName << oendl; | 800 | odebug << "saveFile "+currentFileName << oendl; |
795 | 801 | ||
796 | struct stat buf; | 802 | struct stat buf; |
797 | mode_t mode; | 803 | mode_t mode; |
798 | stat(file.latin1(), &buf); | 804 | stat(file.latin1(), &buf); |
799 | mode = buf.st_mode; | 805 | mode = buf.st_mode; |
800 | 806 | ||
801 | if(!fileIs) { | 807 | if(!fileIs) { |
802 | doc->setName( name); | 808 | doc->setName( name); |
803 | FileManager fm; | 809 | FileManager fm; |
804 | if ( !fm.saveFile( *doc, rt ) ) { | 810 | if ( !fm.saveFile( *doc, rt ) ) { |
805 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 811 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
806 | return false; | 812 | return false; |
807 | } | 813 | } |
808 | } else { | 814 | } else { |
809 | odebug << "regular save file" << oendl; | 815 | odebug << "regular save file" << oendl; |
810 | QFile f(file); | 816 | QFile f(file); |
811 | if( f.open(IO_WriteOnly)) { | 817 | if( f.open(IO_WriteOnly)) { |
812 | QCString crt = rt.utf8(); | 818 | QCString crt = rt.utf8(); |
813 | f.writeBlock(crt,crt.length()); | 819 | f.writeBlock(crt,crt.length()); |
814 | } else { | 820 | } else { |
815 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 821 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
816 | return false; | 822 | return false; |
817 | } | 823 | } |
818 | 824 | ||
819 | } | 825 | } |
820 | editor->setEdited( false); | 826 | editor->setEdited( false); |
821 | edited1=false; | 827 | edited1=false; |
822 | edited=false; | 828 | edited=false; |
823 | if(caption().left(1)=="*") | 829 | if(caption().left(1)=="*") |
824 | setCaption(caption().right(caption().length()-1)); | 830 | setCaption(caption().right(caption().length()-1)); |
825 | 831 | ||
826 | 832 | ||
827 | chmod( file.latin1(), mode); | 833 | chmod( file.latin1(), mode); |
828 | } | 834 | } |
829 | return true; | 835 | return true; |
830 | } | 836 | } |
831 | return false; | 837 | return false; |
832 | } | 838 | } |
833 | 839 | ||
834 | /*! | 840 | /*! |
835 | prompted save */ | 841 | prompted save */ |
836 | bool TextEdit::saveAs() { | 842 | bool TextEdit::saveAs() { |
837 | 843 | ||
838 | if(caption() == tr("Text Editor")) | 844 | if(caption() == tr("Text Editor")) |
839 | return false; | 845 | return false; |
840 | odebug << "saveAsFile " + currentFileName << oendl; | 846 | odebug << "saveAsFile " + currentFileName << oendl; |
841 | // case of nothing to save... | 847 | // case of nothing to save... |
842 | // if ( !doc && !currentFileName.isEmpty()) { | 848 | // if ( !doc && !currentFileName.isEmpty()) { |
843 | // //|| !bFromDocView) | 849 | // //|| !bFromDocView) |
844 | // odebug << "no doc" << oendl; | 850 | // odebug << "no doc" << oendl; |
845 | // return true; | 851 | // return true; |
846 | // } | 852 | // } |
847 | // if ( !editor->edited() ) { | 853 | // if ( !editor->edited() ) { |
848 | // delete doc; | 854 | // delete doc; |
849 | // doc = 0; | 855 | // doc = 0; |
850 | // return true; | 856 | // return true; |
851 | // } | 857 | // } |
852 | 858 | ||
853 | QString rt = editor->text(); | 859 | QString rt = editor->text(); |
854 | odebug << currentFileName << oendl; | 860 | odebug << currentFileName << oendl; |
855 | 861 | ||
856 | if( currentFileName.isEmpty() | 862 | if( currentFileName.isEmpty() |
857 | || currentFileName == tr("Unnamed") | 863 | || currentFileName == tr("Unnamed") |
858 | || currentFileName == tr("Text Editor")) { | 864 | || currentFileName == tr("Text Editor")) { |
859 | odebug << "do silly TT filename thing" << oendl; | 865 | odebug << "do silly TT filename thing" << oendl; |
860 | // if ( doc && doc->name().isEmpty() ) { | 866 | // if ( doc && doc->name().isEmpty() ) { |
861 | QString pt = rt.simplifyWhiteSpace(); | 867 | QString pt = rt.simplifyWhiteSpace(); |
862 | int i = pt.find( ' ' ); | 868 | int i = pt.find( ' ' ); |
863 | QString docname = pt; | 869 | QString docname = pt; |
864 | if ( i > 0 ) | 870 | if ( i > 0 ) |
865 | docname = pt.left( i ); | 871 | docname = pt.left( i ); |
866 | // remove "." at the beginning | 872 | // remove "." at the beginning |
867 | while( docname.startsWith( "." ) ) | 873 | while( docname.startsWith( "." ) ) |
868 | docname = docname.mid( 1 ); | 874 | docname = docname.mid( 1 ); |
869 | docname.replace( QRegExp("/"), "_" ); | 875 | docname.replace( QRegExp("/"), "_" ); |
870 | // cut the length. filenames longer than that | 876 | // cut the length. filenames longer than that |
871 | //don't make sense and something goes wrong when they get too long. | 877 | //don't make sense and something goes wrong when they get too long. |
872 | if ( docname.length() > 40 ) | 878 | if ( docname.length() > 40 ) |
873 | docname = docname.left(40); | 879 | docname = docname.left(40); |
874 | if ( docname.isEmpty() ) | 880 | if ( docname.isEmpty() ) |
875 | docname = tr("Unnamed"); | 881 | docname = tr("Unnamed"); |
876 | if(doc) doc->setName(docname); | 882 | if(doc) doc->setName(docname); |
877 | currentFileName=docname; | 883 | currentFileName=docname; |
878 | // } | 884 | // } |
879 | // else | 885 | // else |
880 | // odebug << "hmmmmmm" << oendl; | 886 | // odebug << "hmmmmmm" << oendl; |
881 | } | 887 | } |
882 | 888 | ||
883 | 889 | ||
884 | QMap<QString, QStringList> map; | 890 | QMap<QString, QStringList> map; |
885 | map.insert(tr("All"), QStringList() ); | 891 | map.insert(tr("All"), QStringList() ); |
886 | QStringList text; | 892 | QStringList text; |
887 | text << "text/*"; | 893 | text << "text/*"; |
888 | map.insert(tr("Text"), text ); | 894 | map.insert(tr("Text"), text ); |
889 | text << "*"; | 895 | text << "*"; |
890 | map.insert(tr("All"), text ); | 896 | map.insert(tr("All"), text ); |
891 | 897 | ||
892 | QFileInfo cuFi( currentFileName); | 898 | QFileInfo cuFi( currentFileName); |
893 | QString filee = cuFi.fileName(); | 899 | QString filee = cuFi.fileName(); |
894 | QString dire = cuFi.dirPath(); | 900 | QString dire = cuFi.dirPath(); |
895 | if(dire==".") | 901 | if(dire==".") |
896 | dire = QPEApplication::documentDir(); | 902 | dire = QPEApplication::documentDir(); |
897 | QString str; | 903 | QString str; |
898 | if( !featureAutoSave) { | 904 | if( !featureAutoSave) { |
899 | str = OFileDialog::getSaveFileName( 2, | 905 | str = OFileDialog::getSaveFileName( 2, |
900 | dire, | 906 | dire, |
901 | filee, map); | 907 | filee, map); |
902 | } else | 908 | } else |
903 | str=currentFileName; | 909 | str=currentFileName; |
904 | 910 | ||
905 | if(!str.isEmpty()) { | 911 | if(!str.isEmpty()) { |
906 | QString fileNm=str; | 912 | QString fileNm=str; |
907 | 913 | ||
908 | odebug << "saving filename "+fileNm << oendl; | 914 | odebug << "saving filename "+fileNm << oendl; |
909 | QFileInfo fi(fileNm); | 915 | QFileInfo fi(fileNm); |
910 | currentFileName=fi.fileName(); | 916 | currentFileName=fi.fileName(); |
911 | if(doc) | 917 | if(doc) |
912 | // QString file = doc->file(); | 918 | // QString file = doc->file(); |
913 | // doc->removeFiles(); | 919 | // doc->removeFiles(); |
914 | delete doc; | 920 | delete doc; |
915 | DocLnk nf; | 921 | DocLnk nf; |
916 | nf.setType("text/plain"); | 922 | nf.setType("text/plain"); |
917 | nf.setFile( fileNm); | 923 | nf.setFile( fileNm); |
918 | doc = new DocLnk(nf); | 924 | doc = new DocLnk(nf); |
919 | // editor->setText(rt); | 925 | // editor->setText(rt); |
920 | odebug << "Saving file as "+currentFileName << oendl; | 926 | odebug << "Saving file as "+currentFileName << oendl; |
921 | doc->setName( currentFileName); | 927 | doc->setName( currentFileName); |
922 | updateCaption( currentFileName); | 928 | updateCaption( currentFileName); |
923 | 929 | ||
924 | FileManager fm; | 930 | FileManager fm; |
925 | if ( !fm.saveFile( *doc, rt ) ) { | 931 | if ( !fm.saveFile( *doc, rt ) ) { |
926 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); | 932 | QMessageBox::message(tr("Text Edit"),tr("Save Failed")); |
927 | return false; | 933 | return false; |
928 | } | 934 | } |
929 | 935 | ||
930 | if( filePerms ) { | 936 | if( filePerms ) { |
931 | filePermissions *filePerm; | 937 | filePermissions *filePerm; |
932 | filePerm = new filePermissions(this, | 938 | filePerm = new filePermissions(this, |
933 | tr("Permissions"),true, | 939 | tr("Permissions"),true, |
934 | 0,(const QString &)fileNm); | 940 | 0,(const QString &)fileNm); |
935 | QPEApplication::execDialog( filePerm ); | 941 | QPEApplication::execDialog( filePerm ); |
936 | 942 | ||
937 | if( filePerm) | 943 | if( filePerm) |
938 | delete filePerm; | 944 | delete filePerm; |
939 | } | 945 | } |
940 | // } | 946 | // } |
941 | editor->setEdited( false); | 947 | editor->setEdited( false); |
942 | edited1 = false; | 948 | edited1 = false; |
943 | edited = false; | 949 | edited = false; |
944 | if(caption().left(1)=="*") | 950 | if(caption().left(1)=="*") |
945 | setCaption(caption().right(caption().length()-1)); | 951 | setCaption(caption().right(caption().length()-1)); |
946 | 952 | ||
947 | return true; | 953 | return true; |
948 | } | 954 | } |
949 | odebug << "returning false" << oendl; | 955 | odebug << "returning false" << oendl; |
950 | return false; | 956 | return false; |
951 | } //end saveAs | 957 | } //end saveAs |
952 | 958 | ||
953 | void TextEdit::clear() { | 959 | void TextEdit::clear() { |
954 | delete doc; | 960 | delete doc; |
955 | doc = 0; | 961 | doc = 0; |
956 | editor->clear(); | 962 | editor->clear(); |
957 | } | 963 | } |
958 | 964 | ||
959 | void TextEdit::updateCaption( const QString &name ) { | 965 | void TextEdit::updateCaption( const QString &name ) { |
960 | 966 | ||
961 | if ( name.isEmpty() ) | 967 | if ( name.isEmpty() ) |
962 | setCaption( tr("Text Editor") ); | 968 | setCaption( tr("Text Editor") ); |
963 | else { | 969 | else { |
964 | QString s = name; | 970 | QString s = name; |
965 | if ( s.isNull() ) | 971 | if ( s.isNull() ) |
966 | s = doc->name(); | 972 | s = doc->name(); |
967 | if ( s.isEmpty() ) { | 973 | if ( s.isEmpty() ) { |
968 | s = tr( "Unnamed" ); | 974 | s = tr( "Unnamed" ); |
969 | currentFileName=s; | 975 | currentFileName=s; |
970 | } | 976 | } |
971 | // if(s.left(1) == "/") | 977 | // if(s.left(1) == "/") |
972 | // s = s.right(s.length()-1); | 978 | // s = s.right(s.length()-1); |
973 | setCaption( tr("%1 - Text Editor").arg( s ) ); | 979 | setCaption( tr("%1 - Text Editor").arg( s ) ); |
974 | } | 980 | } |
975 | } | 981 | } |
976 | 982 | ||
977 | void TextEdit::setDocument(const QString& fileref) { | 983 | void TextEdit::setDocument(const QString& fileref) { |
978 | if(fileref != "Unnamed") { | 984 | if(fileref != "Unnamed") { |
979 | currentFileName=fileref; | 985 | currentFileName=fileref; |
980 | odebug << "setDocument" << oendl; | 986 | odebug << "setDocument" << oendl; |
981 | QFileInfo fi(currentFileName); | 987 | QFileInfo fi(currentFileName); |
982 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; | 988 | odebug << "basename:"+fi.baseName()+": current filenmame "+currentFileName << oendl; |
983 | if( (fi.baseName().left(1)).isEmpty() ) { | 989 | if( (fi.baseName().left(1)).isEmpty() ) { |
984 | openDotFile(currentFileName); | 990 | openDotFile(currentFileName); |
985 | 991 | ||
986 | } else { | 992 | } else { |
987 | odebug << "setDoc open" << oendl; | 993 | odebug << "setDoc open" << oendl; |
988 | bFromDocView = true; | 994 | bFromDocView = true; |
989 | openFile(fileref); | 995 | openFile(fileref); |
990 | editor->setEdited(true); | 996 | editor->setEdited(true); |
991 | edited1=false; | 997 | edited1=false; |
992 | edited=true; | 998 | edited=true; |
993 | // fromSetDocument=false; | 999 | // fromSetDocument=false; |
994 | // doSearchBar(); | 1000 | // doSearchBar(); |
995 | } | 1001 | } |
996 | } | 1002 | } |
997 | updateCaption( currentFileName); | 1003 | updateCaption( currentFileName); |
998 | } | 1004 | } |
999 | 1005 | ||
1000 | void TextEdit::changeFont() { | 1006 | void TextEdit::changeFont() { |
1001 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 1007 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
1002 | d-> setCaption ( tr( "Choose font" )); | 1008 | d-> setCaption ( tr( "Choose font" )); |
1003 | QBoxLayout *lay = new QVBoxLayout ( d ); | 1009 | QBoxLayout *lay = new QVBoxLayout ( d ); |
1004 | OFontSelector *ofs = new OFontSelector ( true, d ); | 1010 | OFontSelector *ofs = new OFontSelector ( true, d ); |
1005 | lay-> addWidget ( ofs ); | 1011 | lay-> addWidget ( ofs ); |
1006 | ofs-> setSelectedFont ( editor-> font ( )); | 1012 | ofs-> setSelectedFont ( editor-> font ( )); |
1007 | 1013 | ||
1008 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) | 1014 | if ( QPEApplication::execDialog( d ) == QDialog::Accepted ) |
1009 | editor-> setFont ( ofs-> selectedFont ( )); | 1015 | editor-> setFont ( ofs-> selectedFont ( )); |
1010 | delete d; | 1016 | delete d; |
1011 | 1017 | ||
1012 | } | 1018 | } |
1013 | 1019 | ||
1014 | void TextEdit::editDelete() { | 1020 | void TextEdit::editDelete() { |
1015 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 1021 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
1016 | tr("Do you really want<BR>to <B>delete</B> " | 1022 | tr("Do you really want<BR>to <B>delete</B> " |
1017 | "the current file\nfrom the disk?<BR>This is " | 1023 | "the current file\nfrom the disk?<BR>This is " |
1018 | "<B>irreversable!</B>"), | 1024 | "<B>irreversable!</B>"), |
1019 | tr("Yes"),tr("No"),0,0,1) ) { | 1025 | tr("Yes"),tr("No"),0,0,1) ) { |
1020 | case 0: | 1026 | case 0: |
1021 | if(doc) { | 1027 | if(doc) { |
1022 | doc->removeFiles(); | 1028 | doc->removeFiles(); |
1023 | clear(); | 1029 | clear(); |
1024 | setCaption( tr("Text Editor") ); | 1030 | setCaption( tr("Text Editor") ); |
1025 | } | 1031 | } |
1026 | break; | 1032 | break; |
1027 | case 1: | 1033 | case 1: |
1028 | // exit | 1034 | // exit |
1029 | break; | 1035 | break; |
1030 | }; | 1036 | }; |
1031 | } | 1037 | } |
1032 | 1038 | ||
1033 | void TextEdit::changeStartConfig( bool b ) { | 1039 | void TextEdit::changeStartConfig( bool b ) { |
1034 | startWithNew=b; | 1040 | startWithNew=b; |
1035 | Config cfg("TextEdit"); | 1041 | Config cfg("TextEdit"); |
1036 | cfg.setGroup("View"); | 1042 | cfg.setGroup("View"); |
1037 | cfg.writeEntry("startNew",b); | 1043 | cfg.writeEntry("startNew",b); |
1038 | update(); | 1044 | update(); |
1039 | } | 1045 | } |
1040 | 1046 | ||
1041 | void TextEdit::editorChanged() { | 1047 | void TextEdit::editorChanged() { |
1042 | // odebug << "editor changed" << oendl; | 1048 | // odebug << "editor changed" << oendl; |
1043 | if( /*editor->edited() &&*/ /*edited && */!edited1) { | 1049 | if( /*editor->edited() &&*/ /*edited && */!edited1) { |
1044 | setCaption( "*"+caption()); | 1050 | setCaption( "*"+caption()); |
1045 | edited1=true; | 1051 | edited1=true; |
1046 | } | 1052 | } |
1047 | edited=true; | 1053 | edited=true; |
1048 | } | 1054 | } |
1049 | 1055 | ||
1050 | void TextEdit::receive(const QCString&msg, const QByteArray &) { | 1056 | void TextEdit::receive(const QCString&msg, const QByteArray &) { |
1051 | odebug << "QCop "+msg << oendl; | 1057 | odebug << "QCop "+msg << oendl; |
1052 | if ( msg == "setDocument(QString)" ) { | 1058 | if ( msg == "setDocument(QString)" ) { |
1053 | odebug << "bugger all" << oendl; | 1059 | odebug << "bugger all" << oendl; |
1054 | 1060 | ||
1055 | } | 1061 | } |
1056 | 1062 | ||
1057 | } | 1063 | } |
1058 | 1064 | ||
1059 | void TextEdit::doAbout() { | 1065 | void TextEdit::doAbout() { |
1060 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" | 1066 | QMessageBox::about(0,tr("Text Edit"),tr("Text Edit is copyright<BR>" |
1061 | "2000 Trolltech AS, and<BR>" | 1067 | "2000 Trolltech AS, and<BR>" |
1062 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" | 1068 | "2002 by <B>L. J. Potter <BR>llornkcor@handhelds.org</B><BR>" |
1063 | "and is licensed under the GPL")); | 1069 | "and is licensed under the GPL")); |
1064 | } | 1070 | } |
1065 | 1071 | ||
1066 | void TextEdit::doPrompt(bool b) { | 1072 | void TextEdit::doPrompt(bool b) { |
1067 | promptExit=b; | 1073 | promptExit=b; |
1068 | Config cfg("TextEdit"); | 1074 | Config cfg("TextEdit"); |
1069 | cfg.setGroup ( "View" ); | 1075 | cfg.setGroup ( "View" ); |
1070 | cfg.writeEntry ( "PromptExit", b); | 1076 | cfg.writeEntry ( "PromptExit", b); |
1071 | } | 1077 | } |
1072 | 1078 | ||
1073 | void TextEdit::doDesktop(bool b) { | 1079 | void TextEdit::doDesktop(bool b) { |
1074 | openDesktop=b; | 1080 | openDesktop=b; |
1075 | Config cfg("TextEdit"); | 1081 | Config cfg("TextEdit"); |
1076 | cfg.setGroup ( "View" ); | 1082 | cfg.setGroup ( "View" ); |
1077 | cfg.writeEntry ( "OpenDesktop", b); | 1083 | cfg.writeEntry ( "OpenDesktop", b); |
1078 | } | 1084 | } |
1079 | 1085 | ||
1080 | void TextEdit::doFilePerms(bool b) { | 1086 | void TextEdit::doFilePerms(bool b) { |
1081 | filePerms=b; | 1087 | filePerms=b; |
1082 | Config cfg("TextEdit"); | 1088 | Config cfg("TextEdit"); |
1083 | cfg.setGroup ( "View" ); | 1089 | cfg.setGroup ( "View" ); |
1084 | cfg.writeEntry ( "FilePermissions", b); | 1090 | cfg.writeEntry ( "FilePermissions", b); |
1085 | } | 1091 | } |
1086 | 1092 | ||
1087 | void TextEdit::editPasteTimeDate() { | 1093 | void TextEdit::editPasteTimeDate() { |
1088 | #ifndef QT_NO_CLIPBOARD | 1094 | #ifndef QT_NO_CLIPBOARD |
1089 | QClipboard *cb = QApplication::clipboard(); | 1095 | QClipboard *cb = QApplication::clipboard(); |
1090 | QDateTime dt = QDateTime::currentDateTime(); | 1096 | QDateTime dt = QDateTime::currentDateTime(); |
1091 | cb->setText( dt.toString()); | 1097 | cb->setText( dt.toString()); |
1092 | editor->paste(); | 1098 | editor->paste(); |
1093 | #endif | 1099 | #endif |
1094 | } | 1100 | } |
1095 | 1101 | ||
1096 | int TextEdit::savePrompt() | 1102 | int TextEdit::savePrompt() |
1097 | { | 1103 | { |
1098 | switch( QMessageBox::information( 0, (tr("Textedit")), | 1104 | switch( QMessageBox::information( 0, (tr("Textedit")), |
1099 | (tr("Textedit detected\n" | 1105 | (tr("Textedit detected\n" |
1100 | "you have unsaved changes\n" | 1106 | "you have unsaved changes\n" |
1101 | "Go ahead and save?\n")), | 1107 | "Go ahead and save?\n")), |
1102 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) | 1108 | (tr("Save")), (tr("Don't Save")), (tr("&Cancel")), 2, 2 ) ) |
1103 | { | 1109 | { |
1104 | case 0: | 1110 | case 0: |
1105 | { | 1111 | { |
1106 | return 1; | 1112 | return 1; |
1107 | } | 1113 | } |
1108 | break; | 1114 | break; |
1109 | 1115 | ||
1110 | case 1: | 1116 | case 1: |
1111 | { | 1117 | { |
1112 | return 2; | 1118 | return 2; |
1113 | } | 1119 | } |
1114 | break; | 1120 | break; |
1115 | 1121 | ||
1116 | case 2: | 1122 | case 2: |
1117 | { | 1123 | { |
1118 | return -1; | 1124 | return -1; |
1119 | } | 1125 | } |
1120 | break; | 1126 | break; |
1121 | }; | 1127 | }; |
1122 | 1128 | ||
1123 | return 0; | 1129 | return 0; |
1124 | } | 1130 | } |
1125 | 1131 | ||
1126 | void TextEdit::timerCrank() | 1132 | void TextEdit::timerCrank() |
1127 | { | 1133 | { |
1128 | if(featureAutoSave && edited1) | 1134 | if(featureAutoSave && edited1) |
1129 | { | 1135 | { |
1130 | if(currentFileName.isEmpty()) | 1136 | if(currentFileName.isEmpty()) |
1131 | { | 1137 | { |
1132 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; | 1138 | currentFileName = QDir::homeDirPath()+"/textedit.tmp"; |
1133 | saveAs(); | 1139 | saveAs(); |
1134 | } | 1140 | } |
1135 | else | 1141 | else |
1136 | { | 1142 | { |
1137 | // odebug << "autosave" << oendl; | 1143 | // odebug << "autosave" << oendl; |
1138 | save(); | 1144 | save(); |
1139 | } | 1145 | } |
1140 | setTimer(); | 1146 | setTimer(); |
1141 | } | 1147 | } |
1142 | } | 1148 | } |
1143 | 1149 | ||
1144 | void TextEdit::doTimer(bool b) | 1150 | void TextEdit::doTimer(bool b) |
1145 | { | 1151 | { |
1146 | Config cfg("TextEdit"); | 1152 | Config cfg("TextEdit"); |
1147 | cfg.setGroup ( "View" ); | 1153 | cfg.setGroup ( "View" ); |
1148 | cfg.writeEntry ( "autosave", b); | 1154 | cfg.writeEntry ( "autosave", b); |
1149 | featureAutoSave = b; | 1155 | featureAutoSave = b; |
1150 | nAutoSave->setOn(b); | 1156 | nAutoSave->setOn(b); |
1151 | if(b) | 1157 | if(b) |
1152 | { | 1158 | { |
1153 | // odebug << "doTimer true" << oendl; | 1159 | // odebug << "doTimer true" << oendl; |
1154 | setTimer(); | 1160 | setTimer(); |
1155 | } | 1161 | } |
1156 | // else | 1162 | // else |
1157 | // odebug << "doTimer false" << oendl; | 1163 | // odebug << "doTimer false" << oendl; |
1158 | } | 1164 | } |
1159 | 1165 | ||
1160 | void TextEdit::setTimer() | 1166 | void TextEdit::setTimer() |
1161 | { | 1167 | { |
1162 | if(featureAutoSave) | 1168 | if(featureAutoSave) |
1163 | { | 1169 | { |
1164 | // odebug << "setting autosave" << oendl; | 1170 | // odebug << "setting autosave" << oendl; |
1165 | QTimer *timer = new QTimer(this ); | 1171 | QTimer *timer = new QTimer(this ); |
1166 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); | 1172 | connect( timer, SIGNAL(timeout()), this, SLOT(timerCrank()) ); |
1167 | timer->start( 300000, true); //5 minutes | 1173 | timer->start( 300000, true); //5 minutes |
1168 | } | 1174 | } |
1169 | } | 1175 | } |
1170 | 1176 | ||
1171 | void TextEdit::gotoLine() { | 1177 | void TextEdit::gotoLine() { |
1172 | if( editor->length() < 1) | 1178 | if( editor->length() < 1) |
1173 | return; | 1179 | return; |
1174 | QWidget *d = QApplication::desktop(); | 1180 | QWidget *d = QApplication::desktop(); |
1175 | gotoEdit = new QLineEdit( 0, "Goto line"); | 1181 | gotoEdit = new QLineEdit( 0, "Goto line"); |
1176 | 1182 | ||
1177 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); | 1183 | gotoEdit->move( (d->width()/2) - ( gotoEdit->width()/2) , (d->height()/2) - (gotoEdit->height()/2)); |
1178 | gotoEdit->setFrame(true); | 1184 | gotoEdit->setFrame(true); |
1179 | gotoEdit->show(); | 1185 | gotoEdit->show(); |
1180 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); | 1186 | connect (gotoEdit,SIGNAL(returnPressed()), this, SLOT(doGoto())); |
1181 | } | 1187 | } |
1182 | 1188 | ||
1183 | void TextEdit::doGoto() { | 1189 | void TextEdit::doGoto() { |
1184 | QString number = gotoEdit->text(); | 1190 | QString number = gotoEdit->text(); |
1185 | gotoEdit->hide(); | 1191 | gotoEdit->hide(); |
1186 | 1192 | ||
1187 | if(gotoEdit) { | 1193 | if(gotoEdit) { |
1188 | delete gotoEdit; | 1194 | delete gotoEdit; |
1189 | gotoEdit = 0; | 1195 | gotoEdit = 0; |
1190 | } | 1196 | } |
1191 | 1197 | ||
1192 | bool ok; | 1198 | bool ok; |
1193 | int lineNumber = number.toInt(&ok, 10); | 1199 | int lineNumber = number.toInt(&ok, 10); |
1194 | if( editor->numLines() < lineNumber) | 1200 | if( editor->numLines() < lineNumber) |
1195 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); | 1201 | QMessageBox::message(tr("Text Edit"),tr("Not enough lines")); |
1196 | else | 1202 | else |
1197 | { | 1203 | { |
1198 | editor->setCursorPosition(lineNumber, 0, false); | 1204 | editor->setCursorPosition(lineNumber, 0, false); |
1199 | } | 1205 | } |
1200 | } | 1206 | } |