summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-12-15 21:32:35 (UTC)
committer llornkcor <llornkcor>2002-12-15 21:32:35 (UTC)
commit6de66e1e2af2b3b06e53dd83338b9dc9df6190df (patch) (unidiff)
tree1c6d955f2acf0f2a1b93b7959748ceed85bab8e0
parent0a32396b7294d535b467b4fb4a4a0fb6038a21dc (diff)
downloadopie-6de66e1e2af2b3b06e53dd83338b9dc9df6190df.zip
opie-6de66e1e2af2b3b06e53dd83338b9dc9df6190df.tar.gz
opie-6de66e1e2af2b3b06e53dd83338b9dc9df6190df.tar.bz2
fix bug in open when cancelling
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index b199c81..8b3c4c6 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -399,385 +399,385 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
399 searchBar->hide(); 399 searchBar->hide();
400 400
401 editor = new QpeEditor( this ); 401 editor = new QpeEditor( this );
402 setCentralWidget( editor ); 402 setCentralWidget( editor );
403 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 403 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
404 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 404 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
405 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); 405 QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold);
406 406
407 Config cfg("TextEdit"); 407 Config cfg("TextEdit");
408 cfg. setGroup ( "Font" ); 408 cfg. setGroup ( "Font" );
409 409
410 QFont defaultFont = editor-> font ( ); 410 QFont defaultFont = editor-> font ( );
411 411
412 QString family = cfg. readEntry ( "Family", defaultFont. family ( )); 412 QString family = cfg. readEntry ( "Family", defaultFont. family ( ));
413 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); 413 int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( ));
414 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); 414 int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( ));
415 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); 415 bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( ));
416 416
417 defaultFont = QFont ( family, size, weight, italic ); 417 defaultFont = QFont ( family, size, weight, italic );
418 editor-> setFont ( defaultFont ); 418 editor-> setFont ( defaultFont );
419 419
420// updateCaption(); 420// updateCaption();
421 421
422 cfg.setGroup ( "View" ); 422 cfg.setGroup ( "View" );
423 423
424 promptExit = cfg.readBoolEntry ( "PromptExit", false ); 424 promptExit = cfg.readBoolEntry ( "PromptExit", false );
425 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); 425 openDesktop = cfg.readBoolEntry ( "OpenDesktop", true );
426 filePerms = cfg.readBoolEntry ( "FilePermissions", false ); 426 filePerms = cfg.readBoolEntry ( "FilePermissions", false );
427 useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); 427 useSearchBar = cfg.readBoolEntry ( "SearchBar", false );
428 startWithNew = cfg.readBoolEntry ( "startNew", true); 428 startWithNew = cfg.readBoolEntry ( "startNew", true);
429 429
430 if(useSearchBar) searchBarAction->setOn(true); 430 if(useSearchBar) searchBarAction->setOn(true);
431 if(promptExit ) nAdvanced->setOn( true ); 431 if(promptExit ) nAdvanced->setOn( true );
432 if(openDesktop) desktopAction->setOn( true ); 432 if(openDesktop) desktopAction->setOn( true );
433 if(filePerms) filePermAction->setOn( true ); 433 if(filePerms) filePermAction->setOn( true );
434 if(startWithNew) nStart->setOn( true ); 434 if(startWithNew) nStart->setOn( true );
435 435
436 bool wrap = cfg. readBoolEntry ( "Wrap", true ); 436 bool wrap = cfg. readBoolEntry ( "Wrap", true );
437 wa-> setOn ( wrap ); 437 wa-> setOn ( wrap );
438 setWordWrap ( wrap ); 438 setWordWrap ( wrap );
439 439
440 if( qApp->argc() > 1) { 440 if( qApp->argc() > 1) {
441 currentFileName=qApp->argv()[1]; 441 currentFileName=qApp->argv()[1];
442 442
443 QFileInfo fi(currentFileName); 443 QFileInfo fi(currentFileName);
444 444
445 if(fi.baseName().left(1) == "") { 445 if(fi.baseName().left(1) == "") {
446 openDotFile(currentFileName); 446 openDotFile(currentFileName);
447 } else { 447 } else {
448 openFile(currentFileName); 448 openFile(currentFileName);
449 } 449 }
450 } else { 450 } else {
451 edited1=false; 451 edited1=false;
452 452
453// if(startWithNew ) { 453// if(startWithNew ) {
454 openDotFile(""); 454 openDotFile("");
455// fileNew(); 455// fileNew();
456// } 456// }
457// else { 457// else {
458// fileOpen(); 458// fileOpen();
459// } 459// }
460 } 460 }
461 461
462 viewSelection = cfg.readNumEntry( "FileView", 0 ); 462 viewSelection = cfg.readNumEntry( "FileView", 0 );
463// setCaption(tr("Text Editor")); 463// setCaption(tr("Text Editor"));
464} 464}
465 465
466TextEdit::~TextEdit() { 466TextEdit::~TextEdit() {
467// qDebug("destr"); 467// qDebug("destr");
468} 468}
469 469
470void TextEdit::closeEvent(QCloseEvent *) { 470void TextEdit::closeEvent(QCloseEvent *) {
471// qDebug("closing here"); 471// qDebug("closing here");
472 if( edited1 && promptExit) 472 if( edited1 && promptExit)
473 saveAs(); 473 saveAs();
474 qApp->quit(); 474 qApp->quit();
475} 475}
476 476
477void TextEdit::cleanUp() { 477void TextEdit::cleanUp() {
478// qDebug("cleanUp");// save(); 478// qDebug("cleanUp");// save();
479 479
480 Config cfg ( "TextEdit" ); 480 Config cfg ( "TextEdit" );
481 cfg. setGroup ( "Font" ); 481 cfg. setGroup ( "Font" );
482 QFont f = editor->font(); 482 QFont f = editor->font();
483 cfg.writeEntry ( "Family", f. family ( )); 483 cfg.writeEntry ( "Family", f. family ( ));
484 cfg.writeEntry ( "Size", f. pointSize ( )); 484 cfg.writeEntry ( "Size", f. pointSize ( ));
485 cfg.writeEntry ( "Weight", f. weight ( )); 485 cfg.writeEntry ( "Weight", f. weight ( ));
486 cfg.writeEntry ( "Italic", f. italic ( )); 486 cfg.writeEntry ( "Italic", f. italic ( ));
487 487
488 cfg.setGroup ( "View" ); 488 cfg.setGroup ( "View" );
489 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); 489 cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth );
490 cfg.writeEntry ( "FileView", viewSelection ); 490 cfg.writeEntry ( "FileView", viewSelection );
491 491
492 cfg.writeEntry ( "PromptExit", promptExit ); 492 cfg.writeEntry ( "PromptExit", promptExit );
493 cfg.writeEntry ( "OpenDesktop", openDesktop ); 493 cfg.writeEntry ( "OpenDesktop", openDesktop );
494 cfg.writeEntry ( "FilePermissions", filePerms ); 494 cfg.writeEntry ( "FilePermissions", filePerms );
495 cfg.writeEntry ( "SearchBar", useSearchBar ); 495 cfg.writeEntry ( "SearchBar", useSearchBar );
496 cfg.writeEntry ( "startNew", startWithNew ); 496 cfg.writeEntry ( "startNew", startWithNew );
497 497
498} 498}
499 499
500 500
501void TextEdit::accept() { 501void TextEdit::accept() {
502// qDebug("accept"); 502// qDebug("accept");
503 if( edited1) 503 if( edited1)
504 saveAs(); 504 saveAs();
505 qApp->quit(); 505 qApp->quit();
506} 506}
507 507
508void TextEdit::zoomIn() { 508void TextEdit::zoomIn() {
509 setFontSize(editor->font().pointSize()+1,false); 509 setFontSize(editor->font().pointSize()+1,false);
510} 510}
511 511
512void TextEdit::zoomOut() { 512void TextEdit::zoomOut() {
513 setFontSize(editor->font().pointSize()-1,true); 513 setFontSize(editor->font().pointSize()-1,true);
514} 514}
515 515
516 516
517void TextEdit::setFontSize(int sz, bool round_down_not_up) { 517void TextEdit::setFontSize(int sz, bool round_down_not_up) {
518 int s=10; 518 int s=10;
519 for (int i=0; i<nfontsizes; i++) { 519 for (int i=0; i<nfontsizes; i++) {
520 if ( fontsize[i] == sz ) { 520 if ( fontsize[i] == sz ) {
521 s = sz; 521 s = sz;
522 break; 522 break;
523 } else if ( round_down_not_up ) { 523 } else if ( round_down_not_up ) {
524 if ( fontsize[i] < sz ) 524 if ( fontsize[i] < sz )
525 s = fontsize[i]; 525 s = fontsize[i];
526 } else { 526 } else {
527 if ( fontsize[i] > sz ) { 527 if ( fontsize[i] > sz ) {
528 s = fontsize[i]; 528 s = fontsize[i];
529 break; 529 break;
530 } 530 }
531 } 531 }
532 } 532 }
533 533
534 QFont f = editor->font(); 534 QFont f = editor->font();
535 f.setPointSize(s); 535 f.setPointSize(s);
536 editor->setFont(f); 536 editor->setFont(f);
537 537
538 zin->setEnabled(s != fontsize[nfontsizes-1]); 538 zin->setEnabled(s != fontsize[nfontsizes-1]);
539 zout->setEnabled(s != fontsize[0]); 539 zout->setEnabled(s != fontsize[0]);
540} 540}
541 541
542void TextEdit::setBold(bool y) { 542void TextEdit::setBold(bool y) {
543 QFont f = editor->font(); 543 QFont f = editor->font();
544 f.setBold(y); 544 f.setBold(y);
545 editor->setFont(f); 545 editor->setFont(f);
546} 546}
547 547
548void TextEdit::setItalic(bool y) { 548void TextEdit::setItalic(bool y) {
549 QFont f = editor->font(); 549 QFont f = editor->font();
550 f.setItalic(y); 550 f.setItalic(y);
551 editor->setFont(f); 551 editor->setFont(f);
552} 552}
553 553
554void TextEdit::setWordWrap(bool y) { 554void TextEdit::setWordWrap(bool y) {
555 bool state = editor->edited(); 555 bool state = editor->edited();
556 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 556 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
557 editor->setEdited( state ); 557 editor->setEdited( state );
558} 558}
559 559
560void TextEdit::setSearchBar(bool b) { 560void TextEdit::setSearchBar(bool b) {
561 useSearchBar=b; 561 useSearchBar=b;
562 Config cfg("TextEdit"); 562 Config cfg("TextEdit");
563 cfg.setGroup("View"); 563 cfg.setGroup("View");
564 cfg.writeEntry ( "SearchBar", b ); 564 cfg.writeEntry ( "SearchBar", b );
565 searchBarAction->setOn(b); 565 searchBarAction->setOn(b);
566 if(b) 566 if(b)
567 searchBar->show(); 567 searchBar->show();
568 else 568 else
569 searchBar->hide(); 569 searchBar->hide();
570 editor->setFocus(); 570 editor->setFocus();
571} 571}
572 572
573void TextEdit::fileNew() { 573void TextEdit::fileNew() {
574// if( !bFromDocView ) { 574// if( !bFromDocView ) {
575// saveAs(); 575// saveAs();
576// } 576// }
577 newFile(DocLnk()); 577 newFile(DocLnk());
578} 578}
579 579
580void TextEdit::fileOpen() { 580void TextEdit::fileOpen() {
581 QMap<QString, QStringList> map; 581 QMap<QString, QStringList> map;
582 map.insert(tr("All"), QStringList() ); 582 map.insert(tr("All"), QStringList() );
583 QStringList text; 583 QStringList text;
584 text << "text/*"; 584 text << "text/*";
585 map.insert(tr("Text"), text ); 585 map.insert(tr("Text"), text );
586 text << "*"; 586 text << "*";
587 map.insert(tr("All"), text ); 587 map.insert(tr("All"), text );
588 QString str = OFileDialog::getOpenFileName( 2, 588 QString str = OFileDialog::getOpenFileName( 2,
589 QPEApplication::documentDir(), 589 QPEApplication::documentDir(),
590 QString::null, map); 590 QString::null, map);
591 if(!str.isEmpty() ) 591 if( QFile(str).exists())
592 openFile( str ); 592 openFile( str );
593 else 593 else
594 updateCaption(); 594 updateCaption();
595} 595}
596 596
597void TextEdit::doSearchBar() { 597void TextEdit::doSearchBar() {
598 if(!useSearchBar) 598 if(!useSearchBar)
599 searchBar->hide(); 599 searchBar->hide();
600 else 600 else
601 searchBar->show(); 601 searchBar->show();
602} 602}
603 603
604#if 0 604#if 0
605void TextEdit::slotFind() { 605void TextEdit::slotFind() {
606 FindDialog frmFind( tr("Text Editor"), this ); 606 FindDialog frmFind( tr("Text Editor"), this );
607 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 607 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
608 editor, SLOT(slotDoFind( const QString&,bool,bool))); 608 editor, SLOT(slotDoFind( const QString&,bool,bool)));
609 609
610 //case sensitive, backwards, [category] 610 //case sensitive, backwards, [category]
611 611
612 connect( editor, SIGNAL(notFound()), 612 connect( editor, SIGNAL(notFound()),
613 &frmFind, SLOT(slotNotFound()) ); 613 &frmFind, SLOT(slotNotFound()) );
614 connect( editor, SIGNAL(searchWrapped()), 614 connect( editor, SIGNAL(searchWrapped()),
615 &frmFind, SLOT(slotWrapAround()) ); 615 &frmFind, SLOT(slotWrapAround()) );
616 616
617 frmFind.exec(); 617 frmFind.exec();
618 618
619 619
620} 620}
621#endif 621#endif
622 622
623void TextEdit::fileRevert() { 623void TextEdit::fileRevert() {
624 clear(); 624 clear();
625 fileOpen(); 625 fileOpen();
626} 626}
627 627
628void TextEdit::editCut() { 628void TextEdit::editCut() {
629#ifndef QT_NO_CLIPBOARD 629#ifndef QT_NO_CLIPBOARD
630 editor->cut(); 630 editor->cut();
631#endif 631#endif
632} 632}
633 633
634void TextEdit::editCopy() { 634void TextEdit::editCopy() {
635#ifndef QT_NO_CLIPBOARD 635#ifndef QT_NO_CLIPBOARD
636 editor->copy(); 636 editor->copy();
637#endif 637#endif
638} 638}
639 639
640void TextEdit::editPaste() { 640void TextEdit::editPaste() {
641#ifndef QT_NO_CLIPBOARD 641#ifndef QT_NO_CLIPBOARD
642 editor->paste(); 642 editor->paste();
643#endif 643#endif
644} 644}
645 645
646void TextEdit::editFind() { 646void TextEdit::editFind() {
647 searchBar->show(); 647 searchBar->show();
648 searchEdit->setFocus(); 648 searchEdit->setFocus();
649} 649}
650 650
651void TextEdit::findNext() { 651void TextEdit::findNext() {
652 editor->find( searchEdit->text(), false, false ); 652 editor->find( searchEdit->text(), false, false );
653 653
654} 654}
655 655
656void TextEdit::findClose() { 656void TextEdit::findClose() {
657 searchBar->hide(); 657 searchBar->hide();
658} 658}
659 659
660void TextEdit::search() { 660void TextEdit::search() {
661 editor->find( searchEdit->text(), false, false ); 661 editor->find( searchEdit->text(), false, false );
662} 662}
663 663
664void TextEdit::newFile( const DocLnk &f ) { 664void TextEdit::newFile( const DocLnk &f ) {
665 DocLnk nf = f; 665 DocLnk nf = f;
666 nf.setType("text/plain"); 666 nf.setType("text/plain");
667 clear(); 667 clear();
668 setWState (WState_Reserved1 ); 668 setWState (WState_Reserved1 );
669 editor->setFocus(); 669 editor->setFocus();
670 doc = new DocLnk(nf); 670 doc = new DocLnk(nf);
671 currentFileName = "Unnamed"; 671 currentFileName = "Unnamed";
672 qDebug("newFile "+currentFileName); 672 qDebug("newFile "+currentFileName);
673 updateCaption( currentFileName); 673 updateCaption( currentFileName);
674// editor->setEdited( false); 674// editor->setEdited( false);
675} 675}
676 676
677void TextEdit::openDotFile( const QString &f ) { 677void TextEdit::openDotFile( const QString &f ) {
678 if(!currentFileName.isEmpty()) { 678 if(!currentFileName.isEmpty()) {
679 currentFileName=f; 679 currentFileName=f;
680 680
681 qDebug("openFile dotfile " + currentFileName); 681 qDebug("openFile dotfile " + currentFileName);
682 QString txt; 682 QString txt;
683 QFile file(f); 683 QFile file(f);
684 file.open(IO_ReadWrite); 684 file.open(IO_ReadWrite);
685 QTextStream t(&file); 685 QTextStream t(&file);
686 while ( !t.atEnd()) { 686 while ( !t.atEnd()) {
687 txt+=t.readLine(); 687 txt+=t.readLine();
688 } 688 }
689 editor->setText(txt); 689 editor->setText(txt);
690 editor->setEdited( false); 690 editor->setEdited( false);
691 edited1=false; 691 edited1=false;
692 edited=false; 692 edited=false;
693 693
694 694
695 } 695 }
696 updateCaption( currentFileName); 696 updateCaption( currentFileName);
697} 697}
698 698
699void TextEdit::openFile( const QString &f ) { 699void TextEdit::openFile( const QString &f ) {
700 qDebug("filename is "+ f); 700 qDebug("filename is "+ f);
701 QString filer; 701 QString filer;
702 QFileInfo fi( f); 702 QFileInfo fi( f);
703// bFromDocView = true; 703// bFromDocView = true;
704 if(f.find(".desktop",0,true) != -1 && !openDesktop ) { 704 if(f.find(".desktop",0,true) != -1 && !openDesktop ) {
705 switch ( QMessageBox::warning(this,tr("Text Editor"), 705 switch ( QMessageBox::warning(this,tr("Text Editor"),
706 tr("Text Editor has detected<BR>you selected a <B>.desktop</B> 706 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
707file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), 707file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
708 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 708 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
709 case 0: 709 case 0:
710 filer = f; 710 filer = f;
711 break; 711 break;
712 case 1: 712 case 1:
713 DocLnk sf(f); 713 DocLnk sf(f);
714 filer = sf.file(); 714 filer = sf.file();
715 break; 715 break;
716 } 716 }
717 } else if(fi.baseName().left(1) == "") { 717 } else if(fi.baseName().left(1) == "") {
718 currentFileName=f; 718 currentFileName=f;
719 openDotFile(currentFileName); 719 openDotFile(currentFileName);
720 } else { 720 } else {
721 DocLnk sf(f); 721 DocLnk sf(f);
722 filer = sf.file(); 722 filer = sf.file();
723 if(filer.right(1) == "/") 723 if(filer.right(1) == "/")
724 filer = f; 724 filer = f;
725 } 725 }
726 726
727 DocLnk nf; 727 DocLnk nf;
728 nf.setType("text/plain"); 728 nf.setType("text/plain");
729 nf.setFile(filer); 729 nf.setFile(filer);
730 currentFileName=filer; 730 currentFileName=filer;
731 731
732 nf.setName(fi.baseName()); 732 nf.setName(fi.baseName());
733 openFile(nf); 733 openFile(nf);
734 734
735 qDebug("openFile string "+currentFileName); 735 qDebug("openFile string "+currentFileName);
736 736
737 showEditTools(); 737 showEditTools();
738 // Show filename in caption 738 // Show filename in caption
739 QString name = filer; 739 QString name = filer;
740 int sep = name.findRev( '/' ); 740 int sep = name.findRev( '/' );
741 if ( sep > 0 ) 741 if ( sep > 0 )
742 name = name.mid( sep+1 ); 742 name = name.mid( sep+1 );
743 updateCaption( name ); 743 updateCaption( name );
744} 744}
745 745
746void TextEdit::openFile( const DocLnk &f ) { 746void TextEdit::openFile( const DocLnk &f ) {
747// clear(); 747// clear();
748// bFromDocView = true; 748// bFromDocView = true;
749 FileManager fm; 749 FileManager fm;
750 QString txt; 750 QString txt;
751 currentFileName=f.file(); 751 currentFileName=f.file();
752 qDebug("openFile doclnk " + currentFileName); 752 qDebug("openFile doclnk " + currentFileName);
753 if ( !fm.loadFile( f, txt ) ) { 753 if ( !fm.loadFile( f, txt ) ) {
754 // ####### could be a new file 754 // ####### could be a new file
755 qDebug( "Cannot open file" ); 755 qDebug( "Cannot open file" );
756 } 756 }
757// fileNew(); 757// fileNew();
758 if ( doc ) 758 if ( doc )
759 delete doc; 759 delete doc;
760 doc = new DocLnk(f); 760 doc = new DocLnk(f);
761 editor->setText(txt); 761 editor->setText(txt);
762 editor->setEdited( false); 762 editor->setEdited( false);
763 edited1=false; 763 edited1=false;
764 edited=false; 764 edited=false;
765 765
766 doc->setName(currentFileName); 766 doc->setName(currentFileName);
767 updateCaption(); 767 updateCaption();
768} 768}
769 769
770void TextEdit::showEditTools() { 770void TextEdit::showEditTools() {
771 menu->show(); 771 menu->show();
772 editBar->show(); 772 editBar->show();
773 if(!useSearchBar) 773 if(!useSearchBar)
774 searchBar->hide(); 774 searchBar->hide();
775 else 775 else
776 searchBar->show(); 776 searchBar->show();
777 setWState (WState_Reserved1 ); 777 setWState (WState_Reserved1 );
778} 778}
779 779
780/*! 780/*!
781 unprompted save */ 781 unprompted save */
782bool TextEdit::save() { 782bool TextEdit::save() {
783 QString file = doc->file(); 783 QString file = doc->file();