-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 84 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 17 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 72 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 4 |
4 files changed, 82 insertions, 95 deletions
diff --git a/core/apps/textedit/fileBrowser.cpp b/core/apps/textedit/fileBrowser.cpp index 2e88067..92c15cb 100644 --- a/core/apps/textedit/fileBrowser.cpp +++ b/core/apps/textedit/fileBrowser.cpp @@ -13,18 +13,25 @@ ****************************************************************************/ #include "fileBrowser.h" #include <qpe/config.h> #include <qpe/resource.h> +#include <qpe/fileselector.h> #include <qpe/qpeapplication.h> +#include <qwidgetstack.h> #include <qlistview.h> +#include <qcombo.h> #include <qpushbutton.h> #include <qfile.h> #include <qmessagebox.h> #include <qlayout.h> #include <unistd.h> - +static int u_id = 1; +static int get_unique_id() +{ + return u_id++; +} fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fl , const QString filter ) : QDialog( parent, name, modal, fl ) { @@ -43,29 +50,23 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags dirLabel->setMinimumSize( QSize( 50, 15 ) ); dirLabel->setMaximumSize( QSize( 250, 15 ) ); layout->addWidget( dirLabel, 0, 0 ); - hideButton = new QPushButton( Resource::loadIconSet("s_hidden"),"",this,"hideButton"); - hideButton->setMinimumSize( QSize( 25, 25 ) ); - hideButton->setMaximumSize( QSize( 25, 25 ) ); - connect( hideButton,SIGNAL(toggled(bool)),this,SLOT( hideButtonPushed(bool)) ); - hideButton->setToggleButton(TRUE); - hideButton->setFlat(TRUE); - layout->addWidget( hideButton, 0, 1 ); - docButton = new QPushButton(Resource::loadIconSet("DocsIcon"),"",this,"docsButton"); docButton->setMinimumSize( QSize( 25, 25 ) ); docButton->setMaximumSize( QSize( 25, 25 ) ); connect( docButton,SIGNAL(released()),this,SLOT( docButtonPushed()) ); docButton->setFlat(TRUE); - layout->addWidget( docButton, 0, 2 ); + layout->addWidget( docButton, 0, 1 ); homeButton = new QPushButton( Resource::loadIconSet("home"),"",this,"homeButton"); homeButton->setMinimumSize( QSize( 25, 25 ) ); homeButton->setMaximumSize( QSize( 25, 25 ) ); connect(homeButton,SIGNAL(released()),this,SLOT(homeButtonPushed()) ); homeButton->setFlat(TRUE); - layout->addWidget( homeButton, 0, 3 ); + layout->addWidget( homeButton, 0, 2 ); + + FileStack = new QWidgetStack( this ); ListView = new QListView( this, "ListView" ); ListView->setMinimumSize( QSize( 100, 25 ) ); ListView->addColumn( tr( "Name" ) ); @@ -77,15 +78,27 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags ListView->setColumnWidthMode(0,QListView::Manual); ListView->setColumnAlignment(1,QListView::AlignRight); // ListView->setMultiSelection(true); // ListView->setSelectionMode(QListView::Extended); - ListView->setAllColumnsShowFocus( TRUE ); - layout->addMultiCellWidget( ListView, 1, 1, 0, 3 ); - - // signals and slots connections - connect( ListView, SIGNAL(doubleClicked( QListViewItem*)), SLOT(listDoubleClicked(QListViewItem *)) ); connect( ListView, SIGNAL(pressed( QListViewItem*)), SLOT(listClicked(QListViewItem *)) ); + FileStack->addWidget( ListView, get_unique_id() ); + + fileSelector = new FileSelector( "text/*", FileStack, "fileselector" , FALSE, FALSE); //buggy +// connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); +// connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); + connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( docOpen( const DocLnk & ) ) ); + layout->addMultiCellWidget( FileStack, 1, 1, 0, 2 ); + + SelectionCombo = new QComboBox( FALSE, this, "SelectionCombo" ); + SelectionCombo->setMinimumSize( QSize( 200, 25 ) ); + SelectionCombo->insertItem( tr( "Documents" ) ); + SelectionCombo->insertItem( tr( "All files" ) ); + SelectionCombo->insertItem( tr( "All files (incl. hidden)" ) ); + layout->addMultiCellWidget( SelectionCombo, 2, 2, 0, 2 ); + connect( SelectionCombo, SIGNAL( activated( const QString & ) ), + this, SLOT( selectionChanged( const QString & ) ) ); + currentDir.setPath(QDir::currentDirPath()); currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden */| QDir::All); populateList(); @@ -95,8 +108,13 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags fileBrowser::~fileBrowser() { } +void fileBrowser::setFileView( int selection ) +{ + SelectionCombo->setCurrentItem( selection ); + selectionChanged( SelectionCombo->currentText() ); +} void fileBrowser::populateList() { ListView->clear(); @@ -139,12 +157,8 @@ void fileBrowser::upDir() { // qDebug(currentDir.canonicalPath()); } -void fileBrowser::listDoubleClicked(QListViewItem *selectedItem) -{ -} - // you may want to switch these 2 functions. I like single clicks void fileBrowser::listClicked(QListViewItem *selectedItem) { QString strItem=selectedItem->text(0); @@ -215,16 +229,34 @@ void fileBrowser::docButtonPushed() { update(); } -void fileBrowser::hideButtonPushed(bool b) { - if (b) - currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); +void fileBrowser::selectionChanged( const QString &select ) +{ + if ( select == "Documents") + { + FileStack->raiseWidget( fileSelector ); + dirLabel->hide(); + docButton->hide(); + homeButton->hide(); + } else - currentDir.setFilter( QDir::Files | QDir::Dirs/* | QDir::Hidden*/ | QDir::All); + { + if ( select == "All files" ) + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); + else + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); -// chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); -// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); populateList(); update(); + dirLabel->show(); + docButton->show(); + homeButton->show(); + FileStack->raiseWidget( ListView ); + } +} +void fileBrowser::docOpen( const DocLnk &doc ) +{ + fileList.append( doc.file().latin1() ); + accept(); } diff --git a/core/apps/textedit/fileBrowser.h b/core/apps/textedit/fileBrowser.h index 50ed485..d8f0d0d 100644 --- a/core/apps/textedit/fileBrowser.h +++ b/core/apps/textedit/fileBrowser.h @@ -22,14 +22,19 @@ copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com #include <qstringlist.h> #include <qlabel.h> #include <qstring.h> +#include <qpe/filemanager.h> + class QVBoxLayout; class QHBoxLayout; class QGridLayout; class QListView; class QListViewItem; class QPushButton; +class QComboBox; +class QWidgetStack; +class FileSelector; class fileBrowser : public QDialog { Q_OBJECT @@ -38,8 +43,10 @@ public: void populateList(); fileBrowser( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ,const QString filter=0); ~fileBrowser(); + void setFileView( int ); + QPushButton *buttonOk, *buttonCancel, *homeButton, *docButton, *hideButton; QListView* ListView; QLabel *dirLabel; @@ -47,19 +54,25 @@ public: QDir currentDir; QFile file; QStringList fileList; QListViewItem * item; + QComboBox *SelectionCombo; + QWidgetStack *FileStack; + FileSelector *fileSelector; + public slots: void homeButtonPushed(); void docButtonPushed(); - void hideButtonPushed(bool); + private: private slots: void upDir(); - void listDoubleClicked(QListViewItem *); void listClicked(QListViewItem *); + void selectionChanged( const QString & ); void OnOK(); + void docOpen( const DocLnk & ); + protected slots: protected: 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 @@ -48,8 +48,9 @@ #include <qspinbox.h> #include <qtoolbutton.h> #include <qwidgetstack.h> #include <qcheckbox.h> +#include <qcombo.h> #include <unistd.h> #include <sys/stat.h> #include <stdlib.h> //getenv @@ -224,16 +225,8 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, #endif - - -static int u_id = 1; -static int get_unique_id() -{ - return u_id++; -} - static const int nfontsizes = 6; static const int fontsize[nfontsizes] = {8,10,12,14,18,24}; TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) @@ -264,19 +257,13 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) a->addTo( file ); a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); -// a->addTo( bar ); - a->addTo( file ); - - a = new QAction( tr( "Browse" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( newFileOpen() ) ); a->addTo( bar ); a->addTo( file ); a = new QAction( tr( "Save" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( save() ) ); -// a->addTo( bar ); file->insertSeparator(); a->addTo( file ); a = new QAction( tr( "Save As" ), QPixmap(( const char** ) filesave_xpm ) , QString::null, 0, this, 0 ); @@ -303,9 +290,8 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) edit->insertSeparator(); a->addTo( bar ); a->addTo( edit ); - int defsize; bool defb, defi, wrap; Config cfg("TextEdit"); @@ -386,22 +372,12 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) a->addTo( edit ); searchBar->hide(); - editorStack = new QWidgetStack( this ); - setCentralWidget( editorStack ); - - searchVisible = FALSE; - - fileSelector = new FileSelector( "text/*", editorStack, "fileselector" , TRUE, TRUE); //buggy - connect( fileSelector, SIGNAL( closeMe() ), this, SLOT( showEditTools() ) ); - connect( fileSelector, SIGNAL( newSelected( const DocLnk &) ), this, SLOT( newFile( const DocLnk & ) ) ); - connect( fileSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( openFile( const DocLnk & ) ) ); -// fileOpen(); - editor = new QpeEditor( editorStack ); + editor = new QpeEditor( this ); + setCentralWidget( editor ); editor->setFrameStyle( QFrame::Panel | QFrame::Sunken ); - editorStack->addWidget( editor, get_unique_id() ); connect( editor, SIGNAL( textChanged() ), this, SLOT( editorChanged() ) ); resize( 200, 300 ); @@ -428,9 +404,9 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) fileNew(); } else { fileOpen(); } - + viewSelection = cfg.readNumEntry( "FileView", 0 ); } TextEdit::~TextEdit() { @@ -442,8 +418,9 @@ TextEdit::~TextEdit() cfg.writeEntry("FontSize",f.pointSize()); cfg.writeEntry("Bold",f.bold()); cfg.writeEntry("Italic",f.italic()); cfg.writeEntry("Wrap",editor->wordWrap() == QMultiLineEdit::WidgetWidth); + cfg.writeEntry( "FileView", viewSelection ); } void TextEdit::zoomIn() { @@ -512,35 +489,10 @@ void TextEdit::fileNew() } void TextEdit::fileOpen() { -// if ( !save() ) { -// if ( QMessageBox::critical( this, tr( "Out of space" ), -// tr( "Text Editor was unable to\n" -// "save your changes.\n" -// "Free some space and try again.\n" -// "\nContinue anyway?" ), -// QMessageBox::Yes|QMessageBox::Escape, -// QMessageBox::No|QMessageBox::Default ) -// != QMessageBox::Yes ) -// return; -// else { -// delete doc; -// doc = 0; -// } -// } - menu->hide(); - editBar->hide(); - searchBar->hide(); - clearWState (WState_Reserved1 ); - editorStack->raiseWidget( fileSelector ); - fileSelector->reread(); - updateCaption(); -} - -void TextEdit::newFileOpen() -{ browseForFiles=new fileBrowser(this,"Open File",TRUE,0, "*"); + browseForFiles->setFileView( viewSelection ); browseForFiles->showMaximized(); if( browseForFiles->exec() != -1 ) { QString selFile= browseForFiles->selectedFileName; QStringList fileList=browseForFiles->fileList; @@ -556,8 +508,9 @@ void TextEdit::newFileOpen() qDebug("please open "+currentFileName); openFile(fileName ); } } + viewSelection = browseForFiles->SelectionCombo->currentItem(); } delete browseForFiles; editor->setEdited( FALSE); edited1=FALSE; @@ -641,9 +594,8 @@ void TextEdit::newFile( const DocLnk &f ) { DocLnk nf = f; nf.setType("text/plain"); clear(); - editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); editor->setFocus(); doc = new DocLnk(nf); qDebug("newFile "+currentFileName); @@ -651,8 +603,9 @@ void TextEdit::newFile( const DocLnk &f ) } void TextEdit::openFile( const QString &f ) { + bFromDocView = TRUE; DocLnk nf; nf.setType("text/plain"); nf.setFile(f); @@ -704,15 +657,13 @@ void TextEdit::showEditTools() { // if ( !doc ) // close(); // clear(); - fileSelector->hide(); menu->show(); editBar->show(); if ( searchVisible ) searchBar->show(); // updateCaption(); - editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); } /*! @@ -885,18 +836,11 @@ void TextEdit::setDocument(const QString& fileref) } void TextEdit::closeEvent( QCloseEvent *e ) { - if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { - e->ignore(); - repaint(); -// fileRevert(); - - } else { bFromDocView = FALSE; e->accept(); } -} void TextEdit::accept() { QString file = doc->file(); diff --git a/core/apps/textedit/textedit.h b/core/apps/textedit/textedit.h index e7e20e3..aca2933 100644 --- a/core/apps/textedit/textedit.h +++ b/core/apps/textedit/textedit.h @@ -67,9 +67,8 @@ private slots: void changeFont(); void fileNew(); void fileRevert(); void fileOpen(); - void newFileOpen(); void changeStartConfig(bool); bool save(); bool saveAs(); @@ -102,10 +101,8 @@ private: void updateCaption( const QString &name=QString::null ); void setFontSize(int sz, bool round_down_not_up); private: - QWidgetStack *editorStack; - FileSelector *fileSelector; fileSaver *fileSaveDlg; fileBrowser *browseForFiles; QpeEditor* editor; @@ -113,8 +110,9 @@ private: QLineEdit *searchEdit; DocLnk *doc; bool searchVisible; bool bFromDocView; + int viewSelection; QAction *zin, *zout; QString currentFileName; }; |