add export
This commit is contained in:
@@ -120,6 +120,14 @@ Padding="16,8"
|
|||||||
Command="{Binding ClearHistoryCommand}"
|
Command="{Binding ClearHistoryCommand}"
|
||||||
Padding="8,4"
|
Padding="8,4"
|
||||||
VerticalAlignment="Center" />
|
VerticalAlignment="Center" />
|
||||||
|
<ui:Button DockPanel.Dock="Right"
|
||||||
|
Content="Exportieren"
|
||||||
|
Appearance="Secondary"
|
||||||
|
Icon="{ui:SymbolIcon ArrowExportUp24}"
|
||||||
|
Command="{Binding ExportHistoryCommand}"
|
||||||
|
Padding="8,4"
|
||||||
|
Margin="0,0,8,0"
|
||||||
|
VerticalAlignment="Center" />
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<TextBlock Text="Farbverlauf"
|
<TextBlock Text="Farbverlauf"
|
||||||
Style="{StaticResource HeaderText}" />
|
Style="{StaticResource HeaderText}" />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using MaxSlurper.Models;
|
using MaxSlurper.Models;
|
||||||
@@ -42,6 +43,7 @@ namespace MaxSlurper.ViewModels
|
|||||||
public ICommand CopyHexCommand { get; }
|
public ICommand CopyHexCommand { get; }
|
||||||
public ICommand OpenColorPickerCommand { get; }
|
public ICommand OpenColorPickerCommand { get; }
|
||||||
public ICommand OpenSettingsCommand { get; }
|
public ICommand OpenSettingsCommand { get; }
|
||||||
|
public ICommand ExportHistoryCommand { get; }
|
||||||
|
|
||||||
public MainViewModel(IColorPickerService colorPicker, IAudioPlayer audioPlayer, ISettingsService settingsService)
|
public MainViewModel(IColorPickerService colorPicker, IAudioPlayer audioPlayer, ISettingsService settingsService)
|
||||||
{
|
{
|
||||||
@@ -57,6 +59,7 @@ namespace MaxSlurper.ViewModels
|
|||||||
CopyHexCommand = new RelayCommand(CopyHex, _ => Selected != null || _ is ColorItem);
|
CopyHexCommand = new RelayCommand(CopyHex, _ => Selected != null || _ is ColorItem);
|
||||||
OpenColorPickerCommand = new RelayCommand(_ => OpenColorPicker());
|
OpenColorPickerCommand = new RelayCommand(_ => OpenColorPicker());
|
||||||
OpenSettingsCommand = new RelayCommand(_ => OpenSettings());
|
OpenSettingsCommand = new RelayCommand(_ => OpenSettings());
|
||||||
|
ExportHistoryCommand = new RelayCommand(_ => ExportHistory(), _ => History.Count > 0);
|
||||||
|
|
||||||
// Restore persisted history
|
// Restore persisted history
|
||||||
foreach (var item in _settingsService.LoadHistory())
|
foreach (var item in _settingsService.LoadHistory())
|
||||||
@@ -90,6 +93,7 @@ namespace MaxSlurper.ViewModels
|
|||||||
System.Windows.Clipboard.SetText(item.Hex);
|
System.Windows.Clipboard.SetText(item.Hex);
|
||||||
_settingsService.SaveHistory(History);
|
_settingsService.SaveHistory(History);
|
||||||
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
||||||
|
((RelayCommand)ExportHistoryCommand).RaiseCanExecuteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenColorPicker()
|
private void OpenColorPicker()
|
||||||
@@ -117,6 +121,7 @@ namespace MaxSlurper.ViewModels
|
|||||||
System.Windows.Clipboard.SetText(item.Hex);
|
System.Windows.Clipboard.SetText(item.Hex);
|
||||||
_settingsService.SaveHistory(History);
|
_settingsService.SaveHistory(History);
|
||||||
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
||||||
|
((RelayCommand)ExportHistoryCommand).RaiseCanExecuteChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,6 +140,7 @@ namespace MaxSlurper.ViewModels
|
|||||||
Selected = null;
|
Selected = null;
|
||||||
_settingsService.SaveHistory(History);
|
_settingsService.SaveHistory(History);
|
||||||
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
||||||
|
((RelayCommand)ExportHistoryCommand).RaiseCanExecuteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveColor(object? parameter)
|
private void RemoveColor(object? parameter)
|
||||||
@@ -149,6 +155,7 @@ namespace MaxSlurper.ViewModels
|
|||||||
|
|
||||||
_settingsService.SaveHistory(History);
|
_settingsService.SaveHistory(History);
|
||||||
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
((RelayCommand)ClearHistoryCommand).RaiseCanExecuteChanged();
|
||||||
|
((RelayCommand)ExportHistoryCommand).RaiseCanExecuteChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CopyHex(object? parameter)
|
private void CopyHex(object? parameter)
|
||||||
@@ -164,6 +171,53 @@ namespace MaxSlurper.ViewModels
|
|||||||
// Show a notification (optional - can add UI feedback)
|
// Show a notification (optional - can add UI feedback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ExportHistory()
|
||||||
|
{
|
||||||
|
var dialog = new Microsoft.Win32.SaveFileDialog
|
||||||
|
{
|
||||||
|
Title = "Farbpalette exportieren",
|
||||||
|
Filter = "CSS-Datei (*.css)|*.css|JSON-Datei (*.json)|*.json|Textdatei (*.txt)|*.txt",
|
||||||
|
DefaultExt = ".css",
|
||||||
|
FileName = "palette"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() != true) return;
|
||||||
|
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
var ext = System.IO.Path.GetExtension(dialog.FileName).ToLowerInvariant();
|
||||||
|
|
||||||
|
switch (ext)
|
||||||
|
{
|
||||||
|
case ".css":
|
||||||
|
sb.AppendLine(":root {");
|
||||||
|
for (int i = 0; i < History.Count; i++)
|
||||||
|
{
|
||||||
|
var c = History[i];
|
||||||
|
sb.AppendLine($" --color-{i + 1}: {c.Hex};");
|
||||||
|
}
|
||||||
|
sb.AppendLine("}");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ".json":
|
||||||
|
sb.AppendLine("[");
|
||||||
|
for (int i = 0; i < History.Count; i++)
|
||||||
|
{
|
||||||
|
var c = History[i];
|
||||||
|
var comma = i < History.Count - 1 ? "," : "";
|
||||||
|
sb.AppendLine($" {{ \"hex\": \"{c.Hex}\", \"rgb\": \"{c.Rgb}\" }}{comma}");
|
||||||
|
}
|
||||||
|
sb.AppendLine("]");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: // .txt
|
||||||
|
foreach (var c in History)
|
||||||
|
sb.AppendLine(c.Hex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.IO.File.WriteAllText(dialog.FileName, sb.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
private void UpdateSelected()
|
private void UpdateSelected()
|
||||||
{
|
{
|
||||||
if (Selected == null)
|
if (Selected == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user