修复日期读取错误

替换确定与取消的位置
多语言编辑器可以独立运行, 并随模组的编辑而改变
This commit is contained in:
Hakoyu 2023-11-14 20:11:23 +08:00
parent 7ffc9fcd7d
commit e6700407bd
20 changed files with 298 additions and 133 deletions

View File

@ -11,4 +11,5 @@
<c:FalseToHiddenConverter x:Key="FalseToHiddenConverter" /> <c:FalseToHiddenConverter x:Key="FalseToHiddenConverter" />
<c:EqualsConverter x:Key="EqualsConverter" /> <c:EqualsConverter x:Key="EqualsConverter" />
<c:NotEqualsConverter x:Key="NotEqualsConverter" /> <c:NotEqualsConverter x:Key="NotEqualsConverter" />
<c:NullToFalseConverter x:Key="NullToFalseConverter" />
</ResourceDictionary> </ResourceDictionary>

View File

@ -0,0 +1,18 @@
using System;
using System.Globalization;
using System.Windows.Data;
namespace VPet.ModMaker.Converters;
public class NullToFalseConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is not null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@ -46,7 +46,9 @@ public class I18nModel<T>
/// <param name="newValue"></param> /// <param name="newValue"></param>
private void CultureChanged(string oldValue, string newValue) private void CultureChanged(string oldValue, string newValue)
{ {
if (I18nDatas.TryGetValue(newValue, out var result)) if (newValue is null)
CurrentI18nData.Value = null;
else if (I18nDatas.TryGetValue(newValue, out var result))
CurrentI18nData.Value = result; CurrentI18nData.Value = result;
} }

View File

@ -366,7 +366,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
new Line("intro", DescriptionId.Value), new Line("intro", DescriptionId.Value),
new Line("authorid", AuthorID.ToString()), new Line("authorid", AuthorID.ToString()),
new Line("itemid", ItemID.ToString()), new Line("itemid", ItemID.ToString()),
new Line("cachedate", DateTime.Now.Date.ToString()) new Line("cachedate", DateTime.Now.Date.ToString("s"))
}; };
foreach (var cultureName in I18nHelper.Current.CultureNames) foreach (var cultureName in I18nHelper.Current.CultureNames)
{ {

View File

@ -98,6 +98,7 @@
<Compile Include="Converters\FalseToHiddenConverter.cs" /> <Compile Include="Converters\FalseToHiddenConverter.cs" />
<Compile Include="Converters\MediaColorToBrushConverter.cs" /> <Compile Include="Converters\MediaColorToBrushConverter.cs" />
<Compile Include="Converters\NotEqualsConverter.cs" /> <Compile Include="Converters\NotEqualsConverter.cs" />
<Compile Include="Converters\NullToFalseConverter.cs" />
<Compile Include="Converters\StringFormatConverter.cs" /> <Compile Include="Converters\StringFormatConverter.cs" />
<Compile Include="Converters\RatioMarginConverter.cs" /> <Compile Include="Converters\RatioMarginConverter.cs" />
<Compile Include="Converters\MaxConverter.cs" /> <Compile Include="Converters\MaxConverter.cs" />

View File

@ -96,14 +96,7 @@ public class ModEditWindowVM
return; return;
} }
var window = new I18nEditWindow(ModInfo.Value); var window = new I18nEditWindow(ModInfo.Value);
//foreach (var culture in I18nHelper.Current.CultureNames) window.Show();
// window.AddCulture(culture);
//if (window.IsCancel)
// return;
//I18nHelper.Current.CultureNames.Add(window.ViewModel.Culture.Value);
//if (I18nHelper.Current.CultureNames.Count == 1)
// I18nHelper.Current.CultureName.Value = window.ViewModel.Culture.Value;
window.ShowDialog();
} }
/// <summary> /// <summary>
@ -112,6 +105,7 @@ public class ModEditWindowVM
public void Close() public void Close()
{ {
ModInfo.Value.Image.Value?.StreamSource?.Close(); ModInfo.Value.Image.Value?.StreamSource?.Close();
I18nEditWindow.Instance?.Close();
} }
/// <summary> /// <summary>
@ -227,20 +221,20 @@ public class ModEditWindowVM
private void SaveTo(string path) private void SaveTo(string path)
{ {
var pending = PendingBox.Show("保存中".Translate()); var pending = PendingBox.Show("保存中".Translate());
//try try
//{ {
ModInfo.Value.SaveTo(path); ModInfo.Value.SaveTo(path);
if (string.IsNullOrWhiteSpace(ModInfo.Value.SourcePath.Value)) if (string.IsNullOrWhiteSpace(ModInfo.Value.SourcePath.Value))
ModInfo.Value.SourcePath.Value = path; ModInfo.Value.SourcePath.Value = path;
pending.Close(); pending.Close();
MessageBox.Show(ModEditWindow, "保存成功".Translate()); MessageBox.Show(ModEditWindow, "保存成功".Translate());
//} }
//catch (Exception ex) catch (Exception ex)
//{ {
// pending.Close(); pending.Close();
// MessageBox.Show("保存失败 错误信息:\n{0}".Translate(ex)); MessageBox.Show("保存失败 错误信息:\n{0}".Translate(ex));
// return; return;
//} }
} }
/// <summary> /// <summary>

