Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 99 |
1 files changed, 54 insertions, 45 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 6804918..943fecd 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <qpe/qpeapplication.h> | 35 | #include <qpe/qpeapplication.h> |
36 | #include <qpe/qpemenubar.h> | 36 | #include <qpe/qpemenubar.h> |
37 | #include <qpe/qpetoolbar.h> | 37 | #include <qpe/qpetoolbar.h> |
38 | #include <qpe/qcopenvelope_qws.h> | ||
38 | //#include <qpe/finddialog.h> | 39 | //#include <qpe/finddialog.h> |
39 | 40 | ||
40 | #include <qstringlist.h> | 41 | #include <qstringlist.h> |
@@ -238,6 +239,10 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
238 | setToolBarsMovable( FALSE ); | 239 | setToolBarsMovable( FALSE ); |
239 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); | 240 | connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); |
240 | 241 | ||
242 | channel = new QCopChannel( "QPE/Application/textedit", this ); | ||
243 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | ||
244 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | ||
245 | |||
241 | setIcon( Resource::loadPixmap( "TextEditor" ) ); | 246 | setIcon( Resource::loadPixmap( "TextEditor" ) ); |
242 | 247 | ||
243 | QPEToolBar *bar = new QPEToolBar( this ); | 248 | QPEToolBar *bar = new QPEToolBar( this ); |
@@ -397,13 +402,13 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
397 | wa->setOn(wrap); | 402 | wa->setOn(wrap); |
398 | updateCaption(); | 403 | updateCaption(); |
399 | 404 | ||
400 | cfg.setGroup("View"); | 405 | cfg.setGroup("View"); |
401 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 406 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { |
402 | nStart->setOn(TRUE); | 407 | nStart->setOn(TRUE); |
403 | fileNew(); | 408 | fileNew(); |
404 | } else { | 409 | } else { |
405 | fileOpen(); | 410 | fileOpen(); |
406 | } | 411 | } |
407 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 412 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
408 | } | 413 | } |
409 | 414 | ||
@@ -485,17 +490,19 @@ void TextEdit::setWordWrap(bool y) | |||
485 | 490 | ||
486 | void TextEdit::fileNew() | 491 | void TextEdit::fileNew() |
487 | { | 492 | { |
488 | if( !bFromDocView ) { | 493 | // if( !bFromDocView ) { |
489 | saveAs(); | 494 | // saveAs(); |
490 | } | 495 | // } |
491 | newFile(DocLnk()); | 496 | newFile(DocLnk()); |
492 | } | 497 | } |
493 | 498 | ||
494 | void TextEdit::fileOpen() | 499 | void TextEdit::fileOpen() |
495 | { | 500 | { |
496 | browseForFiles=new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); // | 501 | browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); // |
497 | browseForFiles->setFileView( viewSelection ); | 502 | browseForFiles->setFileView( viewSelection ); |
498 | browseForFiles->showMaximized(); | 503 | browseForFiles->showMaximized(); |
504 | // if( result != -1 ) | ||
505 | |||
499 | if( browseForFiles->exec() != -1 ) { | 506 | if( browseForFiles->exec() != -1 ) { |
500 | QString selFile = browseForFiles->selectedFileName; | 507 | QString selFile = browseForFiles->selectedFileName; |
501 | QStringList fileList = browseForFiles->fileList; | 508 | QStringList fileList = browseForFiles->fileList; |
@@ -618,14 +625,16 @@ void TextEdit::newFile( const DocLnk &f ) | |||
618 | setWState (WState_Reserved1 ); | 625 | setWState (WState_Reserved1 ); |
619 | editor->setFocus(); | 626 | editor->setFocus(); |
620 | doc = new DocLnk(nf); | 627 | doc = new DocLnk(nf); |
628 | currentFileName = "Unnamed"; | ||
621 | qDebug("newFile "+currentFileName); | 629 | qDebug("newFile "+currentFileName); |
622 | updateCaption(currentFileName); | 630 | updateCaption( currentFileName); |
631 | // editor->setEdited( FALSE); | ||
623 | } | 632 | } |
624 | 633 | ||
625 | void TextEdit::openFile( const QString &f ) | 634 | void TextEdit::openFile( const QString &f ) |
626 | { | 635 | { |
627 | 636 | ||
628 | bFromDocView = TRUE; | 637 | // bFromDocView = TRUE; |
629 | DocLnk nf; | 638 | DocLnk nf; |
630 | nf.setType("text/plain"); | 639 | nf.setType("text/plain"); |
631 | nf.setFile(f); | 640 | nf.setFile(f); |
@@ -636,39 +645,35 @@ void TextEdit::openFile( const QString &f ) | |||
636 | 645 | ||
637 | openFile(nf); | 646 | openFile(nf); |
638 | showEditTools(); | 647 | showEditTools(); |
639 | // Show filename in caption | 648 | // Show filename in caption |
640 | QString name = f; | 649 | QString name = f; |
641 | int sep = name.findRev( '/' ); | 650 | int sep = name.findRev( '/' ); |
642 | if ( sep > 0 ) | 651 | if ( sep > 0 ) |
643 | name = name.mid( sep+1 ); | 652 | name = name.mid( sep+1 ); |
644 | updateCaption( name ); | 653 | updateCaption( name ); |
645 | } | 654 | } |
646 | 655 | ||
647 | void TextEdit::openFile( const DocLnk &f ) | 656 | void TextEdit::openFile( const DocLnk &f ) |
648 | { | 657 | { |
649 | // clear(); | 658 | // clear(); |
650 | bFromDocView = TRUE; | 659 | // bFromDocView = TRUE; |
651 | FileManager fm; | 660 | FileManager fm; |
652 | QString txt; | 661 | QString txt; |
653 | currentFileName=f.name(); | 662 | currentFileName=f.name(); |
654 | qDebug("openFile doclnk " + currentFileName); | 663 | qDebug("openFile doclnk " + currentFileName); |
655 | if ( !fm.loadFile( f, txt ) ) { | 664 | if ( !fm.loadFile( f, txt ) ) { |
656 | // ####### could be a new file | 665 | // ####### could be a new file |
657 | qDebug( "Cannot open file" ); | 666 | qDebug( "Cannot open file" ); |
658 | |||
659 | //return; | ||
660 | } | 667 | } |
661 | 668 | // fileNew(); | |
662 | fileNew(); | ||
663 | if ( doc ) | 669 | if ( doc ) |
664 | delete doc; | 670 | delete doc; |
665 | doc = new DocLnk(f); | 671 | doc = new DocLnk(f); |
666 | editor->setText(txt); | 672 | editor->setText(txt); |
667 | editor->setEdited( FALSE); | 673 | editor->setEdited( FALSE); |
668 | edited1=FALSE; | 674 | edited1=FALSE; |
669 | edited=FALSE; | 675 | edited=FALSE; |
670 | 676 | ||
671 | qDebug("openFile doclnk "+currentFileName); | ||
672 | doc->setName(currentFileName); | 677 | doc->setName(currentFileName); |
673 | updateCaption(); | 678 | updateCaption(); |
674 | } | 679 | } |
@@ -691,9 +696,9 @@ void TextEdit::showEditTools() | |||
691 | bool TextEdit::save() | 696 | bool TextEdit::save() |
692 | { | 697 | { |
693 | QString file = doc->file(); | 698 | QString file = doc->file(); |
694 | qDebug(file); | 699 | qDebug("saver file "+file); |
695 | QString name= doc->name(); | 700 | QString name= doc->name(); |
696 | qDebug(name); | 701 | qDebug("File named "+name); |
697 | QString rt = editor->text(); | 702 | QString rt = editor->text(); |
698 | if( !rt.isEmpty() ) { | 703 | if( !rt.isEmpty() ) { |
699 | if(name.isEmpty()) { | 704 | if(name.isEmpty()) { |
@@ -731,13 +736,12 @@ bool TextEdit::save() | |||
731 | bool TextEdit::saveAs() | 736 | bool TextEdit::saveAs() |
732 | { | 737 | { |
733 | // qDebug("saveAsFile "+currentFileName); | 738 | // qDebug("saveAsFile "+currentFileName); |
734 | 739 | // case of nothing to save... | |
735 | // case of nothing to save... /// there's always something to save | 740 | if ( !doc )//|| !bFromDocView) |
736 | // if ( !doc )//|| !bFromDocView) | 741 | { |
737 | // { | 742 | qDebug("no doc"); |
738 | // qDebug("no doc"); | 743 | return true; |
739 | // return true; | 744 | } |
740 | // } | ||
741 | if ( !editor->edited() ) { | 745 | if ( !editor->edited() ) { |
742 | delete doc; | 746 | delete doc; |
743 | doc = 0; | 747 | doc = 0; |
@@ -747,7 +751,7 @@ bool TextEdit::saveAs() | |||
747 | QString rt = editor->text(); | 751 | QString rt = editor->text(); |
748 | qDebug(currentFileName); | 752 | qDebug(currentFileName); |
749 | 753 | ||
750 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed")) { | 754 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { |
751 | qDebug("do silly TT filename thing"); | 755 | qDebug("do silly TT filename thing"); |
752 | if ( doc->name().isEmpty() ) { | 756 | if ( doc->name().isEmpty() ) { |
753 | QString pt = rt.simplifyWhiteSpace(); | 757 | QString pt = rt.simplifyWhiteSpace(); |
@@ -814,7 +818,7 @@ bool TextEdit::saveAs() | |||
814 | if(fileSaveDlg) | 818 | if(fileSaveDlg) |
815 | delete fileSaveDlg; | 819 | delete fileSaveDlg; |
816 | return true; | 820 | return true; |
817 | } | 821 | } //end saveAs |
818 | 822 | ||
819 | void TextEdit::clear() | 823 | void TextEdit::clear() |
820 | { | 824 | { |
@@ -835,7 +839,8 @@ void TextEdit::updateCaption( const QString &name ) | |||
835 | s = tr( "Unnamed" ); | 839 | s = tr( "Unnamed" ); |
836 | currentFileName=s; | 840 | currentFileName=s; |
837 | } | 841 | } |
838 | 842 | if(s.left(1) == "/") | |
843 | s = s.right(s.length()-1); | ||
839 | setCaption( s + " - " + tr("Text Editor") ); | 844 | setCaption( s + " - " + tr("Text Editor") ); |
840 | } | 845 | } |
841 | } | 846 | } |
@@ -843,12 +848,11 @@ void TextEdit::updateCaption( const QString &name ) | |||
843 | void TextEdit::setDocument(const QString& fileref) | 848 | void TextEdit::setDocument(const QString& fileref) |
844 | { | 849 | { |
845 | bFromDocView = TRUE; | 850 | bFromDocView = TRUE; |
846 | qDebug("setDocument "+fileref); | ||
847 | bFromDocView = TRUE; | ||
848 | if(fileref.find(".desktop",0,TRUE) == -1) { | 851 | if(fileref.find(".desktop",0,TRUE) == -1) { |
849 | openFile(fileref); | 852 | openFile(fileref); |
850 | } else { | 853 | } else { |
851 | openFile(DocLnk(fileref)); | 854 | qDebug("is desktop file"); |
855 | openFile(DocLnk(fileref)); | ||
852 | } | 856 | } |
853 | editor->setEdited(TRUE); | 857 | editor->setEdited(TRUE); |
854 | edited1=FALSE; | 858 | edited1=FALSE; |
@@ -864,12 +868,9 @@ void TextEdit::closeEvent( QCloseEvent *e ) | |||
864 | 868 | ||
865 | void TextEdit::accept() | 869 | void TextEdit::accept() |
866 | { | 870 | { |
867 | QString file = doc->file(); | 871 | //if(caption() !="Unnamed") |
868 | if (file.find("_.txt",0,TRUE) ==-1) | 872 | if(edited1) |
869 | save(); | 873 | saveAs(); |
870 | else { | ||
871 | QFile(file).remove(); | ||
872 | } | ||
873 | exit(0); | 874 | exit(0); |
874 | 875 | ||
875 | } | 876 | } |
@@ -934,3 +935,11 @@ void TextEdit::editorChanged() { | |||
934 | } | 935 | } |
935 | edited=TRUE; | 936 | edited=TRUE; |
936 | } | 937 | } |
938 | |||
939 | void TextEdit::receive(const QCString&msg, const QByteArray&) { | ||
940 | qDebug("QCop "+msg); | ||
941 | if ( msg == "setDocument(QString)" ) { | ||
942 | qDebug("bugger all"); | ||
943 | } | ||
944 | |||
945 | } | ||