author | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-21 22:05:19 (UTC) |
commit | d48baa03492fd4785ca273defb4e21bf8c0d1c08 (patch) (unidiff) | |
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 | 13 | ||||
-rw-r--r-- | noncore/apps/advancedfm/advancedfmMenu.cpp | 152 |
2 files changed, 124 insertions, 41 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 | |||
@@ -45,4 +45,5 @@ class QFile; | |||
45 | class QListViewItem; | 45 | class QListViewItem; |
46 | class QLineEdit; | 46 | class QLineEdit; |
47 | |||
47 | //class QPushButton; | 48 | //class QPushButton; |
48 | class QToolButton; | 49 | class QToolButton; |
@@ -117,5 +118,6 @@ protected: | |||
117 | QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; | 118 | QGridLayout *tabLayout, *tabLayout_2, *tabLayout_3; |
118 | QStringList remoteDirPathStringList, localDirPathStringList; | 119 | QStringList remoteDirPathStringList, localDirPathStringList; |
119 | 120 | QLineEdit *renameBox; | |
121 | |||
120 | void init(); | 122 | void init(); |
121 | void initConnections(); | 123 | void initConnections(); |
@@ -150,6 +152,11 @@ protected slots: | |||
150 | 152 | ||
151 | private: | 153 | private: |
152 | QTimer menuTimer; | 154 | QString oldName; |
153 | void startProcess(const QString &); | 155 | QTimer menuTimer; |
156 | void startProcess(const QString &); | ||
157 | bool eventFilter( QObject * , QEvent * ); | ||
158 | void cancelRename(); | ||
159 | void doRename(QListView *); | ||
160 | void okRename(); | ||
154 | private slots: | 161 | private slots: |
155 | void processEnded(); | 162 | 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 | |||
@@ -340,42 +340,4 @@ void AdvancedFm::remoteDelete() { | |||
340 | } | 340 | } |
341 | 341 | ||
342 | void AdvancedFm::localRename() { | ||
343 | QString curFile = Local_View->currentItem()->text(0); | ||
344 | qDebug("currentItem "+curFile); | ||
345 | if( curFile !="../") { | ||
346 | InputDialog *fileDlg; | ||
347 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | ||
348 | fileDlg->setInputText((const QString &)curFile); | ||
349 | fileDlg->exec(); | ||
350 | if( fileDlg->result() == 1 ) { | ||
351 | QString oldname = currentDir.canonicalPath() + "/" + curFile; | ||
352 | QString newName = currentDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); | ||
353 | //+".playlist"; | ||
354 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
355 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
356 | } | ||
357 | populateLocalView(); | ||
358 | } | ||
359 | } | ||
360 | |||
361 | void AdvancedFm::remoteRename() | ||
362 | { | ||
363 | QString curFile = Remote_View->currentItem()->text(0); | ||
364 | if( curFile !="../") { | ||
365 | InputDialog *fileDlg; | ||
366 | fileDlg = new InputDialog(this,tr("Rename"),TRUE, 0); | ||
367 | fileDlg->setInputText((const QString &)curFile); | ||
368 | fileDlg->exec(); | ||
369 | if( fileDlg->result() == 1 ) { | ||
370 | QString oldname = currentRemoteDir.canonicalPath() + "/" + curFile; | ||
371 | QString newName = currentRemoteDir.canonicalPath() + "/" + fileDlg->LineEdit1->text(); | ||
372 | //+".playlist"; | ||
373 | if( rename(oldname.latin1(), newName.latin1())== -1) | ||
374 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
375 | } | ||
376 | populateRemoteView(); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | 342 | ||
381 | void AdvancedFm::filePerms() { | 343 | void AdvancedFm::filePerms() { |
@@ -1048,2 +1010,116 @@ void AdvancedFm::processEnded() { | |||
1048 | populateRemoteView(); | 1010 | populateRemoteView(); |
1049 | } | 1011 | } |
1012 | |||
1013 | bool AdvancedFm::eventFilter( QObject * o, QEvent * e ) { | ||
1014 | if ( o->inherits( "QLineEdit" ) ) { | ||
1015 | if ( e->type() == QEvent::KeyPress ) { | ||
1016 | QKeyEvent *ke = (QKeyEvent*)e; | ||
1017 | if ( ke->key() == Key_Return || | ||
1018 | ke->key() == Key_Enter ) { | ||
1019 | okRename(); | ||
1020 | return true; | ||
1021 | } else if ( ke->key() == Key_Escape ) { | ||
1022 | cancelRename(); | ||
1023 | return true; | ||
1024 | } | ||
1025 | } else if ( e->type() == QEvent::FocusOut ) { | ||
1026 | cancelRename(); | ||
1027 | return true; | ||
1028 | } | ||
1029 | } | ||
1030 | return QWidget::eventFilter( o, e ); | ||
1031 | } | ||
1032 | |||
1033 | |||
1034 | void AdvancedFm::cancelRename() { | ||
1035 | qDebug("cancel rename"); | ||
1036 | QListView * view; | ||
1037 | if (TabWidget->getCurrentTab() == 0) { | ||
1038 | view = Local_View; | ||
1039 | } | ||
1040 | else | ||
1041 | { | ||
1042 | view = Remote_View; | ||
1043 | } | ||
1044 | |||
1045 | bool resetFocus = view->viewport()->focusProxy() == renameBox; | ||
1046 | delete renameBox; | ||
1047 | renameBox = 0; | ||
1048 | if ( resetFocus ) { | ||
1049 | view->viewport()->setFocusProxy( view); | ||
1050 | view->setFocus(); | ||
1051 | } | ||
1052 | } | ||
1053 | |||
1054 | void AdvancedFm::doRename(QListView * view) { | ||
1055 | |||
1056 | QRect r = view->itemRect( view->currentItem( )); | ||
1057 | r = QRect( view->viewportToContents( r.topLeft() ), r.size() ); | ||
1058 | r.setX( view->contentsX() ); | ||
1059 | if ( r.width() > view->visibleWidth() ) | ||
1060 | r.setWidth( view->visibleWidth() ); | ||
1061 | |||
1062 | renameBox = new QLineEdit( view->viewport(), "qt_renamebox" ); | ||
1063 | renameBox->setFrame(true); | ||
1064 | |||
1065 | renameBox->setText( view->currentItem()->text(0) ); | ||
1066 | |||
1067 | renameBox->selectAll(); | ||
1068 | renameBox->installEventFilter( this ); | ||
1069 | view->addChild( renameBox, r.x(), r.y() ); | ||
1070 | renameBox->resize( r.size() ); | ||
1071 | view->viewport()->setFocusProxy( renameBox ); | ||
1072 | renameBox->setFocus(); | ||
1073 | renameBox->show(); | ||
1074 | |||
1075 | } | ||
1076 | |||
1077 | |||
1078 | void AdvancedFm::localRename() { | ||
1079 | oldName = Local_View->currentItem()->text(0); | ||
1080 | doRename(Local_View ); | ||
1081 | populateLocalView(); | ||
1082 | } | ||
1083 | |||
1084 | void AdvancedFm::remoteRename() | ||
1085 | { | ||
1086 | oldName = Remote_View->currentItem()->text(0); | ||
1087 | doRename(Local_View ); | ||
1088 | populateRemoteView(); | ||
1089 | } | ||
1090 | |||
1091 | void AdvancedFm::okRename() { | ||
1092 | QString newName = renameBox->text(); | ||
1093 | cancelRename(); | ||
1094 | int tabs=0; | ||
1095 | QListView * view; | ||
1096 | tabs = TabWidget->getCurrentTab(); | ||
1097 | if ( tabs == 0) | ||
1098 | { | ||
1099 | view = Local_View; | ||
1100 | QString path = currentDir.canonicalPath() + "/"; | ||
1101 | oldName = path + oldName; | ||
1102 | newName = path + newName; | ||
1103 | } | ||
1104 | else | ||
1105 | { | ||
1106 | view = Remote_View; | ||
1107 | QString path = currentRemoteDir.canonicalPath() + "/"; | ||
1108 | oldName = path + oldName; | ||
1109 | newName = path + newName; | ||
1110 | } | ||
1111 | |||
1112 | if( view->currentItem() == NULL) | ||
1113 | return; | ||
1114 | if( rename(oldName.latin1(), newName.latin1())== -1) | ||
1115 | QMessageBox::message(tr("Note"),tr("Could not rename")); | ||
1116 | else | ||
1117 | oldName = ""; | ||
1118 | |||
1119 | view->takeItem( view->currentItem() ); | ||
1120 | delete view->currentItem(); | ||
1121 | if ( tabs == 0) | ||
1122 | populateLocalView(); | ||
1123 | else | ||
1124 | populateRemoteView(); | ||
1125 | } | ||