New feature #406 : Right Click Menu for Stop-Light Icon (Chardonnay UI)
This commit is contained in:
parent
d1528a095b
commit
5ca0d2a399
@ -1,4 +1,5 @@
|
|||||||
using Avalonia.Media;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Media;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -16,5 +17,23 @@ namespace LibationAvalonia
|
|||||||
return brush;
|
return brush;
|
||||||
return defaultBrush;
|
return defaultBrush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Window GetParentWindow(this IControl control)
|
||||||
|
{
|
||||||
|
Window window = null;
|
||||||
|
|
||||||
|
var p = control.Parent;
|
||||||
|
while (p != null)
|
||||||
|
{
|
||||||
|
if (p is Window)
|
||||||
|
{
|
||||||
|
window = (Window)p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
p = p.Parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ namespace LibationAvalonia.ViewModels
|
|||||||
[Browsable(false)] public string LongDescription { get; protected set; }
|
[Browsable(false)] public string LongDescription { get; protected set; }
|
||||||
[Browsable(false)] public abstract DateTime DateAdded { get; }
|
[Browsable(false)] public abstract DateTime DateAdded { get; }
|
||||||
[Browsable(false)] public int ListIndex { get; set; }
|
[Browsable(false)] public int ListIndex { get; set; }
|
||||||
[Browsable(false)] protected Book Book => LibraryBook.Book;
|
[Browsable(false)] public Book Book => LibraryBook.Book;
|
||||||
|
|
||||||
#region Model properties exposed to the view
|
#region Model properties exposed to the view
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,7 @@ namespace LibationAvalonia.ViewModels
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Call when there's been a change to the library
|
/// Call when there's been a change to the library
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task DisplayBooks(List<LibraryBook> dbBooks)
|
public async Task DisplayBooksAsync(List<LibraryBook> dbBooks)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@ -54,7 +54,7 @@ namespace LibationAvalonia.Views
|
|||||||
{
|
{
|
||||||
this.LibraryLoaded += MainWindow_LibraryLoaded;
|
this.LibraryLoaded += MainWindow_LibraryLoaded;
|
||||||
|
|
||||||
LibraryCommands.LibrarySizeChanged += async (_, _) => await _viewModel.ProductsDisplay.DisplayBooks(DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
LibraryCommands.LibrarySizeChanged += async (_, _) => await _viewModel.ProductsDisplay.DisplayBooksAsync(DbContexts.GetLibrary_Flat_NoTracking(includeParents: true));
|
||||||
Closing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance);
|
Closing += (_, _) => this.SaveSizeAndLocation(Configuration.Instance);
|
||||||
}
|
}
|
||||||
Opened += MainWindow_Opened;
|
Opened += MainWindow_Opened;
|
||||||
@ -178,7 +178,7 @@ namespace LibationAvalonia.Views
|
|||||||
if (QuickFilters.UseDefault)
|
if (QuickFilters.UseDefault)
|
||||||
await performFilter(QuickFilters.Filters.FirstOrDefault());
|
await performFilter(QuickFilters.Filters.FirstOrDefault());
|
||||||
|
|
||||||
await _viewModel.ProductsDisplay.DisplayBooks(dbBooks);
|
await _viewModel.ProductsDisplay.DisplayBooksAsync(dbBooks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
|
|||||||
@ -1,16 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Collections;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
using DataLayer;
|
using DataLayer;
|
||||||
using FileLiberator;
|
using FileLiberator;
|
||||||
using LibationFileManager;
|
|
||||||
using LibationAvalonia.ViewModels;
|
|
||||||
using LibationAvalonia.Dialogs;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using LibationAvalonia.Controls;
|
using LibationAvalonia.Controls;
|
||||||
|
using LibationAvalonia.Dialogs;
|
||||||
|
using LibationAvalonia.ViewModels;
|
||||||
|
using LibationFileManager;
|
||||||
|
|
||||||
namespace LibationAvalonia.Views
|
namespace LibationAvalonia.Views
|
||||||
{
|
{
|
||||||
@ -41,7 +42,7 @@ namespace LibationAvalonia.Views
|
|||||||
};
|
};
|
||||||
|
|
||||||
var pdvm = new ProductsDisplayViewModel();
|
var pdvm = new ProductsDisplayViewModel();
|
||||||
pdvm.DisplayBooks(sampleEntries);
|
pdvm.DisplayBooksAsync(sampleEntries);
|
||||||
DataContext = pdvm;
|
DataContext = pdvm;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -75,9 +76,62 @@ namespace LibationAvalonia.Views
|
|||||||
|
|
||||||
public void ProductsGrid_CellContextMenuStripNeeded(object sender, DataGridCellContextMenuStripNeededEventArgs args)
|
public void ProductsGrid_CellContextMenuStripNeeded(object sender, DataGridCellContextMenuStripNeededEventArgs args)
|
||||||
{
|
{
|
||||||
|
// stop light
|
||||||
if (args.Column.SortMemberPath == "Liberate")
|
if (args.Column.SortMemberPath == "Liberate")
|
||||||
{
|
{
|
||||||
|
var entry = args.GridEntry;
|
||||||
|
|
||||||
|
if (entry.IsSeries)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var setDownloadMenuItem = new MenuItem()
|
||||||
|
{
|
||||||
|
Header = "_Set Download status to 'Downloaded'",
|
||||||
|
IsEnabled = entry.Book.UserDefinedItem.BookStatus != LiberatedStatus.Liberated
|
||||||
|
};
|
||||||
|
setDownloadMenuItem.Click += (_, __) => entry.Book.UpdateBookStatus(LiberatedStatus.Liberated);
|
||||||
|
|
||||||
|
var setNotDownloadMenuItem = new MenuItem()
|
||||||
|
{
|
||||||
|
Header = "_Set Download status to 'Not Downloaded'",
|
||||||
|
IsEnabled = entry.Book.UserDefinedItem.BookStatus != LiberatedStatus.NotLiberated
|
||||||
|
};
|
||||||
|
setNotDownloadMenuItem.Click += (_, __) => entry.Book.UpdateBookStatus(LiberatedStatus.NotLiberated);
|
||||||
|
|
||||||
|
var removeMenuItem = new MenuItem() { Header = "_Remove from library" };
|
||||||
|
removeMenuItem.Click += (_, __) => LibraryCommands.RemoveBook(entry.AudibleProductId);
|
||||||
|
|
||||||
|
var locateFileMenuItem = new MenuItem() { Header = "_Locate file..." };
|
||||||
|
locateFileMenuItem.Click += async (_, __) =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var openFileDialog = new OpenFileDialog()
|
||||||
|
{
|
||||||
|
Title = $"Locate the audio file for '{entry.Book.Title}'",
|
||||||
|
Filters = new() { new() { Name = "All files (*.*)", Extensions = new() { "|*.*" } } },
|
||||||
|
AllowMultiple= false
|
||||||
|
};
|
||||||
|
var filePaths = await openFileDialog.ShowAsync(this.GetParentWindow());
|
||||||
|
var filePath = filePaths.SingleOrDefault();
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(filePath))
|
||||||
|
FilePathCache.Insert(entry.AudibleProductId, filePath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var msg = "Error saving book's location";
|
||||||
|
await MessageBox.ShowAdminAlert(null, msg, msg, ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
args.ContextMenuItems.AddRange(new[]
|
||||||
|
{
|
||||||
|
setDownloadMenuItem,
|
||||||
|
setNotDownloadMenuItem,
|
||||||
|
removeMenuItem,
|
||||||
|
locateFileMenuItem
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -136,40 +136,31 @@ namespace LibationWinForms.GridView
|
|||||||
if (entry.IsSeries)
|
if (entry.IsSeries)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stopLightContextMenu = new ContextMenuStrip();
|
var setDownloadMenuItem = new ToolStripMenuItem()
|
||||||
e.ContextMenuStrip = stopLightContextMenu;
|
|
||||||
{
|
|
||||||
var menuItem = new ToolStripMenuItem()
|
|
||||||
{
|
{
|
||||||
Text = "Set Download status to 'Downloaded'",
|
Text = "Set Download status to 'Downloaded'",
|
||||||
Enabled = entry.Book.UserDefinedItem.BookStatus != LiberatedStatus.Liberated
|
Enabled = entry.Book.UserDefinedItem.BookStatus != LiberatedStatus.Liberated
|
||||||
};
|
};
|
||||||
menuItem.Click += (_, __) => entry.Book.UpdateBookStatus(LiberatedStatus.Liberated);
|
setDownloadMenuItem.Click += (_, __) => entry.Book.UpdateBookStatus(LiberatedStatus.Liberated);
|
||||||
stopLightContextMenu.Items.Add(menuItem);
|
|
||||||
}
|
var setNotDownloadMenuItem = new ToolStripMenuItem()
|
||||||
{
|
|
||||||
var menuItem = new ToolStripMenuItem()
|
|
||||||
{
|
{
|
||||||
Text = "Set Download status to 'Not Downloaded'",
|
Text = "Set Download status to 'Not Downloaded'",
|
||||||
Enabled = entry.Book.UserDefinedItem.BookStatus != LiberatedStatus.NotLiberated
|
Enabled = entry.Book.UserDefinedItem.BookStatus != LiberatedStatus.NotLiberated
|
||||||
};
|
};
|
||||||
menuItem.Click += (_, __) => entry.Book.UpdateBookStatus(LiberatedStatus.NotLiberated);
|
setNotDownloadMenuItem.Click += (_, __) => entry.Book.UpdateBookStatus(LiberatedStatus.NotLiberated);
|
||||||
stopLightContextMenu.Items.Add(menuItem);
|
|
||||||
}
|
var removeMenuItem = new ToolStripMenuItem() { Text = "Remove from library" };
|
||||||
{
|
removeMenuItem.Click += (_, __) => LibraryCommands.RemoveBook(entry.AudibleProductId);
|
||||||
var menuItem = new ToolStripMenuItem() { Text = "Remove from library" };
|
|
||||||
menuItem.Click += (_, __) => LibraryCommands.RemoveBook(entry.AudibleProductId);
|
var locateFileMenuItem = new ToolStripMenuItem() { Text = "Locate file..." };
|
||||||
stopLightContextMenu.Items.Add(menuItem);
|
locateFileMenuItem.Click += (_, __) =>
|
||||||
}
|
|
||||||
{
|
|
||||||
var menuItem = new ToolStripMenuItem() { Text = "Locate file..." };
|
|
||||||
menuItem.Click += (_, __) =>
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var openFileDialog = new OpenFileDialog
|
var openFileDialog = new OpenFileDialog
|
||||||
{
|
{
|
||||||
Title = $"Locate the audiofile for '{entry.Book.Title}'",
|
Title = $"Locate the audio file for '{entry.Book.Title}'",
|
||||||
Filter = "All files (*.*)|*.*",
|
Filter = "All files (*.*)|*.*",
|
||||||
FilterIndex = 1
|
FilterIndex = 1
|
||||||
};
|
};
|
||||||
@ -182,8 +173,14 @@ namespace LibationWinForms.GridView
|
|||||||
MessageBoxLib.ShowAdminAlert(this, msg, msg, ex);
|
MessageBoxLib.ShowAdminAlert(this, msg, msg, ex);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
stopLightContextMenu.Items.Add(menuItem);
|
|
||||||
}
|
var stopLightContextMenu = new ContextMenuStrip();
|
||||||
|
stopLightContextMenu.Items.Add(setDownloadMenuItem);
|
||||||
|
stopLightContextMenu.Items.Add(setNotDownloadMenuItem);
|
||||||
|
stopLightContextMenu.Items.Add(removeMenuItem);
|
||||||
|
stopLightContextMenu.Items.Add(locateFileMenuItem);
|
||||||
|
|
||||||
|
e.ContextMenuStrip = stopLightContextMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GridEntry getGridEntry(int rowIndex) => gridEntryDataGridView.GetBoundItem<GridEntry>(rowIndex);
|
private GridEntry getGridEntry(int rowIndex) => gridEntryDataGridView.GetBoundItem<GridEntry>(rowIndex);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user