ADD: Drag and drop - option to move instead copy (fixes #271)

(cherry picked from commit c42011485b)
This commit is contained in:
Alexander Koblov 2024-10-01 21:44:14 +03:00
commit f02511c0b3
4 changed files with 26 additions and 15 deletions

View file

@ -698,7 +698,8 @@ begin
DropParams := TDropParams.Create(
SourceFiles, // Will be freed automatically.
GetDropEffectByKeyAndMouse(GetKeyShiftStateEx,
SourcePanel.FMainControlLastMouseButton),
SourcePanel.FMainControlLastMouseButton,
gDefaultDropEffect),
MainControl.ClientToScreen(Classes.Point(X, Y)),
True,
SourcePanel, Self,
@ -1400,7 +1401,7 @@ var
begin
if (DragManager <> nil) and DragManager.IsDragging then
begin
DropEffect := GetDropEffectByKey(Shift);
DropEffect := GetDropEffectByKey(Shift, gDefaultDropEffect);
if DropEffect = DropMoveEffect then
TControlHandlersHack(MainControl).DragCursor:= crArrowMove

View file

@ -1478,7 +1478,7 @@ begin
TargetPath := IncludeTrailingPathDelimiter(TargetPath);
if not Assigned(TargetFileSource) then
TargetFileSource := TFileSystemFileSource.GetFileSource;
case GetDropEffectByKeyAndMouse(GetKeyShiftStateEx, mbLeft) of
case GetDropEffectByKeyAndMouse(GetKeyShiftStateEx, mbLeft, gDefaultDropEffect) of
DropCopyEffect:
Self.CopyFiles(ActiveFrame.FileSource, TargetFileSource, SourceFiles, TargetPath, gShowDialogOnDragDrop);
DropMoveEffect:
@ -1886,7 +1886,7 @@ begin
DropParams := TDropParams.Create(
Files,
GetDropEffectByKeyAndMouse(GetKeyShiftState, mbLeft),
GetDropEffectByKeyAndMouse(GetKeyShiftState, mbLeft, gDefaultDropEffect),
Point, False,
nil, TargetFileView,
TargetFileView.FileSource,
@ -2687,7 +2687,7 @@ begin
begin
TargetPath := ANotebook.View[ATabIndex].CurrentPath;
TargetFileSource := ANotebook.View[ATabIndex].FileSource;
case GetDropEffectByKeyAndMouse(GetKeyShiftStateEx, mbLeft) of
case GetDropEffectByKeyAndMouse(GetKeyShiftStateEx, mbLeft, gDefaultDropEffect) of
DropCopyEffect:
Self.CopyFiles(ActiveFrame.FileSource, TargetFileSource, SourceFiles, TargetPath, gShowDialogOnDragDrop);
DropMoveEffect:

View file

@ -163,8 +163,10 @@ type
{ Analyzes keyboard modifier keys (Shift, Ctrl, etc.) and mouse button nr
and returns the appropriate drop effect. }
function GetDropEffectByKeyAndMouse(ShiftState: TShiftState;
MouseButton: TMouseButton): TDropEffect;
function GetDropEffectByKey(ShiftState: TShiftState): TDropEffect;
MouseButton: TMouseButton;
DefaultEffect: Boolean): TDropEffect;
function GetDropEffectByKey(ShiftState: TShiftState;
DefaultEffect: Boolean): TDropEffect;
var
{ If set to True, then dragging is being transformed: internal to external or vice-versa. }
@ -192,6 +194,8 @@ uses
uDragDropQt;
{$ENDIF}
const
DropDefaultEffect: array[Boolean] of TDropEffect = (DropMoveEffect, DropCopyEffect);
{ ---------- TDragDropSource ---------- }
@ -386,19 +390,20 @@ begin
{$ENDIF}
end;
function GetDropEffectByKey(ShiftState: TShiftState): TDropEffect;
function GetDropEffectByKey(ShiftState: TShiftState;
DefaultEffect: Boolean): TDropEffect;
const
ssBoth = [ssLeft, ssRight];
begin
if (ssBoth * ShiftState = ssBoth) then
Exit(DropMoveEffect);
Exit(DropDefaultEffect[not DefaultEffect]);
ShiftState := [ssModifier, ssShift, ssAlt] * ShiftState;
if ShiftState = [] then
Result := DropCopyEffect // default to Copy when no keys pressed
Result := DropDefaultEffect[DefaultEffect] // default to Copy when no keys pressed
else if ShiftState = [ssShift] then
Result := DropMoveEffect
Result := DropDefaultEffect[not DefaultEffect]
else if ShiftState = [ssModifier] then
Result := DropMoveEffect
Result := DropDefaultEffect[not DefaultEffect]
else if ShiftState = [ssAlt] then
Result := DropAskEffect
else if ShiftState = [ssModifier, ssShift] then
@ -408,15 +413,16 @@ begin
end;
function GetDropEffectByKeyAndMouse(ShiftState: TShiftState;
MouseButton: TMouseButton): TDropEffect;
MouseButton: TMouseButton;
DefaultEffect: Boolean): TDropEffect;
begin
case MouseButton of
mbLeft:
begin
if ShiftState = [ssRight] then
Result := DropMoveEffect
Result := DropDefaultEffect[not DefaultEffect]
else
Result := GetDropEffectByKey(ShiftState);
Result := GetDropEffectByKey(ShiftState, DefaultEffect);
end;
mbMiddle:

