1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-26 06:49:19 +00:00

Wire up Open, Save, and Save As

These just needed to have methods added to the command definitions.

Also, added a style to the toolbar buttons so they fade when not
enabled.

Also, fixed the DataFileLoadIssue dialog, which was seriously broken.
This commit is contained in:
Andy McFadden 2019-06-21 16:27:58 -07:00
parent 440deda743
commit c87d79ec9e
6 changed files with 104 additions and 64 deletions

View File

@ -772,7 +772,7 @@ namespace SourceGenWPF {
/// <summary>
/// Handles opening an existing project by letting the user select the project file.
/// </summary>
private void DoOpen() {
public void OpenProject() {
if (!CloseProject()) {
return;
}
@ -941,7 +941,11 @@ namespace SourceGenWPF {
return newPath;
}
private bool DoSaveAs() {
/// <summary>
/// Saves the project, querying for the filename.
/// </summary>
/// <returns>True on success, false if the save attempt failed or was canceled.</returns>
public bool SaveProjectAs() {
SaveFileDialog fileDlg = new SaveFileDialog() {
Filter = ProjectFile.FILENAME_FILTER + "|" + Res.Strings.FILE_FILTER_ALL,
FilterIndex = 1,
@ -949,30 +953,33 @@ namespace SourceGenWPF {
AddExtension = true,
FileName = Path.GetFileName(mDataPathName) + ProjectFile.FILENAME_EXT
};
if (fileDlg.ShowDialog() == true) {
string pathName = Path.GetFullPath(fileDlg.FileName);
Debug.WriteLine("Project save path: " + pathName);
if (DoSave(pathName)) {
// Success, record the path name.
mProjectPathName = mProject.ProjectPathName = pathName;
// add it to the title bar
#if false
UpdateMenuItemsAndTitle();
#endif
return true;
}
if (fileDlg.ShowDialog() != true) {
Debug.WriteLine("SaveAs canceled by user");
return false;
}
return false;
string pathName = Path.GetFullPath(fileDlg.FileName);
Debug.WriteLine("Project save path: " + pathName);
if (!DoSave(pathName)) {
return false;
}
// Success, record the path name.
mProjectPathName = mProject.ProjectPathName = pathName;
// add it to the title bar
#if false
UpdateMenuItemsAndTitle();
#endif
return true;
}
/// <summary>
/// Save the project. If it hasn't been saved before, use save-as behavior instead.
/// Saves the project. If it hasn't been saved before, use save-as behavior instead.
/// </summary>
/// <returns>True on success, false if the save attempt failed.</returns>
private bool DoSave() {
public bool SaveProject() {
if (string.IsNullOrEmpty(mProjectPathName)) {
return DoSaveAs();
return SaveProjectAs();
}
return DoSave(mProjectPathName);
}
@ -1028,7 +1035,7 @@ namespace SourceGenWPF {
if (ok != true) {
return false;
} else if (dlg.UserChoice == DiscardChanges.Choice.SaveAndContinue) {
if (!DoSave()) {
if (!SaveProject()) {
return false;
}
}

View File

@ -13,10 +13,21 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SourceGenWPF.Res">
<!-- Fade the icon when the associated button is disabled.
cf. https://stackoverflow.com/a/2530941/294248 -->
<Style x:Key="DisableFade" TargetType="Viewbox">
<Style.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.25"/>
</Trigger>
</Style.Triggers>
</Style>
<ControlTemplate x:Key="icon_CopyToClipboard">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22116.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
@ -41,7 +52,8 @@
<ControlTemplate x:Key="icon_F1Help">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
@ -64,7 +76,8 @@
<ControlTemplate x:Key="icon_NewFile">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
@ -88,7 +101,8 @@
<ControlTemplate x:Key="icon_OpenFile">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
@ -112,7 +126,8 @@
<ControlTemplate x:Key="icon_SaveFile">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
@ -135,7 +150,8 @@
<ControlTemplate x:Key="icon_StepBackwards">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>
@ -157,7 +173,8 @@
<ControlTemplate x:Key="icon_StepForward">
<!-- This file was generated by the AiToXaml tool.-->
<!-- Tool Version: 14.0.22307.0 -->
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Viewbox Width="16" Height="16" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Style="{StaticResource DisableFade}">
<Rectangle Width="16" Height="16">
<Rectangle.Fill>
<DrawingBrush>

View File

@ -24,21 +24,17 @@ limitations under the License.
Title="Data File Load Issue"
SizeToContent="WidthAndHeight" ResizeMode="NoResize"
ShowInTaskbar="False" WindowStartupLocation="CenterOwner">
<DockPanel Margin="8" LastChildFill="False">
<TextBlock DockPanel.Dock="Top">There was an error while loading the data file:</TextBlock>
<TextBox Name="pathNameTextBox" DockPanel.Dock="Top" Margin="0,8,0,0" IsReadOnly="True"
Width="540" MaxLines="1" Text="(filename)"/>
<TextBlock Name="problemLabel" DockPanel.Dock="Top" Margin="0,8,0,0" Text="(reason)"/>
<Grid DockPanel.Dock="Bottom" Margin="0,8,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Do you want to locate the data file?"/>
<Button Grid.Column="1" Content="OK" Width="75" IsDefault="True"/>
<Button Grid.Column="2" Content="Cancel" Width="75" Margin="8,0,0,0" IsCancel="True"/>
</Grid>
</DockPanel>
<StackPanel Margin="8">
<TextBlock>While loading the file:</TextBlock>
<TextBox Margin="0,8,0,0" IsReadOnly="True"
Width="540" MaxLines="1" Text="{Binding PathName}"/>
<TextBlock Margin="0,8,0,0" Text="There was a problem:"/>
<TextBox Margin="0,8,0,0" IsReadOnly="True" Text="{Binding Message}"/>
<DockPanel Margin="0,8,0,0" LastChildFill="False">
<TextBlock DockPanel.Dock="Left" Text="Do you want to locate the data file?"/>
<Button DockPanel.Dock="Right" Content="Cancel" Width="75" Margin="8,0,0,0" IsCancel="True"/>
<Button DockPanel.Dock="Right" Grid.Column="1" Content="OK" Width="75"
IsDefault="True" Click="OkButton_Click"/>
</DockPanel>
</StackPanel>
</Window>

View File

@ -24,25 +24,25 @@ namespace SourceGenWPF.WpfGui {
/// <summary>
/// Path name of problematic file.
/// </summary>
private string mPathName;
public string PathName { get; set; }
/// <summary>
/// Message to show in the dialog.
/// </summary>
private string mMessage;
public string Message { get; set; }
public DataFileLoadIssue(Window owner, string pathName, string message) {
PathName = pathName;
Message = message;
this.DataContext = this;
InitializeComponent();
Owner = owner;
mPathName = pathName;
mMessage = message;
}
private void DataFileLoadIssue_Load(object sender, EventArgs e) {
pathNameTextBox.Text = mPathName;
problemLabel.Text = mMessage;
private void OkButton_Click(object sender, RoutedEventArgs e) {
DialogResult = true;
}
}
}

View File

@ -70,6 +70,7 @@ limitations under the License.
<KeyGesture>Ctrl+Shift+Minus</KeyGesture>
</RoutedUICommand.InputGestures>
</RoutedUICommand>
<RoutedUICommand x:Key="OpenCmd" Text="Open"/>
<RoutedUICommand x:Key="RemoveHintsCmd" Text="Remove Hints"/>
<RoutedUICommand x:Key="RecentProjectCmd"/>
<RoutedUICommand x:Key="RedoCmd" Text="Redo">
@ -115,11 +116,18 @@ limitations under the License.
CanExecute="CanNavigateBackward" Executed="NavigateBackwardCmd_Executed"/>
<CommandBinding Command="{StaticResource NavigateForwardCmd}"
CanExecute="CanNavigateForward" Executed="NavigateForwardCmd_Executed"/>
<CommandBinding Command="{StaticResource OpenCmd}"
Executed="OpenCmd_Executed"/>
<CommandBinding Command="{StaticResource RemoveHintsCmd}"
CanExecute="CanRemoveHints" Executed="RemoveHintsCmd_Executed"/>
<CommandBinding Command="{StaticResource RecentProjectCmd}" Executed="RecentProjectCmd_Executed"/>
<CommandBinding Command="{StaticResource RecentProjectCmd}"
Executed="RecentProjectCmd_Executed"/>
<CommandBinding Command="{StaticResource RedoCmd}"
CanExecute="CanRedo" Executed="RedoCmd_Executed"/>
<CommandBinding Command="Save"
CanExecute="IsProjectOpen" Executed="SaveCmd_Executed"/>
<CommandBinding Command="SaveAs"
CanExecute="IsProjectOpen" Executed="SaveAsCmd_Executed"/>
<!-- ListView has a built-in Ctrl+A handler; this only fires when codeListView is not in focus -->
<CommandBinding Command="{StaticResource SelectAllCmd}"
CanExecute="IsProjectOpen" Executed="SelectAllCmd_Executed"/>
@ -131,7 +139,7 @@ limitations under the License.
<Menu Name="appMenu" DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="New"/>
<MenuItem Header="Open"/>
<MenuItem Command="{StaticResource OpenCmd}"/>
<MenuItem Command="Save"/>
<MenuItem Command="SaveAs"/>
<MenuItem Command="{StaticResource CloseCmd}"/>
@ -218,10 +226,10 @@ limitations under the License.
<Button ToolTip="Create new project">
<ContentControl Template="{StaticResource icon_NewFile}"/>
</Button>
<Button ToolTip="Open project">
<Button ToolTip="Open project" Command="{StaticResource OpenCmd}">
<ContentControl Template="{StaticResource icon_OpenFile}"/>
</Button>
<Button ToolTip="Save project">
<Button ToolTip="Save project" Command="Save">
<ContentControl Template="{StaticResource icon_SaveFile}"/>
</Button>
<Separator/>
@ -229,7 +237,7 @@ limitations under the License.
<ContentControl Template="{StaticResource icon_CopyToClipboard}"/>
</Button>
<Separator/>
<Button ToolTip="Help - open manual in browser">
<Button ToolTip="Help - open manual in browser" Command="Help">
<ContentControl Template="{StaticResource icon_F1Help}"/>
</Button>
</ToolBar>

View File

@ -720,13 +720,6 @@ namespace SourceGenWPF.WpfGui {
(counts.mCodeHints != 0 || counts.mDataHints != 0 || counts.mInlineDataHints != 0);
}
private void CanRedo(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = mMainCtrl != null && mMainCtrl.CanRedo();
}
private void CanUndo(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = mMainCtrl != null && mMainCtrl.CanUndo();
}
private void CanNavigateBackward(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = mMainCtrl != null && mMainCtrl.CanNavigateBackward();
}
@ -734,6 +727,13 @@ namespace SourceGenWPF.WpfGui {
e.CanExecute = mMainCtrl != null && mMainCtrl.CanNavigateForward();
}
private void CanRedo(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = mMainCtrl != null && mMainCtrl.CanRedo();
}
private void CanUndo(object sender, CanExecuteRoutedEventArgs e) {
e.CanExecute = mMainCtrl != null && mMainCtrl.CanUndo();
}
#endregion Can-execute handlers
@ -785,6 +785,10 @@ namespace SourceGenWPF.WpfGui {
mMainCtrl.NavigateForward();
}
private void OpenCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.OpenProject();
}
private void RemoveHintsCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
Debug.WriteLine("remove hints");
mMainCtrl.MarkAsType(CodeAnalysis.TypeHint.NoHint, false);
@ -794,6 +798,14 @@ namespace SourceGenWPF.WpfGui {
mMainCtrl.RedoChanges();
}
private void SaveCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.SaveProject();
}
private void SaveAsCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
mMainCtrl.SaveProjectAs();
}
private void SelectAllCmd_Executed(object sender, ExecutedRoutedEventArgs e) {
DateTime start = DateTime.Now;