View File

@ -59,21 +59,21 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
IsCancel="True"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
IsDefault="True" IsDefault="True"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
IsCancel="True"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<Grid Grid.Column="1"> <Grid Grid.Column="1">

View File

@ -289,20 +289,20 @@
Command="{Binding AddAnimeCommand}" Command="{Binding AddAnimeCommand}"
Content="{ll:Str 添加动画}" Content="{ll:Str 添加动画}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="2" Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="2"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -629,20 +629,20 @@
Command="{Binding AddAnimeCommand}" Command="{Binding AddAnimeCommand}"
Content="{ll:Str 添加动画}" Content="{ll:Str 添加动画}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="2" Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="2"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -57,19 +57,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource ThemedButtonStyle}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
</Window> </Window>

View File

@ -169,19 +169,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" /> <ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" />

View File

@ -186,19 +186,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" /> <ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" />

View File

@ -27,13 +27,14 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBox <TextBox
pu:TextBoxHelper.Watermark="{ll:Str 搜索}" pu:TextBoxHelper.Watermark="{ll:Str 搜索}"
IsEnabled="{Binding SearchTarget.Value, Converter={StaticResource NullToFalseConverter}}"
Style="{DynamicResource StandardTextBoxStyle}" Style="{DynamicResource StandardTextBoxStyle}"
Text="{Binding Search.Value, UpdateSourceTrigger=PropertyChanged}" /> Text="{Binding Search.Value, UpdateSourceTrigger=PropertyChanged}" />
<ComboBox <ComboBox
Grid.Column="1" Grid.Column="1"
ItemsSource="{Binding SearchTargets}" ItemsSource="{Binding SearchTargets}"
SelectedIndex="0" SelectedItem="{Binding SearchTarget.Value}"
SelectedItem="{Binding SearchTarget.Value}" /> Style="{DynamicResource StandardComboBoxStyle}" />
</Grid> </Grid>
<DataGrid <DataGrid
x:Name="DataGrid_Datas" x:Name="DataGrid_Datas"

View File

