Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a MRU list #35

Merged
merged 5 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/StringMaster.Civil/StringCivilPointService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ public void StringCivilPoints(IList<DescriptionKey> descriptionKeys)
}
}

if (pointCollection.Count <= 1)
continue;

// Draw the polylines.
if (deskeyMatch.DescriptionKey.Draw2D && !hasCurve)
PolylineHelpers.DrawPolyline2d(tr, btr, pointCollection, layerName, deskeyMatch.DescriptionKey.AcadColor.ToColor(), isClosed);
Expand Down
28 changes: 26 additions & 2 deletions src/StringMaster.UI/Palettes/StringCogoPointsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
xmlns:converters="clr-namespace:StringMaster.UI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:helpers="clr-namespace:StringMaster.UI.Helpers"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:StringMaster.UI.Models"
xmlns:viewmodels="clr-namespace:StringMaster.UI.ViewModels"
Expand All @@ -21,7 +22,6 @@
<ResourceDictionary Source="pack://application:,,,/StringMaster.UI;component/Resources/ToolTips.xaml" />
<ResourceDictionary Source="pack://application:,,,/StringMaster.UI;component/Resources/ToolBar.xaml" />
<ResourceDictionary Source="pack://application:,,,/StringMaster.UI;component/Resources/Icons.xaml" />
<ResourceDictionary Source="pack://application:,,,/StringMaster.UI;component/Resources/ComboBox.xaml" />
</ResourceDictionary.MergedDictionaries>
<converters:BooleanYesNoConverter x:Key="BooleanYesNoConverter" />
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />
Expand All @@ -31,7 +31,6 @@
</Style>
<Cursor x:Key="PlusCursor">pack://application:,,,/StringMaster.UI;component/Resources/Cursors/pluscursor.cur</Cursor>
<Cursor x:Key="CheckCursor">pack://application:,,,/StringMaster.UI;component/Resources/Cursors/checkmark.cur</Cursor>

<models:ColumnContext x:Key="proxy" Data="{Binding}" />
</ResourceDictionary>
</UserControl.Resources>
Expand Down Expand Up @@ -73,6 +72,30 @@
</Button.ToolTip>
<Image Source="{StaticResource ExecuteToolBarIcon}" />
</Button>
<ComboBox ItemsSource="{Binding MRUList}" SelectedItem="{Binding CurrentFileName}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding MRUListSelectionChanged}" CommandParameter="{Binding ElementName=myListBox, Path=SelectedItem}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Button Command="{Binding UnloadDescriptionKeyCommand}" IsEnabled="{Binding IsDescriptionKeyLoaded}">
<!--<Image Source="{StaticResource RemoveToolBarIcon}" />-->
<Image Width="16" Height="16">
<Image.Style>
<Style TargetType="Image">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" Value="True">
<Setter Property="Source" Value="{StaticResource RemoveToolBarIcon}" />
</DataTrigger>
<DataTrigger Binding="{Binding Path=IsEnabled, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Button}}" Value="False">
<Setter Property="Source" Value="{StaticResource RemoveDisabledToolBarIcon}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
</Button>
</ToolBar>
<ToolBar
HorizontalAlignment="Right"
Expand Down Expand Up @@ -109,6 +132,7 @@
ColumnHeaderStyle="{StaticResource DataGridHeader}"
CurrentItem="{Binding SelectedKey, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Cursor="{StaticResource PlusCursor}"
DockPanel.Dock="Left"
HorizontalGridLinesBrush="{StaticResource BlueGridLine}"
ItemsSource="{Binding DescriptionKeys, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
RowHeaderWidth="0"
Expand Down
1 change: 1 addition & 0 deletions src/StringMaster.UI/Palettes/StringCogoPointsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using StringMaster.UI.Services.Interfaces;
Expand Down
13 changes: 12 additions & 1 deletion src/StringMaster.UI/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/StringMaster.UI/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="StringMaster.Properties" GeneratedClassName="Settings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="StringMaster.UI.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="DescriptionKeyFileName" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="MRUList" Type="System.Collections.Specialized.StringCollection" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
1 change: 1 addition & 0 deletions src/StringMaster.UI/Resources/Icons.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<BitmapImage x:Key="TickToolBarIcon" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/tick.png" />
<BitmapImage x:Key="AddToolBarIcon" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/add.png" />
<BitmapImage x:Key="RemoveToolBarIcon" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/remove.bmp" />
<BitmapImage x:Key="RemoveDisabledToolBarIcon" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/remove - disabled.bmp" />
<BitmapImage x:Key="ExecuteToolBarIcon" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/execute.png" />
<BitmapImage x:Key="LayerOnImage" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/on.png" />
<BitmapImage x:Key="LayerOffImage" UriSource="pack://application:,,,/StringMaster.UI;component/Resources/Icons/off.png" />
Expand Down
Binary file not shown.
9 changes: 8 additions & 1 deletion src/StringMaster.UI/StringMaster.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.39\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework.Aero2" />
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -133,6 +136,8 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ResourceStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -247,6 +252,8 @@
<ItemGroup>
<Resource Include="Resources\Icons\unlocked.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="Resources\Icons\remove - disabled.bmp" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
75 changes: 75 additions & 0 deletions src/StringMaster.UI/ViewModels/StringCogoPointsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class StringCogoPointsViewModel : ObservableObject
private ObservableCollection<DescriptionKey> _unchangedDescriptionKeys;
private string _currentFileName;
private DescriptionKey _selectedKey;
private ObservableCollection<string> _mruList;


