Skip to content

Commit

Permalink
Implement fast drag drop support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhngtu committed Oct 20, 2024
1 parent afea3db commit 826970c
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 53 deletions.
1 change: 1 addition & 0 deletions NanaZip.UI.Classic/NanaZip.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="SevenZip\CPP\7zip\Archive\Common\ItemNameUtils.h" />
<ClInclude Include="SevenZip\CPP\7zip\UI\Explorer\CopyHook.h" />
<ClInclude Include="SevenZip\CPP\7zip\UI\Explorer\MyExplorerCommand.h" />
<ClInclude Include="SevenZip\CPP\Common\DynLimBuf.h" />
<ClInclude Include="SevenZip\C\7zTypes.h" />
Expand Down
5 changes: 4 additions & 1 deletion NanaZip.UI.Classic/NanaZip.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,9 @@
<ClInclude Include="AboutDialog.h">
<Filter>AboutDialog</Filter>
</ClInclude>
<ClInclude Include="SevenZip\CPP\7zip\UI\Explorer\CopyHook.h">
<Filter>SevenZip\UI\Explorer</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Manifest Include="NanaZip.manifest" />
Expand All @@ -1099,4 +1102,4 @@
<Filter>SevenZip\Spec</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
</Project>
13 changes: 13 additions & 0 deletions NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/Explorer/CopyHook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __COPY_HOOK_H
#define __COPY_HOOK_H

#include "../../../Common/MyWindows.h"

#define COPYHOOK_UUID "{7F4FD2EA-8CC8-43C4-8440-CD76805B4E95}"
#define COPYHOOK_COPY 0x7F4FD2EA

struct CopyHookData {
wchar_t filename[MAX_PATH];
};

#endif
22 changes: 22 additions & 0 deletions NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/FM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "../GUI/ExtractRes.h"

#include "../Explorer/CopyHook.h"

#include "resource.h"

#include "App.h"
Expand Down Expand Up @@ -1055,6 +1057,26 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
SWP_NOZORDER | SWP_NOACTIVATE);

::UpdateWindow(hWnd);
break;
}

case WM_COPYDATA:
{
PCOPYDATASTRUCT lpCds = (PCOPYDATASTRUCT)lParam;
if (lpCds->dwData == COPYHOOK_COPY && lpCds->cbData == sizeof(CopyHookData)) {
CPanel& panel = g_App.Panels[g_App.LastFocusedPanel];
CCopyToOptions options;
CopyHookData* data = static_cast<CopyHookData*>(lpCds->lpData);
options.folder = UString(data->filename);
options.showErrorMessages = true;
CRecordVector<UInt32> indices;
panel.GetOperatedItemIndices(indices);
if (indices.Size() > 0) {
panel.CopyTo(options, indices, NULL);
}
return TRUE;
}
break;
}
}
#ifndef _UNICODE
Expand Down
72 changes: 47 additions & 25 deletions NanaZip.UI.Classic/SevenZip/CPP/7zip/UI/FileManager/PanelDrag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
#include "../Common/CompressCall.h"
#include "../Common/ExtractingFilePath.h"

#include "../Explorer/CopyHook.h"

#include "MessagesDialog.h"

#include "App.h"
#include "EnumFormatEtc.h"
#include "RegistryUtils.h"

using namespace NWindows;
using namespace NFile;
Expand Down Expand Up @@ -333,6 +336,10 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */)
FString dirPrefix;
CTempDir tempDirectory;

CFmSettings st;
st.Load();
FString fakeDirPath;

bool isFSFolder = IsFSFolder();
if (isFSFolder)
dirPrefix = us2fs(GetFsPath());
Expand All @@ -346,6 +353,16 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */)
dirPrefix = tempDirectory.GetPath();
// dirPrefix2 = dirPrefix;
NFile::NName::NormalizeDirPathPrefix(dirPrefix);
if (st.FastDragDrop) {
fakeDirPath = dirPrefix;
fakeDirPath += FTEXT(COPYHOOK_UUID) FTEXT(".");
fakeDirPath.Add_UInt64(reinterpret_cast<UInt64>(g_App._window.operator HWND()));
if (!CreateDir(fakeDirPath))
{
MessageBox_Error(L"Can't create fake folder");
return;
}
}
}

CDataObject *dataObjectSpec = new CDataObject;
Expand All @@ -357,43 +374,48 @@ void CPanel::OnDrag(LPNMLISTVIEW /* nmListView */)
// names variable is USED for drag and drop from NanaZip to Explorer or to NanaZip archive folder.
// names variable is NOT USED for drag and drop from NanaZip to NanaZip File System folder.

