Exemplo n.º 1
0
 private void OnWindowUnload(object sender, HtmlElementEventArgs e)
 {
     // Refresh button clicked. Current document state is 'complete'.
     // We need to delay until it changes to 'loading' and then
     // delay again until it changes again to 'complete'.
     IdleTimeAction.Create(() => SetThemeColorsWhenReady(), 10, new object(), _idleTime);
 }
Exemplo n.º 2
0
        public static void OnCommand(object sender, EventArgs args)
        {
            if (MessageButtons.Yes == VsAppShell.Current.ShowMessage(Resources.Warning_SettingsReset, MessageButtons.YesNo))
            {
                IVsUIShell shell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell));
                Guid       group = VSConstants.CMDSETID.StandardCommandSet2K_guid;

                string asmDirectory      = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetAssemblyPath());
                string settingsFilePath1 = Path.Combine(asmDirectory, @"Profiles\", "R.vssettings");
                string settingsFilePath2 = Path.Combine(asmDirectory, @"Profiles\", "RStudioKeyboard.vssettings");
                if (!File.Exists(settingsFilePath1))
                {
                    string ideFolder = asmDirectory.Substring(0, asmDirectory.IndexOf(@"\Extensions", StringComparison.OrdinalIgnoreCase));
                    settingsFilePath1 = Path.Combine(ideFolder, @"Profiles\", "R.vssettings");
                }

                object arguments = string.Format(CultureInfo.InvariantCulture, "-import:\"{0}\"", settingsFilePath1);
                shell.PostExecCommand(ref group, (uint)VSConstants.VSStd2KCmdID.ManageUserSettings, 0, ref arguments);

                if (MessageButtons.Yes == VsAppShell.Current.ShowMessage(Resources.Warning_RStudioKeyboardShortcuts, MessageButtons.YesNo))
                {
                    arguments = string.Format(CultureInfo.InvariantCulture, "-import:\"{0}\"", settingsFilePath2);
                    shell.PostExecCommand(ref group, (uint)VSConstants.VSStd2KCmdID.ManageUserSettings, 0, ref arguments);
                }

                // Restore Ctrl+Enter if necessary
                IdleTimeAction.Create(() => {
                    ReplShortcutSetting.Close();
                    ReplShortcutSetting.Initialize();
                }, 100, typeof(ImportRSettingsCommand));
            }
        }
Exemplo n.º 3
0
        protected override void Initialize()
        {
            Current = this;

            VsAppShell.EnsureInitialized();
            if (IsCommandLineMode())
            {
                return;
            }

            VsWpfOverrides.Apply();
            CranMirrorList.Download();

            base.Initialize();

            ProjectIconProvider.LoadProjectImages(VsAppShell.Current.Services);
            LogCleanup.DeleteLogsAsync(DiagnosticLogs.DaysToRetain);

            var settings       = VsAppShell.Current.GetService <IRToolsSettings>();
            var editorSettings = VsAppShell.Current.GetService <IREditorSettings>();

            RtvsTelemetry.Initialize(_packageIndex, settings, editorSettings);

            BuildFunctionIndex();
            AdviseExportedWindowFrameEvents <ActiveWpfTextViewTracker>();
            AdviseExportedWindowFrameEvents <VsActiveRInteractiveWindowTracker>();
            AdviseExportedDebuggerEvents <VsDebuggerModeTracker>();

            System.Threading.Tasks.Task.Run(() => RtvsTelemetry.Current.ReportConfiguration());
            IdleTimeAction.Create(ExpansionsCache.Load, 200, typeof(ExpansionsCache), VsAppShell.Current);
        }
Exemplo n.º 4
0
        protected override void Initialize()
        {
            Current = this;

            VsAppShell.EnsureInitialized();
            if (IsCommandLineMode())
            {
                return;
            }

            VsWpfOverrides.Apply();
            CranMirrorList.Download();

            using (var p = Current.GetDialogPage(typeof(RToolsOptionsPage)) as RToolsOptionsPage) {
                p?.LoadSettings();
            }

            RtvsTelemetry.Initialize(_packageIndex, VsAppShell.Current.ExportProvider.GetExportedValue <IRSettings>());
            base.Initialize();

            ProjectIconProvider.LoadProjectImages();
            LogCleanup.DeleteLogsAsync(DiagnosticLogs.DaysToRetain);

            BuildFunctionIndex();
            AdviseExportedWindowFrameEvents <ActiveWpfTextViewTracker>();
            AdviseExportedWindowFrameEvents <VsActiveRInteractiveWindowTracker>();
            AdviseExportedDebuggerEvents <VsDebuggerModeTracker>();

            IdleTimeAction.Create(ExpansionsCache.Load, 200, typeof(ExpansionsCache), VsAppShell.Current);
            IdleTimeAction.Create(() => RtvsTelemetry.Current.ReportConfiguration(), 5000, typeof(RtvsTelemetry), VsAppShell.Current);
        }
Exemplo n.º 5
0
 private void OnCaretPositionChanged(object sender, CaretPositionChangedEventArgs e)
 {
     if (CanHighlight(_textView) || _highlighted)
     {
         IdleTimeAction.Create(UpdateAtCaretPosition, 150, this, _idleTime);
     }
 }
Exemplo n.º 6
0
        public VariableProvider(
            [Import(typeof(IRSessionProvider))] IRSessionProvider sessionProvider,
            [Import(typeof(IDebugSessionProvider))] IDebugSessionProvider debugSessionProvider)
        {
            if (sessionProvider == null)
            {
                throw new ArgumentNullException(nameof(sessionProvider));
            }
            if (debugSessionProvider == null)
            {
                throw new ArgumentNullException(nameof(debugSessionProvider));
            }


            RSession = sessionProvider.GetInteractiveWindowRSession();
            if (RSession == null)
            {
                throw new InvalidOperationException(Invariant($"{nameof(IRSessionProvider)} failed to return RSession for {nameof(IVariableDataProvider)}"));
            }
            RSession.Mutated += RSession_Mutated;

            IdleTimeAction.Create(() => {
                PublishAllAsync().SilenceException <Exception>().DoNotWait();
            }, 10, typeof(VariableProvider));
        }
Exemplo n.º 7
0
        private static void DisposeServiceManagerOnIdle(IPropertyOwner propertyOwner, ICoreShell shell)
        {
            var sm = FromPropertyOwner(propertyOwner, null);

            if (sm != null)
            {
                IdleTimeAction.Create(() => sm.Dispose(), 150, new object(), shell);
            }
        }
Exemplo n.º 8
0
 private void NavigateOnIdle(WebBrowserRole role, string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         IdleTimeAction.Create(() => {
             OpenVsBrowser(role, url);
         }, 100, typeof(WebBrowserServices), _coreShell.GetService <IIdleTimeService>());
     }
 }
