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

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

            RootTreeGrid.ItemsSource = new TreeNodeCollection(_rootNode).ItemList;
        }
Esempio n. 8
0
 private void CopyEntry(VariableViewModel model)
 {
     if (model != null)
     {
         string data = Invariant($"{model.Name} {model.Value} {model.Class} {model.TypeName}");
         SetClipboardData(data);
     }
 }
Esempio n. 9
0
 internal void SetEvaluation(VariableViewModel evaluation, string caption)
 {
     if (!string.IsNullOrWhiteSpace(evaluation.Expression))
     {
         Caption = Invariant($"{Resources.VariableGrid_Caption}: {caption}");
     }
     _gridHost.SetEvaluation(evaluation);
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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));
            }
        }
Esempio n. 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;
            }
        }
Esempio n. 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));
            }
        }
Esempio n. 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));
            }
        }
Esempio n. 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();
            }
        }
Esempio n. 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();
             }
         }
     }
 }
Esempio n. 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);
        }
Esempio n. 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;
        }
Esempio n. 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();
            }
        }
Esempio n. 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();
        }
Esempio n. 22
0
        private void SetRootNode(VariableViewModel evaluation) {
            _rootNode = new ObservableTreeNode(
                new VariableNode(_settings, evaluation),
                Comparer<ITreeNode>.Create(Comparison));

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

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

            return(wrapper.CanShowDetail);
        }