예제 #1
0
        public virtual void EditorActionGetState(EditorAction.GetStateContext context)
        {
            switch (context.Action.Name)
            {
            case "Save":
                if (!string.IsNullOrEmpty(RealFileName))
                {
                    context.Enabled = true;
                }
                break;

            case "Save As":
                if (!string.IsNullOrEmpty(RealFileName))
                {
                    context.Enabled = CanSaveAs();
                }
                break;

            case "Undo":
                context.Enabled = undoSystem != null && undoSystem.GetTopUndoAction() != null;
                break;

            case "Redo":
                context.Enabled = undoSystem != null && undoSystem.GetTopRedoAction() != null;
                break;

            case "Play":
            {
                var component = LoadedResource?.ResultComponent;
                if (component != null && RunSimulation.CheckTypeSupportedByPlayer(component.BaseType))
                {
                    context.Enabled = true;
                }
            }
            break;

            case "Find Resource":
                context.Enabled = !string.IsNullOrEmpty(RealFileName);
                break;
            }
        }
예제 #2
0
        public virtual void EditorActionClick(EditorAction.ClickContext context)
        {
            switch (context.Action.Name)
            {
            case "Save":
                Save(null);
                break;

            case "Save As":
            {
#if !PROJECT_DEPLOY
                var dialog = new CommonSaveFileDialog();
                dialog.InitialDirectory = Path.GetDirectoryName(RealFileName);
                dialog.DefaultFileName  = Path.GetFileName(RealFileName);
                dialog.Filters.Add(new CommonFileDialogFilter("All Files", ".*"));
                if (dialog.ShowDialog() != CommonFileDialogResult.Ok)
                {
                    return;
                }

                var saveAsFileName = dialog.FileName;

                //if( File.Exists( saveAsFileName ) )
                //{
                //	var text = string.Format( EditorLocalization.Translate( "General", "A file with the name \'{0}\' already exists. Overwrite?" ), saveAsFileName );
                //	if( EditorMessageBox.ShowQuestion( text, MessageBoxButtons.OKCancel ) != DialogResult.OK )
                //		return;
                //}

                if (string.Compare(RealFileName, saveAsFileName, true) == 0)
                {
                    Save();
                }
                else
                {
                    Save(saveAsFileName, false);
                    EditorAPI.OpenFileAsDocument(saveAsFileName, true, true);
                }
#endif
            }
            break;

            case "Undo":
                if (undoSystem != null)
                {
                    if (undoSystem.DoUndo())
                    {
                        Modified = true;
                    }
                }
                break;

            case "Redo":
                if (undoSystem != null)
                {
                    if (undoSystem.DoRedo())
                    {
                        Modified = true;
                    }
                }
                break;

            case "Play":
            {
                var component = LoadedResource?.ResultComponent;
                if (component != null && RunSimulation.CheckTypeSupportedByPlayer(component.BaseType))
                {
                    if (!EditorAPI.SaveDocuments())
                    {
                        return;
                    }
                    //if( Modified )
                    //{
                    //	if( !Save( null ) )
                    //		return;
                    //}

                    //!!!!не только standalone
                    var realFileName = VirtualPathUtility.GetRealPathByVirtual(LoadedResource.Owner.Name);
                    RunSimulation.Run(realFileName, RunSimulation.RunMethod.Player);
                }
            }
            break;

            case "Find Resource":
                if (!string.IsNullOrEmpty(RealFileName))
                {
                    EditorAPI.SelectFilesOrDirectoriesInMainResourcesWindow(new string[] { RealFileName });
                }
                break;
            }
        }