Skip to content

Commit

Permalink
Scroll Navigation and others:
Browse files Browse the repository at this point in the history
Hide Unavailable
Advance on Delete
More prominent deleted indicator
  • Loading branch information
RupertAvery committed Aug 18, 2024
1 parent 0a38f97 commit f65b7d4
Show file tree
Hide file tree
Showing 31 changed files with 574 additions and 65 deletions.
5 changes: 5 additions & 0 deletions Diffusion.Database/DataStore.Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ private string GetInitialWhereClause(bool forceDeleted = false)
whereClauses.Add("ForDeletion = 0");
}

if (QueryBuilder.HideUnavailable)
{
whereClauses.Add("(Unavailable = 0)");
}

var whereExpression = string.Join(" AND ", whereClauses);

return whereClauses.Any() ? $" WHERE {whereExpression}" : "";
Expand Down
1 change: 1 addition & 0 deletions Diffusion.Database/DataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ await Task.Run(() =>

db.CreateIndex("Image", new[] { "ForDeletion", "CreatedDate" });
db.CreateIndex("Image", new[] { "NSFW", "CreatedDate" });
db.CreateIndex("Image", new[] { "Unavailable", "CreatedDate" });

db.CreateTable<Album>();
db.CreateIndex<Album>(album => album.Name, true);
Expand Down
6 changes: 6 additions & 0 deletions Diffusion.Database/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@ private string RupertAvery20231224_0002_AlbumImageForeignKeys()
DROP TABLE ""AlbumImage"";
ALTER TABLE ""AlbumImageTemp"" RENAME TO ""AlbumImage"";";
}

[Migrate(MigrationType.Post)]
private string RupertAvery20240818_0001_SetUnavailable()
{
return "UPDATE Image SET Unavailable = 0";
}
}
6 changes: 6 additions & 0 deletions Diffusion.Database/QueryBuilder.Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public static (string WhereClause, IEnumerable<object> Bindings, IEnumerable<str
filter.UseForDeletion = false;
}

if (HideUnavailable && !filter.UseUnavailable)
{
conditions.Add(new KeyValuePair<string, object>("(Unavailable = ?)", false));
filter.UseUnavailable = false;
}

FilterAlbum(filter, conditions, joins);
FilterFolder(filter, conditions, joins);
FilterPath(filter, conditions);
Expand Down
8 changes: 7 additions & 1 deletion Diffusion.Database/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static partial class QueryBuilder

public static bool HideNSFW { get; set; }
public static bool HideDeleted { get; set; }
public static bool HideUnavailable { get; set; }

