void DrawHeader()
        {
            headerArea.Begin();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Project workspace:", GUILayout.ExpandWidth(false));
            projectWorkspacePath = GUILayout.TextField(projectWorkspacePath, GUILayout.ExpandWidth(true));

            if (GUILayout.Button("Reload", GUILayout.Width(100)))
            {
                ReloadProjectWorkspace();
            }

            GUILayout.EndHorizontal();

            projectFilesScrollPosition = GUILayout.BeginScrollView(projectFilesScrollPosition);
            GUILayout.BeginHorizontal();

            foreach (var file in projectFiles)
            {
                if (GUILayout.Button(Path.GetFileName(file.path), GUILayout.ExpandWidth(false)))
                {
                    currentFile = file;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            headerArea.End();
        }
 void SaveProjectFile(ScriptEditorFile file)
 {
     try
     {
         File.WriteAllText(file.path, file.source);
     }
     catch (Exception ex)
     {
         lastError = ex.Message;
     }
 }
示例#3
0
        public void ReloadProjectWorkspace()
        {
            projectWorkspacePath = ModTools.Instance.config.scriptEditorWorkspacePath;
            if (projectWorkspacePath.Length == 0)
            {
                lastError = "Invalid project workspace path";
                return;
            }

            bool exampleFileExists = false;

            projectFiles.Clear();

            try
            {
                var files = FileUtil.ListFilesInDirectory(projectWorkspacePath);
                foreach (var file in files)
                {
                    if (Path.GetExtension(file) == ".cs")
                    {
                        if (Path.GetFileName(file) == ExampleScriptFileName)
                        {
                            exampleFileExists = true;
                        }

                        projectFiles.Add(new ScriptEditorFile()
                        {
                            path = file, source = File.ReadAllText(file)
                        });
                    }
                }
                if (!exampleFileExists)
                {
                    var exampleFile = new ScriptEditorFile()
                    {
                        path   = Path.Combine(projectWorkspacePath, ExampleScriptFileName),
                        source = defaultSource
                    };

                    projectFiles.Add(exampleFile);
                    SaveProjectFile(exampleFile);
                }
            }
            catch (Exception ex)
            {
                lastError = ex.Message;
                return;
            }
            lastError = "";
        }
示例#4
0
        void RunCommandLine()
        {
            var commandLine = commandHistory[currentCommandHistoryIndex];

            if (emptyCommandLineArea)
            {
                if (commandHistory.Last() != "")
                {
                    commandHistory.Add("");
                    currentCommandHistoryIndex = commandHistory.Count - 1;
                }
                else
                {
                    currentCommandHistoryIndex = commandHistory.Count - 1;
                }
            }
            emptyCommandLineArea = true;

            var source = String.Format(defaultSource, commandLine);
            var file   = new ScriptEditorFile()
            {
                path = "ModToolsCommandLineScript.cs", source = source
            };
            string         errorMessage;
            IModEntryPoint instance;

            if (!ScriptCompiler.RunSource(new List <ScriptEditorFile>()
            {
                file
            }, out errorMessage, out instance))
            {
                Log.Error("Failed to compile command-line!");
            }
            else
            {
                if (instance != null)
                {
                    Log.Message("Executing command-line..");
                    instance.OnModLoaded();
                }
                else
                {
                    Log.Error("Error executing command-line..");
                }
            }
            commandLine          = "";
            focusCommandLineArea = true;
        }
        void ReloadProjectWorkspace()
        {
            if (projectWorkspacePath.Trim().Length == 0)
            {
                lastError = "Invalid project workspace path";
                return;
            }

            bool modToolsHookFileExists = false;

            projectFiles.Clear();

            try
            {
                var files = FileUtil.ListFilesInDirectoryRecursively(projectWorkspacePath);
                foreach (var file in files)
                {
                    if (Path.GetExtension(file) == ".cs")
                    {
                        if (Path.GetFileName(file) == modToolsHookFileName)
                        {
                            modToolsHookFileExists = true;
                        }

                        projectFiles.Add(new ScriptEditorFile()
                        {
                            path = file, source = File.ReadAllText(file)
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                lastError = ex.Message;
            }

            if (!modToolsHookFileExists)
            {
                var hookFile = new ScriptEditorFile()
                {
                    path   = Path.Combine(projectWorkspacePath, modToolsHookFileName),
                    source = defaultSource
                };

                projectFiles.Add(hookFile);
                SaveProjectFile(hookFile);
            }
        }
示例#6
0
        void DrawHeader()
        {
            headerArea.Begin();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Scripts are stored in project workspace. To add a script create a new .cs file in workspace and click 'Reload'", GUILayout.ExpandWidth(false));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Project workspace:", GUILayout.ExpandWidth(false));
            var newProjectWorkspacePath = GUILayout.TextField(projectWorkspacePath, GUILayout.ExpandWidth(true));

            if (!newProjectWorkspacePath.Equals(projectWorkspacePath))
            {
                projectWorkspacePath = newProjectWorkspacePath.Trim();
                ModTools.Instance.config.scriptEditorWorkspacePath = projectWorkspacePath;
                ModTools.Instance.SaveConfig();
            }

            if (GUILayout.Button("Reload", GUILayout.Width(100)))
            {
                ReloadProjectWorkspace();
            }

            GUILayout.EndHorizontal();

            projectFilesScrollPosition = GUILayout.BeginScrollView(projectFilesScrollPosition);
            GUILayout.BeginHorizontal();

            foreach (var file in projectFiles)
            {
                if (GUILayout.Button(Path.GetFileName(file.path), GUILayout.ExpandWidth(false)))
                {
                    currentFile = file;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            headerArea.End();
        }
示例#7
0
 void SaveProjectFile(ScriptEditorFile file)
 {
     File.WriteAllText(file.path, file.source);
 }
示例#8
0
 void SaveProjectFile(ScriptEditorFile file)
 {
     try
     {
         File.WriteAllText(file.path, file.source);
     }
     catch (Exception ex)
     {
         lastError = ex.Message;
     }
 }
示例#9
0
        void ReloadProjectWorkspace()
        {
            if (projectWorkspacePath.Trim().Length == 0)
            {
                lastError = "Invalid project workspace path";
                return;
            }

            bool modToolsHookFileExists = false;

            projectFiles.Clear();

            try
            {
                var files = FileUtil.ListFilesInDirectoryRecursively(projectWorkspacePath);
                foreach (var file in files)
                {
                    if (Path.GetExtension(file) == ".cs")
                    {
                        if (Path.GetFileName(file) == modToolsHookFileName)
                        {
                            modToolsHookFileExists = true;
                        }

                        projectFiles.Add(new ScriptEditorFile() { path = file, source = File.ReadAllText(file) } );
                    }
                }
            }
            catch (Exception ex)
            {
                lastError = ex.Message;
            }

            if (!modToolsHookFileExists)
            {
                var hookFile = new ScriptEditorFile()
                {
                    path = Path.Combine(projectWorkspacePath, modToolsHookFileName),
                    source = defaultSource
                };

                projectFiles.Add(hookFile);
                SaveProjectFile(hookFile);
            }
        }
示例#10
0
        void DrawHeader()
        {
            headerArea.Begin();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Project workspace:", GUILayout.ExpandWidth(false));
            projectWorkspacePath = GUILayout.TextField(projectWorkspacePath, GUILayout.ExpandWidth(true));

            if (GUILayout.Button("Reload", GUILayout.Width(100)))
            {
                ReloadProjectWorkspace();
            }

            GUILayout.EndHorizontal();

            projectFilesScrollPosition = GUILayout.BeginScrollView(projectFilesScrollPosition);
            GUILayout.BeginHorizontal();

            foreach (var file in projectFiles)
            {
                if (GUILayout.Button(Path.GetFileName(file.path), GUILayout.ExpandWidth(false)))
                {
                    currentFile = file;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            headerArea.End();
        }
示例#11
0
        void RunCommandLine()
        {
            var commandLine = commandHistory[currentCommandHistoryIndex];

            if (emptyCommandLineArea)
            {
                if (commandHistory.Last() != "")
                {
                    commandHistory.Add("");
                    currentCommandHistoryIndex = commandHistory.Count - 1;
                }
                else
                {
                    currentCommandHistoryIndex = commandHistory.Count - 1;
                }
            }
            emptyCommandLineArea = true;

            var source = String.Format(defaultSource, commandLine);
            var file = new ScriptEditorFile() { path = "ModToolsCommandLineScript.cs", source = source };
            string errorMessage;
            IModEntryPoint instance;
            if (!ScriptCompiler.RunSource(new List<ScriptEditorFile>() { file }, out errorMessage, out instance))
            {
                Log.Error("Failed to compile command-line!");
            }
            else
            {
                if (instance != null)
                {
                    Log.Message("Executing command-line..");
                    instance.OnModLoaded();
                }
                else
                {
                    Log.Error("Error executing command-line..");
                }
            }
            commandLine = "";
            focusCommandLineArea = true;
        }