Exemple #1
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            if (!TaskAvailable())
            {
                return(CommandResult.Disabled);
            }

            IMarkdownFlavorPublishHandler flavorHandler = GetFlavorHandler(TextView.TextBuffer);

            if (flavorHandler != null)
            {
                var workflow        = _workflowProvider.GetOrCreate();
                var getPackagesTask = workflow.Packages.GetInstalledPackagesAsync();
                getPackagesTask.Wait(5000);
                var packages = getPackagesTask.Result;

                if (!packages.Any(p => p.Package.EqualsIgnoreCase(flavorHandler.RequiredPackageName)))
                {
                    _coreShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_PackageMissing, flavorHandler.RequiredPackageName));
                    return(CommandResult.Disabled);
                }

                if (!CheckPrerequisites())
                {
                    return(CommandResult.Disabled);
                }

                // Save the file
                var document = EditorExtensions.FindInProjectedBuffers <MdEditorDocument>(TextView.TextBuffer, MdContentTypeDefinition.ContentType);
                var tb       = document.TextBuffer;
                if (!tb.CanBeSavedInCurrentEncoding())
                {
                    if (MessageButtons.No == _coreShell.ShowMessage(Resources.Warning_SaveInUtf8, MessageButtons.YesNo))
                    {
                        return(CommandResult.Executed);
                    }
                    tb.Save(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
                }
                else
                {
                    tb.Save();
                }

                var inputFilePath = tb.GetFilePath();
                _outputFilePath = Path.ChangeExtension(inputFilePath, FileExtension);

                try {
                    _fs.DeleteFile(_outputFilePath);
                } catch (IOException ex) {
                    _coreShell.ShowErrorMessage(ex.Message);
                    return(CommandResult.Executed);
                }

                var session = workflow.RSession;
                _lastCommandTask = flavorHandler.PublishAsync(session, _coreShell, _fs, inputFilePath, _outputFilePath, Format, tb.GetEncoding()).ContinueWith(t => LaunchViewer());
            }
            return(CommandResult.Executed);
        }
Exemple #2
0
        public override CommandResult Invoke(Guid group, int id, object inputArg, ref object outputArg)
        {
            if (!TaskAvailable())
            {
                return(CommandResult.Disabled);
            }

            IMarkdownFlavorPublishHandler flavorHandler = GetFlavorHandler(TextView.TextBuffer);

            if (flavorHandler != null)
            {
                if (!InstallPackages.IsInstalled(flavorHandler.RequiredPackageName, 5000, RToolsSettings.Current.RBasePath))
                {
                    VsAppShell.Current.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_PackageMissing, flavorHandler.RequiredPackageName));
                    return(CommandResult.Disabled);
                }

                if (!CheckPrerequisites())
                {
                    return(CommandResult.Disabled);
                }

                // Save the file
                var document = EditorExtensions.FindInProjectedBuffers <MdEditorDocument>(TextView.TextBuffer, MdContentTypeDefinition.ContentType);
                var tb       = document.TextBuffer;
                if (!tb.CanBeSavedInCurrentEncoding())
                {
                    if (MessageButtons.No == VsAppShell.Current.ShowMessage(Resources.Warning_SaveInUtf8, MessageButtons.YesNo))
                    {
                        return(CommandResult.Executed);
                    }
                    tb.Save(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
                }
                else
                {
                    tb.Save();
                }

                var inputFilePath = tb.GetFilePath();
                _outputFilePath = Path.ChangeExtension(inputFilePath, FileExtension);

                try {
                    File.Delete(_outputFilePath);
                } catch (IOException ex) {
                    VsAppShell.Current.ShowErrorMessage(ex.Message);
                    return(CommandResult.Executed);
                }

                inputFilePath = inputFilePath.Replace('\\', '/');
                string outputFilePath = _outputFilePath.Replace('\\', '/');

                string arguments = flavorHandler.GetCommandLine(inputFilePath, outputFilePath, Format, tb.GetEncoding());
                var    session   = _workflowProvider.GetOrCreate().RSession;
                _lastCommandTask = session.ExecuteAsync(arguments).ContinueWith(t => LaunchViewer());
            }
            return(CommandResult.Executed);
        }
Exemple #3
0
        private ITextBuffer SaveFile()
        {
            var document = EditorExtensions.FindInProjectedBuffers <MdEditorDocument>(TextView.TextBuffer, MdContentTypeDefinition.ContentType);
            var tb       = document.TextBuffer;

            if (!tb.CanBeSavedInCurrentEncoding())
            {
                if (MessageButtons.No == Services.ShowMessage(Resources.Warning_SaveInUtf8, MessageButtons.YesNo))
                {
                    return(null);
                }
                tb.Save(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
            }
            else
            {
                tb.Save();
            }
            return(tb);
        }
Exemple #4
0
 /// <summary>
 /// Given text view locates R document in underlying text buffer graph.
 /// In REPL window there may be multiple R text buffers but usually
 /// only last one (the one active at the > prompt) has attached R document.
 /// Other R buffers represent previously typed commands. They still have
 /// colorizer attached but no active R documents.
 /// </summary>
 /// <param name="viewBuffer"></param>
 /// <returns></returns>
 public static IREditorDocument FindInProjectedBuffers(ITextBuffer viewBuffer)
 {
     return(EditorExtensions.FindInProjectedBuffers <IREditorDocument>(viewBuffer, RContentTypeDefinition.ContentType));
 }