public void ShowDataGrid(IREvaluationResultInfo evaluationResult) { var wrapper = new VariableViewModel(evaluationResult, _aggregator); if (!wrapper.CanShowDetail) { throw new InvalidOperationException("Cannot show data grid on evaluation result " + evaluationResult); } wrapper.ShowDetailCommand.Execute(null); }
private void CopyValue(VariableViewModel model) { if (model != null) { SetClipboardData(model.Value); } }
public static VariableViewModel Error(string text) { var instance = new VariableViewModel(); instance.Name = string.Empty; instance.Value = text; instance.HasChildren = false; return instance; }
private async Task SetRootModelAsync(REnvironment env) { _shell.AssertIsOnMainThread(); if (env.Kind != REnvironmentKind.Error) { try { var result = await EvaluateAndDescribeAsync(env); var wrapper = new VariableViewModel(result, _aggregator); _rootNode.Model = new VariableNode(_settings, wrapper); } catch (RException ex) { SetRootNode(VariableViewModel.Error(ex.Message)); } catch (RHostDisconnectedException ex) { SetRootNode(VariableViewModel.Error(ex.Message)); } } else { SetRootNode(VariableViewModel.Error(env.Name)); } // Some of the Variable Explorer tool bar buttons are depend on the R Environment (e.g., Delete all Variables button). // This will give those UI elements a chance to update state. _shell.UpdateCommandStatus(); }
public GridDataProvider(VariableViewModel evaluation) { _evaluation = evaluation; RowCount = evaluation.Dimensions[0]; ColumnCount = evaluation.Dimensions[1]; }
internal void SetEvaluation(VariableViewModel wrapper) { VsAppShell.Current.AssertIsOnMainThread(); // Is the variable gone? if (wrapper.TypeName == null) { SetError(string.Format(CultureInfo.InvariantCulture, Package.Resources.VariableGrid_Missing, wrapper.Expression)); _evaluation = null; return; } ClearError(); // Does it have the same size and shape? If so, can update in-place (without losing scrolling etc). if (_evaluation?.Dimensions.SequenceEqual(wrapper.Dimensions) == true) { VariableGrid.Refresh(); return; } // Otherwise, need to refresh the whole thing from scratch. VariableGrid.Initialize(new GridDataProvider(wrapper)); _evaluation = wrapper; }
private void SetRootNode(VariableViewModel evaluation) { _rootNode = new ObservableTreeNode( new VariableNode(_settings, evaluation), Comparer <ITreeNode> .Create(Comparison)); RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList; }
private void CopyEntry(VariableViewModel model) { if (model != null) { string data = Invariant($"{model.Name} {model.Value} {model.Class} {model.TypeName}"); SetClipboardData(data); } }
internal void SetEvaluation(VariableViewModel evaluation, string caption) { if (!string.IsNullOrWhiteSpace(evaluation.Expression)) { Caption = Invariant($"{Resources.VariableGrid_Caption}: {caption}"); } _gridHost.SetEvaluation(evaluation); }
public static VariableViewModel Error(string text) { var instance = new VariableViewModel(null); instance.Name = string.Empty; instance.Value = text; instance.HasChildren = false; return(instance); }
private async Task EvaluateAsync() { try { await TaskUtilities.SwitchToBackgroundThread(); const REvaluationResultProperties properties = ClassesProperty| ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty; var result = await _rSession.TryEvaluateAndDescribeAsync(_evaluation.Expression, properties, null); var wrapper = new VariableViewModel(result, _aggregator); VsAppShell.Current.DispatchOnUIThread(() => SetEvaluation(wrapper)); } catch (Exception ex) { VsAppShell.Current.DispatchOnUIThread(() => SetError(ex.Message)); } }
public GridDataProvider(VariableViewModel evaluation) { _evaluation = evaluation; RowCount = evaluation.Dimensions[0]; ColumnCount = evaluation.Dimensions.Count >= 2 ? evaluation.Dimensions[1] : 1; CanSort = true; // Lists cannot be sorted, except when the list is a dataframe. if (evaluation.TypeName == "list") { var er = evaluation.DebugEvaluation as IRValueInfo; CanSort = er?.Classes.Contains("data.frame") == true; } }
private async Task EvaluateAsync() { try { await TaskUtilities.SwitchToBackgroundThread(); const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty; var result = await _rSession.TryEvaluateAndDescribeAsync(_evaluation.Expression, properties, null); var wrapper = new VariableViewModel(result, _services); _services.MainThread().Post(() => SetEvaluation(wrapper)); } catch (Exception ex) { _services.MainThread().Post(() => SetError(ex.Message)); } }
private async Task EvaluateAsync() { try { await TaskUtilities.SwitchToBackgroundThread(); const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty; var result = await _rSession.TryEvaluateAndDescribeAsync(_evaluation.Expression, properties, null); var wrapper = new VariableViewModel(result, _aggregator); VsAppShell.Current.DispatchOnUIThread(() => SetEvaluation(wrapper)); } catch (Exception ex) { VsAppShell.Current.DispatchOnUIThread(() => SetError(ex.Message)); } }
public async Task<IREvaluationResultInfo> EvaluateAsync(string rScript) { // One eval at a time await _sem.WaitAsync(); try { var frames = await Session.TracebackAsync(); var frame = frames.FirstOrDefault(f => f.Index == 0); const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty| LengthProperty; var result = await frame.TryEvaluateAndDescribeAsync(rScript, properties, RValueRepresentations.Str()); var globalResult = await frame.TryEvaluateAndDescribeAsync("base::environment()", properties, RValueRepresentations.Str()); _globalEnv = new VariableViewModel(globalResult, VsAppShell.Current.ExportProvider.GetExportedValue<IObjectDetailsViewerAggregator>()); return result; } finally { _sem.Release(); } }
private void EnvironmentComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if ((EnvironmentComboBox.ItemsSource != _defaultEnvironments) && (e.AddedItems.Count > 0)) { var env = e.AddedItems[0] as REnvironment; if (env != null) { if (env.Kind == REnvironmentKind.Error) { SetRootNode(VariableViewModel.Error(env.Name)); } else { SetRootModelAsync(env).DoNotWait(); } } } }
private async Task SetRootModelAsync(REnvironment env) { await TaskUtilities.SwitchToBackgroundThread(); const REvaluationResultProperties properties = ClassesProperty | ExpressionProperty | TypeNameProperty | DimProperty | LengthProperty; IRValueInfo result; try { result = await _session.EvaluateAndDescribeAsync(env.EnvironmentExpression, properties, null); } catch (RException ex) { VsAppShell.Current.DispatchOnUIThread(() => SetRootNode(VariableViewModel.Error(ex.Message))); return; } var wrapper = new VariableViewModel(result, _aggregator); var rootNodeModel = new VariableNode(_settings, wrapper); VsAppShell.Current.DispatchOnUIThread(() => _rootNode.Model = rootNodeModel); }
internal void SetEvaluation(VariableViewModel wrapper) { VsAppShell.Current.AssertIsOnMainThread(); if (wrapper.TypeName == "NULL" && wrapper.Value == "NULL") { // the variable should have been removed SetError(string.Format(CultureInfo.InvariantCulture, Package.Resources.VariableGrid_Missing, wrapper.Expression)); } else if (_evaluation == null || (wrapper.Dimensions.Count == 2 && (wrapper.Dimensions[0] != _evaluation.Dimensions[0] || wrapper.Dimensions[1] != _evaluation.Dimensions[1]))) { // matrix size changed. Reset the evaluation ClearError(); VariableGrid.Initialize(new GridDataProvider(wrapper)); _evaluation = wrapper; } else { ClearError(); // size stays same. Refresh VariableGrid.Refresh(); } }
public async Task DoesNotExist() { // This is the equivalent of what we get when we fetch a variable // for a data grid after that variable is no longer available (rm or reset). var script = "idonotexist"; var evaluationResult = await _hostScript.EvaluateAsync(script); evaluationResult.Name.Should().BeNull(); evaluationResult.Expression.Should().Be("idonotexist"); var model = new VariableViewModel(evaluationResult, null); model.TypeName.Should().BeNull(); model.Value.Should().BeNull(); }
private void SetRootNode(VariableViewModel evaluation) { _rootNode = new ObservableTreeNode( new VariableNode(_settings, evaluation), Comparer<ITreeNode>.Create(Comparison)); RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList; }
public bool CanShowDataGrid(IREvaluationResultInfo evaluationResult) { var wrapper = new VariableViewModel(evaluationResult, _aggregator); return wrapper.CanShowDetail; }
public VariableNode(IRSettings settings, VariableViewModel evaluation) { _settings = settings; _evaluation = evaluation; }
private async Task PrepareControl(VariableRHostScript hostScript, ControlTestScript script, string expression) { DoIdle(100); var result = await hostScript.EvaluateAsync(expression); VariableViewModel wrapper = new VariableViewModel(result, VsAppShell.Current.ExportProvider.GetExportedValue<IObjectDetailsViewerAggregator>()); DoIdle(2000); wrapper.Should().NotBeNull(); UIThreadHelper.Instance.Invoke(() => { var host = (VariableGridHost)script.Control; host.SetEvaluation(wrapper); }); DoIdle(1000); }
public bool CanShowDataGrid(IREvaluationResultInfo evaluationResult) { var wrapper = new VariableViewModel(evaluationResult, _aggregator); return(wrapper.CanShowDetail); }
public VariableNode(IRToolsSettings settings, VariableViewModel evaluation) { _settings = settings; _evaluation = evaluation; }
public bool CanShowDataGrid(IREvaluationResultInfo evaluationResult) { var wrapper = new VariableViewModel(evaluationResult, _coreShell.Services); return(wrapper.CanShowDetail); }