示例#1
0
 public bool Enabled(object arg)
 {
     return(ValidContexts.HasX(ui.Selection.Context) && _enabled(ui.Selection, ui.Handler.Model, arg));
 }
示例#2
0
        private void InternalExecute(object arg, IEnumerable <ITabularNamedObject> alternateSelection = null)
        {
            TabularModelHandler handler;

            if (ui != null)
            {
                ui.Actions.SelectObjects.Clear();
                ui.Actions.LastActionExecuted = this;
                handler = ui.Handler;
            }
            else
            {
                handler = TabularModelHandler.Singleton;
            }

            EditObjectName = null;
            ExpandObject   = null;
            var selection = alternateSelection == null ? (ui == null ? UITreeSelection.Empty : ui.Selection) : new UITreeSelection(alternateSelection);

            // Check if the context is valid before executing the action:
            if (!ValidContexts.HasX(selection.Context | Context.Model | Context.Tool))
            {
                return;
            }

            try
            {
                handler.BeginUpdate(Name);
                _execute(selection, handler.Model);
            }
            catch (Exception e)
            {
                MessageBox.Show("The action failed with the following error: " + e.Message, "Unable to perform action", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                handler.EndUpdate();
            }


            if (ui == null)
            {
                return;
            }

            // Actions can trigger certain UI actions after execution (for example, tree expansion, name editing, tree selection):
            if (ExpandObject != null)
            {
                ui.ExpandItem(ExpandObject);
            }
            if (EditObjectName != null)
            {
                ui.EditName(EditObjectName);
            }
            if (ui.Actions.SelectObjects.Count > 0)
            {
                var tree = ui.Elements.TreeView;
                tree.ClearSelection();
                TreeNodeAdv firstNode = null;
                foreach (var obj in ui.Actions.SelectObjects)
                {
                    var node = tree.FindNodeByTag(obj);
                    if (firstNode == null)
                    {
                        firstNode = node;
                    }
                    if (node != null)
                    {
                        node.IsSelected = true;
                    }
                }
                if (firstNode != null)
                {
                    tree.EnsureVisible(firstNode);
                }
            }
        }