-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tag import from other collection #51
- Loading branch information
Showing
14 changed files
with
438 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using COMPASS.Commands; | ||
using COMPASS.Models; | ||
using COMPASS.Tools; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace COMPASS.ViewModels.Import | ||
{ | ||
public class ImportTagsViewModel : ViewModelBase | ||
{ | ||
public ImportTagsViewModel(List<CodexCollection> collections) | ||
{ | ||
TagTemplates = collections.Select(c => new TagTemplateHelper(c)).ToList(); | ||
SelectedTagTemplate = TagTemplates.FirstOrDefault(); | ||
} | ||
|
||
private List<TagTemplateHelper> _tagTemplates = new(); | ||
public List<TagTemplateHelper> TagTemplates | ||
{ | ||
get => _tagTemplates; | ||
set => SetProperty(ref _tagTemplates, value); | ||
} | ||
|
||
private TagTemplateHelper _selectedTagTemplate; | ||
public TagTemplateHelper SelectedTagTemplate | ||
{ | ||
get => _selectedTagTemplate; | ||
set => SetProperty(ref _selectedTagTemplate, value); | ||
} | ||
|
||
private ActionCommand _mergeTagsCommand; | ||
public ActionCommand MergeTagsCommand => _mergeTagsCommand ??= new(MergeTags); | ||
public void MergeTags() | ||
{ | ||
foreach (var template in TagTemplates) | ||
{ | ||
var tags = CheckableTreeNode<Tag>.GetCheckedItems(template.TagsRoot.Children); | ||
if (tags.Any()) | ||
{ | ||
MainViewModel.CollectionVM.CurrentCollection.ImportTags(tags); | ||
} | ||
} | ||
CloseAction.Invoke(); | ||
} | ||
|
||
public Action CloseAction = () => { }; | ||
|
||
public class TagTemplateHelper : ObservableObject | ||
{ | ||
public TagTemplateHelper(CodexCollection c) | ||
{ | ||
Name = c.DirectoryName; | ||
_collection = c; | ||
} | ||
|
||
private CodexCollection _collection; | ||
|
||
public string Name { get; set; } | ||
|
||
public CheckableTreeNode<Tag> _tagsRoot = null; | ||
public CheckableTreeNode<Tag> TagsRoot | ||
{ | ||
get | ||
{ | ||
//Lazy load, only load the first time | ||
if (_tagsRoot != null) return _tagsRoot; | ||
|
||
//load | ||
_collection.LoadTags(); | ||
//convert to treenodes | ||
_tagsRoot = new CheckableTreeNode<Tag>(); | ||
_tagsRoot.Children = new(_collection.RootTags | ||
.Select(t => new CheckableTreeNode<Tag>(t))); | ||
//init expanded and checked | ||
foreach (var node in Utils.FlattenTree(_tagsRoot.Children)) | ||
{ | ||
node.Expanded = node.Item.IsGroup; | ||
node.IsChecked = false; | ||
} | ||
_tagsRoot.Updated += _ => RaisePropertyChanged(nameof(ImportCount)); | ||
return _tagsRoot; | ||
} | ||
} | ||
|
||
public int ImportCount | ||
{ | ||
get | ||
{ | ||
if (TagsRoot == null) return 0; | ||
return Utils.FlattenTree(CheckableTreeNode<Tag>.GetCheckedItems(TagsRoot.Children)).Count(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<UserControl x:Class="COMPASS.Views.ImportTagsView" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:COMPASS.Views" | ||
xmlns:tools="clr-namespace:COMPASS.Tools" | ||
xmlns:viewmodels="clr-namespace:COMPASS.ViewModels.Import" | ||
xmlns:models="clr-namespace:COMPASS.Models" | ||
mc:Ignorable="d" | ||
d:DataContext="{d:DesignInstance Type=viewmodels:ImportTagsViewModel}" | ||
d:DesignHeight="450" d:DesignWidth="800"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="auto"/> | ||
<ColumnDefinition Width="auto"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<Grid.Resources> | ||
<tools:TagTemplateSelector x:Key="TagTemplateSelector"/> | ||
<HierarchicalDataTemplate x:Key="RegularTag" ItemsSource="{Binding Children}"> | ||
<Border CornerRadius="5" Margin="0,3"> | ||
<Border.Background> | ||
<SolidColorBrush Color="{Binding Item.BackgroundColor}"/> | ||
</Border.Background> | ||
<CheckBox Margin="5,0,0,0" IsChecked="{Binding IsChecked, Mode=TwoWay}" | ||
Content="{Binding Item.Content}" Foreground="{StaticResource TextColor}"/> | ||
</Border> | ||
</HierarchicalDataTemplate> | ||
<HierarchicalDataTemplate x:Key="GroupTag" ItemsSource="{Binding Children}"> | ||
<Border Margin="0,3" Background="{x:Null}" > | ||
<StackPanel Orientation="Horizontal" > | ||
<Rectangle Fill="{Binding Item.BackgroundColor, Converter={StaticResource ColorToBrushConverter}}" | ||
Width="2" Height="16" Margin="3" VerticalAlignment="Bottom" /> | ||
<CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}" | ||
Content="{Binding Item.Content}" Foreground="LightGray" | ||
FontSize="16" FontWeight="Bold" Typography.Capitals="AllSmallCaps"/> | ||
</StackPanel> | ||
</Border> | ||
</HierarchicalDataTemplate> | ||
</Grid.Resources> | ||
<ListBox Width="200" Background="Transparent" BorderThickness="0" | ||
ItemsSource="{Binding TagTemplates}" | ||
SelectedItem="{Binding SelectedTagTemplate}"> | ||
<ListBox.ItemContainerStyle> | ||
<Style TargetType="ListBoxItem"> | ||
<Setter Property="Template"> | ||
<Setter.Value> | ||
<ControlTemplate> | ||
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" | ||
BorderThickness="0,1" BorderBrush="{StaticResource Separator}" | ||
Background="{TemplateBinding Background}"> | ||
<StackPanel Orientation="Vertical" Margin="20,10"> | ||
<TextBlock Text="{Binding Name}"/> | ||
<Border Background="{StaticResource AccentColorMuted}" CornerRadius="3" | ||
HorizontalAlignment="Left" Margin="0,5,0,0"> | ||
<TextBlock FontSize="12" Margin="5,1" Visibility="{Binding ImportCount, | ||
Converter={StaticResource ToVisibilityConverter}, Mode=OneWay}"> | ||
<Run Text="{Binding ImportCount, Mode=OneWay}"></Run> tags selected | ||
</TextBlock> | ||
</Border> | ||
</StackPanel> | ||
</Border> | ||
</ControlTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
<Style.Triggers> | ||
<Trigger Property="IsMouseOver" Value="true"> | ||
<Setter Property="Background" Value="{StaticResource CardBackground}" /> | ||
</Trigger> | ||
<Trigger Property="IsSelected" Value="True"> | ||
<Setter Property="Background" Value="{StaticResource ListSelected}" /> | ||
</Trigger> | ||
</Style.Triggers> | ||
</Style> | ||
</ListBox.ItemContainerStyle> | ||
</ListBox> | ||
<Rectangle Grid.Column="1" Width="3" Fill="{StaticResource Separator}"/> | ||
<Grid Grid.Column="2" Margin="30,0"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="auto"/> | ||
<RowDefinition Height="auto"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
<CheckBox Content="All Tags" IsChecked="{Binding SelectedTagTemplate.TagsRoot.IsChecked}" Margin="0,10"/> | ||
<Rectangle Height="3" Fill="{StaticResource Separator}" Grid.Row="1"/> | ||
<TreeView Background="Transparent" Grid.Row="2" | ||
ItemsSource="{Binding SelectedTagTemplate.TagsRoot.Children}" | ||
HorizontalAlignment="Stretch" BorderThickness="0" | ||
ItemTemplateSelector="{StaticResource TagTemplateSelector}"> | ||
<TreeView.ItemContainerStyle> | ||
<Style TargetType="TreeViewItem"> | ||
<Setter Property="Focusable" Value="False" /> | ||
<Setter Property="IsExpanded" Value="{Binding Expanded}"/> | ||
</Style> | ||
</TreeView.ItemContainerStyle> | ||
</TreeView> | ||
</Grid> | ||
</Grid> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace COMPASS.Views | ||
{ | ||
/// <summary> | ||
/// Interaction logic for ImportTagsView.xaml | ||
/// </summary> | ||
public partial class ImportTagsView : UserControl | ||
{ | ||
public ImportTagsView() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
Oops, something went wrong.