author | drw <drw> | 2002-03-18 00:02:20 (UTC) |
---|---|---|
committer | drw <drw> | 2002-03-18 00:02:20 (UTC) |
commit | b02657a01fc513e099c2d66be48d5a7b46cf6074 (patch) (unidiff) | |
tree | 1222fd77f10de1b1948b38bfb5fbe5656f8fa5c6 /core/apps/textedit/textedit.cpp | |
parent | 378db8490c6c80ced939622605be1500fa126a2d (diff) | |
download | opie-b02657a01fc513e099c2d66be48d5a7b46cf6074.zip opie-b02657a01fc513e099c2d66be48d5a7b46cf6074.tar.gz opie-b02657a01fc513e099c2d66be48d5a7b46cf6074.tar.bz2 |
Combined file open & filebrowse into one dialog
Diffstat (limited to 'core/apps/textedit/textedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/apps/textedit/textedit.cpp | 108 |
1 files changed, 26 insertions, 82 deletions
diff --git a/core/apps/textedit/textedit.cpp b/core/apps/textedit/textedit.cpp index 3a189cb..68ee1b4 100644 --- a/core/apps/textedit/textedit.cpp +++ b/core/apps/textedit/textedit.cpp | |||
@@ -49,6 +49,7 @@ | |||
49 | #include <qtoolbutton.h> | 49 | #include <qtoolbutton.h> |
50 | #include <qwidgetstack.h> | 50 | #include <qwidgetstack.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | #include <qcombo.h> | ||
52 | #include <unistd.h> | 53 | #include <unistd.h> |
53 | #include <sys/stat.h> | 54 | #include <sys/stat.h> |
54 | 55 | ||
@@ -225,14 +226,6 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, | |||
225 | #endif | 226 | #endif |
226 | 227 | ||
227 | 228 | ||
228 | |||
229 | |||
230 | static int u_id = 1; | ||
231 | static int get_unique_id() | ||
232 | { | ||
233 | return u_id++; | ||
234 | } | ||
235 | |||
236 | static const int nfontsizes = 6; | 229 | static const int nfontsizes = 6; |
237 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; | 230 | static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; |
238 | 231 | ||
@@ -265,17 +258,11 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
265 | 258 | ||
266 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 259 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
267 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); | 260 | connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); |
268 | // a->addTo( bar ); | ||
269 | a->addTo( file ); | ||
270 | |||
271 | a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | ||
272 | connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); | ||
273 | a->addTo( bar ); | 261 | a->addTo( bar ); |
274 | a->addTo( file ); | 262 | a->addTo( file ); |
275 | 263 | ||
276 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); | 264 | a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); |
277 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); | 265 | connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); |
278 | // a->addTo( bar ); | ||
279 | file->insertSeparator(); | 266 | file->insertSeparator(); |
280 | a->addTo( file ); | 267 | a->addTo( file ); |
281 | 268 | ||
@@ -298,13 +285,12 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
298 | a->addTo( editBar ); | 285 | a->addTo( editBar ); |
299 | a->addTo( edit ); | 286 | a->addTo( edit ); |
300 | 287 | ||
301 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); | 288 | a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); |
302 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); | 289 | connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); |
303 | edit->insertSeparator(); | 290 | edit->insertSeparator(); |
304 | a->addTo( bar ); | 291 | a->addTo( bar ); |
305 | a->addTo( edit ); | 292 | a->addTo( edit ); |
306 | 293 | ||
307 | |||
308 | int defsize; | 294 | int defsize; |
309 | bool defb, defi, wrap; | 295 | bool defb, defi, wrap; |
310 | 296 | ||
@@ -371,36 +357,26 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
371 | this, SLOT( search() ) ); | 357 | this, SLOT( search() ) ); |
372 | 358 | ||
373 | 359 | ||
374 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); | 360 | a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); |
375 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); | 361 | connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); |
376 | a->addTo( searchBar ); | 362 | a->addTo( searchBar ); |
377 | a->addTo( edit ); | 363 | a->addTo( edit ); |
378 | 364 | ||
379 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 365 | a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
380 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); | 366 | connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); |
381 | a->addTo( searchBar ); | 367 | a->addTo( searchBar ); |
382 | 368 | ||
383 | edit->insertSeparator(); | 369 | edit->insertSeparator(); |
384 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | 370 | a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); |
385 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); | 371 | connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); |
386 | a->addTo( edit ); | 372 | a->addTo( edit ); |
387 | |||
388 | searchBar->hide(); | ||
389 | |||
390 | editorStack = new QWidgetStack( this ); | ||
391 | setCentralWidget( editorStack ); | ||
392 | 373 | ||
393 | searchVisible = FALSE; | 374 | searchBar->hide(); |
394 | 375 | ||
395 | fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy | ||
396 | connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); | ||
397 | connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); | ||
398 | connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); | ||
399 | // fileOpen(); | ||
400 | 376 | ||
401 | editor = new QpeEditor( editorStack ); | 377 | editor = new QpeEditor( this ); |
378 | setCentralWidget( editor ); | ||
402 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 379 | editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
403 | editorStack->addWidget( editor, get_unique_id() ); | ||
404 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); | 380 | connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); |
405 | 381 | ||
406 | resize( 200, 300 ); | 382 | resize( 200, 300 ); |
@@ -429,7 +405,7 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) | |||
429 | } else { | 405 | } else { |
430 | fileOpen(); | 406 | fileOpen(); |
431 | } | 407 | } |
432 | 408 | viewSelection = cfg.readNumEntry( "FileView", 0 ); | |
433 | } | 409 | } |
434 | 410 | ||
435 | TextEdit::~TextEdit() | 411 | TextEdit::~TextEdit() |
@@ -443,6 +419,7 @@ TextEdit::~TextEdit() | |||
443 | cfg.writeEntry("Bold",f.bold()); | 419 | cfg.writeEntry("Bold",f.bold()); |
444 | cfg.writeEntry("Italic",f.italic()); | 420 | cfg.writeEntry("Italic",f.italic()); |
445 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); | 421 | cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); |
422 | cfg.writeEntry( "FileView", viewSelection ); | ||
446 | } | 423 | } |
447 | 424 | ||
448 | void TextEdit::zoomIn() | 425 | void TextEdit::zoomIn() |
@@ -513,33 +490,8 @@ void TextEdit::fileNew() | |||
513 | 490 | ||
514 | void TextEdit::fileOpen() | 491 | void TextEdit::fileOpen() |
515 | { | 492 | { |
516 | // if ( !save() ) { | ||
517 | // if ( QMessageBox::critical( this, tr( "Out of space" ), | ||
518 | // tr( "Text Editor was unable to\n" | ||
519 | // "save your changes.\n" | ||
520 | // "Free some space and try again.\n" | ||
521 | // "\nContinue anyway?" ), | ||
522 | // QMessageBox::Yes|QMessageBox::Escape, | ||
523 | // QMessageBox::No|QMessageBox::Default ) | ||
524 | // != QMessageBox::Yes ) | ||
525 | // return; | ||
526 | // else { | ||
527 | // delete doc; | ||
528 | // doc = 0; | ||
529 | // } | ||
530 | // } | ||
531 | menu->hide(); | ||
532 | editBar->hide(); | ||
533 | searchBar->hide(); | ||
534 | clearWState (WState_Reserved1 ); | ||
535 | editorStack->raiseWidget( fileSelector ); | ||
536 | fileSelector->reread(); | ||
537 | updateCaption(); | ||
538 | } | ||
539 | |||
540 | void TextEdit::newFileOpen() | ||
541 | { | ||
542 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); | 493 | browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); |
494 | browseForFiles->setFileView( viewSelection ); | ||
543 | browseForFiles->showMaximized(); | 495 | browseForFiles->showMaximized(); |
544 | if( browseForFiles->exec() != -1 ) { | 496 | if( browseForFiles->exec() != -1 ) { |
545 | QString selFile= browseForFiles->selectedFileName; | 497 | QString selFile= browseForFiles->selectedFileName; |
@@ -557,6 +509,7 @@ void TextEdit::newFileOpen() | |||
557 | openFile(fileName ); | 509 | openFile(fileName ); |
558 | } | 510 | } |
559 | } | 511 | } |
512 | viewSelection = browseForFiles->SelectionCombo->currentItem(); | ||
560 | } | 513 | } |
561 | delete browseForFiles; | 514 | delete browseForFiles; |
562 | editor->setEdited( FALSE); | 515 | editor->setEdited( FALSE); |
@@ -642,7 +595,6 @@ void TextEdit::newFile( const DocLnk &f ) | |||
642 | DocLnk nf = f; | 595 | DocLnk nf = f; |
643 | nf.setType("text/plain"); | 596 | nf.setType("text/plain"); |
644 | clear(); | 597 | clear(); |
645 | editorStack->raiseWidget( editor ); | ||
646 | setWState (WState_Reserved1 ); | 598 | setWState (WState_Reserved1 ); |
647 | editor->setFocus(); | 599 | editor->setFocus(); |
648 | doc = new DocLnk(nf); | 600 | doc = new DocLnk(nf); |
@@ -652,6 +604,7 @@ void TextEdit::newFile( const DocLnk &f ) | |||
652 | 604 | ||
653 | void TextEdit::openFile( const QString &f ) | 605 | void TextEdit::openFile( const QString &f ) |
654 | { | 606 | { |
607 | |||
655 | bFromDocView = TRUE; | 608 | bFromDocView = TRUE; |
656 | DocLnk nf; | 609 | DocLnk nf; |
657 | nf.setType("text/plain"); | 610 | nf.setType("text/plain"); |
@@ -682,10 +635,10 @@ void TextEdit::openFile( const DocLnk &f ) | |||
682 | if ( !fm.loadFile( f, txt ) ) { | 635 | if ( !fm.loadFile( f, txt ) ) { |
683 | // ####### could be a new file | 636 | // ####### could be a new file |
684 | qDebug( "Cannot open file" ); | 637 | qDebug( "Cannot open file" ); |
685 | 638 | ||
686 | //return; | 639 | //return; |
687 | } | 640 | } |
688 | 641 | ||
689 | fileNew(); | 642 | fileNew(); |
690 | if ( doc ) | 643 | if ( doc ) |
691 | delete doc; | 644 | delete doc; |
@@ -705,13 +658,11 @@ void TextEdit::showEditTools() | |||
705 | // if ( !doc ) | 658 | // if ( !doc ) |
706 | // close(); | 659 | // close(); |
707 | // clear(); | 660 | // clear(); |
708 | fileSelector->hide(); | ||
709 | menu->show(); | 661 | menu->show(); |
710 | editBar->show(); | 662 | editBar->show(); |
711 | if ( searchVisible ) | 663 | if ( searchVisible ) |
712 | searchBar->show(); | 664 | searchBar->show(); |
713 | // updateCaption(); | 665 | // updateCaption(); |
714 | editorStack->raiseWidget( editor ); | ||
715 | setWState (WState_Reserved1 ); | 666 | setWState (WState_Reserved1 ); |
716 | } | 667 | } |
717 | 668 | ||
@@ -886,15 +837,8 @@ void TextEdit::setDocument(const QString& fileref) | |||
886 | 837 | ||
887 | void TextEdit::closeEvent( QCloseEvent *e ) | 838 | void TextEdit::closeEvent( QCloseEvent *e ) |
888 | { | 839 | { |
889 | if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { | 840 | bFromDocView = FALSE; |
890 | e->ignore(); | 841 | e->accept(); |
891 | repaint(); | ||
892 | // fileRevert(); | ||
893 | |||
894 | } else { | ||
895 | bFromDocView = FALSE; | ||
896 | e->accept(); | ||
897 | } | ||
898 | } | 842 | } |
899 | 843 | ||
900 | void TextEdit::accept() | 844 | void TextEdit::accept() |