Exemplo n.º 9
0
 private void SetThemeColorsWhenReady()
 {
     if (!ConnectBrowser())
     {
         // The browser document is not ready yet. Create another idle
         // time action that will run after few milliseconds.
         IdleTimeAction.Create(SetThemeColorsWhenReady, 10, new object(), _services.GetService <IIdleTimeService>());
     }
 }
Exemplo n.º 10
0
 internal ExpansionsCache(IVsExpansionManager expansionManager, IServiceContainer services)
 {
     // Caching language expansion structs requires access to the IVsExpansionManager
     // service which is valid on the main thread only. So we create cache on the main
     // thread so we can then access objects from background threads.
     _instance = this;
     _services = services;
     IdleTimeAction.Create(() => CacheLanguageExpansionStructs(expansionManager), 200, typeof(ExpansionsCache), services.GetService <IIdleTimeService>());
 }
Exemplo n.º 11
0
 public Task AfterPackagesInstalledAsync(CancellationToken cancellationToken)
 {
     _updatePending = true;
     // Create delayed action. There may be multiple install.packages
     // commands pending and we want to update index when processing
     // is fully completes.
     IdleTimeAction.Create(() => UpdateInstalledPackagesAsync(cancellationToken).DoNotWait(), 1000, GetType(), _idleTime);
     return(Task.CompletedTask);
 }
Exemplo n.º 12
0
 private void SetThemeColorsWhenReady()
 {
     if (!ConnectBrowser())
     {
         // The browser document is not ready yet. Create another idle
         // time action that will run after few milliseconds.
         IdleTimeAction.Create(SetThemeColorsWhenReady, 10, new object(), VsAppShell.Current);
     }
 }
Exemplo n.º 13
0
 private void NavigateOnIdle(WebBrowserRole role, string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         IdleTimeAction.Create(() => {
             OpenVsBrowser(role, url);
         }, 100, typeof(WebBrowserServices), VsAppShell.Current);
     }
 }
Exemplo n.º 14
0
 public void NavigateOnIdle(string url)
 {
     if (!string.IsNullOrEmpty(url))
     {
         IdleTimeAction.Create(() => {
             Navigate(url);
         }, 100, typeof(SurveyNewsBrowserLauncher));
     }
 }