public IAcadColorDialogService ACADColorDialogService { get; }

Expand Down Expand Up @@ -55,6 +57,23 @@ public DescriptionKey SelectedKey
set => SetProperty(ref _selectedKey, value);
}

public ObservableCollection<string> MRUList
{
get => _mruList;
set => SetProperty(ref _mruList, value);
}

public bool IsDescriptionKeyLoaded
{
get
{
if (MRUList == null || MRUList.Count == 0)
return false;
else
return true;
}
}

public ICommand NewDescriptionKeyFileCommand { get; }
public ICommand OpenDescriptionKeyFileCommand { get; }
public ICommand SaveDescriptionKeyFileCommand { get; }
Expand All @@ -65,6 +84,8 @@ public DescriptionKey SelectedKey
public ICommand CopyRowCommand { get; }
public ICommand StringCommand { get; }
public ICommand LayerSelectCommand { get; }
public ICommand MRUListSelectionChanged { get; }
public ICommand UnloadDescriptionKeyCommand { get; }

public StringCogoPointsViewModel(IOpenDialogService openDialogService,
ISaveDialogService saveDialogService,
Expand Down Expand Up @@ -110,7 +131,10 @@ public DescriptionKey SelectedKey
DescriptionKeys.Count > 0 &&
DescriptionKeys.All(x => x.IsValid));
LayerSelectCommand = new RelayCommand(ShowLayerSelectionDialog);
MRUListSelectionChanged = new RelayCommand(SelectionChanged);
UnloadDescriptionKeyCommand = new RelayCommand(UnloadDescriptionKeyFile);

LoadMRUList();
LoadSettingsFromFile(Properties.Settings.Default.DescriptionKeyFileName);
}

Expand Down Expand Up @@ -260,7 +284,10 @@ private void UnhookPropertyChangeEvents()
private void LoadSettingsFromFile(string fileName)
{
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
{
DescriptionKeys = new ObservableCollection<DescriptionKey>();
return;
}

DescriptionKeys.CollectionChanged -= DescriptionKeysOnCollectionChanged;
UnhookPropertyChangeEvents();
Expand Down Expand Up @@ -294,6 +321,8 @@ private void LoadSettingsFromFile(string fileName)
IsUnsavedChanges = false;
Properties.Settings.Default.DescriptionKeyFileName = fileName;
Properties.Settings.Default.Save();
AddToMRUList(fileName);
SaveMRUList();
}

/// <summary>
Expand Down Expand Up @@ -410,4 +439,50 @@ private void OpenDescriptionKeyFile()
CurrentFileName = _openDialogService.FileName;
LoadSettingsFromFile(CurrentFileName);
}


private void UnloadDescriptionKeyFile()
{
MRUList.Remove(CurrentFileName);

if (MRUList.Count > 0)
CurrentFileName = MRUList[MRUList.Count - 1];

SaveMRUList();

NotifyPropertyChanged(nameof(IsDescriptionKeyLoaded));
}


// MRU list
private void AddToMRUList(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return;

if (MRUList.Contains(fileName))
return;

MRUList.Add(fileName);
}

private void LoadMRUList()
{
MRUList = Properties.Settings.Default.MRUList != null
? new ObservableCollection<string>(Properties.Settings.Default.MRUList.Cast<string>().ToList())
: new ObservableCollection<string>();
}

private void SaveMRUList()
{
Properties.Settings.Default.MRUList = new StringCollection();
Properties.Settings.Default.MRUList.AddRange(MRUList.ToArray());
Properties.Settings.Default.Save();
}

private void SelectionChanged()
{
LoadSettingsFromFile(CurrentFileName);
NotifyPropertyChanged(nameof(IsDescriptionKeyLoaded));
}
}
15 changes: 15 additions & 0 deletions src/StringMaster.UI/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="StringMaster.UI.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<StringMaster.UI.Properties.Settings>
<setting name="DescriptionKeyFileName" serializeAs="String">
<value />
</setting>
</StringMaster.UI.Properties.Settings>
</userSettings>
</configuration>
4 changes: 4 additions & 0 deletions src/StringMaster.UI/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.39" targetFramework="net47" />
</packages>