FOR_VECTOR (i, indices)
{
UInt32 index = indices[i];
UString s;
if (isFSFolder)
s = GetItemRelPath(index);
else
if (!isFSFolder && st.FastDragDrop) {
names.Add(fs2us(fakeDirPath));
}
else {
FOR_VECTOR(i, indices)
{
s = GetItemName(index);
/*
// We use (keepAndReplaceEmptyPrefixes = true) in CAgentFolder::Extract
// So the following code is not required.
// Maybe we also can change IFolder interface and send some flag also.
if (s.IsEmpty())
UInt32 index = indices[i];
UString s;
if (isFSFolder)
s = GetItemRelPath(index);
else
{
// Correct_FsFile_Name("") returns "_".
// If extracting code removes empty folder prefixes from path (as it was in old version),
// Explorer can't find "_" folder in temp folder.
// We can ask Explorer to copy parent temp folder "7zE" instead.
s = GetItemName(index);
/*
// We use (keepAndReplaceEmptyPrefixes = true) in CAgentFolder::Extract
// So the following code is not required.
// Maybe we also can change IFolder interface and send some flag also.
names.Clear();
names.Add(dirPrefix2);
break;
if (s.IsEmpty())
{
// Correct_FsFile_Name("") returns "_".
// If extracting code removes empty folder prefixes from path (as it was in old version),
// Explorer can't find "_" folder in temp folder.
// We can ask Explorer to copy parent temp folder "7zE" instead.
names.Clear();
names.Add(dirPrefix2);
break;
}
*/
s = Get_Correct_FsFile_Name(s);
}
*/
s = Get_Correct_FsFile_Name(s);
names.Add(fs2us(dirPrefix) + s);
}
names.Add(fs2us(dirPrefix) + s);
}
if (!CopyNamesToHGlobal(dataObjectSpec->hGlobal, names))
return;
}

CDropSource *dropSourceSpec = new CDropSource;
CMyComPtr<IDropSource> dropSource = dropSourceSpec;
dropSourceSpec->NeedExtract = !isFSFolder;
dropSourceSpec->NeedExtract = !st.FastDragDrop && !isFSFolder;
dropSourceSpec->Panel = this;
dropSourceSpec->Indices = indices;
dropSourceSpec->Folder = fs2us(dirPrefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static LPCTSTR const kAlternativeSelection = TEXT("AlternativeSelection");
// static LPCTSTR const kUnderline = TEXT("Underline");

static LPCTSTR const kShowSystemMenu = TEXT("ShowSystemMenu");
static LPCTSTR const kFastDragDrop = TEXT("FastDragDrop");

// static LPCTSTR const kLockMemoryAdd = TEXT("LockMemoryAdd");
static LPCTSTR const kLargePages = TEXT("LargePages");
Expand Down Expand Up @@ -155,6 +156,7 @@ void CFmSettings::Save() const
// SaveOption(kUnderline, Underline);

SaveOption(kShowSystemMenu, ShowSystemMenu);
SaveOption(kFastDragDrop, FastDragDrop);
}

void CFmSettings::Load()
Expand All @@ -173,6 +175,7 @@ void CFmSettings::Load()
// Underline = false;

ShowSystemMenu = false;
FastDragDrop = false;

CKey key;
if (key.Open(HKEY_CURRENT_USER, kCU_FMPath, KEY_READ) == ERROR_SUCCESS)
Expand All @@ -191,6 +194,7 @@ void CFmSettings::Load()
// ReadOption(key, kUnderline, Underline);

ReadOption(key, kShowSystemMenu, ShowSystemMenu );
ReadOption(key, kFastDragDrop, FastDragDrop);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct CFmSettings
// bool Underline;

bool ShowSystemMenu;
bool FastDragDrop;

void Save() const;
void Load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ bool CSettingsPage::OnInit()
// CheckButton(IDX_SETTINGS_UNDERLINE, st.Underline);

CheckButton(IDX_SETTINGS_SHOW_SYSTEM_MENU, st.ShowSystemMenu);
CheckButton(IDX_SETTINGS_FAST_DRAG_DROP, st.FastDragDrop);

if (IsLargePageSupported())
CheckButton(IDX_SETTINGS_LARGE_PAGES, ReadLockMemoryEnable());
Expand Down Expand Up @@ -227,6 +228,7 @@ LONG CSettingsPage::OnApply()
// st.Underline = IsButtonCheckedBool(IDX_SETTINGS_UNDERLINE);

st.ShowSystemMenu = IsButtonCheckedBool(IDX_SETTINGS_SHOW_SYSTEM_MENU);
st.FastDragDrop = IsButtonCheckedBool(IDX_SETTINGS_FAST_DRAG_DROP);

