/// <summary> /// Set the provided target as the current target. /// </summary> /// <param name="target">Reference to the new target.</param> /// <param name="startTimer">Should a timer be started for handling sub menu showing.</param> public void SetTarget(IContextMenuTarget target, bool startTimer) { // Only interested in a change of target if (_target != target) { // Tell current target to reset drawing if (_target != null) { _itemDelayTimer.Stop(); _target.ClearTarget(); _target = null; } // Shift the active view to the new target ActiveView = target?.GetActiveView(); _target = target; // Tell new target to draw as highlighted and start delay timer if (_target != null) { _itemDelayTimer.Stop(); if (startTimer) { _itemDelayTimer.Start(); } _target.ShowTarget(); } } }
/// <summary> /// Set the provided target as the current target and it is already showing a sub menu /// </summary> public void SetTargetSubMenu(IContextMenuTarget target) { // Kill any running timer _itemDelayTimer?.Stop(); // If the currently showing sub menu is not for the new target if (_targetSubMenu != target) { // Do we know a target that was instructed to show any sub menu? if (_targetSubMenu != null) { // Inform the same target to remove any showing sub menu _targetSubMenu.ClearSubMenu(); _targetSubMenu = null; } // Remember the new sub menu target _targetSubMenu = target; } // Tell current target to reset drawing if (_target != target) { _target.ClearTarget(); _target = null; } _target = target; // Tell new target to draw as highlighted and start delay timer _target?.ShowTarget(); }
/// <summary> /// Clear the provided target from being the current target. /// </summary> /// <param name="target"></param> public void ClearTarget(IContextMenuTarget target) { // Is there a current target to clear down? if (_target != null) { _itemDelayTimer.Stop(); _target.ClearTarget(); _target = null; } // With no target, we might still be showing a sub menu... if (_targetSubMenu != null) { // We need to show the sub menu target as active _target = _targetSubMenu; _target.ShowTarget(); } }