summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-04-11 23:53:23 (UTC)
committer llornkcor <llornkcor>2002-04-11 23:53:23 (UTC)
commita1615d98bdd7430e0533c0325dfdc39bf6627ab2 (patch) (unidiff)
tree14989f0603a32abaa90826b2eff5fb318f99bf70
parent2599e347d9444cfa6282fec9f2bfb9df4743d6d2 (diff)
downloadopie-a1615d98bdd7430e0533c0325dfdc39bf6627ab2.zip
opie-a1615d98bdd7430e0533c0325dfdc39bf6627ab2.tar.gz
opie-a1615d98bdd7430e0533c0325dfdc39bf6627ab2.tar.bz2
here ya go
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/apps/textedit/textedit.cpp65
-rw-r--r--core/apps/textedit/textedit.pro2
2 files changed, 36 insertions, 31 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp
index 943fecd..a66b967 100644
--- a/core/apps/textedit/textedit.cpp
+++ b/core/apps/textedit/textedit.cpp
@@ -1,945 +1,950 @@
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#include "filePermissions.h" 25#include "filePermissions.h"
26 26
27#include "fontDialog.h" 27#include "fontDialog.h"
28 28
29#include <qpe/fontdatabase.h> 29#include <qpe/fontdatabase.h>
30#include <qpe/global.h> 30#include <qpe/global.h>
31#include <qpe/fileselector.h> 31#include <qpe/fileselector.h>
32#include <qpe/applnk.h> 32#include <qpe/applnk.h>
33#include <qpe/resource.h> 33#include <qpe/resource.h>
34#include <qpe/config.h> 34#include <qpe/config.h>
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/qcopenvelope_qws.h>
39//#include <qpe/finddialog.h> 39//#include <qpe/finddialog.h>
40#include <opie/ofileselector.h>
40 41
41#include <qstringlist.h> 42#include <qstringlist.h>
42#include <qaction.h> 43#include <qaction.h>
43#include <qcolordialog.h> 44#include <qcolordialog.h>
44#include <qfileinfo.h> 45#include <qfileinfo.h>
45#include <qlineedit.h> 46#include <qlineedit.h>
46#include <qmessagebox.h> 47#include <qmessagebox.h>
47#include <qobjectlist.h> 48#include <qobjectlist.h>
48#include <qpopupmenu.h> 49#include <qpopupmenu.h>
49#include <qspinbox.h> 50#include <qspinbox.h>
50#include <qtoolbutton.h> 51#include <qtoolbutton.h>
51#include <qwidgetstack.h> 52#include <qwidgetstack.h>
52#include <qcheckbox.h> 53#include <qcheckbox.h>
53#include <qcombo.h> 54#include <qcombo.h>
54#include <unistd.h> 55#include <unistd.h>
55#include <sys/stat.h> 56#include <sys/stat.h>
56 57
57#include <stdlib.h> //getenv 58#include <stdlib.h> //getenv
58/* XPM */ 59/* XPM */
59static char * filesave_xpm[] = { 60static char * filesave_xpm[] = {
60"16 16 78 1", 61"16 16 78 1",
61" c None", 62" c None",
62". c #343434", 63". c #343434",
63"+ c #A0A0A0", 64"+ c #A0A0A0",
64"@ c #565656", 65"@ c #565656",
65"# c #9E9E9E", 66"# c #9E9E9E",
66"$ c #525252", 67"$ c #525252",
67"% c #929292", 68"% c #929292",
68"& c #676767", 69"& c #676767",
69"* c #848484", 70"* c #848484",
70"= c #666666", 71"= c #666666",
71"- c #D8D8D8", 72"- c #D8D8D8",
72"; c #FFFFFF", 73"; c #FFFFFF",
73"> c #DBDBDB", 74"> c #DBDBDB",
74", c #636363", 75", c #636363",
75"' c #989898", 76"' c #989898",
76") c #2D2D2D", 77") c #2D2D2D",
77"! c #909090", 78"! c #909090",
78"~ c #AEAEAE", 79"~ c #AEAEAE",
79"{ c #EAEAEA", 80"{ c #EAEAEA",
80"] c #575757", 81"] c #575757",
81"^ c #585858", 82"^ c #585858",
82"/ c #8A8A8A", 83"/ c #8A8A8A",
83"( c #828282", 84"( c #828282",
84"_ c #6F6F6F", 85"_ c #6F6F6F",
85": c #C9C9C9", 86": c #C9C9C9",
86"< c #050505", 87"< c #050505",
87"[ c #292929", 88"[ c #292929",
88"} c #777777", 89"} c #777777",
89"| c #616161", 90"| c #616161",
90"1 c #3A3A3A", 91"1 c #3A3A3A",
91"2 c #BEBEBE", 92"2 c #BEBEBE",
92"3 c #2C2C2C", 93"3 c #2C2C2C",
93"4 c #7C7C7C", 94"4 c #7C7C7C",
94"5 c #F6F6F6", 95"5 c #F6F6F6",
95"6 c #FCFCFC", 96"6 c #FCFCFC",
96"7 c #6B6B6B", 97"7 c #6B6B6B",
97"8 c #959595", 98"8 c #959595",
98"9 c #4F4F4F", 99"9 c #4F4F4F",
99"0 c #808080", 100"0 c #808080",
100"a c #767676", 101"a c #767676",
101"b c #818181", 102"b c #818181",
102"c c #B8B8B8", 103"c c #B8B8B8",
103"d c #FBFBFB", 104"d c #FBFBFB",
104"e c #F9F9F9", 105"e c #F9F9F9",
105"f c #CCCCCC", 106"f c #CCCCCC",
106"g c #030303", 107"g c #030303",
107"h c #737373", 108"h c #737373",
108"i c #7A7A7A", 109"i c #7A7A7A",
109"j c #7E7E7E", 110"j c #7E7E7E",
110"k c #6A6A6A", 111"k c #6A6A6A",
111"l c #FAFAFA", 112"l c #FAFAFA",
112"m c #505050", 113"m c #505050",
113"n c #9D9D9D", 114"n c #9D9D9D",
114"o c #333333", 115"o c #333333",
115"p c #7B7B7B", 116"p c #7B7B7B",
116"q c #787878", 117"q c #787878",
117"r c #696969", 118"r c #696969",
118"s c #494949", 119"s c #494949",
119"t c #555555", 120"t c #555555",
120"u c #949494", 121"u c #949494",
121"v c #E6E6E6", 122"v c #E6E6E6",
122"w c #424242", 123"w c #424242",
123"x c #515151", 124"x c #515151",
124"y c #535353", 125"y c #535353",
125"z c #3E3E3E", 126"z c #3E3E3E",
126"A c #D4D4D4", 127"A c #D4D4D4",
127"B c #0C0C0C", 128"B c #0C0C0C",
128"C c #353535", 129"C c #353535",
129"D c #474747", 130"D c #474747",
130"E c #ECECEC", 131"E c #ECECEC",
131"F c #919191", 132"F c #919191",
132"G c #7D7D7D", 133"G c #7D7D7D",
133"H c #000000", 134"H c #000000",
134"I c #404040", 135"I c #404040",
135"J c #858585", 136"J c #858585",
136"K c #323232", 137"K c #323232",
137"L c #D0D0D0", 138"L c #D0D0D0",
138"M c #1C1C1C", 139"M c #1C1C1C",
139" ...+ ", 140" ...+ ",
140" @#$%&..+ ", 141" @#$%&..+ ",
141" .*=-;;>,..+ ", 142" .*=-;;>,..+ ",
142" ')!~;;;;;;{]..", 143" ')!~;;;;;;{]..",
143" ^/(-;;;;;;;_:<", 144" ^/(-;;;;;;;_:<",
144" [}|;;;;;;;{12$", 145" [}|;;;;;;;{12$",
145" #34-55;;;;678$+", 146" #34-55;;;;678$+",
146" 90ab=c;dd;e1fg ", 147" 90ab=c;dd;e1fg ",
147" [ahij((kbl0mn$ ", 148" [ahij((kbl0mn$ ",
148" op^q^^7r&]s/$+ ", 149" op^q^^7r&]s/$+ ",
149"@btu;vbwxy]zAB ", 150"@btu;vbwxy]zAB ",
150"CzDEvEv;;DssF$ ", 151"CzDEvEv;;DssF$ ",
151"G.H{E{E{IxsJ$+ ", 152"G.H{E{E{IxsJ$+ ",
152" +...vEKxzLM ", 153" +...vEKxzLM ",
153" +...z]n$ ", 154" +...z]n$ ",
154" +... "}; 155" +... "};
155 156
156 157
157#if QT_VERSION < 300 158#if QT_VERSION < 300
158 159
159class QpeEditor : public QMultiLineEdit 160class QpeEditor : public QMultiLineEdit
160{ 161{
161 // Q_OBJECT 162 // Q_OBJECT
162public: 163public:
163 QpeEditor( QWidget *parent, const char * name = 0 ) 164 QpeEditor( QWidget *parent, const char * name = 0 )
164 : QMultiLineEdit( parent, name ) 165 : QMultiLineEdit( parent, name )
165 { 166 {
166 clearTableFlags(); 167 clearTableFlags();
167 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar ); 168 setTableFlags( Tbl_vScrollBar | Tbl_autoHScrollBar );
168 } 169 }
169 170
170 void find( const QString &txt, bool caseSensitive, 171 void find( const QString &txt, bool caseSensitive,
171 bool backwards ); 172 bool backwards );
172//public slots: 173//public slots:
173 /* 174 /*
174signals: 175signals:
175 void notFound(); 176 void notFound();
176 void searchWrapped(); 177 void searchWrapped();
177 */ 178 */
178 179
179private: 180private:
180 181
181}; 182};
182 183
183 184
184void QpeEditor::find ( const QString &txt, bool caseSensitive, 185void QpeEditor::find ( const QString &txt, bool caseSensitive,
185 bool backwards ) 186 bool backwards )
186{ 187{
187 static bool wrap = FALSE; 188 static bool wrap = FALSE;
188 int line, col; 189 int line, col;
189 if ( wrap ) { 190 if ( wrap ) {
190 if ( !backwards ) 191 if ( !backwards )
191 line = col = 0; 192 line = col = 0;
192 wrap = FALSE; 193 wrap = FALSE;
193 // emit searchWrapped(); 194 // emit searchWrapped();
194 } else { 195 } else {
195 getCursorPosition( &line, &col ); 196 getCursorPosition( &line, &col );
196 } 197 }
197 //ignore backwards for now.... 198 //ignore backwards for now....
198 if ( !backwards ) { 199 if ( !backwards ) {
199 for ( ; ; ) { 200 for ( ; ; ) {
200 if ( line >= numLines() ) { 201 if ( line >= numLines() ) {
201 wrap = TRUE; 202 wrap = TRUE;
202 //emit notFound(); 203 //emit notFound();
203 break; 204 break;
204 } 205 }
205 int findCol = getString( line )->find( txt, col, caseSensitive ); 206 int findCol = getString( line )->find( txt, col, caseSensitive );
206 if ( findCol >= 0 ) { 207 if ( findCol >= 0 ) {
207 setCursorPosition( line, findCol, FALSE ); 208 setCursorPosition( line, findCol, FALSE );
208 col = findCol + txt.length(); 209 col = findCol + txt.length();
209 setCursorPosition( line, col, TRUE ); 210 setCursorPosition( line, col, TRUE );
210 211
211 //found = TRUE; 212 //found = TRUE;
212 break; 213 break;
213 } 214 }
214 line++; 215 line++;
215 col = 0; 216 col = 0;
216 } 217 }
217 218
218 } 219 }
219 220
220} 221}
221 222
222 223
223#else 224#else
224 225
225#error "Must make a QpeEditor that inherits QTextEdit" 226#error "Must make a QpeEditor that inherits QTextEdit"
226 227
227#endif 228#endif
228 229
229 230
230static const int nfontsizes = 6; 231static const int nfontsizes = 6;
231static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; 232static const int fontsize[nfontsizes] = {8,10,12,14,18,24};
232 233
233TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) 234TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f )
234 : QMainWindow( parent, name, f ), bFromDocView( FALSE ) 235 : QMainWindow( parent, name, f ), bFromDocView( FALSE )
235{ 236{
236 doc = 0; 237 doc = 0;
237 edited=FALSE; 238 edited=FALSE;
238 edited1=FALSE; 239 edited1=FALSE;
239 setToolBarsMovable( FALSE ); 240 setToolBarsMovable( FALSE );
240 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) ); 241 connect( qApp,SIGNAL( aboutToQuit()),SLOT( cleanUp()) );
241 242
242 channel = new QCopChannel( "QPE/Application/textedit", this ); 243 channel = new QCopChannel( "QPE/Application/textedit", this );
243 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 244 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
244 this, SLOT(receive(const QCString&, const QByteArray&)) ); 245 this, SLOT(receive(const QCString&, const QByteArray&)) );
245 246
246 setIcon( Resource::loadPixmap( "TextEditor" ) ); 247 setIcon( Resource::loadPixmap( "TextEditor" ) );
247 248
248 QPEToolBar *bar = new QPEToolBar( this ); 249 QPEToolBar *bar = new QPEToolBar( this );
249 bar->setHorizontalStretchable( TRUE ); 250 bar->setHorizontalStretchable( TRUE );
250 menu = bar; 251 menu = bar;
251 252
252 QPEMenuBar *mb = new QPEMenuBar( bar ); 253 QPEMenuBar *mb = new QPEMenuBar( bar );
253 QPopupMenu *file = new QPopupMenu( this ); 254 QPopupMenu *file = new QPopupMenu( this );
254 QPopupMenu *edit = new QPopupMenu( this ); 255 QPopupMenu *edit = new QPopupMenu( this );
255 font = new QPopupMenu( this ); 256 font = new QPopupMenu( this );
256 257
257 bar = new QPEToolBar( this ); 258 bar = new QPEToolBar( this );
258 editBar = bar; 259 editBar = bar;
259 260
260 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); 261 QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
261 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); 262 connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
262 a->addTo( bar ); 263 a->addTo( bar );
263 a->addTo( file ); 264 a->addTo( file );
264 265
265 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 266 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
266 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); 267 connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
267 a->addTo( bar ); 268 a->addTo( bar );
268 a->addTo( file ); 269 a->addTo( file );
269 270
270 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 271 a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
271 connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); 272 connect( a, SIGNAL( activated() ), this, SLOT( save() ) );
272 file->insertSeparator(); 273 file->insertSeparator();
273 a->addTo( file ); 274 a->addTo( file );
274 275
275 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); 276 a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 );
276 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); 277 connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) );
277 a->addTo( file ); 278 a->addTo( file );
278 279
279 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); 280 a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
280 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 281 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
281 a->addTo( editBar ); 282 a->addTo( editBar );
282 a->addTo( edit ); 283 a->addTo( edit );
283 284
284 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); 285 a = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
285 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 286 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
286 a->addTo( editBar ); 287 a->addTo( editBar );
287 a->addTo( edit ); 288 a->addTo( edit );
288 289
289 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); 290 a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
290 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 291 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
291 a->addTo( editBar ); 292 a->addTo( editBar );
292 a->addTo( edit ); 293 a->addTo( edit );
293 294
294 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); 295 a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
295 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); 296 connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
296 edit->insertSeparator(); 297 edit->insertSeparator();
297 a->addTo( bar ); 298 a->addTo( bar );
298 a->addTo( edit ); 299 a->addTo( edit );
299 300
300 int defsize; 301 int defsize;
301 bool defb, defi, wrap; 302 bool defb, defi, wrap;
302 303
303 Config cfg("TextEdit"); 304 Config cfg("TextEdit");
304 cfg.setGroup("View"); 305 cfg.setGroup("View");
305 defsize = cfg.readNumEntry("FontSize",10); 306 defsize = cfg.readNumEntry("FontSize",10);
306 defb = cfg.readBoolEntry("Bold",FALSE); 307 defb = cfg.readBoolEntry("Bold",FALSE);
307 defi = cfg.readBoolEntry("Italic",FALSE); 308 defi = cfg.readBoolEntry("Italic",FALSE);
308 wrap = cfg.readBoolEntry("Wrap",TRUE); 309 wrap = cfg.readBoolEntry("Wrap",TRUE);
309 310
310 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); 311 zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 );
311 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); 312 connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) );
312 zin->addTo( font ); 313 zin->addTo( font );
313 314
314 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); 315 zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 );
315 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); 316 connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) );
316 zout->addTo( font ); 317 zout->addTo( font );
317 318
318 font->insertSeparator(); 319 font->insertSeparator();
319 320
320#if 0 321#if 0
321 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); 322 QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 );
322 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); 323 connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) );
323 ba->setToggleAction(TRUE); 324 ba->setToggleAction(TRUE);
324 ba->addTo( font ); 325 ba->addTo( font );
325 326
326 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); 327 QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 );
327 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); 328 connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) );
328 ia->setToggleAction(TRUE); 329 ia->setToggleAction(TRUE);
329 ia->addTo( font ); 330 ia->addTo( font );
330 331
331 ba->setOn(defb); 332 ba->setOn(defb);
332 ia->setOn(defi); 333 ia->setOn(defi);
333 334
334 font->insertSeparator(); 335 font->insertSeparator();
335#endif 336#endif
336 337
337 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); 338 QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 );
338 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); 339 connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) );
339 wa->setToggleAction(TRUE); 340 wa->setToggleAction(TRUE);
340 wa->addTo( font ); 341 wa->addTo( font );
341 342
342 font->insertSeparator(); 343 font->insertSeparator();
343 font->insertItem(tr("Font"), this, SLOT(changeFont()) ); 344 font->insertItem(tr("Font"), this, SLOT(changeFont()) );
344 345
345 font->insertSeparator(); 346 font->insertSeparator();
346 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); 347 nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 );
347 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); 348 connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) );
348 nStart->setToggleAction(TRUE); 349 nStart->setToggleAction(TRUE);
349 nStart->addTo( font ); 350 nStart->addTo( font );
350 351
351 mb->insertItem( tr( "File" ), file ); 352 mb->insertItem( tr( "File" ), file );
352 mb->insertItem( tr( "Edit" ), edit ); 353 mb->insertItem( tr( "Edit" ), edit );
353 mb->insertItem( tr( "View" ), font ); 354 mb->insertItem( tr( "View" ), font );
354 355
355 searchBar = new QPEToolBar(this); 356 searchBar = new QPEToolBar(this);
356 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); 357 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
357 358
358 searchBar->setHorizontalStretchable( TRUE ); 359 searchBar->setHorizontalStretchable( TRUE );
359 360
360 searchEdit = new QLineEdit( searchBar, "searchEdit" ); 361 searchEdit = new QLineEdit( searchBar, "searchEdit" );
361 searchBar->setStretchableWidget( searchEdit ); 362 searchBar->setStretchableWidget( searchEdit );
362 connect( searchEdit, SIGNAL( textChanged( const QString & ) ), 363 connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
363 this, SLOT( search() ) ); 364 this, SLOT( search() ) );
364 365
365 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); 366 a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
366 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); 367 connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
367 a->addTo( searchBar ); 368 a->addTo( searchBar );
368 a->addTo( edit ); 369 a->addTo( edit );
369 370
370 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 371 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
371 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); 372 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
372 a->addTo( searchBar ); 373 a->addTo( searchBar );
373 374
374 edit->insertSeparator(); 375 edit->insertSeparator();
375 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); 376 a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
376 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); 377 connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) );
377 a->addTo( edit ); 378 a->addTo( edit );
378 379
379 searchBar->hide(); 380 searchBar->hide();
380 381
381 editor = new QpeEditor( this ); 382 editor = new QpeEditor( this );
382 setCentralWidget( editor ); 383 setCentralWidget( editor );
383 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 384 editor->setFrameStyle( QFrame::Panel | QFrame::Sunken );
384 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); 385 connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) );
385 386
386// resize( 200, 300 ); 387// resize( 200, 300 );
387 388
388// setFontSize(defsize,TRUE); 389// setFontSize(defsize,TRUE);
389 FontDatabase fdb; 390 FontDatabase fdb;
390 QFont defaultFont=editor->font(); 391 QFont defaultFont=editor->font();
391 QFontInfo fontInfo(defaultFont); 392 QFontInfo fontInfo(defaultFont);
392 393
393 cfg.setGroup("Font"); 394 cfg.setGroup("Font");
394 QString family = cfg.readEntry("Family", fontInfo.family()); 395 QString family = cfg.readEntry("Family", fontInfo.family());
395 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 396 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
396 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 397 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
397 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 398 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
398 399
399 defaultFont = fdb.font(family,style,i_size,charSet); 400 defaultFont = fdb.font(family,style,i_size,charSet);
400 editor->setFont( defaultFont); 401 editor->setFont( defaultFont);
401 402
402 wa->setOn(wrap); 403 wa->setOn(wrap);
403 updateCaption(); 404 updateCaption();
404 405
405 cfg.setGroup("View"); 406 cfg.setGroup("View");
406 if(cfg.readEntry("startNew","TRUE") == "TRUE") { 407 if(cfg.readEntry("startNew","TRUE") == "TRUE") {
407 nStart->setOn(TRUE); 408 nStart->setOn(TRUE);
408 fileNew(); 409 fileNew();
409 } else { 410 } else {
410 fileOpen(); 411 fileOpen();
411 } 412 }
412 viewSelection = cfg.readNumEntry( "FileView", 0 ); 413 viewSelection = cfg.readNumEntry( "FileView", 0 );
413} 414}
414 415
415void TextEdit::cleanUp() 416void TextEdit::cleanUp()
416{ 417{
417// save(); 418// save();
418 Config cfg("TextEdit"); 419 Config cfg("TextEdit");
419 cfg.setGroup("View"); 420 cfg.setGroup("View");
420 QFont f = editor->font(); 421 QFont f = editor->font();
421 cfg.writeEntry("FontSize",f.pointSize()); 422 cfg.writeEntry("FontSize",f.pointSize());
422 cfg.writeEntry("Bold",f.bold()); 423 cfg.writeEntry("Bold",f.bold());
423 cfg.writeEntry("Italic",f.italic()); 424 cfg.writeEntry("Italic",f.italic());
424 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); 425 cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth);
425 cfg.writeEntry( "FileView", viewSelection ); 426 cfg.writeEntry( "FileView", viewSelection );
426 427
427} 428}
428 429
429TextEdit::~TextEdit() 430TextEdit::~TextEdit()
430{ 431{
431} 432}
432 433
433void TextEdit::zoomIn() 434void TextEdit::zoomIn()
434{ 435{
435 setFontSize(editor->font().pointSize()+1,FALSE); 436 setFontSize(editor->font().pointSize()+1,FALSE);
436} 437}
437 438
438void TextEdit::zoomOut() 439void TextEdit::zoomOut()
439{ 440{
440 setFontSize(editor->font().pointSize()-1,TRUE); 441 setFontSize(editor->font().pointSize()-1,TRUE);
441} 442}
442 443
443 444
444void TextEdit::setFontSize(int sz, bool round_down_not_up) 445void TextEdit::setFontSize(int sz, bool round_down_not_up)
445{ 446{
446 int s=10; 447 int s=10;
447 for (int i=0; i<nfontsizes; i++) { 448 for (int i=0; i<nfontsizes; i++) {
448 if ( fontsize[i] == sz ) { 449 if ( fontsize[i] == sz ) {
449 s = sz; 450 s = sz;
450 break; 451 break;
451 } else if ( round_down_not_up ) { 452 } else if ( round_down_not_up ) {
452 if ( fontsize[i] < sz ) 453 if ( fontsize[i] < sz )
453 s = fontsize[i]; 454 s = fontsize[i];
454 } else { 455 } else {
455 if ( fontsize[i] > sz ) { 456 if ( fontsize[i] > sz ) {
456 s = fontsize[i]; 457 s = fontsize[i];
457 break; 458 break;
458 } 459 }
459 } 460 }
460 } 461 }
461 462
462 QFont f = editor->font(); 463 QFont f = editor->font();
463 f.setPointSize(s); 464 f.setPointSize(s);
464 editor->setFont(f); 465 editor->setFont(f);
465 466
466 zin->setEnabled(s != fontsize[nfontsizes-1]); 467 zin->setEnabled(s != fontsize[nfontsizes-1]);
467 zout->setEnabled(s != fontsize[0]); 468 zout->setEnabled(s != fontsize[0]);
468} 469}
469 470
470void TextEdit::setBold(bool y) 471void TextEdit::setBold(bool y)
471{ 472{
472 QFont f = editor->font(); 473 QFont f = editor->font();
473 f.setBold(y); 474 f.setBold(y);
474 editor->setFont(f); 475 editor->setFont(f);
475} 476}
476 477
477void TextEdit::setItalic(bool y) 478void TextEdit::setItalic(bool y)
478{ 479{
479 QFont f = editor->font(); 480 QFont f = editor->font();
480 f.setItalic(y); 481 f.setItalic(y);
481 editor->setFont(f); 482 editor->setFont(f);
482} 483}
483 484
484void TextEdit::setWordWrap(bool y) 485void TextEdit::setWordWrap(bool y)
485{ 486{
486 bool state = editor->edited(); 487 bool state = editor->edited();
487 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); 488 editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap );
488 editor->setEdited( state ); 489 editor->setEdited( state );
489} 490}
490 491
491void TextEdit::fileNew() 492void TextEdit::fileNew()
492{ 493{
493// if( !bFromDocView ) { 494// if( !bFromDocView ) {
494// saveAs(); 495// saveAs();
495// } 496// }
496 newFile(DocLnk()); 497 newFile(DocLnk());
497} 498}
498 499
499void TextEdit::fileOpen() 500void TextEdit::fileOpen()
500{ 501{
501 browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); // 502 OFileSelector *fileSelector;
502 browseForFiles->setFileView( viewSelection ); 503 fileSelector = new OFileSelector( this, 1,1,"/","", "text/*");
503 browseForFiles->showMaximized(); 504 fileSelector->showMaximized();
504// if( result != -1 ) 505
505 506// browseForFiles = new fileBrowser(this,tr("Open File"),TRUE,0, "text/*"); //
506 if( browseForFiles->exec() != -1 ) { 507// browseForFiles->setFileView( viewSelection );
507 QString selFile = browseForFiles->selectedFileName; 508// browseForFiles->showMaximized();
508 QStringList fileList = browseForFiles->fileList; 509// // if( result != -1 )
509 qDebug(selFile); 510
510 QStringList::ConstIterator f; 511// if( browseForFiles->exec() != -1 ) {
511 QString fileTemp; 512// QString selFile = browseForFiles->selectedFileName;
512 for ( f = fileList.begin(); f != fileList.end(); f++ ) { 513// QStringList fileList = browseForFiles->fileList;
513 fileTemp = *f; 514// qDebug(selFile);
514 fileTemp.right( fileTemp.length()-5); 515// QStringList::ConstIterator f;
515 QString fileName = fileTemp; 516// QString fileTemp;
516 if( fileName != "Unnamed" || fileName != "Empty Text" ) { 517// for ( f = fileList.begin(); f != fileList.end(); f++ ) {
517 currentFileName = fileName; 518// fileTemp = *f;
518 qDebug("please open "+currentFileName); 519// fileTemp.right( fileTemp.length()-5);
519 openFile(fileName ); 520// QString fileName = fileTemp;
520 } 521// if( fileName != "Unnamed" || fileName != "Empty Text" ) {
521 } 522// currentFileName = fileName;
522 viewSelection = browseForFiles->SelectionCombo->currentItem(); 523// qDebug("please open "+currentFileName);
523 } 524// openFile(fileName );
524 delete browseForFiles; 525// }
525 editor->setEdited( FALSE); 526// }
526 edited1=FALSE; 527// viewSelection = browseForFiles->SelectionCombo->currentItem();
527 edited=FALSE; 528// }
528 if(caption().left(1)=="*") 529// delete browseForFiles;
529 setCaption(caption().right(caption().length()-1)); 530// editor->setEdited( FALSE);
530 doSearchBar(); 531// edited1=FALSE;
532// edited=FALSE;
533// if(caption().left(1)=="*")
534// setCaption(caption().right(caption().length()-1));
535// doSearchBar();
531} 536}
532 537
533void TextEdit::doSearchBar() 538void TextEdit::doSearchBar()
534{ 539{
535 Config cfg("TextEdit"); 540 Config cfg("TextEdit");
536 cfg.setGroup("View"); 541 cfg.setGroup("View");
537 if(cfg.readEntry("SearchBar","Closed") != "Opened") 542 if(cfg.readEntry("SearchBar","Closed") != "Opened")
538 searchBar->hide(); 543 searchBar->hide();
539} 544}
540 545
541#if 0 546#if 0
542void TextEdit::slotFind() 547void TextEdit::slotFind()
543{ 548{
544 FindDialog frmFind( tr("Text Editor"), this ); 549 FindDialog frmFind( tr("Text Editor"), this );
545 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), 550 connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)),
546 editor, SLOT(slotDoFind( const QString&,bool,bool))); 551 editor, SLOT(slotDoFind( const QString&,bool,bool)));
547 552
548 //case sensitive, backwards, [category] 553 //case sensitive, backwards, [category]
549 554
550 connect( editor, SIGNAL(notFound()), 555 connect( editor, SIGNAL(notFound()),
551 &frmFind, SLOT(slotNotFound()) ); 556 &frmFind, SLOT(slotNotFound()) );
552 connect( editor, SIGNAL(searchWrapped()), 557 connect( editor, SIGNAL(searchWrapped()),
553 &frmFind, SLOT(slotWrapAround()) ); 558 &frmFind, SLOT(slotWrapAround()) );
554 559
555 frmFind.exec(); 560 frmFind.exec();
556 561
557 562
558} 563}
559#endif 564#endif
560 565
561void TextEdit::fileRevert() 566void TextEdit::fileRevert()
562{ 567{
563 clear(); 568 clear();
564 fileOpen(); 569 fileOpen();
565} 570}
566 571
567void TextEdit::editCut() 572void TextEdit::editCut()
568{ 573{
569#ifndef QT_NO_CLIPBOARD 574#ifndef QT_NO_CLIPBOARD
570 editor->cut(); 575 editor->cut();
571#endif 576#endif
572} 577}
573 578
574void TextEdit::editCopy() 579void TextEdit::editCopy()
575{ 580{
576#ifndef QT_NO_CLIPBOARD 581#ifndef QT_NO_CLIPBOARD
577 editor->copy(); 582 editor->copy();
578#endif 583#endif
579} 584}
580 585
581void TextEdit::editPaste() 586void TextEdit::editPaste()
582{ 587{
583#ifndef QT_NO_CLIPBOARD 588#ifndef QT_NO_CLIPBOARD
584 editor->paste(); 589 editor->paste();
585#endif 590#endif
586} 591}
587 592
588void TextEdit::editFind() 593void TextEdit::editFind()
589{ 594{
590 searchBar->show(); 595 searchBar->show();
591 searchVisible = TRUE; 596 searchVisible = TRUE;
592 searchEdit->setFocus(); 597 searchEdit->setFocus();
593 Config cfg("TextEdit"); 598 Config cfg("TextEdit");
594 cfg.setGroup("View"); 599 cfg.setGroup("View");
595 cfg.writeEntry("SearchBar","Opened"); 600 cfg.writeEntry("SearchBar","Opened");
596 601
597} 602}
598 603
599void TextEdit::findNext() 604void TextEdit::findNext()
600{ 605{
601 editor->find( searchEdit->text(), FALSE, FALSE ); 606 editor->find( searchEdit->text(), FALSE, FALSE );
602 607
603} 608}
604 609
605void TextEdit::findClose() 610void TextEdit::findClose()
606{ 611{
607 searchVisible = FALSE; 612 searchVisible = FALSE;
608 searchBar->hide(); 613 searchBar->hide();
609 Config cfg("TextEdit"); 614 Config cfg("TextEdit");
610 cfg.setGroup("View"); 615 cfg.setGroup("View");
611 cfg.writeEntry("SearchBar","Closed"); 616 cfg.writeEntry("SearchBar","Closed");
612 cfg.write(); 617 cfg.write();
613} 618}
614 619
615void TextEdit::search() 620void TextEdit::search()
616{ 621{
617 editor->find( searchEdit->text(), FALSE, FALSE ); 622 editor->find( searchEdit->text(), FALSE, FALSE );
618} 623}
619 624
620void TextEdit::newFile( const DocLnk &f ) 625void TextEdit::newFile( const DocLnk &f )
621{ 626{
622 DocLnk nf = f; 627 DocLnk nf = f;
623 nf.setType("text/plain"); 628 nf.setType("text/plain");
624 clear(); 629 clear();
625 setWState (WState_Reserved1 ); 630 setWState (WState_Reserved1 );
626 editor->setFocus(); 631 editor->setFocus();
627 doc = new DocLnk(nf); 632 doc = new DocLnk(nf);
628 currentFileName = "Unnamed"; 633 currentFileName = "Unnamed";
629 qDebug("newFile "+currentFileName); 634 qDebug("newFile "+currentFileName);
630 updateCaption( currentFileName); 635 updateCaption( currentFileName);
631// editor->setEdited( FALSE); 636// editor->setEdited( FALSE);
632} 637}
633 638
634void TextEdit::openFile( const QString &f ) 639void TextEdit::openFile( const QString &f )
635{ 640{
636 641
637// bFromDocView = TRUE; 642// bFromDocView = TRUE;
638 DocLnk nf; 643 DocLnk nf;
639 nf.setType("text/plain"); 644 nf.setType("text/plain");
640 nf.setFile(f); 645 nf.setFile(f);
641 currentFileName=f; 646 currentFileName=f;
642 QFileInfo fi( currentFileName); 647 QFileInfo fi( currentFileName);
643 nf.setName(fi.baseName()); 648 nf.setName(fi.baseName());
644 qDebug("openFile string"+currentFileName); 649 qDebug("openFile string"+currentFileName);
645 650
646 openFile(nf); 651 openFile(nf);
647 showEditTools(); 652 showEditTools();
648 // Show filename in caption 653 // Show filename in caption
649 QString name = f; 654 QString name = f;
650 int sep = name.findRev( '/' ); 655 int sep = name.findRev( '/' );
651 if ( sep > 0 ) 656 if ( sep > 0 )
652 name = name.mid( sep+1 ); 657 name = name.mid( sep+1 );
653 updateCaption( name ); 658 updateCaption( name );
654} 659}
655 660
656void TextEdit::openFile( const DocLnk &f ) 661void TextEdit::openFile( const DocLnk &f )
657{ 662{
658// clear(); 663// clear();
659// bFromDocView = TRUE; 664// bFromDocView = TRUE;
660 FileManager fm; 665 FileManager fm;
661 QString txt; 666 QString txt;
662 currentFileName=f.name(); 667 currentFileName=f.name();
663 qDebug("openFile doclnk " + currentFileName); 668 qDebug("openFile doclnk " + currentFileName);
664 if ( !fm.loadFile( f, txt ) ) { 669 if ( !fm.loadFile( f, txt ) ) {
665 // ####### could be a new file 670 // ####### could be a new file
666 qDebug( "Cannot open file" ); 671 qDebug( "Cannot open file" );
667 } 672 }
668// fileNew(); 673// fileNew();
669 if ( doc ) 674 if ( doc )
670 delete doc; 675 delete doc;
671 doc = new DocLnk(f); 676 doc = new DocLnk(f);
672 editor->setText(txt); 677 editor->setText(txt);
673 editor->setEdited( FALSE); 678 editor->setEdited( FALSE);
674 edited1=FALSE; 679 edited1=FALSE;
675 edited=FALSE; 680 edited=FALSE;
676 681
677 doc->setName(currentFileName); 682 doc->setName(currentFileName);
678 updateCaption(); 683 updateCaption();
679} 684}
680 685
681void TextEdit::showEditTools() 686void TextEdit::showEditTools()
682{ 687{
683// if ( !doc ) 688// if ( !doc )
684// close(); 689// close();
685// clear(); 690// clear();
686 menu->show(); 691 menu->show();
687 editBar->show(); 692 editBar->show();
688 if ( searchVisible ) 693 if ( searchVisible )
689 searchBar->show(); 694 searchBar->show();
690// updateCaption(); 695// updateCaption();
691 setWState (WState_Reserved1 ); 696 setWState (WState_Reserved1 );
692} 697}
693 698
694/*! 699/*!
695 unprompted save */ 700 unprompted save */
696bool TextEdit::save() 701bool TextEdit::save()
697{ 702{
698 QString file = doc->file(); 703 QString file = doc->file();
699 qDebug("saver file "+file); 704 qDebug("saver file "+file);
700 QString name= doc->name(); 705 QString name= doc->name();
701 qDebug("File named "+name); 706 qDebug("File named "+name);
702 QString rt = editor->text(); 707 QString rt = editor->text();
703 if( !rt.isEmpty() ) { 708 if( !rt.isEmpty() ) {
704 if(name.isEmpty()) { 709 if(name.isEmpty()) {
705 saveAs(); 710 saveAs();
706 } else { 711 } else {
707 currentFileName= name ; 712 currentFileName= name ;
708 qDebug("saveFile "+currentFileName); 713 qDebug("saveFile "+currentFileName);
709 714
710 struct stat buf; 715 struct stat buf;
711 mode_t mode; 716 mode_t mode;
712 stat(file.latin1(), &buf); 717 stat(file.latin1(), &buf);
713 mode = buf.st_mode; 718 mode = buf.st_mode;
714 719
715 doc->setName( name); 720 doc->setName( name);
716 FileManager fm; 721 FileManager fm;
717 if ( !fm.saveFile( *doc, rt ) ) { 722 if ( !fm.saveFile( *doc, rt ) ) {
718 return false; 723 return false;
719 } 724 }
720 editor->setEdited( FALSE); 725 editor->setEdited( FALSE);
721 edited1=FALSE; 726 edited1=FALSE;
722 edited=FALSE; 727 edited=FALSE;
723 if(caption().left(1)=="*") 728 if(caption().left(1)=="*")
724 setCaption(caption().right(caption().length()-1)); 729 setCaption(caption().right(caption().length()-1));
725 730
726 731
727 chmod( file.latin1(), mode); 732 chmod( file.latin1(), mode);
728 } 733 }
729 return true; 734 return true;
730 } 735 }
731 return false; 736 return false;
732} 737}
733 738
734/*! 739/*!
735 prompted save */ 740 prompted save */
736bool TextEdit::saveAs() 741bool TextEdit::saveAs()
737{ 742{
738// qDebug("saveAsFile "+currentFileName); 743// qDebug("saveAsFile "+currentFileName);
739 // case of nothing to save... 744 // case of nothing to save...
740 if ( !doc )//|| !bFromDocView) 745 if ( !doc )//|| !bFromDocView)
741 { 746 {
742 qDebug("no doc"); 747 qDebug("no doc");
743 return true; 748 return true;
744 } 749 }
745 if ( !editor->edited() ) { 750 if ( !editor->edited() ) {
746 delete doc; 751 delete doc;
747 doc = 0; 752 doc = 0;
748 return true; 753 return true;
749 } 754 }
750 755
751 QString rt = editor->text(); 756 QString rt = editor->text();
752 qDebug(currentFileName); 757 qDebug(currentFileName);
753 758
754 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { 759 if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) {
755 qDebug("do silly TT filename thing"); 760 qDebug("do silly TT filename thing");
756 if ( doc->name().isEmpty() ) { 761 if ( doc->name().isEmpty() ) {
757 QString pt = rt.simplifyWhiteSpace(); 762 QString pt = rt.simplifyWhiteSpace();
758 int i = pt.find( ' ' ); 763 int i = pt.find( ' ' );
759 QString docname = pt; 764 QString docname = pt;
760 if ( i > 0 ) 765 if ( i > 0 )
761 docname = pt.left( i ); 766 docname = pt.left( i );
762 // remove "." at the beginning 767 // remove "." at the beginning
763 while( docname.startsWith( "." ) ) 768 while( docname.startsWith( "." ) )
764 docname = docname.mid( 1 ); 769 docname = docname.mid( 1 );
765 docname.replace( QRegExp("/"), "_" ); 770 docname.replace( QRegExp("/"), "_" );
766 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. 771 // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long.
767 if ( docname.length() > 40 ) 772 if ( docname.length() > 40 )
768 docname = docname.left(40); 773 docname = docname.left(40);
769 if ( docname.isEmpty() ) 774 if ( docname.isEmpty() )
770 docname = tr("Unnamed"); 775 docname = tr("Unnamed");
771 doc->setName(docname); 776 doc->setName(docname);
772 currentFileName=docname; 777 currentFileName=docname;
773 } 778 }
774 } 779 }
775 780
776 781
777 fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName); 782 fileSaveDlg=new fileSaver(this,tr("Save File As?"),TRUE, 0, currentFileName);
778 qDebug("wanna save filename "+currentFileName); 783 qDebug("wanna save filename "+currentFileName);
779 fileSaveDlg->exec(); 784 fileSaveDlg->exec();
780 if( fileSaveDlg->result() == 1 ) { 785 if( fileSaveDlg->result() == 1 ) {
781 QString fileNm=fileSaveDlg->selectedFileName; 786 QString fileNm=fileSaveDlg->selectedFileName;
782 qDebug("saving filename "+fileNm); 787 qDebug("saving filename "+fileNm);
783 QFileInfo fi(fileNm); 788 QFileInfo fi(fileNm);
784 currentFileName=fi.fileName(); 789 currentFileName=fi.fileName();
785 if(doc) { 790 if(doc) {
786// QString file = doc->file(); 791// QString file = doc->file();
787// doc->removeFiles(); 792// doc->removeFiles();
788 delete doc; 793 delete doc;
789 DocLnk nf; 794 DocLnk nf;
790 nf.setType("text/plain"); 795 nf.setType("text/plain");
791 nf.setFile( fileNm); 796 nf.setFile( fileNm);
792 doc = new DocLnk(nf); 797 doc = new DocLnk(nf);
793// editor->setText(rt); 798// editor->setText(rt);
794// qDebug("openFile doclnk "+currentFileName); 799// qDebug("openFile doclnk "+currentFileName);
795 doc->setName( currentFileName); 800 doc->setName( currentFileName);
796 updateCaption( currentFileName); 801 updateCaption( currentFileName);
797 802
798 FileManager fm; 803 FileManager fm;
799 if ( !fm.saveFile( *doc, rt ) ) { 804 if ( !fm.saveFile( *doc, rt ) ) {
800 return false; 805 return false;
801 } 806 }
802 if( fileSaveDlg->filePermCheck->isChecked() ) { 807 if( fileSaveDlg->filePermCheck->isChecked() ) {
803 filePermissions *filePerm; 808 filePermissions *filePerm;
804 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); 809 filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm);
805 filePerm->exec(); 810 filePerm->exec();
806 811
807 if( filePerm) 812 if( filePerm)
808 delete filePerm; 813 delete filePerm;
809 } 814 }
810 } 815 }
811 } 816 }
812 editor->setEdited(TRUE); 817 editor->setEdited(TRUE);
813 edited1=FALSE; 818 edited1=FALSE;
814 edited=TRUE; 819 edited=TRUE;
815 if(caption().left(1)=="*") 820 if(caption().left(1)=="*")
816 setCaption(caption().right(caption().length()-1)); 821 setCaption(caption().right(caption().length()-1));
817 822
818 if(fileSaveDlg) 823 if(fileSaveDlg)
819 delete fileSaveDlg; 824 delete fileSaveDlg;
820 return true; 825 return true;
821} //end saveAs 826} //end saveAs
822 827
823void TextEdit::clear() 828void TextEdit::clear()
824{ 829{
825 delete doc; 830 delete doc;
826 doc = 0; 831 doc = 0;
827 editor->clear(); 832 editor->clear();
828} 833}
829 834
830void TextEdit::updateCaption( const QString &name ) 835void TextEdit::updateCaption( const QString &name )
831{ 836{
832 if ( !doc ) 837 if ( !doc )
833 setCaption( tr("Text Editor") ); 838 setCaption( tr("Text Editor") );
834 else { 839 else {
835 QString s = name; 840 QString s = name;
836 if ( s.isNull() ) 841 if ( s.isNull() )
837 s = doc->name(); 842 s = doc->name();
838 if ( s.isEmpty() ) { 843 if ( s.isEmpty() ) {
839 s = tr( "Unnamed" ); 844 s = tr( "Unnamed" );
840 currentFileName=s; 845 currentFileName=s;
841 } 846 }
842 if(s.left(1) == "/") 847 if(s.left(1) == "/")
843 s = s.right(s.length()-1); 848 s = s.right(s.length()-1);
844 setCaption( s + " - " + tr("Text Editor") ); 849 setCaption( s + " - " + tr("Text Editor") );
845 } 850 }
846} 851}
847 852
848void TextEdit::setDocument(const QString& fileref) 853void TextEdit::setDocument(const QString& fileref)
849{ 854{
850 bFromDocView = TRUE; 855 bFromDocView = TRUE;
851 if(fileref.find(".desktop",0,TRUE) == -1) { 856 if(fileref.find(".desktop",0,TRUE) == -1) {
852 openFile(fileref); 857 openFile(fileref);
853 } else { 858 } else {
854 qDebug("is desktop file"); 859 qDebug("is desktop file");
855 openFile(DocLnk(fileref)); 860 openFile(DocLnk(fileref));
856 } 861 }
857 editor->setEdited(TRUE); 862 editor->setEdited(TRUE);
858 edited1=FALSE; 863 edited1=FALSE;
859 edited=TRUE; 864 edited=TRUE;
860 doSearchBar(); 865 doSearchBar();
861} 866}
862 867
863void TextEdit::closeEvent( QCloseEvent *e ) 868void TextEdit::closeEvent( QCloseEvent *e )
864{ 869{
865 bFromDocView = FALSE; 870 bFromDocView = FALSE;
866 e->accept(); 871 e->accept();
867} 872}
868 873
869void TextEdit::accept() 874void TextEdit::accept()
870 { 875 {
871 //if(caption() !="Unnamed") 876 //if(caption() !="Unnamed")
872 if(edited1) 877 if(edited1)
873 saveAs(); 878 saveAs();
874 exit(0); 879 exit(0);
875 880
876} 881}
877 882
878void TextEdit::changeFont() { 883void TextEdit::changeFont() {
879 FontDatabase fdb; 884 FontDatabase fdb;
880 QFont defaultFont=editor->font(); 885 QFont defaultFont=editor->font();
881 QFontInfo fontInfo(defaultFont); 886 QFontInfo fontInfo(defaultFont);
882 Config cfg("TextEdit"); 887 Config cfg("TextEdit");
883 cfg.setGroup("Font"); 888 cfg.setGroup("Font");
884 QString family = cfg.readEntry("Family", fontInfo.family()); 889 QString family = cfg.readEntry("Family", fontInfo.family());
885 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); 890 QString style = cfg.readEntry("Style", fdb.styleString(defaultFont));
886 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); 891 int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10);
887 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); 892 QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) );
888 893
889 defaultFont = fdb.font(family,style,i_size,charSet); 894 defaultFont = fdb.font(family,style,i_size,charSet);
890 895
891 FontDialog *fontDlg; 896 FontDialog *fontDlg;
892 fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); 897 fontDlg=new FontDialog(this,tr("FontDialog"),TRUE);
893 898
894 fontDlg->exec(); 899 fontDlg->exec();
895 900
896 QFont myFont=fontDlg->selectedFont; 901 QFont myFont=fontDlg->selectedFont;
897 editor->setFont( myFont); 902 editor->setFont( myFont);
898 delete fontDlg; 903 delete fontDlg;
899 904
900} 905}
901 906
902void TextEdit::editDelete() 907void TextEdit::editDelete()
903{ 908{
904 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) ) { 909 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) ) {
905 case 0: 910 case 0:
906 if(doc) { 911 if(doc) {
907 doc->removeFiles(); 912 doc->removeFiles();
908 clear(); 913 clear();
909 setCaption( tr("Text Editor") ); 914 setCaption( tr("Text Editor") );
910 } 915 }
911 break; 916 break;
912 case 1: 917 case 1:
913 // exit 918 // exit
914 break; 919 break;
915 }; 920 };
916} 921}
917 922
918void TextEdit::changeStartConfig( bool b ) { 923void TextEdit::changeStartConfig( bool b ) {
919 924
920 Config cfg("TextEdit"); 925 Config cfg("TextEdit");
921 cfg.setGroup("View"); 926 cfg.setGroup("View");
922 if(b) { 927 if(b) {
923 qDebug("bool"); 928 qDebug("bool");
924 cfg.writeEntry("startNew","TRUE"); 929 cfg.writeEntry("startNew","TRUE");
925 } else { 930 } else {
926 cfg.writeEntry("startNew","FALSE"); 931 cfg.writeEntry("startNew","FALSE");
927 } 932 }
928 update(); 933 update();
929} 934}
930 935
931void TextEdit::editorChanged() { 936void TextEdit::editorChanged() {
932 if(editor->edited() && edited && !edited1) { 937 if(editor->edited() && edited && !edited1) {
933 setCaption( "*"+caption()); 938 setCaption( "*"+caption());
934 edited1=TRUE; 939 edited1=TRUE;
935 } 940 }
936 edited=TRUE; 941 edited=TRUE;
937} 942}
938 943
939void TextEdit::receive(const QCString&msg, const QByteArray&) { 944void TextEdit::receive(const QCString&msg, const QByteArray&) {
940 qDebug("QCop "+msg); 945 qDebug("QCop "+msg);
941 if ( msg == "setDocument(QString)" ) { 946 if ( msg == "setDocument(QString)" ) {
942 qDebug("bugger all"); 947 qDebug("bugger all");
943 } 948 }
944 949
945} 950}
diff --git a/core/apps/textedit/textedit.pro b/core/apps/textedit/textedit.pro
index fce76bd..aae7f89 100644
--- a/core/apps/textedit/textedit.pro
+++ b/core/apps/textedit/textedit.pro
@@ -1,24 +1,24 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 3
4DESTDIR = $(OPIEDIR)/bin 4DESTDIR = $(OPIEDIR)/bin
5HEADERS = textedit.h fileBrowser.h fontDialog.h fileSaver.h filePermissions.h 5HEADERS = textedit.h fileBrowser.h fontDialog.h fileSaver.h filePermissions.h
6SOURCES = main.cpp textedit.cpp fileBrowser.cpp fontDialog.cpp fileSaver.cpp filePermissions.cpp 6SOURCES = main.cpp textedit.cpp fileBrowser.cpp fontDialog.cpp fileSaver.cpp filePermissions.cpp
7 7
8INCLUDEPATH += $(OPIEDIR)/include 8INCLUDEPATH += $(OPIEDIR)/include
9DEPENDPATH += $(OPIEDIR)/include 9DEPENDPATH += $(OPIEDIR)/include
10LIBS += -lqpe 10LIBS += -lqpe -lopie
11 11
12TARGET = textedit 12TARGET = textedit
13 13
14TRANSLATIONS += ../i18n/de/textedit.ts 14TRANSLATIONS += ../i18n/de/textedit.ts
15TRANSLATIONS += ../i18n/pt_BR/textedit.ts 15TRANSLATIONS += ../i18n/pt_BR/textedit.ts
16TRANSLATIONS += ../i18n/en/textedit.ts 16TRANSLATIONS += ../i18n/en/textedit.ts
17TRANSLATIONS += ../i18n/hu/textedit.ts 17TRANSLATIONS += ../i18n/hu/textedit.ts
18TRANSLATIONS += ../i18n/fr/textedit.ts 18TRANSLATIONS += ../i18n/fr/textedit.ts
19TRANSLATIONS += ../i18n/ja/textedit.ts 19TRANSLATIONS += ../i18n/ja/textedit.ts
20TRANSLATIONS += ../i18n/sl/textedit.ts 20TRANSLATIONS += ../i18n/sl/textedit.ts
21TRANSLATIONS += ../i18n/ko/textedit.ts 21TRANSLATIONS += ../i18n/ko/textedit.ts
22TRANSLATIONS += ../i18n/no/textedit.ts 22TRANSLATIONS += ../i18n/no/textedit.ts
23TRANSLATIONS += ../i18n/zh_CN/textedit.ts 23TRANSLATIONS += ../i18n/zh_CN/textedit.ts
24TRANSLATIONS += ../i18n/zh_TW/textedit.ts 24TRANSLATIONS += ../i18n/zh_TW/textedit.ts