author | llornkcor <llornkcor> | 2002-11-09 23:11:09 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-11-09 23:11:09 (UTC) |
commit | 0c81c6287771d5ad416c2ddf0ae32ad5ce18c116 (patch) (unidiff) | |
tree | 9e565161740031ed63f51ce09377b7e2ef2bb4a7 | |
parent | c1f59c3404e9c0312e3d0418d5286b12d2e98d92 (diff) | |
download | opie-0c81c6287771d5ad416c2ddf0ae32ad5ce18c116.zip opie-0c81c6287771d5ad416c2ddf0ae32ad5ce18c116.tar.gz opie-0c81c6287771d5ad416c2ddf0ae32ad5ce18c116.tar.bz2 |
various fixes.. saveAs and quit stuff
-rw-r--r-- | core/apps/textedit/textedit.cpp | 281 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 4 |
2 files changed, 137 insertions, 148 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 464671a..1c3b393 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -191,37 +191,37 @@ private: | |||
191 | }; | 191 | }; |
192 | 192 | ||
193 | 193 | ||
194 | void QpeEditor::find ( const QString &txt, bool caseSensitive, | 194 | void QpeEditor::find ( const QString &txt, bool caseSensitive, |
195 | bool backwards ) | 195 | bool backwards ) |
196 | { | 196 | { |
197 | static bool wrap = FALSE; | 197 | static bool wrap = false; |
198 | int line, col; | 198 | int line, col; |
199 | if ( wrap ) { | 199 | if ( wrap ) { |
200 | if ( !backwards ) | 200 | if ( !backwards ) |
201 | line = col = 0; | 201 | line = col = 0; |
202 | wrap = FALSE; | 202 | wrap = false; |
203 | // emit searchWrapped(); | 203 | // emit searchWrapped(); |
204 | } else { | 204 | } else { |
205 | getCursorPosition( &line, &col ); | 205 | getCursorPosition( &line, &col ); |
206 | } | 206 | } |
207 | //ignore backwards for now.... | 207 | //ignore backwards for now.... |
208 | if ( !backwards ) { | 208 | if ( !backwards ) { |
209 | for ( ; ; ) { | 209 | for ( ; ; ) { |
210 | if ( line >= numLines() ) { | 210 | if ( line >= numLines() ) { |
211 | wrap = TRUE; | 211 | wrap = true; |
212 | //emit notFound(); | 212 | //emit notFound(); |
213 | break; | 213 | break; |
214 | } | 214 | } |
215 | int findCol = getString( line )->find( txt, col, caseSensitive ); | 215 | int findCol = getString( line )->find( txt, col, caseSensitive ); |
216 | if ( findCol >= 0 ) { | 216 | if ( findCol >= 0 ) { |
217 | setCursorPosition( line, findCol, FALSE ); | 217 | setCursorPosition( line, findCol, false ); |
218 | col = findCol + txt.length(); | 218 | col = findCol + txt.length(); |
219 | setCursorPosition( line, col, TRUE ); | 219 | setCursorPosition( line, col, true ); |
220 | 220 | ||
221 | //found = TRUE; | 221 | //found = true; |
222 | break; | 222 | break; |
223 | } | 223 | } |
224 | line++; | 224 | line++; |
225 | col = 0; | 225 | col = 0; |
226 | } | 226 | } |
227 | } | 227 | } |
@@ -236,28 +236,28 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, | |||
236 | 236 | ||
237 | 237 | ||
238 | static const int nfontsizes = 6; | 238 | static const int nfontsizes = 6; |
239 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 239 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
240 | 240 | ||
241 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | 241 | TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) |
242 | : QMainWindow( parent, name, f ), bFromDocView( FALSE ) | 242 | : QMainWindow( parent, name, f ), bFromDocView( false ) |
243 | { | 243 | { |
244 | doc = 0; | 244 | doc = 0; |
245 | edited=FALSE; | 245 | edited=false; |
246 | edited1=FALSE; | 246 | edited1=false; |
247 | setToolBarsMovable( FALSE ); | 247 | setToolBarsMovable( false ); |
248 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 248 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
249 | 249 | ||
250 | channel = new QCopChannel( "QPE/Application/textedit", this ); | 250 | channel = new QCopChannel( "QPE/Application/textedit", this ); |
251 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 251 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
252 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 252 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
253 | 253 | ||
254 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 254 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
255 | 255 | ||
256 | QPEToolBar *bar = new QPEToolBar( this ); | 256 | QPEToolBar *bar = new QPEToolBar( this ); |
257 | bar->setHorizontalStretchable( TRUE ); | 257 | bar->setHorizontalStretchable( true ); |
258 | menu = bar; | 258 | menu = bar; |
259 | 259 | ||
260 | QPEMenuBar *mb = new QPEMenuBar( bar ); | 260 | QPEMenuBar *mb = new QPEMenuBar( bar ); |
261 | QPopupMenu *file = new QPopupMenu( this ); | 261 | QPopupMenu *file = new QPopupMenu( this ); |
262 | QPopupMenu *edit = new QPopupMenu( this ); | 262 | QPopupMenu *edit = new QPopupMenu( this ); |
263 | QPopupMenu *advancedMenu = new QPopupMenu(this); | 263 | QPopupMenu *advancedMenu = new QPopupMenu(this); |
@@ -329,53 +329,53 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
329 | 329 | ||
330 | font->insertSeparator(); | 330 | font->insertSeparator(); |
331 | font->insertItem(tr("Advanced Features"), advancedMenu); | 331 | font->insertItem(tr("Advanced Features"), advancedMenu); |
332 | 332 | ||
333 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 333 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
334 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 334 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
335 | wa->setToggleAction(TRUE); | 335 | wa->setToggleAction(true); |
336 | wa->addTo( advancedMenu); | 336 | wa->addTo( advancedMenu); |
337 | 337 | ||
338 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 338 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
339 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 339 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
340 | nStart->setToggleAction(TRUE); | 340 | nStart->setToggleAction(true); |
341 | nStart->addTo( advancedMenu ); | 341 | nStart->addTo( advancedMenu ); |
342 | 342 | ||
343 | nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 ); | 343 | nAdvanced = new QAction( tr("Prompt on Exit"), QString::null, 0, this, 0 ); |
344 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); | 344 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doPrompt(bool) ) ); |
345 | nAdvanced->setToggleAction(TRUE); | 345 | nAdvanced->setToggleAction(true); |
346 | nAdvanced->addTo( advancedMenu ); | 346 | nAdvanced->addTo( advancedMenu ); |
347 | 347 | ||
348 | desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 ); | 348 | desktopAction = new QAction( tr("Always open linked file"), QString::null, 0, this, 0 ); |
349 | connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); | 349 | connect( desktopAction, SIGNAL( toggled(bool) ), this, SLOT( doDesktop(bool) ) ); |
350 | desktopAction->setToggleAction(TRUE); | 350 | desktopAction->setToggleAction(true); |
351 | desktopAction->addTo( advancedMenu); | 351 | desktopAction->addTo( advancedMenu); |
352 | 352 | ||
353 | filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 ); | 353 | filePermAction = new QAction( tr("File Permissions"), QString::null, 0, this, 0 ); |
354 | connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); | 354 | connect( filePermAction, SIGNAL( toggled(bool) ), this, SLOT( doFilePerms(bool) ) ); |
355 | filePermAction->setToggleAction(TRUE); | 355 | filePermAction->setToggleAction(true); |
356 | filePermAction->addTo( advancedMenu); | 356 | filePermAction->addTo( advancedMenu); |
357 | 357 | ||
358 | searchBarAction = new QAction( tr("Search Bar Open"), QString::null, 0, this, 0 ); | 358 | searchBarAction = new QAction( tr("Search Bar Open"), QString::null, 0, this, 0 ); |
359 | connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); | 359 | connect( searchBarAction, SIGNAL( toggled(bool) ), this, SLOT( setSearchBar(bool) ) ); |
360 | searchBarAction->setToggleAction(TRUE); | 360 | searchBarAction->setToggleAction(true); |
361 | searchBarAction->addTo( advancedMenu); | 361 | searchBarAction->addTo( advancedMenu); |
362 | 362 | ||
363 | 363 | ||
364 | font->insertSeparator(); | 364 | font->insertSeparator(); |
365 | 365 | ||
366 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 366 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
367 | 367 | ||
368 | mb->insertItem( tr( "File" ), file ); | 368 | mb->insertItem( tr( "File" ), file ); |
369 | mb->insertItem( tr( "Edit" ), edit ); | 369 | mb->insertItem( tr( "Edit" ), edit ); |
370 | mb->insertItem( tr( "View" ), font ); | 370 | mb->insertItem( tr( "View" ), font ); |
371 | 371 | ||
372 | searchBar = new QPEToolBar(this); | 372 | searchBar = new QPEToolBar(this); |
373 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 373 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
374 | 374 | ||
375 | searchBar->setHorizontalStretchable( TRUE ); | 375 | searchBar->setHorizontalStretchable( true ); |
376 | 376 | ||
377 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 377 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
378 | searchBar->setStretchableWidget( searchEdit ); | 378 | searchBar->setStretchableWidget( searchEdit ); |
379 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 379 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
380 | this, SLOT( search() ) ); | 380 | this, SLOT( search() ) ); |
381 | 381 | ||
@@ -419,89 +419,95 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
419 | cfg.setGroup ( "View" ); | 419 | cfg.setGroup ( "View" ); |
420 | 420 | ||
421 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 421 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
422 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 422 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
423 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 423 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
424 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 424 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
425 | 425 | startWithNew = cfg.readBoolEntry ( "startNew", true); | |
426 | if(useSearchBar) { | 426 | |
427 | searchBarAction->setOn(true); | 427 | if(useSearchBar) searchBarAction->setOn(true); |
428 | } else{ | 428 | if(promptExit ) nAdvanced->setOn( true ); |
429 | } | 429 | if(openDesktop) desktopAction->setOn( true ); |
430 | if(promptExit ) nAdvanced->setOn ( true ); | 430 | if(filePerms) filePermAction->setOn( true ); |
431 | if(openDesktop) desktopAction->setOn ( true ); | 431 | if(startWithNew) nStart->setOn( true ); |
432 | if(filePerms) filePermAction->setOn ( true ); | ||
433 | 432 | ||
434 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 433 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
435 | wa-> setOn ( wrap ); | 434 | wa-> setOn ( wrap ); |
436 | setWordWrap ( wrap ); | 435 | setWordWrap ( wrap ); |
437 | 436 | ||
438 | if( qApp->argc() > 0) { | 437 | if( qApp->argc() > 1) { |
439 | currentFileName=qApp->argv()[1]; | 438 | currentFileName=qApp->argv()[1]; |
440 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<< "+currentFileName); | 439 | // qDebug("<<<<<<<<<<<<<<<<<<<<<<<< "+currentFileName+" %d",qApp->argc()); |
441 | QFileInfo fi(currentFileName); | 440 | QFileInfo fi(currentFileName); |
442 | |||
443 | if(fi.baseName().left(1) == "") { | ||
444 | openDotFile(currentFileName); | ||
445 | } else { | ||
446 | |||
447 | nStart->setOn(TRUE); | ||
448 | openFile(currentFileName); | ||
449 | } | ||
450 | } else | ||
451 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | ||
452 | 441 | ||
453 | nStart->setOn(TRUE); | 442 | if(fi.baseName().left(1) == "") { |
454 | fileNew(); | 443 | openDotFile(currentFileName); |
444 | } else { | ||
445 | openFile(currentFileName); | ||
446 | } | ||
455 | } else { | 447 | } else { |
456 | 448 | // qDebug("Do other thing"); | |
457 | fileOpen(); | 449 | if(startWithNew) { |
450 | openDotFile(""); | ||
451 | // fileNew(); | ||
452 | } else { | ||
453 | fileOpen(); | ||
454 | } | ||
458 | } | 455 | } |
459 | 456 | ||
460 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 457 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
461 | } | 458 | } |
462 | 459 | ||
463 | TextEdit::~TextEdit() { | 460 | TextEdit::~TextEdit() { |
464 | if( edited1 & promptExit ) | 461 | // qDebug("destr"); |
465 | saveAs(); | 462 | } |
463 | |||
464 | void TextEdit::closeEvent(QCloseEvent *) { | ||
465 | // qDebug("closing here"); | ||
466 | if( edited1 && promptExit) | ||
467 | saveAs(); | ||
468 | qApp->quit(); | ||
466 | } | 469 | } |
467 | 470 | ||
468 | void TextEdit::cleanUp() { | 471 | void TextEdit::cleanUp() { |
469 | qDebug("cleanUp");// save(); | 472 | // qDebug("cleanUp");// save(); |
470 | 473 | ||
471 | Config cfg ( "TextEdit" ); | 474 | Config cfg ( "TextEdit" ); |
472 | cfg. setGroup ( "Font" ); | 475 | cfg. setGroup ( "Font" ); |
473 | QFont f = editor->font(); | 476 | QFont f = editor->font(); |
474 | cfg.writeEntry ( "Family", f. family ( )); | 477 | cfg.writeEntry ( "Family", f. family ( )); |
475 | cfg.writeEntry ( "Size", f. pointSize ( )); | 478 | cfg.writeEntry ( "Size", f. pointSize ( )); |
476 | cfg.writeEntry ( "Weight", f. weight ( )); | 479 | cfg.writeEntry ( "Weight", f. weight ( )); |
477 | cfg.writeEntry ( "Italic", f. italic ( )); | 480 | cfg.writeEntry ( "Italic", f. italic ( )); |
478 | 481 | ||
479 | cfg.setGroup ( "View" ); | 482 | cfg.setGroup ( "View" ); |
480 | cfg.writeEntry ( "Wrap", editor-> wordWrap ( ) == QMultiLineEdit::WidgetWidth ); | 483 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
481 | cfg.writeEntry ( "FileView", viewSelection ); | 484 | cfg.writeEntry ( "FileView", viewSelection ); |
482 | 485 | ||
483 | cfg.writeEntry ( "PromptExit", promptExit ); | 486 | cfg.writeEntry ( "PromptExit", promptExit ); |
484 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 487 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
485 | cfg.writeEntry ( "FilePermissions", filePerms ); | 488 | cfg.writeEntry ( "FilePermissions", filePerms ); |
486 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 489 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
490 | cfg.writeEntry ( "startNew", startWithNew ); | ||
491 | |||
487 | } | 492 | } |
488 | 493 | ||
489 | 494 | ||
490 | void TextEdit::accept() { | 495 | void TextEdit::accept() { |
491 | if( edited1) | 496 | // qDebug("accept"); |
492 | saveAs(); | 497 | if( edited1) |
493 | exit(0); | 498 | saveAs(); |
499 | qApp->quit(); | ||
494 | } | 500 | } |
495 | 501 | ||
496 | void TextEdit::zoomIn() { | 502 | void TextEdit::zoomIn() { |
497 | setFontSize(editor->font().pointSize()+1,FALSE); | 503 | setFontSize(editor->font().pointSize()+1,false); |
498 | } | 504 | } |
499 | 505 | ||
500 | void TextEdit::zoomOut() { | 506 | void TextEdit::zoomOut() { |
501 | setFontSize(editor->font().pointSize()-1,TRUE); | 507 | setFontSize(editor->font().pointSize()-1,true); |
502 | } | 508 | } |
503 | 509 | ||
504 | 510 | ||
505 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 511 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
506 | int s=10; | 512 | int s=10; |
507 | for (int i=0; i<nfontsizes; i++) { | 513 | for (int i=0; i<nfontsizes; i++) { |
@@ -563,27 +569,26 @@ void TextEdit::fileNew() { | |||
563 | // saveAs(); | 569 | // saveAs(); |
564 | // } | 570 | // } |
565 | newFile(DocLnk()); | 571 | newFile(DocLnk()); |
566 | } | 572 | } |
567 | 573 | ||
568 | void TextEdit::fileOpen() { | 574 | void TextEdit::fileOpen() { |
569 | Config cfg("TextEdit"); | ||
570 | cfg.setGroup("View"); | ||
571 | // bool b=FALSE; | ||
572 | |||
573 | QMap<QString, QStringList> map; | 575 | QMap<QString, QStringList> map; |
574 | map.insert(tr("All"), QStringList() ); | 576 | map.insert(tr("All"), QStringList() ); |
575 | QStringList text; | 577 | QStringList text; |
576 | text << "text/*"; | 578 | text << "text/*"; |
577 | map.insert(tr("Text"), text ); | 579 | map.insert(tr("Text"), text ); |
578 | text << "*"; | 580 | text << "*"; |
579 | map.insert(tr("All"), text ); | 581 | map.insert(tr("All"), text ); |
580 | QString str = OFileDialog::getOpenFileName( 2, QPEApplication::documentDir(), QString::null, map); | 582 | QString str = OFileDialog::getOpenFileName( 2, |
583 | QPEApplication::documentDir(), | ||
584 | QString::null, map); | ||
581 | if(!str.isEmpty() ) | 585 | if(!str.isEmpty() ) |
582 | openFile( str ); | 586 | openFile( str ); |
583 | 587 | else | |
588 | updateCaption(); | ||
584 | } | 589 | } |
585 | 590 | ||
586 | void TextEdit::doSearchBar() { | 591 | void TextEdit::doSearchBar() { |
587 | if(!useSearchBar) | 592 | if(!useSearchBar) |
588 | searchBar->hide(); | 593 | searchBar->hide(); |
589 | else | 594 | else |
@@ -631,49 +636,39 @@ void TextEdit::editPaste() { | |||
631 | editor->paste(); | 636 | editor->paste(); |
632 | #endif | 637 | #endif |
633 | } | 638 | } |
634 | 639 | ||
635 | void TextEdit::editFind() { | 640 | void TextEdit::editFind() { |
636 | searchBar->show(); | 641 | searchBar->show(); |
637 | searchVisible = TRUE; | ||
638 | searchEdit->setFocus(); | 642 | searchEdit->setFocus(); |
639 | // Config cfg("TextEdit"); | ||
640 | // cfg.setGroup("View"); | ||
641 | // cfg.writeEntry("SearchBar","Opened"); | ||
642 | |||
643 | } | 643 | } |
644 | 644 | ||
645 | void TextEdit::findNext() { | 645 | void TextEdit::findNext() { |
646 | editor->find( searchEdit->text(), FALSE, FALSE ); | 646 | editor->find( searchEdit->text(), false, false ); |
647 | 647 | ||
648 | } | 648 | } |
649 | 649 | ||
650 | void TextEdit::findClose() { | 650 | void TextEdit::findClose() { |
651 | searchVisible = FALSE; | ||
652 | searchBar->hide(); | 651 | searchBar->hide(); |
653 | // Config cfg("TextEdit"); | ||
654 | // cfg.setGroup("View"); | ||
655 | // cfg.writeEntry("SearchBar","Closed"); | ||
656 | // cfg.write(); | ||
657 | } | 652 | } |
658 | 653 | ||
659 | void TextEdit::search() { | 654 | void TextEdit::search() { |
660 | editor->find( searchEdit->text(), FALSE, FALSE ); | 655 | editor->find( searchEdit->text(), false, false ); |
661 | } | 656 | } |
662 | 657 | ||
663 | void TextEdit::newFile( const DocLnk &f ) { | 658 | void TextEdit::newFile( const DocLnk &f ) { |
664 | DocLnk nf = f; | 659 | DocLnk nf = f; |
665 | nf.setType("text/plain"); | 660 | nf.setType("text/plain"); |
666 | clear(); | 661 | clear(); |
667 | setWState (WState_Reserved1 ); | 662 | setWState (WState_Reserved1 ); |
668 | editor->setFocus(); | 663 | editor->setFocus(); |
669 | doc = new DocLnk(nf); | 664 | doc = new DocLnk(nf); |
670 | currentFileName = "Unnamed"; | 665 | currentFileName = "Unnamed"; |
671 | qDebug("newFile "+currentFileName); | 666 | qDebug("newFile "+currentFileName); |
672 | updateCaption( currentFileName); | 667 | updateCaption( currentFileName); |
673 | // editor->setEdited( FALSE); | 668 | // editor->setEdited( false); |
674 | } | 669 | } |
675 | 670 | ||
676 | void TextEdit::openDotFile( const QString &f ) { | 671 | void TextEdit::openDotFile( const QString &f ) { |
677 | if(!currentFileName.isEmpty()) { | 672 | if(!currentFileName.isEmpty()) { |
678 | currentFileName=f; | 673 | currentFileName=f; |
679 | 674 | ||
@@ -683,27 +678,27 @@ void TextEdit::openDotFile( const QString &f ) { | |||
683 | file.open(IO_ReadWrite); | 678 | file.open(IO_ReadWrite); |
684 | QTextStream t(&file); | 679 | QTextStream t(&file); |
685 | while ( !t.atEnd()) { | 680 | while ( !t.atEnd()) { |
686 | txt+=t.readLine(); | 681 | txt+=t.readLine(); |
687 | } | 682 | } |
688 | editor->setText(txt); | 683 | editor->setText(txt); |
689 | editor->setEdited( FALSE); | 684 | editor->setEdited( false); |
690 | edited1=FALSE; | 685 | edited1=false; |
691 | edited=FALSE; | 686 | edited=false; |
692 | 687 | ||
693 | 688 | ||
694 | } | 689 | } |
695 | updateCaption( currentFileName); | 690 | updateCaption( currentFileName); |
696 | } | 691 | } |
697 | 692 | ||
698 | void TextEdit::openFile( const QString &f ) { | 693 | void TextEdit::openFile( const QString &f ) { |
699 | qDebug("filename is "+ f); | 694 | qDebug("filename is "+ f); |
700 | QString filer; | 695 | QString filer; |
701 | QFileInfo fi( f); | 696 | QFileInfo fi( f); |
702 | // bFromDocView = TRUE; | 697 | // bFromDocView = true; |
703 | if(f.find(".desktop",0,TRUE) != -1 && !openDesktop) { | 698 | if(f.find(".desktop",0,true) != -1 && !openDesktop) { |
704 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 699 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
705 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> | 700 | tr("Text Editor has detected<BR>you selected a <B>.desktop</B> |
706 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | 701 | file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), |
707 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 702 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
708 | case 0: | 703 | case 0: |
709 | filer = f; | 704 | filer = f; |
@@ -741,13 +736,13 @@ file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), | |||
741 | name = name.mid( sep+1 ); | 736 | name = name.mid( sep+1 ); |
742 | updateCaption( name ); | 737 | updateCaption( name ); |
743 | } | 738 | } |
744 | 739 | ||
745 | void TextEdit::openFile( const DocLnk &f ) { | 740 | void TextEdit::openFile( const DocLnk &f ) { |
746 | // clear(); | 741 | // clear(); |
747 | // bFromDocView = TRUE; | 742 | // bFromDocView = true; |
748 | FileManager fm; | 743 | FileManager fm; |
749 | QString txt; | 744 | QString txt; |
750 | currentFileName=f.file(); | 745 | currentFileName=f.file(); |
751 | qDebug("openFile doclnk " + currentFileName); | 746 | qDebug("openFile doclnk " + currentFileName); |
752 | if ( !fm.loadFile( f, txt ) ) { | 747 | if ( !fm.loadFile( f, txt ) ) { |
753 | // ####### could be a new file | 748 | // ####### could be a new file |
@@ -755,29 +750,27 @@ void TextEdit::openFile( const DocLnk &f ) { | |||
755 | } | 750 | } |
756 | // fileNew(); | 751 | // fileNew(); |
757 | if ( doc ) | 752 | if ( doc ) |
758 | delete doc; | 753 | delete doc; |
759 | doc = new DocLnk(f); | 754 | doc = new DocLnk(f); |
760 | editor->setText(txt); | 755 | editor->setText(txt); |
761 | editor->setEdited( FALSE); | 756 | editor->setEdited( false); |
762 | edited1=FALSE; | 757 | edited1=false; |
763 | edited=FALSE; | 758 | edited=false; |
764 | 759 | ||
765 | doc->setName(currentFileName); | 760 | doc->setName(currentFileName); |
766 | updateCaption(); | 761 | updateCaption(); |
767 | } | 762 | } |
768 | 763 | ||
769 | void TextEdit::showEditTools() { | 764 | void TextEdit::showEditTools() { |
770 | // if ( !doc ) | ||
771 | // close(); | ||
772 | // clear(); | ||
773 | menu->show(); | 765 | menu->show(); |
774 | editBar->show(); | 766 | editBar->show(); |
775 | if ( searchVisible ) | 767 | if(!useSearchBar) |
768 | searchBar->hide(); | ||
769 | else | ||
776 | searchBar->show(); | 770 | searchBar->show(); |
777 | // updateCaption(); | ||
778 | setWState (WState_Reserved1 ); | 771 | setWState (WState_Reserved1 ); |
779 | } | 772 | } |
780 | 773 | ||
781 | /*! | 774 | /*! |
782 | unprompted save */ | 775 | unprompted save */ |
783 | bool TextEdit::save() { | 776 | bool TextEdit::save() { |
@@ -813,15 +806,15 @@ bool TextEdit::save() { | |||
813 | } else { | 806 | } else { |
814 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); | 807 | QMessageBox::message(tr("Text Edit"),tr("Write Failed")); |
815 | return false; | 808 | return false; |
816 | } | 809 | } |
817 | 810 | ||
818 | } | 811 | } |
819 | editor->setEdited( FALSE); | 812 | editor->setEdited( false); |
820 | edited1=FALSE; | 813 | edited1=false; |
821 | edited=FALSE; | 814 | edited=false; |
822 | if(caption().left(1)=="*") | 815 | if(caption().left(1)=="*") |
823 | setCaption(caption().right(caption().length()-1)); | 816 | setCaption(caption().right(caption().length()-1)); |
824 | 817 | ||
825 | 818 | ||
826 | chmod( file.latin1(), mode); | 819 | chmod( file.latin1(), mode); |
827 | } | 820 | } |
@@ -832,79 +825,87 @@ bool TextEdit::save() { | |||
832 | 825 | ||
833 | /*! | 826 | /*! |
834 | prompted save */ | 827 | prompted save */ |
835 | bool TextEdit::saveAs() { | 828 | bool TextEdit::saveAs() { |
836 | qDebug("saveAsFile " + currentFileName); | 829 | qDebug("saveAsFile " + currentFileName); |
837 | // case of nothing to save... | 830 | // case of nothing to save... |
838 | if ( !doc ) { | 831 | // if ( !doc && !currentFileName.isEmpty()) { |
839 | //|| !bFromDocView) | 832 | // //|| !bFromDocView) |
840 | qDebug("no doc"); | 833 | // qDebug("no doc"); |
841 | return true; | 834 | // return true; |
842 | } | 835 | // } |
843 | if ( !editor->edited() ) { | 836 | // if ( !editor->edited() ) { |
844 | delete doc; | 837 | // delete doc; |
845 | doc = 0; | 838 | // doc = 0; |
846 | return true; | 839 | // return true; |
847 | } | 840 | // } |
848 | 841 | ||
849 | QString rt = editor->text(); | 842 | QString rt = editor->text(); |
850 | qDebug(currentFileName); | 843 | qDebug(currentFileName); |
851 | 844 | ||
852 | if( currentFileName.isEmpty() | 845 | if( currentFileName.isEmpty() |
853 | || currentFileName == tr("Unnamed") | 846 | || currentFileName == tr("Unnamed") |
854 | || currentFileName == tr("Text Editor")) { | 847 | || currentFileName == tr("Text Editor")) { |
855 | // qDebug("do silly TT filename thing"); | 848 | qDebug("do silly TT filename thing"); |
856 | if ( doc->name().isEmpty() ) { | 849 | // if ( doc && doc->name().isEmpty() ) { |
857 | QString pt = rt.simplifyWhiteSpace(); | 850 | QString pt = rt.simplifyWhiteSpace(); |
858 | int i = pt.find( ' ' ); | 851 | int i = pt.find( ' ' ); |
859 | QString docname = pt; | 852 | QString docname = pt; |
860 | if ( i > 0 ) | 853 | if ( i > 0 ) |
861 | docname = pt.left( i ); | 854 | docname = pt.left( i ); |
862 | // remove "." at the beginning | 855 | // remove "." at the beginning |
863 | while( docname.startsWith( "." ) ) | 856 | while( docname.startsWith( "." ) ) |
864 | docname = docname.mid( 1 ); | 857 | docname = docname.mid( 1 ); |
865 | docname.replace( QRegExp("/"), "_" ); | 858 | docname.replace( QRegExp("/"), "_" ); |
866 | // cut the length. filenames longer than that | 859 | // cut the length. filenames longer than that |
867 | //don't make sense and something goes wrong when they get too long. | 860 | //don't make sense and something goes wrong when they get too long. |
868 | if ( docname.length() > 40 ) | 861 | if ( docname.length() > 40 ) |
869 | docname = docname.left(40); | 862 | docname = docname.left(40); |
870 | if ( docname.isEmpty() ) | 863 | if ( docname.isEmpty() ) |
871 | docname = tr("Unnamed"); | 864 | docname = tr("Unnamed"); |
872 | doc->setName(docname); | 865 | if(doc) doc->setName(docname); |
873 | currentFileName=docname; | 866 | currentFileName=docname; |
874 | } | 867 | // } |
868 | // else | ||
869 | // qDebug("hmmmmmm"); | ||
875 | } | 870 | } |
876 | 871 | ||
872 | |||
877 | QMap<QString, QStringList> map; | 873 | QMap<QString, QStringList> map; |
878 | map.insert(tr("All"), QStringList() ); | 874 | map.insert(tr("All"), QStringList() ); |
879 | QStringList text; | 875 | QStringList text; |
880 | text << "text/*"; | 876 | text << "text/*"; |
881 | map.insert(tr("Text"), text ); | 877 | map.insert(tr("Text"), text ); |
882 | text << "*"; | 878 | text << "*"; |
883 | map.insert(tr("All"), text ); | 879 | map.insert(tr("All"), text ); |
884 | // if(currentFileName | 880 | |
881 | QFileInfo cuFi( currentFileName); | ||
882 | QString filee = cuFi.fileName(); | ||
883 | QString dire = cuFi.dirPath(); | ||
884 | if(dire==".") | ||
885 | dire = QPEApplication::documentDir(); | ||
885 | QString str = OFileDialog::getSaveFileName( 2, | 886 | QString str = OFileDialog::getSaveFileName( 2, |
886 | QPEApplication::documentDir(), | 887 | dire, |
887 | currentFileName, map); | 888 | filee, map); |
888 | 889 | ||
889 | if(!str.isEmpty() ) { | 890 | if(!str.isEmpty()) { |
890 | QString fileNm=str; | 891 | QString fileNm=str; |
891 | 892 | ||
892 | qDebug("saving filename "+fileNm); | 893 | qDebug("saving filename "+fileNm); |
893 | QFileInfo fi(fileNm); | 894 | QFileInfo fi(fileNm); |
894 | currentFileName=fi.fileName(); | 895 | currentFileName=fi.fileName(); |
895 | if(doc) { | 896 | if(doc) |
896 | // QString file = doc->file(); | 897 | // QString file = doc->file(); |
897 | // doc->removeFiles(); | 898 | // doc->removeFiles(); |
898 | delete doc; | 899 | delete doc; |
899 | DocLnk nf; | 900 | DocLnk nf; |
900 | nf.setType("text/plain"); | 901 | nf.setType("text/plain"); |
901 | nf.setFile( fileNm); | 902 | nf.setFile( fileNm); |
902 | doc = new DocLnk(nf); | 903 | doc = new DocLnk(nf); |
903 | // editor->setText(rt); | 904 | // editor->setText(rt); |
904 | // qDebug("openFile doclnk "+currentFileName); | 905 | qDebug("Saving file as "+currentFileName); |
905 | doc->setName( currentFileName); | 906 | doc->setName( currentFileName); |
906 | updateCaption( currentFileName); | 907 | updateCaption( currentFileName); |
907 | 908 | ||
908 | FileManager fm; | 909 | FileManager fm; |
909 | if ( !fm.saveFile( *doc, rt ) ) { | 910 | if ( !fm.saveFile( *doc, rt ) ) { |
910 | return false; | 911 | return false; |
@@ -918,13 +919,13 @@ bool TextEdit::saveAs() { | |||
918 | filePerm->showMaximized(); | 919 | filePerm->showMaximized(); |
919 | filePerm->exec(); | 920 | filePerm->exec(); |
920 | 921 | ||
921 | if( filePerm) | 922 | if( filePerm) |
922 | delete filePerm; | 923 | delete filePerm; |
923 | } | 924 | } |
924 | } | 925 | // } |
925 | editor->setEdited( false); | 926 | editor->setEdited( false); |
926 | edited1 = false; | 927 | edited1 = false; |
927 | edited = false; | 928 | edited = false; |
928 | if(caption().left(1)=="*") | 929 | if(caption().left(1)=="*") |
929 | setCaption(caption().right(caption().length()-1)); | 930 | setCaption(caption().right(caption().length()-1)); |
930 | 931 | ||
@@ -965,29 +966,24 @@ void TextEdit::setDocument(const QString& fileref) { | |||
965 | QFileInfo fi(currentFileName); | 966 | QFileInfo fi(currentFileName); |
966 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); | 967 | qDebug("basename:"+fi.baseName()+": current filenmame "+currentFileName); |
967 | if(fi.baseName().left(1) == "") { | 968 | if(fi.baseName().left(1) == "") { |
968 | // openDotFile(currentFileName); | 969 | // openDotFile(currentFileName); |
969 | } else { | 970 | } else { |
970 | qDebug("setDoc open"); | 971 | qDebug("setDoc open"); |
971 | bFromDocView = TRUE; | 972 | bFromDocView = true; |
972 | openFile(fileref); | 973 | openFile(fileref); |
973 | editor->setEdited(TRUE); | 974 | editor->setEdited(true); |
974 | edited1=FALSE; | 975 | edited1=false; |
975 | edited=TRUE; | 976 | edited=true; |
976 | 977 | ||
977 | // doSearchBar(); | 978 | // doSearchBar(); |
978 | } | 979 | } |
979 | } | 980 | } |
980 | updateCaption( currentFileName); | 981 | updateCaption( currentFileName); |
981 | } | 982 | } |
982 | 983 | ||
983 | void TextEdit::closeEvent( QCloseEvent *e ) { | ||
984 | bFromDocView = FALSE; | ||
985 | e->accept(); | ||
986 | } | ||
987 | |||
988 | void TextEdit::changeFont() { | 984 | void TextEdit::changeFont() { |
989 | QDialog *d = new QDialog ( this, "FontDialog", true ); | 985 | QDialog *d = new QDialog ( this, "FontDialog", true ); |
990 | d-> setCaption ( tr( "Choose font" )); | 986 | d-> setCaption ( tr( "Choose font" )); |
991 | QBoxLayout *lay = new QVBoxLayout ( d ); | 987 | QBoxLayout *lay = new QVBoxLayout ( d ); |
992 | OFontSelector *ofs = new OFontSelector ( true, d ); | 988 | OFontSelector *ofs = new OFontSelector ( true, d ); |
993 | lay-> addWidget ( ofs ); | 989 | lay-> addWidget ( ofs ); |
@@ -1013,30 +1009,25 @@ void TextEdit::editDelete() { | |||
1013 | // exit | 1009 | // exit |
1014 | break; | 1010 | break; |
1015 | }; | 1011 | }; |
1016 | } | 1012 | } |
1017 | 1013 | ||
1018 | void TextEdit::changeStartConfig( bool b ) { | 1014 | void TextEdit::changeStartConfig( bool b ) { |
1019 | 1015 | startWithNew=b; | |
1020 | Config cfg("TextEdit"); | 1016 | Config cfg("TextEdit"); |
1021 | cfg.setGroup("View"); | 1017 | cfg.setGroup("View"); |
1022 | if(b) { | 1018 | cfg.writeEntry("startNew",b); |
1023 | qDebug("bool"); | ||
1024 | cfg.writeEntry("startNew","TRUE"); | ||
1025 | } else { | ||
1026 | cfg.writeEntry("startNew","FALSE"); | ||
1027 | } | ||
1028 | update(); | 1019 | update(); |
1029 | } | 1020 | } |
1030 | 1021 | ||
1031 | void TextEdit::editorChanged() { | 1022 | void TextEdit::editorChanged() { |
1032 | if(editor->edited() && edited && !edited1) { | 1023 | if(editor->edited() && edited && !edited1) { |
1033 | setCaption( "*"+caption()); | 1024 | setCaption( "*"+caption()); |
1034 | edited1=TRUE; | 1025 | edited1=true; |
1035 | } | 1026 | } |
1036 | edited=TRUE; | 1027 | edited=true; |
1037 | } | 1028 | } |
1038 | 1029 | ||
1039 | void TextEdit::receive(const QCString&msg, const QByteArray&) { | 1030 | void TextEdit::receive(const QCString&msg, const QByteArray&) { |
1040 | qDebug("QCop "+msg); | 1031 | qDebug("QCop "+msg); |
1041 | if ( msg == "setDocument(QString)" ) { | 1032 | if ( msg == "setDocument(QString)" ) { |
1042 | qDebug("bugger all"); | 1033 | qDebug("bugger all"); |
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index a95e742..bb7d693 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -62,13 +62,12 @@ public: | |||
62 | void openFile( const QString & ); | 62 | void openFile( const QString & ); |
63 | QCopChannel * channel; | 63 | QCopChannel * channel; |
64 | public slots: | 64 | public slots: |
65 | void editorChanged(); | 65 | void editorChanged(); |
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, useSearchBar; | ||
69 | void closeEvent( QCloseEvent *e ); | 68 | void closeEvent( QCloseEvent *e ); |
70 | void doSearchBar(); | 69 | void doSearchBar(); |
71 | private slots: | 70 | private slots: |
72 | void editPasteTimeDate(); | 71 | void editPasteTimeDate(); |
73 | void doPrompt(bool); | 72 | void doPrompt(bool); |
74 | void doDesktop(bool); | 73 | void doDesktop(bool); |
@@ -111,22 +110,21 @@ private slots: | |||
111 | private: | 110 | private: |
112 | void openDotFile(const QString &); | 111 | void openDotFile(const QString &); |
113 | void colorChanged( const QColor &c ); | 112 | void colorChanged( const QColor &c ); |
114 | void clear(); | 113 | void clear(); |
115 | void updateCaption( const QString &name=QString::null ); | 114 | void updateCaption( const QString &name=QString::null ); |
116 | void setFontSize(int sz, bool round_down_not_up); | 115 | void setFontSize(int sz, bool round_down_not_up); |
117 | |||
118 | private: | 116 | private: |
119 | // fileSaver *fileSaveDlg; | 117 | // fileSaver *fileSaveDlg; |
120 | // fileBrowser *browseForFiles; | 118 | // fileBrowser *browseForFiles; |
121 | QpeEditor* editor; | 119 | QpeEditor* editor; |
122 | QToolBar *menu, *editBar, *searchBar; | 120 | QToolBar *menu, *editBar, *searchBar; |
123 | QPopupMenu *advancedMenu; | 121 | QPopupMenu *advancedMenu; |
124 | QLineEdit *searchEdit; | 122 | QLineEdit *searchEdit; |
125 | DocLnk *doc; | 123 | DocLnk *doc; |
126 | bool searchVisible; | 124 | bool fileIs, useAdvancedFeatures, promptExit, openDesktop, filePerms, useSearchBar, startWithNew; |
127 | bool bFromDocView; | 125 | bool bFromDocView; |
128 | int viewSelection; | 126 | int viewSelection; |
129 | QAction *zin, *zout; | 127 | QAction *zin, *zout; |
130 | QString currentFileName; | 128 | QString currentFileName; |
131 | }; | 129 | }; |
132 | 130 | ||