Skip to content

Commit

Permalink
Restore dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nice3point committed Nov 17, 2023
1 parent a62a440 commit 690e6db
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 127 deletions.
2 changes: 1 addition & 1 deletion RevitLookup.UI/Controls/ContentDialog/ContentDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Style TargetType="{x:Type controls:ContentDialog}">
<Setter Property="ScrollViewer.CanContentScroll" Value="True" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
<Setter Property="Border.CornerRadius" Value="{DynamicResource PopupCornerRadius}" />
Expand Down
3 changes: 2 additions & 1 deletion RevitLookup/Core/RevitApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public static UIControlledApplication CreateUiControlledApplication()
null);
}

public static List<UnitInfo> GetUnitInfos(Type unitType)
public static List<UnitInfo> GetUnitInfos<T>()
{
var unitType = typeof(T);
if (unitType == typeof(BuiltInParameter))
{
var parameters = Enum.GetValues(unitType).Cast<BuiltInParameter>();
Expand Down
9 changes: 3 additions & 6 deletions RevitLookup/ViewModels/Dialogs/SearchElementsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public sealed partial class SearchElementsViewModel : ObservableObject
{
[ObservableProperty] private string _searchText = string.Empty;

public bool SearchIds(ISnoopVisualService snoopVisualService)
[Pure]
public List<Element> SearchElements()
{
var rows = SearchText.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
var items = ParseRawRequest(rows);
Expand Down Expand Up @@ -66,11 +67,7 @@ public bool SearchIds(ISnoopVisualService snoopVisualService)
}
}

if (results.Count == 0) return false;

snoopVisualService.Snoop(new SnoopableObject(results));
throw new Exception("Required navigation");
return true;
return results;
}

private static IEnumerable<Element> SearchByName(string rawId)
Expand Down
17 changes: 8 additions & 9 deletions RevitLookup/ViewModels/Dialogs/UnitsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,15 @@ namespace RevitLookup.ViewModels.Dialogs;

public sealed partial class UnitsViewModel : ObservableObject
{
private readonly List<UnitInfo> _units;
[ObservableProperty] private List<UnitInfo> _units;
[ObservableProperty] private List<UnitInfo> _filteredUnits;
[ObservableProperty] private string _searchText = string.Empty;

public UnitsViewModel(List<UnitInfo> unitType)
{
_units = unitType;
_filteredUnits = _units;
}

async partial void OnSearchTextChanged(string value)
{
if (string.IsNullOrEmpty(SearchText))
{
FilteredUnits = _units;
FilteredUnits = Units;
return;
}

Expand All @@ -48,11 +42,16 @@ async partial void OnSearchTextChanged(string value)
var formattedText = value.ToLower().Trim();
var searchResults = new List<UnitInfo>();
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var family in _units)
foreach (var family in Units)
if (family.Label.ToLower().Contains(formattedText) || family.Unit.ToLower().Contains(formattedText))
searchResults.Add(family);

return searchResults;
});
}

partial void OnUnitsChanged(List<UnitInfo> value)
{
FilteredUnits = value;
}
}
18 changes: 15 additions & 3 deletions RevitLookup/ViewModels/Pages/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@
using Microsoft.Extensions.Configuration;
using RevitLookup.Services.Contracts;
using RevitLookup.Services.Enums;
using RevitLookup.Views.Dialogs;
using Wpf.Ui;

namespace RevitLookup.ViewModels.Pages;

public sealed partial class AboutViewModel : ObservableObject
{
private readonly ISoftwareUpdateService _updateService;
private readonly IContentDialogService _dialogService;

[ObservableProperty] private string _dotNetVersion;
[ObservableProperty] private bool _isUpdateChecked;
[ObservableProperty] private string _runtimeVersion;

public AboutViewModel(ISoftwareUpdateService updateService, IConfiguration configuration)
public AboutViewModel(ISoftwareUpdateService updateService, IContentDialogService dialogService, IConfiguration configuration)
{
_updateService = updateService;
_dialogService = dialogService;
_dotNetVersion = configuration.GetValue<string>("Framework");
_runtimeVersion = Environment.Version.ToString();
}

[RelayCommand]
private async Task CheckUpdates()
private async Task CheckUpdatesAsync()
{
await _updateService.CheckUpdates();
IsUpdateChecked = true;
Expand All @@ -53,13 +58,20 @@ private async Task CheckUpdates()
}

[RelayCommand]
private async Task DownloadUpdate()
private async Task DownloadUpdateAsync()
{
await _updateService.DownloadUpdate();
OnPropertyChanged(nameof(State));
OnPropertyChanged(nameof(ErrorMessage));
}

[RelayCommand]
private Task ShowSoftwareDialogAsync()
{
var openSourceDialog = new OpenSourceDialog(_dialogService);
return openSourceDialog.ShowAsync();
}

#region Updater Wrapping

public SoftwareUpdateState State => _updateService.State;
Expand Down
58 changes: 22 additions & 36 deletions RevitLookup/ViewModels/Pages/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.

using Autodesk.Revit.DB;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using RevitLookup.Core;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.Services.Enums;
using RevitLookup.Views.Dialogs;
using RevitLookup.Views.Pages;
using Wpf.Ui;
using Wpf.Ui.Controls;

namespace RevitLookup.ViewModels.Pages;

Expand Down Expand Up @@ -135,44 +138,27 @@ private async Task NavigateSnoopPage(string parameter)
}

