author | llornkcor <llornkcor> | 2002-11-09 20:52:24 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-09 20:52:24 (UTC) |
commit | c1f59c3404e9c0312e3d0418d5286b12d2e98d92 (patch) (unidiff) | |
tree | a7700be7ae3af4656c365c664e4db9822fdf7e3a /core/apps/textedit | |
parent | b9cd525928755b78fe5041c4ea9d674a457dfa0d (diff) | |
download | opie-c1f59c3404e9c0312e3d0418d5286b12d2e98d92.zip opie-c1f59c3404e9c0312e3d0418d5286b12d2e98d92.tar.gz opie-c1f59c3404e9c0312e3d0418d5286b12d2e98d92.tar.bz2 |
fixes and options. commandline now works a bit more sane, and makes new file if not found
-rw-r--r-- | core/apps/textedit/main.cpp | 4 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 214 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 6 |
3 files changed, 153 insertions, 71 deletions
diff --git a/core/apps/textedit/main.cpp b/core/apps/textedit/main.cpp index d0d37d2..4f27667 100644 --- a/core/apps/textedit/main.cpp +++ b/core/apps/textedit/main.cpp | |||
@@ -29,6 +29,6 @@ int main( int argc, char **argv ) | |||
29 | TextEdit e; | 29 | TextEdit e; |
30 | a.showMainDocumentWidget(&e); | 30 | a.showMainDocumentWidget(&e); |
31 | if ( argc == 3 && argv[1] == QCString("-f") ) | 31 | // if ( argc == 3 && argv[1] == QCString("-f") ) |
32 | e.openFile(argv[2]); | 32 | // e.openFile(argv[2]); |
33 | 33 | ||
34 | a.exec(); | 34 | a.exec(); |
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index e3b8361..464671a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -44,4 +44,5 @@ | |||
44 | #include <qpe/qcopenvelope_qws.h> | 44 | #include <qpe/qcopenvelope_qws.h> |
45 | 45 | ||
46 | #include <qtextstream.h> | ||
46 | #include <qdatetime.h> | 47 | #include <qdatetime.h> |
47 | #include <qclipboard.h> | 48 | #include <qclipboard.h> |
@@ -60,5 +61,5 @@ | |||
60 | #include <qcombo.h> | 61 | #include <qcombo.h> |
61 | #include <qlayout.h> | 62 | #include <qlayout.h> |
62 | 63 | #include <qapplication.h> | |
63 | #include <unistd.h> | 64 | #include <unistd.h> |
64 | #include <sys/stat.h> | 65 | #include <sys/stat.h> |
@@ -172,9 +173,8 @@ class QpeEditor : public QMultiLineEdit | |||
172 | public: | 173 | public: |
173 | QpeEditor( QWidget *parent, const char * name = 0 ) | 174 | QpeEditor( QWidget *parent, const char * name = 0 ) |
174 | : QMultiLineEdit( parent, name ) | 175 | : QMultiLineEdit( parent, name ) { |
175 | { | ||
176 | clearTableFlags(); | 176 | clearTableFlags(); |
177 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); | 177 | setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); |
178 | } | 178 | } |
179 | 179 | ||
180 | void find( const QString &txt, bool caseSensitive, | 180 | void find( const QString &txt, bool caseSensitive, |
@@ -225,7 +225,5 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, | |||
225 | col = 0; | 225 | col = 0; |
226 | } | 226 | } |
227 | |||
228 | } | 227 | } |
229 | |||
230 | } | 228 | } |
231 | 229 | ||
@@ -358,4 +356,10 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
358 | filePermAction->addTo( advancedMenu); | 356 | filePermAction->addTo( advancedMenu); |
359 | 357 | ||
358 | searchBarAction = new QAction( tr("Search Bar Open"), QString::null, 0, this, 0 ); | ||
359 | connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); | ||
360 | searchBarAction->setToggleAction(TRUE); | ||
361 | searchBarAction->addTo( advancedMenu); | ||
362 | |||
363 | |||
360 | font->insertSeparator(); | 364 | font->insertSeparator(); |
361 | 365 | ||
@@ -411,12 +415,17 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
411 | editor-> setFont ( defaultFont ); | 415 | editor-> setFont ( defaultFont ); |
412 | 416 | ||
413 | updateCaption(); | 417 | // updateCaption(); |
414 | 418 | ||
415 | cfg.setGroup ( "View" ); | 419 | cfg.setGroup ( "View" ); |
416 | 420 | ||
417 | promptExit = cfg. readBoolEntry ( "PromptExit", false ); | 421 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
418 | openDesktop = cfg. readBoolEntry ( "OpenDesktop", true ); | 422 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
419 | filePerms = cfg. readBoolEntry ( "FilePermissions", false ); | 423 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
420 | 424 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | |
425 | |||
426 | if(useSearchBar) { | ||
427 | searchBarAction->setOn(true); | ||
428 | } else{ | ||
429 | } | ||
421 | if(promptExit ) nAdvanced->setOn ( true ); | 430 | if(promptExit ) nAdvanced->setOn ( true ); |
422 | if(openDesktop) desktopAction->setOn ( true ); | 431 | if(openDesktop) desktopAction->setOn ( true ); |
@@ -427,11 +436,26 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
427 | setWordWrap ( wrap ); | 436 | setWordWrap ( wrap ); |
428 | 437 | ||
429 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 438 | if( qApp->argc() > 0) { |
430 | nStart->setOn(TRUE); | 439 | currentFileName=qApp->argv()[1]; |
431 | fileNew(); | 440 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<< "+currentFileName); |
432 | } else { | 441 | QFileInfo fi(currentFileName); |
433 | fileOpen(); | 442 | |
434 | } | 443 | if(fi.baseName().left(1) == "") { |
435 | 444 | openDotFile(currentFileName); | |
445 | } else { | ||
446 | |||
447 | nStart->setOn(TRUE); | ||
448 | openFile(currentFileName); | ||
449 | } | ||
450 | } else | ||
451 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | ||
452 | |||
453 | nStart->setOn(TRUE); | ||
454 | fileNew(); | ||
455 | } else { | ||
456 | |||
457 | fileOpen(); | ||
458 | } | ||
459 | |||
436 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 460 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
437 | } | 461 | } |
@@ -448,16 +472,17 @@ void TextEdit::cleanUp() { | |||
448 | cfg. setGroup ( "Font" ); | 472 | cfg. setGroup ( "Font" ); |
449 | QFont f = editor->font(); | 473 | QFont f = editor->font(); |
450 | cfg. writeEntry ( "Family", f. family ( )); | 474 | cfg.writeEntry ( "Family", f. family ( )); |
451 | cfg. writeEntry ( "Size", f. pointSize ( )); | 475 | cfg.writeEntry ( "Size", f. pointSize ( )); |
452 | cfg. writeEntry ( "Weight", f. weight ( )); | 476 | cfg.writeEntry ( "Weight", f. weight ( )); |
453 | cfg. writeEntry ( "Italic", f. italic ( )); | 477 | cfg.writeEntry ( "Italic", f. italic ( )); |
454 | 478 | ||
455 | cfg. setGroup ( "View" ); | 479 | cfg.setGroup ( "View" ); |
456 | cfg. writeEntry ( "Wrap", editor-> wordWrap ( ) == QMultiLineEdit::WidgetWidth ); | 480 | cfg.writeEntry ( "Wrap", editor-> wordWrap ( ) == QMultiLineEdit::WidgetWidth ); |
457 | cfg. writeEntry ( "FileView", viewSelection ); | 481 | cfg.writeEntry ( "FileView", viewSelection ); |
458 | 482 | ||
459 | cfg. writeEntry ( "PromptExit", promptExit ); | 483 | cfg.writeEntry ( "PromptExit", promptExit ); |
460 | cfg. writeEntry ( "OpenDesktop", openDesktop ); | 484 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
461 | cfg. writeEntry ( "FilePermissions", filePerms ); | 485 | cfg.writeEntry ( "FilePermissions", filePerms ); |
486 | cfg.writeEntry ( "SearchBar", useSearchBar ); | ||
462 | } | 487 | } |
463 | 488 | ||
@@ -521,4 +546,17 @@ void TextEdit::setWordWrap(bool y) { | |||
521 | } | 546 | } |
522 | 547 | ||
548 | void TextEdit::setSearchBar(bool b) { | ||
549 | useSearchBar=b; | ||
550 | Config cfg("TextEdit"); | ||
551 | cfg.setGroup("View"); | ||
552 | cfg.writeEntry ( "SearchBar", b ); | ||
553 | searchBarAction->setOn(b); | ||
554 | if(b) | ||
555 | searchBar->show(); | ||
556 | else | ||
557 | searchBar->hide(); | ||
558 | editor->setFocus(); | ||
559 | } | ||
560 | |||
523 | void TextEdit::fileNew() { | 561 | void TextEdit::fileNew() { |
524 | // if( !bFromDocView ) { | 562 | // if( !bFromDocView ) { |
@@ -547,8 +585,8 @@ void TextEdit::fileOpen() { | |||
547 | 585 | ||
548 | void TextEdit::doSearchBar() { | 586 | void TextEdit::doSearchBar() { |
549 | Config cfg("TextEdit"); | 587 | if(!useSearchBar) |
550 | cfg.setGroup("View"); | ||
551 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | ||
552 | searchBar->hide(); | 588 | searchBar->hide(); |
589 | else | ||
590 | searchBar->show(); | ||
553 | } | 591 | } |
554 | 592 | ||
@@ -599,7 +637,7 @@ void TextEdit::editFind() { | |||
599 | searchVisible = TRUE; | 637 | searchVisible = TRUE; |
600 | searchEdit->setFocus(); | 638 | searchEdit->setFocus(); |
601 | Config cfg("TextEdit"); | 639 | // Config cfg("TextEdit"); |
602 | cfg.setGroup("View"); | 640 | // cfg.setGroup("View"); |
603 | cfg.writeEntry("SearchBar","Opened"); | 641 | // cfg.writeEntry("SearchBar","Opened"); |
604 | 642 | ||
605 | } | 643 | } |
@@ -613,8 +651,8 @@ void TextEdit::findClose() { | |||
613 | searchVisible = FALSE; | 651 | searchVisible = FALSE; |
614 | searchBar->hide(); | 652 | searchBar->hide(); |
615 | Config cfg("TextEdit"); | 653 | // Config cfg("TextEdit"); |
616 | cfg.setGroup("View"); | 654 | // cfg.setGroup("View"); |
617 | cfg.writeEntry("SearchBar","Closed"); | 655 | // cfg.writeEntry("SearchBar","Closed"); |
618 | cfg.write(); | 656 | // cfg.write(); |
619 | } | 657 | } |
620 | 658 | ||
@@ -636,13 +674,36 @@ void TextEdit::newFile( const DocLnk &f ) { | |||
636 | } | 674 | } |
637 | 675 | ||
676 | void TextEdit::openDotFile( const QString &f ) { | ||
677 | if(!currentFileName.isEmpty()) { | ||
678 | currentFileName=f; | ||
679 | |||
680 | qDebug("openFile dotfile " + currentFileName); | ||
681 | QString txt; | ||
682 | QFile file(f); | ||
683 | file.open(IO_ReadWrite); | ||
684 | QTextStream t(&file); | ||
685 | while ( !t.atEnd()) { | ||
686 | txt+=t.readLine(); | ||
687 | } | ||
688 | editor->setText(txt); | ||
689 | editor->setEdited( FALSE); | ||
690 | edited1=FALSE; | ||
691 | edited=FALSE; | ||
692 | |||
693 | |||
694 | } | ||
695 | updateCaption( currentFileName); | ||
696 | } | ||
697 | |||
638 | void TextEdit::openFile( const QString &f ) { | 698 | void TextEdit::openFile( const QString &f ) { |
639 | qDebug("filename is "+ f); | 699 | qDebug("filename is "+ f); |
640 | QString filer; | 700 | QString filer; |
701 | QFileInfo fi( f); | ||
641 | // bFromDocView = TRUE; | 702 | // bFromDocView = TRUE; |
642 | if(f.find(".desktop",0,TRUE) != -1 && !openDesktop) { | 703 | if(f.find(".desktop",0,TRUE) != -1 && !openDesktop) { |
643 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 704 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
644 | 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> |
645 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 706 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
646 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 707 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
647 | case 0: | 708 | case 0: |
648 | filer = f; | 709 | filer = f; |
@@ -653,9 +714,12 @@ file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | |||
653 | break; | 714 | break; |
654 | } | 715 | } |
716 | } else if(fi.baseName().left(1) == "") { | ||
717 | currentFileName=f; | ||
718 | openDotFile(currentFileName); | ||
655 | } else { | 719 | } else { |
656 | DocLnk sf(f); | 720 | DocLnk sf(f); |
657 | filer = sf.file(); | 721 | filer = sf.file(); |
658 | if(filer.right(1) == "/") | 722 | if(filer.right(1) == "/") |
659 | filer = f; | 723 | filer = f; |
660 | } | 724 | } |
661 | 725 | ||
@@ -664,9 +728,10 @@ file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | |||
664 | nf.setFile(filer); | 728 | nf.setFile(filer); |
665 | currentFileName=filer; | 729 | currentFileName=filer; |
666 | QFileInfo fi( currentFileName); | ||
667 | nf.setName(fi.baseName()); | ||
668 | qDebug("openFile string "+currentFileName); | ||
669 | 730 | ||
670 | openFile(nf); | 731 | nf.setName(fi.baseName()); |
732 | openFile(nf); | ||
733 | |||
734 | qDebug("openFile string "+currentFileName); | ||
735 | |||
671 | showEditTools(); | 736 | showEditTools(); |
672 | // Show filename in caption | 737 | // Show filename in caption |
@@ -709,5 +774,5 @@ void TextEdit::showEditTools() { | |||
709 | editBar->show(); | 774 | editBar->show(); |
710 | if ( searchVisible ) | 775 | if ( searchVisible ) |
711 | searchBar->show(); | 776 | searchBar->show(); |
712 | // updateCaption(); | 777 | // updateCaption(); |
713 | setWState (WState_Reserved1 ); | 778 | setWState (WState_Reserved1 ); |
@@ -877,27 +942,41 @@ void TextEdit::clear() { | |||
877 | 942 | ||
878 | void TextEdit::updateCaption( const QString &name ) { | 943 | void TextEdit::updateCaption( const QString &name ) { |
879 | if ( !doc ) | 944 | |
880 | setCaption( tr("Text Editor") ); | 945 | if ( name.isEmpty() ) |
946 | setCaption( tr("Text Editor") ); | ||
881 | else { | 947 | else { |
882 | QString s = name; | 948 | QString s = name; |
883 | if ( s.isNull() ) | 949 | if ( s.isNull() ) |
884 | s = doc->name(); | 950 | s = doc->name(); |
885 | if ( s.isEmpty() ) { | 951 | if ( s.isEmpty() ) { |
886 | s = tr( "Unnamed" ); | 952 | s = tr( "Unnamed" ); |
887 | currentFileName=s; | 953 | currentFileName=s; |
888 | } | 954 | } |
889 | if(s.left(1) == "/") | 955 | if(s.left(1) == "/") |
890 | s = s.right(s.length()-1); | 956 | s = s.right(s.length()-1); |
891 | setCaption( s + " - " + tr("Text Editor") ); | 957 | setCaption( s + " - " + tr("Text Editor") ); |
892 | } | 958 | } |
893 | } | 959 | } |
894 | 960 | ||
895 | void TextEdit::setDocument(const QString& fileref) { | 961 | void TextEdit::setDocument(const QString& fileref) { |
896 | bFromDocView = TRUE; | 962 | if(fileref != "Unnamed") { |
897 | openFile(fileref); | 963 | currentFileName=fileref; |
898 | editor->setEdited(TRUE); | 964 | qDebug("setDocument"); |
899 | edited1=FALSE; | 965 | QFileInfo fi(currentFileName); |
900 | edited=TRUE; | 966 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
901 | doSearchBar(); | 967 | if(fi.baseName().left(1) == "") { |
968 | // openDotFile(currentFileName); | ||
969 | } else { | ||
970 | qDebug("setDoc open"); | ||
971 | bFromDocView = TRUE; | ||
972 | openFile(fileref); | ||
973 | editor->setEdited(TRUE); | ||
974 | edited1=FALSE; | ||
975 | edited=TRUE; | ||
976 | |||
977 | // doSearchBar(); | ||
978 | } | ||
979 | } | ||
980 | updateCaption( currentFileName); | ||
902 | } | 981 | } |
903 | 982 | ||
@@ -1001,2 +1080,3 @@ void TextEdit::editPasteTimeDate() { | |||
1001 | #endif | 1080 | #endif |
1002 | } | 1081 | } |
1082 | |||
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 4848051..a95e742 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -58,5 +58,5 @@ public: | |||
58 | 58 | ||
59 | QPopupMenu *font; | 59 | QPopupMenu *font; |
60 | QAction *nStart, *nFileDlgOpt, *nAdvanced, *desktopAction, *filePermAction; | 60 | QAction *nStart, *nFileDlgOpt, *nAdvanced, *desktopAction, *filePermAction, *searchBarAction; |
61 | bool edited, edited1; | 61 | bool edited, edited1; |
62 | void openFile( const QString & ); | 62 | void openFile( const QString & ); |
@@ -66,5 +66,5 @@ public slots: | |||
66 | void receive(const QCString&, const QByteArray&); | 66 | void receive(const QCString&, const QByteArray&); |
67 | protected: | 67 | protected: |
68 | bool fileIs, useAdvancedFeatures, promptExit, openDesktop, filePerms; | 68 | bool fileIs, useAdvancedFeatures, promptExit, openDesktop, filePerms, useSearchBar; |
69 | void closeEvent( QCloseEvent *e ); | 69 | void closeEvent( QCloseEvent *e ); |
70 | void doSearchBar(); | 70 | void doSearchBar(); |
@@ -107,6 +107,8 @@ private slots: | |||
107 | void setItalic(bool y); | 107 | void setItalic(bool y); |
108 | void setWordWrap(bool y); | 108 | void setWordWrap(bool y); |
109 | void setSearchBar(bool); | ||
109 | 110 | ||
110 | private: | 111 | private: |
112 | void openDotFile(const QString &); | ||
111 | void colorChanged( const QColor &c ); | 113 | void colorChanged( const QColor &c ); |
112 | void clear(); | 114 | void clear(); |