Ejemplo n.º 1
0
        private void ungroupToParentGroupButton_Click(object sender, System.EventArgs e)
        {
            // get the group and its parent group
            NGroup group = (view.Selection.AnchorNode as NGroup);

            if (group == null)
            {
                return;
            }

            NGroup parentGroup = group.Group;

            if (parentGroup == null)
            {
                return;
            }

            // create a new batch ungroup and check whether it can be executed
            NBatchUngroup batchUngroup = new NBatchUngroup(document, view.Selection.Nodes);

            if (batchUngroup.CanUngroup(parentGroup, false) == false)
            {
                return;
            }

            // ungroup the selected groups to the active layer
            NNodeList          shapes;
            NTransactionResult res = batchUngroup.Ungroup(parentGroup, false, out shapes);

            // single select the parent group if the ungroup was successful
            if (res.Succeeded)
            {
                view.Selection.SingleSelect(parentGroup);
            }

            // ask the view to display any information about the transaction status (if it was not completed)
            view.ProcessTransactionResult(res);
        }
Ejemplo n.º 2
0
        private void ungroupToLayerButton_Click(object sender, System.EventArgs e)
        {
            // create a new batch ungroup and check whether it can be executed
            NBatchUngroup batchUngroup = new NBatchUngroup(document, view.Selection.Nodes);

            if (batchUngroup.CanUngroup(document.ActiveLayer, false) == false)
            {
                return;
            }

            // ungroup the selected groups to the active layer
            NNodeList          shapes;
            NTransactionResult res = batchUngroup.Ungroup(document.ActiveLayer, false, out shapes);

            // single select the ungrouped shapes if the ungroup was successful
            if (res.Succeeded)
            {
                view.Selection.SingleSelect(shapes);
            }

            // ask the view to display any information about the transaction status (if it was not completed)
            view.ProcessTransactionResult(res);
        }
Ejemplo n.º 3
0
        private void UpdateControlsState()
        {
            PauseEventsHandling();

            // get the selected nodes
            NNodeList selectedNodes = view.Selection.Nodes;

            if (selectedNodes.Count == 0)
            {
                // if not nodes are selected - disable form controls
                selectedGroupsActionsGroup.Enabled = false;
                selectedShapesActionsGroup.Enabled = false;
            }
            else if (selectedNodes.Count == 1)
            {
                // if the selected node is a group
                NGroup group = (view.Selection.AnchorNode as NGroup);
                if (group != null)
                {
                    selectedGroupsActionsGroup.Enabled = true;

                    // check whether the group can be ungrouped to layer
                    NBatchUngroup batchUngroup = new NBatchUngroup(document, selectedNodes);
                    ungroupToLayerButton.Enabled = batchUngroup.CanUngroup(document.ActiveLayer, false);

                    // check whether the group can be ungrouped to a parent group
                    NGroup parentGroup = group.Group;
                    if (parentGroup != null)
                    {
                        ungroupToParentGroupButton.Enabled = batchUngroup.CanUngroup(parentGroup, false);
                    }
                    else
                    {
                        ungroupToParentGroupButton.Enabled = false;
                    }

                    // update the protect from ungroup check button
                    protectFromUngroupCheckBox.Enabled = true;
                    protectFromUngroupCheckBox.Checked = group.Protection.Ungroup;
                }
                else
                {
                    selectedGroupsActionsGroup.Enabled = false;
                }

                // if the selected node is a shape
                NShape shape = (view.Selection.AnchorNode as NShape);
                if (shape != null)
                {
                    selectedShapesActionsGroup.Enabled = true;

                    // check whether the selected shape can be grouped
                    NBatchGroup batchGroup = new NBatchGroup(document, selectedNodes);
                    groupButton.Enabled = batchGroup.CanGroup(document.ActiveLayer, false);

                    // update the protect from group check button
                    protectFromGroupCheckBox.Enabled = true;
                    protectFromGroupCheckBox.Checked = shape.Protection.Group;
                }
                else
                {
                    selectedShapesActionsGroup.Enabled = false;
                }
            }
            else
            {
                // multiple nodes are selected
                selectedGroupsActionsGroup.Enabled = true;
                selectedShapesActionsGroup.Enabled = true;

                // update ungroup buttons
                NBatchUngroup batchUngroup = new NBatchUngroup(document, selectedNodes);
                ungroupToLayerButton.Enabled       = batchUngroup.CanUngroup(document.ActiveLayer, false);
                ungroupToParentGroupButton.Enabled = false;

                // update group button
                NBatchGroup batchGroup = new NBatchGroup(document, selectedNodes);
                groupButton.Enabled = batchGroup.CanGroup(document.ActiveLayer, false);

                // disable protection checks
                protectFromUngroupCheckBox.Enabled = true;
                protectFromGroupCheckBox.Enabled   = false;
            }

            base.ResumeEventsHandling();
        }