author | llornkcor <llornkcor> | 2002-02-18 14:52:54 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-18 14:52:54 (UTC) |
commit | 00f89d28e669140eb50f1f220c389f88fba1105c (patch) (unidiff) | |
tree | deb87bb87d855bbacddc79d8a0a79edfb1cf1cd8 | |
parent | 9741205aa0b0892b870d2b7df7c5dd7e25b0bb18 (diff) | |
download | opie-00f89d28e669140eb50f1f220c389f88fba1105c.zip opie-00f89d28e669140eb50f1f220c389f88fba1105c.tar.gz opie-00f89d28e669140eb50f1f220c389f88fba1105c.tar.bz2 |
fixed filesave and fileopen cancel
-rw-r--r-- | core/apps/textedit/fileSaver.cpp | 16 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 52 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 2 |
3 files changed, 42 insertions, 28 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp index d01daee..88608cc 100644 --- a/core/apps/textedit/fileSaver.cpp +++ b/core/apps/textedit/fileSaver.cpp | |||
@@ -1,104 +1,111 @@ | |||
1 | /**************************************************************************** | 1 | /**************************************************************************** |
2 | ** copyright 2001 ljp ljp@llornkcor.com | 2 | ** copyright 2001 ljp ljp@llornkcor.com |
3 | ** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp | 3 | ** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp |
4 | ** | 4 | ** |
5 | ** This file may be distributed and/or modified under the terms of the | 5 | ** This file may be distributed and/or modified under the terms of the |
6 | ** GNU General Public License version 2 as published by the Free Software | 6 | ** GNU General Public License version 2 as published by the Free Software |
7 | ** Foundation and appearing in the file LICENSE.GPL included in the | 7 | ** Foundation and appearing in the file LICENSE.GPL included in the |
8 | ** packaging of this file. | 8 | ** packaging of this file. |
9 | ** | 9 | ** |
10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
12 | ** | 12 | ** |
13 | ****************************************************************************/ | 13 | ****************************************************************************/ |
14 | #include "fileSaver.h" | 14 | #include "fileSaver.h" |
15 | #include <qpe/config.h> | 15 | #include <qpe/config.h> |
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | 17 | ||
18 | #include <qlistview.h> | 18 | #include <qlistview.h> |
19 | #include <qpushbutton.h> | 19 | #include <qpushbutton.h> |
20 | #include <qfile.h> | 20 | #include <qfile.h> |
21 | #include <qmessagebox.h> | 21 | #include <qmessagebox.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #include <qlineedit.h> | 23 | #include <qlineedit.h> |
24 | 24 | ||
25 | fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) | 25 | fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) |
26 | : QDialog( parent, name, modal, fl ) | 26 | : QDialog( parent, name, modal, fl ) |
27 | { | 27 | { |
28 | if ( !name ) | 28 | if ( !name ) |
29 | setName( "fileSaver" ); | 29 | setName( "fileSaver" ); |
30 | resize( 236, 280 ); | 30 | resize( 236, 280 ); |
31 | setCaption(tr( "Save file" ) ); | 31 | setCaption(tr( "Save file" ) ); |
32 | // filterStr=currentFileName; | 32 | QFileInfo fi(currentFileName); |
33 | QString tmpFileName=fi.fileName(); | ||
34 | // qDebug( tmpFileName); | ||
33 | 35 | ||
34 | dirLabel = new QLabel(this, "DirLabel"); | 36 | dirLabel = new QLabel(this, "DirLabel"); |
35 | dirLabel->setText(currentDir.canonicalPath()); | 37 | dirLabel->setText(currentDir.canonicalPath()); |
36 | dirLabel->setGeometry(10,4,230,30); | 38 | dirLabel->setGeometry(10,4,230,30); |
37 | 39 | ||
38 | ListView = new QListView( this, "ListView" ); | 40 | ListView = new QListView( this, "ListView" ); |
39 | ListView->addColumn( tr( "Name" ) ); | 41 | ListView->addColumn( tr( "Name" ) ); |
40 | ListView->setColumnWidth(0,140); | 42 | ListView->setColumnWidth(0,140); |
41 | ListView->setSorting( 2, FALSE); | 43 | ListView->setSorting( 2, FALSE); |
42 | ListView->addColumn( tr( "Size" ) ); | 44 | ListView->addColumn( tr( "Size" ) ); |
43 | ListView->setColumnWidth(1,59); | 45 | ListView->setColumnWidth(1,59); |
44 | // ListView->setMultiSelection(true); | 46 | // ListView->setMultiSelection(true); |
45 | // ListView->setSelectionMode(QListView::Extended); | 47 | // ListView->setSelectionMode(QListView::Extended); |
46 | 48 | ||
47 | ListView->setAllColumnsShowFocus( TRUE ); | 49 | ListView->setAllColumnsShowFocus( TRUE ); |
48 | ListView->setGeometry( QRect( 10, 35, 220, 160 ) ); | 50 | ListView->setGeometry( QRect( 10, 35, 220, 160 ) ); |
49 | 51 | ||
50 | fileEdit= new QLineEdit(this); | 52 | fileEdit= new QLineEdit(this); |
51 | fileEdit->setGeometry( QRect( 10, 230, 200, 25)); | 53 | fileEdit->setGeometry( QRect( 10, 230, 200, 25)); |
52 | fileEdit->setText(currentFileName); | 54 | |
53 | // signals and slots connections | 55 | fileEdit->setText( tmpFileName); |
56 | |||
57 | // signals and slots connections | ||
54 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); | 58 | connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); |
55 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); | 59 | connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); |
56 | currentDir.setPath(QDir::currentDirPath() ); | 60 | |
61 | // tmpFileName=fi.FilePath(); | ||
62 | // qDebug( tmpFileName); | ||
63 | currentDir.setPath( QDir::currentDirPath() ); | ||
57 | populateList(); | 64 | populateList(); |
58 | } | 65 | } |
59 | 66 | ||
60 | fileSaver::~fileSaver() | 67 | fileSaver::~fileSaver() |
61 | { | 68 | { |
62 | } | 69 | } |
63 | 70 | ||
64 | 71 | ||
65 | void fileSaver::populateList() | 72 | void fileSaver::populateList() |
66 | { | 73 | { |
67 | ListView->clear(); | 74 | ListView->clear(); |
68 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); | 75 | currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); |
69 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); | 76 | currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); |
70 | currentDir.setMatchAllDirs(TRUE); | 77 | currentDir.setMatchAllDirs(TRUE); |
71 | 78 | ||
72 | currentDir.setNameFilter("*"); | 79 | currentDir.setNameFilter("*"); |
73 | QString fileL, fileS; | 80 | QString fileL, fileS; |
74 | const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); | 81 | const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); |
75 | QFileInfoListIterator it(*list); | 82 | QFileInfoListIterator it(*list); |
76 | QFileInfo *fi; | 83 | QFileInfo *fi; |
77 | while ( (fi=it.current()) ) { | 84 | while ( (fi=it.current()) ) { |
78 | 85 | ||
79 | if (fi->isSymLink() ){ | 86 | if (fi->isSymLink() ){ |
80 | QString symLink=fi->readLink(); | 87 | QString symLink=fi->readLink(); |
81 | // qDebug("Symlink detected "+symLink); | 88 | // qDebug("Symlink detected "+symLink); |
82 | QFileInfo sym( symLink); | 89 | QFileInfo sym( symLink); |
83 | fileS.sprintf( "%10li", sym.size() ); | 90 | fileS.sprintf( "%10li", sym.size() ); |
84 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); | 91 | fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); |
85 | 92 | ||
86 | } else { | 93 | } else { |
87 | // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); | 94 | // // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); |
88 | fileS.sprintf( "%10li", fi->size() ); | 95 | fileS.sprintf( "%10li", fi->size() ); |
89 | fileL.sprintf( "%s",fi->fileName().data() ); | 96 | fileL.sprintf( "%s",fi->fileName().data() ); |
90 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { | 97 | if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { |
91 | fileL+="/"; | 98 | fileL+="/"; |
92 | // qDebug(currentDir.canonicalPath()+fileL); | 99 | // qDebug(currentDir.canonicalPath()+fileL); |
93 | } | 100 | } |
94 | } | 101 | } |
95 | item= new QListViewItem( ListView,fileL,fileS ); | 102 | item= new QListViewItem( ListView,fileL,fileS ); |
96 | ++it; | 103 | ++it; |
97 | } | 104 | } |
98 | ListView->setSorting( 2, FALSE); | 105 | ListView->setSorting( 2, FALSE); |
99 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); | 106 | dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); |
100 | 107 | ||
101 | 108 | ||
102 | } | 109 | } |
103 | 110 | ||
104 | void fileSaver::upDir() | 111 | void fileSaver::upDir() |
@@ -115,50 +122,51 @@ void fileSaver::listClicked(QListViewItem *selectedItem) | |||
115 | QString strItem=selectedItem->text(0); | 122 | QString strItem=selectedItem->text(0); |
116 | QString strSize=selectedItem->text(1); | 123 | QString strSize=selectedItem->text(1); |
117 | // qDebug("strItem is "+strItem); | 124 | // qDebug("strItem is "+strItem); |
118 | strSize.stripWhiteSpace(); | 125 | strSize.stripWhiteSpace(); |
119 | // qDebug(strSize); | 126 | // qDebug(strSize); |
120 | 127 | ||
121 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink | 128 | if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink |
122 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); | 129 | QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); |
123 | // qDebug("strItem symlink is "+strItem2); | 130 | // qDebug("strItem symlink is "+strItem2); |
124 | if(QDir(strItem2).exists() ) { | 131 | if(QDir(strItem2).exists() ) { |
125 | currentDir.cd(strItem2, TRUE); | 132 | currentDir.cd(strItem2, TRUE); |
126 | populateList(); | 133 | populateList(); |
127 | } | 134 | } |
128 | } else { // not a symlink | 135 | } else { // not a symlink |
129 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { | 136 | if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { |
130 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { | 137 | if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { |
131 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); | 138 | strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); |
132 | currentDir.cd(strItem,FALSE); | 139 | currentDir.cd(strItem,FALSE); |
133 | // qDebug("Path is "+strItem); | 140 | // qDebug("Path is "+strItem); |
134 | populateList(); | 141 | populateList(); |
135 | } else { | 142 | } else { |
136 | currentDir.cdUp(); | 143 | currentDir.cdUp(); |
137 | populateList(); | 144 | populateList(); |
138 | } | 145 | } |
139 | if(QDir(strItem).exists()){ | 146 | if(QDir(strItem).exists()){ |
140 | currentDir.cd(strItem, TRUE); | 147 | currentDir.cd(strItem, TRUE); |
141 | populateList(); | 148 | populateList(); |
142 | } | 149 | } |
143 | } // else | 150 | } // else |
144 | // if( QFile::exists(strItem ) ) { | 151 | // if( QFile::exists(strItem ) ) { |
145 | // qDebug("We found our files!!"); | 152 | // qDebug("We found our files!!"); |
146 | 153 | ||
147 | // OnOK(); | 154 | // OnOK(); |
148 | } //end not symlink | 155 | } //end not symlink |
149 | chdir(strItem.latin1()); | 156 | chdir(strItem.latin1()); |
150 | 157 | ||
151 | 158 | ||
152 | } | 159 | } |
153 | 160 | ||
154 | 161 | ||
155 | void fileSaver::OnOK() | 162 | void fileSaver::OnOK() |
156 | { | 163 | { |
157 | // reject(); | 164 | // reject(); |
158 | } | 165 | } |
159 | 166 | ||
160 | void fileSaver::accept() { | 167 | void fileSaver::accept() { |
161 | selectedFileName = fileEdit->text(); | 168 | selectedFileName = fileEdit->text(); |
162 | selectedFileName = currentDir.canonicalPath()+ selectedFileName; | 169 | selectedFileName = currentDir.canonicalPath()+ selectedFileName; |
170 | qDebug("goint to save "+selectedFileName); | ||
163 | reject(); | 171 | reject(); |
164 | } | 172 | } |
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 14bc496..429c195 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -440,327 +440,333 @@ void TextEdit::setFontSize(int sz, bool round_down_not_up) | |||
440 | { | 440 | { |
441 | int s=10; | 441 | int s=10; |
442 | for (int i=0; i<nfontsizes; i++) { | 442 | for (int i=0; i<nfontsizes; i++) { |
443 | if ( fontsize[i] == sz ) { | 443 | if ( fontsize[i] == sz ) { |
444 | s = sz; | 444 | s = sz; |
445 | break; | 445 | break; |
446 | } else if ( round_down_not_up ) { | 446 | } else if ( round_down_not_up ) { |
447 | if ( fontsize[i] < sz ) | 447 | if ( fontsize[i] < sz ) |
448 | s = fontsize[i]; | 448 | s = fontsize[i]; |
449 | } else { | 449 | } else { |
450 | if ( fontsize[i] > sz ) { | 450 | if ( fontsize[i] > sz ) { |
451 | s = fontsize[i]; | 451 | s = fontsize[i]; |
452 | break; | 452 | break; |
453 | } | 453 | } |
454 | } | 454 | } |
455 | } | 455 | } |
456 | 456 | ||
457 | QFont f = editor->font(); | 457 | QFont f = editor->font(); |
458 | f.setPointSize(s); | 458 | f.setPointSize(s); |
459 | editor->setFont(f); | 459 | editor->setFont(f); |
460 | 460 | ||
461 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 461 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
462 | zout->setEnabled(s != fontsize[0]); | 462 | zout->setEnabled(s != fontsize[0]); |
463 | } | 463 | } |
464 | 464 | ||
465 | void TextEdit::setBold(bool y) | 465 | void TextEdit::setBold(bool y) |
466 | { | 466 | { |
467 | QFont f = editor->font(); | 467 | QFont f = editor->font(); |
468 | f.setBold(y); | 468 | f.setBold(y); |
469 | editor->setFont(f); | 469 | editor->setFont(f); |
470 | } | 470 | } |
471 | 471 | ||
472 | void TextEdit::setItalic(bool y) | 472 | void TextEdit::setItalic(bool y) |
473 | { | 473 | { |
474 | QFont f = editor->font(); | 474 | QFont f = editor->font(); |
475 | f.setItalic(y); | 475 | f.setItalic(y); |
476 | editor->setFont(f); | 476 | editor->setFont(f); |
477 | } | 477 | } |
478 | 478 | ||
479 | void TextEdit::setWordWrap(bool y) | 479 | void TextEdit::setWordWrap(bool y) |
480 | { | 480 | { |
481 | bool state = editor->edited(); | 481 | bool state = editor->edited(); |
482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
483 | editor->setEdited( state ); | 483 | editor->setEdited( state ); |
484 | } | 484 | } |
485 | 485 | ||
486 | void TextEdit::fileNew() | 486 | void TextEdit::fileNew() |
487 | { | 487 | { |
488 | save(); | 488 | if( !bFromDocView ) { |
489 | save(); | ||
490 | } | ||
489 | newFile(DocLnk()); | 491 | newFile(DocLnk()); |
490 | } | 492 | } |
491 | 493 | ||
492 | void TextEdit::fileOpen() | 494 | void TextEdit::fileOpen() |
493 | { | 495 | { |
494 | // if ( !save() ) { | 496 | // if ( !save() ) { |
495 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 497 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
496 | // tr( "Text Editor was unable to\n" | 498 | // tr( "Text Editor was unable to\n" |
497 | // "save your changes.\n" | 499 | // "save your changes.\n" |
498 | // "Free some space and try again.\n" | 500 | // "Free some space and try again.\n" |
499 | // "\nContinue anyway?" ), | 501 | // "\nContinue anyway?" ), |
500 | // QMessageBox::Yes|QMessageBox::Escape, | 502 | // QMessageBox::Yes|QMessageBox::Escape, |
501 | // QMessageBox::No|QMessageBox::Default ) | 503 | // QMessageBox::No|QMessageBox::Default ) |
502 | // != QMessageBox::Yes ) | 504 | // != QMessageBox::Yes ) |
503 | // return; | 505 | // return; |
504 | // else { | 506 | // else { |
505 | // delete doc; | 507 | // delete doc; |
506 | // doc = 0; | 508 | // doc = 0; |
507 | // } | 509 | // } |
508 | // } | 510 | // } |
509 | menu->hide(); | 511 | menu->hide(); |
510 | editBar->hide(); | 512 | editBar->hide(); |
511 | searchBar->hide(); | 513 | searchBar->hide(); |
512 | clearWState (WState_Reserved1 ); | 514 | clearWState (WState_Reserved1 ); |
513 | editorStack->raiseWidget( fileSelector ); | 515 | editorStack->raiseWidget( fileSelector ); |
514 | fileSelector->reread(); | 516 | fileSelector->reread(); |
515 | updateCaption(); | 517 | updateCaption(currentFileName); |
516 | } | 518 | } |
517 | 519 | ||
518 | void TextEdit::newFileOpen() | 520 | void TextEdit::newFileOpen() |
519 | { | 521 | { |
520 | fileBrowser *browseForFiles; | 522 | fileBrowser *browseForFiles; |
521 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); | 523 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); |
522 | browseForFiles->exec(); | 524 | if( browseForFiles->exec()!= 0 ) { |
523 | QString selFile= browseForFiles->selectedFileName; | 525 | QString selFile= browseForFiles->selectedFileName; |
524 | QStringList fileList=browseForFiles->fileList; | 526 | QStringList fileList=browseForFiles->fileList; |
525 | qDebug(selFile); | 527 | qDebug(selFile); |
526 | QStringList::ConstIterator f; | 528 | QStringList::ConstIterator f; |
527 | QString fileTemp; | 529 | QString fileTemp; |
528 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 530 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
529 | fileTemp = *f; | 531 | fileTemp = *f; |
530 | fileTemp.right( fileTemp.length()-5); | 532 | fileTemp.right( fileTemp.length()-5); |
531 | QString fileName = fileTemp; | 533 | QString fileName = fileTemp; |
532 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 534 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
533 | currentFileName = fileName; | 535 | currentFileName = fileName; |
534 | qDebug("please open "+currentFileName); | 536 | // qDebug("please open "+currentFileName); |
535 | openFile(fileName ); | 537 | openFile(fileName ); |
538 | } | ||
536 | } | 539 | } |
537 | } | 540 | } |
538 | delete browseForFiles; | 541 | delete browseForFiles; |
539 | 542 | ||
540 | } | 543 | } |
541 | 544 | ||
542 | #if 0 | 545 | #if 0 |
543 | void TextEdit::slotFind() | 546 | void TextEdit::slotFind() |
544 | { | 547 | { |
545 | FindDialog frmFind( "Text Editor", this ); | 548 | FindDialog frmFind( "Text Editor", this ); |
546 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 549 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
547 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 550 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
548 | 551 | ||
549 | //case sensitive, backwards, [category] | 552 | //case sensitive, backwards, [category] |
550 | 553 | ||
551 | connect( editor, SIGNAL(notFound()), | 554 | connect( editor, SIGNAL(notFound()), |
552 | &frmFind, SLOT(slotNotFound()) ); | 555 | &frmFind, SLOT(slotNotFound()) ); |
553 | connect( editor, SIGNAL(searchWrapped()), | 556 | connect( editor, SIGNAL(searchWrapped()), |
554 | &frmFind, SLOT(slotWrapAround()) ); | 557 | &frmFind, SLOT(slotWrapAround()) ); |
555 | 558 | ||
556 | frmFind.exec(); | 559 | frmFind.exec(); |
557 | 560 | ||
558 | 561 | ||
559 | } | 562 | } |
560 | #endif | 563 | #endif |
561 | 564 | ||
562 | void TextEdit::fileRevert() | 565 | void TextEdit::fileRevert() |
563 | { | 566 | { |
564 | clear(); | 567 | clear(); |
565 | fileOpen(); | 568 | fileOpen(); |
566 | } | 569 | } |
567 | 570 | ||
568 | void TextEdit::editCut() | 571 | void TextEdit::editCut() |
569 | { | 572 | { |
570 | #ifndef QT_NO_CLIPBOARD | 573 | #ifndef QT_NO_CLIPBOARD |
571 | editor->cut(); | 574 | editor->cut(); |
572 | #endif | 575 | #endif |
573 | } | 576 | } |
574 | 577 | ||
575 | void TextEdit::editCopy() | 578 | void TextEdit::editCopy() |
576 | { | 579 | { |
577 | #ifndef QT_NO_CLIPBOARD | 580 | #ifndef QT_NO_CLIPBOARD |
578 | editor->copy(); | 581 | editor->copy(); |
579 | #endif | 582 | #endif |
580 | } | 583 | } |
581 | 584 | ||
582 | void TextEdit::editPaste() | 585 | void TextEdit::editPaste() |
583 | { | 586 | { |
584 | #ifndef QT_NO_CLIPBOARD | 587 | #ifndef QT_NO_CLIPBOARD |
585 | editor->paste(); | 588 | editor->paste(); |
586 | #endif | 589 | #endif |
587 | } | 590 | } |
588 | 591 | ||
589 | void TextEdit::editFind() | 592 | void TextEdit::editFind() |
590 | { | 593 | { |
591 | searchBar->show(); | 594 | searchBar->show(); |
592 | searchVisible = TRUE; | 595 | searchVisible = TRUE; |
593 | searchEdit->setFocus(); | 596 | searchEdit->setFocus(); |
594 | } | 597 | } |
595 | 598 | ||
596 | void TextEdit::findNext() | 599 | void TextEdit::findNext() |
597 | { | 600 | { |
598 | editor->find( searchEdit->text(), FALSE, FALSE ); | 601 | editor->find( searchEdit->text(), FALSE, FALSE ); |
599 | 602 | ||
600 | } | 603 | } |
601 | 604 | ||
602 | void TextEdit::findClose() | 605 | void TextEdit::findClose() |
603 | { | 606 | { |
604 | searchVisible = FALSE; | 607 | searchVisible = FALSE; |
605 | searchBar->hide(); | 608 | searchBar->hide(); |
606 | } | 609 | } |
607 | 610 | ||
608 | void TextEdit::search() | 611 | void TextEdit::search() |
609 | { | 612 | { |
610 | editor->find( searchEdit->text(), FALSE, FALSE ); | 613 | editor->find( searchEdit->text(), FALSE, FALSE ); |
611 | } | 614 | } |
612 | 615 | ||
613 | void TextEdit::newFile( const DocLnk &f ) | 616 | void TextEdit::newFile( const DocLnk &f ) |
614 | { | 617 | { |
615 | DocLnk nf = f; | 618 | DocLnk nf = f; |
616 | nf.setType("text/plain"); | 619 | nf.setType("text/plain"); |
617 | clear(); | 620 | clear(); |
618 | editorStack->raiseWidget( editor ); | 621 | editorStack->raiseWidget( editor ); |
619 | setWState (WState_Reserved1 ); | 622 | setWState (WState_Reserved1 ); |
620 | editor->setFocus(); | 623 | editor->setFocus(); |
621 | doc = new DocLnk(nf); | 624 | doc = new DocLnk(nf); |
622 | updateCaption(); | 625 | // updateCaption(); |
623 | } | 626 | } |
624 | 627 | ||
625 | void TextEdit::openFile( const QString &f ) | 628 | void TextEdit::openFile( const QString &f ) |
626 | { | 629 | { |
627 | bFromDocView = TRUE; | 630 | bFromDocView = TRUE; |
628 | DocLnk nf; | 631 | DocLnk nf; |
629 | nf.setType("text/plain"); | 632 | nf.setType("text/plain"); |
630 | nf.setFile(f); | 633 | nf.setFile(f); |
631 | openFile(nf); | 634 | openFile(nf); |
632 | showEditTools(); | 635 | showEditTools(); |
633 | // Show filename in caption | 636 | // Show filename in caption |
634 | QString name = f; | 637 | QString name = f; |
635 | int sep = name.findRev( '/' ); | 638 | int sep = name.findRev( '/' ); |
636 | if ( sep > 0 ) | 639 | if ( sep > 0 ) |
637 | name = name.mid( sep+1 ); | 640 | name = name.mid( sep+1 ); |
638 | updateCaption( name ); | 641 | updateCaption( name ); |
639 | } | 642 | } |
640 | 643 | ||
641 | void TextEdit::openFile( const DocLnk &f ) | 644 | void TextEdit::openFile( const DocLnk &f ) |
642 | { | 645 | { |
643 | // clear(); | 646 | // clear(); |
647 | bFromDocView = TRUE; | ||
644 | FileManager fm; | 648 | FileManager fm; |
645 | QString txt; | 649 | QString txt; |
646 | if ( !fm.loadFile( f, txt ) ) { | 650 | if ( !fm.loadFile( f, txt ) ) { |
647 | // ####### could be a new file | 651 | // ####### could be a new file |
648 | qDebug( "Cannot open file" ); | 652 | qDebug( "Cannot open file" ); |
649 | 653 | ||
650 | //return; | 654 | //return; |
651 | } | 655 | } |
652 | 656 | ||
653 | fileNew(); | 657 | fileNew(); |
654 | if ( doc ) | 658 | if ( doc ) |
655 | delete doc; | 659 | delete doc; |
656 | doc = new DocLnk(f); | 660 | doc = new DocLnk(f); |
657 | editor->setText(txt); | 661 | editor->setText(txt); |
658 | editor->setEdited(FALSE); | 662 | editor->setEdited(FALSE); |
659 | updateCaption(); | 663 | updateCaption(currentFileName); |
660 | } | 664 | } |
661 | 665 | ||
662 | void TextEdit::showEditTools() | 666 | void TextEdit::showEditTools() |
663 | { | 667 | { |
664 | // if ( !doc ) | 668 | // if ( !doc ) |
665 | // close(); | 669 | // close(); |
666 | // clear(); | 670 | // clear(); |
667 | fileSelector->hide(); | 671 | fileSelector->hide(); |
668 | menu->show(); | 672 | menu->show(); |
669 | editBar->show(); | 673 | editBar->show(); |
670 | if ( searchVisible ) | 674 | if ( searchVisible ) |
671 | searchBar->show(); | 675 | searchBar->show(); |
672 | updateCaption(); | 676 | // updateCaption(); |
673 | editorStack->raiseWidget( editor ); | 677 | editorStack->raiseWidget( editor ); |
674 | setWState (WState_Reserved1 ); | 678 | setWState (WState_Reserved1 ); |
675 | } | 679 | } |
676 | 680 | ||
677 | bool TextEdit::save() | 681 | bool TextEdit::save() |
678 | { | 682 | { |
679 | // case of nothing to save... | 683 | // case of nothing to save... |
680 | if ( !doc || !bFromDocView) | 684 | if ( !doc || !bFromDocView) |
681 | return true; | 685 | return true; |
682 | if ( !editor->edited() ) { | 686 | if ( !editor->edited() ) { |
683 | delete doc; | 687 | delete doc; |
684 | doc = 0; | 688 | doc = 0; |
685 | return true; | 689 | return true; |
686 | } | 690 | } |
687 | 691 | ||
688 | QString rt = editor->text(); | 692 | QString rt = editor->text(); |
689 | 693 | qDebug(currentFileName); | |
690 | if(currentFileName.isEmpty() || currentFileName == "Unnamed") { | 694 | |
695 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | ||
691 | 696 | ||
692 | if ( doc->name().isEmpty() ) { | 697 | if ( doc->name().isEmpty() ) { |
693 | QString pt = rt.simplifyWhiteSpace(); | 698 | QString pt = rt.simplifyWhiteSpace(); |
694 | int i = pt.find( ' ' ); | 699 | int i = pt.find( ' ' ); |
695 | QString docname = pt; | 700 | QString docname = pt; |
696 | if ( i > 0 ) | 701 | if ( i > 0 ) |
697 | docname = pt.left( i ); | 702 | docname = pt.left( i ); |
698 | // remove "." at the beginning | 703 | // remove "." at the beginning |
699 | while( docname.startsWith( "." ) ) | 704 | while( docname.startsWith( "." ) ) |
700 | docname = docname.mid( 1 ); | 705 | docname = docname.mid( 1 ); |
701 | docname.replace( QRegExp("/"), "_" ); | 706 | docname.replace( QRegExp("/"), "_" ); |
702 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 707 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
703 | if ( docname.length() > 40 ) | 708 | if ( docname.length() > 40 ) |
704 | docname = docname.left(40); | 709 | docname = docname.left(40); |
705 | if ( docname.isEmpty() ) | 710 | if ( docname.isEmpty() ) |
706 | docname = "Empty Text"; | 711 | docname = "Empty Text"; |
707 | doc->setName(docname); | 712 | doc->setName(docname); |
708 | currentFileName=docname; | 713 | currentFileName=docname; |
709 | } | 714 | } |
710 | } | 715 | } |
711 | 716 | ||
712 | fileSaver *fileSaveDlg; | 717 | fileSaver *fileSaveDlg; |
713 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | 718 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); |
714 | fileSaveDlg->exec(); | 719 | if( fileSaveDlg->exec() != 0 ) { |
715 | QString fileNm=fileSaveDlg->selectedFileName; | 720 | QString fileNm=fileSaveDlg->selectedFileName; |
716 | qDebug("save filename "+fileNm); | 721 | qDebug("save filename "+fileNm); |
717 | doc->setName(fileNm); | 722 | doc->setName(fileNm); |
718 | updateCaption(); | 723 | updateCaption(fileNm); |
724 | } | ||
719 | delete fileSaveDlg; | 725 | delete fileSaveDlg; |
720 | 726 | ||
721 | FileManager fm; | 727 | FileManager fm; |
722 | if ( !fm.saveFile( *doc, rt ) ) { | 728 | if ( !fm.saveFile( *doc, rt ) ) { |
723 | return false; | 729 | return false; |
724 | } | 730 | } |
725 | delete doc; | 731 | delete doc; |
726 | doc = 0; | 732 | doc = 0; |
727 | editor->setEdited( false ); | 733 | editor->setEdited( false ); |
728 | return true; | 734 | return true; |
729 | } | 735 | } |
730 | 736 | ||
731 | void TextEdit::clear() | 737 | void TextEdit::clear() |
732 | { | 738 | { |
733 | delete doc; | 739 | delete doc; |
734 | doc = 0; | 740 | doc = 0; |
735 | editor->clear(); | 741 | editor->clear(); |
736 | } | 742 | } |
737 | 743 | ||
738 | void TextEdit::updateCaption( const QString &name ) | 744 | void TextEdit::updateCaption( const QString &name ) |
739 | { | 745 | { |
740 | if ( !doc ) | 746 | if ( !doc ) |
741 | setCaption( tr("Text Editor") ); | 747 | setCaption( tr("Text Editor") ); |
742 | else { | 748 | else { |
743 | QString s = name; | 749 | QString s = name; |
744 | if ( s.isNull() ) | 750 | if ( s.isNull() ) |
745 | s = doc->name(); | 751 | s = doc->name(); |
746 | if ( s.isEmpty() ) { | 752 | if ( s.isEmpty() ) { |
747 | s = tr( "Unnamed" ); | 753 | s = tr( "Unnamed" ); |
748 | currentFileName=s; | 754 | currentFileName=s; |
749 | } | 755 | } |
750 | setCaption( s + " - " + tr("Text Editor") ); | 756 | setCaption( s + " - " + tr("Text Editor") ); |
751 | } | 757 | } |
752 | } | 758 | } |
753 | 759 | ||
754 | void TextEdit::setDocument(const QString& fileref) | 760 | void TextEdit::setDocument(const QString& fileref) |
755 | { | 761 | { |
756 | bFromDocView = TRUE; | 762 | bFromDocView = TRUE; |
757 | openFile(DocLnk(fileref)); | 763 | openFile(DocLnk(fileref)); |
758 | // showEditTools(); | 764 | // showEditTools(); |
759 | } | 765 | } |
760 | 766 | ||
761 | void TextEdit::closeEvent( QCloseEvent *e ) | 767 | void TextEdit::closeEvent( QCloseEvent *e ) |
762 | { | 768 | { |
763 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 769 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
764 | e->ignore(); | 770 | e->ignore(); |
765 | repaint(); | 771 | repaint(); |
766 | // fileRevert(); | 772 | // fileRevert(); |
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 4e469cc..4bfb260 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -10,96 +10,96 @@ | |||
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 | 20 | // additions made by L.J. Potter Sun 02-17-2002 22:27:46 |
21 | 21 | ||
22 | #ifndef TEXTEDIT_H | 22 | #ifndef TEXTEDIT_H |
23 | #define TEXTEDIT_H | 23 | #define TEXTEDIT_H |
24 | 24 | ||
25 | #define QTEXTEDIT_OPEN_API | 25 | #define QTEXTEDIT_OPEN_API |
26 | 26 | ||
27 | #include <qpe/filemanager.h> | 27 | #include <qpe/filemanager.h> |
28 | 28 | ||
29 | #include <qmainwindow.h> | 29 | #include <qmainwindow.h> |
30 | #include <qmultilineedit.h> | 30 | #include <qmultilineedit.h> |
31 | #include <qlist.h> | 31 | #include <qlist.h> |
32 | #include <qmap.h> | 32 | #include <qmap.h> |
33 | 33 | ||
34 | class QWidgetStack; | 34 | class QWidgetStack; |
35 | class QToolButton; | 35 | class QToolButton; |
36 | class QPopupMenu; | 36 | class QPopupMenu; |
37 | class QToolBar; | 37 | class QToolBar; |
38 | class QLineEdit; | 38 | class QLineEdit; |
39 | class QAction; | 39 | class QAction; |
40 | class FileSelector; | 40 | class FileSelector; |
41 | class QpeEditor; | 41 | class QpeEditor; |
42 | 42 | ||
43 | class TextEdit : public QMainWindow | 43 | class TextEdit : public QMainWindow |
44 | { | 44 | { |
45 | Q_OBJECT | 45 | Q_OBJECT |
46 | 46 | ||
47 | public: | 47 | public: |
48 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 48 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
49 | ~TextEdit(); | 49 | ~TextEdit(); |
50 | 50 | ||
51 | void openFile( const QString & ); | 51 | void openFile( const QString & ); |
52 | 52 | ||
53 | protected: | 53 | protected: |
54 | void closeEvent( QCloseEvent *e ); | 54 | void closeEvent( QCloseEvent *e ); |
55 | 55 | ||
56 | private slots: | 56 | private slots: |
57 | void setDocument(const QString&); | 57 | void setDocument(const QString&); |
58 | void changeFont(); | 58 | void changeFont(); |
59 | void fileNew(); | 59 | void fileNew(); |
60 | void fileRevert(); | 60 | void fileRevert(); |
61 | void fileOpen(); | 61 | void fileOpen(); |
62 | void newFileOpen(); | 62 | void newFileOpen(); |
63 | bool save(); | 63 | bool save(); |
64 | 64 | ||
65 | void editCut(); | 65 | void editCut(); |
66 | void editCopy(); | 66 | void editCopy(); |
67 | void editPaste(); | 67 | void editPaste(); |
68 | void editFind(); | 68 | void editFind(); |
69 | 69 | ||
70 | void findNext(); | 70 | void findNext(); |
71 | void findClose(); | 71 | void findClose(); |
72 | 72 | ||
73 | void search(); | 73 | void search(); |
74 | void accept(); | 74 | void accept(); |
75 | 75 | ||
76 | void newFile( const DocLnk & ); | 76 | void newFile( const DocLnk & ); |
77 | void openFile( const DocLnk & ); | 77 | void openFile( const DocLnk & ); |
78 | void showEditTools(); | 78 | void showEditTools(); |
79 | 79 | ||
80 | void zoomIn(); | 80 | void zoomIn(); |
81 | void zoomOut(); | 81 | void zoomOut(); |
82 | void setBold(bool y); | 82 | void setBold(bool y); |
83 | void setItalic(bool y); | 83 | void setItalic(bool y); |
84 | void setWordWrap(bool y); | 84 | void setWordWrap(bool y); |
85 | 85 | ||
86 | private: | 86 | private: |
87 | void colorChanged( const QColor &c ); | 87 | void colorChanged( const QColor &c ); |
88 | void clear(); | 88 | void clear(); |
89 | void updateCaption( const QString &name=QString::null ); | 89 | void updateCaption( const QString &name=QString::null ); |
90 | void setFontSize(int sz, bool round_down_not_up); | 90 | void setFontSize(int sz, bool round_down_not_up); |
91 | 91 | ||
92 | private: | 92 | private: |
93 | QWidgetStack *editorStack; | 93 | QWidgetStack *editorStack; |
94 | FileSelector *fileSelector; | 94 | FileSelector *fileSelector; |
95 | QpeEditor* editor; | 95 | QpeEditor* editor; |
96 | QToolBar *menu, *editBar, *searchBar; | 96 | QToolBar *menu, *editBar, *searchBar; |
97 | QLineEdit *searchEdit; | 97 | QLineEdit *searchEdit; |
98 | DocLnk *doc; | 98 | DocLnk *doc; |
99 | bool searchVisible; | 99 | bool searchVisible; |
100 | bool bFromDocView; | 100 | bool bFromDocView; |
101 | QAction *zin, *zout; | 101 | QAction *zin, *zout; |
102 | QString currentFileName; | 102 | QString currentFileName; |
103 | }; | 103 | }; |
104 | 104 | ||
105 | #endif | 105 | #endif |