Skip to content

Commit

Permalink
Auto-select first image on search / reload (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
RupertAvery committed Jan 18, 2024
1 parent 7a73407 commit c7b8a63
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Diffusion.Toolkit/Controls/ThumbnailView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public void ResetView(bool focus, bool gotoEnd = false)
{
var index = gotoEnd ? Model.Images.Count - 1 : 0;
ShowItem(index, focus && ThumbnailListView.IsFocused);
ShowItem(index, focus);
}
});
}
Expand Down
27 changes: 15 additions & 12 deletions Diffusion.Toolkit/MainWindow.xaml.Watchers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,24 @@ private void QueueFile(string path)
{
lock (_lock)
{
var attr = File.GetAttributes(path);
if (File.Exists(path))
{
var attr = File.GetAttributes(path);

if (attr.HasFlag(FileAttributes.Directory))
return;
if (attr.HasFlag(FileAttributes.Directory))
return;

if (t == null)
{
_detectedFiles = new List<string>();
t = new Timer(ProcessQueueCallback, null, 2000, Timeout.Infinite);
}
else
{
t.Change(2000, Timeout.Infinite);
if (t == null)
{
_detectedFiles = new List<string>();
t = new Timer(ProcessQueueCallback, null, 2000, Timeout.Infinite);
}
else
{
t.Change(2000, Timeout.Infinite);
}
_detectedFiles.Add(path);
}
_detectedFiles.Add(path);
}
}

Expand Down
24 changes: 23 additions & 1 deletion Diffusion.Toolkit/Pages/Search.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,29 @@ public void ReloadMatches(ReloadOptions? options)
{
LoadMatches();
ThumbnailListView.ResetView(options?.Focus ?? true, options?.GotoEnd ?? false);
Dispatcher.Invoke(() => { options?.OnCompleted?.Invoke(); });
Dispatcher.Invoke(() =>
{
options?.OnCompleted?.Invoke();
if (_model.Images is { Count: > 0 })
{
if (options?.GotoEnd ?? false)
{
_model.SelectedImageEntry = _model.Images[^1];
}
else
{
_model.SelectedImageEntry = _model.Images[0];
}
}
else
{
_model.SelectedImageEntry = null;
}
});
});
}

Expand Down

0 comments on commit c7b8a63

Please sign in to comment.