Exemple #1
0
        public void Execute(string[] arguments)
        {
            Logger.Write("Getting editor instance");
            var instance = _editorFactory.GetInstance(_rootPath);
            // TODO remove that unbeleavable nasty setfocus solution. Only init if launching editor
            var isSetfocus = arguments.Length > 0 && arguments[0] == "setfocus";

            if (instance == null && arguments.Length >= 0 && !isSetfocus)
            {
                var args = new List <string>();
                Logger.Write("Reading configuration from " + _rootPath);
                var configReader = new ConfigReader(_rootPath);
                if (arguments.Length == 0)
                {
                    var name = configReader.Get("default.editor");
                    if (name == null)
                    {
                        Console.WriteLine("To launch without specifying editor you must specify the default.editor config option");
                        return;
                    }
                    args.Add(name);
                }
                else
                {
                    args.AddRange(arguments);
                }
                var editorName = args[0];
                args.AddRange(
                    configReader
                    .GetStartingWith("editor." + editorName)
                    .Select(x => "--" + x.Key + "=" + x.Value));

                // A bit of a hack but if we find a configuration called executable for the editor
                // if the path is rooted (avvoids checking for files in PATH) display a warning
                // if it does not exist.
                var executableSetting = configReader.Get("editor." + editorName + ".executable");
                if (executableSetting != null)
                {
                    if (Path.IsPathRooted(executableSetting))
                    {
                        if (!File.Exists(executableSetting))
                        {
                            _dispatch("warning|The configured path for the " + editorName + " editor does not exist: " + executableSetting);
                        }
                    }
                }

                if (!_environment.HasEditorEngine(_rootPath))
                {
                    if (!_environment.StartEditorEngine(args, _rootPath))
                    {
                        Logger.Write("Could not launch editor " + args[0]);
                        return;
                    }
                }
                if (!_environment.HasEditorEngine(_rootPath))
                {
                    Logger.Write("Could not launch editor " + args[0]);
                    return;
                }
                if (!_environment.IsRunning(_rootPath))
                {
                    _environment.Start(_rootPath);
                }
            }
            else if (arguments.Length >= 1 && arguments[0] == "get-dirty-files")
            {
                if (instance == null)
                {
                    return;
                }
                string file = null;
                if (arguments.Length > 1)
                {
                    file = arguments[1];
                }
                Console.WriteLine(instance.GetDirtyFiles(file));
            }
            else if (arguments.Length == 1 && arguments[0] == "get-caret")
            {
                Console.WriteLine(instance.GetCaret());
            }
            else if (arguments.Length == 3 && arguments[0] == "user-select")
            {
                instance.UserSelect(arguments[1], arguments[2]);
            }
            else if (arguments.Length >= 2 && arguments[0] == "user-input")
            {
                var defaultvalue = "";
                if (arguments.Length > 2)
                {
                    defaultvalue = arguments[2];
                }
                instance.UserInput(arguments[1], defaultvalue);
            }
            else
            {
                if (instance == null)
                {
                    return;
                }
                var editor = _editorFactory.GetInstance(_rootPath);
                if (editor != null)
                {
                    Console.WriteLine("There is already an editor session running at this location. Run 'oi environment details' for more information.");
                }
                instance.Run(arguments);
            }
        }