[RelayCommand]
private async Task OpenDialog(string parameter)
private Task OpenDialog(string parameter)
{
if (!Validate()) return;
if (!Validate()) return Task.CompletedTask;

switch (parameter)
{
case "parameters":
var unitsDialog = new UnitsDialog(_serviceProvider);
return unitsDialog.ShowParametersAsync();
case "categories":
unitsDialog = new UnitsDialog(_serviceProvider);
return unitsDialog.ShowCategoriesAsync();
case "forge":
unitsDialog = new UnitsDialog(_serviceProvider);
return unitsDialog.ShowForgeSchemaAsync();
case "search":
var searchDialog = new SearchElementsDialog(_serviceProvider);
return searchDialog.ShowAsync();
}

// var dialog = _dialogService.CreateDialog();
// switch (parameter)
// {
// case "parameters":
// var units = await Task.Run(() => RevitApi.GetUnitInfos(typeof(BuiltInParameter)));
// dialog.Title = "BuiltIn Parameters";
// dialog.Content = new UnitsDialog(_serviceProvider, units);
// dialog.DialogWidth = 800;
// dialog.DialogHeight = 600;
// await dialog.ShowAsync();
// break;
// case "categories":
// units = await Task.Run(() => RevitApi.GetUnitInfos(typeof(BuiltInCategory)));
// dialog.Title = "BuiltIn Categories";
// dialog.Content = new UnitsDialog(_serviceProvider, units);
// dialog.DialogWidth = 800;
// dialog.DialogHeight = 600;
// await dialog.ShowAsync();
// break;
// case "forge":
// units = await Task.Run(() => RevitApi.GetUnitInfos(typeof(ForgeTypeId)));
// dialog.Title = "Forge Schema";
// dialog.Content = new UnitsDialog(_serviceProvider, units);
// dialog.DialogWidth = 800;
// dialog.DialogHeight = 600;
// await dialog.ShowAsync();
// break;
// case "search":
// dialog = new SearchElementsDialog(_serviceProvider, _dialogService.GetContentPresenter());
// dialog.DialogWidth = 570;
// dialog.DialogHeight = 330;
// await dialog.ShowAsync();
// break;
// }
return Task.CompletedTask;
}

private bool Validate()
Expand Down
12 changes: 5 additions & 7 deletions RevitLookup/Views/Dialogs/OpenSourceDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@
xmlns:dialogs="clr-namespace:RevitLookup.ViewModels.Dialogs"
xmlns:rl="http://revitlookup.com/xaml"
mc:Ignorable="d"
MinWidth="300"
MinHeight="265"
d:DataContext="{d:DesignInstance dialogs:OpenSourceViewModel}">
<Grid.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<rl:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Grid.Resources>
<DataGrid
AutoGenerateColumns="False"
GridLinesVisibility="None"
Expand Down Expand Up @@ -53,6 +48,9 @@
</DataGridHyperlinkColumn.ElementStyle>
</DataGridHyperlinkColumn>
</DataGrid.Columns>
<DataGrid.Resources>
<rl:ControlsDictionary />
</DataGrid.Resources>
<DataGrid.CellStyle>
<Style
TargetType="DataGridCell"
Expand Down
23 changes: 22 additions & 1 deletion RevitLookup/Views/Dialogs/OpenSourceDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,38 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Documents;
using RevitLookup.Core.Objects;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.ViewModels.Dialogs;
using RevitLookup.Views.Pages;
using Wpf.Ui;
using Wpf.Ui.Controls;

namespace RevitLookup.Views.Dialogs;

