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