summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-02-18 14:52:54 (UTC)
committer llornkcor <llornkcor>2002-02-18 14:52:54 (UTC)
commit00f89d28e669140eb50f1f220c389f88fba1105c (patch) (unidiff)
treedeb87bb87d855bbacddc79d8a0a79edfb1cf1cd8
parent9741205aa0b0892b870d2b7df7c5dd7e25b0bb18 (diff)
downloadopie-00f89d28e669140eb50f1f220c389f88fba1105c.zip
opie-00f89d28e669140eb50f1f220c389f88fba1105c.tar.gz
opie-00f89d28e669140eb50f1f220c389f88fba1105c.tar.bz2
fixed filesave and fileopen cancel
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/fileSaver.cpp16
-rw-r--r--core/apps/textedit/textedit.cpp52
-rw-r--r--core/apps/textedit/textedit.h2
3 files changed, 42 insertions, 28 deletions
diff --git a/core/apps/textedit/fileSaver.cpp b/core/apps/textedit/fileSaver.cpp
index d01daee..88608cc 100644
--- a/core/apps/textedit/fileSaver.cpp
+++ b/core/apps/textedit/fileSaver.cpp
@@ -1,164 +1,172 @@
1/**************************************************************************** 1/****************************************************************************
2** copyright 2001 ljp ljp@llornkcor.com 2** copyright 2001 ljp ljp@llornkcor.com
3** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp 3** Created: Fri Dec 14 08:16:46 2001 fileSaver.cpp
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13****************************************************************************/ 13****************************************************************************/
14#include "fileSaver.h" 14#include "fileSaver.h"
15#include <qpe/config.h> 15#include <qpe/config.h>
16#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
17 17
18#include <qlistview.h> 18#include <qlistview.h>
19#include <qpushbutton.h> 19#include <qpushbutton.h>
20#include <qfile.h> 20#include <qfile.h>
21#include <qmessagebox.h> 21#include <qmessagebox.h>
22#include <unistd.h> 22#include <unistd.h>
23#include <qlineedit.h> 23#include <qlineedit.h>
24 24
25fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName ) 25fileSaver::fileSaver( QWidget* parent, const char* name, bool modal, WFlags fl , const QString currentFileName )
26 : QDialog( parent, name, modal, fl ) 26 : QDialog( parent, name, modal, fl )
27{ 27{
28 if ( !name ) 28 if ( !name )
29 setName( "fileSaver" ); 29 setName( "fileSaver" );
30 resize( 236, 280 ); 30 resize( 236, 280 );
31 setCaption(tr( "Save file" ) ); 31 setCaption(tr( "Save file" ) );
32// filterStr=currentFileName; 32 QFileInfo fi(currentFileName);
33 QString tmpFileName=fi.fileName();
34// qDebug( tmpFileName);
33 35
34 dirLabel = new QLabel(this, "DirLabel"); 36 dirLabel = new QLabel(this, "DirLabel");
35 dirLabel->setText(currentDir.canonicalPath()); 37 dirLabel->setText(currentDir.canonicalPath());
36 dirLabel->setGeometry(10,4,230,30); 38 dirLabel->setGeometry(10,4,230,30);
37 39
38 ListView = new QListView( this, "ListView" ); 40 ListView = new QListView( this, "ListView" );
39 ListView->addColumn( tr( "Name" ) ); 41 ListView->addColumn( tr( "Name" ) );
40 ListView->setColumnWidth(0,140); 42 ListView->setColumnWidth(0,140);
41 ListView->setSorting( 2, FALSE); 43 ListView->setSorting( 2, FALSE);
42 ListView->addColumn( tr( "Size" ) ); 44 ListView->addColumn( tr( "Size" ) );
43 ListView->setColumnWidth(1,59); 45 ListView->setColumnWidth(1,59);
44// ListView->setMultiSelection(true); 46// ListView->setMultiSelection(true);
45// ListView->setSelectionMode(QListView::Extended); 47// ListView->setSelectionMode(QListView::Extended);
46 48
47 ListView->setAllColumnsShowFocus( TRUE ); 49 ListView->setAllColumnsShowFocus( TRUE );
48 ListView->setGeometry( QRect( 10, 35, 220, 160 ) ); 50 ListView->setGeometry( QRect( 10, 35, 220, 160 ) );
49 51
50 fileEdit= new QLineEdit(this); 52 fileEdit= new QLineEdit(this);
51 fileEdit->setGeometry( QRect( 10, 230, 200, 25)); 53 fileEdit->setGeometry( QRect( 10, 230, 200, 25));
52 fileEdit->setText(currentFileName); 54
53 // signals and slots connections 55 fileEdit->setText( tmpFileName);
56
57 // signals and slots connections
54 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); 58 connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) );
55 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); 59 connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) );
56 currentDir.setPath(QDir::currentDirPath() ); 60
61// tmpFileName=fi.FilePath();
62// qDebug( tmpFileName);
63 currentDir.setPath( QDir::currentDirPath() );
57 populateList(); 64 populateList();
58} 65}
59 66
60fileSaver::~fileSaver() 67fileSaver::~fileSaver()
61{ 68{
62} 69}
63 70
64 71
65void fileSaver::populateList() 72void fileSaver::populateList()
66{ 73{
67 ListView->clear(); 74 ListView->clear();
68 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden ); 75 currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden );
69 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); 76 currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst);
70 currentDir.setMatchAllDirs(TRUE); 77 currentDir.setMatchAllDirs(TRUE);
71 78
72 currentDir.setNameFilter("*"); 79 currentDir.setNameFilter("*");
73 QString fileL, fileS; 80 QString fileL, fileS;
74 const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/); 81 const QFileInfoList *list = currentDir.entryInfoList(QDir::All /*, QDir::SortByMask*/);
75 QFileInfoListIterator it(*list); 82 QFileInfoListIterator it(*list);
76 QFileInfo *fi; 83 QFileInfo *fi;
77 while ( (fi=it.current()) ) { 84 while ( (fi=it.current()) ) {
78 85
79 if (fi->isSymLink() ){ 86 if (fi->isSymLink() ){
80 QString symLink=fi->readLink(); 87 QString symLink=fi->readLink();
81// qDebug("Symlink detected "+symLink); 88// qDebug("Symlink detected "+symLink);
82 QFileInfo sym( symLink); 89 QFileInfo sym( symLink);
83 fileS.sprintf( "%10li", sym.size() ); 90 fileS.sprintf( "%10li", sym.size() );
84 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() ); 91 fileL.sprintf( "%s -> %s", sym.fileName().data(),sym.absFilePath().data() );
85 92
86 } else { 93 } else {
87// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL); 94// // qDebug("Not a dir: "+currentDir.canonicalPath()+fileL);
88 fileS.sprintf( "%10li", fi->size() ); 95 fileS.sprintf( "%10li", fi->size() );
89 fileL.sprintf( "%s",fi->fileName().data() ); 96 fileL.sprintf( "%s",fi->fileName().data() );
90 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) { 97 if( QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+fileL)).exists() ) {
91 fileL+="/"; 98 fileL+="/";
92// qDebug(currentDir.canonicalPath()+fileL); 99// qDebug(currentDir.canonicalPath()+fileL);
93 } 100 }
94 } 101 }
95 item= new QListViewItem( ListView,fileL,fileS ); 102 item= new QListViewItem( ListView,fileL,fileS );
96 ++it; 103 ++it;
97 } 104 }
98 ListView->setSorting( 2, FALSE); 105 ListView->setSorting( 2, FALSE);
99 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath()); 106 dirLabel->setText("Current Directory:\n"+currentDir.canonicalPath());
100 107
101 108
102} 109}
103 110
104void fileSaver::upDir() 111void fileSaver::upDir()
105{ 112{
106// qDebug(currentDir.canonicalPath()); 113// qDebug(currentDir.canonicalPath());
107} 114}
108 115
109void fileSaver::listDoubleClicked(QListViewItem *selectedItem) 116void fileSaver::listDoubleClicked(QListViewItem *selectedItem)
110{ 117{
111} 118}
112 119
113void fileSaver::listClicked(QListViewItem *selectedItem) 120void fileSaver::listClicked(QListViewItem *selectedItem)
114{ 121{
115 QString strItem=selectedItem->text(0); 122 QString strItem=selectedItem->text(0);
116 QString strSize=selectedItem->text(1); 123 QString strSize=selectedItem->text(1);
117// qDebug("strItem is "+strItem); 124// qDebug("strItem is "+strItem);
118 strSize.stripWhiteSpace(); 125 strSize.stripWhiteSpace();
119// qDebug(strSize); 126// qDebug(strSize);
120 127
121 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink 128 if(strItem.find("@",0,TRUE) !=-1 || strItem.find("->",0,TRUE) !=-1 ) { //if symlink
122 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4); 129 QString strItem2=strItem.right( (strItem.length()-strItem.find("->",0,TRUE)) -4);
123// qDebug("strItem symlink is "+strItem2); 130// qDebug("strItem symlink is "+strItem2);
124 if(QDir(strItem2).exists() ) { 131 if(QDir(strItem2).exists() ) {
125 currentDir.cd(strItem2, TRUE); 132 currentDir.cd(strItem2, TRUE);
126 populateList(); 133 populateList();
127 } 134 }
128 } else { // not a symlink 135 } else { // not a symlink
129 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) { 136 if(strItem.find(". .",0,TRUE) && strItem.find("/",0,TRUE)!=-1 ) {
130 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) { 137 if(QDir(QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem)).exists() ) {
131 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem); 138 strItem=QDir::cleanDirPath(currentDir.canonicalPath()+"/"+strItem);
132 currentDir.cd(strItem,FALSE); 139 currentDir.cd(strItem,FALSE);
133// qDebug("Path is "+strItem); 140// qDebug("Path is "+strItem);
134 populateList(); 141 populateList();
135 } else { 142 } else {
136 currentDir.cdUp(); 143 currentDir.cdUp();
137 populateList(); 144 populateList();
138 } 145 }
139 if(QDir(strItem).exists()){ 146 if(QDir(strItem).exists()){
140 currentDir.cd(strItem, TRUE); 147 currentDir.cd(strItem, TRUE);
141 populateList(); 148 populateList();
142 } 149 }
143 } // else 150 } // else
144// if( QFile::exists(strItem ) ) { 151// if( QFile::exists(strItem ) ) {
145// qDebug("We found our files!!"); 152// qDebug("We found our files!!");
146 153
147// OnOK(); 154// OnOK();
148 } //end not symlink 155 } //end not symlink
149 chdir(strItem.latin1()); 156 chdir(strItem.latin1());
150 157
151 158
152} 159}
153 160
154 161
155void fileSaver::OnOK() 162void fileSaver::OnOK()
156{ 163{
157// reject(); 164// reject();
158} 165}
159 166
160void fileSaver::accept() { 167void fileSaver::accept() {
161 selectedFileName = fileEdit->text(); 168 selectedFileName = fileEdit->text();
162 selectedFileName = currentDir.canonicalPath()+ selectedFileName; 169 selectedFileName = currentDir.canonicalPath()+ selectedFileName;
170 qDebug("goint to save "+selectedFileName);
163 reject(); 171 reject();
164} 172}
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 14bc496..429c195 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -1,803 +1,809 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// changes added by L. J. Potter Sun 02-17-2002 21:31:31 20// changes added by L. J. Potter Sun 02-17-2002 21:31:31
21 21
22#include "textedit.h" 22#include "textedit.h"
23#include "fileBrowser.h" 23#include "fileBrowser.h"
24#include "fileSaver.h" 24#include "fileSaver.h"
25 25
26#include "fontDialog.h" 26#include "fontDialog.h"
27 27
28#include <qpe/fontdatabase.h> 28#include <qpe/fontdatabase.h>
29#include <qpe/global.h> 29#include <qpe/global.h>
30#include <qpe/fileselector.h> 30#include <qpe/fileselector.h>
31#include <qpe/applnk.h> 31#include <qpe/applnk.h>
32#include <qpe/resource.h> 32#include <qpe/resource.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/qpeapplication.h> 34#include <qpe/qpeapplication.h>
35#include <qpe/qpemenubar.h> 35#include <qpe/qpemenubar.h>
36#include <qpe/qpetoolbar.h> 36#include <qpe/qpetoolbar.h>
37//#include <qpe/finddialog.h> 37//#include <qpe/finddialog.h>
38 38
39#include <qstringlist.h> 39#include <qstringlist.h>
40#include <qaction.h> 40#include <qaction.h>
41#include <qcolordialog.h> 41#include <qcolordialog.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43#include <qlineedit.h> 43#include <qlineedit.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qobjectlist.h> 45#include <qobjectlist.h>
46#include <qpopupmenu.h> 46#include <qpopupmenu.h>
47#include <qspinbox.h> 47#include <qspinbox.h>
48#include <qtoolbutton.h> 48#include <qtoolbutton.h>
49#include <qwidgetstack.h> 49#include <qwidgetstack.h>
50 50
51#include <stdlib.h> //getenv 51#include <stdlib.h> //getenv
52/* XPM */ 52/* XPM */
53static char * filesave_xpm[] = { 53static char * filesave_xpm[] = {
54"16 16 78 1", 54"16 16 78 1",
55" c None", 55" c None",
56". c #343434", 56". c #343434",
57"+ c #A0A0A0", 57"+ c #A0A0A0",
58"@ c #565656", 58"@ c #565656",
59"# c #9E9E9E", 59"# c #9E9E9E",
60"$ c #525252", 60"$ c #525252",
61"% c #929292", 61"% c #929292",
62"& c #676767", 62"& c #676767",
63"* c #848484", 63"* c #848484",
64"= c #666666", 64"= c #666666",
65"- c #D8D8D8", 65"- c #D8D8D8",
66"; c #FFFFFF", 66"; c #FFFFFF",
67"> c #DBDBDB", 67"> c #DBDBDB",
68", c #636363", 68", c #636363",
69"' c #989898", 69"' c #989898",
70") c #2D2D2D", 70") c #2D2D2D",
71"! c #909090", 71"! c #909090",
72"~ c #AEAEAE", 72"~ c #AEAEAE",
73"{ c #EAEAEA", 73"{ c #EAEAEA",
74"] c #575757", 74"] c #575757",
75"^ c #585858", 75"^ c #585858",
76"/ c #8A8A8A", 76"/ c #8A8A8A",
77"( c #828282", 77"( c #828282",
78"_ c #6F6F6F", 78"_ c #6F6F6F",
79": c #C9C9C9", 79": c #C9C9C9",
80"< c #050505", 80"< c #050505",
81"[ c #292929", 81"[ c #292929",
82"} c #777777", 82"} c #777777",
83"| c #616161", 83"| c #616161",
84"1 c #3A3A3A", 84"1 c #3A3A3A",
85"2 c #BEBEBE", 85"2 c #BEBEBE",
86"3 c #2C2C2C", 86"3 c #2C2C2C",
87"4 c #7C7C7C", 87"4 c #7C7C7C",
88"5 c #F6F6F6", 88"5 c #F6F6F6",
89"6 c #FCFCFC", 89"6 c #FCFCFC",
90"7 c #6B6B6B", 90"7 c #6B6B6B",
91"8 c #959595", 91"8 c #959595",
92"9 c #4F4F4F", 92"9 c #4F4F4F",
93"0 c #808080", 93"0 c #808080",
94"a c #767676", 94"a c #767676",
95"b c #818181", 95"b c #818181",
96"c c #B8B8B8", 96"c c #B8B8B8",
97"d c #FBFBFB", 97"d c #FBFBFB",
98"e c #F9F9F9", 98"e c #F9F9F9",
99"f c #CCCCCC", 99"f c #CCCCCC",
100"g c #030303", 100"g c #030303",
101"h c #737373", 101"h c #737373",
102"i c #7A7A7A", 102"i c #7A7A7A",
103"j c #7E7E7E", 103"j c #7E7E7E",
104"k c #6A6A6A", 104"k c #6A6A6A",
105"l c #FAFAFA", 105"l c #FAFAFA",
106"m c #505050", 106"m c #505050",
107"n c #9D9D9D", 107"n c #9D9D9D",
108"o c #333333", 108"o c #333333",
109"p c #7B7B7B", 109"p c #7B7B7B",
110"q c #787878", 110"q c #787878",
111"r c #696969", 111"r c #696969",
112"s c #494949", 112"s c #494949",
113"t c #555555", 113"t c #555555",
114"u c #949494", 114"u c #949494",
115"v c #E6E6E6", 115"v c #E6E6E6",
116"w c #424242", 116"w c #424242",
117"x c #515151", 117"x c #515151",
118"y c #535353", 118"y c #535353",
119"z c #3E3E3E", 119"z c #3E3E3E",
120"A c #D4D4D4", 120"A c #D4D4D4",
121"B c #0C0C0C", 121"B c #0C0C0C",
122"C c #353535", 122"C c #353535",
123"D c #474747", 123"D c #474747",
124"E c #ECECEC", 124"E c #ECECEC",
125"F c #919191", 125"F c #919191",
126"G c #7D7D7D", 126"G c #7D7D7D",
127"H c #000000", 127"H c #000000",
128"I c #404040", 128"I c #404040",
129"J c #858585", 129"J c #858585",
130"K c #323232", 130"K c #323232",
131"L c #D0D0D0", 131"L c #D0D0D0",
132"M c #1C1C1C", 132"M c #1C1C1C",
133" ...+ ", 133" ...+ ",
134" @#$%&..+ ", 134" @#$%&..+ ",
135" .*=-;;>,..+ ", 135" .*=-;;>,..+ ",
136" ')!~;;;;;;{]..", 136" ')!~;;;;;;{]..",
137" ^/(-;;;;;;;_:<", 137" ^/(-;;;;;;;_:<",
138" [}|;;;;;;;{12$", 138" [}|;;;;;;;{12$",
139" #34-55;;;;678$+", 139" #34-55;;;;678$+",
140" 90ab=c;dd;e1fg ", 140" 90ab=c;dd;e1fg ",
141" [ahij((kbl0mn$ ", 141" [ahij((kbl0mn$ ",
142" op^q^^7r&]s/$+ ", 142" op^q^^7r&]s/$+ ",
143"@btu;vbwxy]zAB ", 143"@btu;vbwxy]zAB ",
144"CzDEvEv;;DssF$ ", 144"CzDEvEv;;DssF$ ",
145"G.H{E{E{IxsJ$+ ", 145"G.H{E{E{IxsJ$+ ",
146" +...vEKxzLM ", 146" +...vEKxzLM ",
147" +...z]n$ ", 147" +...z]n$ ",
148" +... "}; 148" +... "};
149 149
150 150
151#if QT_VERSION < 300 151#if QT_VERSION < 300
152 152
153class QpeEditor : public QMultiLineEdit 153class QpeEditor : public QMultiLineEdit
154{ 154{
155 // Q_OBJECT 155 // Q_OBJECT
156public: 156public:
157 QpeEditor( QWidget *parent, const char * name = 0 ) 157 QpeEditor( QWidget *parent, const char * name = 0 )
158 : QMultiLineEdit( parent, name ) 158 : QMultiLineEdit( parent, name )
159 { 159 {
160 clearTableFlags(); 160 clearTableFlags();
161 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 161 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
162 } 162 }
163 163
164 //public slots: 164 //public slots:
165 void find( const QString &txt, bool caseSensitive, 165 void find( const QString &txt, bool caseSensitive,
166 bool backwards ); 166 bool backwards );
167 /* 167 /*
168signals: 168signals:
169 void notFound(); 169 void notFound();
170 void searchWrapped(); 170 void searchWrapped();
171 */ 171 */
172 172
173private: 173private:
174 174
175}; 175};
176 176
177 177
178void QpeEditor::find ( const QString &txt, bool caseSensitive, 178void QpeEditor::find ( const QString &txt, bool caseSensitive,
179 bool backwards ) 179 bool backwards )
180{ 180{
181 static bool wrap = FALSE; 181 static bool wrap = FALSE;
182 int line, col; 182 int line, col;
183 if ( wrap ) { 183 if ( wrap ) {
184 if ( !backwards ) 184 if ( !backwards )
185 line = col = 0; 185 line = col = 0;
186 wrap = FALSE; 186 wrap = FALSE;
187 // emit searchWrapped(); 187 // emit searchWrapped();
188 } else { 188 } else {
189 getCursorPosition( &line, &col ); 189 getCursorPosition( &line, &col );
190 } 190 }
191 //ignore backwards for now.... 191 //ignore backwards for now....
192 if ( !backwards ) { 192 if ( !backwards ) {
193 for ( ; ; ) { 193 for ( ; ; ) {
194 if ( line >= numLines() ) { 194 if ( line >= numLines() ) {
195 wrap = TRUE; 195 wrap = TRUE;
196 //emit notFound(); 196 //emit notFound();
197 break; 197 break;
198 } 198 }
199 int findCol = getString( line )->find( txt, col, caseSensitive ); 199 int findCol = getString( line )->find( txt, col, caseSensitive );
200 if ( findCol >= 0 ) { 200 if ( findCol >= 0 ) {
201 setCursorPosition( line, findCol, FALSE ); 201 setCursorPosition( line, findCol, FALSE );
202 col = findCol + txt.length(); 202 col = findCol + txt.length();
203 setCursorPosition( line, col, TRUE ); 203 setCursorPosition( line, col, TRUE );
204 204
205 //found = TRUE; 205 //found = TRUE;
206 break; 206 break;
207 } 207 }
208 line++; 208 line++;
209 col = 0; 209 col = 0;
210 } 210 }
211 211
212 } 212 }
213 213
214} 214}
215 215
216 216
217#else 217#else
218 218
219#error "Must make a QpeEditor that inherits QTextEdit" 219#error "Must make a QpeEditor that inherits QTextEdit"
220 220
221#endif 221#endif
222 222
223 223
224 224
225 225
226static int u_id = 1; 226static int u_id = 1;
227static int get_unique_id() 227static int get_unique_id()
228{ 228{
229 return u_id++; 229 return u_id++;
230} 230}
231 231
232static const int nfontsizes = 6; 232static const int nfontsizes = 6;
233static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 233static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
234 234
235TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 235TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
236 : QMainWindow( parent, name, f ), bFromDocView( FALSE ) 236 : QMainWindow( parent, name, f ), bFromDocView( FALSE )
237{ 237{
238 doc = 0; 238 doc = 0;
239 239
240 setToolBarsMovable( FALSE ); 240 setToolBarsMovable( FALSE );
241 241
242 setIcon( Resource::loadPixmap( "TextEditor" ) ); 242 setIcon( Resource::loadPixmap( "TextEditor" ) );
243 243
244 QPEToolBar *bar = new QPEToolBar( this ); 244 QPEToolBar *bar = new QPEToolBar( this );
245 bar->setHorizontalStretchable( TRUE ); 245 bar->setHorizontalStretchable( TRUE );
246 menu = bar; 246 menu = bar;
247 247
248 QPEMenuBar *mb = new QPEMenuBar( bar ); 248 QPEMenuBar *mb = new QPEMenuBar( bar );
249 QPopupMenu *file = new QPopupMenu( this ); 249 QPopupMenu *file = new QPopupMenu( this );
250 QPopupMenu *edit = new QPopupMenu( this ); 250 QPopupMenu *edit = new QPopupMenu( this );
251 QPopupMenu *font = new QPopupMenu( this ); 251 QPopupMenu *font = new QPopupMenu( this );
252 252
253 bar = new QPEToolBar( this ); 253 bar = new QPEToolBar( this );
254 editBar = bar; 254 editBar = bar;
255 255
256 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 256 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
257 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 257 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
258 a->addTo( bar ); 258 a->addTo( bar );
259 a->addTo( file ); 259 a->addTo( file );
260 260
261 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 261 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
262 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 262 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
263// a->addTo( bar ); 263// a->addTo( bar );
264 a->addTo( file ); 264 a->addTo( file );
265 265
266 a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 266 a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
267 connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); 267 connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) );
268 a->addTo( bar ); 268 a->addTo( bar );
269 a->addTo( file ); 269 a->addTo( file );
270 270
271// 271//
272 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 272 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
273 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 273 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
274// a->addTo( bar ); 274// a->addTo( bar );
275 file->insertSeparator(); 275 file->insertSeparator();
276 a->addTo( file ); 276 a->addTo( file );
277 277
278 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 278 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
279 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 279 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
280 a->addTo( editBar ); 280 a->addTo( editBar );
281 a->addTo( edit ); 281 a->addTo( edit );
282 282
283 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 283 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
284 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 284 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
285 a->addTo( editBar ); 285 a->addTo( editBar );
286 a->addTo( edit ); 286 a->addTo( edit );
287 287
288 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 288 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
289 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 289 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
290 a->addTo( editBar ); 290 a->addTo( editBar );
291 a->addTo( edit ); 291 a->addTo( edit );
292 292
293 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 293 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
294 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 294 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
295 edit->insertSeparator(); 295 edit->insertSeparator();
296 a->addTo( bar ); 296 a->addTo( bar );
297 a->addTo( edit ); 297 a->addTo( edit );
298 298
299 int defsize; 299 int defsize;
300 bool defb, defi, wrap; 300 bool defb, defi, wrap;
301 301
302 Config cfg("TextEdit"); 302 Config cfg("TextEdit");
303 cfg.setGroup("View"); 303 cfg.setGroup("View");
304 defsize = cfg.readNumEntry("FontSize",10); 304 defsize = cfg.readNumEntry("FontSize",10);
305 defb = cfg.readBoolEntry("Bold",FALSE); 305 defb = cfg.readBoolEntry("Bold",FALSE);
306 defi = cfg.readBoolEntry("Italic",FALSE); 306 defi = cfg.readBoolEntry("Italic",FALSE);
307 wrap = cfg.readBoolEntry("Wrap",TRUE); 307 wrap = cfg.readBoolEntry("Wrap",TRUE);
308 308
309 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 309 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
310 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 310 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
311 zin->addTo( font ); 311 zin->addTo( font );
312 312
313 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 313 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
314 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 314 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
315 zout->addTo( font ); 315 zout->addTo( font );
316 316
317 font->insertSeparator(); 317 font->insertSeparator();
318 318
319#if 0 319#if 0
320 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); 320 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
321 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); 321 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
322 ba->setToggleAction(TRUE); 322 ba->setToggleAction(TRUE);
323 ba->addTo( font ); 323 ba->addTo( font );
324 324
325 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); 325 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
326 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); 326 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
327 ia->setToggleAction(TRUE); 327 ia->setToggleAction(TRUE);
328 ia->addTo( font ); 328 ia->addTo( font );
329 329
330 ba->setOn(defb); 330 ba->setOn(defb);
331 ia->setOn(defi); 331 ia->setOn(defi);
332 332
333 font->insertSeparator(); 333 font->insertSeparator();
334#endif 334#endif
335 335
336 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 336 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
337 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 337 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
338 wa->setToggleAction(TRUE); 338 wa->setToggleAction(TRUE);
339 wa->addTo( font ); 339 wa->addTo( font );
340 340
341 font->insertSeparator(); 341 font->insertSeparator();
342 font->insertItem("Font", this, SLOT(changeFont()) ); 342 font->insertItem("Font", this, SLOT(changeFont()) );
343 343
344 mb->insertItem( tr( "File" ), file ); 344 mb->insertItem( tr( "File" ), file );
345 mb->insertItem( tr( "Edit" ), edit ); 345 mb->insertItem( tr( "Edit" ), edit );
346 mb->insertItem( tr( "View" ), font ); 346 mb->insertItem( tr( "View" ), font );
347 347
348 searchBar = new QPEToolBar(this); 348 searchBar = new QPEToolBar(this);
349 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 349 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
350 350
351 searchBar->setHorizontalStretchable( TRUE ); 351 searchBar->setHorizontalStretchable( TRUE );
352 352
353 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 353 searchEdit = new QLineEdit( searchBar, "searchEdit" );
354 searchBar->setStretchableWidget( searchEdit ); 354 searchBar->setStretchableWidget( searchEdit );
355 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 355 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
356 this, SLOT( search() ) ); 356 this, SLOT( search() ) );
357 357
358 358
359 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 359 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
360 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 360 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
361 a->addTo( searchBar ); 361 a->addTo( searchBar );
362 a->addTo( edit ); 362 a->addTo( edit );
363 363
364 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 364 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
365 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 365 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
366 a->addTo( searchBar ); 366 a->addTo( searchBar );
367 367
368 searchBar->hide(); 368 searchBar->hide();
369 369
370 editorStack = new QWidgetStack( this ); 370 editorStack = new QWidgetStack( this );
371 setCentralWidget( editorStack ); 371 setCentralWidget( editorStack );
372 372
373 searchVisible = FALSE; 373 searchVisible = FALSE;
374 374
375 fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy 375 fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy
376 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); 376 connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) );
377 connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); 377 connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) );
378 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); 378 connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) );
379// fileOpen(); 379// fileOpen();
380 380
381 editor = new QpeEditor( editorStack ); 381 editor = new QpeEditor( editorStack );
382 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 382 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
383 editorStack->addWidget( editor, get_unique_id() ); 383 editorStack->addWidget( editor, get_unique_id() );
384 384
385 resize( 200, 300 ); 385 resize( 200, 300 );
386 386
387// setFontSize(defsize,TRUE); 387// setFontSize(defsize,TRUE);
388 FontDatabase fdb; 388 FontDatabase fdb;
389 QFont defaultFont=editor->font(); 389 QFont defaultFont=editor->font();
390 QFontInfo fontInfo(defaultFont); 390 QFontInfo fontInfo(defaultFont);
391 391
392 cfg.setGroup("Font"); 392 cfg.setGroup("Font");
393 QString family = cfg.readEntry("Family", fontInfo.family()); 393 QString family = cfg.readEntry("Family", fontInfo.family());
394 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 394 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
395 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 395 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
396 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 396 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
397 397
398 defaultFont = fdb.font(family,style,i_size,charSet); 398 defaultFont = fdb.font(family,style,i_size,charSet);
399 editor->setFont( defaultFont); 399 editor->setFont( defaultFont);
400 400
401 wa->setOn(wrap); 401 wa->setOn(wrap);
402 updateCaption(); 402 updateCaption();
403 if( qApp->argc() > 1 ) { 403 if( qApp->argc() > 1 ) {
404 for (int i=1;i< qApp->argc();i++) { 404 for (int i=1;i< qApp->argc();i++) {
405 QString tmp; 405 QString tmp;
406 currentFileName = tmp.sprintf("%s",qApp->argv()[i]); 406 currentFileName = tmp.sprintf("%s",qApp->argv()[i]);
407 qDebug(currentFileName); 407 qDebug(currentFileName);
408 setDocument( currentFileName ); 408 setDocument( currentFileName );
409 } 409 }
410 } 410 }
411 else 411 else
412 fileNew(); 412 fileNew();
413} 413}
414 414
415TextEdit::~TextEdit() 415TextEdit::~TextEdit()
416{ 416{
417 save(); 417 save();
418 418
419 Config cfg("TextEdit"); 419 Config cfg("TextEdit");
420 cfg.setGroup("View"); 420 cfg.setGroup("View");
421 QFont f = editor->font(); 421 QFont f = editor->font();
422 cfg.writeEntry("FontSize",f.pointSize()); 422 cfg.writeEntry("FontSize",f.pointSize());
423 cfg.writeEntry("Bold",f.bold()); 423 cfg.writeEntry("Bold",f.bold());
424 cfg.writeEntry("Italic",f.italic()); 424 cfg.writeEntry("Italic",f.italic());
425 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 425 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
426} 426}
427 427
428void TextEdit::zoomIn() 428void TextEdit::zoomIn()
429{ 429{
430 setFontSize(editor->font().pointSize()+1,FALSE); 430 setFontSize(editor->font().pointSize()+1,FALSE);
431} 431}
432 432
433void TextEdit::zoomOut() 433void TextEdit::zoomOut()
434{ 434{
435 setFontSize(editor->font().pointSize()-1,TRUE); 435 setFontSize(editor->font().pointSize()-1,TRUE);
436} 436}
437 437
438 438
439void TextEdit::setFontSize(int sz, bool round_down_not_up) 439void TextEdit::setFontSize(int sz, bool round_down_not_up)
440{ 440{
441 int s=10; 441 int s=10;
442 for (int i=0; i<nfontsizes; i++) { 442 for (int i=0; i<nfontsizes; i++) {
443 if ( fontsize[i] == sz ) { 443 if ( fontsize[i] == sz ) {
444 s = sz; 444 s = sz;
445 break; 445 break;
446 } else if ( round_down_not_up ) { 446 } else if ( round_down_not_up ) {
447 if ( fontsize[i] < sz ) 447 if ( fontsize[i] < sz )
448 s = fontsize[i]; 448 s = fontsize[i];
449 } else { 449 } else {
450 if ( fontsize[i] > sz ) { 450 if ( fontsize[i] > sz ) {
451 s = fontsize[i]; 451 s = fontsize[i];
452 break; 452 break;
453 } 453 }
454 } 454 }
455 } 455 }
456 456
457 QFont f = editor->font(); 457 QFont f = editor->font();
458 f.setPointSize(s); 458 f.setPointSize(s);
459 editor->setFont(f); 459 editor->setFont(f);
460 460
461 zin->setEnabled(s != fontsize[nfontsizes-1]); 461 zin->setEnabled(s != fontsize[nfontsizes-1]);
462 zout->setEnabled(s != fontsize[0]); 462 zout->setEnabled(s != fontsize[0]);
463} 463}
464 464
465void TextEdit::setBold(bool y) 465void TextEdit::setBold(bool y)
466{ 466{
467 QFont f = editor->font(); 467 QFont f = editor->font();
468 f.setBold(y); 468 f.setBold(y);
469 editor->setFont(f); 469 editor->setFont(f);
470} 470}
471 471
472void TextEdit::setItalic(bool y) 472void TextEdit::setItalic(bool y)
473{ 473{
474 QFont f = editor->font(); 474 QFont f = editor->font();
475 f.setItalic(y); 475 f.setItalic(y);
476 editor->setFont(f); 476 editor->setFont(f);
477} 477}
478 478
479void TextEdit::setWordWrap(bool y) 479void TextEdit::setWordWrap(bool y)
480{ 480{
481 bool state = editor->edited(); 481 bool state = editor->edited();
482 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 482 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
483 editor->setEdited( state ); 483 editor->setEdited( state );
484} 484}
485 485
486void TextEdit::fileNew() 486void TextEdit::fileNew()
487{ 487{
488 save(); 488 if( !bFromDocView ) {
489 save();
490 }
489 newFile(DocLnk()); 491 newFile(DocLnk());
490} 492}
491 493
492void TextEdit::fileOpen() 494void TextEdit::fileOpen()
493{ 495{
494// if ( !save() ) { 496// if ( !save() ) {
495// if ( QMessageBox::critical( this, tr( "Out of space" ), 497// if ( QMessageBox::critical( this, tr( "Out of space" ),
496// tr( "Text Editor was unable to\n" 498// tr( "Text Editor was unable to\n"
497// "save your changes.\n" 499// "save your changes.\n"
498// "Free some space and try again.\n" 500// "Free some space and try again.\n"
499// "\nContinue anyway?" ), 501// "\nContinue anyway?" ),
500// QMessageBox::Yes|QMessageBox::Escape, 502// QMessageBox::Yes|QMessageBox::Escape,
501// QMessageBox::No|QMessageBox::Default ) 503// QMessageBox::No|QMessageBox::Default )
502// != QMessageBox::Yes ) 504// != QMessageBox::Yes )
503// return; 505// return;
504// else { 506// else {
505// delete doc; 507// delete doc;
506// doc = 0; 508// doc = 0;
507// } 509// }
508// } 510// }
509 menu->hide(); 511 menu->hide();
510 editBar->hide(); 512 editBar->hide();
511 searchBar->hide(); 513 searchBar->hide();
512 clearWState (WState_Reserved1 ); 514 clearWState (WState_Reserved1 );
513 editorStack->raiseWidget( fileSelector ); 515 editorStack->raiseWidget( fileSelector );
514 fileSelector->reread(); 516 fileSelector->reread();
515 updateCaption(); 517 updateCaption(currentFileName);
516} 518}
517 519
518void TextEdit::newFileOpen() 520void TextEdit::newFileOpen()
519{ 521{
520 fileBrowser *browseForFiles; 522 fileBrowser *browseForFiles;
521 browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*"); 523 browseForFiles=new fileBrowser(this,"fileBrowser",TRUE,0, "*");
522 browseForFiles->exec(); 524 if( browseForFiles->exec()!= 0 ) {
523 QString selFile= browseForFiles->selectedFileName; 525 QString selFile= browseForFiles->selectedFileName;
524 QStringList fileList=browseForFiles->fileList; 526 QStringList fileList=browseForFiles->fileList;
525 qDebug(selFile); 527 qDebug(selFile);
526 QStringList::ConstIterator f; 528 QStringList::ConstIterator f;
527 QString fileTemp; 529 QString fileTemp;
528 for ( f = fileList.begin(); f != fileList.end(); f++ ) { 530 for ( f = fileList.begin(); f != fileList.end(); f++ ) {
529 fileTemp = *f; 531 fileTemp = *f;
530 fileTemp.right( fileTemp.length()-5); 532 fileTemp.right( fileTemp.length()-5);
531 QString fileName = fileTemp; 533 QString fileName = fileTemp;
532 if( fileName != "Unnamed" || fileName != "Empty Text" ) { 534 if( fileName != "Unnamed" || fileName != "Empty Text" ) {
533 currentFileName = fileName; 535 currentFileName = fileName;
534 qDebug("please open "+currentFileName); 536// qDebug("please open "+currentFileName);
535 openFile(fileName ); 537 openFile(fileName );
538 }
536 } 539 }
537 } 540 }
538 delete browseForFiles; 541 delete browseForFiles;
539 542
540} 543}
541 544
542#if 0 545#if 0
543void TextEdit::slotFind() 546void TextEdit::slotFind()
544{ 547{
545 FindDialog frmFind( "Text Editor", this ); 548 FindDialog frmFind( "Text Editor", this );
546 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 549 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
547 editor, SLOT(slotDoFind( const QString&,bool,bool))); 550 editor, SLOT(slotDoFind( const QString&,bool,bool)));
548 551
549 //case sensitive, backwards, [category] 552 //case sensitive, backwards, [category]
550 553
551 connect( editor, SIGNAL(notFound()), 554 connect( editor, SIGNAL(notFound()),
552 &frmFind, SLOT(slotNotFound()) ); 555 &frmFind, SLOT(slotNotFound()) );
553 connect( editor, SIGNAL(searchWrapped()), 556 connect( editor, SIGNAL(searchWrapped()),
554 &frmFind, SLOT(slotWrapAround()) ); 557 &frmFind, SLOT(slotWrapAround()) );
555 558
556 frmFind.exec(); 559 frmFind.exec();
557 560
558 561
559} 562}
560#endif 563#endif
561 564
562void TextEdit::fileRevert() 565void TextEdit::fileRevert()
563{ 566{
564 clear(); 567 clear();
565 fileOpen(); 568 fileOpen();
566} 569}
567 570
568void TextEdit::editCut() 571void TextEdit::editCut()
569{ 572{
570#ifndef QT_NO_CLIPBOARD 573#ifndef QT_NO_CLIPBOARD
571 editor->cut(); 574 editor->cut();
572#endif 575#endif
573} 576}
574 577
575void TextEdit::editCopy() 578void TextEdit::editCopy()
576{ 579{
577#ifndef QT_NO_CLIPBOARD 580#ifndef QT_NO_CLIPBOARD
578 editor->copy(); 581 editor->copy();
579#endif 582#endif
580} 583}
581 584
582void TextEdit::editPaste() 585void TextEdit::editPaste()
583{ 586{
584#ifndef QT_NO_CLIPBOARD 587#ifndef QT_NO_CLIPBOARD
585 editor->paste(); 588 editor->paste();
586#endif 589#endif
587} 590}
588 591
589void TextEdit::editFind() 592void TextEdit::editFind()
590{ 593{
591 searchBar->show(); 594 searchBar->show();
592 searchVisible = TRUE; 595 searchVisible = TRUE;
593 searchEdit->setFocus(); 596 searchEdit->setFocus();
594} 597}
595 598
596void TextEdit::findNext() 599void TextEdit::findNext()
597{ 600{
598 editor->find( searchEdit->text(), FALSE, FALSE ); 601 editor->find( searchEdit->text(), FALSE, FALSE );
599 602
600} 603}
601 604
602void TextEdit::findClose() 605void TextEdit::findClose()
603{ 606{
604 searchVisible = FALSE; 607 searchVisible = FALSE;
605 searchBar->hide(); 608 searchBar->hide();
606} 609}
607 610
608void TextEdit::search() 611void TextEdit::search()
609{ 612{
610 editor->find( searchEdit->text(), FALSE, FALSE ); 613 editor->find( searchEdit->text(), FALSE, FALSE );
611} 614}
612 615
613void TextEdit::newFile( const DocLnk &f ) 616void TextEdit::newFile( const DocLnk &f )
614{ 617{
615 DocLnk nf = f; 618 DocLnk nf = f;
616 nf.setType("text/plain"); 619 nf.setType("text/plain");
617 clear(); 620 clear();
618 editorStack->raiseWidget( editor ); 621 editorStack->raiseWidget( editor );
619 setWState (WState_Reserved1 ); 622 setWState (WState_Reserved1 );
620 editor->setFocus(); 623 editor->setFocus();
621 doc = new DocLnk(nf); 624 doc = new DocLnk(nf);
622 updateCaption(); 625// updateCaption();
623} 626}
624 627
625void TextEdit::openFile( const QString &f ) 628void TextEdit::openFile( const QString &f )
626{ 629{
627 bFromDocView = TRUE; 630 bFromDocView = TRUE;
628 DocLnk nf; 631 DocLnk nf;
629 nf.setType("text/plain"); 632 nf.setType("text/plain");
630 nf.setFile(f); 633 nf.setFile(f);
631 openFile(nf); 634 openFile(nf);
632 showEditTools(); 635 showEditTools();
633 // Show filename in caption 636 // Show filename in caption
634 QString name = f; 637 QString name = f;
635 int sep = name.findRev( '/' ); 638 int sep = name.findRev( '/' );
636 if ( sep > 0 ) 639 if ( sep > 0 )
637 name = name.mid( sep+1 ); 640 name = name.mid( sep+1 );
638 updateCaption( name ); 641 updateCaption( name );
639} 642}
640 643
641void TextEdit::openFile( const DocLnk &f ) 644void TextEdit::openFile( const DocLnk &f )
642{ 645{
643// clear(); 646// clear();
647 bFromDocView = TRUE;
644 FileManager fm; 648 FileManager fm;
645 QString txt; 649 QString txt;
646 if ( !fm.loadFile( f, txt ) ) { 650 if ( !fm.loadFile( f, txt ) ) {
647 // ####### could be a new file 651 // ####### could be a new file
648 qDebug( "Cannot open file" ); 652 qDebug( "Cannot open file" );
649 653
650 //return; 654 //return;
651 } 655 }
652 656
653 fileNew(); 657 fileNew();
654 if ( doc ) 658 if ( doc )
655 delete doc; 659 delete doc;
656 doc = new DocLnk(f); 660 doc = new DocLnk(f);
657 editor->setText(txt); 661 editor->setText(txt);
658 editor->setEdited(FALSE); 662 editor->setEdited(FALSE);
659 updateCaption(); 663 updateCaption(currentFileName);
660} 664}
661 665
662void TextEdit::showEditTools() 666void TextEdit::showEditTools()
663{ 667{
664// if ( !doc ) 668// if ( !doc )
665// close(); 669// close();
666// clear(); 670// clear();
667 fileSelector->hide(); 671 fileSelector->hide();
668 menu->show(); 672 menu->show();
669 editBar->show(); 673 editBar->show();
670 if ( searchVisible ) 674 if ( searchVisible )
671 searchBar->show(); 675 searchBar->show();
672 updateCaption(); 676// updateCaption();
673 editorStack->raiseWidget( editor ); 677 editorStack->raiseWidget( editor );
674 setWState (WState_Reserved1 ); 678 setWState (WState_Reserved1 );
675} 679}
676 680
677bool TextEdit::save() 681bool TextEdit::save()
678{ 682{
679 // case of nothing to save... 683 // case of nothing to save...
680 if ( !doc || !bFromDocView) 684 if ( !doc || !bFromDocView)
681 return true; 685 return true;
682 if ( !editor->edited() ) { 686 if ( !editor->edited() ) {
683 delete doc; 687 delete doc;
684 doc = 0; 688 doc = 0;
685 return true; 689 return true;
686 } 690 }
687 691
688 QString rt = editor->text(); 692 QString rt = editor->text();
689 693 qDebug(currentFileName);
690 if(currentFileName.isEmpty() || currentFileName == "Unnamed") { 694
695 if( currentFileName.isEmpty() || currentFileName == "Unnamed") {
691 696
692 if ( doc->name().isEmpty() ) { 697 if ( doc->name().isEmpty() ) {
693 QString pt = rt.simplifyWhiteSpace(); 698 QString pt = rt.simplifyWhiteSpace();
694 int i = pt.find( ' ' ); 699 int i = pt.find( ' ' );
695 QString docname = pt; 700 QString docname = pt;
696 if ( i > 0 ) 701 if ( i > 0 )
697 docname = pt.left( i ); 702 docname = pt.left( i );
698 // remove "." at the beginning 703 // remove "." at the beginning
699 while( docname.startsWith( "." ) ) 704 while( docname.startsWith( "." ) )
700 docname = docname.mid( 1 ); 705 docname = docname.mid( 1 );
701 docname.replace( QRegExp("/"), "_" ); 706 docname.replace( QRegExp("/"), "_" );
702 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 707 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
703 if ( docname.length() > 40 ) 708 if ( docname.length() > 40 )
704 docname = docname.left(40); 709 docname = docname.left(40);
705 if ( docname.isEmpty() ) 710 if ( docname.isEmpty() )
706 docname = "Empty Text"; 711 docname = "Empty Text";
707 doc->setName(docname); 712 doc->setName(docname);
708 currentFileName=docname; 713 currentFileName=docname;
709 } 714 }
710 } 715 }
711 716
712 fileSaver *fileSaveDlg; 717 fileSaver *fileSaveDlg;
713 fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName); 718 fileSaveDlg=new fileSaver(this,"SaveFile",TRUE,0, currentFileName);
714 fileSaveDlg->exec(); 719 if( fileSaveDlg->exec() != 0 ) {
715 QString fileNm=fileSaveDlg->selectedFileName; 720 QString fileNm=fileSaveDlg->selectedFileName;
716 qDebug("save filename "+fileNm); 721 qDebug("save filename "+fileNm);
717 doc->setName(fileNm); 722 doc->setName(fileNm);
718 updateCaption(); 723 updateCaption(fileNm);
724 }
719 delete fileSaveDlg; 725 delete fileSaveDlg;
720 726
721 FileManager fm; 727 FileManager fm;
722 if ( !fm.saveFile( *doc, rt ) ) { 728 if ( !fm.saveFile( *doc, rt ) ) {
723 return false; 729 return false;
724 } 730 }
725 delete doc; 731 delete doc;
726 doc = 0; 732 doc = 0;
727 editor->setEdited( false ); 733 editor->setEdited( false );
728 return true; 734 return true;
729} 735}
730 736
731void TextEdit::clear() 737void TextEdit::clear()
732{ 738{
733 delete doc; 739 delete doc;
734 doc = 0; 740 doc = 0;
735 editor->clear(); 741 editor->clear();
736} 742}
737 743
738void TextEdit::updateCaption( const QString &name ) 744void TextEdit::updateCaption( const QString &name )
739{ 745{
740 if ( !doc ) 746 if ( !doc )
741 setCaption( tr("Text Editor") ); 747 setCaption( tr("Text Editor") );
742 else { 748 else {
743 QString s = name; 749 QString s = name;
744 if ( s.isNull() ) 750 if ( s.isNull() )
745 s = doc->name(); 751 s = doc->name();
746 if ( s.isEmpty() ) { 752 if ( s.isEmpty() ) {
747 s = tr( "Unnamed" ); 753 s = tr( "Unnamed" );
748 currentFileName=s; 754 currentFileName=s;
749 } 755 }
750 setCaption( s + " - " + tr("Text Editor") ); 756 setCaption( s + " - " + tr("Text Editor") );
751 } 757 }
752} 758}
753 759
754void TextEdit::setDocument(const QString& fileref) 760void TextEdit::setDocument(const QString& fileref)
755{ 761{
756 bFromDocView = TRUE; 762 bFromDocView = TRUE;
757 openFile(DocLnk(fileref)); 763 openFile(DocLnk(fileref));
758// showEditTools(); 764// showEditTools();
759} 765}
760 766
761void TextEdit::closeEvent( QCloseEvent *e ) 767void TextEdit::closeEvent( QCloseEvent *e )
762{ 768{
763 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { 769 if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) {
764 e->ignore(); 770 e->ignore();
765 repaint(); 771 repaint();
766// fileRevert(); 772// fileRevert();
767 773
768 } else { 774 } else {
769 bFromDocView = FALSE; 775 bFromDocView = FALSE;
770 e->accept(); 776 e->accept();
771 } 777 }
772} 778}
773 779
774void TextEdit::accept() 780void TextEdit::accept()
775{ 781{
776 close(); 782 close();
777// fileOpen(); //godamn thats obnoxious! lemme out!!! 783// fileOpen(); //godamn thats obnoxious! lemme out!!!
778} 784}
779 785
780void TextEdit::changeFont() { 786void TextEdit::changeFont() {
781 FontDatabase fdb; 787 FontDatabase fdb;
782 QFont defaultFont=editor->font(); 788 QFont defaultFont=editor->font();
783 QFontInfo fontInfo(defaultFont); 789 QFontInfo fontInfo(defaultFont);
784 Config cfg("TextEdit"); 790 Config cfg("TextEdit");
785 cfg.setGroup("Font"); 791 cfg.setGroup("Font");
786 QString family = cfg.readEntry("Family", fontInfo.family()); 792 QString family = cfg.readEntry("Family", fontInfo.family());
787 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 793 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
788 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 794 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
789 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 795 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
790 796
791 defaultFont = fdb.font(family,style,i_size,charSet); 797 defaultFont = fdb.font(family,style,i_size,charSet);
792 798
793 FontDialog *fontDlg; 799 FontDialog *fontDlg;
794 fontDlg=new FontDialog(this,"FontDialog",TRUE); 800 fontDlg=new FontDialog(this,"FontDialog",TRUE);
795 801
796 fontDlg->exec(); 802 fontDlg->exec();
797 803
798 QFont myFont=fontDlg->selectedFont; 804 QFont myFont=fontDlg->selectedFont;
799 editor->setFont( myFont); 805 editor->setFont( myFont);
800 delete fontDlg; 806 delete fontDlg;
801 807
802} 808}
803 809
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h
index 4e469cc..4bfb260 100644
--- a/core/apps/textedit/textedit.h
+++ b/core/apps/textedit/textedit.h
@@ -1,105 +1,105 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// additions made by L.J. Potter Sun 02-17-2002 22:27:46 20// additions made by L.J. Potter Sun 02-17-2002 22:27:46
21 21
22#ifndef TEXTEDIT_H 22#ifndef TEXTEDIT_H
23#define TEXTEDIT_H 23#define TEXTEDIT_H
24 24
25#define QTEXTEDIT_OPEN_API 25#define QTEXTEDIT_OPEN_API
26 26
27#include <qpe/filemanager.h> 27#include <qpe/filemanager.h>
28 28
29#include <qmainwindow.h> 29#include <qmainwindow.h>
30#include <qmultilineedit.h> 30#include <qmultilineedit.h>
31#include <qlist.h> 31#include <qlist.h>
32#include <qmap.h> 32#include <qmap.h>
33 33
34class QWidgetStack; 34class QWidgetStack;
35class QToolButton; 35class QToolButton;
36class QPopupMenu; 36class QPopupMenu;
37class QToolBar; 37class QToolBar;
38class QLineEdit; 38class QLineEdit;
39class QAction; 39class QAction;
40class FileSelector; 40class FileSelector;
41class QpeEditor; 41class QpeEditor;
42 42
43class TextEdit : public QMainWindow 43class TextEdit : public QMainWindow
44{ 44{
45 Q_OBJECT 45 Q_OBJECT
46 46
47public: 47public:
48 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); 48 TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
49 ~TextEdit(); 49 ~TextEdit();
50 50
51 void openFile( const QString & ); 51 void openFile( const QString & );
52 52
53protected: 53protected:
54 void closeEvent( QCloseEvent *e ); 54 void closeEvent( QCloseEvent *e );
55 55
56private slots: 56private slots:
57 void setDocument(const QString&); 57 void setDocument(const QString&);
58 void changeFont(); 58 void changeFont();
59 void fileNew(); 59 void fileNew();
60 void fileRevert(); 60 void fileRevert();
61 void fileOpen(); 61 void fileOpen();
62 void newFileOpen(); 62 void newFileOpen();
63 bool save(); 63 bool save();
64 64
65 void editCut(); 65 void editCut();
66 void editCopy(); 66 void editCopy();
67 void editPaste(); 67 void editPaste();
68 void editFind(); 68 void editFind();
69 69
70 void findNext(); 70 void findNext();
71 void findClose(); 71 void findClose();
72 72
73 void search(); 73 void search();
74 void accept(); 74 void accept();
75 75
76 void newFile( const DocLnk & ); 76 void newFile( const DocLnk & );
77 void openFile( const DocLnk & ); 77 void openFile( const DocLnk & );
78 void showEditTools(); 78 void showEditTools();
79 79
80 void zoomIn(); 80 void zoomIn();
81 void zoomOut(); 81 void zoomOut();
82 void setBold(bool y); 82 void setBold(bool y);
83 void setItalic(bool y); 83 void setItalic(bool y);
84 void setWordWrap(bool y); 84 void setWordWrap(bool y);
85 85
86private: 86private:
87 void colorChanged( const QColor &c ); 87 void colorChanged( const QColor &c );
88 void clear(); 88 void clear();
89 void updateCaption( const QString &name=QString::null ); 89 void updateCaption( const QString &name=QString::null );
90 void setFontSize(int sz, bool round_down_not_up); 90 void setFontSize(int sz, bool round_down_not_up);
91 91
92private: 92private:
93 QWidgetStack *editorStack; 93 QWidgetStack *editorStack;
94 FileSelector *fileSelector; 94 FileSelector *fileSelector;
95 QpeEditor* editor; 95 QpeEditor* editor;
96 QToolBar *menu, *editBar, *searchBar; 96 QToolBar *menu, *editBar, *searchBar;
97 QLineEdit *searchEdit; 97 QLineEdit *searchEdit;
98 DocLnk *doc; 98 DocLnk *doc;
99 bool searchVisible; 99 bool searchVisible;
100 bool bFromDocView; 100 bool bFromDocView;
101 QAction *zin, *zout; 101 QAction *zin, *zout;
102 QString currentFileName; 102 QString currentFileName;
103}; 103};
104 104
105#endif 105#endif