Model for variable tree grid, that provides UI customization of REvaluationInfo
Inheritance: Microsoft.R.Editor.Data.RSessionDataObject, IIndexedItem
示例#1
0
 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);
 }
示例#2
0
 private void CopyValue(VariableViewModel model)
 {
     if (model != null)
     {
         SetClipboardData(model.Value);
     }
 }
示例#3
0
 public static VariableViewModel Error(string text) {
     var instance = new VariableViewModel();
     instance.Name = string.Empty;
     instance.Value = text;
     instance.HasChildren = false;
     return instance;
 }
示例#4
0
        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();
        }
示例#5
0
        public GridDataProvider(VariableViewModel evaluation)
        {
            _evaluation = evaluation;

            RowCount    = evaluation.Dimensions[0];
            ColumnCount = evaluation.Dimensions[1];
        }
示例#6
0
        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;
        }
示例#7
0
        private void SetRootNode(VariableViewModel evaluation)
        {
            _rootNode = new ObservableTreeNode(
                new VariableNode(_settings, evaluation),
                Comparer <ITreeNode> .Create(Comparison));

            RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList;
        }
示例#8
0
 private void CopyEntry(VariableViewModel model)
 {
     if (model != null)
     {
         string data = Invariant($"{model.Name} {model.Value} {model.Class} {model.TypeName}");
         SetClipboardData(data);
     }
 }
示例#9
0
 internal void SetEvaluation(VariableViewModel evaluation, string caption)
 {
     if (!string.IsNullOrWhiteSpace(evaluation.Expression))
     {
         Caption = Invariant($"{Resources.VariableGrid_Caption}: {caption}");
     }
     _gridHost.SetEvaluation(evaluation);
 }
示例#10
0
        public static VariableViewModel Error(string text)
        {
            var instance = new VariableViewModel(null);

            instance.Name        = string.Empty;
            instance.Value       = text;
            instance.HasChildren = false;
            return(instance);
        }
示例#11
0
        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);
        }
示例#12
0
        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));
            }
        }
示例#13
0
        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;
            }
        }
示例#14
0
        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));
            }
        }
示例#15
0
        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));
            }
        }
示例#16
0
        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();
            }
        }
示例#17
0
 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();
             }
         }
     }
 }
示例#18
0
        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);
        }
示例#19
0
        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;
        }
示例#20
0
        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();
            }
        }
示例#21
0
        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();
        }
示例#22
0
        private void SetRootNode(VariableViewModel evaluation) {
            _rootNode = new ObservableTreeNode(
                new VariableNode(_settings, evaluation),
                Comparer<ITreeNode>.Create(Comparison));

            RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList;
        }
示例#23
0
        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();
        }
示例#24
0
 private void CopyValue(VariableViewModel model) {
     if (model != null) {
         SetClipboardData(model.Value);
     }
 }
示例#25
0
 private void CopyEntry(VariableViewModel model) {
     if (model != null) {
         string data = Invariant($"{model.Name} {model.Value} {model.Class} {model.TypeName}");
         SetClipboardData(data);
     }
 }
示例#26
0
 public bool CanShowDataGrid(IREvaluationResultInfo evaluationResult) {
     var wrapper = new VariableViewModel(evaluationResult, _aggregator);
     return wrapper.CanShowDetail;
 }
示例#27
0
 public VariableNode(IRSettings settings, VariableViewModel evaluation)
 {
     _settings   = settings;
     _evaluation = evaluation;
 }
示例#28
0
        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);
        }
示例#29
0
        public bool CanShowDataGrid(IREvaluationResultInfo evaluationResult)
        {
            var wrapper = new VariableViewModel(evaluationResult, _aggregator);

            return(wrapper.CanShowDetail);
        }
示例#30
0
 internal void SetEvaluation(VariableViewModel evaluation, string caption) {
     if (!string.IsNullOrWhiteSpace(evaluation.Expression)) {
         Caption = Invariant($"{Resources.VariableGrid_Caption}: {caption}");
     }
     _gridHost.SetEvaluation(evaluation);
 }
示例#31
0
 public VariableNode(IRToolsSettings settings, VariableViewModel evaluation) {
     _settings = settings;
     _evaluation = evaluation;
 }
示例#32
0
        public bool CanShowDataGrid(IREvaluationResultInfo evaluationResult)
        {
            var wrapper = new VariableViewModel(evaluationResult, _coreShell.Services);

            return(wrapper.CanShowDetail);
        }