public static (string WhereClause, IEnumerable<object> Bindings, IEnumerable<object> Joins) QueryPrompt(string prompt)
{
Expand All @@ -69,7 +70,12 @@ public static (string WhereClause, IEnumerable<object> Bindings, IEnumerable<obj

if (HideDeleted)
{
conditions.Add(new KeyValuePair<string, object>("(ForDeletion = ?)", false));
conditions.Add(new KeyValuePair<string, object>("(ForDeletion = ? OR ForDeletion IS NULL)", false));
}

if (HideUnavailable)
{
conditions.Add(new KeyValuePair<string, object>("(Unavailable = ? OR Unavailable IS NULL)", false));
}

return (string.Join(" AND ", conditions.Select(c => c.Key)),
Expand Down
10 changes: 10 additions & 0 deletions Diffusion.Toolkit/Controls/PreviewPane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:fa="http://schemas.fontawesome.io/icons/"
xmlns:classes="clr-namespace:Diffusion.Toolkit.Classes"
xmlns:converters="clr-namespace:Diffusion.Toolkit.Converters"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="800">
<UserControl.Resources>
Expand Down Expand Up @@ -46,6 +47,8 @@
</TextBlock>
</Grid>



<!--<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto" />
Expand Down Expand Up @@ -320,5 +323,12 @@

</Grid>

<Grid Background="{x:Null}" Visibility="{Binding Image.ForDeletion, Converter={StaticResource boolToVis}}" VerticalAlignment="Center" HorizontalAlignment="Center">
<Border BorderBrush="White" BorderThickness="1" Background="#81000000" CornerRadius="5">
<TextBlock Margin="15,5,15,5" TextAlignment="Center" FontSize="20" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Text="{lex:Loc Preview.Deleted}">
</TextBlock>
</Border>
</Grid>

</Grid>
</UserControl>
86 changes: 54 additions & 32 deletions Diffusion.Toolkit/Controls/PreviewPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Diffusion.Toolkit.Models;
using Diffusion.Toolkit.Services;
using Point = System.Windows.Point;

namespace Diffusion.Toolkit.Controls
Expand Down Expand Up @@ -200,56 +201,77 @@ public void ResetZoom()
this.UpdateLayout();
}

private void UIElement_OnMouseWheel(object sender, MouseWheelEventArgs e)
private void Zoom(MouseWheelEventArgs e)
{
MainModel.FitToPreview = false;
MainModel.HundredPercent = false;
Point mouseAtImage = e.GetPosition(Preview); // ScrollViewer_CanvasMain.TranslatePoint(middleOfScrollViewer, Canvas_Main);
Point mouseAtScrollViewer = e.GetPosition(ScrollViewer);

var ctrlPressed = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);
// Calculate the new zoom level based on the mouse wheel delta
double zoomDelta = e.Delta > 0 ? 0.1 : -0.1;

var active = true;
zoomDelta = Preview.LayoutTransform.Value.M11 * zoomDelta;

double newZoom = Math.Min(Math.Max(Preview.LayoutTransform.Value.M11 + zoomDelta, 0.1), 10);

if (active)
{
Point mouseAtImage = e.GetPosition(Preview); // ScrollViewer_CanvasMain.TranslatePoint(middleOfScrollViewer, Canvas_Main);
Point mouseAtScrollViewer = e.GetPosition(ScrollViewer);

// Calculate the new zoom level based on the mouse wheel delta
double zoomDelta = e.Delta > 0 ? 0.1 : -0.1;
Preview.LayoutTransform = new ScaleTransform(newZoom, newZoom);

ScrollViewer.ScrollToHorizontalOffset(0);
ScrollViewer.ScrollToVerticalOffset(0);
this.UpdateLayout();

Vector offset = Preview.TranslatePoint(mouseAtImage, ScrollViewer) - mouseAtScrollViewer; // (Vector)middleOfScrollViewer;
ScrollViewer.ScrollToHorizontalOffset(offset.X);
ScrollViewer.ScrollToVerticalOffset(offset.Y);
this.UpdateLayout();
}

zoomDelta = Preview.LayoutTransform.Value.M11 * zoomDelta;
private void UIElement_OnMouseWheel(object sender, MouseWheelEventArgs e)
{
MainModel.FitToPreview = false;
MainModel.HundredPercent = false;

double newZoom = Math.Min(Math.Max(Preview.LayoutTransform.Value.M11 + zoomDelta, 0.1), 10);
var ctrlPressed = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

var active = true;

Preview.LayoutTransform = new ScaleTransform(newZoom, newZoom);
var scrollNavigation = ServiceLocator.Settings.ScrollNavigation;

ScrollViewer.ScrollToHorizontalOffset(0);
ScrollViewer.ScrollToVerticalOffset(0);
this.UpdateLayout();

Vector offset = Preview.TranslatePoint(mouseAtImage, ScrollViewer) - mouseAtScrollViewer; // (Vector)middleOfScrollViewer;
ScrollViewer.ScrollToHorizontalOffset(offset.X);
ScrollViewer.ScrollToVerticalOffset(offset.Y);
this.UpdateLayout();

e.Handled = true;
if (ctrlPressed)
{
if (scrollNavigation)
{
Zoom(e);
e.Handled = true;
}
}
else
{
//Key vkey = e.Delta > 0 ? Key.Left : e.Delta < 0 ? Key.Right : Key.None;
if (scrollNavigation)
{
Key vkey = e.Delta > 0 ? Key.Left : e.Delta < 0 ? Key.Right : Key.None;

//var ps = PresentationSource.FromVisual((ScrollViewer)sender);
var ps = PresentationSource.FromVisual((ScrollViewer)sender);

//if (vkey == Key.None)
//{
// OnPreviewKeyUp(new KeyEventArgs(null, ps, 0, vkey));
//}
//else
//{
// OnPreviewKeyDown(new KeyEventArgs(null, ps, 0, vkey));
//}
switch (vkey)
{
case Key.Left:
ServiceLocator.ThumbnailNavigationService.MovePrevious();
break;
case Key.Right:
ServiceLocator.ThumbnailNavigationService.MoveNext();
break;
}

e.Handled = true;
}
else
{
Zoom(e);
e.Handled = true;
}
}
}

Expand Down
36 changes: 35 additions & 1 deletion Diffusion.Toolkit/Controls/Thumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ protected override void OnRender(DrawingContext drawingContext)

var margin = 5;

var borderRect = new Rect(margin, margin, Width- margin, Height - margin);
var borderRect = new Rect(margin, margin, Width - margin, Height - margin);

var pen = new Pen(Foreground, 1);

drawingContext.DrawRoundedRectangle(Brushes.Transparent, pen, borderRect, 3, 3);

if (Data.ForDeletion)
{
DrawDeleted(drawingContext, 25);
}

}

Expand Down Expand Up @@ -136,6 +140,36 @@ protected override void OnRender(DrawingContext drawingContext)
if (Data.ForDeletion)
{
drawingContext.Pop();

DrawDeleted(drawingContext, 0);
}
}