Exemplo n.º 15
0
 private void OnViewLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
 {
     if (e.NewSnapshot != e.OldSnapshot)
     {
         if (CanHighlight(_textView) || _highlighted)
         {
             IdleTimeAction.Create(UpdateAtCaretPosition, 150, this, _idleTime);
         }
     }
 }
Exemplo n.º 16
0
 void OnViewLayoutChanged(object sender, TextViewLayoutChangedEventArgs e)
 {
     if (e.NewSnapshot != e.OldSnapshot) // make sure that there has really been a change
     {
         if (CanHighlight(_textView) || _highlighted)
         {
             IdleTimeAction.Create(() => UpdateAtCaretPosition(), 150, this);
         }
     }
 }
Exemplo n.º 17
0
        private void UpdateBrowserScrollPosition()
        {
            if (!_settings.ScrollPreviewWithEditor)
            {
                return;
            }

            IdleTimeAction.Create(() => {
                var lineNumber = _textView.TextSnapshot.GetLineNumberFromPosition(_textView.TextViewLines.FirstVisibleLine.Start);
                Browser.UpdatePosition(lineNumber);
            }, 5, GetType(), _idleTime);
        }
Exemplo n.º 18
0
 private void UpdateBrowser()
 {
     if (_browserUpdateTask == null)
     {
         _textChanged       = false;
         _browserUpdateTask = Browser
                              .UpdateBrowserAsync(_textView.TextBuffer.CurrentSnapshot)
                              .ContinueWith(t => _browserUpdateTask = null);
     }
     else
     {
         // Still running, try again later
         IdleTimeAction.Create(Update, 500, _idleActionTag, _idleTime);
     }
 }
Exemplo n.º 19
0
        private void PlotWindowPane_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
        {
            var unadjustedPixelSize = WpfUnitsConversion.ToPixels(Content as Visual, e.NewSize);

            // If the window gets below a certain minimum size, plot to the minimum size
            // and user will be able to use scrollbars to see the whole thing
            int pixelWidth  = Math.Max((int)unadjustedPixelSize.Width, MinPixelWidth);
            int pixelHeight = Math.Max((int)unadjustedPixelSize.Height, MinPixelHeight);

            // Throttle resize requests since we get a lot of size changed events when the tool window is undocked
            IdleTimeAction.Cancel(this);
            IdleTimeAction.Create(() => {
                PlotContentProvider.DoNotWait(_plotHistory.PlotContentProvider.ResizePlotAsync(pixelWidth, pixelHeight));
            }, 100, this);
        }
Exemplo n.º 20
0
        private void SetThemeColorsWhenReady()
        {
            var domDoc = Browser.Document.DomDocument as IHTMLDocument2;

            if (Browser.ReadyState == WebBrowserReadyState.Complete)
            {
                SetThemeColors();
                Browser.Document.Window.Unload += OnWindowUnload;
            }
            else
            {
                // The browser document is not ready yet. Create another idle
                // time action that will run after few milliseconds.
                IdleTimeAction.Create(() => SetThemeColorsWhenReady(), 10, new object());
            }
        }