View file

@ -482,6 +482,7 @@ var
gShowCopyTabSelectPanel:boolean;
gUseTrash : Boolean; // if using delete to trash by default
gRenameSelOnlyName:boolean;
gDefaultDropEffect: Boolean;
gShowDialogOnDragDrop: Boolean;
gDragAndDropDesiredTextFormat:array[0..pred(NbOfDropTextFormat)] of tDesiredDropTextFormat;
gDragAndDropAskFormatEachTime: Boolean;
@ -1913,6 +1914,7 @@ begin
gUseTrash := True;
gSkipFileOpError := False;
gTypeOfDuplicatedRename := drLegacyWithCopy;
gDefaultDropEffect:= True;
gShowDialogOnDragDrop := True;
gDragAndDropDesiredTextFormat[DropTextRichText_Index].Name:='Richtext format';
gDragAndDropDesiredTextFormat[DropTextRichText_Index].DesireLevel:=0;
@ -2874,6 +2876,7 @@ begin
gUseTrash := GetValue(Node, 'UseTrash', gUseTrash);
gSkipFileOpError := GetValue(Node, 'SkipFileOpError', gSkipFileOpError);
gTypeOfDuplicatedRename := tDuplicatedRename(GetValue(Node, 'TypeOfDuplicatedRename', Integer(gTypeOfDuplicatedRename)));
gDefaultDropEffect := GetValue(Node, 'DefaultDropEffect', gDefaultDropEffect);
gShowDialogOnDragDrop := GetValue(Node, 'ShowDialogOnDragDrop', gShowDialogOnDragDrop);
gDragAndDropDesiredTextFormat[DropTextRichText_Index].DesireLevel := GetValue(Node, 'DragAndDropTextRichtextDesireLevel', gDragAndDropDesiredTextFormat[DropTextRichText_Index].DesireLevel);
gDragAndDropDesiredTextFormat[DropTextHtml_Index].DesireLevel := GetValue(Node, 'DragAndDropTextHtmlDesireLevel',gDragAndDropDesiredTextFormat[DropTextHtml_Index].DesireLevel);
@ -3543,6 +3546,7 @@ begin
SetValue(Node, 'UseTrash', gUseTrash);
SetValue(Node, 'SkipFileOpError', gSkipFileOpError);
SetValue(Node, 'TypeOfDuplicatedRename', Integer(gTypeOfDuplicatedRename));
SetValue(Node, 'DefaultDropEffect', gDefaultDropEffect);
SetValue(Node, 'ShowDialogOnDragDrop', gShowDialogOnDragDrop);
SetValue(Node, 'DragAndDropTextRichtextDesireLevel', gDragAndDropDesiredTextFormat[DropTextRichText_Index].DesireLevel);
SetValue(Node, 'DragAndDropTextHtmlDesireLevel',gDragAndDropDesiredTextFormat[DropTextHtml_Index].DesireLevel);