author | llornkcor <llornkcor> | 2002-04-24 01:00:52 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-24 01:00:52 (UTC) |
commit | 29e4dd18cbbe6d5967561b428a9632629cff3fde (patch) (unidiff) | |
tree | 4e3f6daaabd72937b2d1222f22d5797bb4c80b96 | |
parent | 23f73a3a483a4daf3a26d0e83fd947d4f4118013 (diff) | |
download | opie-29e4dd18cbbe6d5967561b428a9632629cff3fde.zip opie-29e4dd18cbbe6d5967561b428a9632629cff3fde.tar.gz opie-29e4dd18cbbe6d5967561b428a9632629cff3fde.tar.bz2 |
changed way of saving files, so a file opened through the file dialog, which is not a DocLnk, gets saved without a DocLnk. I got tired of hearing, 'I edited /etc/so-and-so and it saved it to Documents.' Will make this an option later. :)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 40 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 2 |
2 files changed, 33 insertions, 9 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 84888c1..19449cb 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -321,126 +321,129 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
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(tr("Font"), this, SLOT(changeFont()) ); | 346 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
347 | 347 | ||
348 | font->insertSeparator(); | 348 | font->insertSeparator(); |
349 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 349 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
350 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 350 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
351 | nStart->setToggleAction(TRUE); | 351 | nStart->setToggleAction(TRUE); |
352 | nStart->addTo( font ); | 352 | nStart->addTo( font ); |
353 | font->insertSeparator(); | ||
354 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | ||
353 | 355 | ||
354 | mb->insertItem( tr( "File" ), file ); | 356 | mb->insertItem( tr( "File" ), file ); |
355 | mb->insertItem( tr( "Edit" ), edit ); | 357 | mb->insertItem( tr( "Edit" ), edit ); |
356 | mb->insertItem( tr( "View" ), font ); | 358 | mb->insertItem( tr( "View" ), font ); |
357 | 359 | ||
358 | searchBar = new QPEToolBar(this); | 360 | searchBar = new QPEToolBar(this); |
359 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 361 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
360 | 362 | ||
361 | searchBar->setHorizontalStretchable( TRUE ); | 363 | searchBar->setHorizontalStretchable( TRUE ); |
362 | 364 | ||
363 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 365 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
364 | searchBar->setStretchableWidget( searchEdit ); | 366 | searchBar->setStretchableWidget( searchEdit ); |
365 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 367 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
366 | this, SLOT( search() ) ); | 368 | this, SLOT( search() ) ); |
367 | 369 | ||
368 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 370 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
369 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 371 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
370 | a->addTo( searchBar ); | 372 | a->addTo( searchBar ); |
371 | a->addTo( edit ); | 373 | a->addTo( edit ); |
372 | 374 | ||
373 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 375 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
374 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 376 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
375 | a->addTo( searchBar ); | 377 | a->addTo( searchBar ); |
376 | 378 | ||
377 | edit->insertSeparator(); | 379 | edit->insertSeparator(); |
378 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 380 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
379 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 381 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
380 | a->addTo( edit ); | 382 | a->addTo( edit ); |
381 | 383 | ||
382 | searchBar->hide(); | 384 | searchBar->hide(); |
383 | 385 | ||
384 | editor = new QpeEditor( this ); | 386 | editor = new QpeEditor( this ); |
385 | setCentralWidget( editor ); | 387 | setCentralWidget( editor ); |
386 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 388 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
387 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 389 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); |
388 | 390 | ||
389 | // resize( 200, 300 ); | 391 | // resize( 200, 300 ); |
390 | 392 | ||
391 | // setFontSize(defsize,TRUE); | 393 | // setFontSize(defsize,TRUE); |
392 | FontDatabase fdb; | 394 | FontDatabase fdb; |
393 | QFont defaultFont=editor->font(); | 395 | QFont defaultFont=editor->font(); |
394 | QFontInfo fontInfo(defaultFont); | 396 | QFontInfo fontInfo(defaultFont); |
395 | 397 | ||
396 | cfg.setGroup("Font"); | 398 | cfg.setGroup("Font"); |
397 | QString family = cfg.readEntry("Family", fontInfo.family()); | 399 | QString family = cfg.readEntry("Family", fontInfo.family()); |
398 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 400 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
399 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 401 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
400 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 402 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
401 | 403 | ||
402 | defaultFont = fdb.font(family,style,i_size,charSet); | 404 | defaultFont = fdb.font(family,style,i_size,charSet); |
403 | editor->setFont( defaultFont); | 405 | editor->setFont( defaultFont); |
404 | 406 | ||
405 | wa->setOn(wrap); | 407 | wa->setOn(wrap); |
406 | updateCaption(); | 408 | updateCaption(); |
407 | 409 | ||
408 | cfg.setGroup("View"); | 410 | cfg.setGroup("View"); |
409 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 411 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { |
410 | nStart->setOn(TRUE); | 412 | nStart->setOn(TRUE); |
411 | fileNew(); | 413 | fileNew(); |
412 | } else { | 414 | } else { |
413 | fileOpen(); | 415 | fileOpen(); |
414 | } | 416 | } |
417 | |||
415 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 418 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
416 | } | 419 | } |
417 | 420 | ||
418 | void TextEdit::cleanUp() | 421 | void TextEdit::cleanUp() |
419 | { | 422 | { |
420 | // save(); | 423 | // save(); |
421 | Config cfg("TextEdit"); | 424 | Config cfg("TextEdit"); |
422 | cfg.setGroup("View"); | 425 | cfg.setGroup("View"); |
423 | QFont f = editor->font(); | 426 | QFont f = editor->font(); |
424 | cfg.writeEntry("FontSize",f.pointSize()); | 427 | cfg.writeEntry("FontSize",f.pointSize()); |
425 | cfg.writeEntry("Bold",f.bold()); | 428 | cfg.writeEntry("Bold",f.bold()); |
426 | cfg.writeEntry("Italic",f.italic()); | 429 | cfg.writeEntry("Italic",f.italic()); |
427 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 430 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
428 | cfg.writeEntry( "FileView", viewSelection ); | 431 | cfg.writeEntry( "FileView", viewSelection ); |
429 | 432 | ||
430 | } | 433 | } |
431 | 434 | ||
432 | TextEdit::~TextEdit() | 435 | TextEdit::~TextEdit() |
433 | { | 436 | { |
434 | } | 437 | } |
435 | 438 | ||
436 | void TextEdit::zoomIn() | 439 | void TextEdit::zoomIn() |
437 | { | 440 | { |
438 | setFontSize(editor->font().pointSize()+1,FALSE); | 441 | setFontSize(editor->font().pointSize()+1,FALSE); |
439 | } | 442 | } |
440 | 443 | ||
441 | void TextEdit::zoomOut() | 444 | void TextEdit::zoomOut() |
442 | { | 445 | { |
443 | setFontSize(editor->font().pointSize()-1,TRUE); | 446 | setFontSize(editor->font().pointSize()-1,TRUE); |
444 | } | 447 | } |
445 | 448 | ||
446 | 449 | ||
@@ -475,95 +478,95 @@ void TextEdit::setBold(bool y) | |||
475 | QFont f = editor->font(); | 478 | QFont f = editor->font(); |
476 | f.setBold(y); | 479 | f.setBold(y); |
477 | editor->setFont(f); | 480 | editor->setFont(f); |
478 | } | 481 | } |
479 | 482 | ||
480 | void TextEdit::setItalic(bool y) | 483 | void TextEdit::setItalic(bool y) |
481 | { | 484 | { |
482 | QFont f = editor->font(); | 485 | QFont f = editor->font(); |
483 | f.setItalic(y); | 486 | f.setItalic(y); |
484 | editor->setFont(f); | 487 | editor->setFont(f); |
485 | } | 488 | } |
486 | 489 | ||
487 | void TextEdit::setWordWrap(bool y) | 490 | void TextEdit::setWordWrap(bool y) |
488 | { | 491 | { |
489 | bool state = editor->edited(); | 492 | bool state = editor->edited(); |
490 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 493 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
491 | editor->setEdited( state ); | 494 | editor->setEdited( state ); |
492 | } | 495 | } |
493 | 496 | ||
494 | void TextEdit::fileNew() | 497 | void TextEdit::fileNew() |
495 | { | 498 | { |
496 | // if( !bFromDocView ) { | 499 | // if( !bFromDocView ) { |
497 | // saveAs(); | 500 | // saveAs(); |
498 | // } | 501 | // } |
499 | newFile(DocLnk()); | 502 | newFile(DocLnk()); |
500 | } | 503 | } |
501 | 504 | ||
502 | void TextEdit::fileOpen() | 505 | void TextEdit::fileOpen() |
503 | { | 506 | { |
504 | Config cfg("TextEdit"); | 507 | Config cfg("TextEdit"); |
505 | cfg.setGroup("View"); | 508 | cfg.setGroup("View"); |
506 | bool b=FALSE; | 509 | bool b=FALSE; |
507 | if(cfg.readEntry("useOldFileDialog") == "TRUE") | 510 | if(cfg.readEntry("useOldFileDialog") == "TRUE") |
508 | b=TRUE; | 511 | b=TRUE; |
509 | if(!b) { | 512 | if(!b) { |
510 | QString str = OFileDialog::getOpenFileName( 1,"/","", "text/plain", this ); | 513 | QString str = OFileDialog::getOpenFileName( 1,"/","", "text/plain", this ); |
511 | if(!str.isEmpty() ) | 514 | if(!str.isEmpty() ) |
512 | openFile( str ); | 515 | openFile( str ); |
513 | } else { | 516 | } else { |
514 | QString str; | 517 | QString str; |
515 | browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); // | 518 | browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); // |
516 | browseForFiles->setFileView( viewSelection ); | 519 | browseForFiles->setFileView( viewSelection ); |
517 | browseForFiles->showMaximized(); | 520 | browseForFiles->showMaximized(); |
518 | // if( result != -1 ) | 521 | // if( result != -1 ) |
519 | 522 | ||
520 | if( browseForFiles->exec() != -1 ) { | 523 | if( browseForFiles->exec() != -1 ) { |
521 | QString selFile = browseForFiles->selectedFileName; | 524 | QString selFile = browseForFiles->selectedFileName; |
522 | QStringList fileList = browseForFiles->fileList; | 525 | QStringList fileList = browseForFiles->fileList; |
523 | qDebug(selFile); | 526 | qDebug(selFile); |
524 | QStringList::ConstIterator f; | 527 | QStringList::ConstIterator f; |
525 | QString fileTemp; | 528 | QString fileTemp; |
526 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { | 529 | for ( f = fileList.begin(); f != fileList.end(); f++ ) { |
527 | fileTemp = *f; | 530 | fileTemp = *f; |
528 | fileTemp.right( fileTemp.length()-5); | 531 | fileTemp.right( fileTemp.length()-5); |
529 | QString fileName = fileTemp; | 532 | QString fileName = fileTemp; |
530 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { | 533 | if( fileName != "Unnamed" || fileName != "Empty Text" ) { |
531 | currentFileName = fileName; | 534 | currentFileName = fileName; |
532 | qDebug("please open "+currentFileName); | 535 | qDebug("please open "+currentFileName); |
533 | openFile(str ); | 536 | openFile(currentFileName ); |
534 | } | 537 | } |
535 | } | 538 | } |
536 | viewSelection = browseForFiles->SelectionCombo->currentItem(); | 539 | viewSelection = browseForFiles->SelectionCombo->currentItem(); |
537 | } | 540 | } |
538 | delete browseForFiles; | 541 | delete browseForFiles; |
539 | editor->setEdited( FALSE); | 542 | editor->setEdited( FALSE); |
540 | edited1=FALSE; | 543 | edited1=FALSE; |
541 | edited=FALSE; | 544 | edited=FALSE; |
542 | if(caption().left(1)=="*") | 545 | if(caption().left(1)=="*") |
543 | setCaption(caption().right(caption().length()-1)); | 546 | setCaption(caption().right(caption().length()-1)); |
544 | doSearchBar(); | 547 | doSearchBar(); |
545 | } | 548 | } |
546 | } | 549 | } |
547 | 550 | ||
548 | void TextEdit::doSearchBar() | 551 | void TextEdit::doSearchBar() |
549 | { | 552 | { |
550 | Config cfg("TextEdit"); | 553 | Config cfg("TextEdit"); |
551 | cfg.setGroup("View"); | 554 | cfg.setGroup("View"); |
552 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 555 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
553 | searchBar->hide(); | 556 | searchBar->hide(); |
554 | } | 557 | } |
555 | 558 | ||
556 | #if 0 | 559 | #if 0 |
557 | void TextEdit::slotFind() | 560 | void TextEdit::slotFind() |
558 | { | 561 | { |
559 | FindDialog frmFind( tr("Text Editor"), this ); | 562 | FindDialog frmFind( tr("Text Editor"), this ); |
560 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 563 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
561 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 564 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
562 | 565 | ||
563 | //case sensitive, backwards, [category] | 566 | //case sensitive, backwards, [category] |
564 | 567 | ||
565 | connect( editor, SIGNAL(notFound()), | 568 | connect( editor, SIGNAL(notFound()), |
566 | &frmFind, SLOT(slotNotFound()) ); | 569 | &frmFind, SLOT(slotNotFound()) ); |
567 | connect( editor, SIGNAL(searchWrapped()), | 570 | connect( editor, SIGNAL(searchWrapped()), |
568 | &frmFind, SLOT(slotWrapAround()) ); | 571 | &frmFind, SLOT(slotWrapAround()) ); |
569 | 572 | ||
@@ -634,66 +637,68 @@ void TextEdit::search() | |||
634 | 637 | ||
635 | void TextEdit::newFile( const DocLnk &f ) | 638 | void TextEdit::newFile( const DocLnk &f ) |
636 | { | 639 | { |
637 | DocLnk nf = f; | 640 | DocLnk nf = f; |
638 | nf.setType("text/plain"); | 641 | nf.setType("text/plain"); |
639 | clear(); | 642 | clear(); |
640 | setWState (WState_Reserved1 ); | 643 | setWState (WState_Reserved1 ); |
641 | editor->setFocus(); | 644 | editor->setFocus(); |
642 | doc = new DocLnk(nf); | 645 | doc = new DocLnk(nf); |
643 | currentFileName = "Unnamed"; | 646 | currentFileName = "Unnamed"; |
644 | qDebug("newFile "+currentFileName); | 647 | qDebug("newFile "+currentFileName); |
645 | updateCaption( currentFileName); | 648 | updateCaption( currentFileName); |
646 | // editor->setEdited( FALSE); | 649 | // editor->setEdited( FALSE); |
647 | } | 650 | } |
648 | 651 | ||
649 | void TextEdit::openFile( const QString &f ) | 652 | void TextEdit::openFile( const QString &f ) |
650 | { | 653 | { |
651 | qDebug("filename is "+ f); | 654 | qDebug("filename is "+ f); |
652 | QString filer; | 655 | QString filer; |
653 | // bFromDocView = TRUE; | 656 | // bFromDocView = TRUE; |
654 | if(f.find(".desktop",0,TRUE) != -1) { | 657 | if(f.find(".desktop",0,TRUE) != -1) { |
655 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 658 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
656 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), | 659 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), |
657 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 660 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
658 | case 0: | 661 | case 0: |
659 | filer = f; | 662 | filer = f; |
660 | break; | 663 | break; |
661 | case 1: | 664 | case 1: |
662 | DocLnk sf(f); | 665 | DocLnk sf(f); |
663 | filer = sf.file(); | 666 | filer = sf.file(); |
664 | break; | 667 | break; |
665 | } | 668 | } |
666 | } else | 669 | } else { |
667 | filer = f; | 670 | filer = f; |
671 | fileIs = TRUE; | ||
672 | } | ||
668 | 673 | ||
669 | DocLnk nf; | 674 | DocLnk nf; |
670 | nf.setType("text/plain"); | 675 | nf.setType("text/plain"); |
671 | nf.setFile(filer); | 676 | nf.setFile(filer); |
672 | currentFileName=filer; | 677 | currentFileName=filer; |
673 | QFileInfo fi( currentFileName); | 678 | QFileInfo fi( currentFileName); |
674 | nf.setName(fi.baseName()); | 679 | nf.setName(fi.baseName()); |
675 | qDebug("openFile string "+currentFileName); | 680 | qDebug("openFile string "+currentFileName); |
676 | 681 | ||
677 | openFile(nf); | 682 | openFile(nf); |
678 | showEditTools(); | 683 | showEditTools(); |
679 | // Show filename in caption | 684 | // Show filename in caption |
680 | QString name = filer; | 685 | QString name = filer; |
681 | int sep = name.findRev( '/' ); | 686 | int sep = name.findRev( '/' ); |
682 | if ( sep > 0 ) | 687 | if ( sep > 0 ) |
683 | name = name.mid( sep+1 ); | 688 | name = name.mid( sep+1 ); |
684 | updateCaption( name ); | 689 | updateCaption( name ); |
685 | } | 690 | } |
686 | 691 | ||
687 | void TextEdit::openFile( const DocLnk &f ) | 692 | void TextEdit::openFile( const DocLnk &f ) |
688 | { | 693 | { |
689 | // clear(); | 694 | // clear(); |
690 | // bFromDocView = TRUE; | 695 | // bFromDocView = TRUE; |
691 | FileManager fm; | 696 | FileManager fm; |
692 | QString txt; | 697 | QString txt; |
693 | currentFileName=f.file(); | 698 | currentFileName=f.file(); |
694 | qDebug("openFile doclnk " + currentFileName); | 699 | qDebug("openFile doclnk " + currentFileName); |
695 | if ( !fm.loadFile( f, txt ) ) { | 700 | if ( !fm.loadFile( f, txt ) ) { |
696 | // ####### could be a new file | 701 | // ####### could be a new file |
697 | qDebug( "Cannot open file" ); | 702 | qDebug( "Cannot open file" ); |
698 | } | 703 | } |
699 | // fileNew(); | 704 | // fileNew(); |
@@ -713,69 +718,80 @@ void TextEdit::showEditTools() | |||
713 | { | 718 | { |
714 | // if ( !doc ) | 719 | // if ( !doc ) |
715 | // close(); | 720 | // close(); |
716 | // clear(); | 721 | // clear(); |
717 | menu->show(); | 722 | menu->show(); |
718 | editBar->show(); | 723 | editBar->show(); |
719 | if ( searchVisible ) | 724 | if ( searchVisible ) |
720 | searchBar->show(); | 725 | searchBar->show(); |
721 | // updateCaption(); | 726 | // updateCaption(); |
722 | setWState (WState_Reserved1 ); | 727 | setWState (WState_Reserved1 ); |
723 | } | 728 | } |
724 | 729 | ||
725 | /*! | 730 | /*! |
726 | unprompted save */ | 731 | unprompted save */ |
727 | bool TextEdit::save() | 732 | bool TextEdit::save() |
728 | { | 733 | { |
729 | QString file = doc->file(); | 734 | QString file = doc->file(); |
730 | qDebug("saver file "+file); | 735 | qDebug("saver file "+file); |
731 | QString name= doc->name(); | 736 | QString name= doc->name(); |
732 | qDebug("File named "+name); | 737 | qDebug("File named "+name); |
733 | QString rt = editor->text(); | 738 | QString rt = editor->text(); |
734 | if( !rt.isEmpty() ) { | 739 | if( !rt.isEmpty() ) { |
735 | if(name.isEmpty()) { | 740 | if(name.isEmpty()) { |
736 | saveAs(); | 741 | saveAs(); |
737 | } else { | 742 | } else { |
738 | currentFileName= name ; | 743 | currentFileName= name ; |
739 | qDebug("saveFile "+currentFileName); | 744 | qDebug("saveFile "+currentFileName); |
740 | 745 | ||
741 | struct stat buf; | 746 | struct stat buf; |
742 | mode_t mode; | 747 | mode_t mode; |
743 | stat(file.latin1(), &buf); | 748 | stat(file.latin1(), &buf); |
744 | mode = buf.st_mode; | 749 | mode = buf.st_mode; |
745 | 750 | if(!fileIs) { | |
746 | doc->setName( name); | 751 | doc->setName( name); |
747 | FileManager fm; | 752 | FileManager fm; |
748 | if ( !fm.saveFile( *doc, rt ) ) { | 753 | if ( !fm.saveFile( *doc, rt ) ) { |
749 | return false; | 754 | return false; |
755 | } | ||
756 | } else { | ||
757 | qDebug("regular save file"); | ||
758 | QFile f(file); | ||
759 | if( f.open(IO_WriteOnly)) { | ||
760 | f.writeBlock(rt,rt.length()); | ||
761 | } else { | ||
762 | QMessageBox::message("Text Edit","Write Failed"); | ||
763 | return false; | ||
764 | } | ||
765 | |||
750 | } | 766 | } |
751 | editor->setEdited( FALSE); | 767 | editor->setEdited( FALSE); |
752 | edited1=FALSE; | 768 | edited1=FALSE; |
753 | edited=FALSE; | 769 | edited=FALSE; |
754 | if(caption().left(1)=="*") | 770 | if(caption().left(1)=="*") |
755 | setCaption(caption().right(caption().length()-1)); | 771 | setCaption(caption().right(caption().length()-1)); |
756 | 772 | ||
757 | 773 | ||
758 | chmod( file.latin1(), mode); | 774 | chmod( file.latin1(), mode); |
759 | } | 775 | } |
760 | return true; | 776 | return true; |
761 | } | 777 | } |
762 | return false; | 778 | return false; |
763 | } | 779 | } |
764 | 780 | ||
765 | /*! | 781 | /*! |
766 | prompted save */ | 782 | prompted save */ |
767 | bool TextEdit::saveAs() | 783 | bool TextEdit::saveAs() |
768 | { | 784 | { |
769 | // qDebug("saveAsFile "+currentFileName); | 785 | // qDebug("saveAsFile "+currentFileName); |
770 | // case of nothing to save... | 786 | // case of nothing to save... |
771 | if ( !doc )//|| !bFromDocView) | 787 | if ( !doc )//|| !bFromDocView) |
772 | { | 788 | { |
773 | qDebug("no doc"); | 789 | qDebug("no doc"); |
774 | return true; | 790 | return true; |
775 | } | 791 | } |
776 | if ( !editor->edited() ) { | 792 | if ( !editor->edited() ) { |
777 | delete doc; | 793 | delete doc; |
778 | doc = 0; | 794 | doc = 0; |
779 | return true; | 795 | return true; |
780 | } | 796 | } |
781 | 797 | ||
@@ -940,32 +956,38 @@ void TextEdit::editDelete() | |||
940 | break; | 956 | break; |
941 | }; | 957 | }; |
942 | } | 958 | } |
943 | 959 | ||
944 | void TextEdit::changeStartConfig( bool b ) { | 960 | void TextEdit::changeStartConfig( bool b ) { |
945 | 961 | ||
946 | Config cfg("TextEdit"); | 962 | Config cfg("TextEdit"); |
947 | cfg.setGroup("View"); | 963 | cfg.setGroup("View"); |
948 | if(b) { | 964 | if(b) { |
949 | qDebug("bool"); | 965 | qDebug("bool"); |
950 | cfg.writeEntry("startNew","TRUE"); | 966 | cfg.writeEntry("startNew","TRUE"); |
951 | } else { | 967 | } else { |
952 | cfg.writeEntry("startNew","FALSE"); | 968 | cfg.writeEntry("startNew","FALSE"); |
953 | } | 969 | } |
954 | update(); | 970 | update(); |
955 | } | 971 | } |
956 | 972 | ||
957 | void TextEdit::editorChanged() { | 973 | void TextEdit::editorChanged() { |
958 | if(editor->edited() && edited && !edited1) { | 974 | if(editor->edited() && edited && !edited1) { |
959 | setCaption( "*"+caption()); | 975 | setCaption( "*"+caption()); |
960 | edited1=TRUE; | 976 | edited1=TRUE; |
961 | } | 977 | } |
962 | edited=TRUE; | 978 | edited=TRUE; |
963 | } | 979 | } |
964 | 980 | ||
965 | void TextEdit::receive(const QCString&msg, const QByteArray&) { | 981 | void TextEdit::receive(const QCString&msg, const QByteArray&) { |
966 | qDebug("QCop "+msg); | 982 | qDebug("QCop "+msg); |
967 | if ( msg == "setDocument(QString)" ) { | 983 | if ( msg == "setDocument(QString)" ) { |
968 | qDebug("bugger all"); | 984 | qDebug("bugger all"); |
969 | } | 985 | } |
970 | 986 | ||
971 | } | 987 | } |
988 | void TextEdit::doAbout() { | ||
989 | QMessageBox::about(0,"Text Edit","Text Edit is copyright\n" | ||
990 | "2000 Trolltech AS, and\n" | ||
991 | "2002 by L.J.Potter \nljp@llornkcor.com\n" | ||
992 | "and is licensed under the GPL"); | ||
993 | } | ||
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index edc6fe3..9d27ab0 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -36,67 +36,69 @@ | |||
36 | #include <qmultilineedit.h> | 36 | #include <qmultilineedit.h> |
37 | #include <qlist.h> | 37 | #include <qlist.h> |
38 | #include <qmap.h> | 38 | #include <qmap.h> |
39 | 39 | ||
40 | class QAction; | 40 | class QAction; |
41 | class QWidgetStack; | 41 | class QWidgetStack; |
42 | class QToolButton; | 42 | class QToolButton; |
43 | class QPopupMenu; | 43 | class QPopupMenu; |
44 | class QToolBar; | 44 | class QToolBar; |
45 | class QLineEdit; | 45 | class QLineEdit; |
46 | class QAction; | 46 | class QAction; |
47 | class FileSelector; | 47 | class FileSelector; |
48 | class QpeEditor; | 48 | class QpeEditor; |
49 | class QPopupMenu; | 49 | class QPopupMenu; |
50 | 50 | ||
51 | class TextEdit : public QMainWindow | 51 | class TextEdit : public QMainWindow |
52 | { | 52 | { |
53 | Q_OBJECT | 53 | Q_OBJECT |
54 | 54 | ||
55 | public: | 55 | public: |
56 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 56 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
57 | ~TextEdit(); | 57 | ~TextEdit(); |
58 | 58 | ||
59 | QPopupMenu *font; | 59 | QPopupMenu *font; |
60 | QAction *nStart, *nFileDlgOpt; | 60 | QAction *nStart, *nFileDlgOpt; |
61 | bool edited, edited1; | 61 | bool edited, edited1; |
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; | ||
68 | void closeEvent( QCloseEvent *e ); | 69 | void closeEvent( QCloseEvent *e ); |
69 | void doSearchBar(); | 70 | void doSearchBar(); |
70 | private slots: | 71 | private slots: |
72 | void doAbout(); | ||
71 | void setDocument(const QString&); | 73 | void setDocument(const QString&); |
72 | void changeFont(); | 74 | void changeFont(); |
73 | void fileNew(); | 75 | void fileNew(); |
74 | void fileRevert(); | 76 | void fileRevert(); |
75 | void fileOpen(); | 77 | void fileOpen(); |
76 | void changeStartConfig(bool); | 78 | void changeStartConfig(bool); |
77 | bool save(); | 79 | bool save(); |
78 | bool saveAs(); | 80 | bool saveAs(); |
79 | void cleanUp(); | 81 | void cleanUp(); |
80 | 82 | ||
81 | 83 | ||
82 | void editCut(); | 84 | void editCut(); |
83 | void editCopy(); | 85 | void editCopy(); |
84 | void editPaste(); | 86 | void editPaste(); |
85 | void editFind(); | 87 | void editFind(); |
86 | void editDelete(); | 88 | void editDelete(); |
87 | 89 | ||
88 | void findNext(); | 90 | void findNext(); |
89 | void findClose(); | 91 | void findClose(); |
90 | 92 | ||
91 | void search(); | 93 | void search(); |
92 | void accept(); | 94 | void accept(); |
93 | 95 | ||
94 | void newFile( const DocLnk & ); | 96 | void newFile( const DocLnk & ); |
95 | void openFile( const DocLnk & ); | 97 | void openFile( const DocLnk & ); |
96 | void showEditTools(); | 98 | void showEditTools(); |
97 | 99 | ||
98 | void zoomIn(); | 100 | void zoomIn(); |
99 | void zoomOut(); | 101 | void zoomOut(); |
100 | void setBold(bool y); | 102 | void setBold(bool y); |
101 | void setItalic(bool y); | 103 | void setItalic(bool y); |
102 | void setWordWrap(bool y); | 104 | void setWordWrap(bool y); |