author | llornkcor <llornkcor> | 2002-02-19 01:29:58 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-02-19 01:29:58 (UTC) |
commit | 994691c1659fdac4980b0319aa8fab1c98ef3c73 (patch) (unidiff) | |
tree | a7fa94deb3cbd4c7cda17f184eed634bbc0caac4 | |
parent | fe66103c21d3337bb6c7fc7ad112cbdedd255d67 (diff) | |
download | opie-994691c1659fdac4980b0319aa8fab1c98ef3c73.zip opie-994691c1659fdac4980b0319aa8fab1c98ef3c73.tar.gz opie-994691c1659fdac4980b0319aa8fab1c98ef3c73.tar.bz2 |
bug- saveas
-rw-r--r-- | core/apps/textedit/textedit.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 019ffee..197b28b 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -280,598 +280,600 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
280 | 280 | ||
281 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); | 281 | a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); |
282 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 282 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
283 | a->addTo( editBar ); | 283 | a->addTo( editBar ); |
284 | a->addTo( edit ); | 284 | a->addTo( edit ); |
285 | 285 | ||
286 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | 286 | a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); |
287 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 287 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
288 | a->addTo( editBar ); | 288 | a->addTo( editBar ); |
289 | a->addTo( edit ); | 289 | a->addTo( edit ); |
290 | 290 | ||
291 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 291 | a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
292 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 292 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
293 | a->addTo( editBar ); | 293 | a->addTo( editBar ); |
294 | a->addTo( edit ); | 294 | a->addTo( edit ); |
295 | 295 | ||
296 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 296 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
297 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 297 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
298 | edit->insertSeparator(); | 298 | edit->insertSeparator(); |
299 | a->addTo( bar ); | 299 | a->addTo( bar ); |
300 | a->addTo( edit ); | 300 | a->addTo( edit ); |
301 | 301 | ||
302 | 302 | ||
303 | int defsize; | 303 | int defsize; |
304 | bool defb, defi, wrap; | 304 | bool defb, defi, wrap; |
305 | 305 | ||
306 | Config cfg("TextEdit"); | 306 | Config cfg("TextEdit"); |
307 | cfg.setGroup("View"); | 307 | cfg.setGroup("View"); |
308 | defsize = cfg.readNumEntry("FontSize",10); | 308 | defsize = cfg.readNumEntry("FontSize",10); |
309 | defb = cfg.readBoolEntry("Bold",FALSE); | 309 | defb = cfg.readBoolEntry("Bold",FALSE); |
310 | defi = cfg.readBoolEntry("Italic",FALSE); | 310 | defi = cfg.readBoolEntry("Italic",FALSE); |
311 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 311 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
312 | 312 | ||
313 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 313 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
314 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 314 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
315 | zin->addTo( font ); | 315 | zin->addTo( font ); |
316 | 316 | ||
317 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 317 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
318 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 318 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
319 | zout->addTo( font ); | 319 | zout->addTo( font ); |
320 | 320 | ||
321 | font->insertSeparator(); | 321 | font->insertSeparator(); |
322 | 322 | ||
323 | #if 0 | 323 | #if 0 |
324 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 324 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
325 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 325 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
326 | ba->setToggleAction(TRUE); | 326 | ba->setToggleAction(TRUE); |
327 | ba->addTo( font ); | 327 | ba->addTo( font ); |
328 | 328 | ||
329 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 329 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
330 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 330 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
331 | ia->setToggleAction(TRUE); | 331 | ia->setToggleAction(TRUE); |
332 | ia->addTo( font ); | 332 | ia->addTo( font ); |
333 | 333 | ||
334 | ba->setOn(defb); | 334 | ba->setOn(defb); |
335 | ia->setOn(defi); | 335 | ia->setOn(defi); |
336 | 336 | ||
337 | font->insertSeparator(); | 337 | font->insertSeparator(); |
338 | #endif | 338 | #endif |
339 | 339 | ||
340 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 340 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
341 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 341 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
342 | wa->setToggleAction(TRUE); | 342 | wa->setToggleAction(TRUE); |
343 | wa->addTo( font ); | 343 | wa->addTo( font ); |
344 | 344 | ||
345 | font->insertSeparator(); | 345 | font->insertSeparator(); |
346 | font->insertItem("Font", this, SLOT(changeFont()) ); | 346 | font->insertItem("Font", this, SLOT(changeFont()) ); |
347 | 347 | ||
348 | mb->insertItem( tr( "File" ), file ); | 348 | mb->insertItem( tr( "File" ), file ); |
349 | mb->insertItem( tr( "Edit" ), edit ); | 349 | mb->insertItem( tr( "Edit" ), edit ); |
350 | mb->insertItem( tr( "View" ), font ); | 350 | mb->insertItem( tr( "View" ), font ); |
351 | 351 | ||
352 | searchBar = new QPEToolBar(this); | 352 | searchBar = new QPEToolBar(this); |
353 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 353 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
354 | 354 | ||
355 | searchBar->setHorizontalStretchable( TRUE ); | 355 | searchBar->setHorizontalStretchable( TRUE ); |
356 | 356 | ||
357 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 357 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
358 | searchBar->setStretchableWidget( searchEdit ); | 358 | searchBar->setStretchableWidget( searchEdit ); |
359 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 359 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
360 | this, SLOT( search() ) ); | 360 | this, SLOT( search() ) ); |
361 | 361 | ||
362 | 362 | ||
363 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 363 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
364 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 364 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
365 | a->addTo( searchBar ); | 365 | a->addTo( searchBar ); |
366 | a->addTo( edit ); | 366 | a->addTo( edit ); |
367 | 367 | ||
368 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 368 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
369 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 369 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
370 | a->addTo( searchBar ); | 370 | a->addTo( searchBar ); |
371 | 371 | ||
372 | edit->insertSeparator(); | 372 | edit->insertSeparator(); |
373 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "delete" ), QString::null, 0, this, 0 ); | 373 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "delete" ), QString::null, 0, this, 0 ); |
374 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 374 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
375 | a->addTo( edit ); | 375 | a->addTo( edit ); |
376 | 376 | ||
377 | searchBar->hide(); | 377 | searchBar->hide(); |
378 | 378 | ||
379 | editorStack = new QWidgetStack( this ); | 379 | editorStack = new QWidgetStack( this ); |
380 | setCentralWidget( editorStack ); | 380 | setCentralWidget( editorStack ); |
381 | 381 | ||
382 | searchVisible = FALSE; | 382 | searchVisible = FALSE; |
383 | 383 | ||
384 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | 384 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy |
385 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | 385 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); |
386 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | 386 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); |
387 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | 387 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); |
388 | // fileOpen(); | 388 | // fileOpen(); |
389 | 389 | ||
390 | editor = new QpeEditor( editorStack ); | 390 | editor = new QpeEditor( editorStack ); |
391 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 391 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
392 | editorStack->addWidget( editor, get_unique_id() ); | 392 | editorStack->addWidget( editor, get_unique_id() ); |
393 | 393 | ||
394 | resize( 200, 300 ); | 394 | resize( 200, 300 ); |
395 | 395 | ||
396 | // setFontSize(defsize,TRUE); | 396 | // setFontSize(defsize,TRUE); |
397 | FontDatabase fdb; | 397 | FontDatabase fdb; |
398 | QFont defaultFont=editor->font(); | 398 | QFont defaultFont=editor->font(); |
399 | QFontInfo fontInfo(defaultFont); | 399 | QFontInfo fontInfo(defaultFont); |
400 | 400 | ||
401 | cfg.setGroup("Font"); | 401 | cfg.setGroup("Font"); |
402 | QString family = cfg.readEntry("Family", fontInfo.family()); | 402 | QString family = cfg.readEntry("Family", fontInfo.family()); |
403 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 403 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
404 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 404 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
405 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 405 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
406 | 406 | ||
407 | defaultFont = fdb.font(family,style,i_size,charSet); | 407 | defaultFont = fdb.font(family,style,i_size,charSet); |
408 | editor->setFont( defaultFont); | 408 | editor->setFont( defaultFont); |
409 | 409 | ||
410 | wa->setOn(wrap); | 410 | wa->setOn(wrap); |
411 | updateCaption(); | 411 | updateCaption(); |
412 | 412 | ||
413 | fileNew(); | 413 | fileNew(); |
414 | } | 414 | } |
415 | 415 | ||
416 | TextEdit::~TextEdit() | 416 | TextEdit::~TextEdit() |
417 | { | 417 | { |
418 | // saveAs(); | 418 | // saveAs(); |
419 | 419 | ||
420 | Config cfg("TextEdit"); | 420 | Config cfg("TextEdit"); |
421 | cfg.setGroup("View"); | 421 | cfg.setGroup("View"); |
422 | QFont f = editor->font(); | 422 | QFont f = editor->font(); |
423 | cfg.writeEntry("FontSize",f.pointSize()); | 423 | cfg.writeEntry("FontSize",f.pointSize()); |
424 | cfg.writeEntry("Bold",f.bold()); | 424 | cfg.writeEntry("Bold",f.bold()); |
425 | cfg.writeEntry("Italic",f.italic()); | 425 | cfg.writeEntry("Italic",f.italic()); |
426 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 426 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
427 | } | 427 | } |
428 | 428 | ||
429 | void TextEdit::zoomIn() | 429 | void TextEdit::zoomIn() |
430 | { | 430 | { |
431 | setFontSize(editor->font().pointSize()+1,FALSE); | 431 | setFontSize(editor->font().pointSize()+1,FALSE); |
432 | } | 432 | } |
433 | 433 | ||
434 | void TextEdit::zoomOut() | 434 | void TextEdit::zoomOut() |
435 | { | 435 | { |
436 | setFontSize(editor->font().pointSize()-1,TRUE); | 436 | setFontSize(editor->font().pointSize()-1,TRUE); |
437 | } | 437 | } |
438 | 438 | ||
439 | 439 | ||
440 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 440 | void TextEdit::setFontSize(int sz, bool round_down_not_up) |
441 | { | 441 | { |
442 | int s=10; | 442 | int s=10; |
443 | for (int i=0; i<nfontsizes; i++) { | 443 | for (int i=0; i<nfontsizes; i++) { |
444 | if ( fontsize[i] == sz ) { | 444 | if ( fontsize[i] == sz ) { |
445 | s = sz; | 445 | s = sz; |
446 | break; | 446 | break; |
447 | } else if ( round_down_not_up ) { | 447 | } else if ( round_down_not_up ) { |
448 | if ( fontsize[i] < sz ) | 448 | if ( fontsize[i] < sz ) |
449 | s = fontsize[i]; | 449 | s = fontsize[i]; |
450 | } else { | 450 | } else { |
451 | if ( fontsize[i] > sz ) { | 451 | if ( fontsize[i] > sz ) { |
452 | s = fontsize[i]; | 452 | s = fontsize[i]; |
453 | break; | 453 | break; |
454 | } | 454 | } |
455 | } | 455 | } |
456 | } | 456 | } |
457 | 457 | ||
458 | QFont f = editor->font(); | 458 | QFont f = editor->font(); |
459 | f.setPointSize(s); | 459 | f.setPointSize(s); |
460 | editor->setFont(f); | 460 | editor->setFont(f); |
461 | 461 | ||
462 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 462 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
463 | zout->setEnabled(s != fontsize[0]); | 463 | zout->setEnabled(s != fontsize[0]); |
464 | } | 464 | } |
465 | 465 | ||
466 | void TextEdit::setBold(bool y) | 466 | void TextEdit::setBold(bool y) |
467 | { | 467 | { |
468 | QFont f = editor->font(); | 468 | QFont f = editor->font(); |
469 | f.setBold(y); | 469 | f.setBold(y); |
470 | editor->setFont(f); | 470 | editor->setFont(f); |
471 | } | 471 | } |
472 | 472 | ||
473 | void TextEdit::setItalic(bool y) | 473 | void TextEdit::setItalic(bool y) |
474 | { | 474 | { |
475 | QFont f = editor->font(); | 475 | QFont f = editor->font(); |
476 | f.setItalic(y); | 476 | f.setItalic(y); |
477 | editor->setFont(f); | 477 | editor->setFont(f); |
478 | } | 478 | } |
479 | 479 | ||
480 | void TextEdit::setWordWrap(bool y) | 480 | void TextEdit::setWordWrap(bool y) |
481 | { | 481 | { |
482 | bool state = editor->edited(); | 482 | bool state = editor->edited(); |
483 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 483 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
484 | editor->setEdited( state ); | 484 | editor->setEdited( state ); |
485 | } | 485 | } |
486 | 486 | ||
487 | void TextEdit::fileNew() | 487 | void TextEdit::fileNew() |
488 | { | 488 | { |
489 | if( !bFromDocView ) { | 489 | if( !bFromDocView ) { |
490 | saveAs(); | 490 | saveAs(); |
491 | } | 491 | } |
492 | newFile(DocLnk()); | 492 | newFile(DocLnk()); |
493 | } | 493 | } |
494 | 494 | ||
495 | void TextEdit::fileOpen() | 495 | void TextEdit::fileOpen() |
496 | { | 496 | { |
497 | // if ( !save() ) { | 497 | // if ( !save() ) { |
498 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 498 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
499 | // tr( "Text Editor was unable to\n" | 499 | // tr( "Text Editor was unable to\n" |
500 | // "save your changes.\n" | 500 | // "save your changes.\n" |
501 | // "Free some space and try again.\n" | 501 | // "Free some space and try again.\n" |
502 | // "\nContinue anyway?" ), | 502 | // "\nContinue anyway?" ), |
503 | // QMessageBox::Yes|QMessageBox::Escape, | 503 | // QMessageBox::Yes|QMessageBox::Escape, |
504 | // QMessageBox::No|QMessageBox::Default ) | 504 | // QMessageBox::No|QMessageBox::Default ) |
505 | // != QMessageBox::Yes ) | 505 | // != QMessageBox::Yes ) |
506 | // return; | 506 | // return; |
507 | // else { | 507 | // else { |
508 | // delete doc; | 508 | // delete doc; |
509 | // doc = 0; | 509 | // doc = 0; |
510 | // } | 510 | // } |
511 | // } | 511 | // } |
512 | menu->hide(); | 512 | menu->hide(); |
513 | editBar->hide(); | 513 | editBar->hide(); |
514 | searchBar->hide(); | 514 | searchBar->hide(); |
515 | clearWState (WState_Reserved1 ); | 515 | clearWState (WState_Reserved1 ); |
516 | editorStack->raiseWidget( fileSelector ); | 516 | editorStack->raiseWidget( fileSelector ); |
517 | fileSelector->reread(); | 517 | fileSelector->reread(); |
518 | updateCaption(); | 518 | updateCaption(); |
519 | } | 519 | } |
520 | 520 | ||
521 | void TextEdit::newFileOpen() | 521 | void TextEdit::newFileOpen() |
522 | { | 522 | { |
523 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); | 523 | browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); |
524 | if( browseForFiles->exec() != -1 ) { | 524 | if( browseForFiles->exec() != -1 ) { |
525 | QString selFile= browseForFiles->selectedFileName; | 525 | QString selFile= browseForFiles->selectedFileName; |
526 | QStringList fileList=browseForFiles->fileList; | 526 | QStringList fileList=browseForFiles->fileList; |
527 | qDebug(selFile); | 527 | qDebug(selFile); |
528 | QStringList::ConstIterator f; | 528 | QStringList::ConstIterator f; |
529 | QString fileTemp; | 529 | QString fileTemp; |
530 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 530 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
531 | fileTemp = *f; | 531 | fileTemp = *f; |
532 | fileTemp.right( fileTemp.length()-5); | 532 | fileTemp.right( fileTemp.length()-5); |
533 | QString fileName = fileTemp; | 533 | QString fileName = fileTemp; |
534 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 534 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
535 | currentFileName = fileName; | 535 | currentFileName = fileName; |
536 | // qDebug("please open "+currentFileName); | 536 | qDebug("please open "+currentFileName); |
537 | openFile(fileName ); | 537 | openFile(fileName ); |
538 | } | 538 | } |
539 | } | 539 | } |
540 | } | 540 | } |
541 | delete browseForFiles; | 541 | delete browseForFiles; |
542 | editor->setEdited( true ); | 542 | editor->setEdited( true ); |
543 | } | 543 | } |
544 | 544 | ||
545 | #if 0 | 545 | #if 0 |
546 | void TextEdit::slotFind() | 546 | void TextEdit::slotFind() |
547 | { | 547 | { |
548 | FindDialog frmFind( "Text Editor", this ); | 548 | FindDialog frmFind( "Text Editor", this ); |
549 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 549 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
550 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 550 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
551 | 551 | ||
552 | //case sensitive, backwards, [category] | 552 | //case sensitive, backwards, [category] |
553 | 553 | ||
554 | connect( editor, SIGNAL(notFound()), | 554 | connect( editor, SIGNAL(notFound()), |
555 | &frmFind, SLOT(slotNotFound()) ); | 555 | &frmFind, SLOT(slotNotFound()) ); |
556 | connect( editor, SIGNAL(searchWrapped()), | 556 | connect( editor, SIGNAL(searchWrapped()), |
557 | &frmFind, SLOT(slotWrapAround()) ); | 557 | &frmFind, SLOT(slotWrapAround()) ); |
558 | 558 | ||
559 | frmFind.exec(); | 559 | frmFind.exec(); |
560 | 560 | ||
561 | 561 | ||
562 | } | 562 | } |
563 | #endif | 563 | #endif |
564 | 564 | ||
565 | void TextEdit::fileRevert() | 565 | void TextEdit::fileRevert() |
566 | { | 566 | { |
567 | clear(); | 567 | clear(); |
568 | fileOpen(); | 568 | fileOpen(); |
569 | } | 569 | } |
570 | 570 | ||
571 | void TextEdit::editCut() | 571 | void TextEdit::editCut() |
572 | { | 572 | { |
573 | #ifndef QT_NO_CLIPBOARD | 573 | #ifndef QT_NO_CLIPBOARD |
574 | editor->cut(); | 574 | editor->cut(); |
575 | #endif | 575 | #endif |
576 | } | 576 | } |
577 | 577 | ||
578 | void TextEdit::editCopy() | 578 | void TextEdit::editCopy() |
579 | { | 579 | { |
580 | #ifndef QT_NO_CLIPBOARD | 580 | #ifndef QT_NO_CLIPBOARD |
581 | editor->copy(); | 581 | editor->copy(); |
582 | #endif | 582 | #endif |
583 | } | 583 | } |
584 | 584 | ||
585 | void TextEdit::editPaste() | 585 | void TextEdit::editPaste() |
586 | { | 586 | { |
587 | #ifndef QT_NO_CLIPBOARD | 587 | #ifndef QT_NO_CLIPBOARD |
588 | editor->paste(); | 588 | editor->paste(); |
589 | #endif | 589 | #endif |
590 | } | 590 | } |
591 | 591 | ||
592 | void TextEdit::editFind() | 592 | void TextEdit::editFind() |
593 | { | 593 | { |
594 | searchBar->show(); | 594 | searchBar->show(); |
595 | searchVisible = TRUE; | 595 | searchVisible = TRUE; |
596 | searchEdit->setFocus(); | 596 | searchEdit->setFocus(); |
597 | } | 597 | } |
598 | 598 | ||
599 | void TextEdit::findNext() | 599 | void TextEdit::findNext() |
600 | { | 600 | { |
601 | editor->find( searchEdit->text(), FALSE, FALSE ); | 601 | editor->find( searchEdit->text(), FALSE, FALSE ); |
602 | 602 | ||
603 | } | 603 | } |
604 | 604 | ||
605 | void TextEdit::findClose() | 605 | void TextEdit::findClose() |
606 | { | 606 | { |
607 | searchVisible = FALSE; | 607 | searchVisible = FALSE; |
608 | searchBar->hide(); | 608 | searchBar->hide(); |
609 | } | 609 | } |
610 | 610 | ||
611 | void TextEdit::search() | 611 | void TextEdit::search() |
612 | { | 612 | { |
613 | editor->find( searchEdit->text(), FALSE, FALSE ); | 613 | editor->find( searchEdit->text(), FALSE, FALSE ); |
614 | } | 614 | } |
615 | 615 | ||
616 | void TextEdit::newFile( const DocLnk &f ) | 616 | void TextEdit::newFile( const DocLnk &f ) |
617 | { | 617 | { |
618 | DocLnk nf = f; | 618 | DocLnk nf = f; |
619 | nf.setType("text/plain"); | 619 | nf.setType("text/plain"); |
620 | clear(); | 620 | clear(); |
621 | editorStack->raiseWidget( editor ); | 621 | editorStack->raiseWidget( editor ); |
622 | setWState (WState_Reserved1 ); | 622 | setWState (WState_Reserved1 ); |
623 | editor->setFocus(); | 623 | editor->setFocus(); |
624 | doc = new DocLnk(nf); | 624 | doc = new DocLnk(nf); |
625 | qDebug("newFile "+currentFileName); | 625 | qDebug("newFile "+currentFileName); |
626 | updateCaption(currentFileName); | 626 | updateCaption(currentFileName); |
627 | } | 627 | } |
628 | 628 | ||
629 | void TextEdit::openFile( const QString &f ) | 629 | void TextEdit::openFile( const QString &f ) |
630 | { | 630 | { |
631 | bFromDocView = TRUE; | 631 | bFromDocView = TRUE; |
632 | DocLnk nf; | 632 | DocLnk nf; |
633 | nf.setType("text/plain"); | 633 | nf.setType("text/plain"); |
634 | nf.setFile(f); | 634 | nf.setFile(f); |
635 | currentFileName=f; | 635 | currentFileName=f; |
636 | QFileInfo fi( currentFileName); | ||
637 | nf.setName(fi.baseName()); | ||
636 | qDebug("openFile string"+currentFileName); | 638 | qDebug("openFile string"+currentFileName); |
637 | 639 | ||
638 | openFile(nf); | 640 | openFile(nf); |
639 | showEditTools(); | 641 | showEditTools(); |
640 | // Show filename in caption | 642 | // Show filename in caption |
641 | QString name = f; | 643 | QString name = f; |
642 | int sep = name.findRev( '/' ); | 644 | int sep = name.findRev( '/' ); |
643 | if ( sep > 0 ) | 645 | if ( sep > 0 ) |
644 | name = name.mid( sep+1 ); | 646 | name = name.mid( sep+1 ); |
645 | updateCaption( name ); | 647 | updateCaption( name ); |
646 | } | 648 | } |
647 | 649 | ||
648 | void TextEdit::openFile( const DocLnk &f ) | 650 | void TextEdit::openFile( const DocLnk &f ) |
649 | { | 651 | { |
650 | // clear(); | 652 | // clear(); |
651 | bFromDocView = TRUE; | 653 | bFromDocView = TRUE; |
652 | FileManager fm; | 654 | FileManager fm; |
653 | QString txt; | 655 | QString txt; |
654 | currentFileName=f.name(); | 656 | currentFileName=f.name(); |
655 | qDebug("openFile doclnk " + currentFileName); | 657 | qDebug("openFile doclnk " + currentFileName); |
656 | if ( !fm.loadFile( f, txt ) ) { | 658 | if ( !fm.loadFile( f, txt ) ) { |
657 | // ####### could be a new file | 659 | // ####### could be a new file |
658 | qDebug( "Cannot open file" ); | 660 | qDebug( "Cannot open file" ); |
659 | 661 | ||
660 | //return; | 662 | //return; |
661 | } | 663 | } |
662 | 664 | ||
663 | fileNew(); | 665 | fileNew(); |
664 | if ( doc ) | 666 | if ( doc ) |
665 | delete doc; | 667 | delete doc; |
666 | doc = new DocLnk(f); | 668 | doc = new DocLnk(f); |
667 | editor->setText(txt); | 669 | editor->setText(txt); |
668 | editor->setEdited( false); | 670 | editor->setEdited( false); |
669 | qDebug("openFile doclnk "+currentFileName); | 671 | qDebug("openFile doclnk "+currentFileName); |
670 | doc->setName(currentFileName); | 672 | doc->setName(currentFileName); |
671 | updateCaption(); | 673 | updateCaption(); |
672 | } | 674 | } |
673 | 675 | ||
674 | void TextEdit::showEditTools() | 676 | void TextEdit::showEditTools() |
675 | { | 677 | { |
676 | // if ( !doc ) | 678 | // if ( !doc ) |
677 | // close(); | 679 | // close(); |
678 | // clear(); | 680 | // clear(); |
679 | fileSelector->hide(); | 681 | fileSelector->hide(); |
680 | menu->show(); | 682 | menu->show(); |
681 | editBar->show(); | 683 | editBar->show(); |
682 | if ( searchVisible ) | 684 | if ( searchVisible ) |
683 | searchBar->show(); | 685 | searchBar->show(); |
684 | // updateCaption(); | 686 | // updateCaption(); |
685 | editorStack->raiseWidget( editor ); | 687 | editorStack->raiseWidget( editor ); |
686 | setWState (WState_Reserved1 ); | 688 | setWState (WState_Reserved1 ); |
687 | } | 689 | } |
688 | 690 | ||
689 | /*! | 691 | /*! |
690 | unprompted save */ | 692 | unprompted save */ |
691 | bool TextEdit::save() | 693 | bool TextEdit::save() |
692 | { | 694 | { |
693 | QString file = doc->file(); | 695 | QString file = doc->file(); |
694 | QString name= doc->name(); | 696 | QString name= doc->name(); |
695 | QString rt = editor->text(); | 697 | QString rt = editor->text(); |
696 | currentFileName= name ; | 698 | currentFileName= name ; |
697 | qDebug("saveFile "+currentFileName); | 699 | qDebug("saveFile "+currentFileName); |
698 | 700 | ||
699 | doc->setName( name); | 701 | doc->setName( name); |
700 | FileManager fm; | 702 | FileManager fm; |
701 | if ( !fm.saveFile( *doc, rt ) ) { | 703 | if ( !fm.saveFile( *doc, rt ) ) { |
702 | return false; | 704 | return false; |
703 | } | 705 | } |
704 | // if(doc) | 706 | // if(doc) |
705 | // delete doc; | 707 | // delete doc; |
706 | // doc = 0; | 708 | // doc = 0; |
707 | editor->setEdited( false ); | 709 | editor->setEdited( false ); |
708 | return true; | 710 | return true; |
709 | } | 711 | } |
710 | 712 | ||
711 | /*! | 713 | /*! |
712 | prompted save */ | 714 | prompted save */ |
713 | bool TextEdit::saveAs() | 715 | bool TextEdit::saveAs() |
714 | { | 716 | { |
715 | qDebug("saveAsFile "+currentFileName); | 717 | qDebug("saveAsFile "+currentFileName); |
716 | 718 | ||
717 | // case of nothing to save... /// there's always something to save | 719 | // case of nothing to save... /// there's always something to save |
718 | // if ( !doc )//|| !bFromDocView) | 720 | // if ( !doc )//|| !bFromDocView) |
719 | // { | 721 | // { |
720 | // qDebug("no doc"); | 722 | // qDebug("no doc"); |
721 | // return true; | 723 | // return true; |
722 | // } | 724 | // } |
723 | if ( !editor->edited() ) { | 725 | if ( !editor->edited() ) { |
724 | delete doc; | 726 | delete doc; |
725 | doc = 0; | 727 | doc = 0; |
726 | return true; | 728 | return true; |
727 | } | 729 | } |
728 | 730 | ||
729 | QString rt = editor->text(); | 731 | QString rt = editor->text(); |
730 | qDebug(currentFileName); | 732 | qDebug(currentFileName); |
731 | 733 | ||
732 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 734 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
733 | qDebug("do silly TT filename thing"); | 735 | qDebug("do silly TT filename thing"); |
734 | if ( doc->name().isEmpty() ) { | 736 | if ( doc->name().isEmpty() ) { |
735 | QString pt = rt.simplifyWhiteSpace(); | 737 | QString pt = rt.simplifyWhiteSpace(); |
736 | int i = pt.find( ' ' ); | 738 | int i = pt.find( ' ' ); |
737 | QString docname = pt; | 739 | QString docname = pt; |
738 | if ( i > 0 ) | 740 | if ( i > 0 ) |
739 | docname = pt.left( i ); | 741 | docname = pt.left( i ); |
740 | // remove "." at the beginning | 742 | // remove "." at the beginning |
741 | while( docname.startsWith( "." ) ) | 743 | while( docname.startsWith( "." ) ) |
742 | docname = docname.mid( 1 ); | 744 | docname = docname.mid( 1 ); |
743 | docname.replace( QRegExp("/"), "_" ); | 745 | docname.replace( QRegExp("/"), "_" ); |
744 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 746 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
745 | if ( docname.length() > 40 ) | 747 | if ( docname.length() > 40 ) |
746 | docname = docname.left(40); | 748 | docname = docname.left(40); |
747 | if ( docname.isEmpty() ) | 749 | if ( docname.isEmpty() ) |
748 | docname = "Unnamed"; | 750 | docname = "Unnamed"; |
749 | doc->setName(docname); | 751 | doc->setName(docname); |
750 | currentFileName=docname; | 752 | currentFileName=docname; |
751 | } | 753 | } |
752 | } | 754 | } |
753 | 755 | ||
754 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); | 756 | fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); |
755 | qDebug("wanna save filename "+currentFileName); | 757 | qDebug("wanna save filename "+currentFileName); |
756 | fileSaveDlg->exec(); | 758 | fileSaveDlg->exec(); |
757 | if( fileSaveDlg->result() == 1 ) { | 759 | if( fileSaveDlg->result() == 1 ) { |
758 | QString fileNm=fileSaveDlg->selectedFileName; | 760 | QString fileNm=fileSaveDlg->selectedFileName; |
759 | qDebug("saving filename "+fileNm); | 761 | qDebug("saving filename "+fileNm); |
760 | QFileInfo fi(fileNm); | 762 | QFileInfo fi(fileNm); |
761 | currentFileName=fi.fileName(); | 763 | currentFileName=fi.fileName(); |
762 | if(doc) { | 764 | if(doc) { |
763 | qDebug("doclnk exists"); | 765 | qDebug("doclnk exists"); |
764 | // QString file = doc->file(); | 766 | // QString file = doc->file(); |
765 | // doc->removeFiles(); | 767 | // doc->removeFiles(); |
766 | delete doc; | 768 | delete doc; |
767 | DocLnk nf; | 769 | DocLnk nf; |
768 | nf.setType("text/plain"); | 770 | nf.setType("text/plain"); |
769 | nf.setFile( fileNm); | 771 | nf.setFile( fileNm); |
770 | doc = new DocLnk(nf); | 772 | doc = new DocLnk(nf); |
771 | // editor->setText(rt); | 773 | // editor->setText(rt); |
772 | qDebug("openFile doclnk "+currentFileName); | 774 | qDebug("openFile doclnk "+currentFileName); |
773 | } | 775 | } |
774 | doc->setName( currentFileName); | 776 | doc->setName( currentFileName); |
775 | updateCaption( currentFileName); | 777 | updateCaption( currentFileName); |
776 | 778 | ||
777 | FileManager fm; | 779 | FileManager fm; |
778 | if ( !fm.saveFile( *doc, rt ) ) { | 780 | if ( !fm.saveFile( *doc, rt ) ) { |
779 | return false; | 781 | return false; |
780 | } | 782 | } |
781 | // delete doc; | 783 | // delete doc; |
782 | // doc = 0; | 784 | // doc = 0; |
783 | editor->setEdited( false ); | 785 | editor->setEdited( false ); |
784 | } | 786 | } |
785 | if(fileSaveDlg) | 787 | if(fileSaveDlg) |
786 | delete fileSaveDlg; | 788 | delete fileSaveDlg; |
787 | return true; | 789 | return true; |
788 | } | 790 | } |
789 | 791 | ||
790 | void TextEdit::clear() | 792 | void TextEdit::clear() |
791 | { | 793 | { |
792 | delete doc; | 794 | delete doc; |
793 | doc = 0; | 795 | doc = 0; |
794 | editor->clear(); | 796 | editor->clear(); |
795 | } | 797 | } |
796 | 798 | ||
797 | void TextEdit::updateCaption( const QString &name ) | 799 | void TextEdit::updateCaption( const QString &name ) |
798 | { | 800 | { |
799 | if ( !doc ) | 801 | if ( !doc ) |
800 | setCaption( tr("Text Editor") ); | 802 | setCaption( tr("Text Editor") ); |
801 | else { | 803 | else { |
802 | QString s = name; | 804 | QString s = name; |
803 | if ( s.isNull() ) | 805 | if ( s.isNull() ) |
804 | s = doc->name(); | 806 | s = doc->name(); |
805 | if ( s.isEmpty() ) { | 807 | if ( s.isEmpty() ) { |
806 | s = tr( "Unnamed" ); | 808 | s = tr( "Unnamed" ); |
807 | currentFileName=s; | 809 | currentFileName=s; |
808 | } | 810 | } |
809 | 811 | ||
810 | setCaption( s + " - " + tr("Text Editor") ); | 812 | setCaption( s + " - " + tr("Text Editor") ); |
811 | } | 813 | } |
812 | } | 814 | } |
813 | 815 | ||
814 | void TextEdit::setDocument(const QString& fileref) | 816 | void TextEdit::setDocument(const QString& fileref) |
815 | { | 817 | { |
816 | bFromDocView = TRUE; | 818 | bFromDocView = TRUE; |
817 | openFile(DocLnk(fileref)); | 819 | openFile(DocLnk(fileref)); |
818 | // showEditTools(); | 820 | // showEditTools(); |
819 | } | 821 | } |
820 | 822 | ||
821 | void TextEdit::closeEvent( QCloseEvent *e ) | 823 | void TextEdit::closeEvent( QCloseEvent *e ) |
822 | { | 824 | { |
823 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 825 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { |
824 | e->ignore(); | 826 | e->ignore(); |
825 | repaint(); | 827 | repaint(); |
826 | // fileRevert(); | 828 | // fileRevert(); |
827 | 829 | ||
828 | } else { | 830 | } else { |
829 | bFromDocView = FALSE; | 831 | bFromDocView = FALSE; |
830 | e->accept(); | 832 | e->accept(); |
831 | } | 833 | } |
832 | } | 834 | } |
833 | 835 | ||
834 | void TextEdit::accept() | 836 | void TextEdit::accept() |
835 | { | 837 | { |
836 | close(); | 838 | close(); |
837 | // fileOpen(); //godamn thats obnoxious! lemme out!!! | 839 | // fileOpen(); //godamn thats obnoxious! lemme out!!! |
838 | } | 840 | } |
839 | 841 | ||
840 | void TextEdit::changeFont() { | 842 | void TextEdit::changeFont() { |
841 | FontDatabase fdb; | 843 | FontDatabase fdb; |
842 | QFont defaultFont=editor->font(); | 844 | QFont defaultFont=editor->font(); |
843 | QFontInfo fontInfo(defaultFont); | 845 | QFontInfo fontInfo(defaultFont); |
844 | Config cfg("TextEdit"); | 846 | Config cfg("TextEdit"); |
845 | cfg.setGroup("Font"); | 847 | cfg.setGroup("Font"); |
846 | QString family = cfg.readEntry("Family", fontInfo.family()); | 848 | QString family = cfg.readEntry("Family", fontInfo.family()); |
847 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 849 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
848 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 850 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
849 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 851 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
850 | 852 | ||
851 | defaultFont = fdb.font(family,style,i_size,charSet); | 853 | defaultFont = fdb.font(family,style,i_size,charSet); |
852 | 854 | ||
853 | FontDialog *fontDlg; | 855 | FontDialog *fontDlg; |
854 | fontDlg=new FontDialog(this,"FontDialog",TRUE); | 856 | fontDlg=new FontDialog(this,"FontDialog",TRUE); |
855 | 857 | ||
856 | fontDlg->exec(); | 858 | fontDlg->exec(); |
857 | 859 | ||
858 | QFont myFont=fontDlg->selectedFont; | 860 | QFont myFont=fontDlg->selectedFont; |
859 | editor->setFont( myFont); | 861 | editor->setFont( myFont); |
860 | delete fontDlg; | 862 | delete fontDlg; |
861 | 863 | ||
862 | } | 864 | } |
863 | 865 | ||
864 | void TextEdit::editDelete() | 866 | void TextEdit::editDelete() |
865 | { | 867 | { |
866 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { | 868 | switch ( QMessageBox::warning(this,"Text Editor","Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!","Yes","No",0,0,1) ) { |
867 | case 0: | 869 | case 0: |
868 | if(doc) { | 870 | if(doc) { |
869 | doc->removeFiles(); | 871 | doc->removeFiles(); |
870 | clear(); | 872 | clear(); |
871 | } | 873 | } |
872 | break; | 874 | break; |
873 | case 1: | 875 | case 1: |
874 | // exit | 876 | // exit |
875 | break; | 877 | break; |
876 | }; | 878 | }; |
877 | } | 879 | } |