mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
add an export theme button
This commit is contained in:
parent
239a0e3e1d
commit
1b7c8b2b3a
@ -99,9 +99,12 @@
|
|||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
|
<ColumnDefinition Width="*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
|
|
||||||
<ui:Button Grid.Column="0" Margin="0,0,2,0" Icon="Add28" Content="Rename" HorizontalAlignment="Stretch" Command="{Binding RenameCustomThemeCommand, Mode=OneTime}" />
|
<ui:Button Grid.Column="0" Margin="0,0,2,0" Icon="Add28" Content="Rename" HorizontalAlignment="Stretch" Command="{Binding RenameCustomThemeCommand, Mode=OneTime}" />
|
||||||
<ui:Button Grid.Column="1" Margin="2,0,0,0" Icon="Add28" Content="Edit" HorizontalAlignment="Stretch" Command="{Binding EditCustomThemeCommand, Mode=OneTime}" />
|
<ui:Button Grid.Column="1" Margin="2,0,2,0" Icon="Add28" Content="Edit" HorizontalAlignment="Stretch" Command="{Binding EditCustomThemeCommand, Mode=OneTime}" />
|
||||||
|
<ui:Button Grid.Column="2" Margin="2,0,0,0" Icon="Add28" Content="Export" HorizontalAlignment="Stretch" Command="{Binding ExportCustomThemeCommand, Mode=OneTime}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Text="No custom theme selected." TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center">
|
<TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="1" Text="No custom theme selected." TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||||
|
@ -4,13 +4,13 @@ using System.Windows.Controls;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
using Bloxstrap.UI.Elements.Settings;
|
using Bloxstrap.UI.Elements.Settings;
|
||||||
using Bloxstrap.UI.Elements.Editor;
|
using Bloxstrap.UI.Elements.Editor;
|
||||||
using Bloxstrap.UI.Elements.Dialogs;
|
using Bloxstrap.UI.Elements.Dialogs;
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace Bloxstrap.UI.ViewModels.Settings
|
namespace Bloxstrap.UI.ViewModels.Settings
|
||||||
{
|
{
|
||||||
@ -25,6 +25,7 @@ namespace Bloxstrap.UI.ViewModels.Settings
|
|||||||
public ICommand DeleteCustomThemeCommand => new RelayCommand(DeleteCustomTheme);
|
public ICommand DeleteCustomThemeCommand => new RelayCommand(DeleteCustomTheme);
|
||||||
public ICommand RenameCustomThemeCommand => new RelayCommand(RenameCustomTheme);
|
public ICommand RenameCustomThemeCommand => new RelayCommand(RenameCustomTheme);
|
||||||
public ICommand EditCustomThemeCommand => new RelayCommand(EditCustomTheme);
|
public ICommand EditCustomThemeCommand => new RelayCommand(EditCustomTheme);
|
||||||
|
public ICommand ExportCustomThemeCommand => new RelayCommand(ExportCustomTheme);
|
||||||
|
|
||||||
private void PreviewBootstrapper()
|
private void PreviewBootstrapper()
|
||||||
{
|
{
|
||||||
@ -225,6 +226,48 @@ namespace Bloxstrap.UI.ViewModels.Settings
|
|||||||
new BootstrapperEditorWindow(SelectedCustomTheme).ShowDialog();
|
new BootstrapperEditorWindow(SelectedCustomTheme).ShowDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ExportCustomTheme()
|
||||||
|
{
|
||||||
|
if (SelectedCustomTheme is null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var dialog = new SaveFileDialog
|
||||||
|
{
|
||||||
|
FileName = $"{SelectedCustomTheme}.zip",
|
||||||
|
Filter = $"{Strings.FileTypes_ZipArchive}|*.zip"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() != true)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string themeDir = Path.Combine(Paths.CustomThemes, SelectedCustomTheme);
|
||||||
|
|
||||||
|
using var memStream = new MemoryStream();
|
||||||
|
using var zipStream = new ZipOutputStream(memStream);
|
||||||
|
|
||||||
|
foreach (var filePath in Directory.EnumerateFiles(themeDir, "*.*", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
string relativePath = filePath[(themeDir.Length + 1)..];
|
||||||
|
|
||||||
|
var entry = new ZipEntry(relativePath);
|
||||||
|
entry.DateTime = DateTime.Now;
|
||||||
|
|
||||||
|
zipStream.PutNextEntry(entry);
|
||||||
|
|
||||||
|
using var fileStream = File.OpenRead(filePath);
|
||||||
|
fileStream.CopyTo(zipStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
zipStream.CloseEntry();
|
||||||
|
zipStream.Finish();
|
||||||
|
memStream.Position = 0;
|
||||||
|
|
||||||
|
using var outputStream = File.OpenWrite(dialog.FileName);
|
||||||
|
memStream.CopyTo(outputStream);
|
||||||
|
|
||||||
|
Process.Start("explorer.exe", $"/select,\"{dialog.FileName}\"");
|
||||||
|
}
|
||||||
|
|
||||||
private void PopulateCustomThemes()
|
private void PopulateCustomThemes()
|
||||||
{
|
{
|
||||||
string? selected = App.Settings.Prop.SelectedCustomTheme;
|
string? selected = App.Settings.Prop.SelectedCustomTheme;
|
||||||
|
Loading…
Reference in New Issue
Block a user