internal DockOperation GetDockOperation(DragEventArgs e) { DockOperation result = DockOperation.Window; if (InvalidateIndicator(_leftSelector, _leftIndicator, e)) { result = DockOperation.Left; } if (InvalidateIndicator(_rightSelector, _rightIndicator, e)) { result = DockOperation.Right; } if (InvalidateIndicator(_topSelector, _topIndicator, e)) { result = DockOperation.Top; } if (InvalidateIndicator(_bottomSelector, _bottomIndicator, e)) { result = DockOperation.Bottom; } if (InvalidateIndicator(_centerSelector, _centerIndicator, e)) { result = DockOperation.Fill; } return(result); }
private bool Validate(Point point, DockOperation operation, DragAction dragAction, IVisual relativeTo) { if (_targetDropControl is null) { return(false); } var layout = _hostWindow.Window?.Layout; if (layout?.ActiveDockable is { } sourceDockable&& _targetDropControl.DataContext is IDockable targetDockable) { DockManager.Position = DockHelpers.ToDockPoint(point); if (relativeTo.VisualRoot is null) { return(false); } var screenPoint = relativeTo.PointToScreen(point).ToPoint(1.0); DockManager.ScreenPosition = DockHelpers.ToDockPoint(screenPoint); return(DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: false)); } return(false); }
/// <inheritdoc/> public void Enter(object sender, DragEventArgs e, object sourceContext, object targetContext) { DockOperation operation = DockOperation.Fill; bool isView = sourceContext is IView view; if (Validate(sender, e, sourceContext, targetContext, operation) == false) { if (!isView) { e.DragEffects = DragDropEffects.None; e.Handled = true; } } else { if (isView && sender is DockPanel panel) { if (sender is IVisual visual) { _adornerHelper.AddAdorner(visual); } } e.DragEffects |= DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link; e.Handled = true; } }
/// <inheritdoc/> public void Drop(object sender, DragEventArgs e, object sourceContext, object targetContext) { DockOperation operation = DockOperation.Fill; bool isView = sourceContext is IView view; if (_adornerHelper.Adorner is DockTarget target) { operation = target.GetDockOperation(e); } if (isView && sender is DockPanel panel) { _adornerHelper.RemoveAdorner(sender as IVisual); } if (Execute(sender, e, targetContext, sourceContext, operation) == false) { if (!isView) { e.DragEffects = DragDropEffects.None; e.Handled = true; } } else { e.DragEffects |= DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link; e.Handled = true; } }
private bool Validate(Point point, DockOperation operation, DragAction dragAction, IVisual relativeTo) { if (_dragControl == null || _dropControl == null) { return(false); } if (_dragControl.DataContext is IDockable sourceDockable && _dropControl.DataContext is IDockable targetDockable) { DockManager.Position = DockHelpers.ToDockPoint(point); DockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0)); return(DockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: false)); } return(false); }
private bool Execute(Point point, DockOperation operation, DragAction dragAction, IVisual relativeTo) { if (_dragControl == null || _dropControl == null) { return(false); } if (_dragControl.DataContext is IDockable sourceDockable && _dropControl.DataContext is IDockable targetDockable) { Debug.WriteLine($"Execute : {point} : {operation} : {dragAction} : {sourceDockable.Title} -> {targetDockable.Title}"); _dockManager.Position = DockHelpers.ToDockPoint(point); _dockManager.ScreenPosition = DockHelpers.ToDockPoint(relativeTo.PointToScreen(point).ToPoint(1.0)); return(_dockManager.ValidateDockable(sourceDockable, targetDockable, dragAction, operation, bExecute: true)); } return(false); }
/// <inheritdoc/> public virtual void Split(IDock dock, IView view, DockOperation operation) { switch (operation) { case DockOperation.Left: case DockOperation.Right: case DockOperation.Top: case DockOperation.Bottom: { var layout = CreateSplitLayout(dock, view, dock.Context, operation); Replace(dock, layout); Update(layout, dock.Context, dock.Parent); } break; default: throw new NotSupportedException($"Not support dock operation: {operation}."); } }
/// <inheritdoc/> public bool Validate(IView sourceView, IView targetView, DragAction action, DockOperation operation, bool bExecute) { switch (sourceView) { case IRootDock sourceRoot: { return(ValidateRoot(sourceRoot, targetView, action, operation, bExecute)); } case IToolTab sourceToolTab: { return(ValidateToolTab(sourceToolTab, targetView, action, operation, bExecute)); } case IDocumentTab sourceDocumentTab: { return(ValidateDocumentTab(sourceDocumentTab, targetView, action, operation, bExecute)); } case ILayoutDock sourceLayout: { return(ValidateLayout(sourceLayout, targetView, action, operation, bExecute)); } case ITabDock sourceTab: { return(ValidateTab(sourceTab, targetView, action, operation, bExecute)); } default: { #if DEBUG Console.WriteLine($"Not supported type {sourceView.GetType()}: {sourceView} -> {targetView}"); #endif return(false); } } }
/// <inheritdoc/> public void Over(object sender, DragEventArgs e, object sourceContext, object targetContext) { bool isView = sourceContext is IView view; DockOperation operation = DockOperation.Fill; if (_adornerHelper.Adorner is DockTarget target) { operation = target.GetDockOperation(e); } if (Validate(sender, e, sourceContext, targetContext, operation) == false) { if (!isView) { e.DragEffects = DragDropEffects.None; e.Handled = true; } } else { e.DragEffects |= DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link; e.Handled = true; } }
internal bool DockIntoWindow(IView sourceView, IView targetView, DragAction action, DockOperation operation, bool bExecute) { #if DEBUG Console.WriteLine($"{nameof(DockIntoWindow)}: {sourceView.Title} -> {targetView.Title}"); #endif switch (operation) { case DockOperation.Fill: { if (sourceView != targetView && sourceView.Parent != targetView && sourceView.Parent is IDock sourceViewParent && sourceViewParent.Factory is IDockFactory factory && factory.FindRoot(sourceView) is IDock root && root.CurrentView is IDock currentViewRoot) { if (bExecute) { factory.RemoveView(sourceView); var window = factory.CreateWindowFrom(sourceView); if (window != null) { factory.AddWindow(currentViewRoot, window, sourceView.Context); window.X = ScreenPosition.X; window.Y = ScreenPosition.Y; window.Width = 300; window.Height = 400; window.Present(false); } } return(true); } break; } } return(false); }
internal bool DockIntoTab(ITab sourceTab, ITabDock targetTabParent, DragAction action, DockOperation operation, bool bExecute) { #if DEBUG Console.WriteLine($"{nameof(DockIntoTab)}: {sourceTab.Title} -> {targetTabParent.Title}"); #endif if (sourceTab.Parent is ITabDock sourceTabParent) { IView targetTab = targetTabParent.Views.LastOrDefault(); switch (action) { case DragAction.Copy: { if (bExecute) { // TODO: Clone item. } return(true); } case DragAction.Move: { switch (operation) { case DockOperation.Fill: { if (sourceTabParent.Factory is IDockFactory factory) { if (bExecute) { factory.MoveView(sourceTabParent, targetTabParent, sourceTab, targetTab); } return(true); } return(false); } case DockOperation.Left: case DockOperation.Right: case DockOperation.Top: case DockOperation.Bottom: { switch (sourceTab) { case IToolTab toolTab: { if (bExecute) { if (targetTabParent.Factory is IDockFactory factory) { factory.RemoveView(sourceTab); IDock tool = factory.CreateToolDock(); tool.Id = nameof(IToolDock); tool.Title = nameof(IToolDock); tool.CurrentView = sourceTab; tool.Views = factory.CreateList <IView>(); tool.Views.Add(sourceTab); factory.Split(targetTabParent, tool, operation); } } return(true); } case IDocumentTab documentTab: { if (bExecute) { if (targetTabParent.Factory is IDockFactory factory) { factory.RemoveView(sourceTab); IDock document = factory.CreateDocumentDock(); document.Id = nameof(IDocumentDock); document.Title = nameof(IDocumentDock); document.CurrentView = sourceTab; document.Views = factory.CreateList <IView>(); document.Views.Add(sourceTab); factory.Split(targetTabParent, document, operation); } } return(true); } default: { #if DEBUG Console.WriteLine($"Not supported tab type {sourceTab.GetType().Name} to splitting : {sourceTab} -> {targetTabParent}"); #endif return(false); } } } case DockOperation.Window: { return(false); } } return(false); } case DragAction.Link: { if (bExecute) { if (sourceTabParent.Factory is IDockFactory factory) { factory.SwapView(sourceTabParent, targetTabParent, sourceTab, targetTab); } } return(true); } } return(false); } return(false); }
internal void SplitDocumentDockable(IDockable sourceDockable, IDock sourceDockableOwner, IDock targetDock, DockOperation operation) { if (targetDock.Factory is IFactory factory) { IDock documentDock = factory.CreateDocumentDock(); documentDock.Id = nameof(IDocumentDock); documentDock.Title = nameof(IDocumentDock); documentDock.VisibleDockables = factory.CreateList <IDockable>(); factory.MoveDockable(sourceDockableOwner, documentDock, sourceDockable, null); factory.SplitToDock(targetDock, documentDock, operation); } }
///<inheritdoc/> public bool ValidateDock(IDock sourceDock, IDockable targetDockable, DragAction action, DockOperation operation, bool bExecute) { switch (targetDockable) { case IRootDock _: return(DockDockableIntoWindow(sourceDock, targetDockable, operation, bExecute)); case IToolDock toolDock: if (sourceDock == toolDock) { return(false); } return(DockDockable(sourceDock, targetDockable, toolDock, action, operation, bExecute)); case IDocumentDock documentDock: if (sourceDock == documentDock) { return(false); } return(DockDockable(sourceDock, targetDockable, documentDock, action, operation, bExecute)); case IPinDock pinDock: if (sourceDock == pinDock) { return(false); } return(DockDockable(sourceDock, targetDockable, pinDock, action, operation, bExecute)); case IProportionalDock proportionalDock: if (sourceDock == proportionalDock) { return(false); } return(DockDockable(sourceDock, targetDockable, proportionalDock, action, operation, bExecute)); default: return(false); } }
///<inheritdoc/> public bool ValidateTool(ITool sourceTool, IDockable targetDockable, DragAction action, DockOperation operation, bool bExecute) { switch (targetDockable) { case IRootDock _: return(DockDockableIntoWindow(sourceTool, targetDockable, operation, bExecute)); case IToolDock toolDock: return(DockDockableIntoDock(sourceTool, toolDock, action, operation, bExecute)); case IDocumentDock documentDock: return(DockDockableIntoDock(sourceTool, documentDock, action, operation, bExecute)); case IPinDock pinDock: return(DockDockableIntoDock(sourceTool, pinDock, action, operation, bExecute)); case ITool tool: return(DockDockableIntoDockable(sourceTool, tool, action, bExecute)); case IDocument document: return(DockDockableIntoDockable(sourceTool, document, action, bExecute)); default: return(false); } }
internal bool ValidateLayout(ILayoutDock sourceLayout, IView targetView, DragAction action, DockOperation operation, bool bExecute) { switch (targetView) { case IRootDock targetRoot: { return(false); } case IToolTab sourceToolTab: { return(false); } case IDocumentTab sourceDocumentTab: { return(false); } case ILayoutDock targetLayout: { return(false); } case ITabDock targetTab: { return(false); } default: { Logger.Log($"Not supported type {targetView.GetType()}: {sourceLayout} -> {targetView}"); return(false); } } }
internal bool DockDockintoDock(IDock sourceDock, IDock targetDock, DragAction action, DockOperation operation, bool bExecute) { var visible = sourceDock.VisibleDockables.ToList(); if (visible.Count == 1) { if (DockDockableIntoDock(visible.First(), targetDock, action, operation, bExecute) == false) { return(false); } } else { if (DockDockableIntoDock(visible.First(), targetDock, action, operation, bExecute) == false) { return(false); } foreach (var dockable in visible.Skip(1)) { if (DockDockableIntoDockable(dockable, visible.First(), action, bExecute) == false) { return(false); } } } return(true); }
internal bool DockDockable(IDock sourceDock, IDockable targetDockable, IDock targetDock, DragAction action, DockOperation operation, bool bExecute) { switch (operation) { case DockOperation.Fill: return(DockDockableIntoDockVisible(sourceDock, targetDock, action, operation, bExecute)); case DockOperation.Window: return(DockDockableIntoWindow(sourceDock, targetDockable, operation, bExecute)); default: return(DockDockintoDock(sourceDock, targetDock, action, operation, bExecute)); } }
internal bool ValidateTab(ITabDock sourceTab, IView targetView, DragAction action, DockOperation operation, bool bExecute) { switch (targetView) { case IRootDock targetRoot: { return(DockIntoWindow(sourceTab, targetView, action, operation, bExecute)); } case IToolTab sourceToolTab: { return(false); } case IDocumentTab sourceDocumentTab: { return(false); } case ILayoutDock targetLayout: { return(false); } case ITabDock targetTab: { if (bExecute) { switch (operation) { case DockOperation.Fill: foreach (var tab in sourceTab.Views.OfType <ITab>().ToList()) { DockIntoTab(tab, targetTab, action, operation, bExecute); } return(true); case DockOperation.Window: { return(DockIntoWindow(sourceTab, targetView, action, operation, bExecute)); } default: { // when we are splitting. var toMove = sourceTab.Views.OfType <ITab>().ToList(); if (toMove.Count == 1) { DockIntoTab(toMove.First(), targetTab, action, operation, bExecute); } else { DockIntoTab(toMove.First(), targetTab, action, operation, bExecute); foreach (var tab in toMove.Skip(1)) { DockIntoTab(tab, toMove.First(), action, DockOperation.Fill, bExecute); } } } return(true); } } return(true); } default: { Logger.Log($"Not supported type {targetView.GetType()}: {sourceTab} -> {targetView}"); return(false); } } }
///<inheritdoc/> public bool ValidateDocument(IDocument sourceDocument, IDockable targetDockable, DragAction action, DockOperation operation, bool bExecute) { switch (targetDockable) { case IRootDock _: return(DockDockableIntoWindow(sourceDocument, targetDockable, operation, bExecute)); case IDocumentDock documentDock: return(DockDockableIntoDock(sourceDocument, documentDock, action, operation, bExecute)); case IDocument document: return(DockDockableIntoDockable(sourceDocument, document, action, bExecute)); default: return(false); } }
internal bool SplitDockable(IDockable sourceDockable, IDock sourceDockableOwner, IDock targetDock, DockOperation operation, bool bExecute) { switch (sourceDockable) { case ITool _: if (sourceDockableOwner == targetDock) { if (targetDock.VisibleDockables?.Count == 1) { return(false); } } if (bExecute) { SplitToolDockable(sourceDockable, sourceDockableOwner, targetDock, operation); } return(true); case IDocument _: if (sourceDockableOwner == targetDock) { if (targetDock.VisibleDockables?.Count == 1) { return(false); } } if (bExecute) { SplitDocumentDockable(sourceDockable, sourceDockableOwner, targetDock, operation); } return(true); default: return(false); } }
///<inheritdoc/> public bool ValidateDockable(IDockable sourceDockable, IDockable targetDockable, DragAction action, DockOperation operation, bool bExecute) { switch (sourceDockable) { case IToolDock toolDock: return(ValidateDock(toolDock, targetDockable, action, operation, bExecute)); case IDocumentDock documentDock: return(ValidateDock(documentDock, targetDockable, action, operation, bExecute)); case IPinDock pinDock: return(ValidateDock(pinDock, targetDockable, action, operation, bExecute)); case IProportionalDock proportionalDock: return(ValidateDock(proportionalDock, targetDockable, action, operation, bExecute)); case ITool tool: return(ValidateTool(tool, targetDockable, action, operation, bExecute)); case IDocument document: return(ValidateDocument(document, targetDockable, action, operation, bExecute)); default: return(false); } }
internal bool DockDockableIntoWindow(IDockable sourceDockable, IDockable targetDockable, DockOperation operation, bool bExecute) { switch (operation) { case DockOperation.Window: if (sourceDockable == targetDockable) { return(false); } if (sourceDockable.Owner is IDock sourceDockableOwner) { if (sourceDockableOwner.Factory is IFactory factory) { if (factory.FindRoot(sourceDockable) is IRootDock root && root.ActiveDockable is IDock targetWindowOwner) { if (bExecute) { factory.SplitToWindow(targetWindowOwner, sourceDockable, ScreenPosition.X, ScreenPosition.Y, 300, 400); } return(true); } } } return(false); default: return(false); } }
/// <inheritdoc/> public bool Execute(object sourceContext, object targetContext, object sender, DockOperation operation, DragEventArgs e) { // FIXME: //if (context is ProjectEditor editor) //{ // return Validate(editor, sender, e, true); //} return(false); }
internal bool DockDockable(IDockable sourceDockable, IDock sourceDockableOwner, IDock targetDock, DockOperation operation, bool bExecute) { switch (operation) { case DockOperation.Fill: return(MoveDockable(sourceDockable, sourceDockableOwner, targetDock, bExecute)); case DockOperation.Left: case DockOperation.Right: case DockOperation.Top: case DockOperation.Bottom: return(SplitDockable(sourceDockable, sourceDockableOwner, targetDock, operation, bExecute)); case DockOperation.Window: return(DockDockableIntoWindow(sourceDockable, targetDock, operation, bExecute)); default: return(false); } }
internal bool DockIntoTab(ITab sourceTab, ITab targetTab, DragAction action, DockOperation operation, bool bExecute) { #if DEBUG Console.WriteLine($"{nameof(DockIntoTab)}: {sourceTab.Title} -> {targetTab.Title}"); #endif if (sourceTab.Parent is ITabDock sourceTabParent && targetTab.Parent is ITabDock targetTabParent) { if (sourceTabParent == targetTabParent) { switch (action) { case DragAction.Copy: { if (bExecute) { // TODO: Clone item. } return(true); } case DragAction.Move: { if (bExecute) { if (sourceTabParent.Factory is IDockFactory factory) { factory.MoveView(sourceTabParent, sourceTab, targetTab); } } return(true); } case DragAction.Link: { if (bExecute) { if (sourceTabParent.Factory is IDockFactory factory) { factory.SwapView(sourceTabParent, sourceTab, targetTab); } } return(true); } } return(false); } else { switch (action) { case DragAction.Copy: { if (bExecute) { // TODO: Clone item. } return(true); } case DragAction.Move: { if (bExecute) { if (sourceTabParent.Factory is IDockFactory factory) { factory.MoveView(sourceTabParent, targetTabParent, sourceTab, targetTab); } } return(true); } case DragAction.Link: { if (bExecute) { if (sourceTabParent.Factory is IDockFactory factory) { factory.SwapView(sourceTabParent, targetTabParent, sourceTab, targetTab); } } return(true); } } return(false); } } return(false); }
internal bool DockDockableIntoDock(IDockable sourceDockable, IDock targetDock, DragAction action, DockOperation operation, bool bExecute) { if (sourceDockable.Owner is IDock sourceDockableOwner) { return(DockDockableIntoDock(sourceDockable, sourceDockableOwner, targetDock, action, operation, bExecute)); } return(false); }
internal bool ValidateTab(ITabDock sourceTab, IView targetView, DragAction action, DockOperation operation, bool bExecute) { switch (targetView) { case IRootDock targetRoot: { return(DockIntoWindow(sourceTab, targetView, action, operation, bExecute)); } case IToolTab sourceToolTab: { return(false); } case IDocumentTab sourceDocumentTab: { return(false); } case ILayoutDock targetLayout: { return(false); } case ITabDock targetTab: { return(false); } default: { #if DEBUG Console.WriteLine($"Not supported type {targetView.GetType()}: {sourceTab} -> {targetView}"); #endif return(false); } } }
internal bool DockDockableIntoDock(IDockable sourceDockable, IDock sourceDockableOwner, IDock targetDock, DragAction action, DockOperation operation, bool bExecute) { switch (action) { case DragAction.Copy: return(false); case DragAction.Move: return(DockDockable(sourceDockable, sourceDockableOwner, targetDock, operation, bExecute)); case DragAction.Link: return(SwapDockable(sourceDockable, sourceDockableOwner, targetDock, bExecute)); default: return(false); } }
private bool InvalidateIndicator(Control?selector, Grid?indicator, Point point, IVisual relativeTo, DockOperation operation, DragAction dragAction, Func <Point, DockOperation, DragAction, IVisual, bool> validate) { if (selector != null && indicator != null) { var selectorPoint = relativeTo.TranslatePoint(point, selector); if (selectorPoint != null && selector.InputHitTest(selectorPoint.Value) != null && validate(point, operation, dragAction, relativeTo) == true) { indicator.Opacity = 0.5; return(true); } else { indicator.Opacity = 0; return(false); } } return(false); }
internal bool DockDockableIntoDockVisible(IDock sourceDock, IDock targetDock, DragAction action, DockOperation operation, bool bExecute) { var visible = sourceDock.VisibleDockables.ToList(); foreach (var dockable in visible) { if (DockDockableIntoDock(dockable, targetDock, action, operation, bExecute) == false) { return(false); } } return(true); }