private void DrawDeleted(DrawingContext drawingContext, int yOffset)
{
var formattedText = new FormattedText(GetLocalizedText("Thumbnail.Deleted"),
CultureInfo.DefaultThreadCurrentCulture ?? CultureInfo.InvariantCulture,
FlowDirection.LeftToRight,
new Typeface(new FontFamily("Calibri"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
12,
Foreground,
1
);

double centerX = (ActualWidth - formattedText.Width) / 2;
double centerY = (ActualHeight - formattedText.Height) / 2;

var margin = 5;

var pillWidth = formattedText.Width + margin;
var pillHeight = formattedText.Height + margin;

var borderRect = new Rect(centerX - margin, centerY - margin + yOffset, pillWidth + margin, pillHeight + margin);

var pen = new Pen(Foreground, 1);

drawingContext.DrawRoundedRectangle(Brushes.Black, pen, borderRect, 3, 3);

drawingContext.DrawText(formattedText, new Point(centerX, centerY + yOffset));
}
}
24 changes: 12 additions & 12 deletions Diffusion.Toolkit/Controls/ThumbnailIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ protected override void OnRender(DrawingContext drawingContext)
var y = 0;
const int xOffset = 22;

if (Data.ForDeletion)
{
if (ThemeManager.CurrentTheme == "Dark")
{
drawingContext.DrawImage(_darkTrashIcon, new Rect(new Point(x, y), new Size(24, 24)));
}
else if (ThemeManager.CurrentTheme == "Light")
{
drawingContext.DrawImage(_lightTrashIcon, new Rect(new Point(x, y), new Size(24, 24)));
}
x += xOffset;
}
//if (Data.ForDeletion)
//{
// if (ThemeManager.CurrentTheme == "Dark")
// {
// drawingContext.DrawImage(_darkTrashIcon, new Rect(new Point(x, y), new Size(24, 24)));
// }
// else if (ThemeManager.CurrentTheme == "Light")
// {
// drawingContext.DrawImage(_lightTrashIcon, new Rect(new Point(x, y), new Size(24, 24)));
// }
// x += xOffset;
//}

if (Data.NSFW)
{
Expand Down
22 changes: 22 additions & 0 deletions Diffusion.Toolkit/Controls/ThumbnailView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Diffusion.Toolkit.Models;
using Microsoft.Extensions.Options;
using Image = Diffusion.Database.Image;
using Diffusion.Toolkit.Services;

namespace Diffusion.Toolkit.Controls
{
Expand Down Expand Up @@ -290,6 +291,18 @@ public void FocusCurrentItem()
}
}

public void FocusItem(int index)
{
if (index >= 0)
{
var wrapPanel = GetChildOfType<WrapPanel>(this)!;
var item = wrapPanel.Children[index] as ListViewItem;
ThumbnailListView.ScrollIntoView(item);
item.BringIntoView();
item.Focus();
}
}

/// <summary>
/// Handle wrapping around if an arrow key is pressed at the edge of the <see cref="ListView"/>.
/// </summary>
Expand Down Expand Up @@ -555,6 +568,15 @@ private void DeleteSelected()

var ids = imageEntries.Select(x => x.Id).ToList();
DataStore.SetDeleted(ids, delete);

if (imageEntries.Count == 1)
{
if (ServiceLocator.Settings.AdvanceOnDelete)
{
ServiceLocator.ThumbnailNavigationService.MoveNext();
FocusItem(ThumbnailListView.SelectedIndex);
}
}
}
}

Expand Down
Loading

0 comments on commit f65b7d4

Please sign in to comment.