Changeset 76312 in vbox for trunk/src/VBox
- Timestamp:
- Dec 20, 2018 1:02:13 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/guestctrl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.cpp
r76309 r76312 28 28 # include "UICustomFileSystemModel.h" 29 29 # include "UIFileManagerTable.h" 30 # include "UIFileManager.h"31 30 # include "VBoxGlobal.h" 32 31 … … 284 283 UICustomFileSystemModel::UICustomFileSystemModel(QObject *parent) 285 284 : QAbstractItemModel(parent) 286 , m_pParent(qobject_cast<UIFileManagerTable*>(parent))287 285 , m_fShowHumanReadableSizes(false) 288 286 { … … 324 322 if (index.column() == 0 && value.canConvert(QMetaType::QString)) 325 323 { 326 UIFileTableItem * item = static_cast<UIFileTableItem*>(index.internalPointer());327 if (! item || !m_pParent)324 UIFileTableItem *pItem = static_cast<UIFileTableItem*>(index.internalPointer()); 325 if (!pItem) 328 326 return false; 329 if (m_pParent->renameItem(item, value.toString())) 330 { 331 item->setData(value, index.column()); 332 emit dataChanged(index, index); 333 } 334 else 335 { 336 if (m_pParent) 337 m_pParent->emitLogOutput(QString(item->path()).append(" could not be renamed"), FileManagerLogType_Error); 338 } 327 QString strOldName = pItem->name(); 328 pItem->setData(value, index.column()); 329 emit dataChanged(index, index); 330 emit sigItemRenamed(pItem, strOldName, value.toString()); 339 331 return true; 340 332 } -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UICustomFileSystemModel.h
r76309 r76312 25 25 /* COM includes: */ 26 26 #include "COMEnums.h" 27 28 /* Forward declarations: */29 class UIFileManagerTable;30 27 31 28 enum UICustomFileSystemModelColumn … … 126 123 127 124 UICustomFileSystemProxyModel(QObject *parent = 0); 128 129 125 void setListDirectoriesOnTop(bool fListDirectoriesOnTop); 130 126 bool listDirectoriesOnTop() const; … … 141 137 /** UICustomFileSystemModel serves as the model for a file structure. 142 138 * it supports a tree level hierarchy which can be displayed with 143 * QTableView and/or QTreeView. .*/139 * QTableView and/or QTreeView.*/ 144 140 class UICustomFileSystemModel : public QAbstractItemModel 145 141 { 146 142 147 143 Q_OBJECT; 144 145 signals: 146 147 void sigItemRenamed(UIFileTableItem *pItem, QString strOldName, QString strNewName); 148 148 149 149 public: … … 181 181 UIFileTableItem *m_pRootItem; 182 182 void setupModelData(const QStringList &lines, UIFileTableItem *parent); 183 UIFileManagerTable *m_pParent;184 183 bool m_fShowHumanReadableSizes; 185 186 184 }; 187 185 -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.cpp
r76309 r76312 583 583 if (!m_pModel) 584 584 return; 585 connect(m_pModel, &UICustomFileSystemModel::sigItemRenamed, 586 this, &UIFileManagerTable::sltHandleItemRenameAttempt); 585 587 586 588 m_pProxyModel = new UICustomFileSystemProxyModel(this); … … 917 919 void UIFileManagerTable::sltRename() 918 920 { 919 if (!m_pView )921 if (!m_pView || !m_pModel) 920 922 return; 921 923 QItemSelectionModel *selectionModel = m_pView->selectionModel(); … … 1017 1019 performSelectionSearch(strText); 1018 1020 } 1021 1022 void UIFileManagerTable::sltHandleItemRenameAttempt(UIFileTableItem *pItem, QString strOldName, QString strNewName) 1023 { 1024 if (!pItem) 1025 return; 1026 /* Attempt to chage item name in the file system: */ 1027 if (!renameItem(pItem, strNewName)) 1028 { 1029 /* Restore the previous name. relist the view: */ 1030 pItem->setData(strOldName, static_cast<int>(UICustomFileSystemModelColumn_Name)); 1031 relist(); 1032 sigLogOutput(QString(pItem->path()).append(" could not be renamed"), FileManagerLogType_Error); 1033 } 1034 } 1035 1019 1036 1020 1037 void UIFileManagerTable::sltCreateFileViewContextMenu(const QPoint &point) -
trunk/src/VBox/Frontends/VirtualBox/src/guestctrl/UIFileManagerTable.h
r76309 r76312 190 190 void sltRefresh(); 191 191 void sltDelete(); 192 /** Calls the edit on the data item over m_pView. This causes setData(..) call on the model. After setting 193 * user entered text as the name of the item m_pModel signals. This signal is handled by sltHandleItemRenameAttempt which 194 * tries to rename the corresponding file object by calling renameItem(...). If this rename fails the old name of the 195 * model item is restored and view is refreshed by sltHandleItemRenameAttempt. */ 192 196 void sltRename(); 193 197 void sltCopy(); … … 280 284 void sltLocationComboCurrentChange(const QString &strLocation); 281 285 void sltSearchTextChanged(const QString &strText); 286 /** m_pModel signals when an tree item is renamed. we try to apply this rename to the file system. 287 * if the file system rename fails we restore the old name of the item. See the comment of 288 * sltRename() for more details. */ 289 void sltHandleItemRenameAttempt(UIFileTableItem *pItem, QString strOldName, QString strNewName); 282 290 283 291 private:
Note:
See TracChangeset
for help on using the changeset viewer.