private bool CanDoTogglePinVisibility(object context, object target) { if (target.Is <Group>()) { if (CircuitUtil.IsTemplateTargetMissing(target)) { return(false); } var viewingContext = context.Cast <CircuitEditingContext>().DomNode.Cast <ViewingContext>(); if (viewingContext.Control != null) { var contextMenu = viewingContext.Control.As <ContextMenuAdapter>(); if (CommandService.ContextMenuIsTriggering && contextMenu != null) { foreach (var pickingAdapter in viewingContext.Control.AsAll <IPickingAdapter2>()) { DiagramHitRecord hitRecord = pickingAdapter.Pick(contextMenu.TriggeringLocation.GetValueOrDefault()); if (hitRecord.Part.Is <GroupPin>()) { return(true); } if (hitRecord.SubPart.Is <GroupPin>()) { return(true); } if (hitRecord.SubPart.Is <ElementType.Pin>()) { return(true); } } } } } return(false); }
/// <summary> /// Updates command state for given command</summary> /// <param name="commandTag">Command</param> /// <param name="state">Command state to update</param> public void UpdateCommand(object commandTag, CommandState state) { if (commandTag is CommandTag) { if (commandTag.Equals(CommandTag.ResetGroupPinNames)) { if (m_targetRef != null && m_targetRef.Target != null) { object target = m_targetRef.Target; if (target.Is <Group>() && !CircuitUtil.IsTemplateTargetMissing(target)) { var group = target.Cast <Group>(); state.Text = string.Format("Reset Pin Names on \"{0}\"".Localize(), group.Name); } } } else if (commandTag.Equals(CommandTag.ShowExpandedGroupPins)) { if (m_targetRef != null && m_targetRef.Target != null) { object target = m_targetRef.Target; if (target.Is <Group>()) { var group = target.Cast <Group>(); state.Check = group.Info.ShowExpandedGroupPins; state.Text = string.Format("Show Expanded Group Pins on \"{0}\"".Localize(), group.Name); } } } else if (commandTag.Equals(CommandTag.HideUnconnectedPins)) { if (m_targetRef != null && m_targetRef.Target != null) { object target = m_targetRef.Target; if (target.Is <Group>() && !CircuitUtil.IsTemplateTargetMissing(target)) { var group = target.Cast <Group>(); var graphContainer = group.ParentGraph.As <ICircuitContainer>(); if (graphContainer != null) { // check if all unconnected pins are hidden m_allUnconnectedHidden = true; foreach (var grpPin in group.InputGroupPins) { bool externalConectd = graphContainer.Wires.FirstOrDefault( x => x.InputPinTarget.FullyEquals(grpPin.PinTarget)) != null; if (!externalConectd && grpPin.Visible) { m_allUnconnectedHidden = false; break; } } if (m_allUnconnectedHidden) { foreach (var grpPin in group.OutputGroupPins) { bool externalConectd = graphContainer.Wires.FirstOrDefault( x => x.OutputPinTarget.FullyEquals(grpPin.PinTarget)) != null; if (!externalConectd && grpPin.Visible) { m_allUnconnectedHidden = false; break; } } } state.Check = m_allUnconnectedHidden; state.Text = string.Format("Hide Unconnected Pins on \"{0}\"".Localize(), group.Name); } } } } } }
/// <summary> /// Can the client do the command?</summary> /// <param name="commandTag">Command</param> /// <returns>True iff client can do the command</returns> public virtual bool CanDoCommand(object commandTag) { bool enabled = false; var context = m_contextRegistry.GetActiveContext <CircuitEditingContext>(); if (context != null) { var selectionContext = m_contextRegistry.GetActiveContext <ISelectionContext>(); if (commandTag is StandardCommand) { if (StandardCommand.EditGroup.Equals(commandTag)) { var lastSelected = selectionContext.GetLastSelected <Element>(); enabled = (lastSelected != null) && // at least one Module selected selectionContext.Selection.All( // selected elements should have a common parent(i.e. belong to the same container) x => x.Is <Element>() && x.Cast <DomNode>().Parent == lastSelected.DomNode.Parent); if (enabled) { enabled = selectionContext.Selection.All(x => !CircuitUtil.IsTemplateTargetMissing(x)); } if (enabled && (!context.SupportsNestedGroup)) { // if nested group is not supported, then neither any selected item can be a group, // nor any of their ancestry enabled = selectionContext.Selection.All(x => !x.Is <Group>()); if (enabled) { enabled = lastSelected.DomNode.Ancestry.All(x => !x.Is <Group>()); } } } else if (StandardCommand.EditUngroup.Equals(commandTag)) { enabled = selectionContext.Selection.Any() && selectionContext.Selection.All(x => x.Is <Group>() && // selected are all are group instances !(x.Is <IReference <DomNode> >()) // disallow template instances as they suppose acting atomically ); } } else if (commandTag is CommandTag) { if (CommandTag.ShowExpandedGroupPins.Equals(commandTag)) { enabled = m_targetRef != null && m_targetRef.Target.Is <Group>() && m_targetRef.Target.Cast <Group>().Expanded; } else if (CommandTag.ResetGroupPinNames.Equals(commandTag)) { enabled = m_targetRef != null && m_targetRef.Target.Is <Group>() && (m_targetRef.Target is IReference <DomNode>); if (enabled) { enabled = !CircuitUtil.IsTemplateTargetMissing(m_targetRef.Target); } } else if (CommandTag.HideUnconnectedPins.Equals(commandTag)) { enabled = m_targetRef != null && m_targetRef.Target.Is <Group>(); if (enabled) { enabled = !CircuitUtil.IsTemplateTargetMissing(m_targetRef.Target); } } else if (CommandTag.TogglePinVisibility.Equals(commandTag)) { enabled = m_targetRef != null && CanDoTogglePinVisibility(context, m_targetRef.Target); } else if (CommandTag.EdgeStyleDefault.Equals(commandTag)) { enabled = true; } else if (CommandTag.EdgeStyleDirectCurve.Equals(commandTag)) { enabled = true; } } } return(enabled); }