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