summaryrefslogtreecommitdiff
path: root/core/apps/textedit/textedit.cpp
Unidiff
Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp90
1 files changed, 44 insertions, 46 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 59a605a..749e0ac 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -34,50 +34,48 @@
34#include <qtextstream.h> 34#include <qtextstream.h>
35#include <qdatetime.h> 35#include <qdatetime.h>
36#include <qclipboard.h> 36#include <qclipboard.h>
37#include <qstringlist.h> 37#include <qstringlist.h>
38#include <qaction.h> 38#include <qaction.h>
39#include <qcolordialog.h> 39#include <qcolordialog.h>
40#include <qfileinfo.h> 40#include <qfileinfo.h>
41#include <qlineedit.h> 41#include <qlineedit.h>
42#include <qmessagebox.h> 42#include <qmessagebox.h>
43#include <qobjectlist.h> 43#include <qobjectlist.h>
44#include <qpopupmenu.h> 44#include <qpopupmenu.h>
45#include <qspinbox.h> 45#include <qspinbox.h>
46#include <qtoolbutton.h> 46#include <qtoolbutton.h>
47#include <qwidgetstack.h> 47#include <qwidgetstack.h>
48#include <qcheckbox.h> 48#include <qcheckbox.h>
49#include <qcombo.h> 49#include <qcombo.h>
50#include <qlayout.h> 50#include <qlayout.h>
51#include <qapplication.h> 51#include <qapplication.h>
52#include <qtimer.h> 52#include <qtimer.h>
53#include <qdir.h> 53#include <qdir.h>
54#include <unistd.h> 54#include <unistd.h>
55#include <sys/stat.h> 55#include <sys/stat.h>
56#include <stdlib.h> //getenv 56#include <stdlib.h> //getenv
57 57
58#include "resource.h"
59
60#if QT_VERSION < 300 58#if QT_VERSION < 300
61 59
62class QpeEditor : public QMultiLineEdit 60class QpeEditor : public QMultiLineEdit
63{ 61{
64 62
65public: 63public:
66 QpeEditor( QWidget *parent, const char * name = 0 ) 64 QpeEditor( QWidget *parent, const char * name = 0 )
67 : QMultiLineEdit( parent, name ) { 65 : QMultiLineEdit( parent, name ) {
68 clearTableFlags(); 66 clearTableFlags();
69 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 67 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
70} 68}
71 69
72 void find( const QString &txt, bool caseSensitive, 70 void find( const QString &txt, bool caseSensitive,
73 bool backwards ); 71 bool backwards );
74protected: 72protected:
75 bool markIt; 73 bool markIt;
76 int line1, line2, col1, col2; 74 int line1, line2, col1, col2;
77 void mousePressEvent( QMouseEvent * ); 75 void mousePressEvent( QMouseEvent * );
78 void mouseReleaseEvent( QMouseEvent * ); 76 void mouseReleaseEvent( QMouseEvent * );
79 77
80//public slots: 78//public slots:
81 /* 79 /*
82signals: 80signals:
83 void notFound(); 81 void notFound();
@@ -189,56 +187,56 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
189 menu = bar; 187 menu = bar;
190 188
191 QPEMenuBar *mb = new QPEMenuBar( bar ); 189 QPEMenuBar *mb = new QPEMenuBar( bar );
192 QPopupMenu *file = new QPopupMenu( this ); 190 QPopupMenu *file = new QPopupMenu( this );
193 QPopupMenu *edit = new QPopupMenu( this ); 191 QPopupMenu *edit = new QPopupMenu( this );
194 QPopupMenu *advancedMenu = new QPopupMenu(this); 192 QPopupMenu *advancedMenu = new QPopupMenu(this);
195 193
196 font = new QPopupMenu( this ); 194 font = new QPopupMenu( this );
197 195
198 bar = new QPEToolBar( this ); 196 bar = new QPEToolBar( this );
199 editBar = bar; 197 editBar = bar;
200 198
201 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), 199 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ),
202 QString::null, 0, this, 0 ); 200 QString::null, 0, this, 0 );
203 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 201 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
204// a->addTo( bar ); 202// a->addTo( bar );
205 a->addTo( file ); 203 a->addTo( file );
206 204
207 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), 205 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ),
208 QString::null, 0, this, 0 ); 206 QString::null, 0, this, 0 );
209 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 207 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
210 a->addTo( bar ); 208 a->addTo( bar );
211 a->addTo( file ); 209 a->addTo( file );
212 210
213 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , 211 a = new QAction( tr( "Save" ), Resource::loadPixmap("save") ,
214 QString::null, 0, this, 0 ); 212 QString::null, 0, this, 0 );
215 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 213 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
216 file->insertSeparator(); 214 file->insertSeparator();
217 a->addTo( bar ); 215 a->addTo( bar );
218 a->addTo( file ); 216 a->addTo( file );
219 217
220 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , 218 a = new QAction( tr( "Save As" ), Resource::loadPixmap("save") ,
221 QString::null, 0, this, 0 ); 219 QString::null, 0, this, 0 );
222 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 220 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
223 a->addTo( file ); 221 a->addTo( file );
224 222
225 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), 223 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ),
226 QString::null, 0, this, 0 ); 224 QString::null, 0, this, 0 );
227 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 225 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
228 a->addTo( editBar ); 226 a->addTo( editBar );
229 a->addTo( edit ); 227 a->addTo( edit );
230 228
231 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), 229 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ),
232 QString::null, 0, this, 0 ); 230 QString::null, 0, this, 0 );
233 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 231 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
234 a->addTo( editBar ); 232 a->addTo( editBar );
235 a->addTo( edit ); 233 a->addTo( edit );
236 234
237 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), 235 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ),
238 QString::null, 0, this, 0 ); 236 QString::null, 0, this, 0 );
239 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 237 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
240 a->addTo( editBar ); 238 a->addTo( editBar );
241 a->addTo( edit ); 239 a->addTo( edit );
242 240
243 241
244#ifndef QT_NO_CLIPBOARD 242#ifndef QT_NO_CLIPBOARD
@@ -673,100 +671,100 @@ void TextEdit::newFile( const DocLnk &f ) {
673 671
674void TextEdit::openDotFile( const QString &f ) { 672void TextEdit::openDotFile( const QString &f ) {
675 if(!currentFileName.isEmpty()) { 673 if(!currentFileName.isEmpty()) {
676 currentFileName=f; 674 currentFileName=f;
677 675
678 qDebug("openFile dotfile " + currentFileName); 676 qDebug("openFile dotfile " + currentFileName);
679 QString txt; 677 QString txt;
680 QFile file(f); 678 QFile file(f);
681 file.open(IO_ReadWrite); 679 file.open(IO_ReadWrite);
682 QTextStream t(&file); 680 QTextStream t(&file);
683 while ( !t.atEnd()) { 681 while ( !t.atEnd()) {
684 txt+=t.readLine()+"\n"; 682 txt+=t.readLine()+"\n";
685 } 683 }
686 editor->setText(txt); 684 editor->setText(txt);
687 editor->setEdited( false); 685 editor->setEdited( false);
688 edited1=false; 686 edited1=false;
689 edited=false; 687 edited=false;
690 688
691 689
692 } 690 }
693 updateCaption( currentFileName); 691 updateCaption( currentFileName);
694} 692}
695 693
696void TextEdit::openFile( const QString &f ) { 694void TextEdit::openFile( const QString &f ) {
697 qDebug("filename is "+ f); 695 qDebug("filename is "+ f);
698 QString filer; 696 QString filer;
699 QFileInfo fi( f); 697 QFileInfo fi( f);
700// bFromDocView = true; 698// bFromDocView = true;
701 if(f.find(".desktop",0,true) != -1 && !openDesktop ) 699 if(f.find(".desktop",0,true) != -1 && !openDesktop )
702 { 700 {
703 switch ( QMessageBox::warning(this,tr("Text Editor"), 701 switch ( QMessageBox::warning(this,tr("Text Editor"),
704 tr("Text Editor has detected<BR>you selected a <B>.desktop</B> 702 tr("Text Editor has detected<BR>you selected a <B>.desktop</B>
705file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"), 703file.<BR>Open <B>.desktop</B> file or <B>linked</B> file?"),
706 tr(".desktop File"),tr("Linked Document"),0,1,1) ) 704 tr(".desktop File"),tr("Linked Document"),0,1,1) )
707 { 705 {
708 case 0: //desktop 706 case 0: //desktop
709 filer = f; 707 filer = f;
710 break; 708 break;
711 case 1: //linked 709 case 1: //linked
712 DocLnk sf(f); 710 DocLnk sf(f);
713 filer = sf.file(); 711 filer = sf.file();
714 break; 712 break;
715 }; 713 };
716 } 714 }
717 else if(fi.baseName().left(1) == "") 715 else if(fi.baseName().left(1) == "")
718 { 716 {
719 qDebug("opening dotfile"); 717 qDebug("opening dotfile");
720 currentFileName=f; 718 currentFileName=f;
721 openDotFile(currentFileName); 719 openDotFile(currentFileName);
722 return; 720 return;
723 } 721 }
724 else 722 else
725 { 723 {
726 DocLnk sf(f); 724 DocLnk sf(f);
727 filer = sf.file(); 725 filer = sf.file();
728 if(filer.right(1) == "/") 726 if(filer.right(1) == "/")
729 filer = f; 727 filer = f;
730 } 728 }
731 729
732 DocLnk nf; 730 DocLnk nf;
733 nf.setType("text/plain"); 731 nf.setType("text/plain");
734 nf.setFile(filer); 732 nf.setFile(filer);
735 currentFileName=filer; 733 currentFileName=filer;
736 734
737 nf.setName(fi.baseName()); 735 nf.setName(fi.baseName());
738 openFile(nf); 736 openFile(nf);
739 737
740 qDebug("openFile string "+currentFileName); 738 qDebug("openFile string "+currentFileName);
741 739
742 showEditTools(); 740 showEditTools();
743 // Show filename in caption 741 // Show filename in caption
744 QString name = filer; 742 QString name = filer;
745 int sep = name.findRev( '/' ); 743 int sep = name.findRev( '/' );
746 if ( sep > 0 ) 744 if ( sep > 0 )
747 name = name.mid( sep+1 ); 745 name = name.mid( sep+1 );
748 updateCaption( name ); 746 updateCaption( name );
749} 747}
750 748
751void TextEdit::openFile( const DocLnk &f ) { 749void TextEdit::openFile( const DocLnk &f ) {
752// clear(); 750// clear();
753// bFromDocView = true; 751// bFromDocView = true;
754 FileManager fm; 752 FileManager fm;
755 QString txt; 753 QString txt;
756 currentFileName=f.file(); 754 currentFileName=f.file();
757 qDebug("openFile doclnk " + currentFileName); 755 qDebug("openFile doclnk " + currentFileName);
758 if ( !fm.loadFile( f, txt ) ) { 756 if ( !fm.loadFile( f, txt ) ) {
759 // ####### could be a new file 757 // ####### could be a new file
760 qDebug( "Cannot open file" ); 758 qDebug( "Cannot open file" );
761 } 759 }
762// fileNew(); 760// fileNew();
763 if ( doc ) 761 if ( doc )
764 delete doc; 762 delete doc;
765 doc = new DocLnk(f); 763 doc = new DocLnk(f);
766 editor->setText(txt); 764 editor->setText(txt);
767 editor->setEdited( false); 765 editor->setEdited( false);
768 edited1=false; 766 edited1=false;
769 edited=false; 767 edited=false;
770 768
771 doc->setName(currentFileName); 769 doc->setName(currentFileName);
772 updateCaption(); 770 updateCaption();