Esempio n. 1
0
        private static MenuItem CreateMenuItem(DockTabItem dockTabItem)
        {
            var menuItem = new MenuItem
            {
                Header = new TextBlock {
                    Text = dockTabItem.Title
                },                                                   // Use TextBlock to prevent access keys!
                Command       = DockCommands.Show,
                CommandTarget = dockTabItem,
                IsChecked     = dockTabItem.IsSelected,
                IsEnabled     = dockTabItem.IsEnabled,
            };

            if (dockTabItem.Icon is ImageSource || dockTabItem.Icon is MultiColorGlyph)
            {
                menuItem.Icon = new Icon {
                    Source = dockTabItem.Icon
                }
            }
            ;
            else
            {
                menuItem.Icon = new ContentControl {
                    Content = dockTabItem.Icon
                }
            };

            return(menuItem);
        }

        #endregion
    }
Esempio n. 2
0
        private static MenuItem CreateMenuItem(DockTabItem dockTabItem)
        {
            var menuItem = new MenuItem
            {
                Header = new TextBlock { Text = dockTabItem.Title }, // Use TextBlock to prevent access keys!
                Command = DockCommands.Show,
                CommandTarget = dockTabItem,
                IsChecked = dockTabItem.IsSelected,
                IsEnabled = dockTabItem.IsEnabled,
            };

            if (dockTabItem.Icon is ImageSource || dockTabItem.Icon is MultiColorGlyph)
                menuItem.Icon = new Icon { Source = dockTabItem.Icon };
            else
                menuItem.Icon = new ContentControl { Content = dockTabItem.Icon };

            return menuItem;
        }
Esempio n. 3
0
        /// <summary>
        /// Registers the specified <see cref="DockTabItem"/>.
        /// </summary>
        /// <param name="dockTabItem">The <see cref="DockTabItem"/> to add.</param>
        internal void Register(DockTabItem dockTabItem)
        {
            Debug.Assert(dockTabItem != null);

            if (!_dockTabItems.Contains(dockTabItem))
            {
                _dockTabItems.Add(dockTabItem);
            }

            // Activate the DockTabItem if it is the IDockControl.ActiveDockTabItem.
            if (DockStrategy != null)
            {
                var dockTabItemVM = dockTabItem.GetViewModel();
                if (dockTabItemVM != null && DockStrategy.DockControl.ActiveDockTabItem == dockTabItemVM)
                {
                    dockTabItem.Activate();
                }
            }
        }
Esempio n. 4
0
 internal static IDockTabItem GetViewModel(this DockTabItem view)
 {
     return(GetViewModel <IDockTabItem>(view));
 }