@ -65,6 +65,12 @@ public partial class I18nEditWindow : WindowX
{ {
//if (IsCancel) //if (IsCancel)
//ViewModel.Close(); //ViewModel.Close();
I18nHelper.Current.CultureNames.CollectionChanged -= CultureNames_CollectionChanged;
foreach (var i18nData in AllI18nDatas)
{
foreach (var data in i18nData.Value.Datas)
data.Group?.Clear();
}
try try
{ {
DataContext = null; DataContext = null;
@ -74,6 +80,7 @@ public partial class I18nEditWindow : WindowX
}; };
InitializeI18nData(model); InitializeI18nData(model);
ShowI18nDatas.Value = I18nDatas; ShowI18nDatas.Value = I18nDatas;
SearchTarget.Value = nameof(ModInfoModel.Id);
} }
public void InitializeI18nData(ModInfoModel model) public void InitializeI18nData(ModInfoModel model)
@ -83,6 +90,8 @@ public partial class I18nEditWindow : WindowX
AddCulture(culture); AddCulture(culture);
SearchTargets.Add(culture); SearchTargets.Add(culture);
} }
I18nHelper.Current.CultureNames.CollectionChanged -= CultureNames_CollectionChanged;
I18nHelper.Current.CultureNames.CollectionChanged += CultureNames_CollectionChanged;
LoadFood(model); LoadFood(model);
LoadClickText(model); LoadClickText(model);
LoadLowText(model); LoadLowText(model);
@ -90,6 +99,39 @@ public partial class I18nEditWindow : WindowX
LoadPets(model); LoadPets(model);
} }
private void CultureNames_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action is NotifyCollectionChangedAction.Add)
{
var newCulture = (string)e.NewItems[0];
AddCulture(newCulture);
SearchTargets.Add(newCulture);
foreach (var data in AllI18nDatas)
data.Value.Datas.Add(new());
}
else if (e.Action is NotifyCollectionChangedAction.Remove)
{
var oldCulture = (string)e.OldItems[0];
RemoveCulture(oldCulture);
SearchTargets.Remove(oldCulture);
foreach (var data in AllI18nDatas)
{
var value = data.Value.Datas[e.OldStartingIndex];
value.Group?.Remove(value);
data.Value.Datas.RemoveAt(e.OldStartingIndex);
}
if (SearchTarget.Value is null)
SearchTarget.Value = nameof(ModInfoModel.Id);
}
else if (e.Action is NotifyCollectionChangedAction.Replace)
{
var oldCulture = (string)e.OldItems[0];
var newCulture = (string)e.NewItems[0];
ReplaceCulture(oldCulture, newCulture);
SearchTargets[SearchTargets.IndexOf(oldCulture)] = newCulture;
}
}
private void AddData<T>( private void AddData<T>(
ObservableValue<string> id, ObservableValue<string> id,
I18nModel<T> i18nModel, I18nModel<T> i18nModel,
@ -97,7 +139,7 @@ public partial class I18nEditWindow : WindowX
) )
where T : class, new() where T : class, new()
{ {
if (AllData.TryGetValue(id.Value, out var outData)) if (AllI18nDatas.TryGetValue(id.Value, out var outData))
{ {
foreach (var culture in I18nHelper.Current.CultureNames.Enumerate()) foreach (var culture in I18nHelper.Current.CultureNames.Enumerate())
{ {
@ -117,16 +159,16 @@ public partial class I18nEditWindow : WindowX
foreach (var culture in I18nHelper.Current.CultureNames) foreach (var culture in I18nHelper.Current.CultureNames)
data.Datas.Add(i18nValue(i18nModel.I18nDatas[culture])); data.Datas.Add(i18nValue(i18nModel.I18nDatas[culture]));
I18nDatas.Add(data); I18nDatas.Add(data);
AllData.Add(id.Value, data); AllI18nDatas.Add(id.Value, data);
//id.ValueChanged += IdChange; //id.ValueChanged += IdChange;
} }
} }
private void IdChange(string oldValue, string newValue) private void IdChange(string oldValue, string newValue)
{ {
var sourceData = AllData[oldValue]; var sourceData = AllI18nDatas[oldValue];
sourceData.Id.Group?.Remove(sourceData.Id); sourceData.Id.Group?.Remove(sourceData.Id);
if (AllData.TryGetValue(oldValue, out var outData)) if (AllI18nDatas.TryGetValue(oldValue, out var outData))
{ {
foreach (var culture in I18nHelper.Current.CultureNames.Enumerate()) foreach (var culture in I18nHelper.Current.CultureNames.Enumerate())
{ {
@ -140,8 +182,8 @@ public partial class I18nEditWindow : WindowX
else else
{ {
sourceData.Id.Value = newValue; sourceData.Id.Value = newValue;
AllData.Remove(oldValue); AllI18nDatas.Remove(oldValue);
AllData.Add(newValue, sourceData); AllI18nDatas.Add(newValue, sourceData);
} }
} }
@ -152,7 +194,7 @@ public partial class I18nEditWindow : WindowX
) )
where T : class, new() where T : class, new()
{ {
var data = AllData[id.Value]; var data = AllI18nDatas[id.Value];
foreach (var culture in I18nHelper.Current.CultureNames.Enumerate()) foreach (var culture in I18nHelper.Current.CultureNames.Enumerate())
{ {
if (data.Datas[culture.Index].Group is ObservableValueGroup<string> group) if (data.Datas[culture.Index].Group is ObservableValueGroup<string> group)
@ -167,7 +209,7 @@ public partial class I18nEditWindow : WindowX
else else
{ {
I18nDatas.Remove(data); I18nDatas.Remove(data);
AllData.Remove(id.Value); AllI18nDatas.Remove(id.Value);
return; return;
} }
} }
@ -180,7 +222,7 @@ public partial class I18nEditWindow : WindowX
) )
where T : class, new() where T : class, new()
{ {
var data = AllData[id.Value]; var data = AllI18nDatas[id.Value];
foreach (var culture in I18nHelper.Current.CultureNames.Enumerate()) foreach (var culture in I18nHelper.Current.CultureNames.Enumerate())
{ {
var oldValue = data.Datas[culture.Index]; var oldValue = data.Datas[culture.Index];
@ -205,22 +247,22 @@ public partial class I18nEditWindow : WindowX
{ {
if (e.Action is NotifyCollectionChangedAction.Add) if (e.Action is NotifyCollectionChangedAction.Add)
{ {
var newFood = (FoodModel)e.NewItems[0]; var newModel = (FoodModel)e.NewItems[0];
AddData(newFood.Id, newFood, (m) => m.Name); AddData(newModel.Id, newModel, (m) => m.Name);
AddData(newFood.DescriptionId, newFood, (m) => m.Description); AddData(newModel.DescriptionId, newModel, (m) => m.Description);
} }
else if (e.Action is NotifyCollectionChangedAction.Remove) else if (e.Action is NotifyCollectionChangedAction.Remove)
{ {
var oldFood = (FoodModel)e.OldItems[0]; var oldModel = (FoodModel)e.OldItems[0];
RemoveData(oldFood.Id, oldFood, (m) => m.Name); RemoveData(oldModel.Id, oldModel, (m) => m.Name);
RemoveData(oldFood.DescriptionId, oldFood, (m) => m.Description); RemoveData(oldModel.DescriptionId, oldModel, (m) => m.Description);
} }
else if (e.Action is NotifyCollectionChangedAction.Replace) else if (e.Action is NotifyCollectionChangedAction.Replace)
{ {
var newFood = (FoodModel)e.NewItems[0]; var newModel = (FoodModel)e.NewItems[0];
var oldFood = (FoodModel)e.OldItems[0]; var oldModel = (FoodModel)e.OldItems[0];
ReplaceData(newFood.Id, newFood, (m) => m.Name); ReplaceData(newModel.Id, newModel, (m) => m.Name);
ReplaceData(newFood.DescriptionId, newFood, (m) => m.Description); ReplaceData(newModel.DescriptionId, newModel, (m) => m.Description);
} }
}; };
} }
@ -231,6 +273,25 @@ public partial class I18nEditWindow : WindowX
{ {
AddData(text.Id, text, (m) => m.Text); AddData(text.Id, text, (m) => m.Text);
} }
model.ClickTexts.CollectionChanged += (s, e) =>
{
if (e.Action is NotifyCollectionChangedAction.Add)
{
var newModel = (ClickTextModel)e.NewItems[0];
AddData(newModel.Id, newModel, (m) => m.Text);
}
else if (e.Action is NotifyCollectionChangedAction.Remove)
{
var oldModel = (ClickTextModel)e.OldItems[0];
RemoveData(oldModel.Id, oldModel, (m) => m.Text);
}
else if (e.Action is NotifyCollectionChangedAction.Replace)
{
var newModel = (ClickTextModel)e.NewItems[0];
var oldModel = (ClickTextModel)e.OldItems[0];
ReplaceData(newModel.Id, newModel, (m) => m.Text);
}
};
} }
private void LoadLowText(ModInfoModel model) private void LoadLowText(ModInfoModel model)
@ -239,6 +300,25 @@ public partial class I18nEditWindow : WindowX
{ {
AddData(text.Id, text, (m) => m.Text); AddData(text.Id, text, (m) => m.Text);
} }
model.LowTexts.CollectionChanged += (s, e) =>
{
if (e.Action is NotifyCollectionChangedAction.Add)
{
var newModel = (LowTextModel)e.NewItems[0];
AddData(newModel.Id, newModel, (m) => m.Text);
}
else if (e.Action is NotifyCollectionChangedAction.Remove)
{
var oldModel = (LowTextModel)e.OldItems[0];
RemoveData(oldModel.Id, oldModel, (m) => m.Text);
}
else if (e.Action is NotifyCollectionChangedAction.Replace)
{
var newModel = (LowTextModel)e.NewItems[0];
var oldModel = (LowTextModel)e.OldItems[0];
ReplaceData(newModel.Id, newModel, (m) => m.Text);
}
};
} }
private void LoadSelectText(ModInfoModel model) private void LoadSelectText(ModInfoModel model)
@ -248,6 +328,28 @@ public partial class I18nEditWindow : WindowX
AddData(text.Id, text, (m) => m.Text); AddData(text.Id, text, (m) => m.Text);
AddData(text.ChooseId, text, (m) => m.Choose); AddData(text.ChooseId, text, (m) => m.Choose);
} }
model.SelectTexts.CollectionChanged += (s, e) =>
{
if (e.Action is NotifyCollectionChangedAction.Add)
{
var newModel = (SelectTextModel)e.NewItems[0];
AddData(newModel.Id, newModel, (m) => m.Text);
AddData(newModel.ChooseId, newModel, (m) => m.Choose);
}
else if (e.Action is NotifyCollectionChangedAction.Remove)
{
var oldModel = (SelectTextModel)e.OldItems[0];
RemoveData(oldModel.Id, oldModel, (m) => m.Text);
RemoveData(oldModel.ChooseId, oldModel, (m) => m.Choose);
}
else if (e.Action is NotifyCollectionChangedAction.Replace)
{
var newModel = (SelectTextModel)e.NewItems[0];
var oldModel = (SelectTextModel)e.OldItems[0];
ReplaceData(newModel.Id, newModel, (m) => m.Text);
ReplaceData(newModel.ChooseId, newModel, (m) => m.Choose);
}
};
} }
private void LoadPets(ModInfoModel model) private void LoadPets(ModInfoModel model)
@ -259,11 +361,45 @@ public partial class I18nEditWindow : WindowX
AddData(pet.Id, pet, (m) => m.Name); AddData(pet.Id, pet, (m) => m.Name);
AddData(pet.PetNameId, pet, (m) => m.PetName); AddData(pet.PetNameId, pet, (m) => m.PetName);
AddData(pet.DescriptionId, pet, (m) => m.Description); AddData(pet.DescriptionId, pet, (m) => m.Description);
foreach (var work in pet.Works)
AddData(work.Id, work, (m) => m.Name);
} }
model.Pets.CollectionChanged += (s, e) =>
{
if (e.Action is NotifyCollectionChangedAction.Add)
{
var newModel = (PetModel)e.NewItems[0];
AddData(newModel.Id, newModel, (m) => m.Name);
AddData(newModel.DescriptionId, newModel, (m) => m.Description);
foreach (var work in newModel.Works)
AddData(work.Id, work, (m) => m.Name);
}
else if (e.Action is NotifyCollectionChangedAction.Remove)
{
var oldModel = (PetModel)e.OldItems[0];
RemoveData(oldModel.Id, oldModel, (m) => m.Name);
RemoveData(oldModel.DescriptionId, oldModel, (m) => m.Description);
foreach (var work in oldModel.Works)
RemoveData(work.Id, work, (m) => m.Name);
}
else if (e.Action is NotifyCollectionChangedAction.Replace)
{
var newModel = (PetModel)e.NewItems[0];
var oldModel = (PetModel)e.OldItems[0];
ReplaceData(newModel.Id, newModel, (m) => m.Name);
ReplaceData(newModel.DescriptionId, newModel, (m) => m.Description);
foreach (var work in newModel.Works)
ReplaceData(work.Id, work, (m) => m.Name);
}
};
} }
private readonly Dictionary<string, DataGridTextColumn> _dataGridI18nColumns = new(); private readonly Dictionary<string, DataGridTextColumn> _dataGridI18nColumns = new();
public Dictionary<string, I18nData> AllData { get; } = new();
/// <summary>
/// (Id, I18nData)
/// </summary>
public Dictionary<string, I18nData> AllI18nDatas { get; } = new();
public ObservableCollection<I18nData> I18nDatas { get; } = new(); public ObservableCollection<I18nData> I18nDatas { get; } = new();
public ObservableValue<ObservableCollection<I18nData>> ShowI18nDatas { get; } = new(); public ObservableValue<ObservableCollection<I18nData>> ShowI18nDatas { get; } = new();
@ -312,6 +448,13 @@ public partial class I18nEditWindow : WindowX
{ {
DataGrid_Datas.Columns.Remove(_dataGridI18nColumns[culture]); DataGrid_Datas.Columns.Remove(_dataGridI18nColumns[culture]);
_dataGridI18nColumns.Remove(culture); _dataGridI18nColumns.Remove(culture);
for (var i = 1; i < DataGrid_Datas.Columns.Count; i++)
{
var column = (DataGridTextColumn)DataGrid_Datas.Columns[i];
var dataPath = string.Format(ValueBindingFormat, i - 1);
column.Binding = new Binding(dataPath) { Mode = BindingMode.TwoWay };
column.SortMemberPath = dataPath;
}
} }
/// <summary> /// <summary>
@ -323,16 +466,11 @@ public partial class I18nEditWindow : WindowX
{ {
//if (_dataGridI18nColumns.ContainsKey(newCultureName)) //if (_dataGridI18nColumns.ContainsKey(newCultureName))
// throw new(); // throw new();
var dataPath = string.Format(
ValueBindingFormat,
I18nHelper.Current.CultureNames.IndexOf(newCulture)
);
var column = _dataGridI18nColumns[oldCulture]; var column = _dataGridI18nColumns[oldCulture];
column.Header = newCulture; column.Header = newCulture;
column.Binding = new Binding(dataPath) { Mode = BindingMode.TwoWay };
column.SortMemberPath = dataPath;
_dataGridI18nColumns.Remove(oldCulture); _dataGridI18nColumns.Remove(oldCulture);
_dataGridI18nColumns.Add(newCulture, column); _dataGridI18nColumns.Add(newCulture, column);
} }
#endregion #endregion
} }

