Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 9b516e8

Browse files
committed
templates loadable by double clicking or pressing enter
1 parent ddb0af6 commit 9b516e8

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

UI/Windows/NewFileWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ResourceDictionary>
1818
</controls:MetroWindow.Resources>
1919
<Grid>
20-
<ListBox Name="TemplateListBox" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="250" Margin="0,0,0,50" SelectionChanged="TemplateListBox_SelectionChanged" />
20+
<ListBox Name="TemplateListBox" HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="250" Margin="0,0,0,50" SelectionChanged="TemplateListBox_SelectionChanged" MouseDoubleClick="TemplateListBox_MouseDoubleClick" KeyDown="TemplateListBox_KeyDown" />
2121
<TextBlock Name="PreviewBlock" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="260,10,0,0" Text="Preview:" IsHitTestVisible="False" />
2222
<TextBox Name="PrevieBox" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="260,30,5,50" IsReadOnly="True" />
2323
<TextBox Name="PathBox" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="5,0,120,5"

UI/Windows/NewFileWindow.xaml.cs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,6 @@ private void TemplateListBox_SelectionChanged(object sender, SelectionChangedEve
131131
PathBox.Text = Path.Combine(PathStr, templateInfo.NewName);
132132
}
133133

134-
private void Button_Click(object sender, RoutedEventArgs e)
135-
{
136-
var destFile = new FileInfo(PathBox.Text);
137-
var templateInfo = TemplateDictionary[(string)TemplateListBox.SelectedItem];
138-
File.Copy(templateInfo.Path, destFile.FullName, true);
139-
Program.MainWindow.TryLoadSourceFile(destFile.FullName, true, true, true);
140-
Close();
141-
}
142-
143134
private void Language_Translate()
144135
{
145136
if (Program.Translations.IsDefault)
@@ -172,6 +163,33 @@ public void Execute(object parameter)
172163
ExecuteAction?.Invoke(parameter);
173164
}
174165
}
166+
167+
private void Button_Click(object sender, RoutedEventArgs e)
168+
{
169+
GoToSelectedTemplate();
170+
}
171+
172+
private void TemplateListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
173+
{
174+
GoToSelectedTemplate();
175+
}
176+
177+
private void TemplateListBox_KeyDown(object sender, KeyEventArgs e)
178+
{
179+
if (e.Key == Key.Enter)
180+
{
181+
GoToSelectedTemplate();
182+
}
183+
}
184+
185+
private void GoToSelectedTemplate()
186+
{
187+
var destFile = new FileInfo(PathBox.Text);
188+
var templateInfo = TemplateDictionary[(string)TemplateListBox.SelectedItem];
189+
File.Copy(templateInfo.Path, destFile.FullName, true);
190+
Program.MainWindow.TryLoadSourceFile(destFile.FullName, true, true, true);
191+
Close();
192+
}
175193
}
176194

177195
public class TemplateInfo

0 commit comments

Comments
 (0)