-
-
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?
Conversation
|
return hr; | ||
} | ||
|
||
HRESULT FileOperations::InvokeVerb(IContextMenu* pContextMenu, PCSTR pszVerb) |
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:
HRESULT FileOperations::PerformUndeleting(const PCIDLIST_ABSOLUTE &pidl,
const PITEMID_CHILD &pidChild, HWND hwnd)
{
return ExecuteActionFromContextMenu(pidl, { pidChild }, hwnd, L"undelete", 0, nullptr);
}
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:
if (SUCCEEDED(hr) && pContextMenu)
{
// hr = InvokeVerb(pContextMenu.get(), "undelete");
ExecuteActionFromContextMenu();
}
This change would modify pretty much and then make the code more complex, because ExecuteActionFromContextMenu
require PCIDLIST_ABSOLUTE
, and a handle to the window which execute "undelete" action, and we are in FileOperations
, which has no window/handle to window. Is this acceptable?
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
There's an existing implementation of this - see FileProgressSink
. That implementation could be updated to notify on deletes. That would simplify this code, since you wouldn't need to implement the entire class.
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 am affraid this is not possible, because CFileOperationProgressSink
needs a custom constructor:
CFileOperationProgressSink(std::vector<PCIDLIST_ABSOLUTE> &pidls)
:m_vPidls(pidls)
{
}
in order to initialize
std::vector<PCIDLIST_ABSOLUTE> &m_vPidls;
which is a reference.
Because FileProgressSink
is derived from winrt::implements<FileProgressSink, IFileOperationProgressSink, winrt::non_agile>
, I cannot implement that custom constructor:
FileProgressSink(std::vector<PCIDLIST_ABSOLUTE> &pidls)
:m_vPidls(pidls)
{
}
Error:
31>C:\Project\explorerplusplus_undo_delete\vcpkg_installed\x64-windows-static\x64-windows-static\include\winrt\base.h(8059,52): error C2280: 'winrt::impl::heap_implements<FileProgressSink>::heap_implements(void)': attempting to reference a deleted function
31>(compiling source file '/MainMenuHandler.cpp')
31> C:\Project\explorerplusplus_undo_delete\vcpkg_installed\x64-windows-static\x64-windows-static\include\winrt\base.h(8043,1):
31> compiler has generated 'winrt::impl::heap_implements<FileProgressSink>::heap_implements' here
31> C:\Project\explorerplusplus_undo_delete\vcpkg_installed\x64-windows-static\x64-windows-static\include\winrt\base.h(8043,1):
31> 'winrt::impl::heap_implements<FileProgressSink>::heap_implements(void)': function was implicitly deleted because a base class 'FileProgressSink' has either no appropriate default constructor or overload resolution was ambiguous
31> C:\Project\explorerplusplus_undo_delete\Explorer++\Explorer++\FileProgressSink.h(10,7):
31> see declaration of 'FileProgressSink'
31> C:\Project\explorerplusplus_undo_delete\vcpkg_installed\x64-windows-static\x64-windows-static\include\winrt\base.h(8059,52):
31> the template instantiation context (the oldest one first) is
31> C:\Project\explorerplusplus_undo_delete\Explorer++\Explorer++\MainMenuHandler.cpp(216,21):
31> see reference to function template instantiation 'winrt::com_ptr<D> winrt::make_self<FileProgressSink,>(void)' being compiled
31> with
31> [
31> D=FileProgressSink
31> ]
31> C:\Project\explorerplusplus_undo_delete\vcpkg_installed\x64-windows-static\x64-windows-static\include\winrt\base.h(8176,28):
31> see reference to function template instantiation 'T *winrt::impl::create_and_initialize<FileProgressSink,>(void)' being compiled
31> with
31> [
31> T=FileProgressSink
31> ]
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.
Can we derive FileProgressSink
from IFileOperationProgressSink
only?
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.
Moreover, would not be a good idea to use the existing FileProgressSink
class instead of CFileOperationProgressSink
even if I could add a custom constructor to FileProgressSink
class, make no sense to initialize FileProgressSink
with a vector of PCIDLIST_ABSOLUTE
, m_vPidls
from CFileOperationProgressSink
is a reference and cannot be skipped.
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.
Solved undo deleted item - clean code