View File

@ -88,19 +88,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" /> <ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" />

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -50,6 +51,7 @@ public partial class ModEditWindow : Window
{ {
InitializeComponent(); InitializeComponent();
DataContext = new ModEditWindowVM(this); DataContext = new ModEditWindowVM(this);
Closing += ModEditWindow_Closing;
Closed += ModEditWindow_Closed; Closed += ModEditWindow_Closed;
Loaded += ModEditWindow_Loaded; Loaded += ModEditWindow_Loaded;
} }
@ -66,6 +68,14 @@ public partial class ModEditWindow : Window
} }
} }
private void ModEditWindow_Closing(object sender, CancelEventArgs e)
{
if (
MessageBox.Show("确认退出吗?".Translate(), "", MessageBoxButton.YesNo) is MessageBoxResult.No
)
e.Cancel = true;
}
private void ModEditWindow_Closed(object sender, EventArgs e) private void ModEditWindow_Closed(object sender, EventArgs e)
{ {
ViewModel.Close(); ViewModel.Close();

View File

@ -278,19 +278,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
</Grid> </Grid>

View File

@ -809,19 +809,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" /> <ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" />

View File

@ -158,19 +158,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" /> <ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" />

View File

@ -103,7 +103,7 @@
Command="{Binding AddImageCommand}" Command="{Binding AddImageCommand}"
Content="{ll:Str 添加测试图片}"> Content="{ll:Str 添加测试图片}">
<Button.Style> <Button.Style>
<Style BasedOn="{StaticResource {x:Type Button}}" TargetType="Button"> <Style BasedOn="{StaticResource ThemedButtonStyle}" TargetType="Button">
<Setter Property="Visibility" Value="Hidden" /> <Setter Property="Visibility" Value="Hidden" />
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding Image.Value}" Value="{x:Null}"> <DataTrigger Binding="{Binding Image.Value}" Value="{x:Null}">
@ -290,19 +290,19 @@
<ColumnDefinition /> <ColumnDefinition />
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button
x:Name="Button_Cancel"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
<Button <Button
x:Name="Button_Yes" x:Name="Button_Yes"
Grid.Column="1"
Margin="10" Margin="10"
Click="Button_Yes_Click" Click="Button_Yes_Click"
Content="{ll:Str 确定}" Content="{ll:Str 确定}"
Style="{DynamicResource ThemedButtonStyle}" /> Style="{DynamicResource ThemedButtonStyle}" />
<Button
x:Name="Button_Cancel"
Grid.Column="1"
Margin="10"
Click="Button_Cancel_Click"
Content="{ll:Str 取消}"
Style="{DynamicResource Button_Cancel}" />
</Grid> </Grid>
</Grid> </Grid>
<ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" /> <ListBox Grid.Column="2" Template="{StaticResource ListBox_ShowLangs}" />