-rw-r--r-- | core/apps/textedit/textedit.cpp | 158 |
1 files changed, 67 insertions, 91 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 107695a..d61da2a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -238,767 +238,743 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
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 | 297 | ||
298 | #ifndef QT_NO_CLIPBOARD | 298 | #ifndef QT_NO_CLIPBOARD |
299 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); | 299 | a = new QAction( tr( "Insert Time and Date" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); |
300 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); | 300 | connect( a, SIGNAL( activated() ), this, SLOT( editPasteTimeDate() ) ); |
301 | a->addTo( edit ); | 301 | a->addTo( edit ); |
302 | #endif | 302 | #endif |
303 | 303 | ||
304 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 304 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
305 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 305 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
306 | edit->insertSeparator(); | 306 | edit->insertSeparator(); |
307 | a->addTo( bar ); | 307 | a->addTo( bar ); |
308 | a->addTo( edit ); | 308 | a->addTo( edit ); |
309 | 309 | ||
310 | int defsize; | 310 | int defsize; |
311 | bool defb, defi, wrap; | 311 | bool defb, defi, wrap; |
312 | 312 | ||
313 | Config cfg("TextEdit"); | 313 | Config cfg("TextEdit"); |
314 | cfg.setGroup("View"); | 314 | cfg.setGroup("View"); |
315 | defsize = cfg.readNumEntry("FontSize",10); | 315 | defsize = cfg.readNumEntry("FontSize",10); |
316 | defb = cfg.readBoolEntry("Bold",FALSE); | 316 | defb = cfg.readBoolEntry("Bold",FALSE); |
317 | defi = cfg.readBoolEntry("Italic",FALSE); | 317 | defi = cfg.readBoolEntry("Italic",FALSE); |
318 | wrap = cfg.readBoolEntry("Wrap",TRUE); | 318 | wrap = cfg.readBoolEntry("Wrap",TRUE); |
319 | 319 | ||
320 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); | 320 | zin = new QAction( tr("Zoom in"), QString::null, 0, this, 0 ); |
321 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); | 321 | connect( zin, SIGNAL( activated() ), this, SLOT( zoomIn() ) ); |
322 | zin->addTo( font ); | 322 | zin->addTo( font ); |
323 | 323 | ||
324 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); | 324 | zout = new QAction( tr("Zoom out"), QString::null, 0, this, 0 ); |
325 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); | 325 | connect( zout, SIGNAL( activated() ), this, SLOT( zoomOut() ) ); |
326 | zout->addTo( font ); | 326 | zout->addTo( font ); |
327 | 327 | ||
328 | font->insertSeparator(); | 328 | font->insertSeparator(); |
329 | 329 | ||
330 | #if 0 | 330 | #if 0 |
331 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); | 331 | QAction *ba = new QAction( tr("Bold"), QString::null, 0, this, 0 ); |
332 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); | 332 | connect( ba, SIGNAL( toggled(bool) ), this, SLOT( setBold(bool) ) ); |
333 | ba->setToggleAction(TRUE); | 333 | ba->setToggleAction(TRUE); |
334 | ba->addTo( font ); | 334 | ba->addTo( font ); |
335 | 335 | ||
336 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); | 336 | QAction *ia = new QAction( tr("Italic"), QString::null, 0, this, 0 ); |
337 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); | 337 | connect( ia, SIGNAL( toggled(bool) ), this, SLOT( setItalic(bool) ) ); |
338 | ia->setToggleAction(TRUE); | 338 | ia->setToggleAction(TRUE); |
339 | ia->addTo( font ); | 339 | ia->addTo( font ); |
340 | 340 | ||
341 | ba->setOn(defb); | 341 | ba->setOn(defb); |
342 | ia->setOn(defi); | 342 | ia->setOn(defi); |
343 | 343 | ||
344 | font->insertSeparator(); | 344 | font->insertSeparator(); |
345 | #endif | 345 | #endif |
346 | 346 | ||
347 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); | 347 | QAction *wa = new QAction( tr("Wrap lines"), QString::null, 0, this, 0 ); |
348 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); | 348 | connect( wa, SIGNAL( toggled(bool) ), this, SLOT( setWordWrap(bool) ) ); |
349 | wa->setToggleAction(TRUE); | 349 | wa->setToggleAction(TRUE); |
350 | wa->addTo( font ); | 350 | wa->addTo( font ); |
351 | 351 | ||
352 | font->insertSeparator(); | 352 | font->insertSeparator(); |
353 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); | 353 | font->insertItem(tr("Font"), this, SLOT(changeFont()) ); |
354 | 354 | ||
355 | font->insertSeparator(); | 355 | font->insertSeparator(); |
356 | 356 | ||
357 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); | 357 | nStart = new QAction( tr("Start with new file"), QString::null, 0, this, 0 ); |
358 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); | 358 | connect( nStart, SIGNAL( toggled(bool) ), this, SLOT( changeStartConfig(bool) ) ); |
359 | nStart->setToggleAction(TRUE); | 359 | nStart->setToggleAction(TRUE); |
360 | nStart->addTo( font ); | 360 | nStart->addTo( font ); |
361 | 361 | ||
362 | nAdvanced = new QAction( tr("Advanced features"), QString::null, 0, this, 0 ); | 362 | nAdvanced = new QAction( tr("Advanced features"), QString::null, 0, this, 0 ); |
363 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doAdvanced(bool) ) ); | 363 | connect( nAdvanced, SIGNAL( toggled(bool) ), this, SLOT( doAdvanced(bool) ) ); |
364 | nAdvanced->setToggleAction(TRUE); | 364 | nAdvanced->setToggleAction(TRUE); |
365 | nAdvanced->addTo( font ); | 365 | nAdvanced->addTo( font ); |
366 | if(cfg.readBoolEntry("AdvancedFeatures")) | 366 | |
367 | nAdvanced->setOn(TRUE); | 367 | if(cfg.readBoolEntry("AdvancedFeatures")) { |
368 | qDebug("using advanced features"); | ||
369 | useAdvancedFeatures = true; | ||
370 | nAdvanced->setOn(TRUE); | ||
371 | } else | ||
372 | useAdvancedFeatures = false; | ||
373 | |||
368 | font->insertSeparator(); | 374 | font->insertSeparator(); |
369 | 375 | ||
370 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); | 376 | font->insertItem(tr("About"), this, SLOT( doAbout()) ); |
371 | 377 | ||
372 | mb->insertItem( tr( "File" ), file ); | 378 | mb->insertItem( tr( "File" ), file ); |
373 | mb->insertItem( tr( "Edit" ), edit ); | 379 | mb->insertItem( tr( "Edit" ), edit ); |
374 | mb->insertItem( tr( "View" ), font ); | 380 | mb->insertItem( tr( "View" ), font ); |
375 | 381 | ||
376 | searchBar = new QPEToolBar(this); | 382 | searchBar = new QPEToolBar(this); |
377 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); | 383 | addToolBar( searchBar, "Search", QMainWindow::Top, TRUE ); |
378 | 384 | ||
379 | searchBar->setHorizontalStretchable( TRUE ); | 385 | searchBar->setHorizontalStretchable( TRUE ); |
380 | 386 | ||
381 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); | 387 | searchEdit = new QLineEdit( searchBar, "searchEdit" ); |
382 | searchBar->setStretchableWidget( searchEdit ); | 388 | searchBar->setStretchableWidget( searchEdit ); |
383 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), | 389 | connect( searchEdit, SIGNAL( textChanged( const QString & ) ), |
384 | this, SLOT( search() ) ); | 390 | this, SLOT( search() ) ); |
385 | 391 | ||
386 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 392 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
387 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 393 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
388 | a->addTo( searchBar ); | 394 | a->addTo( searchBar ); |
389 | a->addTo( edit ); | 395 | a->addTo( edit ); |
390 | 396 | ||
391 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 397 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
392 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 398 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
393 | a->addTo( searchBar ); | 399 | a->addTo( searchBar ); |
394 | 400 | ||
395 | edit->insertSeparator(); | 401 | edit->insertSeparator(); |
396 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 402 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
397 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 403 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
398 | a->addTo( edit ); | 404 | a->addTo( edit ); |
399 | 405 | ||
400 | searchBar->hide(); | 406 | searchBar->hide(); |
401 | 407 | ||
402 | editor = new QpeEditor( this ); | 408 | editor = new QpeEditor( this ); |
403 | setCentralWidget( editor ); | 409 | setCentralWidget( editor ); |
404 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 410 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
405 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 411 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); |
406 | 412 | ||
407 | // resize( 200, 300 ); | 413 | // resize( 200, 300 ); |
408 | 414 | ||
409 | // setFontSize(defsize,TRUE); | 415 | // setFontSize(defsize,TRUE); |
410 | FontDatabase fdb; | 416 | FontDatabase fdb; |
411 | QFont defaultFont=editor->font(); | 417 | QFont defaultFont=editor->font(); |
412 | QFontInfo fontInfo(defaultFont); | 418 | QFontInfo fontInfo(defaultFont); |
413 | 419 | ||
414 | cfg.setGroup("Font"); | 420 | cfg.setGroup("Font"); |
415 | QString family = cfg.readEntry("Family", fontInfo.family()); | 421 | QString family = cfg.readEntry("Family", fontInfo.family()); |
416 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 422 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
417 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 423 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
418 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 424 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
419 | 425 | ||
420 | defaultFont = fdb.font(family,style,i_size,charSet); | 426 | defaultFont = fdb.font(family,style,i_size,charSet); |
421 | editor->setFont( defaultFont); | 427 | editor->setFont( defaultFont); |
422 | 428 | ||
423 | wa->setOn(wrap); | 429 | wa->setOn(wrap); |
424 | updateCaption(); | 430 | updateCaption(); |
425 | 431 | ||
426 | cfg.setGroup("View"); | 432 | cfg.setGroup("View"); |
427 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { | 433 | if(cfg.readEntry("startNew","TRUE") == "TRUE") { |
428 | nStart->setOn(TRUE); | 434 | nStart->setOn(TRUE); |
429 | fileNew(); | 435 | fileNew(); |
430 | } else { | 436 | } else { |
431 | fileOpen(); | 437 | fileOpen(); |
432 | } | 438 | } |
433 | 439 | ||
434 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | 440 | viewSelection = cfg.readNumEntry( "FileView", 0 ); |
435 | } | 441 | } |
436 | 442 | ||
437 | void TextEdit::cleanUp() | 443 | TextEdit::~TextEdit() { |
438 | { | 444 | } |
445 | |||
446 | void TextEdit::cleanUp() { | ||
439 | // save(); | 447 | // save(); |
440 | Config cfg("TextEdit"); | 448 | Config cfg("TextEdit"); |
441 | cfg.setGroup("View"); | 449 | cfg.setGroup("View"); |
442 | QFont f = editor->font(); | 450 | QFont f = editor->font(); |
443 | cfg.writeEntry("FontSize",f.pointSize()); | 451 | cfg.writeEntry("FontSize",f.pointSize()); |
444 | cfg.writeEntry("Bold",f.bold()); | 452 | cfg.writeEntry("Bold",f.bold()); |
445 | cfg.writeEntry("Italic",f.italic()); | 453 | cfg.writeEntry("Italic",f.italic()); |
446 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 454 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
447 | cfg.writeEntry( "FileView", viewSelection ); | 455 | cfg.writeEntry( "FileView", viewSelection ); |
448 | |||
449 | } | 456 | } |
450 | 457 | ||
451 | TextEdit::~TextEdit() | 458 | |
452 | { | 459 | void TextEdit::accept() { |
460 | if(edited1) | ||
461 | saveAs(); | ||
462 | exit(0); | ||
453 | } | 463 | } |
454 | 464 | ||
455 | void TextEdit::zoomIn() | 465 | void TextEdit::zoomIn() { |
456 | { | ||
457 | setFontSize(editor->font().pointSize()+1,FALSE); | 466 | setFontSize(editor->font().pointSize()+1,FALSE); |
458 | } | 467 | } |
459 | 468 | ||
460 | void TextEdit::zoomOut() | 469 | void TextEdit::zoomOut() { |
461 | { | ||
462 | setFontSize(editor->font().pointSize()-1,TRUE); | 470 | setFontSize(editor->font().pointSize()-1,TRUE); |
463 | } | 471 | } |
464 | 472 | ||
465 | 473 | ||
466 | void TextEdit::setFontSize(int sz, bool round_down_not_up) | 474 | void TextEdit::setFontSize(int sz, bool round_down_not_up) { |
467 | { | ||
468 | int s=10; | 475 | int s=10; |
469 | for (int i=0; i<nfontsizes; i++) { | 476 | for (int i=0; i<nfontsizes; i++) { |
470 | if ( fontsize[i] == sz ) { | 477 | if ( fontsize[i] == sz ) { |
471 | s = sz; | 478 | s = sz; |
472 | break; | 479 | break; |
473 | } else if ( round_down_not_up ) { | 480 | } else if ( round_down_not_up ) { |
474 | if ( fontsize[i] < sz ) | 481 | if ( fontsize[i] < sz ) |
475 | s = fontsize[i]; | 482 | s = fontsize[i]; |
476 | } else { | 483 | } else { |
477 | if ( fontsize[i] > sz ) { | 484 | if ( fontsize[i] > sz ) { |
478 | s = fontsize[i]; | 485 | s = fontsize[i]; |
479 | break; | 486 | break; |
480 | } | 487 | } |
481 | } | 488 | } |
482 | } | 489 | } |
483 | 490 | ||
484 | QFont f = editor->font(); | 491 | QFont f = editor->font(); |
485 | f.setPointSize(s); | 492 | f.setPointSize(s); |
486 | editor->setFont(f); | 493 | editor->setFont(f); |
487 | 494 | ||
488 | zin->setEnabled(s != fontsize[nfontsizes-1]); | 495 | zin->setEnabled(s != fontsize[nfontsizes-1]); |
489 | zout->setEnabled(s != fontsize[0]); | 496 | zout->setEnabled(s != fontsize[0]); |
490 | } | 497 | } |
491 | 498 | ||
492 | void TextEdit::setBold(bool y) | 499 | void TextEdit::setBold(bool y) { |
493 | { | ||
494 | QFont f = editor->font(); | 500 | QFont f = editor->font(); |
495 | f.setBold(y); | 501 | f.setBold(y); |
496 | editor->setFont(f); | 502 | editor->setFont(f); |
497 | } | 503 | } |
498 | 504 | ||
499 | void TextEdit::setItalic(bool y) | 505 | void TextEdit::setItalic(bool y) { |
500 | { | ||
501 | QFont f = editor->font(); | 506 | QFont f = editor->font(); |
502 | f.setItalic(y); | 507 | f.setItalic(y); |
503 | editor->setFont(f); | 508 | editor->setFont(f); |
504 | } | 509 | } |
505 | 510 | ||
506 | void TextEdit::setWordWrap(bool y) | 511 | void TextEdit::setWordWrap(bool y) { |
507 | { | ||
508 | bool state = editor->edited(); | 512 | bool state = editor->edited(); |
509 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 513 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
510 | editor->setEdited( state ); | 514 | editor->setEdited( state ); |
511 | } | 515 | } |
512 | 516 | ||
513 | void TextEdit::fileNew() | 517 | void TextEdit::fileNew() { |
514 | { | ||
515 | // if( !bFromDocView ) { | 518 | // if( !bFromDocView ) { |
516 | // saveAs(); | 519 | // saveAs(); |
517 | // } | 520 | // } |
518 | newFile(DocLnk()); | 521 | newFile(DocLnk()); |
519 | } | 522 | } |
520 | 523 | ||
521 | void TextEdit::fileOpen() | 524 | void TextEdit::fileOpen() { |
522 | { | ||
523 | Config cfg("TextEdit"); | 525 | Config cfg("TextEdit"); |
524 | cfg.setGroup("View"); | 526 | cfg.setGroup("View"); |
525 | // bool b=FALSE; | 527 | // bool b=FALSE; |
526 | 528 | ||
527 | QMap<QString, QStringList> map; | 529 | QMap<QString, QStringList> map; |
528 | map.insert(tr("All"), QStringList() ); | 530 | map.insert(tr("All"), QStringList() ); |
529 | QStringList text; | 531 | QStringList text; |
530 | text << "text/*"; | 532 | text << "text/*"; |
531 | map.insert(tr("Text"), text ); | 533 | map.insert(tr("Text"), text ); |
532 | text << "*"; | 534 | text << "*"; |
533 | map.insert(tr("All"), text ); | 535 | map.insert(tr("All"), text ); |
534 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); | 536 | QString str = OFileDialog::getOpenFileName( 2,"/", QString::null, map); |
535 | if(!str.isEmpty() ) | 537 | if(!str.isEmpty() ) |
536 | openFile( str ); | 538 | openFile( str ); |
537 | 539 | ||
538 | } | 540 | } |
539 | 541 | ||
540 | void TextEdit::doSearchBar() | 542 | void TextEdit::doSearchBar() { |
541 | { | ||
542 | Config cfg("TextEdit"); | 543 | Config cfg("TextEdit"); |
543 | cfg.setGroup("View"); | 544 | cfg.setGroup("View"); |
544 | if(cfg.readEntry("SearchBar","Closed") != "Opened") | 545 | if(cfg.readEntry("SearchBar","Closed") != "Opened") |
545 | searchBar->hide(); | 546 | searchBar->hide(); |
546 | } | 547 | } |
547 | 548 | ||
548 | #if 0 | 549 | #if 0 |
549 | void TextEdit::slotFind() | 550 | void TextEdit::slotFind() { |
550 | { | ||
551 | FindDialog frmFind( tr("Text Editor"), this ); | 551 | FindDialog frmFind( tr("Text Editor"), this ); |
552 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), | 552 | connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), |
553 | editor, SLOT(slotDoFind( const QString&,bool,bool))); | 553 | editor, SLOT(slotDoFind( const QString&,bool,bool))); |
554 | 554 | ||
555 | //case sensitive, backwards, [category] | 555 | //case sensitive, backwards, [category] |
556 | 556 | ||
557 | connect( editor, SIGNAL(notFound()), | 557 | connect( editor, SIGNAL(notFound()), |
558 | &frmFind, SLOT(slotNotFound()) ); | 558 | &frmFind, SLOT(slotNotFound()) ); |
559 | connect( editor, SIGNAL(searchWrapped()), | 559 | connect( editor, SIGNAL(searchWrapped()), |
560 | &frmFind, SLOT(slotWrapAround()) ); | 560 | &frmFind, SLOT(slotWrapAround()) ); |
561 | 561 | ||
562 | frmFind.exec(); | 562 | frmFind.exec(); |
563 | 563 | ||
564 | 564 | ||
565 | } | 565 | } |
566 | #endif | 566 | #endif |
567 | 567 | ||
568 | void TextEdit::fileRevert() | 568 | void TextEdit::fileRevert() { |
569 | { | ||
570 | clear(); | 569 | clear(); |
571 | fileOpen(); | 570 | fileOpen(); |
572 | } | 571 | } |
573 | 572 | ||
574 | void TextEdit::editCut() | 573 | void TextEdit::editCut() { |
575 | { | ||
576 | #ifndef QT_NO_CLIPBOARD | 574 | #ifndef QT_NO_CLIPBOARD |
577 | editor->cut(); | 575 | editor->cut(); |
578 | #endif | 576 | #endif |
579 | } | 577 | } |
580 | 578 | ||
581 | void TextEdit::editCopy() | 579 | void TextEdit::editCopy() { |
582 | { | ||
583 | #ifndef QT_NO_CLIPBOARD | 580 | #ifndef QT_NO_CLIPBOARD |
584 | editor->copy(); | 581 | editor->copy(); |
585 | #endif | 582 | #endif |
586 | } | 583 | } |
587 | 584 | ||
588 | void TextEdit::editPaste() | 585 | void TextEdit::editPaste() { |
589 | { | ||
590 | #ifndef QT_NO_CLIPBOARD | 586 | #ifndef QT_NO_CLIPBOARD |
591 | editor->paste(); | 587 | editor->paste(); |
592 | #endif | 588 | #endif |
593 | } | 589 | } |
594 | 590 | ||
595 | void TextEdit::editFind() | 591 | void TextEdit::editFind() { |
596 | { | ||
597 | searchBar->show(); | 592 | searchBar->show(); |
598 | searchVisible = TRUE; | 593 | searchVisible = TRUE; |
599 | searchEdit->setFocus(); | 594 | searchEdit->setFocus(); |
600 | Config cfg("TextEdit"); | 595 | Config cfg("TextEdit"); |
601 | cfg.setGroup("View"); | 596 | cfg.setGroup("View"); |
602 | cfg.writeEntry("SearchBar","Opened"); | 597 | cfg.writeEntry("SearchBar","Opened"); |
603 | 598 | ||
604 | } | 599 | } |
605 | 600 | ||
606 | void TextEdit::findNext() | 601 | void TextEdit::findNext() { |
607 | { | ||
608 | editor->find( searchEdit->text(), FALSE, FALSE ); | 602 | editor->find( searchEdit->text(), FALSE, FALSE ); |
609 | 603 | ||
610 | } | 604 | } |
611 | 605 | ||
612 | void TextEdit::findClose() | 606 | void TextEdit::findClose() { |
613 | { | ||
614 | searchVisible = FALSE; | 607 | searchVisible = FALSE; |
615 | searchBar->hide(); | 608 | searchBar->hide(); |
616 | Config cfg("TextEdit"); | 609 | Config cfg("TextEdit"); |
617 | cfg.setGroup("View"); | 610 | cfg.setGroup("View"); |
618 | cfg.writeEntry("SearchBar","Closed"); | 611 | cfg.writeEntry("SearchBar","Closed"); |
619 | cfg.write(); | 612 | cfg.write(); |
620 | } | 613 | } |
621 | 614 | ||
622 | void TextEdit::search() | 615 | void TextEdit::search() { |
623 | { | ||
624 | editor->find( searchEdit->text(), FALSE, FALSE ); | 616 | editor->find( searchEdit->text(), FALSE, FALSE ); |
625 | } | 617 | } |
626 | 618 | ||
627 | void TextEdit::newFile( const DocLnk &f ) | 619 | void TextEdit::newFile( const DocLnk &f ) { |
628 | { | ||
629 | DocLnk nf = f; | 620 | DocLnk nf = f; |
630 | nf.setType("text/plain"); | 621 | nf.setType("text/plain"); |
631 | clear(); | 622 | clear(); |
632 | setWState (WState_Reserved1 ); | 623 | setWState (WState_Reserved1 ); |
633 | editor->setFocus(); | 624 | editor->setFocus(); |
634 | doc = new DocLnk(nf); | 625 | doc = new DocLnk(nf); |
635 | currentFileName = "Unnamed"; | 626 | currentFileName = "Unnamed"; |
636 | qDebug("newFile "+currentFileName); | 627 | qDebug("newFile "+currentFileName); |
637 | updateCaption( currentFileName); | 628 | updateCaption( currentFileName); |
638 | // editor->setEdited( FALSE); | 629 | // editor->setEdited( FALSE); |
639 | } | 630 | } |
640 | 631 | ||
641 | void TextEdit::openFile( const QString &f ) | 632 | void TextEdit::openFile( const QString &f ) { |
642 | { | ||
643 | qDebug("filename is "+ f); | 633 | qDebug("filename is "+ f); |
644 | QString filer; | 634 | QString filer; |
645 | // bFromDocView = TRUE; | 635 | // bFromDocView = TRUE; |
646 | if(f.find(".desktop",0,TRUE) != -1 && useAdvancedFeatures) { | 636 | if(f.find(".desktop",0,TRUE) != -1 && useAdvancedFeatures) { |
647 | switch ( QMessageBox::warning(this,tr("Text Editor"), | 637 | switch ( QMessageBox::warning(this,tr("Text Editor"), |
648 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), | 638 | tr("Text Editor has detected\n you selected a .desktop file.\nOpen .desktop file or linked file?"), |
649 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { | 639 | tr(".desktop File"),tr("Linked Document"),0,1,1) ) { |
650 | case 0: | 640 | case 0: |
651 | filer = f; | 641 | filer = f; |
652 | break; | 642 | break; |
653 | case 1: | 643 | case 1: |
654 | DocLnk sf(f); | 644 | DocLnk sf(f); |
655 | filer = sf.file(); | 645 | filer = sf.file(); |
656 | break; | 646 | break; |
657 | } | 647 | } |
658 | } else { | 648 | } else { |
659 | filer = f; | 649 | filer = f; |
660 | fileIs = TRUE; | 650 | fileIs = TRUE; |
661 | } | 651 | } |
662 | 652 | ||
663 | DocLnk nf; | 653 | DocLnk nf; |
664 | nf.setType("text/plain"); | 654 | nf.setType("text/plain"); |
665 | nf.setFile(filer); | 655 | nf.setFile(filer); |
666 | currentFileName=filer; | 656 | currentFileName=filer; |
667 | QFileInfo fi( currentFileName); | 657 | QFileInfo fi( currentFileName); |
668 | nf.setName(fi.baseName()); | 658 | nf.setName(fi.baseName()); |
669 | qDebug("openFile string "+currentFileName); | 659 | qDebug("openFile string "+currentFileName); |
670 | 660 | ||
671 | openFile(nf); | 661 | openFile(nf); |
672 | showEditTools(); | 662 | showEditTools(); |
673 | // Show filename in caption | 663 | // Show filename in caption |
674 | QString name = filer; | 664 | QString name = filer; |
675 | int sep = name.findRev( '/' ); | 665 | int sep = name.findRev( '/' ); |
676 | if ( sep > 0 ) | 666 | if ( sep > 0 ) |
677 | name = name.mid( sep+1 ); | 667 | name = name.mid( sep+1 ); |
678 | updateCaption( name ); | 668 | updateCaption( name ); |
679 | } | 669 | } |
680 | 670 | ||
681 | void TextEdit::openFile( const DocLnk &f ) | 671 | void TextEdit::openFile( const DocLnk &f ) { |
682 | { | ||
683 | // clear(); | 672 | // clear(); |
684 | // bFromDocView = TRUE; | 673 | // bFromDocView = TRUE; |
685 | FileManager fm; | 674 | FileManager fm; |
686 | QString txt; | 675 | QString txt; |
687 | currentFileName=f.file(); | 676 | currentFileName=f.file(); |
688 | qDebug("openFile doclnk " + currentFileName); | 677 | qDebug("openFile doclnk " + currentFileName); |
689 | if ( !fm.loadFile( f, txt ) ) { | 678 | if ( !fm.loadFile( f, txt ) ) { |
690 | // ####### could be a new file | 679 | // ####### could be a new file |
691 | qDebug( "Cannot open file" ); | 680 | qDebug( "Cannot open file" ); |
692 | } | 681 | } |
693 | // fileNew(); | 682 | // fileNew(); |
694 | if ( doc ) | 683 | if ( doc ) |
695 | delete doc; | 684 | delete doc; |
696 | doc = new DocLnk(f); | 685 | doc = new DocLnk(f); |
697 | editor->setText(txt); | 686 | editor->setText(txt); |
698 | editor->setEdited( FALSE); | 687 | editor->setEdited( FALSE); |
699 | edited1=FALSE; | 688 | edited1=FALSE; |
700 | edited=FALSE; | 689 | edited=FALSE; |
701 | 690 | ||
702 | doc->setName(currentFileName); | 691 | doc->setName(currentFileName); |
703 | updateCaption(); | 692 | updateCaption(); |
704 | } | 693 | } |
705 | 694 | ||
706 | void TextEdit::showEditTools() | 695 | void TextEdit::showEditTools() { |
707 | { | ||
708 | // if ( !doc ) | 696 | // if ( !doc ) |
709 | // close(); | 697 | // close(); |
710 | // clear(); | 698 | // clear(); |
711 | menu->show(); | 699 | menu->show(); |
712 | editBar->show(); | 700 | editBar->show(); |
713 | if ( searchVisible ) | 701 | if ( searchVisible ) |
714 | searchBar->show(); | 702 | searchBar->show(); |
715 | // updateCaption(); | 703 | // updateCaption(); |
716 | setWState (WState_Reserved1 ); | 704 | setWState (WState_Reserved1 ); |
717 | } | 705 | } |
718 | 706 | ||
719 | /*! | 707 | /*! |
720 | unprompted save */ | 708 | unprompted save */ |
721 | bool TextEdit::save() | 709 | bool TextEdit::save() { |
722 | { | ||
723 | QString file = doc->file(); | 710 | QString file = doc->file(); |
724 | qDebug("saver file "+file); | 711 | qDebug("saver file "+file); |
725 | QString name= doc->name(); | 712 | QString name= doc->name(); |
726 | qDebug("File named "+name); | 713 | qDebug("File named "+name); |
727 | QString rt = editor->text(); | 714 | QString rt = editor->text(); |
728 | if( !rt.isEmpty() ) { | 715 | if( !rt.isEmpty() ) { |
729 | if(name.isEmpty()) { | 716 | if(name.isEmpty()) { |
730 | saveAs(); | 717 | saveAs(); |
731 | } else { | 718 | } else { |
732 | currentFileName= name ; | 719 | currentFileName= name ; |
733 | qDebug("saveFile "+currentFileName); | 720 | qDebug("saveFile "+currentFileName); |
734 | 721 | ||
735 | struct stat buf; | 722 | struct stat buf; |
736 | mode_t mode; | 723 | mode_t mode; |
737 | stat(file.latin1(), &buf); | 724 | stat(file.latin1(), &buf); |
738 | mode = buf.st_mode; | 725 | mode = buf.st_mode; |
739 | 726 | ||
740 | if(!fileIs) { | 727 | if(!fileIs) { |
741 | doc->setName( name); | 728 | doc->setName( name); |
742 | FileManager fm; | 729 | FileManager fm; |
743 | if ( !fm.saveFile( *doc, rt ) ) { | 730 | if ( !fm.saveFile( *doc, rt ) ) { |
744 | return false; | 731 | return false; |
745 | } | 732 | } |
746 | } else { | 733 | } else { |
747 | qDebug("regular save file"); | 734 | qDebug("regular save file"); |
748 | QFile f(file); | 735 | QFile f(file); |
749 | if( f.open(IO_WriteOnly)) { | 736 | if( f.open(IO_WriteOnly)) { |
750 | QCString crt = rt.utf8(); | 737 | QCString crt = rt.utf8(); |
751 | f.writeBlock(crt,crt.length()); | 738 | f.writeBlock(crt,crt.length()); |
752 | } else { | 739 | } else { |
753 | QMessageBox::message("Text Edit","Write Failed"); | 740 | QMessageBox::message("Text Edit","Write Failed"); |
754 | return false; | 741 | return false; |
755 | } | 742 | } |
756 | 743 | ||
757 | } | 744 | } |
758 | editor->setEdited( FALSE); | 745 | editor->setEdited( FALSE); |
759 | edited1=FALSE; | 746 | edited1=FALSE; |
760 | edited=FALSE; | 747 | edited=FALSE; |
761 | if(caption().left(1)=="*") | 748 | if(caption().left(1)=="*") |
762 | setCaption(caption().right(caption().length()-1)); | 749 | setCaption(caption().right(caption().length()-1)); |
763 | 750 | ||
764 | 751 | ||
765 | chmod( file.latin1(), mode); | 752 | chmod( file.latin1(), mode); |
766 | } | 753 | } |
767 | return true; | 754 | return true; |
768 | } | 755 | } |
769 | return false; | 756 | return false; |
770 | } | 757 | } |
771 | 758 | ||
772 | /*! | 759 | /*! |
773 | prompted save */ | 760 | prompted save */ |
774 | bool TextEdit::saveAs() | 761 | bool TextEdit::saveAs() { |
775 | { | 762 | qDebug("saveAsFile "+currentFileName); |
776 | // qDebug("saveAsFile "+currentFileName); | 763 | // case of nothing to save... |
777 | // case of nothing to save... | 764 | if ( !doc ) { |
778 | if ( !doc )//|| !bFromDocView) | 765 | //|| !bFromDocView) |
779 | { | 766 | qDebug("no doc"); |
780 | qDebug("no doc"); | 767 | return true; |
781 | return true; | 768 | } |
782 | } | ||
783 | if ( !editor->edited() ) { | 769 | if ( !editor->edited() ) { |
784 | delete doc; | 770 | delete doc; |
785 | doc = 0; | 771 | doc = 0; |
786 | return true; | 772 | return true; |
787 | } | 773 | } |
788 | 774 | ||
789 | QString rt = editor->text(); | 775 | QString rt = editor->text(); |
790 | qDebug(currentFileName); | 776 | qDebug(currentFileName); |
791 | 777 | ||
792 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { | 778 | if( currentFileName.isEmpty() || currentFileName == tr("Unnamed") || currentFileName == tr("Text Editor")) { |
793 | qDebug("do silly TT filename thing"); | 779 | // qDebug("do silly TT filename thing"); |
794 | if ( doc->name().isEmpty() ) { | 780 | if ( doc->name().isEmpty() ) { |
795 | QString pt = rt.simplifyWhiteSpace(); | 781 | QString pt = rt.simplifyWhiteSpace(); |
796 | int i = pt.find( ' ' ); | 782 | int i = pt.find( ' ' ); |
797 | QString docname = pt; | 783 | QString docname = pt; |
798 | if ( i > 0 ) | 784 | if ( i > 0 ) |
799 | docname = pt.left( i ); | 785 | docname = pt.left( i ); |
800 | // remove "." at the beginning | 786 | // remove "." at the beginning |
801 | while( docname.startsWith( "." ) ) | 787 | while( docname.startsWith( "." ) ) |
802 | docname = docname.mid( 1 ); | 788 | docname = docname.mid( 1 ); |
803 | docname.replace( QRegExp("/"), "_" ); | 789 | docname.replace( QRegExp("/"), "_" ); |
804 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. | 790 | // cut the length. filenames longer than that don't make sense and something goes wrong when they get too long. |
805 | if ( docname.length() > 40 ) | 791 | if ( docname.length() > 40 ) |
806 | docname = docname.left(40); | 792 | docname = docname.left(40); |
807 | if ( docname.isEmpty() ) | 793 | if ( docname.isEmpty() ) |
808 | docname = tr("Unnamed"); | 794 | docname = tr("Unnamed"); |
809 | doc->setName(docname); | 795 | doc->setName(docname); |
810 | currentFileName=docname; | 796 | currentFileName=docname; |
811 | } | 797 | } |
812 | } | 798 | } |
813 | 799 | ||
814 | QMap<QString, QStringList> map; | 800 | QMap<QString, QStringList> map; |
815 | map.insert(tr("All"), QStringList() ); | 801 | map.insert(tr("All"), QStringList() ); |
816 | QStringList text; | 802 | QStringList text; |
817 | text << "text/*"; | 803 | text << "text/*"; |
818 | map.insert(tr("Text"), text ); | 804 | map.insert(tr("Text"), text ); |
819 | text << "*"; | 805 | text << "*"; |
820 | map.insert(tr("All"), text ); | 806 | map.insert(tr("All"), text ); |
807 | |||
821 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); | 808 | QString str = OFileDialog::getSaveFileName( 2,"/", QString::null, map); |
809 | |||
822 | if(!str.isEmpty() ) { | 810 | if(!str.isEmpty() ) { |
823 | QString fileNm=str; | 811 | QString fileNm=str; |
824 | 812 | ||
825 | qDebug("saving filename "+fileNm); | 813 | qDebug("saving filename "+fileNm); |
826 | QFileInfo fi(fileNm); | 814 | QFileInfo fi(fileNm); |
827 | currentFileName=fi.fileName(); | 815 | currentFileName=fi.fileName(); |
828 | if(doc) { | 816 | if(doc) { |
829 | // QString file = doc->file(); | 817 | // QString file = doc->file(); |
830 | // doc->removeFiles(); | 818 | // doc->removeFiles(); |
831 | delete doc; | 819 | delete doc; |
832 | DocLnk nf; | 820 | DocLnk nf; |
833 | nf.setType("text/plain"); | 821 | nf.setType("text/plain"); |
834 | nf.setFile( fileNm); | 822 | nf.setFile( fileNm); |
835 | doc = new DocLnk(nf); | 823 | doc = new DocLnk(nf); |
836 | // editor->setText(rt); | 824 | // editor->setText(rt); |
837 | // qDebug("openFile doclnk "+currentFileName); | 825 | // qDebug("openFile doclnk "+currentFileName); |
838 | doc->setName( currentFileName); | 826 | doc->setName( currentFileName); |
839 | updateCaption( currentFileName); | 827 | updateCaption( currentFileName); |
840 | 828 | ||
841 | FileManager fm; | 829 | FileManager fm; |
842 | if ( !fm.saveFile( *doc, rt ) ) { | 830 | if ( !fm.saveFile( *doc, rt ) ) { |
843 | return false; | 831 | return false; |
844 | } | 832 | } |
845 | 833 | ||
846 | if( useAdvancedFeatures ) { | 834 | if( useAdvancedFeatures ) { |
847 | filePermissions *filePerm; | 835 | filePermissions *filePerm; |
848 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); | 836 | filePerm = new filePermissions(this, tr("Permissions"),true,0,(const QString &)fileNm); |
849 | filePerm->exec(); | 837 | filePerm->exec(); |
850 | 838 | ||
851 | if( filePerm) | 839 | if( filePerm) |
852 | delete filePerm; | 840 | delete filePerm; |
853 | } | 841 | } |
854 | } | 842 | } |
843 | editor->setEdited( false); | ||
844 | edited1 = false; | ||
845 | edited = false; | ||
846 | if(caption().left(1)=="*") | ||
847 | setCaption(caption().right(caption().length()-1)); | ||
848 | |||
849 | return true; | ||
855 | } | 850 | } |
856 | editor->setEdited(TRUE); | 851 | qDebug("returning false"); |
857 | edited1=FALSE; | 852 | return false; |
858 | edited=TRUE; | ||
859 | if(caption().left(1)=="*") | ||
860 | setCaption(caption().right(caption().length()-1)); | ||
861 | |||
862 | return true; | ||
863 | } //end saveAs | 853 | } //end saveAs |
864 | 854 | ||
865 | void TextEdit::clear() | 855 | void TextEdit::clear() { |
866 | { | ||
867 | delete doc; | 856 | delete doc; |
868 | doc = 0; | 857 | doc = 0; |
869 | editor->clear(); | 858 | editor->clear(); |
870 | } | 859 | } |
871 | 860 | ||
872 | void TextEdit::updateCaption( const QString &name ) | 861 | void TextEdit::updateCaption( const QString &name ) { |
873 | { | ||
874 | if ( !doc ) | 862 | if ( !doc ) |
875 | setCaption( tr("Text Editor") ); | 863 | setCaption( tr("Text Editor") ); |
876 | else { | 864 | else { |
877 | QString s = name; | 865 | QString s = name; |
878 | if ( s.isNull() ) | 866 | if ( s.isNull() ) |
879 | s = doc->name(); | 867 | s = doc->name(); |
880 | if ( s.isEmpty() ) { | 868 | if ( s.isEmpty() ) { |
881 | s = tr( "Unnamed" ); | 869 | s = tr( "Unnamed" ); |
882 | currentFileName=s; | 870 | currentFileName=s; |
883 | } | 871 | } |
884 | if(s.left(1) == "/") | 872 | if(s.left(1) == "/") |
885 | s = s.right(s.length()-1); | 873 | s = s.right(s.length()-1); |
886 | setCaption( s + " - " + tr("Text Editor") ); | 874 | setCaption( s + " - " + tr("Text Editor") ); |
887 | } | 875 | } |
888 | } | 876 | } |
889 | 877 | ||
890 | void TextEdit::setDocument(const QString& fileref) | 878 | void TextEdit::setDocument(const QString& fileref) { |
891 | { | ||
892 | bFromDocView = TRUE; | 879 | bFromDocView = TRUE; |
893 | openFile(fileref); | 880 | openFile(fileref); |
894 | editor->setEdited(TRUE); | 881 | editor->setEdited(TRUE); |
895 | edited1=FALSE; | 882 | edited1=FALSE; |
896 | edited=TRUE; | 883 | edited=TRUE; |
897 | doSearchBar(); | 884 | doSearchBar(); |
898 | } | 885 | } |
899 | 886 | ||
900 | void TextEdit::closeEvent( QCloseEvent *e ) | 887 | void TextEdit::closeEvent( QCloseEvent *e ) { |
901 | { | ||
902 | bFromDocView = FALSE; | 888 | bFromDocView = FALSE; |
903 | e->accept(); | 889 | e->accept(); |
904 | } | 890 | } |
905 | 891 | ||
906 | void TextEdit::accept() | ||
907 | { | ||
908 | //if(caption() !="Unnamed") | ||
909 | if(edited1) | ||
910 | saveAs(); | ||
911 | exit(0); | ||
912 | |||
913 | } | ||
914 | |||
915 | void TextEdit::changeFont() { | 892 | void TextEdit::changeFont() { |
916 | FontDatabase fdb; | 893 | FontDatabase fdb; |
917 | QFont defaultFont=editor->font(); | 894 | QFont defaultFont=editor->font(); |
918 | QFontInfo fontInfo(defaultFont); | 895 | QFontInfo fontInfo(defaultFont); |
919 | Config cfg("TextEdit"); | 896 | Config cfg("TextEdit"); |
920 | cfg.setGroup("Font"); | 897 | cfg.setGroup("Font"); |
921 | QString family = cfg.readEntry("Family", fontInfo.family()); | 898 | QString family = cfg.readEntry("Family", fontInfo.family()); |
922 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); | 899 | QString style = cfg.readEntry("Style", fdb.styleString(defaultFont)); |
923 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); | 900 | int i_size = cfg.readNumEntry("Size", fontInfo.pointSize()/10); |
924 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); | 901 | QString charSet = cfg.readEntry("CharSet", QFont::encodingName( fontInfo.charSet()) ); |
925 | 902 | ||
926 | defaultFont = fdb.font(family,style,i_size,charSet); | 903 | defaultFont = fdb.font(family,style,i_size,charSet); |
927 | 904 | ||
928 | FontDialog *fontDlg; | 905 | FontDialog *fontDlg; |
929 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); | 906 | fontDlg=new FontDialog(this,tr("FontDialog"),TRUE); |
930 | 907 | ||
931 | fontDlg->exec(); | 908 | fontDlg->exec(); |
932 | 909 | ||
933 | QFont myFont=fontDlg->selectedFont; | 910 | QFont myFont=fontDlg->selectedFont; |
934 | editor->setFont( myFont); | 911 | editor->setFont( myFont); |
935 | delete fontDlg; | 912 | delete fontDlg; |
936 | 913 | ||
937 | } | 914 | } |
938 | 915 | ||
939 | void TextEdit::editDelete() | 916 | void TextEdit::editDelete() { |
940 | { | ||
941 | 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) ) { | 917 | 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) ) { |
942 | case 0: | 918 | case 0: |
943 | if(doc) { | 919 | if(doc) { |
944 | doc->removeFiles(); | 920 | doc->removeFiles(); |
945 | clear(); | 921 | clear(); |
946 | setCaption( tr("Text Editor") ); | 922 | setCaption( tr("Text Editor") ); |
947 | } | 923 | } |
948 | break; | 924 | break; |
949 | case 1: | 925 | case 1: |
950 | // exit | 926 | // exit |
951 | break; | 927 | break; |
952 | }; | 928 | }; |
953 | } | 929 | } |
954 | 930 | ||
955 | void TextEdit::changeStartConfig( bool b ) { | 931 | void TextEdit::changeStartConfig( bool b ) { |
956 | 932 | ||
957 | Config cfg("TextEdit"); | 933 | Config cfg("TextEdit"); |
958 | cfg.setGroup("View"); | 934 | cfg.setGroup("View"); |
959 | if(b) { | 935 | if(b) { |
960 | qDebug("bool"); | 936 | qDebug("bool"); |
961 | cfg.writeEntry("startNew","TRUE"); | 937 | cfg.writeEntry("startNew","TRUE"); |
962 | } else { | 938 | } else { |
963 | cfg.writeEntry("startNew","FALSE"); | 939 | cfg.writeEntry("startNew","FALSE"); |
964 | } | 940 | } |
965 | update(); | 941 | update(); |
966 | } | 942 | } |
967 | 943 | ||
968 | void TextEdit::editorChanged() { | 944 | void TextEdit::editorChanged() { |
969 | if(editor->edited() && edited && !edited1) { | 945 | if(editor->edited() && edited && !edited1) { |
970 | setCaption( "*"+caption()); | 946 | setCaption( "*"+caption()); |
971 | edited1=TRUE; | 947 | edited1=TRUE; |
972 | } | 948 | } |
973 | edited=TRUE; | 949 | edited=TRUE; |
974 | } | 950 | } |
975 | 951 | ||
976 | void TextEdit::receive(const QCString&msg, const QByteArray&) { | 952 | void TextEdit::receive(const QCString&msg, const QByteArray&) { |
977 | qDebug("QCop "+msg); | 953 | qDebug("QCop "+msg); |
978 | if ( msg == "setDocument(QString)" ) { | 954 | if ( msg == "setDocument(QString)" ) { |
979 | qDebug("bugger all"); | 955 | qDebug("bugger all"); |
980 | } | 956 | } |
981 | 957 | ||
982 | } | 958 | } |
983 | void TextEdit::doAbout() { | 959 | void TextEdit::doAbout() { |
984 | QMessageBox::about(0,"Text Edit","Text Edit is copyright\n" | 960 | QMessageBox::about(0,"Text Edit","Text Edit is copyright\n" |
985 | "2000 Trolltech AS, and\n" | 961 | "2000 Trolltech AS, and\n" |
986 | "2002 by L.J.Potter \nljp@llornkcor.com\n" | 962 | "2002 by L.J.Potter \nljp@llornkcor.com\n" |
987 | "and is licensed under the GPL"); | 963 | "and is licensed under the GPL"); |
988 | } | 964 | } |
989 | 965 | ||
990 | void TextEdit::doAdvanced(bool b) { | 966 | void TextEdit::doAdvanced(bool b) { |
991 | useAdvancedFeatures=b; | 967 | useAdvancedFeatures=b; |
992 | Config cfg("TextEdit"); | 968 | Config cfg("TextEdit"); |
993 | cfg.setGroup("View"); | 969 | cfg.setGroup("View"); |
994 | cfg.writeEntry("AdvancedFeatures",b); | 970 | cfg.writeEntry("AdvancedFeatures",b); |
995 | } | 971 | } |
996 | 972 | ||
997 | void TextEdit::editPasteTimeDate() { | 973 | void TextEdit::editPasteTimeDate() { |
998 | #ifndef QT_NO_CLIPBOARD | 974 | #ifndef QT_NO_CLIPBOARD |
999 | QClipboard *cb = QApplication::clipboard(); | 975 | QClipboard *cb = QApplication::clipboard(); |
1000 | QDateTime dt = QDateTime::currentDateTime(); | 976 | QDateTime dt = QDateTime::currentDateTime(); |
1001 | cb->setText( dt.toString()); | 977 | cb->setText( dt.toString()); |
1002 | editor->paste(); | 978 | editor->paste(); |
1003 | #endif | 979 | #endif |
1004 | } | 980 | } |