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