Skip to content
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
76 changes: 65 additions & 11 deletions src/MSDIAL5/MsdialGuiApp/Model/Core/MainWindowModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public MainWindowModel(IMessageBroker broker) {
_settings.PreviousProjects = new List<ProjectCrumb>();
_settings.Save();
}
_previousProjects = _settings.PreviousProjects;
PreviousProjects = _previousProjects.AsReadOnly();
_previousProjects = new ObservableCollection<ProjectCrumb>(_settings.PreviousProjects);
PreviousProjects = new ReadOnlyObservableCollection<ProjectCrumb>(_previousProjects);

//InternalMsfinderSettingModel = new InternalMsfinderSettingModel(IonMode.Negative);
}
Expand All @@ -61,19 +61,25 @@ public ProjectSettingModel ProjectSetting {
}
private ProjectSettingModel projectSetting;

public ReadOnlyCollection<ProjectCrumb> PreviousProjects { get; }
private readonly List<ProjectCrumb> _previousProjects;
public ReadOnlyObservableCollection<ProjectCrumb> PreviousProjects { get; }
private readonly ObservableCollection<ProjectCrumb> _previousProjects;

private Task SetNewProject(IProjectModel project) {
CurrentProject = project;
ProjectSetting = new ProjectSettingModel(SetNewProject, _broker);
var currentCrumb = new ProjectCrumb(project.Storage.ProjectParameter);
if (_previousProjects.Any(currentCrumb.MaybeSame)) {
_previousProjects.RemoveAll(currentCrumb.MaybeSame);
var resembleProjects = _previousProjects.Where(currentCrumb.MaybeSame).ToList();
foreach (var resembleProject in resembleProjects)
{
_previousProjects.Remove(resembleProject);
}
}
_previousProjects.Insert(0, currentCrumb);
if (_previousProjects.Count > 50) {
_previousProjects.RemoveRange(50, _previousProjects.Count - 50);
while (_previousProjects.Count > 50) {
_previousProjects.RemoveAt(_previousProjects.Count - 1);
}
}
return Task.CompletedTask;
}
Expand All @@ -83,7 +89,21 @@ public async Task SaveAsync() {
return;
}
using (nowSaving.ProcessStart()) {
await CurrentProject.SaveAsync().ConfigureAwait(false);
await CurrentProject.SaveAsync().ConfigureAwait(true);
var currentCrumb = new ProjectCrumb(CurrentProject.Storage.ProjectParameter);
if (_previousProjects.Any(currentCrumb.MaybeSame))
{
_previousProjects.Remove(_previousProjects.First(currentCrumb.MaybeSame));
Comment on lines +94 to +96
}
_previousProjects.Insert(0, currentCrumb);
if (_previousProjects.Count > 50)
Comment on lines 91 to +99
{
while (_previousProjects.Count > 50)
{
_previousProjects.RemoveAt(_previousProjects.Count - 1);
}
}
_settings.PreviousProjects = PreviousProjects.ToList();
_settings.Save();
Comment on lines +92 to 107
}
}
Expand Down Expand Up @@ -123,11 +143,17 @@ public async Task LoadAsync() {
CurrentProject = loadedProject;
var currentCrumb = new ProjectCrumb(loadedProject.Storage.ProjectParameter);
if (_previousProjects.Any(currentCrumb.MaybeSame)) {
_previousProjects.RemoveAll(currentCrumb.MaybeSame);
var resembleProjects = _previousProjects.Where(currentCrumb.MaybeSame).ToList();
foreach (var resembleProject in resembleProjects)
{
_previousProjects.Remove(resembleProject);
}
}
_previousProjects.Insert(0, currentCrumb);
if (_previousProjects.Count > 50) {
_previousProjects.RemoveRange(50, _previousProjects.Count - 50);
while (_previousProjects.Count > 50) {
_previousProjects.RemoveAt(_previousProjects.Count - 1);
}
Comment on lines +146 to +156
}
}
catch {
Expand All @@ -153,11 +179,17 @@ public async Task LoadProjectAsync(ProjectCrumb projectCrumb) {
CurrentProject = loadedProject;
var currentCrumb = new ProjectCrumb(loadedProject.Storage.ProjectParameter);
if (_previousProjects.Any(currentCrumb.MaybeSame)) {
_previousProjects.RemoveAll(currentCrumb.MaybeSame);
var resembleProjects = _previousProjects.Where(currentCrumb.MaybeSame).ToList();
foreach (var resembleProject in resembleProjects)
{
_previousProjects.Remove(resembleProject);
}
}
_previousProjects.Insert(0, currentCrumb);
if (_previousProjects.Count > 50) {
_previousProjects.RemoveRange(50, _previousProjects.Count - 50);
while (_previousProjects.Count > 50) {
_previousProjects.RemoveAt(_previousProjects.Count - 1);
}
}
}
catch {
Expand All @@ -168,5 +200,27 @@ await Application.Current.Dispatcher.InvokeAsync(() => {
}
}
}

public async Task DeleteProjectAsync(ProjectCrumb projectCrumb){
using (nowLoading.ProcessStart()){
try
{
var resembleProjects = _previousProjects.Where(projectCrumb.MaybeSame).ToList();
Comment on lines +204 to +208
foreach (var resembleProject in resembleProjects)
{
_previousProjects.Remove(resembleProject);
}
_settings.PreviousProjects = PreviousProjects.ToList();
_settings.Save();
}
catch
{
await Application.Current.Dispatcher.InvokeAsync(() => {
MessageBox.Show("Failed to delete project.\nPlease check your project.");
return Task.CompletedTask;
});
}
}
Comment on lines +205 to +223
}
}
}
13 changes: 12 additions & 1 deletion src/MSDIAL5/MsdialGuiApp/View/Core/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
xmlns:properties="clr-namespace:CompMs.App.Msdial.Properties"
xmlns:util="clr-namespace:CompMs.App.Msdial.Utility"
xmlns:progressbar="clr-namespace:CompMs.Graphics.UI.ProgressBar;assembly=ChartDrawing"
xmlns:mvvm="clr-namespace:CompMs.CommonMVVM;assembly=CommonMVVM"
mc:Ignorable="d"
Icon="/Resources/msdial_icon.ico"
d:DataContext="{d:DesignInstance Type={x:Type vm:MainWindowVM}}"
Expand Down Expand Up @@ -138,6 +139,9 @@
<ItemsControl ItemsSource="{Binding PreviousProjects}"
BorderThickness="0.5"
BorderBrush="Black">
<ItemsControl.Resources>
<mvvm:BindingProxy x:Key="delete" Data="{Binding Path=DeletePreviousProjectCommand}"/>
</ItemsControl.Resources>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding Path=DataContext.OpenPreviousProjectCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
Expand All @@ -161,7 +165,14 @@
<TextBlock Text="{Binding FilePath}"/>
</ToolTip>
</Button.ToolTip>
</Button>
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove from recent projects"
Command="{Binding Data, Source={StaticResource delete}}"
CommandParameter="{Binding}"/>
</ContextMenu>
Comment on lines +168 to +173
</Button.ContextMenu>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
Expand Down
6 changes: 5 additions & 1 deletion src/MSDIAL5/MsdialGuiApp/ViewModel/Core/MainWindowVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public MainWindowVM(IWindowService<PeakSpotTableViewModelBase> peakSpotTableServ
OpenPreviousProjectCommand = new AsyncReactiveCommand<ProjectCrumb>()
.WithSubscribe(Model.LoadProjectAsync)
.AddTo(Disposables);
DeletePreviousProjectCommand = new AsyncReactiveCommand<ProjectCrumb>()
.WithSubscribe(Model.DeleteProjectAsync)
.AddTo(Disposables);

_taskProgressCollection = new TaskProgressCollection();
_taskProgressCollection.ShowWhileSwitchOn(Model.NowSaving, "Saving...").AddTo(Disposables);
Expand Down Expand Up @@ -177,7 +180,8 @@ private async Task ExecuteAlignmentMethodProcess() {

public AsyncReactiveCommand OpenProjectCommand { get; }
public AsyncReactiveCommand<ProjectCrumb> OpenPreviousProjectCommand { get; }
public ReadOnlyCollection<ProjectCrumb> PreviousProjects => Model.PreviousProjects;
public AsyncReactiveCommand<ProjectCrumb> DeletePreviousProjectCommand { get; }
public ReadOnlyObservableCollection<ProjectCrumb> PreviousProjects => Model.PreviousProjects;

public AsyncReactiveCommand SaveProjectCommand { get; }
public AsyncReactiveCommand SaveAsProjectCommand { get; }
Expand Down
Loading