Browse Source

Lospec palettes import support

Krzysztof Krysiński 3 years ago
parent
commit
2c3e66fb47

+ 3 - 3
PixiEditor/Helpers/Converters/SKColorToMediaColorConverter.cs

@@ -6,15 +6,15 @@ using System.Windows.Media;
 
 namespace PixiEditor.Helpers.Converters
 {
-    class SKColorToMediaColorConverter : IValueConverter
+    public class SKColorToMediaColorConverter : SingleInstanceConverter<SKColorToMediaColorConverter>
     {
-        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
             var skcolor = (SKColor)value;
             return Color.FromArgb(skcolor.Alpha, skcolor.Red, skcolor.Green, skcolor.Blue);
         }
 
-        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
             var color = (Color)value;
             return new SKColor(color.R, color.G, color.B, color.A);

+ 1 - 1
PixiEditor/Models/DataHolders/Palettes/FilteringSettings.cs

@@ -23,7 +23,7 @@ namespace PixiEditor.Models.DataHolders.Palettes
         public bool Filter(Palette palette)
         {
             // Lexical comparison
-            bool result = string.IsNullOrWhiteSpace(Name) || palette.Title.Contains(Name, StringComparison.OrdinalIgnoreCase);
+            bool result = string.IsNullOrWhiteSpace(Name) || palette.Name.Contains(Name, StringComparison.OrdinalIgnoreCase);
 
             result = (ShowOnlyFavourites && palette.IsFavourite) || !ShowOnlyFavourites;
 

+ 3 - 3
PixiEditor/Models/DataHolders/Palettes/Palette.cs

@@ -7,15 +7,15 @@ namespace PixiEditor.Models.DataHolders.Palettes
 {
     public class Palette
     {
-        public string Title { get; set; }
+        public string Name { get; set; }
         public List<string> Colors { get; set; }
         public string FileName { get; set; }
 
         public bool IsFavourite { get; set; }
 
-        public Palette(string title, List<string> colors, string fileName)
+        public Palette(string name, List<string> colors, string fileName)
         {
-            Title = title;
+            Name = name;
             Colors = colors;
             FileName = fileName;
         }

+ 25 - 2
PixiEditor/Models/DataProviders/LocalPalettesFetcher.cs

@@ -7,7 +7,9 @@ using System.Collections.Generic;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
+using PixiEditor.Models.IO.JascPalFile;
 using PixiEditor.Models.UserPreferences;
+using SkiaSharp;
 
 namespace PixiEditor.Models.DataProviders
 {
@@ -68,7 +70,7 @@ namespace PixiEditor.Models.DataProviders
                     List<string> favouritePalettes = IPreferences.Current.GetLocalPreference<List<string>>(PreferencesConstants.FavouritePalettes);
                     if (favouritePalettes != null)
                     {
-                        palette.IsFavourite = favouritePalettes.Contains(palette.Title);
+                        palette.IsFavourite = favouritePalettes.Contains(palette.Name);
                     }
 
                     result.Add(palette);
@@ -78,9 +80,30 @@ namespace PixiEditor.Models.DataProviders
             return result;
         }
 
+        public static async Task SavePalette(string name, SKColor[] colors)
+        {
+            string path = Path.Join(PathToPalettesFolder, name + ".pal");
+            InitDir();
+            await JascFileParser.SaveFile(path, new PaletteFileData(colors));
+        }
+
+        public static void DeletePalette(string name)
+        {
+            if (!Directory.Exists(PathToPalettesFolder)) return;
+            string path = Path.Join(PathToPalettesFolder, name);
+            if (!File.Exists(path)) return;
+
+            File.Delete(path);
+        }
+
         public override void Initialize()
         {
-            if(!Directory.Exists(PathToPalettesFolder))
+            InitDir();
+        }
+
+        private static void InitDir()
+        {
+            if (!Directory.Exists(PathToPalettesFolder))
             {
                 Directory.CreateDirectory(PathToPalettesFolder);
             }

+ 13 - 29
PixiEditor/Models/ExternalServices/LospecPaletteFetcher.cs

@@ -12,47 +12,31 @@ namespace PixiEditor.Models.ExternalServices
     public static class LospecPaletteFetcher
     {
         public const string LospecApiUrl = "https://lospec.com/palette-list";
-        public static async Task<PaletteList> FetchPage(int page, string sortingType = "default", string[] tags = null, 
-            ColorsNumberMode colorsNumberMode = ColorsNumberMode.Any, int colorNumber = 8)
+
+        public static async Task<Palette> FetchPalette(string slug)
         {
             try
             {
-                using (HttpClient client = new HttpClient())
+                using HttpClient client = new HttpClient();
+                string url = @$"{LospecApiUrl}/{slug}.json";
+
+                HttpResponseMessage response = await client.GetAsync(url);
+                if (response.StatusCode == HttpStatusCode.OK)
                 {
-                    string url = @$"{LospecApiUrl}/load?colorNumberFilterType={colorsNumberMode.ToString().ToLower()}&page={page}&sortingType={sortingType}&tag=";
-                    
-                    if(tags != null && tags.Length > 0)
-                    {
-                        url += $"{string.Join(',', tags)}";
-                    }
+                    string content = await response.Content.ReadAsStringAsync();
+                    var obj = JsonConvert.DeserializeObject<Palette>(content);
 
-                    if(colorsNumberMode != ColorsNumberMode.Any)
+                    if (obj is { Colors: { } })
                     {
-                        url += $"&colorNumber={colorNumber}";
+                        ReadjustColors(obj.Colors);
                     }
 
-                    HttpResponseMessage response = await client.GetAsync(url);
-                    if (response.StatusCode == HttpStatusCode.OK)
-                    {
-                        string content = await response.Content.ReadAsStringAsync();
-                        var obj = JsonConvert.DeserializeObject<PaletteList>(content);
-
-                        obj.FetchedCorrectly = obj.Palettes != null;
-                        if (obj.Palettes != null)
-                        {
-                            foreach (var palette in obj.Palettes)
-                            {
-                                ReadjustColors(palette.Colors);
-                            }
-                        }
-
-                        return obj;
-                    }
+                    return obj;
                 }
             }
             catch(HttpRequestException)
             {
-                return new PaletteList() { FetchedCorrectly = false };
+                return null;
             }
 
             return null;

+ 5 - 4
PixiEditor/Models/Tools/ToolSettings/Settings/ColorSetting.cs

@@ -29,13 +29,14 @@ namespace PixiEditor.Models.Tools.ToolSettings.Settings
                 Style = (Style)resourceDictionary["DefaultColorPickerStyle"]
             };
 
-            Binding binding = new Binding("Value")
+            Binding selectedColorBinding = new Binding("Value")
             {
                 Mode = BindingMode.TwoWay
             };
-            GlobalShortcutFocusBehavior behavor = new GlobalShortcutFocusBehavior();
-            Interaction.GetBehaviors(picker).Add(behavor);
-            picker.SetBinding(ToolSettingColorPicker.SelectedColorProperty, binding);
+
+            GlobalShortcutFocusBehavior behavior = new GlobalShortcutFocusBehavior();
+            Interaction.GetBehaviors(picker).Add(behavior);
+            picker.SetBinding(ToolSettingColorPicker.SelectedColorProperty, selectedColorBinding);
             return picker;
         }
     }

+ 1 - 1
PixiEditor/Models/Tools/ToolSettings/Toolbars/BasicShapeToolbar.cs

@@ -7,7 +7,7 @@ namespace PixiEditor.Models.Tools.ToolSettings.Toolbars
         public BasicShapeToolbar()
         {
             Settings.Add(new BoolSetting("Fill", "Fill shape: "));
-            Settings.Add(new ColorSetting("FillColor", "Fill color"));
+            Settings.Add(new ColorSetting("FillColor",  "Fill color"));
         }
     }
 }

+ 1 - 1
PixiEditor/PixiEditor.csproj

@@ -202,7 +202,7 @@
 			<NoWarn>NU1701</NoWarn>
 		</PackageReference>
 		<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
-		<PackageReference Include="PixiEditor.ColorPicker" Version="3.2.0" />
+		<PackageReference Include="PixiEditor.ColorPicker" Version="3.3.0" />
 		<PackageReference Include="PixiEditor.Parser" Version="2.0.0.1" />
 		<PackageReference Include="PixiEditor.Parser.Skia" Version="2.0.0.1" />
 		<PackageReference Include="SkiaSharp" Version="2.80.3" />

+ 43 - 2
PixiEditor/ViewModels/SubViewModels/Main/ColorsViewModel.cs

@@ -10,7 +10,12 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.IO;
 using System.Linq;
+using System.Threading.Tasks;
+using System.Windows;
+using PixiEditor.Models.ExternalServices;
+using PixiEditor.Views.Dialogs;
 
 namespace PixiEditor.ViewModels.SubViewModels.Main
 {
@@ -63,12 +68,48 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         public ColorsViewModel(ViewModelMain owner)
             : base(owner)
         {
-
             SelectColorCommand = new RelayCommand(SelectColor);
             RemoveSwatchCommand = new RelayCommand(RemoveSwatch);
             SwapColorsCommand = new RelayCommand(SwapColors);
             SelectPaletteColorCommand = new RelayCommand<int>(SelectPaletteColor);
-            ImportPaletteCommand = new RelayCommand<List<string>>(ImportPalette);
+            ImportPaletteCommand = new RelayCommand<List<string>>(ImportPalette, Owner.DocumentIsNotNull);
+            Owner.OnStartupEvent += OwnerOnStartupEvent;
+        }
+
+        private async void OwnerOnStartupEvent(object? sender, EventArgs e)
+        {
+            await ImportLospecPalette();
+        }
+
+        private async Task ImportLospecPalette()
+        {
+            var args = Environment.GetCommandLineArgs();
+            var lospecPaletteArg = args.FirstOrDefault(x => x.StartsWith("lospec-palette://"));
+
+            if (lospecPaletteArg != null)
+            {
+                var browser = PalettesBrowser.Open(PaletteDataSources, ImportPaletteCommand,
+                    new WpfObservableRangeCollection<SKColor>());
+
+                browser.IsFetching = true;
+                var palette = await LospecPaletteFetcher.FetchPalette(lospecPaletteArg.Split(@"://")[1].Replace("/", ""));
+                if (palette != null)
+                {
+                    await LocalPalettesFetcher.SavePalette(
+                        palette.Name,
+                        palette.Colors.Select(SKColor.Parse).ToArray());
+
+                    palette.FileName = $"{palette.Name}.pal";
+
+                    await browser.UpdatePaletteList();
+                    int indexOfImported = browser.SortedResults.IndexOf(browser.SortedResults.First(x => x.FileName == palette.FileName));
+                    browser.SortedResults.Move(indexOfImported, 0);
+                }
+                else
+                {
+                    await browser.UpdatePaletteList();
+                }
+            }
         }
 
         public void ImportPalette(List<string> palette)

+ 2 - 2
PixiEditor/ViewModels/SubViewModels/Main/FileViewModel.cs

@@ -190,8 +190,8 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
         private void Owner_OnStartupEvent(object sender, System.EventArgs e)
         {
             var args = Environment.GetCommandLineArgs();
-            var file = args.Last();
-            if (Importer.IsSupportedFile(file) && File.Exists(file))
+            var file = args.FirstOrDefault(x => Importer.IsSupportedFile(x) && File.Exists(x));
+            if (file != null)
             {
                 Open(file);
             }

+ 37 - 9
PixiEditor/Views/Dialogs/PalettesBrowser.xaml.cs

@@ -147,6 +147,8 @@ namespace PixiEditor.Views.Dialogs
         public WpfObservableRangeCollection<SKColor> CurrentEditingPalette { get; set; }
         public static PalettesBrowser Instance { get; internal set; }
 
+        private static PaletteList _cachedPaletteList;
+
         public PalettesBrowser()
         {
             InitializeComponent();
@@ -156,6 +158,32 @@ namespace PixiEditor.Views.Dialogs
             Closed += (s, e) => Instance = null;
         }
 
+        public static PalettesBrowser Open(WpfObservableRangeCollection<PaletteListDataSource> dataSources, ICommand importPaletteCommand, WpfObservableRangeCollection<SKColor> currentEditingPalette)
+        {
+            if (Instance != null) return Instance;
+            PalettesBrowser browser = new PalettesBrowser
+            {
+                Owner = Application.Current.MainWindow,
+                ImportPaletteCommand = importPaletteCommand,
+                PaletteListDataSources = dataSources
+            };
+
+            if (_cachedPaletteList != null)
+            {
+                browser.PaletteList = _cachedPaletteList;
+            }
+
+            browser.OnListFetched += list =>
+            {
+                _cachedPaletteList = list;
+            };
+
+            browser.CurrentEditingPalette = currentEditingPalette;
+
+            browser.Show();
+            return browser;
+        }
+
         private async void ToggleFavourite(Palette palette)
         {
             palette.IsFavourite = !palette.IsFavourite;
@@ -163,11 +191,11 @@ namespace PixiEditor.Views.Dialogs
 
             if (palette.IsFavourite)
             {
-                favouritePalettes.Add(palette.Title);
+                favouritePalettes.Add(palette.Name);
             }
             else
             {
-                favouritePalettes.Remove(palette.Title);
+                favouritePalettes.Remove(palette.Name);
             }
 
             IPreferences.Current.UpdateLocalPreference(PreferencesConstants.FavouritePalettes, favouritePalettes);
@@ -183,7 +211,7 @@ namespace PixiEditor.Views.Dialogs
             {
                 if (ConfirmationDialog.Show("Are you sure you want to delete this palette? This cannot be undone.", "Warning!") == ConfirmationType.Yes)
                 {
-                    File.Delete(filePath);
+                    LocalPalettesFetcher.DeletePalette(palette.FileName);
                     RemoveFavouritePalette(palette);
 
                     LocalPalettesFetcher paletteListDataSource = (LocalPalettesFetcher)PaletteListDataSources.First(x => x is LocalPalettesFetcher);
@@ -197,9 +225,9 @@ namespace PixiEditor.Views.Dialogs
         {
             var favouritePalettes =
                 IPreferences.Current.GetLocalPreference<List<string>>(PreferencesConstants.FavouritePalettes);
-            if (favouritePalettes != null && favouritePalettes.Contains(palette.Title))
+            if (favouritePalettes != null && favouritePalettes.Contains(palette.Name))
             {
-                favouritePalettes.Remove(palette.Title);
+                favouritePalettes.Remove(palette.Name);
                 IPreferences.Current.UpdateLocalPreference(PreferencesConstants.FavouritePalettes, favouritePalettes);
             }
         }
@@ -340,7 +368,7 @@ namespace PixiEditor.Views.Dialogs
                         sorted = PaletteList.Palettes.OrderByDescending(x => x.IsFavourite).ThenBy(x => PaletteList.Palettes.IndexOf(x));
                         break;
                     case Models.DataHolders.Palettes.SortingType.Alphabetical:
-                        sorted = PaletteList.Palettes.OrderBy(x => x.Title);
+                        sorted = PaletteList.Palettes.OrderBy(x => x.Name);
                         break;
                     case Models.DataHolders.Palettes.SortingType.ColorCount:
                         sorted = PaletteList.Palettes.OrderBy(x => x.Colors.Count);
@@ -355,7 +383,7 @@ namespace PixiEditor.Views.Dialogs
                         sorted = PaletteList.Palettes.OrderByDescending(x => PaletteList.Palettes.IndexOf(x));
                         break;
                     case Models.DataHolders.Palettes.SortingType.Alphabetical:
-                        sorted = PaletteList.Palettes.OrderByDescending(x => x.Title);
+                        sorted = PaletteList.Palettes.OrderByDescending(x => x.Name);
                         break;
                     case Models.DataHolders.Palettes.SortingType.ColorCount:
                         sorted = PaletteList.Palettes.OrderByDescending(x => x.Colors.Count);
@@ -397,7 +425,7 @@ namespace PixiEditor.Views.Dialogs
                 i++;
             }
 
-            await JascFileParser.SaveFile(path, new PaletteFileData(CurrentEditingPalette.ToArray()));
+            await LocalPalettesFetcher.SavePalette(finalFileName, CurrentEditingPalette.ToArray());
             LocalPalettesFetcher paletteListDataSource = (LocalPalettesFetcher)PaletteListDataSources.First(x => x is LocalPalettesFetcher);
             await paletteListDataSource.RefreshCache();
             await UpdatePaletteList();
@@ -419,7 +447,7 @@ namespace PixiEditor.Views.Dialogs
         private async void PaletteItem_OnRename(object sender, EditableTextBlock.TextChangedEventArgs e)
         {
             PaletteItem item = (PaletteItem)sender;
-            if (string.IsNullOrWhiteSpace(e.NewText) || e.NewText.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || e.NewText == item.Palette.Title)
+            if (string.IsNullOrWhiteSpace(e.NewText) || e.NewText.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 || e.NewText == item.Palette.Name)
             {
                 return;
             }

+ 2 - 0
PixiEditor/Views/MainWindow.xaml

@@ -392,6 +392,8 @@
                                             <palettes:PaletteViewer IsEnabled="{Binding DocumentSubViewModel.Owner.BitmapManager.ActiveDocument,
                                         Converter={converters:NotNullToBoolConverter}}" Colors="{Binding BitmapManager.ActiveDocument.Palette}"
                                                               SelectColorCommand="{Binding ColorsSubViewModel.SelectColorCommand}"
+                                                              HintColor="{Binding Path=ColorsSubViewModel.PrimaryColor,
+                                                Converter={converters:SKColorToMediaColorConverter}}"
                                                                 DataSources="{Binding ColorsSubViewModel.PaletteDataSources}"
                                                                 FileParsers="{Binding ColorsSubViewModel.PaletteParsers}"
                                                                     Visibility="{Binding RelativeSource={RelativeSource Mode=Self}, 

+ 1 - 8
PixiEditor/Views/MainWindow.xaml.cs

@@ -55,14 +55,7 @@ namespace PixiEditor
             DataContext.BitmapManager.DocumentChanged += BitmapManager_DocumentChanged;
             preferences.AddCallback<bool>("ImagePreviewInTaskbar", x =>
             {
-                if (x)
-                {
-                    UpdateTaskbarIcon(DataContext.BitmapManager.ActiveDocument);
-                }
-                else
-                {
-                    UpdateTaskbarIcon(null);
-                }
+                UpdateTaskbarIcon(x ? DataContext.BitmapManager.ActiveDocument : null);
             });
 
             Current = this;

+ 1 - 0
PixiEditor/Views/UserControls/Palettes/PaletteColorAdder.xaml

@@ -11,6 +11,7 @@
         <colorpicker:PortableColorPicker
             ColorChanged="PortableColorPicker_ColorChanged"
             SelectedColor="{Binding SelectedColor, ElementName=paletteColorAdder, Mode=TwoWay}"
+            UseHintColor="True" HintColor="{Binding ElementName=paletteColorAdder, Path=HintColor}"
             Style="{StaticResource DefaultColorPickerStyle}" Width="50" Focusable="False" Margin="0 0 10 0"
             ShowAlpha="False"/>
         <Button Name="AddButton" Margin="0" Width="24" Height="24" 

+ 12 - 0
PixiEditor/Views/UserControls/Palettes/PaletteColorAdder.xaml.cs

@@ -29,6 +29,18 @@ namespace PixiEditor.Views.UserControls.Palettes
             set { SetValue(ColorsProperty, value); }
         }
 
+        public Color HintColor
+        {
+            get { return (Color)GetValue(HintColorProperty); }
+            set { SetValue(HintColorProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for HintColor.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty HintColorProperty =
+            DependencyProperty.Register("HintColor", typeof(Color), typeof(PaletteColorAdder), new PropertyMetadata(System.Windows.Media.Colors.Transparent));
+
+
+
         public Color SelectedColor
         {
             get { return (Color)GetValue(SelectedColorProperty); }

+ 1 - 1
PixiEditor/Views/UserControls/Palettes/PaletteItem.xaml

@@ -21,7 +21,7 @@
         <StackPanel Orientation="Vertical" Grid.RowSpan="2" Grid.ColumnSpan="2">
             <Separator Background="{StaticResource MainColor}"/>
             <StackPanel Orientation="Horizontal">
-                <views:EditableTextBlock x:Name="titleTextBlock" OnSubmit="EditableTextBlock_OnSubmit" Text="{Binding Palette.Title, ElementName=paletteItem, Mode=TwoWay}" Foreground="White" FontSize="20"/>
+                <views:EditableTextBlock x:Name="titleTextBlock" OnSubmit="EditableTextBlock_OnSubmit" Text="{Binding Palette.Name, ElementName=paletteItem, Mode=TwoWay}" Foreground="White" FontSize="20"/>
                 <Button Visibility="{Binding ElementName=paletteItem, Path=IsMouseOver, Converter={StaticResource BoolToVisibilityConverter}}" Click="RenameButton_Click" Style="{StaticResource ImageButtonStyle}" Cursor="Hand" Width="20" Height="20">
                     <Image Source="/Images/Edit.png"/>
                 </Button>

+ 3 - 1
PixiEditor/Views/UserControls/Palettes/PaletteViewer.xaml

@@ -17,7 +17,9 @@
         </Grid.RowDefinitions>
         <StackPanel Orientation="Vertical" Grid.Row="0" Background="{StaticResource MainColor}">
             <DockPanel VerticalAlignment="Center" Margin="0 5 0 0">
-                <palettes:PaletteColorAdder DockPanel.Dock="Left" Margin="5 0 0 0" Colors="{Binding ElementName=paletteControl, Path=Colors}"/>
+                <palettes:PaletteColorAdder DockPanel.Dock="Left" Margin="5 0 0 0"
+                                            HintColor="{Binding ElementName=paletteControl, Path=HintColor}"
+                                            Colors="{Binding ElementName=paletteControl, Path=Colors}"/>
                 <StackPanel Margin="0, 0, 5, 0" HorizontalAlignment="Right" Width="85" VerticalAlignment="Center" Orientation="Horizontal">
                 <Button Margin="0, 0, 5, 0" Style="{StaticResource ToolButtonStyle}" Click="BrowsePalettes_Click"
                 Cursor="Hand" Height="24" Width="24" ToolTip="Browse Palettes">

+ 14 - 21
PixiEditor/Views/UserControls/Palettes/PaletteViewer.xaml.cs

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
+using System.Windows.Media;
 using Microsoft.Win32;
 using PixiEditor.Models.DataHolders;
 using PixiEditor.Models.DataHolders.Palettes;
@@ -31,6 +32,18 @@ namespace PixiEditor.Views.UserControls.Palettes
             set { SetValue(ColorsProperty, value); }
         }
 
+        public Color HintColor
+        {
+            get { return (Color)GetValue(HintColorProperty); }
+            set { SetValue(HintColorProperty, value); }
+        }
+
+        // Using a DependencyProperty as the backing store for HintColor.  This enables animation, styling, binding, etc...
+        public static readonly DependencyProperty HintColorProperty =
+            DependencyProperty.Register("HintColor", typeof(Color), typeof(PaletteViewer), new PropertyMetadata(System.Windows.Media.Colors.Transparent));
+
+
+
         public ICommand SelectColorCommand
         {
             get { return (ICommand)GetValue(SelectColorCommandProperty); }
@@ -217,27 +230,7 @@ namespace PixiEditor.Views.UserControls.Palettes
 
         private async void BrowsePalettes_Click(object sender, RoutedEventArgs e)
         {
-            if (PalettesBrowser.Instance != null) return;
-            PalettesBrowser browser = new PalettesBrowser
-            {
-                Owner = Application.Current.MainWindow,
-                ImportPaletteCommand = ImportPaletteCommand,
-                PaletteListDataSources = DataSources
-            };
-
-            if(_cachedPaletteList != null)
-            {
-                browser.PaletteList = _cachedPaletteList;
-            }
-
-            browser.OnListFetched += list =>
-            {
-                _cachedPaletteList = list;
-            };
-
-            browser.CurrentEditingPalette = Colors;
-
-            browser.Show();
+            var browser = PalettesBrowser.Open(DataSources, ImportPaletteCommand, Colors);
             await browser.UpdatePaletteList();
         }
     }

+ 9 - 7
PixiEditor/Views/UserControls/ToolSettingColorPicker.xaml

@@ -1,16 +1,18 @@
-<UserControl x:Class="PixiEditor.Views.ToolSettingColorPicker"
+<UserControl
              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:PixiEditor.Views.UserControls" xmlns:colorpicker="clr-namespace:ColorPicker;assembly=ColorPicker"
+             xmlns:PixiEditor="clr-namespace:PixiEditor"
+             xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
+             x:Class="PixiEditor.Views.ToolSettingColorPicker"
              mc:Ignorable="d" 
              x:Name="uc"
              d:Background="{StaticResource AccentColor}">
-    <Grid>
-        <StackPanel Orientation="Horizontal">
-            <colorpicker:PortableColorPicker Width="40" Height="20" x:Name="ColorPicker" SelectedColor="{Binding SelectedColor, ElementName=uc,Mode=TwoWay}"/>
-            <Button Command="{Binding CopyMainColorCommand, ElementName=uc}" Style="{StaticResource DarkRoundButton}" FontSize="12" Width="100" Margin="5,0,0,0">Copy Main Color</Button>
-        </StackPanel>
-    </Grid>
+    <colorpicker:PortableColorPicker Width="40" Height="20" x:Name="ColorPicker" UseHintColor="True"
+                                     HintColor="{Binding DataContext.ColorsSubViewModel.PrimaryColor, 
+        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, 
+        Converter={converters:SKColorToMediaColorConverter}}"
+                                     SelectedColor="{Binding SelectedColor, ElementName=uc, Mode=TwoWay}"/>
 </UserControl>

+ 3 - 25
PixiEditor/Views/UserControls/ToolSettingColorPicker.xaml.cs

@@ -2,6 +2,7 @@
 using PixiEditor.ViewModels;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Data;
 using System.Windows.Media;
 
 namespace PixiEditor.Views
@@ -16,37 +17,14 @@ namespace PixiEditor.Views
 
         public Color SelectedColor
         {
-            get => (Color)GetValue(SelectedColorProperty);
-            set
-            {
-                SetValue(SelectedColorProperty, value);
-            }
-        }
-
-        public static readonly DependencyProperty CopyMainColorCommandProperty = DependencyProperty.Register(
-            nameof(CopyMainColorCommand), typeof(RelayCommand), typeof(ToolSettingColorPicker));
-
-        public RelayCommand CopyMainColorCommand
-        {
-            get { return (RelayCommand)GetValue(CopyMainColorCommandProperty); }
-            set { SetValue(CopyMainColorCommandProperty, value); }
+            get => (Color) GetValue(SelectedColorProperty);
+            set { SetValue(SelectedColorProperty, value); }
         }
 
         public ToolSettingColorPicker()
         {
             InitializeComponent();
             ColorPicker.SecondaryColor = Colors.Black;
-
-            CopyMainColorCommand = new RelayCommand(CopyMainColor);
-        }
-
-        public void CopyMainColor(object parameter)
-        {
-            SelectedColor = Color.FromArgb(
-                ViewModelMain.Current.ColorsSubViewModel.PrimaryColor.Alpha,
-                ViewModelMain.Current.ColorsSubViewModel.PrimaryColor.Red,
-                ViewModelMain.Current.ColorsSubViewModel.PrimaryColor.Green,
-                ViewModelMain.Current.ColorsSubViewModel.PrimaryColor.Blue);
         }
     }
 }

+ 0 - 14
PixiEditorTests/ModelsTests/LospecPaletteFetcher/LospecPaletteFetcherTests.cs

@@ -1,14 +0,0 @@
-using Xunit;
-
-namespace PixiEditorTests.ModelsTests.LospecPaletteFetcher
-{
-    public class LospecPaletteFetcherTests
-    {
-        [Fact]
-        public async void TestThatLospecPaletteFetcherFetchesData()
-        {
-            var result = await PixiEditor.Models.ExternalServices.LospecPaletteFetcher.FetchPage(0);
-            Assert.NotEmpty(result.Palettes);
-        }
-    }
-}