author | llornkcor <llornkcor> | 2005-02-06 03:49:06 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2005-02-06 03:49:06 (UTC) |
commit | b09f9ce74d40f47bc336b4647c6c091a4f3bd5b6 (patch) (unidiff) | |
tree | 212816ea85f372b28c22c85b3dbf1e6d4dcfa887 | |
parent | d0af8c31f8c74d8aa90477ad672dd876b661eba1 (diff) | |
download | opie-b09f9ce74d40f47bc336b4647c6c091a4f3bd5b6.zip opie-b09f9ce74d40f47bc336b4647c6c091a4f3bd5b6.tar.gz opie-b09f9ce74d40f47bc336b4647c6c091a4f3bd5b6.tar.bz2 |
fix #1472 - no prompt on esc exit
-rw-r--r-- | core/apps/textedit/textedit.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index c7273c5..26b907b 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -323,221 +323,224 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
323 | 323 | ||
324 | searchBar = new QToolBar(this); | 324 | searchBar = new QToolBar(this); |
325 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); | 325 | addToolBar( searchBar, "Search", QMainWindow::Top, true ); |
326 | 326 | ||
327 | searchBar->setHorizontalStretchable( true ); | 327 | searchBar->setHorizontalStretchable( true ); |
328 | 328 | ||
329 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 329 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
330 | searchBar->setStretchableWidget( searchEdit ); | 330 | searchBar->setStretchableWidget( searchEdit ); |
331 | connect( searchEdit, SIGNAL( textChanged(const QString&) ), | 331 | connect( searchEdit, SIGNAL( textChanged(const QString&) ), |
332 | this, SLOT( search() ) ); | 332 | this, SLOT( search() ) ); |
333 | 333 | ||
334 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), | 334 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), |
335 | QString::null, 0, this, 0 ); | 335 | QString::null, 0, this, 0 ); |
336 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 336 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
337 | a->addTo( searchBar ); | 337 | a->addTo( searchBar ); |
338 | a->addTo( edit ); | 338 | a->addTo( edit ); |
339 | 339 | ||
340 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), | 340 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), |
341 | QString::null, 0, this, 0 ); | 341 | QString::null, 0, this, 0 ); |
342 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 342 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
343 | a->addTo( searchBar ); | 343 | a->addTo( searchBar ); |
344 | 344 | ||
345 | edit->insertSeparator(); | 345 | edit->insertSeparator(); |
346 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), | 346 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), |
347 | QString::null, 0, this, 0 ); | 347 | QString::null, 0, this, 0 ); |
348 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 348 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
349 | a->addTo( edit ); | 349 | a->addTo( edit ); |
350 | 350 | ||
351 | searchBar->hide(); | 351 | searchBar->hide(); |
352 | 352 | ||
353 | editor = new QpeEditor( this ); | 353 | editor = new QpeEditor( this ); |
354 | setCentralWidget( editor ); | 354 | setCentralWidget( editor ); |
355 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 355 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
356 | connect( editor, SIGNAL( textChanged() ), | 356 | connect( editor, SIGNAL( textChanged() ), |
357 | this, SLOT( editorChanged() ) ); | 357 | this, SLOT( editorChanged() ) ); |
358 | 358 | ||
359 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); | 359 | QPEApplication::setStylusOperation( editor, QPEApplication::RightOnHold); |
360 | 360 | ||
361 | Config cfg("TextEdit"); | 361 | Config cfg("TextEdit"); |
362 | cfg. setGroup ( "Font" ); | 362 | cfg. setGroup ( "Font" ); |
363 | 363 | ||
364 | QFont defaultFont = editor-> font ( ); | 364 | QFont defaultFont = editor-> font ( ); |
365 | 365 | ||
366 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); | 366 | QString family = cfg. readEntry ( "Family", defaultFont. family ( )); |
367 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); | 367 | int size = cfg. readNumEntry ( "Size", defaultFont. pointSize ( )); |
368 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); | 368 | int weight = cfg. readNumEntry ( "Weight", defaultFont. weight ( )); |
369 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); | 369 | bool italic = cfg. readBoolEntry ( "Italic", defaultFont. italic ( )); |
370 | 370 | ||
371 | defaultFont = QFont ( family, size, weight, italic ); | 371 | defaultFont = QFont ( family, size, weight, italic ); |
372 | editor-> setFont ( defaultFont ); | 372 | editor-> setFont ( defaultFont ); |
373 | // updateCaption(); | 373 | // updateCaption(); |
374 | 374 | ||
375 | cfg.setGroup ( "View" ); | 375 | cfg.setGroup ( "View" ); |
376 | 376 | ||
377 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); | 377 | promptExit = cfg.readBoolEntry ( "PromptExit", false ); |
378 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); | 378 | openDesktop = cfg.readBoolEntry ( "OpenDesktop", true ); |
379 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); | 379 | filePerms = cfg.readBoolEntry ( "FilePermissions", false ); |
380 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); | 380 | useSearchBar = cfg.readBoolEntry ( "SearchBar", false ); |
381 | startWithNew = cfg.readBoolEntry ( "startNew", true); | 381 | startWithNew = cfg.readBoolEntry ( "startNew", true); |
382 | featureAutoSave = cfg.readBoolEntry( "autosave", false); | 382 | featureAutoSave = cfg.readBoolEntry( "autosave", false); |
383 | 383 | ||
384 | if(useSearchBar) searchBarAction->setOn(true); | 384 | if(useSearchBar) searchBarAction->setOn(true); |
385 | if(promptExit) nAdvanced->setOn( true ); | 385 | if(promptExit) nAdvanced->setOn( true ); |
386 | if(openDesktop) desktopAction->setOn( true ); | 386 | if(openDesktop) desktopAction->setOn( true ); |
387 | if(filePerms) filePermAction->setOn( true ); | 387 | if(filePerms) filePermAction->setOn( true ); |
388 | if(startWithNew) nStart->setOn( true ); | 388 | if(startWithNew) nStart->setOn( true ); |
389 | if(featureAutoSave) nAutoSave->setOn(true); | 389 | if(featureAutoSave) nAutoSave->setOn(true); |
390 | 390 | ||
391 | // { | 391 | // { |
392 | // doTimer(true); | 392 | // doTimer(true); |
393 | // } | 393 | // } |
394 | 394 | ||
395 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); | 395 | bool wrap = cfg. readBoolEntry ( "Wrap", true ); |
396 | wa-> setOn ( wrap ); | 396 | wa-> setOn ( wrap ); |
397 | setWordWrap ( wrap ); | 397 | setWordWrap ( wrap ); |
398 | 398 | ||
399 | ///////////////// | 399 | ///////////////// |
400 | if( qApp->argc() > 1) { | 400 | if( qApp->argc() > 1) { |
401 | currentFileName=qApp->argv()[1]; | 401 | currentFileName=qApp->argv()[1]; |
402 | 402 | ||
403 | QFileInfo fi(currentFileName); | 403 | QFileInfo fi(currentFileName); |
404 | 404 | ||
405 | if(fi.baseName().left(1) == "") { | 405 | if(fi.baseName().left(1) == "") { |
406 | openDotFile(currentFileName); | 406 | openDotFile(currentFileName); |
407 | } else { | 407 | } else { |
408 | openFile(currentFileName); | 408 | openFile(currentFileName); |
409 | } | 409 | } |
410 | } else { | 410 | } else { |
411 | edited1=false; | 411 | edited1=false; |
412 | openDotFile(""); | 412 | openDotFile(""); |
413 | } | 413 | } |
414 | 414 | ||
415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
416 | } | 416 | } |
417 | 417 | ||
418 | TextEdit::~TextEdit() { | 418 | TextEdit::~TextEdit() { |
419 | owarn << "textedit d'tor" << oendl; | 419 | if( edited1 && !promptExit) { |
420 | switch( savePrompt() ) { | ||
421 | case 1: { | ||
422 | saveAs(); | ||
423 | } | ||
424 | break; | ||
425 | }; | ||
426 | } | ||
427 | |||
420 | delete editor; | 428 | delete editor; |
421 | } | 429 | } |
422 | 430 | ||
423 | void TextEdit::closeEvent(QCloseEvent *) { | 431 | void TextEdit::closeEvent(QCloseEvent *) { |
424 | if( edited1 && promptExit) | 432 | if( promptExit) { |
425 | { | 433 | switch( savePrompt() ) { |
426 | switch( savePrompt() ) | 434 | case 1: { |
427 | { | 435 | saveAs(); |
428 | case 1: | 436 | qApp->quit(); |
429 | { | 437 | } |
430 | saveAs(); | 438 | break; |
431 | qApp->quit(); | 439 | |
432 | } | 440 | case 2: { |
433 | break; | 441 | qApp->quit(); |
434 | 442 | } | |
435 | case 2: | 443 | break; |
436 | { | 444 | |
437 | qApp->quit(); | 445 | case -1: |
438 | } | 446 | break; |
439 | break; | 447 | }; |
440 | 448 | } | |
441 | case -1: | ||
442 | break; | ||
443 | }; | ||
444 | } | ||
445 | else | 449 | else |
446 | qApp->quit(); | 450 | qApp->quit(); |
447 | |||
448 | } | 451 | } |
449 | 452 | ||
450 | void TextEdit::cleanUp() { | 453 | void TextEdit::cleanUp() { |
451 | 454 | ||
452 | Config cfg ( "TextEdit" ); | 455 | Config cfg ( "TextEdit" ); |
453 | cfg. setGroup ( "Font" ); | 456 | cfg. setGroup ( "Font" ); |
454 | QFont f = editor->font(); | 457 | QFont f = editor->font(); |
455 | cfg.writeEntry ( "Family", f. family ( )); | 458 | cfg.writeEntry ( "Family", f. family ( )); |
456 | cfg.writeEntry ( "Size", f. pointSize ( )); | 459 | cfg.writeEntry ( "Size", f. pointSize ( )); |
457 | cfg.writeEntry ( "Weight", f. weight ( )); | 460 | cfg.writeEntry ( "Weight", f. weight ( )); |
458 | cfg.writeEntry ( "Italic", f. italic ( )); | 461 | cfg.writeEntry ( "Italic", f. italic ( )); |
459 | 462 | ||
460 | cfg.setGroup ( "View" ); | 463 | cfg.setGroup ( "View" ); |
461 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); | 464 | cfg.writeEntry ( "Wrap", editor->wordWrap() == QMultiLineEdit::WidgetWidth ); |
462 | cfg.writeEntry ( "FileView", viewSelection ); | 465 | cfg.writeEntry ( "FileView", viewSelection ); |
463 | 466 | ||
464 | cfg.writeEntry ( "PromptExit", promptExit ); | 467 | cfg.writeEntry ( "PromptExit", promptExit ); |
465 | cfg.writeEntry ( "OpenDesktop", openDesktop ); | 468 | cfg.writeEntry ( "OpenDesktop", openDesktop ); |
466 | cfg.writeEntry ( "FilePermissions", filePerms ); | 469 | cfg.writeEntry ( "FilePermissions", filePerms ); |
467 | cfg.writeEntry ( "SearchBar", useSearchBar ); | 470 | cfg.writeEntry ( "SearchBar", useSearchBar ); |
468 | cfg.writeEntry ( "startNew", startWithNew ); | 471 | cfg.writeEntry ( "startNew", startWithNew ); |
469 | 472 | ||
470 | } | 473 | } |
471 | 474 | ||
472 | 475 | ||
473 | void TextEdit::accept() { | 476 | void TextEdit::accept() { |
474 | if( edited1) | 477 | if( edited1) |
475 | saveAs(); | 478 | saveAs(); |
476 | qApp->quit(); | 479 | qApp->quit(); |
477 | } | 480 | } |
478 | 481 | ||
479 | void TextEdit::zoomIn() { | 482 | void TextEdit::zoomIn() { |
480 | setFontSize(editor->font().pointSize()+1,false); | 483 | setFontSize(editor->font().pointSize()+1,false); |
481 | } | 484 | } |
482 | 485 | ||
483 | void TextEdit::zoomOut() { | 486 | void TextEdit::zoomOut() { |
484 | setFontSize(editor->font().pointSize()-1,true); | 487 | setFontSize(editor->font().pointSize()-1,true); |
485 | } | 488 | } |
486 | 489 | ||
487 | 490 | ||
488 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { | 491 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
489 | int s=10; | 492 | int s=10; |
490 | for (int i=0; i<nfontsizes; i++) { | 493 | for (int i=0; i<nfontsizes; i++) { |
491 | if ( fontsize[i] == sz ) { | 494 | if ( fontsize[i] == sz ) { |
492 | s = sz; | 495 | s = sz; |
493 | break; | 496 | break; |
494 | } else if ( round_down_not_up ) { | 497 | } else if ( round_down_not_up ) { |
495 | if ( fontsize[i] < sz ) | 498 | if ( fontsize[i] < sz ) |
496 | s = fontsize[i]; | 499 | s = fontsize[i]; |
497 | } else { | 500 | } else { |
498 | if ( fontsize[i] > sz ) { | 501 | if ( fontsize[i] > sz ) { |
499 | s = fontsize[i]; | 502 | s = fontsize[i]; |
500 | break; | 503 | break; |
501 | } | 504 | } |
502 | } | 505 | } |
503 | } | 506 | } |
504 | 507 | ||
505 | QFont f = editor->font(); | 508 | QFont f = editor->font(); |
506 | f.setPointSize(s); | 509 | f.setPointSize(s); |
507 | editor->setFont(f); | 510 | editor->setFont(f); |
508 | 511 | ||
509 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 512 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
510 | zout->setEnabled(s != fontsize[0]); | 513 | zout->setEnabled(s != fontsize[0]); |
511 | } | 514 | } |
512 | 515 | ||
513 | void TextEdit::setBold(bool y) { | 516 | void TextEdit::setBold(bool y) { |
514 | QFont f = editor->font(); | 517 | QFont f = editor->font(); |
515 | f.setBold(y); | 518 | f.setBold(y); |
516 | editor->setFont(f); | 519 | editor->setFont(f); |
517 | } | 520 | } |
518 | 521 | ||
519 | void TextEdit::setItalic(bool y) { | 522 | void TextEdit::setItalic(bool y) { |
520 | QFont f = editor->font(); | 523 | QFont f = editor->font(); |
521 | f.setItalic(y); | 524 | f.setItalic(y); |
522 | editor->setFont(f); | 525 | editor->setFont(f); |
523 | } | 526 | } |
524 | 527 | ||
525 | void TextEdit::setWordWrap(bool y) { | 528 | void TextEdit::setWordWrap(bool y) { |
526 | bool state = editor->edited(); | 529 | bool state = editor->edited(); |
527 | QString captionStr = caption(); | 530 | QString captionStr = caption(); |
528 | bool b1 = edited1; | 531 | bool b1 = edited1; |
529 | bool b2 = edited; | 532 | bool b2 = edited; |
530 | 533 | ||
531 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 534 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
532 | editor->setEdited( state ); | 535 | editor->setEdited( state ); |
533 | edited1=b1; | 536 | edited1=b1; |
534 | edited=b2; | 537 | edited=b2; |
535 | setCaption(captionStr); | 538 | setCaption(captionStr); |
536 | } | 539 | } |
537 | 540 | ||
538 | void TextEdit::setSearchBar(bool b) { | 541 | void TextEdit::setSearchBar(bool b) { |
539 | useSearchBar=b; | 542 | useSearchBar=b; |
540 | Config cfg("TextEdit"); | 543 | Config cfg("TextEdit"); |
541 | cfg.setGroup("View"); | 544 | cfg.setGroup("View"); |
542 | cfg.writeEntry ( "SearchBar", b ); | 545 | cfg.writeEntry ( "SearchBar", b ); |
543 | searchBarAction->setOn(b); | 546 | searchBarAction->setOn(b); |