summaryrefslogtreecommitdiff
path: root/modules/mono/editor/GodotSharpTools/Editor/MonoDevelopInstance.cs
blob: 303be3b732ba8ab2fd696ed0d7dda1d5bb4802ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;

namespace GodotSharpTools.Editor
{
    public class MonoDevelopInstance
    {
        private Process process;
        private string solutionFile;

        public void Execute(string[] files)
        {
            bool newWindow = process == null || process.HasExited;

            List<string> args = new List<string>();

            args.Add("--ipc-tcp");

            if (newWindow)
                args.Add("\"" + Path.GetFullPath(solutionFile) + "\"");

            foreach (var file in files)
            {
                int semicolonIndex = file.IndexOf(';');

                string filePath = semicolonIndex < 0 ? file : file.Substring(0, semicolonIndex);
                string cursor = semicolonIndex < 0 ? string.Empty : file.Substring(semicolonIndex);

                args.Add("\"" + Path.GetFullPath(filePath.NormalizePath()) + cursor + "\"");
            }

            if (newWindow)
            {
                ProcessStartInfo startInfo = new ProcessStartInfo(MonoDevelopFile, string.Join(" ", args));
                process = Process.Start(startInfo);
            }
            else
            {
                Process.Start(MonoDevelopFile, string.Join(" ", args));
            }
        }

        public MonoDevelopInstance(string solutionFile)
        {
            this.solutionFile = solutionFile;
        }

        private static string MonoDevelopFile
        {
            get
            {
                return "monodevelop";
            }
        }
    }
}