summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-06-29 00:51:23 (UTC)
committer llornkcor <llornkcor>2002-06-29 00:51:23 (UTC)
commita9e336965e1cccb41d3e9f5c31168c85cf4e7d36 (patch) (unidiff)
treebf902af67089de044833da378d1f491574ac4965
parent9cc6f3de75b884f338f708ff03900b197f281802 (diff)
downloadopie-a9e336965e1cccb41d3e9f5c31168c85cf4e7d36.zip
opie-a9e336965e1cccb41d3e9f5c31168c85cf4e7d36.tar.gz
opie-a9e336965e1cccb41d3e9f5c31168c85cf4e7d36.tar.bz2
on your way out, save dialog
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp49
1 files changed, 29 insertions, 20 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index ea27e1b..40ea501 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -317,654 +317,663 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
317 317
318 font->insertSeparator(); 318 font->insertSeparator();
319 319
320#if 0 320#if 0
321 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); 321 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
322 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); 322 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
323 ba->setToggleAction(TRUE); 323 ba->setToggleAction(TRUE);
324 ba->addTo( font ); 324 ba->addTo( font );
325 325
326 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); 326 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
327 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); 327 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
328 ia->setToggleAction(TRUE); 328 ia->setToggleAction(TRUE);
329 ia->addTo( font ); 329 ia->addTo( font );
330 330
331 ba->setOn(defb); 331 ba->setOn(defb);
332 ia->setOn(defi); 332 ia->setOn(defi);
333 333
334 font->insertSeparator(); 334 font->insertSeparator();
335#endif 335#endif
336 336
337 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 337 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
338 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 338 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
339 wa->setToggleAction(TRUE); 339 wa->setToggleAction(TRUE);
340 wa->addTo( font ); 340 wa->addTo( font );
341 341
342 font->insertSeparator(); 342 font->insertSeparator();
343 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 343 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
344 344
345 font->insertSeparator(); 345 font->insertSeparator();
346 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); 346 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
347 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); 347 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
348 nStart->setToggleAction(TRUE); 348 nStart->setToggleAction(TRUE);
349 nStart->addTo( font ); 349 nStart->addTo( font );
350 font->insertSeparator(); 350 font->insertSeparator();
351 font->insertItem(tr("About"), this, SLOT( doAbout()) ); 351 font->insertItem(tr("About"), this, SLOT( doAbout()) );
352 352
353 mb->insertItem( tr( "File" ), file ); 353 mb->insertItem( tr( "File" ), file );
354 mb->insertItem( tr( "Edit" ), edit ); 354 mb->insertItem( tr( "Edit" ), edit );
355 mb->insertItem( tr( "View" ), font ); 355 mb->insertItem( tr( "View" ), font );
356 356
357 searchBar = new QPEToolBar(this); 357 searchBar = new QPEToolBar(this);
358 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 358 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
359 359
360 searchBar->setHorizontalStretchable( TRUE ); 360 searchBar->setHorizontalStretchable( TRUE );
361 361
362 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 362 searchEdit = new QLineEdit( searchBar, "searchEdit" );
363 searchBar->setStretchableWidget( searchEdit ); 363 searchBar->setStretchableWidget( searchEdit );
364 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 364 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
365 this, SLOT( search() ) ); 365 this, SLOT( search() ) );
366 366
367 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 367 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
368 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 368 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
369 a->addTo( searchBar ); 369 a->addTo( searchBar );
370 a->addTo( edit ); 370 a->addTo( edit );
371 371
372 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 372 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
373 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 373 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
374 a->addTo( searchBar ); 374 a->addTo( searchBar );
375 375
376 edit->insertSeparator(); 376 edit->insertSeparator();
377 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 377 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
378 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 378 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
379 a->addTo( edit ); 379 a->addTo( edit );
380 380
381 searchBar->hide(); 381 searchBar->hide();
382 382
383 editor = new QpeEditor( this ); 383 editor = new QpeEditor( this );
384 setCentralWidget( editor ); 384 setCentralWidget( editor );
385 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 385 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
386 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 386 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
387 387
388// resize( 200, 300 ); 388// resize( 200, 300 );
389 389
390// setFontSize(defsize,TRUE); 390// setFontSize(defsize,TRUE);
391 FontDatabase fdb; 391 FontDatabase fdb;
392 QFont defaultFont=editor->font(); 392 QFont defaultFont=editor->font();
393 QFontInfo fontInfo(defaultFont); 393 QFontInfo fontInfo(defaultFont);
394 394
395 cfg.setGroup("Font"); 395 cfg.setGroup("Font");
396 QString family = cfg.readEntry("Family", fontInfo.family()); 396 QString family = cfg.readEntry("Family", fontInfo.family());
397 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 397 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
398 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 398 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
399 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 399 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
400 400
401 defaultFont = fdb.font(family,style,i_size,charSet); 401 defaultFont = fdb.font(family,style,i_size,charSet);
402 editor->setFont( defaultFont); 402 editor->setFont( defaultFont);
403 403
404 wa->setOn(wrap); 404 wa->setOn(wrap);
405 updateCaption(); 405 updateCaption();
406 406
407 cfg.setGroup("View"); 407 cfg.setGroup("View");
408 if(cfg.readEntry("startNew","TRUE") == "TRUE") { 408 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
409 nStart->setOn(TRUE); 409 nStart->setOn(TRUE);
410 fileNew(); 410 fileNew();
411 } else { 411 } else {
412 fileOpen(); 412 fileOpen();
413 } 413 }
414 414
415 viewSelection = cfg.readNumEntry( "FileView", 0 ); 415 viewSelection = cfg.readNumEntry( "FileView", 0 );
416} 416}
417 417
418void TextEdit::cleanUp() 418void TextEdit::cleanUp()
419{ 419{
420// save(); 420// save();
421 Config cfg("TextEdit"); 421 Config cfg("TextEdit");
422 cfg.setGroup("View"); 422 cfg.setGroup("View");
423 QFont f = editor->font(); 423 QFont f = editor->font();
424 cfg.writeEntry("FontSize",f.pointSize()); 424 cfg.writeEntry("FontSize",f.pointSize());
425 cfg.writeEntry("Bold",f.bold()); 425 cfg.writeEntry("Bold",f.bold());
426 cfg.writeEntry("Italic",f.italic()); 426 cfg.writeEntry("Italic",f.italic());
427 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 427 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
428 cfg.writeEntry( "FileView", viewSelection ); 428 cfg.writeEntry( "FileView", viewSelection );
429 429
430} 430}
431 431
432TextEdit::~TextEdit() 432TextEdit::~TextEdit()
433{ 433{
434} 434}
435 435
436void TextEdit::zoomIn() 436void TextEdit::zoomIn()
437{ 437{
438 setFontSize(editor->font().pointSize()+1,FALSE); 438 setFontSize(editor->font().pointSize()+1,FALSE);
439} 439}
440 440
441void TextEdit::zoomOut() 441void TextEdit::zoomOut()
442{ 442{
443 setFontSize(editor->font().pointSize()-1,TRUE); 443 setFontSize(editor->font().pointSize()-1,TRUE);
444} 444}
445 445
446 446
447void TextEdit::setFontSize(int sz, bool round_down_not_up) 447void TextEdit::setFontSize(int sz, bool round_down_not_up)
448{ 448{
449 int s=10; 449 int s=10;
450 for (int i=0; i<nfontsizes; i++) { 450 for (int i=0; i<nfontsizes; i++) {
451 if ( fontsize[i] == sz ) { 451 if ( fontsize[i] == sz ) {
452 s = sz; 452 s = sz;
453 break; 453 break;
454 } else if ( round_down_not_up ) { 454 } else if ( round_down_not_up ) {
455 if ( fontsize[i] < sz ) 455 if ( fontsize[i] < sz )
456 s = fontsize[i]; 456 s = fontsize[i];
457 } else { 457 } else {
458 if ( fontsize[i] > sz ) { 458 if ( fontsize[i] > sz ) {
459 s = fontsize[i]; 459 s = fontsize[i];
460 break; 460 break;
461 } 461 }
462 } 462 }
463 } 463 }
464 464
465 QFont f = editor->font(); 465 QFont f = editor->font();
466 f.setPointSize(s); 466 f.setPointSize(s);
467 editor->setFont(f); 467 editor->setFont(f);
468 468
469 zin->setEnabled(s != fontsize[nfontsizes-1]); 469 zin->setEnabled(s != fontsize[nfontsizes-1]);
470 zout->setEnabled(s != fontsize[0]); 470 zout->setEnabled(s != fontsize[0]);
471} 471}
472 472
473void TextEdit::setBold(bool y) 473void TextEdit::setBold(bool y)
474{ 474{
475 QFont f = editor->font(); 475 QFont f = editor->font();
476 f.setBold(y); 476 f.setBold(y);
477 editor->setFont(f); 477 editor->setFont(f);
478} 478}
479 479
480void TextEdit::setItalic(bool y) 480void TextEdit::setItalic(bool y)
481{ 481{
482 QFont f = editor->font(); 482 QFont f = editor->font();
483 f.setItalic(y); 483 f.setItalic(y);
484 editor->setFont(f); 484 editor->setFont(f);
485} 485}
486 486
487void TextEdit::setWordWrap(bool y) 487void TextEdit::setWordWrap(bool y)
488{ 488{
489 bool state = editor->edited(); 489 bool state = editor->edited();
490 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 490 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
491 editor->setEdited( state ); 491 editor->setEdited( state );
492} 492}
493 493
494void TextEdit::fileNew() 494void TextEdit::fileNew()
495{ 495{
496// if( !bFromDocView ) { 496// if( !bFromDocView ) {
497// saveAs(); 497// saveAs();
498// } 498// }
499 newFile(DocLnk()); 499 newFile(DocLnk());
500} 500}
501 501
502void TextEdit::fileOpen() 502void TextEdit::fileOpen()
503{ 503{
504 Config cfg("TextEdit"); 504 Config cfg("TextEdit");
505 cfg.setGroup("View"); 505 cfg.setGroup("View");
506 bool b=FALSE; 506 bool b=FALSE;
507 507
508 QMap<QString, QStringList> map; 508 QMap<QString, QStringList> map;
509 map.insert(tr("All"), QStringList() ); 509 map.insert(tr("All"), QStringList() );
510 QStringList text; 510 QStringList text;
511 text << "text/*"; 511 text << "text/*";
512 map.insert(tr("Text"), text ); 512 map.insert(tr("Text"), text );
513 text << "*"; 513 text << "*";
514 map.insert(tr("All"), text ); 514 map.insert(tr("All"), text );
515 QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); 515 QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map);
516 if(!str.isEmpty() ) 516 if(!str.isEmpty() )
517 openFile( str ); 517 openFile( str );
518 518
519} 519}
520 520
521void TextEdit::doSearchBar() 521void TextEdit::doSearchBar()
522{ 522{
523 Config cfg("TextEdit"); 523 Config cfg("TextEdit");
524 cfg.setGroup("View"); 524 cfg.setGroup("View");
525 if(cfg.readEntry("SearchBar","Closed") != "Opened") 525 if(cfg.readEntry("SearchBar","Closed") != "Opened")
526 searchBar->hide(); 526 searchBar->hide();
527} 527}
528 528
529#if 0 529#if 0
530void TextEdit::slotFind() 530void TextEdit::slotFind()
531{ 531{
532 FindDialog frmFind( tr("Text Editor"), this ); 532 FindDialog frmFind( tr("Text Editor"), this );
533 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 533 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
534 editor, SLOT(slotDoFind( const QString&,bool,bool))); 534 editor, SLOT(slotDoFind( const QString&,bool,bool)));
535 535
536 //case sensitive, backwards, [category] 536 //case sensitive, backwards, [category]
537 537
538 connect( editor, SIGNAL(notFound()), 538 connect( editor, SIGNAL(notFound()),
539 &frmFind, SLOT(slotNotFound()) ); 539 &frmFind, SLOT(slotNotFound()) );
540 connect( editor, SIGNAL(searchWrapped()), 540 connect( editor, SIGNAL(searchWrapped()),
541 &frmFind, SLOT(slotWrapAround()) ); 541 &frmFind, SLOT(slotWrapAround()) );
542 542
543 frmFind.exec(); 543 frmFind.exec();
544 544
545 545
546} 546}
547#endif 547#endif
548 548
549void TextEdit::fileRevert() 549void TextEdit::fileRevert()
550{ 550{
551 clear(); 551 clear();
552 fileOpen(); 552 fileOpen();
553} 553}
554 554
555void TextEdit::editCut() 555void TextEdit::editCut()
556{ 556{
557#ifndef QT_NO_CLIPBOARD 557#ifndef QT_NO_CLIPBOARD
558 editor->cut(); 558 editor->cut();
559#endif 559#endif
560} 560}
561 561
562void TextEdit::editCopy() 562void TextEdit::editCopy()
563{ 563{
564#ifndef QT_NO_CLIPBOARD 564#ifndef QT_NO_CLIPBOARD
565 editor->copy(); 565 editor->copy();
566#endif 566#endif
567} 567}
568 568
569void TextEdit::editPaste() 569void TextEdit::editPaste()
570{ 570{
571#ifndef QT_NO_CLIPBOARD 571#ifndef QT_NO_CLIPBOARD
572 editor->paste(); 572 editor->paste();
573#endif 573#endif
574} 574}
575 575
576void TextEdit::editFind() 576void TextEdit::editFind()
577{ 577{
578 searchBar->show(); 578 searchBar->show();
579 searchVisible = TRUE; 579 searchVisible = TRUE;
580 searchEdit->setFocus(); 580 searchEdit->setFocus();
581 Config cfg("TextEdit"); 581 Config cfg("TextEdit");
582 cfg.setGroup("View"); 582 cfg.setGroup("View");
583 cfg.writeEntry("SearchBar","Opened"); 583 cfg.writeEntry("SearchBar","Opened");
584 584
585} 585}
586 586
587void TextEdit::findNext() 587void TextEdit::findNext()
588{ 588{
589 editor->find( searchEdit->text(), FALSE, FALSE ); 589 editor->find( searchEdit->text(), FALSE, FALSE );
590 590
591} 591}
592 592
593void TextEdit::findClose() 593void TextEdit::findClose()
594{ 594{
595 searchVisible = FALSE; 595 searchVisible = FALSE;
596 searchBar->hide(); 596 searchBar->hide();
597 Config cfg("TextEdit"); 597 Config cfg("TextEdit");
598 cfg.setGroup("View"); 598 cfg.setGroup("View");
599 cfg.writeEntry("SearchBar","Closed"); 599 cfg.writeEntry("SearchBar","Closed");
600 cfg.write(); 600 cfg.write();
601} 601}
602 602
603void TextEdit::search() 603void TextEdit::search()
604{ 604{
605 editor->find( searchEdit->text(), FALSE, FALSE ); 605 editor->find( searchEdit->text(), FALSE, FALSE );
606} 606}
607 607
608void TextEdit::newFile( const DocLnk &f ) 608void TextEdit::newFile( const DocLnk &f )
609{ 609{
610 DocLnk nf = f; 610 DocLnk nf = f;
611 nf.setType("text/plain"); 611 nf.setType("text/plain");
612 clear(); 612 clear();
613 setWState (WState_Reserved1 ); 613 setWState (WState_Reserved1 );
614 editor->setFocus(); 614 editor->setFocus();
615 doc = new DocLnk(nf); 615 doc = new DocLnk(nf);
616 currentFileName = "Unnamed"; 616 currentFileName = "Unnamed";
617 qDebug("newFile "+currentFileName); 617 qDebug("newFile "+currentFileName);
618 updateCaption( currentFileName); 618 updateCaption( currentFileName);
619// editor->setEdited( FALSE); 619// editor->setEdited( FALSE);
620} 620}
621 621
622void TextEdit::openFile( const QString &f ) 622void TextEdit::openFile( const QString &f )
623{ 623{
624 qDebug("filename is "+ f); 624 qDebug("filename is "+ f);
625 QString filer; 625 QString filer;
626// bFromDocView = TRUE; 626// bFromDocView = TRUE;
627 if(f.find(".desktop",0,TRUE) != -1) { 627 if(f.find(".desktop",0,TRUE) != -1) {
628 switch ( QMessageBox::warning(this,tr("Text Editor"), 628 switch ( QMessageBox::warning(this,tr("Text Editor"),
629 tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), 629 tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"),
630 tr(".desktop File"),tr("Linked Document"),0,1,1) ) { 630 tr(".desktop File"),tr("Linked Document"),0,1,1) ) {
631 case 0: 631 case 0:
632 filer = f; 632 filer = f;
633 break; 633 break;
634 case 1: 634 case 1:
635 DocLnk sf(f); 635 DocLnk sf(f);
636 filer = sf.file(); 636 filer = sf.file();
637 break; 637 break;
638 } 638 }
639 } else { 639 } else {
640 filer = f; 640 filer = f;
641 fileIs = TRUE; 641 fileIs = TRUE;
642 } 642 }
643 643
644 DocLnk nf; 644 DocLnk nf;
645 nf.setType("text/plain"); 645 nf.setType("text/plain");
646 nf.setFile(filer); 646 nf.setFile(filer);
647 currentFileName=filer; 647 currentFileName=filer;
648 QFileInfo fi( currentFileName); 648 QFileInfo fi( currentFileName);
649 nf.setName(fi.baseName()); 649 nf.setName(fi.baseName());
650 qDebug("openFile string "+currentFileName); 650 qDebug("openFile string "+currentFileName);
651 651
652 openFile(nf); 652 openFile(nf);
653 showEditTools(); 653 showEditTools();
654 // Show filename in caption 654 // Show filename in caption
655 QString name = filer; 655 QString name = filer;
656 int sep = name.findRev( '/' ); 656 int sep = name.findRev( '/' );
657 if ( sep > 0 ) 657 if ( sep > 0 )
658 name = name.mid( sep+1 ); 658 name = name.mid( sep+1 );
659 updateCaption( name ); 659 updateCaption( name );
660} 660}
661 661
662void TextEdit::openFile( const DocLnk &f ) 662void TextEdit::openFile( const DocLnk &f )
663{ 663{
664// clear(); 664// clear();
665// bFromDocView = TRUE; 665// bFromDocView = TRUE;
666 FileManager fm; 666 FileManager fm;
667 QString txt; 667 QString txt;
668 currentFileName=f.file(); 668 currentFileName=f.file();
669 qDebug("openFile doclnk " + currentFileName); 669 qDebug("openFile doclnk " + currentFileName);
670 if ( !fm.loadFile( f, txt ) ) { 670 if ( !fm.loadFile( f, txt ) ) {
671 // ####### could be a new file 671 // ####### could be a new file
672 qDebug( "Cannot open file" ); 672 qDebug( "Cannot open file" );
673 } 673 }
674// fileNew(); 674// fileNew();
675 if ( doc ) 675 if ( doc )
676 delete doc; 676 delete doc;
677 doc = new DocLnk(f); 677 doc = new DocLnk(f);
678 editor->setText(txt); 678 editor->setText(txt);
679 editor->setEdited( FALSE); 679 editor->setEdited( FALSE);
680 edited1=FALSE; 680 edited1=FALSE;
681 edited=FALSE; 681 edited=FALSE;
682 682
683 doc->setName(currentFileName); 683 doc->setName(currentFileName);
684 updateCaption(); 684 updateCaption();
685} 685}
686 686
687void TextEdit::showEditTools() 687void TextEdit::showEditTools()
688{ 688{
689// if ( !doc ) 689// if ( !doc )
690// close(); 690// close();
691// clear(); 691// clear();
692 menu->show(); 692 menu->show();
693 editBar->show(); 693 editBar->show();
694 if ( searchVisible ) 694 if ( searchVisible )
695 searchBar->show(); 695 searchBar->show();
696// updateCaption(); 696// updateCaption();
697 setWState (WState_Reserved1 ); 697 setWState (WState_Reserved1 );
698} 698}
699 699
700/*! 700/*!
701 unprompted save */ 701 unprompted save */
702bool TextEdit::save() 702bool TextEdit::save()
703{ 703{
704 QString file = doc->file(); 704 QString file = doc->file();
705 qDebug("saver file "+file); 705 qDebug("saver file "+file);
706 QString name= doc->name(); 706 QString name= doc->name();
707 qDebug("File named "+name); 707 qDebug("File named "+name);
708 QString rt = editor->text(); 708 QString rt = editor->text();
709 if( !rt.isEmpty() ) { 709 if( !rt.isEmpty() ) {
710 if(name.isEmpty()) { 710 if(name.isEmpty()) {
711 saveAs(); 711 saveAs();
712 } else { 712 } else {
713 currentFileName= name ; 713 currentFileName= name ;
714 qDebug("saveFile "+currentFileName); 714 qDebug("saveFile "+currentFileName);
715 715
716 struct stat buf; 716 struct stat buf;
717 mode_t mode; 717 mode_t mode;
718 stat(file.latin1(), &buf); 718 stat(file.latin1(), &buf);
719 mode = buf.st_mode; 719 mode = buf.st_mode;
720 720
721 if(!fileIs) { 721 if(!fileIs) {
722 doc->setName( name); 722 doc->setName( name);
723 FileManager fm; 723 FileManager fm;
724 if ( !fm.saveFile( *doc, rt ) ) { 724 if ( !fm.saveFile( *doc, rt ) ) {
725 return false; 725 return false;
726 } 726 }
727 } else { 727 } else {
728 qDebug("regular save file"); 728 qDebug("regular save file");
729 QFile f(file); 729 QFile f(file);
730 if( f.open(IO_WriteOnly)) { 730 if( f.open(IO_WriteOnly)) {
731 QCString crt = rt.utf8(); 731 QCString crt = rt.utf8();
732 f.writeBlock(crt,crt.length()); 732 f.writeBlock(crt,crt.length());
733 } else { 733 } else {
734 QMessageBox::message("Text Edit","Write Failed"); 734 QMessageBox::message("Text Edit","Write Failed");
735 return false; 735 return false;
736 } 736 }
737 737
738 } 738 }
739 editor->setEdited( FALSE); 739 editor->setEdited( FALSE);
740 edited1=FALSE; 740 edited1=FALSE;
741 edited=FALSE; 741 edited=FALSE;
742 if(caption().left(1)=="*") 742 if(caption().left(1)=="*")
743 setCaption(caption().right(caption().length()-1)); 743 setCaption(caption().right(caption().length()-1));
744 744
745 745
746 chmod( file.latin1(), mode); 746 chmod( file.latin1(), mode);
747 } 747 }
748 return true; 748 return true;
749 } 749 }
750 return false; 750 return false;
751} 751}
752 752
753/*! 753/*!
754 prompted save */ 754 prompted save */
755bool TextEdit::saveAs() 755bool TextEdit::saveAs()
756{ 756{
757// qDebug("saveAsFile "+currentFileName); 757// qDebug("saveAsFile "+currentFileName);
758 // case of nothing to save... 758 // case of nothing to save...
759 if ( !doc )//|| !bFromDocView) 759 if ( !doc )//|| !bFromDocView)
760 { 760 {
761 qDebug("no doc"); 761 qDebug("no doc");
762 return true; 762 return true;
763 } 763 }
764 if ( !editor->edited() ) { 764 if ( !editor->edited() ) {
765 delete doc; 765 delete doc;
766 doc = 0; 766 doc = 0;
767 return true; 767 return true;
768 } 768 }
769 769
770 QString rt = editor->text(); 770 QString rt = editor->text();
771 qDebug(currentFileName); 771 qDebug(currentFileName);
772 772
773 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 773 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) {
774 qDebug("do silly TT filename thing"); 774 qDebug("do silly TT filename thing");
775 if ( doc->name().isEmpty() ) { 775 if ( doc->name().isEmpty() ) {
776 QString pt = rt.simplifyWhiteSpace(); 776 QString pt = rt.simplifyWhiteSpace();
777 int i = pt.find( ' ' ); 777 int i = pt.find( ' ' );
778 QString docname = pt; 778 QString docname = pt;
779 if ( i > 0 ) 779 if ( i > 0 )
780 docname = pt.left( i ); 780 docname = pt.left( i );
781 // remove "." at the beginning 781 // remove "." at the beginning
782 while( docname.startsWith( "." ) ) 782 while( docname.startsWith( "." ) )
783 docname = docname.mid( 1 ); 783 docname = docname.mid( 1 );
784 docname.replace( QRegExp("/"), "_" ); 784 docname.replace( QRegExp("/"), "_" );
785 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 785 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
786 if ( docname.length() > 40 ) 786 if ( docname.length() > 40 )
787 docname = docname.left(40); 787 docname = docname.left(40);
788 if ( docname.isEmpty() ) 788 if ( docname.isEmpty() )
789 docname = tr("Unnamed"); 789 docname = tr("Unnamed");
790 doc->setName(docname); 790 doc->setName(docname);
791 currentFileName=docname; 791 currentFileName=docname;
792 } 792 }
793 } 793 }
794 794
795 795/*
796// QString str = OFileDialog::getSaveFileName( 2,"/");//,"", "*", this ); 796 QMap<QString, QStringList> map;
797// if(!str.isEmpty() ) { 797 map.insert(tr("All"), QStringList() );
798// openFile( str ); 798 QStringList text;
799 799 text << "text/*";
800 fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); 800 map.insert(tr("Text"), text );
801 qDebug("wanna save filename "+currentFileName); 801 text << "*";
802 fileSaveDlg->exec(); 802 map.insert(tr("All"), text );
803 if( fileSaveDlg->result() == 1 ) { 803 QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map);
804 if(!str.isEmpty() ) {
805 QString fileNm=str;
806*/
807
808 fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName);
809 qDebug("wanna save filename "+currentFileName);
810 fileSaveDlg->exec();
811 if( fileSaveDlg->result() == 1 ) {
804 QString fileNm=fileSaveDlg->selectedFileName; 812 QString fileNm=fileSaveDlg->selectedFileName;
805// QString fileNm=srt; 813
814
806 qDebug("saving filename "+fileNm); 815 qDebug("saving filename "+fileNm);
807 QFileInfo fi(fileNm); 816 QFileInfo fi(fileNm);
808 currentFileName=fi.fileName(); 817 currentFileName=fi.fileName();
809 if(doc) { 818 if(doc) {
810// QString file = doc->file(); 819// QString file = doc->file();
811// doc->removeFiles(); 820// doc->removeFiles();
812 delete doc; 821 delete doc;
813 DocLnk nf; 822 DocLnk nf;
814 nf.setType("text/plain"); 823 nf.setType("text/plain");
815 nf.setFile( fileNm); 824 nf.setFile( fileNm);
816 doc = new DocLnk(nf); 825 doc = new DocLnk(nf);
817// editor->setText(rt); 826// editor->setText(rt);
818// qDebug("openFile doclnk "+currentFileName); 827// qDebug("openFile doclnk "+currentFileName);
819 doc->setName( currentFileName); 828 doc->setName( currentFileName);
820 updateCaption( currentFileName); 829 updateCaption( currentFileName);
821 830
822 FileManager fm; 831 FileManager fm;
823 if ( !fm.saveFile( *doc, rt ) ) { 832 if ( !fm.saveFile( *doc, rt ) ) {
824 return false; 833 return false;
825 } 834 }
826 if( fileSaveDlg->filePermCheck->isChecked() ) { 835 if( fileSaveDlg->filePermCheck->isChecked() ) {
827 filePermissions *filePerm; 836 filePermissions *filePerm;
828 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 837 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm);
829 filePerm->exec(); 838 filePerm->exec();
830 839
831 if( filePerm) 840 if( filePerm)
832 delete filePerm; 841 delete filePerm;
833 } 842 }
834 } 843 }
835 } 844 }
836 editor->setEdited(TRUE); 845 editor->setEdited(TRUE);
837 edited1=FALSE; 846 edited1=FALSE;
838 edited=TRUE; 847 edited=TRUE;
839 if(caption().left(1)=="*") 848 if(caption().left(1)=="*")
840 setCaption(caption().right(caption().length()-1)); 849 setCaption(caption().right(caption().length()-1));
841 850
842 if(fileSaveDlg) 851 if(fileSaveDlg)
843 delete fileSaveDlg; 852 delete fileSaveDlg;
844 return true; 853 return true;
845} //end saveAs 854} //end saveAs
846 855
847void TextEdit::clear() 856void TextEdit::clear()
848{ 857{
849 delete doc; 858 delete doc;
850 doc = 0; 859 doc = 0;
851 editor->clear(); 860 editor->clear();
852} 861}
853 862
854void TextEdit::updateCaption( const QString &name ) 863void TextEdit::updateCaption( const QString &name )
855{ 864{
856 if ( !doc ) 865 if ( !doc )
857 setCaption( tr("Text Editor") ); 866 setCaption( tr("Text Editor") );
858 else { 867 else {
859 QString s = name; 868 QString s = name;
860 if ( s.isNull() ) 869 if ( s.isNull() )
861 s = doc->name(); 870 s = doc->name();
862 if ( s.isEmpty() ) { 871 if ( s.isEmpty() ) {
863 s = tr( "Unnamed" ); 872 s = tr( "Unnamed" );
864 currentFileName=s; 873 currentFileName=s;
865 } 874 }
866 if(s.left(1) == "/") 875 if(s.left(1) == "/")
867 s = s.right(s.length()-1); 876 s = s.right(s.length()-1);
868 setCaption( s + " - " + tr("Text Editor") ); 877 setCaption( s + " - " + tr("Text Editor") );
869 } 878 }
870} 879}
871 880
872void TextEdit::setDocument(const QString& fileref) 881void TextEdit::setDocument(const QString& fileref)
873{ 882{
874 bFromDocView = TRUE; 883 bFromDocView = TRUE;
875 openFile(fileref); 884 openFile(fileref);
876 editor->setEdited(TRUE); 885 editor->setEdited(TRUE);
877 edited1=FALSE; 886 edited1=FALSE;
878 edited=TRUE; 887 edited=TRUE;
879 doSearchBar(); 888 doSearchBar();
880} 889}
881 890
882void TextEdit::closeEvent( QCloseEvent *e ) 891void TextEdit::closeEvent( QCloseEvent *e )
883{ 892{
884 bFromDocView = FALSE; 893 bFromDocView = FALSE;
885 e->accept(); 894 e->accept();
886} 895}
887 896
888void TextEdit::accept() 897void TextEdit::accept()
889 { 898 {
890 //if(caption() !="Unnamed") 899 //if(caption() !="Unnamed")
891 if(edited1) 900 if(edited1)
892 saveAs(); 901 saveAs();
893 exit(0); 902 exit(0);
894 903
895} 904}
896 905
897void TextEdit::changeFont() { 906void TextEdit::changeFont() {
898 FontDatabase fdb; 907 FontDatabase fdb;
899 QFont defaultFont=editor->font(); 908 QFont defaultFont=editor->font();
900 QFontInfo fontInfo(defaultFont); 909 QFontInfo fontInfo(defaultFont);
901 Config cfg("TextEdit"); 910 Config cfg("TextEdit");
902 cfg.setGroup("Font"); 911 cfg.setGroup("Font");
903 QString family = cfg.readEntry("Family", fontInfo.family()); 912 QString family = cfg.readEntry("Family", fontInfo.family());
904 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 913 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
905 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 914 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
906 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 915 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
907 916
908 defaultFont = fdb.font(family,style,i_size,charSet); 917 defaultFont = fdb.font(family,style,i_size,charSet);
909 918
910 FontDialog *fontDlg; 919 FontDialog *fontDlg;
911 fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); 920 fontDlg=new FontDialog(this,tr("FontDialog"),TRUE);
912 921
913 fontDlg->exec(); 922 fontDlg->exec();
914 923
915 QFont myFont=fontDlg->selectedFont; 924 QFont myFont=fontDlg->selectedFont;
916 editor->setFont( myFont); 925 editor->setFont( myFont);
917 delete fontDlg; 926 delete fontDlg;
918 927
919} 928}
920 929
921void TextEdit::editDelete() 930void TextEdit::editDelete()
922{ 931{
923 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) { 932 switch ( QMessageBox::warning(this,tr("Text Editor"),tr("Do you really want\nto delete the current file\nfrom the disk?\nThis is irreversable!!"),tr("Yes"),tr("No"),0,0,1) ) {
924 case 0: 933 case 0:
925 if(doc) { 934 if(doc) {
926 doc->removeFiles(); 935 doc->removeFiles();
927 clear(); 936 clear();
928 setCaption( tr("Text Editor") ); 937 setCaption( tr("Text Editor") );
929 } 938 }
930 break; 939 break;
931 case 1: 940 case 1:
932 // exit 941 // exit
933 break; 942 break;
934 }; 943 };
935} 944}
936 945
937void TextEdit::changeStartConfig( bool b ) { 946void TextEdit::changeStartConfig( bool b ) {
938 947
939 Config cfg("TextEdit"); 948 Config cfg("TextEdit");
940 cfg.setGroup("View"); 949 cfg.setGroup("View");
941 if(b) { 950 if(b) {
942 qDebug("bool"); 951 qDebug("bool");
943 cfg.writeEntry("startNew","TRUE"); 952 cfg.writeEntry("startNew","TRUE");
944 } else { 953 } else {
945 cfg.writeEntry("startNew","FALSE"); 954 cfg.writeEntry("startNew","FALSE");
946 } 955 }
947 update(); 956 update();
948} 957}
949 958
950void TextEdit::editorChanged() { 959void TextEdit::editorChanged() {
951 if(editor->edited() && edited && !edited1) { 960 if(editor->edited() && edited && !edited1) {
952 setCaption( "*"+caption()); 961 setCaption( "*"+caption());
953 edited1=TRUE; 962 edited1=TRUE;
954 } 963 }
955 edited=TRUE; 964 edited=TRUE;
956} 965}
957 966
958void TextEdit::receive(const QCString&msg, const QByteArray&) { 967void TextEdit::receive(const QCString&msg, const QByteArray&) {
959 qDebug("QCop "+msg); 968 qDebug("QCop "+msg);
960 if ( msg == "setDocument(QString)" ) { 969 if ( msg == "setDocument(QString)" ) {
961 qDebug("bugger all"); 970 qDebug("bugger all");
962 } 971 }
963 972
964} 973}
965void TextEdit::doAbout() { 974void TextEdit::doAbout() {
966 QMessageBox::about(0,"Text Edit","Text Edit is copyright\n" 975 QMessageBox::about(0,"Text Edit","Text Edit is copyright\n"
967 "2000 Trolltech AS, and\n" 976 "2000 Trolltech AS, and\n"
968 "2002 by L.J.Potter \nljp@llornkcor.com\n" 977 "2002 by L.J.Potter \nljp@llornkcor.com\n"
969 "and is licensed under the GPL"); 978 "and is licensed under the GPL");
970} 979}