Exemple #1
0
        /// <summary>
        /// 使用元数据中指定的分组算法,将命令进行分组。
        /// </summary>
        /// <param name="cmd"></param>
        private void AddCommandIntoGroup(WPFCommand cmd)
        {
            var algorithmType = cmd.GroupAlgorithmType ?? typeof(DefaultAlgorithm);

            var algorithm = Activator.CreateInstance(algorithmType) as GroupAlgorithm;

            algorithm.Context     = this.Context;
            algorithm.FinalGroups = this._tmpGroups;
            algorithm.GroupCommand(cmd);
        }
Exemple #2
0
        protected override void GroupCommandCore(WPFCommand cmd)
        {
            var newGroup  = new GeneratableCommandGroup(cmd.Name);
            var generator = new CompoundGenerator
            {
                CommandMetaGroup = newGroup,
                Context          = this.Context
            };

            newGroup.Generator = generator;

            //是否生成到菜单中
            if (cmd.HasLocation(CommandLocation.Menu))
            {
                //为每一个命令都声明一个单独的组
                //构造并设置控件生成器
                generator.Add(new MenuItemGenerator
                {
                    CommandMetaGroup = newGroup,
                    Context          = this.Context
                });
            }

            if (cmd.HasLocation(CommandLocation.Toolbar))
            {
                if (cmd.Hierarchy.Count != 1)
                {
                    generator.Add(new ButtonItemGenerator
                    {
                        CommandMetaGroup = newGroup,
                        Context          = this.Context
                    });
                }
                else
                {
                    string groupName = cmd.Hierarchy[0];
                    newGroup = this.TryFindGroup(groupName);

                    if (newGroup == null)
                    {
                        newGroup           = this.AddNewGroup(groupName);
                        newGroup.Generator = new SplitButtonGroupGenerator
                        {
                            CommandMetaGroup = newGroup,
                            Context          = this.Context
                        };
                    }
                }
            }

            newGroup.AddCommand(cmd);

            FinalGroups[newGroup.Name] = newGroup;
        }
Exemple #3
0
        internal void Config(WPFCommand cmd)
        {
            if (Label != null)
            {
                cmd.HasLabel(Label);
            }

            if (IsVisible != null)
            {
                cmd.IsVisible = IsVisible.Value;
            }
        }
Exemple #4
0
        /// <summary>
        /// 为当前的命令元数据生成一个客户端运行时命令对象。
        /// </summary>
        /// <param name="groupGenerator"></param>
        /// <returns></returns>
        private static ClientCommand CreateItemCommand(WPFCommand commandMeta, object commandArg)
        {
            var command = CommandRepository.CreateCommand(commandMeta, commandArg);

            var view = commandArg as LogicalView;

            if (view != null)
            {
                view.Commands.Add(command);
            }

            return(command);
        }