Esempio n. 5
0
        /// <summary>
        /// Starts a drag operation.
        /// </summary>
        /// <param name="floatWindow">The <see cref="FloatWindow"/> to be dragged.</param>
        /// <param name="dockTabPane">The <see cref="DockTabPane"/> to be dragged.</param>
        /// <param name="dockTabItem">The <see cref="DockTabItem"/> to be dragged.</param>
        /// <returns>
        /// <see langword="true" /> if the drag operation has been started; otherwise,
        /// <see langword="false" /> if the drag operation could not be started (e.g. because the
        /// mouse could not be captured).
        /// </returns>
        private bool BeginDrag(FloatWindow floatWindow, DockTabPane dockTabPane, DockTabItem dockTabItem)
        {
            _dockStrategy = _dockControl.GetViewModel()?.DockStrategy;
            if (_dockStrategy == null || _dockStrategy.DockControl.IsLocked)
            {
                Reset();
                return(false);
            }

            FrameworkElement element     = null;
            IDockTabPane     draggedPane = null;
            IDockTabItem     draggedItem = null;

            if (floatWindow != null)
            {
                // User is dragging a FloatWindow.
                // (Note: Dragging of FloatWindows with nested layouts is not supported.)
                draggedPane  = floatWindow.GetViewModel()?.RootPane as IDockTabPane;
                element      = floatWindow;
                _floatWindow = floatWindow;
                _initialSize = floatWindow.RenderSize;

                // Start dragging immediately.
                _dragDeltaExceeded = true;
            }
            else if (dockTabItem != null)
            {
                // User is dragging a DockTabItem in a DockTabPanel.
                draggedItem        = dockTabItem.GetViewModel();
                element            = dockTabItem;
                _targetDockTabPane = dockTabPane;
                _initialSize       = dockTabPane.RenderSize;

                // Start dragging when threshold is exceeded.
                _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl);
                _dragDeltaExceeded    = false;
            }
            else if (dockTabPane != null)
            {
                // User is dragging a DockTabPane.
                draggedPane           = dockTabPane.GetViewModel();
                element               = dockTabPane;
                _initialSize          = dockTabPane.RenderSize;
                _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl);

                // Start dragging when threshold is exceeded.
                _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl);
                _dragDeltaExceeded    = false;
            }

            if (draggedPane == null && draggedItem == null)
            {
                Reset();
                return(false);
            }

            // When the user is dragging the FloatWindow, the mouse is captured by Win32 move window
            // loop. When dragging a DockTabPane or DockTabItem, the mouse needs to be
            // captured to receive mouse events.
            if (_floatWindow == null)
            {
                if (!_dockControl.CaptureMouse())
                {
                    // Failed to capture the mouse.
                    Reset();
                    return(false);
                }

                _dockControl.LostMouseCapture  += OnLostMouseCapture;
                _dockControl.MouseLeftButtonUp += OnMouseLeftButtonUp;
                _dockControl.MouseMove         += OnMouseMove;
                _dockControl.PreviewKeyDown    += OnPreviewKeyDown;
                if (_targetDockTabPane != null)
                {
                    _targetDockTabPane.PreviewKeyDown += OnPreviewKeyDown;
                }
            }

            _dockStrategy.Begin();

            if (draggedPane != null)
            {
                _dockStrategy.Activate(draggedPane);
                _activeItem = draggedPane.SelectedItem;
                foreach (var item in draggedPane.Items)
                {
                    if (item.DockState == draggedPane.DockState)
                    {
                        _draggedItems.Add(item);
                    }
                }
            }
            else
            {
                Debug.Assert(draggedItem != null);

                _dockStrategy.Activate(draggedItem);
                _activeItem = draggedItem;
                _draggedItems.Add(draggedItem);
            }

            Debug.Assert(_draggedItems.Count > 0);

            // Determine whether dragged items may end in a FloatWindow.
            _canFloat = CanFloat();

            // Store the mouse offset relative to the dragged element.
            _mouseOffset = (Vector)WindowsHelper.GetMousePosition(element);

            // Remember information needed for a rollback.
            ReplaceItemsWithProxies(draggedPane ?? _targetDockTabPane.GetViewModel());
            _originalDockState = _draggedItems[0].DockState;
            BackupFloatWindowPosition();

            // Override mouse cursors. (Mouse cursor should not change to caret over text editor.)
            Mouse.OverrideCursor = Cursors.Arrow;

            return(true);
        }
Esempio n. 6
0
        /// <summary>
        /// Unregisters the specified <see cref="DockTabItem"/>.
        /// </summary>
        /// <param name="dockTabItem">The <see cref="DockTabItem"/> to remove.</param>
        internal void Unregister(DockTabItem dockTabItem)
        {
            Debug.Assert(dockTabItem != null);

            _dockTabItems.Remove(dockTabItem);
        }
