From 726e2dfb60eb0e79bb5c69ab6917aed4a2e65513 Mon Sep 17 00:00:00 2001 From: Matteo Cominetti Date: Tue, 27 Sep 2022 09:32:59 +0100 Subject: [PATCH] fix(rhino): stream edit view selection issues in rhino (#1614) --- .../ConnectorRhinoShared/Entry/Plugin.cs | 5 ----- .../ConnectorRhinoShared/UI/Panel.xaml.cs | 9 ++++++--- DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs | 12 +++++------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/Entry/Plugin.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/Entry/Plugin.cs index 7a9cda1ebe..4821fdf82a 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/Entry/Plugin.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/Entry/Plugin.cs @@ -21,7 +21,6 @@ public class SpeckleRhinoConnectorPlugin : PlugIn private static string SpeckleKey = "speckle2"; public ConnectorBindingsRhino Bindings { get; private set; } - public MainViewModel ViewModel { get; private set; } internal bool _initialized; @@ -39,7 +38,6 @@ public void Init() SpeckleCommand.InitAvalonia(); Bindings = new ConnectorBindingsRhino(); - ViewModel = new MainViewModel(Bindings); RhinoDoc.BeginOpenDocument += RhinoDoc_BeginOpenDocument; RhinoDoc.EndOpenDocument += RhinoDoc_EndOpenDocument; @@ -82,9 +80,6 @@ private void RhinoDoc_EndOpenDocument(object sender, DocumentOpenEventArgs e) private void RhinoDoc_BeginOpenDocument(object sender, DocumentOpenEventArgs e) { - //new document => new view model (used by the panel only) - ViewModel = new MainViewModel(Bindings); - if (e.Merge) // this is a paste or import event { // get existing streams in doc before a paste or import operation to use for cleanup diff --git a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/Panel.xaml.cs b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/Panel.xaml.cs index b0ace12eb8..54fc691737 100644 --- a/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/Panel.xaml.cs +++ b/ConnectorRhino/ConnectorRhino/ConnectorRhinoShared/UI/Panel.xaml.cs @@ -17,8 +17,11 @@ public Panel() try { InitializeComponent(); - //Set in the Plugin so that it's not disposed each time the panel is closed - this.DataContext = SpeckleRhinoConnectorPlugin.Instance.ViewModel; + //set here otherwise we get errors about re-used visual parents when closing and re-opening the panel + //there might be other solutions too. If changing this behaviour make sure to refresh the view model + //when opening a new file as well + var viewModel = new MainViewModel(SpeckleRhinoConnectorPlugin.Instance.Bindings); + this.DataContext = viewModel; AvaloniaHost.Content = new MainUserControl(); } catch (Exception ex) @@ -26,7 +29,7 @@ public Panel() } - + } diff --git a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs index 61f84aad0f..b58776a698 100644 --- a/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs +++ b/DesktopUI2/DesktopUI2/ViewModels/StreamViewModel.cs @@ -33,7 +33,7 @@ public class StreamViewModel : ReactiveObject, IRoutableViewModel { public StreamState StreamState { get; set; } - private IScreen HostScreen { get; set; } + public IScreen HostScreen { get; set; } private ConnectorBindings Bindings; @@ -306,8 +306,8 @@ public List FilteredReport else { var filterItems = _reportSelectedFilterItems.Any() ? Report.Where(o => _reportSelectedFilterItems.Any(a => o.Status == a)).ToList() : Report; - return SearchQuery == "" ? - filterItems : + return SearchQuery == "" ? + filterItems : filterItems.Where(o => _searchQueryItems.All(a => o.SearchText.ToLower().Contains(a.ToLower()))).ToList(); } } @@ -320,13 +320,13 @@ public string Log { get { - string defaultMessage = string.IsNullOrEmpty(Progress.Report.ConversionLogString) ? + string defaultMessage = string.IsNullOrEmpty(Progress.Report.ConversionLogString) ? "\nWelcome to the report! \n\nObjects you send or receive will appear here to help you understand how your document has changed." : Progress.Report.ConversionLogString; string reportInfo = $"\nOperation: {(PreviewOn ? "Preview " : "")}{(IsReceiver ? "Received at " : "Sent at ")}{DateTime.Now.ToLocalTime().ToString("dd/MM/yy HH:mm:ss")}"; reportInfo += $"\nTotal: {Report.Count} objects"; - reportInfo += Progress.Report.OperationErrors.Any() ? $"\n\nErrors: \n{Progress.Report.OperationErrorsString}":""; + reportInfo += Progress.Report.OperationErrors.Any() ? $"\n\nErrors: \n{Progress.Report.OperationErrorsString}" : ""; return Report.Any() || Progress.Report.OperationErrors.Any() ? reportInfo : defaultMessage; } @@ -478,8 +478,6 @@ private string Url } } - IScreen IRoutableViewModel.HostScreen => throw new NotImplementedException(); - public void UpdateVisualParentAndInit(IScreen hostScreen) { HostScreen = hostScreen;