private void InitCommands() { #region Commands _addMenuEntityCommand = new AddMenuEntityCommand() { GetArgumentHandler = () => { MenuEntity selectedItem = _controller.GetSelectedData <MenuEntity>(); if (selectedItem == null) { return(String.Empty); } else { return(selectedItem.Id); } } }; _editMenuEntityCommand = new EditMenuEntityCommand() { CanExcuteHandler = () => { return(_controller.GetSelectedData <MenuEntity>() != null); }, GetArgumentHandler = () => { return(_controller.GetSelectedData <MenuEntity>()); } }; _deleteMenuEntityCommand = new DeleteMenuEntityCommand() { CanExcuteHandler = () => { return(_controller.GetSelectedData <MenuEntity>() != null); }, GetArgumentHandler = () => { return(new List <MenuEntity>() { _controller.GetSelectedData <MenuEntity>() }); } }; _moveBeforeMenuEntityCommand = new MoveBeforeMenuEntityCommand() { CanExcuteHandler = () => { return(_controller.GetSelectedData <MenuEntity>() != null && _controller.GetPreSelectedData <MenuEntity>() != null); }, GetMenuId = () => { return(_controller.GetSelectedData <MenuEntity>().Id); }, GetBeforeMenuId = () => { return(_controller.GetPreSelectedData <MenuEntity>().Id); } }; _moveAfterMenuEntityCommand = new MoveAfterMenuEntityCommand() { CanExcuteHandler = () => { return(_controller.GetSelectedData <MenuEntity>(true) != null && _controller.GetNextSelectedData <MenuEntity>() != null); }, GetMenuId = () => { return(_controller.GetSelectedData <MenuEntity>().Id); }, GetAfterMenuId = () => { return(_controller.GetNextSelectedData <MenuEntity>().Id); } }; #endregion }
private void InitCommands() { #region MenuStrip #region AddMenuEntityCommand _addMenuEntityCommand = new AddMenuEntityCommand() { CanExcuteHandler = () => { return(_currentDataType != null && _currentDataType.Equals(typeof(MenuEntity))); }, //此项所属的项的Id GetArgumentHandler = () => { if (_contextData is MenuEntity) { MenuEntity entity = (MenuEntity)_contextData; return(entity.Id); } else { //正在添加的项为顶层 return(null); } } }; #endregion #region EditMenuEntityCommand _editMenuEntityCommand = new EditMenuEntityCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(MenuEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.GetSelectedItem <MenuEntity>() != null)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItem <MenuEntity>()); } }; #endregion #region DeleteMenuEntityCommand _deleteMenuEntityCommand = new DeleteMenuEntityCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(MenuEntity)); return(currentType && (_controller.GetSelectedItems <MenuEntity>().Count > 0)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItems <MenuEntity>()); } }; #endregion #region MoveUpMenuEntityCommand _moveBeforeMenuEntityCommand = new MoveBeforeMenuEntityCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(MenuEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex > 0 && _controller.GetSelectedItem <MenuEntity>() != null)); }, GetMenuId = () => { return(_controller.GetSelectedItem <MenuEntity>().Id); }, GetBeforeMenuId = () => { return(_controller.GetItem <MenuEntity>( _controller.SelectedItemIndex - 1).Id); } }; #endregion #region MoveDownMenuEntityCommand _moveAfterMenuEntityCommand = new MoveAfterMenuEntityCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(MenuEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex < _controller.ItemsCount - 1 && _controller.GetSelectedItem <MenuEntity>() != null)); }, GetMenuId = () => { return(_controller.GetSelectedItem <MenuEntity>().Id); }, GetAfterMenuId = () => { return(_controller.GetItem <MenuEntity>( _controller.SelectedItemIndex + 1).Id); } }; #endregion #endregion #region ToolStrip #region Page _addToolStripPageCommand = new AddToolStripPageCommand(); _editToolStripPageCommand = new EditToolStripPageCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripPageEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.GetSelectedItem <ToolStripPageEntity>() != null)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItem <ToolStripPageEntity>()); } }; _removeToolStripPageCommand = new RemoveToolStripPageCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripPageEntity)); return(currentType && (_controller.GetSelectedItems <ToolStripPageEntity>().Count > 0)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItems <ToolStripPageEntity>()); } }; _moveBeforeToolStripPageCommand = new MoveBeforeToolStripPageCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripPageEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex > 0 && _controller.GetSelectedItem <ToolStripPageEntity>() != null)); }, GetId = () => { return(_controller.GetSelectedItem <ToolStripPageEntity>().Id); }, GetBeforeId = () => { return(_controller.GetItem <ToolStripPageEntity>( _controller.SelectedItemIndex - 1).Id); } }; _moveAfterToolStripPageCommand = new MoveAfterToolStripPageCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripPageEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex < _controller.ItemsCount - 1 && _controller.GetSelectedItem <ToolStripPageEntity>() != null)); }, GetId = () => { return(_controller.GetSelectedItem <ToolStripPageEntity>().Id); }, GetAfterId = () => { return(_controller.GetItem <ToolStripPageEntity>( _controller.SelectedItemIndex + 1).Id); } }; #endregion #region Group _addToolStripGroupCommand = new AddToolStripGroupCommand() { CanExcuteHandler = () => { return(_currentDataType != null && _currentDataType.Equals(typeof(ToolStripGroupEntity)) && _contextData != null && _contextData is ToolStripPageEntity); }, //此项所属的项的Id GetArgumentHandler = () => { if (_contextData is ToolStripPageEntity) { ToolStripPageEntity entity = (ToolStripPageEntity)_contextData; return(entity.Id); } else { return(null); } } }; _editToolStripGroupCommand = new EditToolStripGroupCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripGroupEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.GetSelectedItem <ToolStripGroupEntity>() != null)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItem <ToolStripGroupEntity>()); } }; _removeToolStripGroupCommand = new RemoveToolStripGroupCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripGroupEntity)); return(currentType && (_controller.GetSelectedItems <ToolStripGroupEntity>().Count > 0)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItems <ToolStripGroupEntity>()); } }; _moveBeforeToolStripGroupCommand = new MoveBeforeToolStripGroupCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripGroupEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex > 0 && _controller.GetSelectedItem <ToolStripGroupEntity>() != null)); }, GetId = () => { return(_controller.GetSelectedItem <ToolStripGroupEntity>().Id); }, GetBeforeId = () => { return(_controller.GetItem <ToolStripGroupEntity>( _controller.SelectedItemIndex - 1).Id); } }; _moveAfterToolStripGroupCommand = new MoveAfterToolStripGroupCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripGroupEntity)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex < _controller.ItemsCount - 1 && _controller.GetSelectedItem <ToolStripGroupEntity>() != null)); }, GetId = () => { return(_controller.GetSelectedItem <ToolStripGroupEntity>().Id); }, GetAfterId = () => { return(_controller.GetItem <ToolStripGroupEntity>( _controller.SelectedItemIndex + 1).Id); } }; #endregion #region Items #region AddToolStripItemCommand _addToolStripItemCommand = new AddToolStripItemCommand() { CanExcuteHandler = () => { return(_currentDataType != null && _currentDataType.Equals(typeof(ToolStripItemAbstract)) && _contextData != null && _contextData is ToolStripGroupEntity); }, //此项所属的项的Id GetArgumentHandler = () => { if (_contextData is ToolStripGroupEntity) { ToolStripGroupEntity entity = (ToolStripGroupEntity)_contextData; return(entity.Id); } else { return(null); } } }; #endregion #region EditToolStripItemCommand _editToolStripItemCommand = new EditToolStripItemCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripItemAbstract)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.GetSelectedItem <ToolStripItemAbstract>() != null)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItem <ToolStripItemAbstract>()); } }; #endregion #region DeleteToolStripItemCommand _deleteToolStripItemCommand = new DeleteToolStripItemCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripItemAbstract)); return(currentType && (_controller.GetSelectedItems <ToolStripItemAbstract>().Count > 0)); }, GetArgumentHandler = () => { return(_controller.GetSelectedItems <ToolStripItemAbstract>()); } }; #endregion #region MoveBeforeToolStripItemCommand _moveBeforeToolStripItemCommand = new MoveBeforeToolStripItemCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripItemAbstract)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex > 0 && _controller.GetSelectedItem <ToolStripItemAbstract>() != null)); }, GetMenuId = () => { return(_controller.GetSelectedItem <ToolStripItemAbstract>().Id); }, GetBeforeMenuId = () => { return(_controller.GetItem <ToolStripItemAbstract>( _controller.SelectedItemIndex - 1).Id); } }; #endregion #region MoveAfterToolStripItemCommand _moveAfterToolStripItemCommand = new MoveAfterToolStripItemCommand() { CanExcuteHandler = () => { bool currentType = _currentDataType != null && _currentDataType.Equals(typeof(ToolStripItemAbstract)); return(currentType && (_controller.SelectedItemsCount == 1 && _controller.SelectedItemIndex < _controller.ItemsCount - 1 && _controller.GetSelectedItem <ToolStripItemAbstract>() != null)); }, GetMenuId = () => { return(_controller.GetSelectedItem <ToolStripItemAbstract>().Id); }, GetAfterMenuId = () => { return(_controller.GetItem <ToolStripItemAbstract>( _controller.SelectedItemIndex + 1).Id); } }; #endregion #endregion #endregion }