TSCB keyboard shortcuts

Adds keyboard shortcuts to the TSCB control (open, save, save as).
This commit is contained in:
Chev 2021-01-24 01:00:53 -08:00
parent eacd7821f0
commit d5b70ce4f3
2 changed files with 70 additions and 25 deletions

View file

@ -5,14 +5,25 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BOTWToolset.Control" xmlns:local="clr-namespace:BOTWToolset.Control"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="597" d:DesignWidth="1246 " Width="Auto" Height="Auto"> d:DesignHeight="597" d:DesignWidth="1246 " Width="Auto" Height="Auto" Loaded="UserControlLoaded">
<UserControl.CommandBindings>
<CommandBinding Command="Open" Executed="Menu_FileOpen"/>
<CommandBinding Command="Save" Executed="Menu_FileSave"/>
<CommandBinding Command="SaveAs" Executed="Menu_FileSaveAs"/>
</UserControl.CommandBindings>
<UserControl.InputBindings>
<KeyBinding Key="O" Modifiers="Ctrl" Command="Open"/>
<KeyBinding Key="S" Modifiers="Ctrl" Command="Save"/>
<KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="SaveAs"/>
</UserControl.InputBindings>
<Grid> <Grid>
<Label Content="TSCB Editor" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/> <Label Content="TSCB Editor" Margin="10,10,10,0" VerticalAlignment="Top" Height="48" FontSize="28" VerticalContentAlignment="Center" FontFamily="Segoe UI Light"/>
<Menu Margin="10,58,10,0" VerticalAlignment="Top"> <Menu Margin="10,58,10,0" VerticalAlignment="Top">
<MenuItem Header="_File" Foreground="White"> <MenuItem Header="_File" Foreground="White">
<MenuItem x:Name="MenuFileOpen" Header="_Open" Click="Menu_FileOpen" InputGestureText="Ctrl+O"/> <MenuItem x:Name="MenuFileOpen" Header="_Open" Command="Open"/>
<MenuItem x:Name="MenuFileSave" Header="_Save" Click="Menu_FileSave" InputGestureText="Ctrl+S" IsEnabled="False"/> <MenuItem x:Name="MenuFileSave" Header="_Save" Command="Save" IsEnabled="False"/>
<MenuItem x:Name="MenuFileSaveAs" Header="_Save As" Command="SaveAs" IsEnabled="False"/>
<MenuItem x:Name="MenuFileClose" Header="_Close" Click="Menu_FileClose" IsEnabled="False"/> <MenuItem x:Name="MenuFileClose" Header="_Close" Click="Menu_FileClose" IsEnabled="False"/>
</MenuItem> </MenuItem>
</Menu> </Menu>

View file

@ -20,11 +20,27 @@ namespace BOTWToolset.Control
/// </summary> /// </summary>
public partial class TabTSCB : UserControl public partial class TabTSCB : UserControl
{ {
/// <summary>
/// The file location for the currently loaded TSCB file.
/// </summary>
public static string fileLocation; public static string fileLocation;
/// <summary>
/// The currently loaded TSCB, if any.
/// </summary>
public static TSCB currentTSCB; public static TSCB currentTSCB;
public static WriteableBitmap writeableBitmap; //used for pixel-like display /// <summary>
/// WriteableBitmap that is used for the map display.
/// </summary>
public static WriteableBitmap writeableBitmap;
/// <summary>
/// Used to modify the map display with new info.
/// </summary>
/// <param name="sarc">The SARC archive to read for data.</param>
/// <param name="xyoffs">X and Y integer offsets.</param>
/// <param name="i"></param>
private delegate void IteratePixels(SARC sarc, int[] xyoffs, int i); private delegate void IteratePixels(SARC sarc, int[] xyoffs, int i);
public TabTSCB() public TabTSCB()
@ -37,6 +53,12 @@ namespace BOTWToolset.Control
PixelView.Stretch = Stretch.Uniform; PixelView.Stretch = Stretch.Uniform;
} }
private void UserControlLoaded(object sender, RoutedEventArgs e)
{
this.Focusable = true;
this.Focus(); // Update IsEnabled on MenuItem buttons
}
private void ClearBitmap() private void ClearBitmap()
{ {
PixelView.Source = null; PixelView.Source = null;
@ -285,7 +307,7 @@ namespace BOTWToolset.Control
} }
} }
private void Menu_FileOpen(object sender, RoutedEventArgs e) private void Menu_FileOpen(object sender, ExecutedRoutedEventArgs e)
{ {
BOTWConsole.Log("Clicked File -> Open button"); BOTWConsole.Log("Clicked File -> Open button");
@ -320,6 +342,7 @@ namespace BOTWToolset.Control
// Allow the file to be saved // Allow the file to be saved
MenuFileClose.IsEnabled = true; MenuFileClose.IsEnabled = true;
MenuFileSave.IsEnabled = true; MenuFileSave.IsEnabled = true;
MenuFileSaveAs.IsEnabled = true;
// Really laggy, creating 9,000+ controls isn't necessarily a fantastic idea // Really laggy, creating 9,000+ controls isn't necessarily a fantastic idea
// Maybe having a filter would help? // Maybe having a filter would help?
@ -334,6 +357,36 @@ namespace BOTWToolset.Control
} }
} }
private void Menu_FileSave(object sender, ExecutedRoutedEventArgs e)
{
BOTWConsole.Log("Clicked File -> Save button");
File.WriteAllBytes(fileLocation, TSCB.ToBytes(currentTSCB));
BOTWConsole.LogStatus($"Saved file to {fileLocation}.");
}
private void Menu_FileSaveAs(object sender, ExecutedRoutedEventArgs e)
{
BOTWConsole.Log("Clicked File -> Save As button");
SaveFileDialog saveFileDialog = new SaveFileDialog
{
InitialDirectory = @"C;\",
RestoreDirectory = true,
Title = "Save TSCB file",
DefaultExt = "tscb",
Filter = "TSCB files (*.tscb)|*.tscb"
};
if ((bool)saveFileDialog.ShowDialog())
{
File.WriteAllBytes(saveFileDialog.FileName, TSCB.ToBytes(currentTSCB));
BOTWConsole.LogStatus($"Saved file to {saveFileDialog.FileName}.");
}
}
private void Menu_FileClose(object sender, RoutedEventArgs e) private void Menu_FileClose(object sender, RoutedEventArgs e)
{ {
BOTWConsole.Log("Clicked File -> Close button"); BOTWConsole.Log("Clicked File -> Close button");
@ -347,26 +400,7 @@ namespace BOTWToolset.Control
// Since there's no file open, don't allow saving // Since there's no file open, don't allow saving
MenuFileClose.IsEnabled = false; MenuFileClose.IsEnabled = false;
MenuFileSave.IsEnabled = false; MenuFileSave.IsEnabled = false;
} MenuFileSaveAs.IsEnabled = false;
// TODO: split this into "save" and "save as"
private void Menu_FileSave(object sender, RoutedEventArgs e)
{
BOTWConsole.Log("Clicked File -> Save button");
SaveFileDialog saveFileDialog = new SaveFileDialog
{
InitialDirectory = @"C;\",
RestoreDirectory = true,
Title = "Save TSCB file",
DefaultExt = "tscb",
Filter = "TSCB files (*.tscb)|*.tscb"
};
if ((bool)saveFileDialog.ShowDialog())
{
File.WriteAllBytes(saveFileDialog.FileName, TSCB.ToBytes(currentTSCB));
}
} }
private void OverrideKeyDown(object sender, KeyEventArgs e) private void OverrideKeyDown(object sender, KeyEventArgs e)