Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Recent: Max, Clear, Scroll
Browse files Browse the repository at this point in the history
- Fixed Scrolling in Recent list
- Option to select maximum number of items persisted in Recent list (Default is 30)
- Option to Clear the Recent list.
  • Loading branch information
MathewSachin committed May 23, 2017
1 parent 836e041 commit 73dc619
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/Captura.Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public List<RecentItemModel> RecentItems
set => Set(value);
}

[UserScopedSetting]
[DefaultSettingValue("30")]
public int RecentMax
{
get => Get<int>();
set => Set(value);
}

#region Remember
[UserScopedSetting]
[DefaultSettingValue("Png")]
Expand Down
11 changes: 8 additions & 3 deletions src/Captura.Core/ViewModels/RecentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace Captura.ViewModels
{
public class RecentViewModel : ViewModelBase, IDisposable
{
public ObservableCollection<RecentItemViewModel> RecentList { get; } = new ObservableCollection<RecentItemViewModel>();

int maxItemsToPersist = 30;
public ICommand ClearCommand { get; }

public RecentViewModel()
{
Expand All @@ -21,6 +22,8 @@ public RecentViewModel()

foreach (var recent in Settings.Instance.RecentItems)
Add(recent.FilePath, recent.ItemType, false);

ClearCommand = new DelegateCommand(() => RecentList.Clear());
}

public RecentItemViewModel Add(string FilePath, RecentItemType ItemType, bool IsSaving)
Expand All @@ -39,7 +42,9 @@ public void Dispose()
{
Settings.Instance.RecentItems.Clear();

for (int i = 0; i < RecentList.Count && i < maxItemsToPersist; ++i)
var max = Settings.Instance.RecentMax;

for (int i = 0; i < RecentList.Count && i < max; ++i)
Settings.Instance.RecentItems.Add(new RecentItemModel(RecentList[i].FilePath, RecentList[i].ItemType));
}
}
Expand Down
41 changes: 24 additions & 17 deletions src/Captura/Views/RecentView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@
xmlns:local="clr-namespace:Captura"
DataContext="{StaticResource MainViewModel}">
<Grid>
<ScrollViewer>
<DockPanel Margin="10">
<TextBlock TextWrapping="Wrap"
DockPanel.Dock="Top"
Text="A List of files created in this session"
Margin="0,0,0,10"/>
<ScrollViewer>
<ItemsControl Margin="0,10,0,0"
ItemsSource="{Binding RecentViewModel.RecentList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:RecentItem DataContext="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<DockPanel Margin="10">
<DockPanel DockPanel.Dock="Top"
Margin="0,0,0,10">
<Button Content="Clear"
ToolTip="Clear Recent List"
DockPanel.Dock="Right"
Command="{Binding RecentViewModel.ClearCommand}"/>
<Label Content="Max Items to persist"
ContentStringFormat="{}{0}:"
VerticalContentAlignment="Center"/>
<local:NumericBox Margin="5,0,10,0"
Minimum="0"
Value="{Binding Settings.RecentMax, Mode=TwoWay}"/>
</DockPanel>
</ScrollViewer>
<ScrollViewer>
<ItemsControl Margin="0,10,0,0"
ItemsSource="{Binding RecentViewModel.RecentList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:RecentItem DataContext="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
</Grid>
</Page>

0 comments on commit 73dc619

Please sign in to comment.