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

Commit 99d9572

Browse files
committed
polished the new template system
1 parent a94b11c commit 99d9572

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

UI/Windows/NewFileWindow.xaml.cs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ private void TemplateListBox_SelectionChanged(object sender, SelectionChangedEve
136136
{
137137
PreviewBox.editor.Text = $"/* \n\n{ex.Message}\n\n{ex.StackTrace}\n\n*/";
138138
}
139-
139+
140140
}
141141

142142
private void SaveButton_Click(object sender, RoutedEventArgs e)
143143
{
144-
if (TemplateEditMode)
144+
if (TemplateEditMode || TemplateNewMode)
145145
{
146146
var tempName = TbxRenameTemplate.Text;
147147
if (!IsValidTemplate(ref tempName, out var message))
@@ -152,39 +152,22 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
152152
return;
153153
}
154154

155-
TemplateEditMode = false;
156-
157155
foreach (ListBoxItem item in TemplateListBox.Items)
158156
{
159157
item.IsEnabled = true;
160158
}
161159

162160
PreviewBox.editor.IsReadOnly = true;
163-
SaveTemplate(tempName);
164-
HideVisuals();
165-
return;
166-
}
167161

168-
if (TemplateNewMode)
169-
{
170-
var tempName = TbxRenameTemplate.Text;
171-
if (!IsValidTemplate(ref tempName, out var message))
162+
if (TemplateEditMode)
172163
{
173-
TbxRenameTemplate.BorderBrush = new SolidColorBrush(Colors.Red);
174-
LblError.Visibility = Visibility.Visible;
175-
LblError.Content = message;
176-
return;
164+
SaveTemplate(tempName);
177165
}
178-
179-
TemplateNewMode = false;
180-
181-
foreach (ListBoxItem item in TemplateListBox.Items)
166+
else
182167
{
183-
item.IsEnabled = true;
168+
CreateTemplate(tempName);
184169
}
185170

186-
PreviewBox.editor.IsReadOnly = true;
187-
CreateTemplate(tempName);
188171
HideVisuals();
189172
return;
190173
}
@@ -193,11 +176,22 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
193176

194177
private void CancelButton_Click(object sender, RoutedEventArgs e)
195178
{
196-
if (TemplateEditMode || TemplateNewMode)
179+
if (TemplateEditMode)
197180
{
198-
HideVisuals(TemplateNewMode);
181+
HideVisuals();
199182
TemplateEditMode = false;
183+
PreviewBox.editor.IsReadOnly = true;
184+
var tInfo = (TemplateListBox.SelectedItem as ListBoxItem).Tag as TemplateInfo;
185+
PreviewBox.editor.Text = File.ReadAllText(tInfo.Path);
186+
PathBox.Text = tInfo.Path;
187+
}
188+
else if (TemplateNewMode)
189+
{
190+
HideVisuals();
200191
TemplateNewMode = false;
192+
PreviewBox.editor.IsReadOnly = true;
193+
TemplateListBox.SelectedIndex = 0;
194+
TemplateListBox.Items.RemoveAt(TemplateListBox.Items.Count - 1);
201195
}
202196
else
203197
{
@@ -472,6 +466,7 @@ private void CreateTemplate(string name)
472466
Path = newFilePath,
473467
}
474468
};
469+
lbi.MouseDoubleClick += TemplateListItem_MouseDoubleClick;
475470
TemplateListBox.Items[TemplateListBox.Items.Count - 1] = lbi;
476471
}
477472

@@ -489,7 +484,7 @@ private void ShowVisuals(bool isNewTemplate)
489484
}
490485
}
491486

492-
private void HideVisuals(bool canceledFromNewTemplate = false)
487+
private void HideVisuals()
493488
{
494489
PreviewBlock.Text = $"{Program.Translations.GetLanguage("Preview")}:";
495490
TbxRenameTemplate.Visibility = Visibility.Collapsed;
@@ -501,11 +496,6 @@ private void HideVisuals(bool canceledFromNewTemplate = false)
501496
{
502497
item.IsEnabled = true;
503498
}
504-
if (canceledFromNewTemplate)
505-
{
506-
TemplateListBox.SelectedIndex = 0;
507-
TemplateListBox.Items.RemoveAt(TemplateListBox.Items.Count - 1);
508-
}
509499
}
510500

511501
private bool IsValidTemplate(ref string name, out string message)
@@ -538,6 +528,6 @@ private bool IsValidTemplate(ref string name, out string message)
538528
return true;
539529
}
540530
#endregion
541-
531+
542532
}
543533
}

0 commit comments

Comments
 (0)