-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solved undo deleted item - clean code #488
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,92 @@ | |
#include <list> | ||
#include <vector> | ||
|
||
#include <wil/com.h> | ||
|
||
class CFileOperationProgressSink : public IFileOperationProgressSink | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an existing implementation of this - see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am affraid this is not possible, because
in order to initialize
which is a reference. Because
Error:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we derive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover, would not be a good idea to use the existing I will drop this request until you review again my updated code. Hope to be soon as possible. I'll make requested changes and I'll notify you when they're ready. |
||
{ | ||
public: | ||
// IUnknown | ||
STDMETHODIMP QueryInterface(REFIID iid, LPVOID *ppv) | ||
{ | ||
HRESULT hr{ E_NOINTERFACE }; | ||
if (!ppv) | ||
return E_POINTER; | ||
|
||
*ppv = nullptr; | ||
if (iid == __uuidof(IUnknown)) | ||
{ | ||
*ppv = static_cast<IUnknown *>(this); | ||
AddRef(); | ||
hr = S_OK; | ||
} | ||
else if (iid == __uuidof(IFileOperationProgressSink)) | ||
{ | ||
*ppv = static_cast<IFileOperationProgressSink *>(this); | ||
AddRef(); | ||
hr = S_OK; | ||
} | ||
|
||
return hr; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) AddRef() | ||
{ | ||
++m_cRef; | ||
return m_cRef; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) Release() | ||
{ | ||
ULONG cRef = --m_cRef; | ||
if (0 == cRef) | ||
delete this; | ||
|
||
return cRef; | ||
} | ||
|
||
// IFileOperationProgressSink | ||
STDMETHODIMP StartOperations() { return S_OK; } | ||
STDMETHODIMP FinishOperations(HRESULT) { return S_OK; } | ||
STDMETHODIMP PreRenameItem(DWORD, IShellItem *, LPCWSTR) { return S_OK; } | ||
STDMETHODIMP PostRenameItem(DWORD, IShellItem *, LPCWSTR, HRESULT, IShellItem *) { return S_OK; } | ||
STDMETHODIMP PreMoveItem(DWORD, IShellItem *, IShellItem *, LPCWSTR) { return S_OK; } | ||
STDMETHODIMP PostMoveItem(DWORD, IShellItem *, IShellItem *, LPCWSTR, HRESULT, IShellItem *) { return S_OK; } | ||
STDMETHODIMP PreCopyItem(DWORD, IShellItem *, IShellItem *, LPCWSTR) { return S_OK; } | ||
STDMETHODIMP PostCopyItem(DWORD, IShellItem *, IShellItem *, LPCWSTR, HRESULT, IShellItem *) { return S_OK; } | ||
STDMETHODIMP PreDeleteItem(DWORD, IShellItem *) { return S_OK; } | ||
STDMETHODIMP PreNewItem(DWORD, IShellItem *, LPCWSTR) { return S_OK; } | ||
STDMETHODIMP PostNewItem(DWORD, IShellItem *, LPCWSTR, LPCWSTR, DWORD, HRESULT, IShellItem *) { return S_OK; } | ||
STDMETHODIMP UpdateProgress(UINT, UINT) { return S_OK; } | ||
STDMETHODIMP ResetTimer() { return S_OK; } | ||
STDMETHODIMP PauseTimer() { return S_OK; } | ||
STDMETHODIMP ResumeTimer() { return S_OK; } | ||
STDMETHODIMP PostDeleteItem(DWORD, IShellItem *, HRESULT, IShellItem *psiNewlyCreated) | ||
{ | ||
HRESULT hr{ S_OK }; | ||
if (psiNewlyCreated) | ||
{ | ||
PIDLIST_ABSOLUTE pidlNewlyCreated{}; | ||
hr = SHGetIDListFromObject(psiNewlyCreated, &pidlNewlyCreated); | ||
if (SUCCEEDED(hr) && pidlNewlyCreated) | ||
m_vPidls.emplace_back(pidlNewlyCreated); | ||
} | ||
return hr; | ||
} | ||
|
||
CFileOperationProgressSink(std::vector<PCIDLIST_ABSOLUTE> &pidls) | ||
:m_vPidls(pidls) | ||
{ | ||
} | ||
|
||
private: | ||
LONG m_cRef{ 1 }; | ||
std::vector<PCIDLIST_ABSOLUTE> &m_vPidls; | ||
~CFileOperationProgressSink() | ||
{ | ||
} | ||
}; | ||
|
||
namespace FileOperations | ||
{ | ||
|
||
|
@@ -18,8 +104,7 @@ enum class OverwriteMethod | |
}; | ||
|
||
HRESULT RenameFile(IShellItem *item, const std::wstring &newName); | ||
HRESULT DeleteFiles(HWND hwnd, const std::vector<PCIDLIST_ABSOLUTE> &pidls, bool permanent, | ||
bool silent); | ||
HRESULT DeleteFiles(HWND hwnd, std::vector<PCIDLIST_ABSOLUTE> &pidls, bool permanent, bool silent); | ||
void DeleteFileSecurely(const std::wstring &strFilename, OverwriteMethod overwriteMethod); | ||
HRESULT CopyFilesToFolder(HWND hOwner, const std::wstring &strTitle, | ||
std::vector<PCIDLIST_ABSOLUTE> &pidls, bool move); | ||
|
@@ -39,10 +124,13 @@ HRESULT ResolveLink(HWND hwnd, DWORD fFlags, const TCHAR *szLinkFilename, TCHAR | |
int nBufferSize); | ||
|
||
BOOL CreateBrowseDialog(HWND hOwner, const std::wstring &strTitle, PIDLIST_ABSOLUTE *ppidl); | ||
|
||
HRESULT Undelete(const PCIDLIST_ABSOLUTE &pidl); | ||
HRESULT PerformUndeleting(wil::com_ptr_nothrow<IShellFolder> &shellFolder, | ||
const PITEMID_CHILD &pidChild); | ||
HRESULT InvokeVerb(IContextMenu *pContextMenu, PCSTR pszVerb); | ||
}; | ||
|
||
HRESULT CopyFiles(const std::vector<PidlAbsolute> &items, IDataObject **dataObjectOut); | ||
HRESULT CutFiles(const std::vector<PidlAbsolute> &items, IDataObject **dataObjectOut); | ||
HRESULT CopyFilesToClipboard(const std::vector<PidlAbsolute> &items, bool move, | ||
IDataObject **dataObjectOut); | ||
HRESULT CopyFilesToClipboard(const std::vector<PidlAbsolute> &items, bool move, IDataObject **dataObjectOut); | ||
HRESULT CreateFileOperationProgressSink(std::vector<PCIDLIST_ABSOLUTE> &pidls, IFileOperationProgressSink **ppSink); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use
ExecuteActionFromContextMenu
for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tried this:
not worked. For the moment, I push the current functional code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requested code for modification:
This change would modify pretty much and then make the code more complex, because
ExecuteActionFromContextMenu
requirePCIDLIST_ABSOLUTE
, and a handle to the window which execute "undelete" action, and we are inFileOperations
, which has no window/handle to window. Is this acceptable?