mirror of
https://github.com/chev2/botw-toolset.git
synced 2025-10-30 08:12:17 +00:00
TSCB keyboard shortcuts
Adds keyboard shortcuts to the TSCB control (open, save, save as).
This commit is contained in:
parent
eacd7821f0
commit
d5b70ce4f3
2 changed files with 70 additions and 25 deletions
|
|
@ -5,14 +5,25 @@
|
|||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:BOTWToolset.Control"
|
||||
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>
|
||||
<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">
|
||||
<MenuItem Header="_File" Foreground="White">
|
||||
<MenuItem x:Name="MenuFileOpen" Header="_Open" Click="Menu_FileOpen" InputGestureText="Ctrl+O"/>
|
||||
<MenuItem x:Name="MenuFileSave" Header="_Save" Click="Menu_FileSave" InputGestureText="Ctrl+S" IsEnabled="False"/>
|
||||
<MenuItem x:Name="MenuFileOpen" Header="_Open" Command="Open"/>
|
||||
<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>
|
||||
</Menu>
|
||||
|
|
|
|||
|
|
@ -20,11 +20,27 @@ namespace BOTWToolset.Control
|
|||
/// </summary>
|
||||
public partial class TabTSCB : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// The file location for the currently loaded TSCB file.
|
||||
/// </summary>
|
||||
public static string fileLocation;
|
||||
|
||||
/// <summary>
|
||||
/// The currently loaded TSCB, if any.
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
public TabTSCB()
|
||||
|
|
@ -37,6 +53,12 @@ namespace BOTWToolset.Control
|
|||
PixelView.Stretch = Stretch.Uniform;
|
||||
}
|
||||
|
||||
private void UserControlLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.Focusable = true;
|
||||
this.Focus(); // Update IsEnabled on MenuItem buttons
|
||||
}
|
||||
|
||||
private void ClearBitmap()
|
||||
{
|
||||
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");
|
||||
|
||||
|
|
@ -320,6 +342,7 @@ namespace BOTWToolset.Control
|
|||
// Allow the file to be saved
|
||||
MenuFileClose.IsEnabled = true;
|
||||
MenuFileSave.IsEnabled = true;
|
||||
MenuFileSaveAs.IsEnabled = true;
|
||||
|
||||
// Really laggy, creating 9,000+ controls isn't necessarily a fantastic idea
|
||||
// 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)
|
||||
{
|
||||
BOTWConsole.Log("Clicked File -> Close button");
|
||||
|
|
@ -347,26 +400,7 @@ namespace BOTWToolset.Control
|
|||
// Since there's no file open, don't allow saving
|
||||
MenuFileClose.IsEnabled = false;
|
||||
MenuFileSave.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));
|
||||
}
|
||||
MenuFileSaveAs.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void OverrideKeyDown(object sender, KeyEventArgs e)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue