-rw-r--r-- | core/apps/textedit/textedit.cpp | 23 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 2 |
2 files changed, 23 insertions, 2 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 429c195..834971a 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -262,32 +262,36 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 262 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
263 | // a->addTo( bar ); | 263 | // a->addTo( bar ); |
264 | a->addTo( file ); | 264 | a->addTo( file ); |
265 | 265 | ||
266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 266 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | 267 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); |
268 | a->addTo( bar ); | 268 | a->addTo( bar ); |
269 | a->addTo( file ); | 269 | a->addTo( file ); |
270 | 270 | ||
271 | // | 271 | // |
272 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 272 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
273 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 273 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
274 | // a->addTo( bar ); | 274 | // a->addTo( bar ); |
275 | file->insertSeparator(); | 275 | file->insertSeparator(); |
276 | a->addTo( file ); | 276 | a->addTo( file ); |
277 | 277 | ||
278 | a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | ||
279 | connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); | ||
280 | a->addTo( file ); | ||
281 | |||
278 | 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 ); |
279 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 283 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
280 | a->addTo( editBar ); | 284 | a->addTo( editBar ); |
281 | a->addTo( edit ); | 285 | a->addTo( edit ); |
282 | 286 | ||
283 | 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 ); |
284 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 288 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
285 | a->addTo( editBar ); | 289 | a->addTo( editBar ); |
286 | a->addTo( edit ); | 290 | a->addTo( edit ); |
287 | 291 | ||
288 | 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 ); |
289 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 293 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
290 | a->addTo( editBar ); | 294 | a->addTo( editBar ); |
291 | a->addTo( edit ); | 295 | a->addTo( edit ); |
292 | 296 | ||
293 | 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 ); |
@@ -401,33 +405,33 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
401 | wa->setOn(wrap); | 405 | wa->setOn(wrap); |
402 | updateCaption(); | 406 | updateCaption(); |
403 | if( qApp->argc() > 1 ) { | 407 | if( qApp->argc() > 1 ) { |
404 | for (int i=1;i< qApp->argc();i++) { | 408 | for (int i=1;i< qApp->argc();i++) { |
405 | QString tmp; | 409 | QString tmp; |
406 | currentFileName = tmp.sprintf("%s",qApp->argv()[i]); | 410 | currentFileName = tmp.sprintf("%s",qApp->argv()[i]); |
407 | qDebug(currentFileName); | 411 | qDebug(currentFileName); |
408 | setDocument( currentFileName ); | 412 | setDocument( currentFileName ); |
409 | } | 413 | } |
410 | } | 414 | } |
411 | else | 415 | else |
412 | fileNew(); | 416 | fileNew(); |
413 | } | 417 | } |
414 | 418 | ||
415 | TextEdit::~TextEdit() | 419 | TextEdit::~TextEdit() |
416 | { | 420 | { |
417 | save(); | 421 | saveAs(); |
418 | 422 | ||
419 | Config cfg("TextEdit"); | 423 | Config cfg("TextEdit"); |
420 | cfg.setGroup("View"); | 424 | cfg.setGroup("View"); |
421 | QFont f = editor->font(); | 425 | QFont f = editor->font(); |
422 | cfg.writeEntry("FontSize",f.pointSize()); | 426 | cfg.writeEntry("FontSize",f.pointSize()); |
423 | cfg.writeEntry("Bold",f.bold()); | 427 | cfg.writeEntry("Bold",f.bold()); |
424 | cfg.writeEntry("Italic",f.italic()); | 428 | cfg.writeEntry("Italic",f.italic()); |
425 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 429 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
426 | } | 430 | } |
427 | 431 | ||
428 | void TextEdit::zoomIn() | 432 | void TextEdit::zoomIn() |
429 | { | 433 | { |
430 | setFontSize(editor->font().pointSize()+1,FALSE); | 434 | setFontSize(editor->font().pointSize()+1,FALSE); |
431 | } | 435 | } |
432 | 436 | ||
433 | void TextEdit::zoomOut() | 437 | void TextEdit::zoomOut() |
@@ -473,33 +477,33 @@ void TextEdit::setItalic(bool y) | |||
473 | { | 477 | { |
474 | QFont f = editor->font(); | 478 | QFont f = editor->font(); |
475 | f.setItalic(y); | 479 | f.setItalic(y); |
476 | editor->setFont(f); | 480 | editor->setFont(f); |
477 | } | 481 | } |
478 | 482 | ||
479 | void TextEdit::setWordWrap(bool y) | 483 | void TextEdit::setWordWrap(bool y) |
480 | { | 484 | { |
481 | bool state = editor->edited(); | 485 | bool state = editor->edited(); |
482 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); | 486 | editor->setWordWrap(y ? QMultiLineEdit::WidgetWidth : QMultiLineEdit::NoWrap ); |
483 | editor->setEdited( state ); | 487 | editor->setEdited( state ); |
484 | } | 488 | } |
485 | 489 | ||
486 | void TextEdit::fileNew() | 490 | void TextEdit::fileNew() |
487 | { | 491 | { |
488 | if( !bFromDocView ) { | 492 | if( !bFromDocView ) { |
489 | save(); | 493 | saveAs(); |
490 | } | 494 | } |
491 | newFile(DocLnk()); | 495 | newFile(DocLnk()); |
492 | } | 496 | } |
493 | 497 | ||
494 | void TextEdit::fileOpen() | 498 | void TextEdit::fileOpen() |
495 | { | 499 | { |
496 | // if ( !save() ) { | 500 | // if ( !save() ) { |
497 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | 501 | // if ( QMessageBox::critical( this, tr( "Out of space" ), |
498 | // tr( "Text Editor was unable to\n" | 502 | // tr( "Text Editor was unable to\n" |
499 | // "save your changes.\n" | 503 | // "save your changes.\n" |
500 | // "Free some space and try again.\n" | 504 | // "Free some space and try again.\n" |
501 | // "\nContinue anyway?" ), | 505 | // "\nContinue anyway?" ), |
502 | // QMessageBox::Yes|QMessageBox::Escape, | 506 | // QMessageBox::Yes|QMessageBox::Escape, |
503 | // QMessageBox::No|QMessageBox::Default ) | 507 | // QMessageBox::No|QMessageBox::Default ) |
504 | // != QMessageBox::Yes ) | 508 | // != QMessageBox::Yes ) |
505 | // return; | 509 | // return; |
@@ -667,32 +671,47 @@ void TextEdit::showEditTools() | |||
667 | { | 671 | { |
668 | // if ( !doc ) | 672 | // if ( !doc ) |
669 | // close(); | 673 | // close(); |
670 | // clear(); | 674 | // clear(); |
671 | fileSelector->hide(); | 675 | fileSelector->hide(); |
672 | menu->show(); | 676 | menu->show(); |
673 | editBar->show(); | 677 | editBar->show(); |
674 | if ( searchVisible ) | 678 | if ( searchVisible ) |
675 | searchBar->show(); | 679 | searchBar->show(); |
676 | // updateCaption(); | 680 | // updateCaption(); |
677 | editorStack->raiseWidget( editor ); | 681 | editorStack->raiseWidget( editor ); |
678 | setWState (WState_Reserved1 ); | 682 | setWState (WState_Reserved1 ); |
679 | } | 683 | } |
680 | 684 | ||
681 | bool TextEdit::save() | 685 | bool TextEdit::save() |
682 | { | 686 | { |
687 | QString rt = editor->text(); | ||
688 | doc->setName( currentFileName); | ||
689 | FileManager fm; | ||
690 | if ( !fm.saveFile( *doc, rt ) ) { | ||
691 | return false; | ||
692 | } | ||
693 | delete doc; | ||
694 | doc = 0; | ||
695 | editor->setEdited( false ); | ||
696 | return true; | ||
697 | |||
698 | } | ||
699 | |||
700 | bool TextEdit::saveAs() | ||
701 | { | ||
683 | // case of nothing to save... | 702 | // case of nothing to save... |
684 | if ( !doc || !bFromDocView) | 703 | if ( !doc || !bFromDocView) |
685 | return true; | 704 | return true; |
686 | if ( !editor->edited() ) { | 705 | if ( !editor->edited() ) { |
687 | delete doc; | 706 | delete doc; |
688 | doc = 0; | 707 | doc = 0; |
689 | return true; | 708 | return true; |
690 | } | 709 | } |
691 | 710 | ||
692 | QString rt = editor->text(); | 711 | QString rt = editor->text(); |
693 | qDebug(currentFileName); | 712 | qDebug(currentFileName); |
694 | 713 | ||
695 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { | 714 | if( currentFileName.isEmpty() || currentFileName == "Unnamed") { |
696 | 715 | ||
697 | if ( doc->name().isEmpty() ) { | 716 | if ( doc->name().isEmpty() ) { |
698 | QString pt = rt.simplifyWhiteSpace(); | 717 | QString pt = rt.simplifyWhiteSpace(); |
diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index 4bfb260..f9eb241 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h | |||
@@ -48,32 +48,34 @@ public: | |||
48 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); | 48 | TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); |
49 | ~TextEdit(); | 49 | ~TextEdit(); |
50 | 50 | ||
51 | void openFile( const QString & ); | 51 | void openFile( const QString & ); |
52 | 52 | ||
53 | protected: | 53 | protected: |
54 | void closeEvent( QCloseEvent *e ); | 54 | void closeEvent( QCloseEvent *e ); |
55 | 55 | ||
56 | private slots: | 56 | private slots: |
57 | void setDocument(const QString&); | 57 | void setDocument(const QString&); |
58 | void changeFont(); | 58 | void changeFont(); |
59 | void fileNew(); | 59 | void fileNew(); |
60 | void fileRevert(); | 60 | void fileRevert(); |
61 | void fileOpen(); | 61 | void fileOpen(); |
62 | void newFileOpen(); | 62 | void newFileOpen(); |
63 | bool save(); | 63 | bool save(); |
64 | bool saveAs(); | ||
65 | |||
64 | 66 | ||
65 | void editCut(); | 67 | void editCut(); |
66 | void editCopy(); | 68 | void editCopy(); |
67 | void editPaste(); | 69 | void editPaste(); |
68 | void editFind(); | 70 | void editFind(); |
69 | 71 | ||
70 | void findNext(); | 72 | void findNext(); |
71 | void findClose(); | 73 | void findClose(); |
72 | 74 | ||
73 | void search(); | 75 | void search(); |
74 | void accept(); | 76 | void accept(); |
75 | 77 | ||
76 | void newFile( const DocLnk & ); | 78 | void newFile( const DocLnk & ); |
77 | void openFile( const DocLnk & ); | 79 | void openFile( const DocLnk & ); |
78 | void showEditTools(); | 80 | void showEditTools(); |
79 | 81 | ||