public sealed partial class OpenSourceDialog
{
public OpenSourceDialog()
private readonly IContentDialogService _dialogService;

public OpenSourceDialog(IContentDialogService dialogService)
{
_dialogService = dialogService;
InitializeComponent();
DataContext = new OpenSourceViewModel();
}

public async Task ShowAsync()
{
var dialogOptions = new SimpleContentDialogCreateOptions
{
Title = "Third-Party Software",
Content = this,
CloseButtonText = "Close"
};

await _dialogService.ShowSimpleDialogAsync(dialogOptions);
}

private void OpenLink(object sender, RoutedEventArgs e)
{
Expand Down
22 changes: 4 additions & 18 deletions RevitLookup/Views/Dialogs/SearchElementsDialog.xaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
<rl:ContentDialog
<Grid
x:Class="RevitLookup.Views.Dialogs.SearchElementsDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:RevitLookup.Views.Dialogs"
xmlns:rl="http://revitlookup.com/xaml"
xmlns:dialogs="clr-namespace:RevitLookup.ViewModels.Dialogs"
mc:Ignorable="d"
Title="Search elements"
PrimaryButtonText="Search"
MinWidth="370"
MinHeight="130"
d:DataContext="{d:DesignInstance dialogs:SearchElementsViewModel}">
<rl:ContentDialog.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<rl:ThemesDictionary />
<rl:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
<Style
BasedOn="{StaticResource {x:Type rl:ContentDialog}}"
TargetType="{x:Type local:SearchElementsDialog}" />
</ResourceDictionary>
</rl:ContentDialog.Resources>
<rl:TextBox
Icon="{rl:SymbolIcon Search24}"
IconPlacement="Right"
PlaceholderText="Search by Name, Id, UniqueId or IfcGUID...&#xA;Separators: tab, semicolon, comma or space&#xA;&#xA;Example:&#xA;136976, 136977, 136978&#xA;Living Room, Exterior Wall, Swing door&#xA;17836a3c-e764-47fa-a2e0-08216444f621-0007882c"
TextWrapping="Wrap"
AcceptsReturn="True"
MinHeight="150"
MaxHeight="150"
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" />
</rl:ContentDialog>
</Grid>
43 changes: 29 additions & 14 deletions RevitLookup/Views/Dialogs/SearchElementsDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,51 @@
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.

using System.Windows.Controls;
using RevitLookup.Core.Objects;
using RevitLookup.Services;
using RevitLookup.Services.Contracts;
using RevitLookup.ViewModels.Dialogs;
using RevitLookup.Views.Pages;
using Wpf.Ui;
using Wpf.Ui.Controls;

namespace RevitLookup.Views.Dialogs;

public sealed partial class SearchElementsDialog
{
private readonly ISnackbarService _snackbarService;
private readonly ISnoopVisualService _snoopVisualService;
private readonly IServiceProvider _serviceProvider;
private readonly SearchElementsViewModel _viewModel;

public SearchElementsDialog(IServiceProvider serviceProvider, ContentPresenter contentPresenter) : base(contentPresenter)
public SearchElementsDialog(IServiceProvider serviceProvider)
{
_snoopVisualService = serviceProvider.GetService<ISnoopVisualService>();
_snackbarService = serviceProvider.GetService<ISnackbarService>();
InitializeComponent();
_serviceProvider = serviceProvider;
_viewModel = new SearchElementsViewModel();
DataContext = _viewModel;
InitializeComponent();
}

protected override void OnButtonClick(ContentDialogButton button)
public async Task ShowAsync()
{
//TODO
// if (button != ContentDialogButton.Primary) return;
// if (_viewModel.SearchIds(_snoopVisualService)) return;

// _snackbarService.Show("Search elements", "There are no elements found for your request", SymbolRegular.Warning24, ControlAppearance.Caution);
// return false;
var dialogOptions = new SimpleContentDialogCreateOptions
{
Title = "Search elements",
Content = this,
CloseButtonText = "Close",
PrimaryButtonText = "Search"
};

var dialogResult = await _serviceProvider.GetService<IContentDialogService>().ShowSimpleDialogAsync(dialogOptions);
if (dialogResult != ContentDialogResult.Primary) return;

var elements = _viewModel.SearchElements();
if (elements.Count == 0)
{
var notificationService = _serviceProvider.GetService<NotificationService>();
notificationService.ShowWarning("Search elements", "There are no elements found for your request");
return;
}

_serviceProvider.GetService<ISnoopVisualService>().Snoop(new SnoopableObject(elements));
_serviceProvider.GetService<INavigationService>().Navigate(typeof(SnoopView));
}
}
Loading

0 comments on commit 690e6db

Please sign in to comment.