Exemple #5
0
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="view"></param>
        private static void LogCommandSuccess(WPFCommand cmd, LogicalView view)
        {
            if (DisableLog(cmd, view))
            {
                return;
            }

            string title        = "执行命令完成:" + cmd.Label;
            string coderContent = string.Format(
                @"类型名:{0}
命令名称:{1}", view.EntityType.Name, cmd.Name);

            LogAsync(title, coderContent, view);
        }
Exemple #6
0
        protected override void GroupCommandCore(WPFCommand cmd)
        {
            //为每一个命令都声明一个单独的组
            var group = AddNewGroup(cmd.Name);

            //构造并设置控件生成器
            var generator = new TGenerator();

            generator.CommandMetaGroup = group;
            generator.Context          = this.Context;
            group.Generator            = generator;

            group.AddCommand(cmd);
        }
Exemple #7
0
        /// <summary>
        /// 记录执行错误的日志
        /// </summary>
        /// <param name="view"></param>
        /// <param name="ex"></param>
        private static void LogCommandFailed(WPFCommand cmd, LogicalView view, Exception ex)
        {
            if (DisableLog(cmd, view))
            {
                return;
            }

            string title        = "执行命令失败:" + cmd.Label;
            string coderContent = string.Format(
                @"类型名:{0}
命令类型:{1}
发生异常:{2}
堆栈:{3}", view.EntityType.Name, cmd.Name, ex.Message, ex.StackTrace);

            LogAsync(title, coderContent, view);
        }
Exemple #8
0
        protected override void GroupCommandCore(WPFCommand cmd)
        {
            if (cmd.Hierarchy.Count != 1)
            {
                throw new ArgumentNullException("groupName");
            }

            string groupName = cmd.Hierarchy[0];
            var    group     = this.TryFindGroup(groupName);

            if (group == null)
            {
                group           = this.AddNewGroup(groupName);
                group.Generator = new SplitButtonGroupGenerator
                {
                    CommandMetaGroup = group,
                    Context          = this.Context
                };
            }

            group.AddCommand(cmd);
        }
Exemple #9
0
        public void AddCommand(WPFCommand cmd, object commandArg = null)
        {
            if (commandArg == null)
            {
                var window = WorkspaceWindow.GetOuterWorkspaceWindow(this.InnerContent) as ModuleWorkspaceWindow;
                if (window == null)
                {
                    throw new ArgumentNullException("内部控件没有 WindowTemplate 时,必须提供 commandArg 参数。");
                }
                commandArg = window.MainView;
            }

            var items = commandPanel.Items;

            items.Remove(btnConfirm);
            items.Remove(btnCancel);

            AutoUI.BlockUIFactory.AppendCommands(commandPanel, commandArg, cmd);

            //始终把 btnConfirm、btnCancel 放到最后。
            items.Add(btnConfirm);
            items.Add(btnCancel);

            //commandPanel.Style = RafyResources.Rafy_CommandsContainer_Style;

            //Button btn = new Button()
            //{
            //    Margin = new Thickness(10, 2, 20, 2),
            //};
            //commandPanel.Children.Insert(0, btn);
            //if (window != null)
            //{
            //    btn.CommandParameter = window.View;
            //}
            //else
            //    btn.CommandParameter = View;
            //ButtonCommand.SetCommand(btn, CommandRepository.NewCommand(commandName));
        }
Exemple #10
0
 /// <summary>
 /// 添加一个Command
 /// </summary>
 /// <param name="item"></param>
 public void AddCommand(WPFCommand item)
 {
     this.Commands.Add(item);
 }
Exemple #11
0
 private static bool DisableLog(WPFCommand cmd, LogicalView view)
 {
     return(view is QueryLogicalView);
 }
Exemple #12
0
 /// <summary>
 /// 获取元数据对应的客户端运行时命令。
 ///
 /// 一个元数据只会生成一个运行时命令。而一个运行时命令,则可以同时生成工具栏、菜单等多个位置的控件。
 /// </summary>
 /// <param name="meta"></param>
 /// <returns></returns>
 public ClientCommand GetClientCommand(WPFCommand meta)
 {
     return(_clientCommands[meta]);
 }
Exemple #13
0
 /// <summary>
 /// 此方法为Command生成一个可生成控件的组,并加入到 FinalGroups 中。
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 protected abstract void GroupCommandCore(WPFCommand cmd);
Exemple #14
0
 /// <summary>
 /// 调用此方法为Command生成一个可生成控件的组,并加入到ExistingGroups中
 /// </summary>
 /// <param name="cmd"></param>
 public void GroupCommand(WPFCommand cmd)
 {
     this.GroupCommandCore(cmd);
 }
 public void LoadCommands()
 {
     CmdExpandCollapse = new WPFCommand(ExpandCollapse, CanExpandCollapse);
     CmdGoTo           = new WPFCommand(GoTo, CanGoTo);
 }
 public void LoadCommands()
 {
     CmdGoTo = new WPFCommand(GoTo, CanGoTo);
 }