-rw-r--r-- | core/apps/textedit/fileBrowser.cpp | 92 | ||||
-rw-r--r-- | core/apps/textedit/fileBrowser.h | 43 | ||||
-rw-r--r-- | core/apps/textedit/textedit.cpp | 108 | ||||
-rw-r--r-- | core/apps/textedit/textedit.h | 6 |
4 files changed, 118 insertions, 131 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 @@ -9,26 +9,33 @@ ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ****************************************************************************/ #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 ) { if ( !name ) setName( "fileBrowser" ); setCaption(tr( name ) ); filterStr=filter; @@ -39,68 +46,79 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags dirLabel = new QLabel(this, "DirLabel"); dirLabel->setText(currentDir.canonicalPath()); 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 = new QListView( this, "ListView" ); ListView->setMinimumSize( QSize( 100, 25 ) ); ListView->addColumn( tr( "Name" ) ); ListView->setColumnWidth(0,140); ListView->setSorting( 2, FALSE); ListView->addColumn( tr( "Size" ) ); ListView->setColumnWidth(1,59); // ListView->addColumn( tr( "" ) ); 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(); move(0,15); } fileBrowser::~fileBrowser() { } +void fileBrowser::setFileView( int selection ) +{ + SelectionCombo->setCurrentItem( selection ); + selectionChanged( SelectionCombo->currentText() ); +} void fileBrowser::populateList() { ListView->clear(); //qDebug(currentDir.canonicalPath()); currentDir.setSorting(/* QDir::Size*/ /*| QDir::Reversed | */QDir::DirsFirst); currentDir.setMatchAllDirs(TRUE); @@ -135,20 +153,16 @@ void fileBrowser::populateList() dirLabel->setText(currentDir.canonicalPath()); } 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); QString strSize=selectedItem->text(1); // qDebug("strItem is "+strItem); strSize.stripWhiteSpace(); // qDebug(strSize); @@ -211,20 +225,38 @@ void fileBrowser::homeButtonPushed() { void fileBrowser::docButtonPushed() { chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); populateList(); 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); - -// chdir( QString(QPEApplication::documentDir()+"/text").latin1() ); -// currentDir.cd( QPEApplication::documentDir()+"/text", TRUE); - populateList(); - update(); + { + if ( select == "All files" ) + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::All); + else + currentDir.setFilter( QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All); + 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 @@ -12,57 +12,70 @@ ** copyright Sun 02-17-2002 22:28:23 L. J. Potter ljp@llornkcor.com ****************************************************************************/ #ifndef FILEBROWSER_H #define FILEBROWSER_H //#include <qvariant.h> #include <qdialog.h> -#include <qfile.h> -#include <qdir.h> -#include <qstringlist.h> +#include <qfile.h> +#include <qdir.h> +#include <qstringlist.h> #include <qlabel.h> #include <qstring.h> -class QVBoxLayout; -class QHBoxLayout; -class QGridLayout; +#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 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; QString selectedFileName, filterStr; QDir currentDir; QFile file; QStringList fileList; QListViewItem * item; + QComboBox *SelectionCombo; + QWidgetStack *FileStack; + FileSelector *fileSelector; + public slots: void homeButtonPushed(); - void docButtonPushed(); - void hideButtonPushed(bool); + void docButtonPushed(); + private: -private slots: - void upDir(); - void listDoubleClicked(QListViewItem *); - void listClicked(QListViewItem *); - void OnOK(); -protected slots: +private slots: + void upDir(); + void listClicked( QListViewItem * ); + void selectionChanged( const QString & ); + void OnOK(); + void docOpen( const DocLnk & ); + +protected slots: protected: }; #endif // FILEBROWSER_H 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 @@ -44,16 +44,17 @@ #include <qlineedit.h> #include <qmessagebox.h> #include <qobjectlist.h> #include <qpopupmenu.h> #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 /* XPM */ static char * filesave_xpm[] = { "16 16 78 1", " c None", @@ -220,24 +221,16 @@ void QpeEditor::find ( const QString &txt, bool caseSensitive, #else #error "Must make a QpeEditor that inherits QTextEdit" #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 ) : QMainWindow( parent, name, f ), bFromDocView( FALSE ) { doc = 0; edited=FALSE; @@ -260,27 +253,21 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) ); a->addTo( bar ); 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 ); connect( a, SIGNAL( activated() ), this, SLOT( saveAs() ) ); a->addTo( file ); a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 ); @@ -293,23 +280,22 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) a->addTo( editBar ); a->addTo( edit ); a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); a->addTo( editBar ); a->addTo( edit ); - a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); - edit->insertSeparator(); - a->addTo( bar ); - a->addTo( edit ); + a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) ); + edit->insertSeparator(); + a->addTo( bar ); + a->addTo( edit ); - int defsize; bool defb, defi, wrap; Config cfg("TextEdit"); cfg.setGroup("View"); defsize = cfg.readNumEntry("FontSize",10); defb = cfg.readBoolEntry("Bold",FALSE); defi = cfg.readBoolEntry("Italic",FALSE); @@ -366,46 +352,36 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) searchBar->setHorizontalStretchable( TRUE ); searchEdit = new QLineEdit( searchBar, "searchEdit" ); searchBar->setStretchableWidget( searchEdit ); connect( searchEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( search() ) ); - a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); - a->addTo( searchBar ); - a->addTo( edit ); + a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) ); + a->addTo( searchBar ); + a->addTo( edit ); a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) ); a->addTo( searchBar ); - edit->insertSeparator(); - a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); - connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); - a->addTo( edit ); - - searchBar->hide(); - - editorStack = new QWidgetStack( this ); - setCentralWidget( editorStack ); + edit->insertSeparator(); + a = new QAction( tr( "Delete" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); + connect( a, SIGNAL( activated() ), this, SLOT( editDelete() ) ); + a->addTo( edit ); - searchVisible = FALSE; + searchBar->hide(); - 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 ); // setFontSize(defsize,TRUE); FontDatabase fdb; QFont defaultFont=editor->font(); QFontInfo fontInfo(defaultFont); @@ -424,30 +400,31 @@ TextEdit::TextEdit( QWidget *parent, const char *name, WFlags f ) cfg.setGroup("View"); if(cfg.readEntry("startNew","TRUE") == "TRUE") { nStart->setOn(TRUE); fileNew(); } else { fileOpen(); } - + viewSelection = cfg.readNumEntry( "FileView", 0 ); } TextEdit::~TextEdit() { // save(); Config cfg("TextEdit"); cfg.setGroup("View"); QFont f = editor->font(); 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() { setFontSize(editor->font().pointSize()+1,FALSE); } void TextEdit::zoomOut() @@ -508,43 +485,18 @@ void TextEdit::fileNew() if( !bFromDocView ) { saveAs(); } newFile(DocLnk()); } 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; qDebug(selFile); QStringList::ConstIterator f; QString fileTemp; for ( f = fileList.begin(); f != fileList.end(); f++ ) { @@ -552,16 +504,17 @@ void TextEdit::newFileOpen() fileTemp.right( fileTemp.length()-5); QString fileName = fileTemp; if( fileName != "Unnamed" || fileName != "Empty Text" ) { currentFileName = fileName; qDebug("please open "+currentFileName); openFile(fileName ); } } + viewSelection = browseForFiles->SelectionCombo->currentItem(); } delete browseForFiles; editor->setEdited( FALSE); edited1=FALSE; edited=FALSE; if(caption().left(1)=="*") setCaption(caption().right(caption().length()-1)); } @@ -637,26 +590,26 @@ void TextEdit::search() editor->find( searchEdit->text(), FALSE, FALSE ); } 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); updateCaption(currentFileName); } void TextEdit::openFile( const QString &f ) { + bFromDocView = TRUE; DocLnk nf; nf.setType("text/plain"); nf.setFile(f); currentFileName=f; QFileInfo fi( currentFileName); nf.setName(fi.baseName()); qDebug("openFile string"+currentFileName); @@ -677,20 +630,20 @@ void TextEdit::openFile( const DocLnk &f ) bFromDocView = TRUE; FileManager fm; QString txt; currentFileName=f.name(); qDebug("openFile doclnk " + currentFileName); if ( !fm.loadFile( f, txt ) ) { // ####### could be a new file qDebug( "Cannot open file" ); - + //return; } - + fileNew(); if ( doc ) delete doc; doc = new DocLnk(f); editor->setText(txt); editor->setEdited( FALSE); edited1=FALSE; edited=FALSE; @@ -700,23 +653,21 @@ void TextEdit::openFile( const DocLnk &f ) updateCaption(); } void TextEdit::showEditTools() { // if ( !doc ) // close(); // clear(); - fileSelector->hide(); menu->show(); editBar->show(); if ( searchVisible ) searchBar->show(); // updateCaption(); - editorStack->raiseWidget( editor ); setWState (WState_Reserved1 ); } /*! unprompted save */ bool TextEdit::save() { QString file = doc->file(); @@ -881,25 +832,18 @@ void TextEdit::setDocument(const QString& fileref) } editor->setEdited(TRUE); edited1=FALSE; edited=TRUE; } void TextEdit::closeEvent( QCloseEvent *e ) { - if ( editorStack->visibleWidget() == fileSelector && !bFromDocView ) { - e->ignore(); - repaint(); -// fileRevert(); - - } else { - bFromDocView = FALSE; - e->accept(); - } + bFromDocView = FALSE; + e->accept(); } void TextEdit::accept() { QString file = doc->file(); if (file.find("_.txt",0,TRUE) ==-1) save(); else { 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 @@ -53,27 +53,26 @@ public: TextEdit( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~TextEdit(); QPopupMenu *font; QAction *nStart; bool edited, edited1; void openFile( const QString & ); public slots: void editorChanged(); - + protected: void closeEvent( QCloseEvent *e ); private slots: void setDocument(const QString&); void changeFont(); void fileNew(); void fileRevert(); void fileOpen(); - void newFileOpen(); void changeStartConfig(bool); bool save(); bool saveAs(); void editCut(); void editCopy(); void editPaste(); @@ -98,24 +97,23 @@ private slots: private: void colorChanged( const QColor &c ); void clear(); 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; QToolBar *menu, *editBar, *searchBar; QLineEdit *searchEdit; DocLnk *doc; bool searchVisible; bool bFromDocView; + int viewSelection; QAction *zin, *zout; QString currentFileName; }; #endif |