st.Save();
_wasChanged = false;
Expand Down Expand Up @@ -346,6 +348,7 @@ bool CSettingsPage::OnButtonClicked(int buttonID, HWND buttonHWND)
case IDX_SETTINGS_WANT_COPY_HISTORY:
case IDX_SETTINGS_WANT_FOLDER_HISTORY:
case IDX_SETTINGS_LOWERCASE_HASHES:
case IDX_SETTINGS_FAST_DRAG_DROP:
_wasChanged = true;
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ BEGIN
CONTROL "Want FolderHistory", IDX_SETTINGS_WANT_FOLDER_HISTORY, MY_CHECKBOX, m, 182, xc, 10
CONTROL "Use Lowercase Hashes", IDX_SETTINGS_LOWERCASE_HASHES, MY_CHECKBOX, m, 196, xc, 10

CONTROL "Use fast drag-and-drop (Experimental)", IDX_SETTINGS_FAST_DRAG_DROP, MY_CHECKBOX, m, 218, xc, 10

// LTEXT "Memory usage for Compressing:", IDT_COMPRESS_MEMORY, m, 140, xc, 8
// COMBOBOX IDC_SETTINGS_MEM, m , 152, g1xs, yc - 152, MY_COMBO
// LTEXT "/ RAM", IDT_SETTINGS_MEM_RAM, m + g1xs + m, 154, xc - g1xs - m, MY_TEXT_NOPREFIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define IDX_SETTINGS_WANT_COPY_HISTORY 2511
#define IDX_SETTINGS_WANT_FOLDER_HISTORY 2512
#define IDX_SETTINGS_LOWERCASE_HASHES 2513
#define IDX_SETTINGS_FAST_DRAG_DROP 2514


// #define IDT_SETTINGS_MEM 100
Expand Down
3 changes: 2 additions & 1 deletion NanaZip.UI.Modern/NanaZip.Modern.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
</ClInclude>
<ClInclude Include="NanaZip.UI.h" />
<ClInclude Include="SevenZip\CPP\7zip\Archive\Common\ItemNameUtils.h" />
<ClInclude Include="SevenZip\CPP\7zip\UI\Explorer\CopyHook.h" />
<ClInclude Include="SevenZip\CPP\7zip\UI\Explorer\MyExplorerCommand.h" />
<ClInclude Include="SevenZip\CPP\Common\DynLimBuf.h" />
<ClInclude Include="SevenZip\C\7zTypes.h" />
Expand Down Expand Up @@ -488,4 +489,4 @@
<PRIResource Include="Strings\zh-Hans\SponsorPage.resw" />
</ItemGroup>
<Import Project="..\Mile.Project.Windows\Mile.Project.Cpp.targets" />
</Project>
</Project>
5 changes: 4 additions & 1 deletion NanaZip.UI.Modern/NanaZip.Modern.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,9 @@
<ClInclude Include="SevenZip\CPP\Common\DynLimBuf.h">
<Filter>SevenZip\Common</Filter>
</ClInclude>
<ClInclude Include="SevenZip\CPP\7zip\UI\Explorer\CopyHook.h">
<Filter>SevenZip\UI\Explorer</Filter>
</ClInclude>
<ClInclude Include="pch.h" />
<ClInclude Include="NanaZip.UI.h" />
</ItemGroup>
Expand Down Expand Up @@ -1099,4 +1102,4 @@
<Filter>Strings\pt-BR</Filter>
</PRIResource>
</ItemGroup>
</Project>
</Project>
13 changes: 13 additions & 0 deletions NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/Explorer/CopyHook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef __COPY_HOOK_H
#define __COPY_HOOK_H

#include "../../../Common/MyWindows.h"

#define COPYHOOK_UUID "{7F4FD2EA-8CC8-43C4-8440-CD76805B4E95}"
#define COPYHOOK_COPY 0x7F4FD2EA

struct CopyHookData {
wchar_t filename[MAX_PATH];
};

#endif
21 changes: 21 additions & 0 deletions NanaZip.UI.Modern/SevenZip/CPP/7zip/UI/FileManager/FM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "../GUI/ExtractRes.h"

#include "../Explorer/CopyHook.h"

#include "resource.h"

#include "App.h"
Expand Down Expand Up @@ -1065,6 +1067,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

break;
}

case WM_COPYDATA:
{
PCOPYDATASTRUCT lpCds = (PCOPYDATASTRUCT)lParam;
if (lpCds->dwData == COPYHOOK_COPY && lpCds->cbData == sizeof(CopyHookData)) {
CPanel& panel = g_App.Panels[g_App.LastFocusedPanel];
CCopyToOptions options;
CopyHookData* data = static_cast<CopyHookData*>(lpCds->lpData);
options.folder = UString(data->filename);
options.showErrorMessages = true;
CRecordVector<UInt32> indices;
panel.GetOperatedItemIndices(indices);
if (indices.Size() > 0) {
panel.CopyTo(options, indices, NULL);
}
return TRUE;
}
break;
}
default:
break;
}
Expand Down
Loading

0 comments on commit 826970c

Please sign in to comment.