Exemplo n.º 21
0
        protected override void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
        {
            var c           = e.ToTextChange();
            var destructive = _separators.IsDestructiveChange(c.Start, c.OldLength, c.NewLength, c.OldTextProvider, c.NewTextProvider);

            if (destructive)
            {
                // Allow existing command call to complete so we don't yank projections
                // from underneath code that expects text buffer to exist, such as formatter.
                IdleTimeAction.Cancel(GetType());
                IdleTimeAction.Create(UpdateProjections, 0, GetType(), idleTime);
            }
            else
            {
                Blocks.ReflectTextChange(c.Start, c.OldLength, c.NewLength);
                _separators.ReflectTextChange(c.Start, c.OldLength, c.NewLength);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Resumes tree updates. If changes were made to the text buffer
        /// since suspend, full parse is performed.
        /// </summary>
        internal void Resume()
        {
            if (UpdatesSuspended)
            {
                UpdatesSuspended = false;

                if (TextBufferChangedSinceSuspend)
                {
                    TextBufferChangedSinceSuspend = false;

                    IdleTimeAction.Create(() => {
                        try {
                            ProcessPendingTextBufferChanges(async: true);
                        } catch (Exception e) {
                            Debug.Assert(false, "Guarded invoke caught exception", e.Message);
                        }
                    }, 10, GetType(), _idleTime);
                }
            }
        }
Exemplo n.º 23
0
        protected override void OnTextBufferChanged(object sender, TextContentChangedEventArgs e)
        {
            var changes = e.ConvertToRelative();

            foreach (var c in changes)
            {
                var destructive = _separators.IsDestructiveChange(c.OldStart, c.OldLength, c.NewLength, c.OldText, c.NewText);
                if (destructive)
                {
                    // Allow existing command call to complete so we don't yank projections
                    // from underneath code that expects text buffer to exist, such as formatter.
                    IdleTimeAction.Cancel(this.GetType());
                    IdleTimeAction.Create(() => UpdateProjections(), 0, this.GetType());
                    break;
                }
                else
                {
                    Blocks.ReflectTextChange(c.OldStart, c.OldLength, c.NewLength);
                    _separators.ReflectTextChange(c.OldStart, c.OldLength, c.NewLength);
                }
            }
        }
Exemplo n.º 24
0
        protected override void Initialize()
        {
            Current = this;

            // Force app shell creation before everything else
            var shell = VsAppShell.Current;

            if (IsCommandLineMode())
            {
                return;
            }

            VsWpfOverrides.Apply();
            CranMirrorList.Download();

            RtvsTelemetry.Initialize();

            using (var p = Current.GetDialogPage(typeof(RToolsOptionsPage)) as RToolsOptionsPage) {
                p.LoadSettings();
            }

            MicrosoftRClient.CheckInstall(VsAppShell.Current);
            base.Initialize();

            ProjectIconProvider.LoadProjectImages();
            LogCleanup.DeleteLogsAsync(DiagnosticLogs.DaysToRetain);

            _indexBuildingTask = FunctionIndex.BuildIndexAsync();

            AdviseExportedWindowFrameEvents <ActiveWpfTextViewTracker>();
            AdviseExportedWindowFrameEvents <VsActiveRInteractiveWindowTracker>();
            AdviseExportedDebuggerEvents <VsDebuggerModeTracker>();

            System.Threading.Tasks.Task.Run(() => RtvsTelemetry.Current.ReportConfiguration());

            IdleTimeAction.Create(ExpansionsCache.Load, 200, typeof(ExpansionsCache));
        }
Exemplo n.º 25
0
        private async Task <IDocumentPeekResult> FindFunctionAsync(string sourceFileName, Span sourceSpan, string functionName)
        {
            try {
                string code = await GetFunctionCode(functionName);

                if (!string.IsNullOrEmpty(code))
                {
                    string tempFile = Path.ChangeExtension(Path.GetTempFileName(), ".r");
                    using (var sw = new StreamWriter(tempFile)) {
                        sw.Write(code);
                    }

                    using (var displayInfo = new PeekResultDisplayInfo(
                               label: functionName, labelTooltip: functionName,
                               title: functionName, titleTooltip: functionName)) {
                        _result = _peekItem.PeekResultFactory.Create(displayInfo, tempFile, new Span(0, 0), 0, isReadOnly: true);

                        // Editor opens external items as plain text. When file opens, change content type to R.
                        IdleTimeAction.Create(() => {
                            if (_result.Span.IsDocumentOpen)
                            {
                                var rs = _services.GetService <IContentTypeRegistryService>();
                                var ct = rs.GetContentType(RContentTypeDefinition.ContentType);
                                _result.Span.Document.TextBuffer.ChangeContentType(ct, this.GetType());
                                try { File.Delete(tempFile); } catch (IOException) { } catch (UnauthorizedAccessException) { }
                            }
                        }, 50, GetType(), _services.GetService <IIdleTimeService>());

                        return(_result);
                    }
                }
            } catch (Exception ex) {
                _exception = ex;
            }
            return(null);
        }
Exemplo n.º 26
0
 private void UpdateOnIdle()
 {
     IdleTimeAction.Cancel(_idleActionTag);
     IdleTimeAction.Create(() => Update(force: true), 0, _idleActionTag, _idleTime);
 }
Exemplo n.º 27
0
 private void UpdateOnIdle()
 {
     IdleTimeAction.Cancel(_idleActionTag);
     IdleTimeAction.Create(Update, 0, _idleActionTag, _idleTime);
 }
Exemplo n.º 28
0
 private void CancelPendingIndexUpdate()
 {
     _updatePending = false;
     IdleTimeAction.Cancel(GetType());
 }
Exemplo n.º 29
0
 private void ScheduleIdleTimeRebuild()
 {
     IdleTimeAction.Cancel(typeof(PackageIndex));
     IdleTimeAction.Create(() => RebuildIndexAsync().DoNotWait(), 100, typeof(PackageIndex), _shell);
 }
Exemplo n.º 30
0
 private void ScheduleIdleTimeRebuild()
 {
     IdleTimeAction.Cancel(typeof(PackageIndex));
     IdleTimeAction.Create(() => RebuildIndexAsync(CancellationToken.None).DoNotWait(), 100, GetType(), _idleTime);
 }