Skip to content

Commit

Permalink
Fix for cleared filter showing all images when in Album mode.
Browse files Browse the repository at this point in the history
Fixes issue #132
  • Loading branch information
RupertAvery committed Jul 28, 2023
1 parent 3e9c6b4 commit 67f19b7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Diffusion.Database/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Filter
{

public bool UsePrompt { get; set; }
public string Prompt { get; set; }
public bool UseNegativePrompt { get; set; }
Expand Down Expand Up @@ -82,8 +83,12 @@ public class Filter
UseCreationDate ||
UseHyperNet ||
UseHyperNetStr ||
UseNoMetadata);
UseNoMetadata ||
UseAlbum ||
UseFolder);

public bool UseFolder => !string.IsNullOrEmpty(Folder);
public string? Folder { get; set; }
public bool UseAlbum => !string.IsNullOrEmpty(Album);
public string? Album { get; set; }
}
16 changes: 8 additions & 8 deletions Diffusion.Toolkit/Models/SearchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public class SearchModel : BaseNotify
private ICommand _showFilter;
private bool _isFilterVisible;
private SearchControlModel _filter;
private ICommand _doFilter;
private ICommand _clearFilter;
private ICommand _filterCommand;
private ICommand _clearCommand;
private string _sortBy;
private string _sortDirection;
private ICommand _openCommand;
Expand Down Expand Up @@ -273,16 +273,16 @@ public SearchControlModel Filter
set => SetField(ref _filter, value);
}

public ICommand DoFilter
public ICommand FilterCommand
{
get => _doFilter;
set => SetField(ref _doFilter, value);
get => _filterCommand;
set => SetField(ref _filterCommand, value);
}

public ICommand ClearFilter
public ICommand ClearCommand
{
get => _clearFilter;
set => SetField(ref _clearFilter, value);
get => _clearCommand;
set => SetField(ref _clearCommand, value);
}

public string SortBy
Expand Down
6 changes: 3 additions & 3 deletions Diffusion.Toolkit/Pages/Search.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@
<Grid Visibility="{Binding IsFilterVisible, Converter={StaticResource boolToVis}}" Grid.Row="2" >
<ScrollViewer VerticalScrollBarVisibility="Auto">
<StackPanel>
<controls:Search Filter="{Binding Filter}" SearchCommand="{Binding DoFilter}" VerticalAlignment="Stretch"/>
<controls:Search Filter="{Binding Filter}" SearchCommand="{Binding FilterCommand}" VerticalAlignment="Stretch"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="1" Height="30" Command="{Binding DoFilter}">Filter</Button>
<Button Grid.Column="0" Height="30" Command="{Binding ClearFilter}">Clear</Button>
<Button Grid.Column="0" Height="30" Command="{Binding ClearCommand}">Clear</Button>
<Button Grid.Column="1" Height="30" Command="{Binding FilterCommand}">Filter</Button>
</Grid>
</StackPanel>
</ScrollViewer>
Expand Down
14 changes: 12 additions & 2 deletions Diffusion.Toolkit/Pages/Search.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

namespace Diffusion.Toolkit.Pages
{
public class AlbumListBox : DragAndDropListBox<Album> { }

public class ModeSettings
{
public ModeSettings()
Expand Down Expand Up @@ -195,14 +197,16 @@ public Search(NavigatorService navigatorService, IOptions<DataStore> dataStoreOp
_model.HideDropDown = new RelayCommand<object>((o) => SearchTermTextBox.IsDropDownOpen = false);

_model.ShowFilter = new RelayCommand<object>((o) => _model.IsFilterVisible = !_model.IsFilterVisible);
_model.DoFilter = new RelayCommand<object>((o) =>

_model.FilterCommand = new RelayCommand<object>((o) =>
{
_model.IsFilterVisible = false;
_model.SearchText = "(filtered)";
UseFilter = true;
SearchImages(null);
});
_model.ClearFilter = new RelayCommand<object>((o) =>

_model.ClearCommand = new RelayCommand<object>((o) =>
{
_model.Filter.Clear();

Expand Down Expand Up @@ -324,6 +328,7 @@ public Search(NavigatorService navigatorService, IOptions<DataStore> dataStoreOp
DataContext = _model;

ThumbnailListView.DataStoreOptions = _dataStoreOptions;

ThumbnailListView.MessagePopupManager = messagePopupManager;

PreviewPane.MainModel = mainModel;
Expand All @@ -333,21 +338,25 @@ public Search(NavigatorService navigatorService, IOptions<DataStore> dataStoreOp
DataStore.SetNSFW(id, b);
Update(id);
};

PreviewPane.Favorite = (id, b) =>
{
DataStore.SetFavorite(id, b);
Update(id);
};

PreviewPane.Rate = (id, b) =>
{
DataStore.SetRating(id, b);
Update(id);
};

PreviewPane.Delete = (id, b) =>
{
DataStore.SetDeleted(id, b);
Update(id);
};

//PreviewPane.OnNext = Next;
//PreviewPane.OnPrev = Prev;
GetRandomHint();
Expand Down Expand Up @@ -1755,5 +1764,6 @@ private void PreviewPane_OnPreviewKeyDown(object sender, KeyEventArgs e)
{
ExtOnKeyDown(this, e);
}

}
}

0 comments on commit 67f19b7

Please sign in to comment.