11using Diffusion . Database ;
2- using System . Windows . Controls ;
3- using System . Windows ;
2+ using Diffusion . Database . Models ;
3+ using Diffusion . Toolkit . Classes ;
4+ using Diffusion . Toolkit . Models ;
5+ using Diffusion . Toolkit . Services ;
6+ using Microsoft . WindowsAPICodePack . Dialogs ;
47using SQLite ;
58using System . Collections . Generic ;
6- using System . Linq ;
79using System . Collections . ObjectModel ;
10+ using System . IO ;
11+ using System . Linq ;
812using System . Threading . Tasks ;
9- using Diffusion . Toolkit . Classes ;
10- using Diffusion . Toolkit . Models ;
11- using Diffusion . Toolkit . Services ;
12- using Diffusion . Database . Models ;
13+ using System . Windows ;
14+ using System . Windows . Controls ;
1315
1416namespace Diffusion . Toolkit
1517{
@@ -19,6 +21,47 @@ private void InitTags()
1921 {
2022 ServiceLocator . TagService . LoadTags = LoadTags ;
2123
24+ _model . ImportTagsCommand = new AsyncCommand < object > ( async ( o ) =>
25+ {
26+ using var dialog = new CommonOpenFileDialog ( ) ;
27+
28+ dialog . Title = GetLocalizedText ( "Actions.Tags.ImportTags.Title" ) ;
29+ dialog . Filters . Add ( new CommonFileDialogFilter ( "Text files" , "*.txt" ) ) ;
30+ dialog . Filters . Add ( new CommonFileDialogFilter ( "All files" , "*.*" ) ) ;
31+ dialog . DefaultExtension = "txt" ;
32+
33+ if ( dialog . ShowDialog ( this ) == CommonFileDialogResult . Ok )
34+ {
35+ var lines = File . ReadAllLines ( dialog . FileName ) ;
36+ var allTags = ServiceLocator . DataStore . GetTags ( ) ;
37+
38+ var tagLookup = allTags . Select ( d => d . Name ) . ToHashSet ( ) ;
39+
40+ var normalizedlines = lines . Select ( d => d . Trim ( ) ) . Distinct ( ) . Where ( d => d . Length > 0 && ! tagLookup . Contains ( d ) ) ;
41+
42+ ServiceLocator . TagService . CreateTags ( normalizedlines ) ;
43+
44+ LoadTags ( ) ;
45+ }
46+ } ) ;
47+
48+ _model . ExportTagsCommand = new AsyncCommand < object > ( async ( o ) =>
49+ {
50+ using var dialog = new CommonSaveFileDialog ( ) ;
51+
52+ dialog . Title = GetLocalizedText ( "Actions.Tags.ExportTags.Title" ) ;
53+ dialog . Filters . Add ( new CommonFileDialogFilter ( "Text files" , "*.txt" ) ) ;
54+ dialog . Filters . Add ( new CommonFileDialogFilter ( "All files" , "*.*" ) ) ;
55+ dialog . DefaultExtension = "txt" ;
56+
57+ if ( dialog . ShowDialog ( this ) == CommonFileDialogResult . Ok )
58+ {
59+ var tags = ServiceLocator . DataStore . GetTags ( ) ;
60+
61+ File . WriteAllLines ( dialog . FileName , tags . Select ( d => d . Name ) ) ;
62+ }
63+ } ) ;
64+
2265 _model . CreateTagCommand = new AsyncCommand < object > ( async ( o ) =>
2366 {
2467 var title = GetLocalizedText ( "Actions.Tags.Create.Title" ) ;
@@ -97,7 +140,7 @@ private void InitTags()
97140 private void LoadTags ( )
98141 {
99142 HashSet < int > currentSelected = new HashSet < int > ( ) ;
100-
143+
101144 if ( _model . Tags is { Count : > 0 } )
102145 {
103146 currentSelected = _model . Tags . Where ( d => d . IsTicked ) . Select ( d => d . Id ) . ToHashSet ( ) ;
0 commit comments