Refactor MoveSelectionTo a bit to reuse other code instead of duplicating most of it practically verbatim with different variable names.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29092 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Rene Gollent 2009-01-29 23:49:57 +00:00
parent 12f46bebca
commit 994541a836
1 changed files with 1 additions and 140 deletions

View File

@ -4488,147 +4488,8 @@ BPoseView::MoveSelectionTo(BPoint dropPt, BPoint clickPt,
if (srcWindow != window && !TargetModel()->IsDropTarget())
return;
// if drop was done with control key or secondary button
// then we need to show a context menu for drop location
uint32 buttons = (uint32)window->CurrentMessage()->FindInt32("buttons");
bool createLink = false;
bool forceCopy = false;
bool forceMove = false;
bool createRelativeLink = false;
bool dropOnGrid = (modifiers() & B_COMMAND_KEY) != 0;
if ((buttons & B_SECONDARY_MOUSE_BUTTON) || (modifiers() & B_CONTROL_KEY)) {
switch (window->ShowDropContextMenu(dropPt)) {
case kCreateRelativeLink:
createRelativeLink = true;
break;
case kCreateLink:
createLink = true;
break;
case kMoveSelectionTo:
forceMove = true;
break;
case kCopySelectionTo:
if (srcWindow == window) {
DuplicateSelection(&clickPt, &dropPt);
return;
}
forceCopy = true;
break;
case kCancelButton:
default:
// user canceled context menu
return;
}
}
if (!createLink && !createRelativeLink && srcWindow == window) { // dropped in same window
if (ViewMode() == kListMode) // can't move in list view
return;
BPoint delta(dropPt - clickPt);
int32 count = fSelectionList->CountItems();
for (int32 index = 0; index < count; index++) {
BPose *pose = fSelectionList->ItemAt(index);
// remove pose from VSlist before changing location
// so that we "find" the correct pose to remove
// need to do this because bsearch uses top of pose
// to locate pose to remove
RemoveFromVSList(pose);
BRect oldBounds(pose->CalcRect(this));
BPoint location(pose->Location() + delta);
if (dropOnGrid)
location = PinToGrid(location, fGrid, fOffset);
pose->MoveTo(location, this);
RemoveFromExtent(oldBounds);
AddToExtent(pose->CalcRect(this));
// remove and reinsert pose to keep VSlist sorted
AddToVSList(pose);
}
} else {
AutoLock<BWindow> lock(srcWindow);
if (!lock)
return;
// dropped from another window
// CopyTask will delete pointList
PoseList *selectionList = srcWindow->PoseView()->SelectionList();
int32 count = selectionList->CountItems();
BList *pointList = GetDropPointList(clickPt, dropPt, selectionList,
srcWindow->PoseView()->ViewMode() == kListMode, dropOnGrid);
// perform asynch copy/move
forceCopy = forceCopy || (modifiers() & B_OPTION_KEY);
bool okToMove = true;
BEntry *destEntry = new BEntry(TargetModel()->EntryRef());
bool destIsTrash = FSIsTrashDir(destEntry);
// don't prompt if we're going to end up copying anyway
if (srcWindow->PoseView()->TargetModel()->IsQuery()
&& !forceCopy
&& !createLink
&& !destIsTrash) {
srcWindow->UpdateIfNeeded();
okToMove = (new BAlert("", kOkToMoveStr, "Cancel", "Move", NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go() == 1;
}
// can't copy items into the trash
if (forceCopy && destIsTrash) {
(new BAlert("", kNoCopyToTrashStr, "Cancel", NULL, NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
okToMove = false;
}
// can't create symlinks into the trash
if ((createLink || createRelativeLink) && destIsTrash) {
(new BAlert("", kNoLinkToTrashStr, "Cancel", NULL, NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
okToMove = false;
}
if (okToMove) {
// create dup Model list, dest Model for CopyTask
BObjectList<entry_ref> *srcList = new BObjectList<entry_ref>(count, true);
CopySelectionListToBListAsEntryRefs(selectionList, srcList);
uint32 moveMode;
if (forceCopy)
moveMode = kCopySelectionTo;
else if (forceMove)
moveMode = kMoveSelectionTo;
else if (createRelativeLink)
moveMode = kCreateRelativeLink;
else if (createLink)
moveMode = kCreateLink;
else {
moveMode = kMoveSelectionTo;
entry_ref *srcRef = srcList->ItemAt(0);
BDirectory destDir (destEntry);
struct stat deststat;
destDir.GetStat(&deststat);
if (srcRef->device != deststat.st_dev)
moveMode = kCopySelectionTo;
}
FSMoveToFolder(srcList, destEntry, moveMode, pointList);
} else {
if (pointList) {
pointList->DoForEach(delete_point);
delete pointList;
}
delete destEntry;
}
}
MoveSelectionInto(TargetModel(), srcWindow, window, buttons, dropPt, false);
}