Esempio n. 7
0
        /// <summary>
        /// Starts a drag operation.
        /// </summary>
        /// <param name="floatWindow">The <see cref="FloatWindow"/> to be dragged.</param>
        /// <param name="dockTabPane">The <see cref="DockTabPane"/> to be dragged.</param>
        /// <param name="dockTabItem">The <see cref="DockTabItem"/> to be dragged.</param>
        /// <returns>
        /// <see langword="true" /> if the drag operation has been started; otherwise,
        /// <see langword="false" /> if the drag operation could not be started (e.g. because the
        /// mouse could not be captured).
        /// </returns>
        private bool BeginDrag(FloatWindow floatWindow, DockTabPane dockTabPane, DockTabItem dockTabItem)
        {
            _dockStrategy = _dockControl.GetViewModel()?.DockStrategy;
            if (_dockStrategy == null || _dockStrategy.DockControl.IsLocked)
            {
                Reset();
                return false;
            }

            FrameworkElement element = null;
            IDockTabPane draggedPane = null;
            IDockTabItem draggedItem = null;
            if (floatWindow != null)
            {
                // User is dragging a FloatWindow.
                // (Note: Dragging of FloatWindows with nested layouts is not supported.)
                draggedPane = floatWindow.GetViewModel()?.RootPane as IDockTabPane;
                element = floatWindow;
                _floatWindow = floatWindow;
                _initialSize = floatWindow.RenderSize;

                // Start dragging immediately.
                _dragDeltaExceeded = true;
            }
            else if (dockTabItem != null)
            {
                // User is dragging a DockTabItem in a DockTabPanel.
                draggedItem = dockTabItem.GetViewModel();
                element = dockTabItem;
                _targetDockTabPane = dockTabPane;
                _initialSize = dockTabPane.RenderSize;

                // Start dragging when threshold is exceeded.
                _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl);
                _dragDeltaExceeded = false;
            }
            else if (dockTabPane != null)
            {
                // User is dragging a DockTabPane.
                draggedPane = dockTabPane.GetViewModel();
                element = dockTabPane;
                _initialSize = dockTabPane.RenderSize;
                _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl);

                // Start dragging when threshold is exceeded.
                _initialMousePosition = WindowsHelper.GetMousePosition(_dockControl);
                _dragDeltaExceeded = false;
            }

            if (draggedPane == null && draggedItem == null)
            {
                Reset();
                return false;
            }

            // When the user is dragging the FloatWindow, the mouse is captured by Win32 move window
            // loop. When dragging a DockTabPane or DockTabItem, the mouse needs to be
            // captured to receive mouse events.
            if (_floatWindow == null)
            {
                if (!_dockControl.CaptureMouse())
                {
                    // Failed to capture the mouse.
                    Reset();
                    return false;
                }

                _dockControl.LostMouseCapture += OnLostMouseCapture;
                _dockControl.MouseLeftButtonUp += OnMouseLeftButtonUp;
                _dockControl.MouseMove += OnMouseMove;
                _dockControl.PreviewKeyDown += OnPreviewKeyDown;
                if (_targetDockTabPane != null)
                    _targetDockTabPane.PreviewKeyDown += OnPreviewKeyDown;
            }

            _dockStrategy.Begin();

            if (draggedPane != null)
            {
                _dockStrategy.Activate(draggedPane);
                _activeItem = draggedPane.SelectedItem;
                foreach (var item in draggedPane.Items)
                    if (item.DockState == draggedPane.DockState)
                        _draggedItems.Add(item);
            }
            else
            {
                Debug.Assert(draggedItem != null);

                _dockStrategy.Activate(draggedItem);
                _activeItem = draggedItem;
                _draggedItems.Add(draggedItem);
            }

            Debug.Assert(_draggedItems.Count > 0);

            // Determine whether dragged items may end in a FloatWindow.
            _canFloat = CanFloat();

            // Store the mouse offset relative to the dragged element.
            _mouseOffset = (Vector)WindowsHelper.GetMousePosition(element);

            // Remember information needed for a rollback.
            ReplaceItemsWithProxies(draggedPane ?? _targetDockTabPane.GetViewModel());
            _originalDockState = _draggedItems[0].DockState;
            BackupFloatWindowPosition();

            // Override mouse cursors. (Mouse cursor should not change to caret over text editor.)
            Mouse.OverrideCursor = Cursors.Arrow;

            return true;
        }
Esempio n. 8
0
        /// <summary>
        /// Unregisters the specified <see cref="DockTabItem"/>.
        /// </summary>
        /// <param name="dockTabItem">The <see cref="DockTabItem"/> to remove.</param>
        internal void Unregister(DockTabItem dockTabItem)
        {
            Debug.Assert(dockTabItem != null);

            _dockTabItems.Remove(dockTabItem);
        }
Esempio n. 9
0
        /// <summary>
        /// Registers the specified <see cref="DockTabItem"/>.
        /// </summary>
        /// <param name="dockTabItem">The <see cref="DockTabItem"/> to add.</param>
        internal void Register(DockTabItem dockTabItem)
        {
            Debug.Assert(dockTabItem != null);

            if (!_dockTabItems.Contains(dockTabItem))
                _dockTabItems.Add(dockTabItem);

            // Activate the DockTabItem if it is the IDockControl.ActiveDockTabItem.
            if (DockStrategy != null)
            {
                var dockTabItemVM = dockTabItem.GetViewModel();
                if (dockTabItemVM != null && DockStrategy.DockControl.ActiveDockTabItem == dockTabItemVM)
                    dockTabItem.Activate();
            }
        }