author | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
commit | d48baa03492fd4785ca273defb4e21bf8c0d1c08 (patch) (side-by-side diff) | |
tree | 3235810cc1113a6f6d25b4f1c60d3d2aa430b7e7 | |
parent | e09381c4b3d482c6b553a61c5fb0502a089dcc5f (diff) | |
download | opie-d48baa03492fd4785ca273defb4e21bf8c0d1c08.zip opie-d48baa03492fd4785ca273defb4e21bf8c0d1c08.tar.gz opie-d48baa03492fd4785ca273defb4e21bf8c0d1c08.tar.bz2 |
inline rename - no popup now, after selecting rename from menu, enter to commit the rename, cancel to cancel
-rw-r--r-- | noncore/apps/advancedfm/advancedfm.h | 7 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 152 |
2 files changed, 121 insertions, 38 deletions
diff --git a/noncore/apps/advancedfm/advancedfm.h b/noncore/apps/advancedfm/advancedfm.h index 7ced056..42775ee 100644 --- a/noncore/apps/advancedfm/advancedfm.h +++ b/noncore/apps/advancedfm/advancedfm.h @@ -43,8 +43,9 @@ class QPEMenuBar; class QPopupMenu; class QFile; class QListViewItem; class QLineEdit; + //class QPushButton; class QToolButton; class Ir; @@ -115,8 +116,9 @@ protected slots: protected: bool zaurusDevice; QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; QStringList remoteDirPathStringList, localDirPathStringList; + QLineEdit *renameBox; void init(); void initConnections(); void keyReleaseEvent( QKeyEvent *); @@ -148,10 +150,15 @@ protected slots: void doBeam(); void fileBeamFinished( Ir *); private: + QString oldName; QTimer menuTimer; void startProcess(const QString &); + bool eventFilter( QObject * , QEvent * ); + void cancelRename(); + void doRename(QListView *); + void okRename(); private slots: void processEnded(); }; diff --git a/noncore/apps/advancedfm/advancedfmMenu.cpp b/noncore/apps/advancedfm/advancedfmMenu.cpp index 98d024d..f067013 100644 --- a/noncore/apps/advancedfm/advancedfmMenu.cpp +++ b/noncore/apps/advancedfm/advancedfmMenu.cpp @@ -338,46 +338,8 @@ void AdvancedFm::remoteDelete() { } populateRemoteView(); } -void AdvancedFm::localRename() { - QString curFile = Local_View->currentItem()->text(0); - qDebug("currentItem "+curFile); - if( curFile !="../") { - InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); - fileDlg->setInputText((const QString &)curFile); - fileDlg->exec(); - if( fileDlg->result() == 1 ) { - QString oldname = currentDir.canonicalPath() + "/" + curFile; - QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); -//+".playlist"; - if( rename(oldname.latin1(), newName.latin1())== -1) - QMessageBox::message(tr("Note"),tr("Could not rename")); - } - populateLocalView(); - } -} - -void AdvancedFm::remoteRename() -{ - QString curFile = Remote_View->currentItem()->text(0); - if( curFile !="../") { - InputDialog *fileDlg; - fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); - fileDlg->setInputText((const QString &)curFile); - fileDlg->exec(); - if( fileDlg->result() == 1 ) { - QString oldname = currentRemoteDir.canonicalPath() + "/" + curFile; - QString newName = currentRemoteDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); -//+".playlist"; - if( rename(oldname.latin1(), newName.latin1())== -1) - QMessageBox::message(tr("Note"),tr("Could not rename")); - } - populateRemoteView(); - } -} - void AdvancedFm::filePerms() { QStringList curFileList = getPath(); @@ -1046,4 +1008,118 @@ void AdvancedFm::startProcess(const QString & cmd) { void AdvancedFm::processEnded() { populateLocalView(); populateRemoteView(); } + +bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { + if ( o->inherits( "QLineEdit" ) ) { + if ( e->type() == QEvent::KeyPress ) { + QKeyEvent *ke = (QKeyEvent*)e; + if ( ke->key() == Key_Return || + ke->key() == Key_Enter ) { + okRename(); + return true; + } else if ( ke->key() == Key_Escape ) { + cancelRename(); + return true; + } + } else if ( e->type() == QEvent::FocusOut ) { + cancelRename(); + return true; + } + } + return QWidget::eventFilter( o, e ); +} + + +void AdvancedFm::cancelRename() { + qDebug("cancel rename"); + QListView * view; + if (TabWidget->getCurrentTab() == 0) { + view = Local_View; + } + else + { + view = Remote_View; + } + + bool resetFocus = view->viewport()->focusProxy() == renameBox; + delete renameBox; + renameBox = 0; + if ( resetFocus ) { + view->viewport()->setFocusProxy( view); + view->setFocus(); + } +} + +void AdvancedFm::doRename(QListView * view) { + + QRect r = view->itemRect( view->currentItem( )); + r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); + r.setX( view->contentsX() ); + if ( r.width() > view->visibleWidth() ) + r.setWidth( view->visibleWidth() ); + + renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); + renameBox->setFrame(true); + + renameBox->setText( view->currentItem()->text(0) ); + + renameBox->selectAll(); + renameBox->installEventFilter( this ); + view->addChild( renameBox, r.x(), r.y() ); + renameBox->resize( r.size() ); + view->viewport()->setFocusProxy( renameBox ); + renameBox->setFocus(); + renameBox->show(); + +} + + +void AdvancedFm::localRename() { + oldName = Local_View->currentItem()->text(0); + doRename(Local_View ); + populateLocalView(); +} + +void AdvancedFm::remoteRename() +{ + oldName = Remote_View->currentItem()->text(0); + doRename(Local_View ); + populateRemoteView(); +} + +void AdvancedFm::okRename() { + QString newName = renameBox->text(); + cancelRename(); + int tabs=0; + QListView * view; + tabs = TabWidget->getCurrentTab(); + if ( tabs == 0) + { + view = Local_View; + QString path = currentDir.canonicalPath() + "/"; + oldName = path + oldName; + newName = path + newName; + } + else + { + view = Remote_View; + QString path = currentRemoteDir.canonicalPath() + "/"; + oldName = path + oldName; + newName = path + newName; + } + + if( view->currentItem() == NULL) + return; + if( rename(oldName.latin1(), newName.latin1())== -1) + QMessageBox::message(tr("Note"),tr("Could not rename")); + else + oldName = ""; + + view->takeItem( view->currentItem() ); + delete view->currentItem(); + if ( tabs == 0) + populateLocalView(); + else + populateRemoteView(); +} |