コード例 #1
0
ファイル: Commands.cs プロジェクト: hacklex/Core2D
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        public static void InitializeCommonCommands(EditorContext context)
        {
            NewCommand =
                Command<object>.Create(
                    (item) => context.OnNew(item),
                    (item) => context.IsEditMode());

            CloseCommand =
                Command.Create(
                    () => context.OnClose(),
                    () => context.IsEditMode());

            ExitCommand =
                Command.Create(
                    () => context.OnExit(),
                    () => true);

            UndoCommand =
                Command.Create(
                    () => context.OnUndo(),
                    () => context.IsEditMode() /* && context.CanUndo() */);

            RedoCommand =
                Command.Create(
                    () => context.OnRedo(),
                    () => context.IsEditMode() /* && context.CanRedo() */);

            CutCommand =
                Command<object>.Create(
                    (item) => context.OnCut(item),
                    (item) => context.IsEditMode() /* && context.CanCopy() */);

            CopyCommand =
                Command<object>.Create(
                    (item) => context.OnCopy(item),
                    (item) => context.IsEditMode() /* && context.CanCopy() */);

            PasteCommand =
                Command<object>.Create(
                    (item) => context.OnPaste(item),
                    (item) => context.IsEditMode() /* && context.CanPaste() */);

            DeleteCommand =
                Command<object>.Create(
                    (item) => context.OnDelete(item),
                    (item) => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            SelectAllCommand =
                Command.Create(
                    () => context.OnSelectAll(),
                    () => context.IsEditMode());

            DeselectAllCommand =
                Command.Create(
                    () => context.OnDeselectAll(),
                    () => context.IsEditMode());

            ClearAllCommand =
                Command.Create(
                    () => context.OnClearAll(),
                    () => context.IsEditMode());

            GroupCommand =
                Command.Create(
                    () => context.Editor.GroupSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            UngroupCommand =
                Command.Create(
                    () => context.Editor.UngroupSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            BringToFrontCommand =
                Command.Create(
                    () => context.Editor.BringToFrontSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            SendToBackCommand =
                Command.Create(
                    () => context.Editor.SendToBackSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            BringForwardCommand =
                Command.Create(
                    () => context.Editor.BringForwardSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            SendBackwardCommand =
                Command.Create(
                    () => context.Editor.SendBackwardSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            MoveUpCommand =
                Command.Create(
                    () => context.Editor.MoveUpSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            MoveDownCommand =
                Command.Create(
                    () => context.Editor.MoveDownSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            MoveLeftCommand =
                Command.Create(
                    () => context.Editor.MoveLeftSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            MoveRightCommand =
                Command.Create(
                    () => context.Editor.MoveRightSelected(),
                    () => context.IsEditMode() /* && context.Editor.IsSelectionAvailable() */);

            ToolNoneCommand =
                Command.Create(
                    () => context.OnToolNone(),
                    () => context.IsEditMode());

            ToolSelectionCommand =
                Command.Create(
                    () => context.OnToolSelection(),
                    () => context.IsEditMode());

            ToolPointCommand =
                Command.Create(
                    () => context.OnToolPoint(),
                    () => context.IsEditMode());

            ToolLineCommand =
                Command.Create(
                    () => context.OnToolLine(),
                    () => context.IsEditMode());

            ToolArcCommand =
                Command.Create(
                    () => context.OnToolArc(),
                    () => context.IsEditMode());

            ToolBezierCommand =
                Command.Create(
                    () => context.OnToolBezier(),
                    () => context.IsEditMode());

            ToolQBezierCommand =
                Command.Create(
                    () => context.OnToolQBezier(),
                    () => context.IsEditMode());

            ToolPathCommand =
                Command.Create(
                    () => context.OnToolPath(),
                    () => context.IsEditMode());

            ToolRectangleCommand =
                Command.Create(
                    () => context.OnToolRectangle(),
                    () => context.IsEditMode());

            ToolEllipseCommand =
                Command.Create(
                    () => context.OnToolEllipse(),
                    () => context.IsEditMode());

            ToolTextCommand =
                Command.Create(
                    () => context.OnToolText(),
                    () => context.IsEditMode());

            ToolImageCommand =
                Command.Create(
                    () => context.OnToolImage(),
                    () => context.IsEditMode());

            ToolMoveCommand =
                Command.Create(
                    () => context.OnToolMove(),
                    () => context.IsEditMode());

            DefaultIsStrokedCommand =
                Command.Create(
                    () => context.OnToggleDefaultIsStroked(),
                    () => context.IsEditMode());

            DefaultIsFilledCommand =
                Command.Create(
                    () => context.OnToggleDefaultIsFilled(),
                    () => context.IsEditMode());

            DefaultIsClosedCommand =
                Command.Create(
                    () => context.OnToggleDefaultIsClosed(),
                    () => context.IsEditMode());

            DefaultIsSmoothJoinCommand =
                Command.Create(
                    () => context.OnToggleDefaultIsSmoothJoin(),
                    () => context.IsEditMode());

            SnapToGridCommand =
                Command.Create(
                    () => context.OnToggleSnapToGrid(),
                    () => context.IsEditMode());

            TryToConnectCommand =
                Command.Create(
                    () => context.OnToggleTryToConnect(),
                    () => context.IsEditMode());

            AddDatabaseCommand =
                Command.Create(
                    () => context.Editor.AddDatabase(),
                    () => context.IsEditMode());

            RemoveDatabaseCommand =
                Command<object>.Create(
                    (db) => context.Editor.RemoveDatabase(db),
                    (db) => context.IsEditMode());

            AddColumnCommand =
                Command<object>.Create(
                    (owner) => context.Editor.AddColumn(owner),
                    (owner) => context.IsEditMode());

            RemoveColumnCommand =
                Command<object>.Create(
                    (parameter) => context.Editor.RemoveColumn(parameter),
                    (parameter) => context.IsEditMode());

            AddRecordCommand =
                Command.Create(
                    () => context.Editor.AddRecord(),
                    () => context.IsEditMode());

            RemoveRecordCommand =
                Command.Create(
                    () => context.Editor.RemoveRecord(),
                    () => context.IsEditMode());

            ResetRecordCommand =
                Command<object>.Create(
                    (owner) => context.Editor.ResetRecord(owner),
                    (owner) => context.IsEditMode());

            ApplyRecordCommand =
                Command<object>.Create(
                    (item) => context.OnApplyRecord(item),
                    (item) => context.IsEditMode());

            AddBindingCommand =
                Command<object>.Create(
                    (owner) => context.Editor.AddBinding(owner),
                    (owner) => context.IsEditMode());

            RemoveBindingCommand =
                Command<object>.Create(
                    (parameter) => context.Editor.RemoveBinding(parameter),
                    (parameter) => context.IsEditMode());

            AddPropertyCommand =
                Command<object>.Create(
                    (owner) => context.Editor.AddProperty(owner),
                    (owner) => context.IsEditMode());

            RemovePropertyCommand =
                Command<object>.Create(
                    (parameter) => context.Editor.RemoveProperty(parameter),
                    (parameter) => context.IsEditMode());

            AddGroupLibraryCommand =
                Command.Create(
                    () => context.Editor.AddGroupLibrary(),
                    () => context.IsEditMode());

            RemoveGroupLibraryCommand =
                Command.Create(
                    () => context.Editor.RemoveCurrentGroupLibrary(),
                    () => context.IsEditMode());

            AddGroupCommand =
                Command.Create(
                    () => context.OnAddGroup(),
                    () => context.IsEditMode());

            RemoveGroupCommand =
                Command.Create(
                    () => context.OnRemoveGroup(),
                    () => context.IsEditMode());

            AddLayerCommand =
                Command.Create(
                    () => context.Editor.AddLayer(),
                    () => context.IsEditMode());

            RemoveLayerCommand =
                Command.Create(
                    () => context.Editor.RemoveCurrentLayer(),
                    () => context.IsEditMode());

            AddStyleLibraryCommand =
                Command.Create(
                    () => context.Editor.AddStyleLibrary(),
                    () => context.IsEditMode());

            RemoveStyleLibraryCommand =
                Command.Create(
                    () => context.Editor.RemoveCurrentStyleLibrary(),
                    () => context.IsEditMode());

            AddStyleCommand =
                Command.Create(
                    () => context.Editor.AddStyle(),
                    () => context.IsEditMode());

            RemoveStyleCommand =
                Command.Create(
                    () => context.Editor.RemoveCurrentStyle(),
                    () => context.IsEditMode());

            ApplyStyleCommand =
                Command<object>.Create(
                    (item) => context.OnApplyStyle(item),
                    (item) => context.IsEditMode());

            RemoveShapeCommand =
                Command.Create(
                    () => context.Editor.RemoveCurrentShape(),
                    () => context.IsEditMode());

            AddTemplateCommand =
                Command.Create(
                    () => context.OnAddTemplate(),
                    () => context.IsEditMode());

            RemoveTemplateCommand =
                Command.Create(
                    () => context.OnRemoveTemplate(),
                    () => context.IsEditMode());

            AddImageKeyCommand =
                Command.Create(
                    async () => await context.Editor.AddImageKey(null),
                    () => context.IsEditMode());

            RemoveImageKeyCommand =
                Command<object>.Create(
                    (parameter) => context.Editor.RemoveImageKey(parameter),
                    (parameter) => context.IsEditMode());

            EditTemplateCommand =
                Command.Create(
                    () => context.OnEditTemplate(),
                    () => context.IsEditMode());

            ApplyTemplateCommand =
                Command<object>.Create(
                    (item) => context.OnApplyTemplate(item),
                    (item) => true);

            SelectedItemChangedCommand =
                Command<object>.Create(
                    (item) => context.OnSelectedItemChanged(item),
                    (item) => context.IsEditMode());

            AddContainerCommand =
                Command<object>.Create(
                    (item) => context.OnAddContainer(item),
                    (item) => context.IsEditMode());

            InsertContainerBeforeCommand =
                Command<object>.Create(
                    (item) => context.OnInsertContainerBefore(item),
                    (item) => context.IsEditMode());

            InsertContainerAfterCommand =
                Command<object>.Create(
                    (item) => context.OnInsertContainerAfter(item),
                    (item) => context.IsEditMode());

            AddDocumentCommand =
                Command<object>.Create(
                    (item) => context.OnAddDocument(item),
                    (item) => context.IsEditMode());

            InsertDocumentBeforeCommand =
                Command<object>.Create(
                    (item) => context.OnInsertDocumentBefore(item),
                    (item) => context.IsEditMode());

            InsertDocumentAfterCommand =
                Command<object>.Create(
                    (item) => context.OnInsertDocumentAfter(item),
                    (item) => context.IsEditMode());
        }