mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Support for file dragging in workspace panel
This commit is contained in:
parent
f928b93644
commit
f6174aade2
8 changed files with 385 additions and 95 deletions
|
@ -4,12 +4,19 @@ using System.Text;
|
|||
|
||||
namespace Beefy.events
|
||||
{
|
||||
public enum DragKind
|
||||
{
|
||||
None,
|
||||
Inside,
|
||||
Before,
|
||||
After
|
||||
}
|
||||
|
||||
public class DragEvent : Event
|
||||
{
|
||||
public float mX;
|
||||
public float mY;
|
||||
public Object mDragTarget;
|
||||
public int32 mDragTargetDir;
|
||||
public bool mDragAllowed = true;
|
||||
public DragKind mDragKind = .Inside;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace Beefy.theme.dark
|
|||
public DragEvent mCurDragEvent ~ delete _;
|
||||
public DragHelper mDragHelper ~ delete _;
|
||||
public DarkListViewItem mDragTarget;
|
||||
public int32 mDragTargetInsertDir;
|
||||
public DragKind mDragKind;
|
||||
public bool mOpenOnDoubleClick = true;
|
||||
public bool mIsBold;
|
||||
|
||||
|
@ -174,6 +174,14 @@ namespace Beefy.theme.dark
|
|||
}
|
||||
}
|
||||
|
||||
public override bool IsDragging
|
||||
{
|
||||
get
|
||||
{
|
||||
return (mDragTarget != null) && (mDragHelper.mIsDragging);
|
||||
}
|
||||
}
|
||||
|
||||
public this()
|
||||
{
|
||||
|
||||
|
@ -596,8 +604,52 @@ namespace Beefy.theme.dark
|
|||
DrawLinesGrid(g);
|
||||
|
||||
DrawChildren(g);
|
||||
|
||||
if (mDragTarget != null)
|
||||
|
||||
if (mDragTarget != null)
|
||||
{
|
||||
listView.mOnPostDraw.Add(new (g) =>
|
||||
{
|
||||
float targetX;
|
||||
float targetY;
|
||||
mDragTarget.SelfToOtherTranslate(mListView, 0, 0, out targetX, out targetY);
|
||||
|
||||
//using (g.PushTranslate(targetX, targetY))
|
||||
{
|
||||
/*if ((mUpdateCnt % 60) == 0)
|
||||
Debug.WriteLine(String.Format("{0} indent {1}", mDragTarget.mLabel, mDragTarget.mDepth));*/
|
||||
|
||||
if (mDragKind == .Inside)
|
||||
{
|
||||
using (g.PushColor(0xFF6f9761))
|
||||
{
|
||||
//g.FillRect(targetX + GS!(4), targetY, mListView.mWidth - targetX - GS!(28), GS!(22));
|
||||
//g.OutlineRect(targetX + GS!(4), targetY, mListView.mWidth - targetX - GS!(28), GS!(20));
|
||||
g.DrawButton(DarkTheme.sDarkTheme.GetImage(Focused ? DarkTheme.ImageIdx.MenuSelect : DarkTheme.ImageIdx.MenuNonFocusSelect),
|
||||
targetX + GS!(2), targetY, listView.mWidth - targetX - GS!(24));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((mDragKind == .Inside) || (mDragKind == .After)) // Inside or after
|
||||
targetY += mDragTarget.mSelfHeight;
|
||||
|
||||
if (mDragKind == .After) // After
|
||||
targetY += mDragTarget.mChildAreaHeight + mDragTarget.mBottomPadding;
|
||||
|
||||
if (mDragKind == .Inside) // Inside
|
||||
targetX += ((DarkListView)mListView).mChildIndent + mDragTarget.mChildIndent;
|
||||
|
||||
/*if (-curY + targetY > mHeight)
|
||||
wasTargetBelowBottom = true;*/
|
||||
|
||||
using (g.PushColor(0xFF95A68F))
|
||||
g.FillRect(targetX + GS!(4), targetY, mListView.mWidth - targetX - GS!(28), GS!(2));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*if (mDragTarget != null)
|
||||
{
|
||||
float targetX;
|
||||
float targetY;
|
||||
|
@ -614,20 +666,28 @@ namespace Beefy.theme.dark
|
|||
/*if ((mUpdateCnt % 60) == 0)
|
||||
Debug.WriteLine(String.Format("{0} indent {1}", mDragTarget.mLabel, mDragTarget.mDepth));*/
|
||||
|
||||
if (mDragTargetInsertDir >= 0) // Inside or after
|
||||
targetY += mDragTarget.mSelfHeight;
|
||||
|
||||
if (mDragTargetInsertDir > 0) // After
|
||||
targetY += mDragTarget.mChildAreaHeight + mDragTarget.mBottomPadding;
|
||||
if (mDragKind == .Inside)
|
||||
{
|
||||
using (g.PushColor(0xFF95A68F))
|
||||
g.FillRect(targetX + GS!(4), targetY, mListView.mWidth - targetX - GS!(28), GS!(22));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((mDragKind == .Inside) || (mDragKind == .After)) // Inside or after
|
||||
targetY += mDragTarget.mSelfHeight;
|
||||
|
||||
if (mDragKind == .After) // After
|
||||
targetY += mDragTarget.mChildAreaHeight + mDragTarget.mBottomPadding;
|
||||
|
||||
if (mDragTargetInsertDir == 0) // Inside
|
||||
targetX += ((DarkListView)mListView).mChildIndent + mDragTarget.mChildIndent;
|
||||
if (mDragKind == .Inside) // Inside
|
||||
targetX += ((DarkListView)mListView).mChildIndent + mDragTarget.mChildIndent;
|
||||
|
||||
if (-curY + targetY > mHeight)
|
||||
wasTargetBelowBottom = true;
|
||||
if (-curY + targetY > mHeight)
|
||||
wasTargetBelowBottom = true;
|
||||
|
||||
using (g.PushColor(0xFF95A68F))
|
||||
g.FillRect(targetX + 4, targetY, mListView.mWidth - targetX - 28, 2);
|
||||
using (g.PushColor(0xFF95A68F))
|
||||
g.FillRect(targetX + GS!(4), targetY, mListView.mWidth - targetX - GS!(28), GS!(2));
|
||||
}
|
||||
}
|
||||
|
||||
if (wasTargetBelowBottom)
|
||||
|
@ -635,7 +695,7 @@ namespace Beefy.theme.dark
|
|||
/*Image img = DarkTheme.sDarkTheme.GetImage(DarkTheme.ImageIdx.MoveDownArrow);
|
||||
g.Draw(img, mWidth / 2 - img.mWidth / 2, mHeight - img.mHeight);*/
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public override bool Open(bool open, bool immediate = false)
|
||||
|
@ -662,7 +722,7 @@ namespace Beefy.theme.dark
|
|||
e.mSender = GetMainItem();
|
||||
e.mDragTarget = mDragTarget;
|
||||
if (mDragHelper.mAborted)
|
||||
e.mDragAllowed = false;
|
||||
e.mDragKind = .None;
|
||||
if (listView.mOnDragEnd.HasListeners)
|
||||
listView.mOnDragEnd(e);
|
||||
}
|
||||
|
@ -723,12 +783,12 @@ namespace Beefy.theme.dark
|
|||
|
||||
float yOfs = aY - childY;
|
||||
if (yOfs < mHeight / 2)
|
||||
mDragTargetInsertDir = -1;
|
||||
mDragKind = .Before;
|
||||
else
|
||||
{
|
||||
mDragTargetInsertDir = 1;
|
||||
mDragKind = .After;
|
||||
if ((listViewItem.mOpenButton != null) && (listViewItem.mOpenButton.mIsOpen))
|
||||
mDragTargetInsertDir = 0;
|
||||
mDragKind = .None;
|
||||
}
|
||||
|
||||
delete mCurDragEvent;
|
||||
|
@ -737,12 +797,12 @@ namespace Beefy.theme.dark
|
|||
mCurDragEvent.mY = y;
|
||||
mCurDragEvent.mSender = head;
|
||||
mCurDragEvent.mDragTarget = foundWidget;
|
||||
mCurDragEvent.mDragTargetDir = mDragTargetInsertDir;
|
||||
mCurDragEvent.mDragKind = mDragKind;
|
||||
listView.mOnDragUpdate(mCurDragEvent);
|
||||
mDragTargetInsertDir = mCurDragEvent.mDragTargetDir;
|
||||
mDragKind = mCurDragEvent.mDragKind;
|
||||
|
||||
mDragTarget = mCurDragEvent.mDragTarget as DarkListViewItem;
|
||||
if (!mCurDragEvent.mDragAllowed)
|
||||
if (mCurDragEvent.mDragKind == .None)
|
||||
mDragTarget = null;
|
||||
|
||||
if (mDragTarget != null)
|
||||
|
@ -847,6 +907,7 @@ namespace Beefy.theme.dark
|
|||
|
||||
public Event<delegate void(DragEvent)> mOnDragUpdate ~ _.Dispose();
|
||||
public Event<delegate void(DragEvent)> mOnDragEnd ~ _.Dispose();
|
||||
public Event<delegate void(Graphics)> mOnPostDraw ~ _.Dispose();
|
||||
|
||||
public this()
|
||||
{
|
||||
|
@ -1004,6 +1065,13 @@ namespace Beefy.theme.dark
|
|||
}
|
||||
}
|
||||
|
||||
public override void DrawAll(Graphics g)
|
||||
{
|
||||
base.DrawAll(g);
|
||||
mOnPostDraw(g);
|
||||
mOnPostDraw.Dispose();
|
||||
}
|
||||
|
||||
public override void MouseMove(float x, float y)
|
||||
{
|
||||
base.MouseMove(x, y);
|
||||
|
|
|
@ -151,20 +151,23 @@ namespace Beefy.widgets
|
|||
|
||||
public void Update()
|
||||
{
|
||||
int32 ticksDown = mWidget.mUpdateCnt - mDownUpdateCnt;
|
||||
//int32 ticksDown = mWidget.mUpdateCnt - mDownUpdateCnt;
|
||||
|
||||
if (((mMouseFlags & MouseFlag.Left) != 0) && (ticksDown >= mMinDownTicks))
|
||||
if ((mMouseFlags & MouseFlag.Left) != 0)
|
||||
{
|
||||
if ((!mIsDragging) && (mAllowDrag))
|
||||
bool isTriggered = false;
|
||||
/*if ((mMinDownTicks > 0) && (ticksDown >= mMinDownTicks))
|
||||
isTriggered = true;*/
|
||||
if ((Math.Abs(mMouseX - mMouseDownX) >= mTriggerDist) || (Math.Abs(mMouseY - mMouseDownY) >= mTriggerDist))
|
||||
isTriggered = true;
|
||||
|
||||
if ((!mIsDragging) && (mAllowDrag) && (isTriggered))
|
||||
{
|
||||
if ((Math.Abs(mMouseX - mMouseDownX) >= mTriggerDist) || (Math.Abs(mMouseY - mMouseDownY) >= mTriggerDist))
|
||||
{
|
||||
SetHooks(true);
|
||||
mPreparingForWidgetMove = false;
|
||||
mAborted = false;
|
||||
mIsDragging = true;
|
||||
mDragInterface.DragStart();
|
||||
}
|
||||
SetHooks(true);
|
||||
mPreparingForWidgetMove = false;
|
||||
mAborted = false;
|
||||
mIsDragging = true;
|
||||
mDragInterface.DragStart();
|
||||
}
|
||||
|
||||
if (mIsDragging)
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Collections;
|
|||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using Beefy.gfx;
|
||||
using Beefy.events;
|
||||
|
||||
namespace Beefy.widgets
|
||||
{
|
||||
|
@ -111,6 +112,14 @@ namespace Beefy.widgets
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsDragging
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float LabelX { get { return 0; } }
|
||||
public virtual float LabelWidth { get { return mWidth; } }
|
||||
|
||||
|
@ -185,6 +194,16 @@ namespace Beefy.widgets
|
|||
return null;
|
||||
}
|
||||
|
||||
public int32 GetSelectedItemCount()
|
||||
{
|
||||
int32 count = 0;
|
||||
WithSelectedItems(scope [&] (item) =>
|
||||
{
|
||||
count++;
|
||||
});
|
||||
return count;
|
||||
}
|
||||
|
||||
public ListViewItem FindLastSelectedItem(bool filterToVisible = false)
|
||||
{
|
||||
ListViewItem selected = null;
|
||||
|
@ -320,13 +339,44 @@ namespace Beefy.widgets
|
|||
}
|
||||
else
|
||||
{
|
||||
SelectItemExclusively(item);
|
||||
if (item.Selected)
|
||||
item.Focused = true;
|
||||
if (item.Selected)
|
||||
{
|
||||
item.mOnMouseUp.AddFront(new => ItemMouseUpHandler);
|
||||
|
||||
var focusedItem = FindFocusedItem();
|
||||
if (focusedItem != null)
|
||||
{
|
||||
focusedItem.Focused = false;
|
||||
focusedItem.Selected = true;
|
||||
}
|
||||
item.Focused = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectItemExclusively(item);
|
||||
if (item.Selected)
|
||||
item.Focused = true;
|
||||
}
|
||||
//SelectItemExclusively(item);
|
||||
//if (item.Selected)
|
||||
//item.Focused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ItemMouseUpHandler(MouseEvent evt)
|
||||
{
|
||||
var item = evt.mSender as ListViewItem;
|
||||
if ((item.mMouseOver) && (!item.IsDragging))
|
||||
{
|
||||
SelectItemExclusively(item);
|
||||
if (item.Selected)
|
||||
item.Focused = true;
|
||||
}
|
||||
|
||||
item.mOnMouseUp.Remove(scope => ItemMouseUpHandler, true);
|
||||
}
|
||||
|
||||
public virtual void Clear()
|
||||
{
|
||||
if (mChildItems == null)
|
||||
|
@ -673,11 +723,6 @@ namespace Beefy.widgets
|
|||
}
|
||||
}
|
||||
|
||||
public class ListViewDragData
|
||||
{
|
||||
List<ListViewItem> mDragItems;
|
||||
}
|
||||
|
||||
public abstract class ListView : ScrollableWidget
|
||||
{
|
||||
public List<ListViewColumn> mColumns = new List<ListViewColumn>() ~ DeleteContainerAndItems!(_);
|
||||
|
|
|
@ -114,6 +114,28 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public void AddFront(T ownDelegate) mut
|
||||
{
|
||||
Object data = Target;
|
||||
if (data == null)
|
||||
{
|
||||
Target = ownDelegate;
|
||||
return;
|
||||
}
|
||||
|
||||
if (var list = data as List<T>)
|
||||
{
|
||||
list.Insert(0, ownDelegate);
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<T>();
|
||||
list.Add(ownDelegate);
|
||||
list.Add((T)data);
|
||||
Target = list;
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(T compareDelegate, bool deleteDelegate = false) mut
|
||||
{
|
||||
Object data = Target;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue