mind多个根节点的时候,切换模式的修复

This commit is contained in:
艾竹
2023-04-05 20:35:10 +08:00
parent fccac1da23
commit 5935a58541
10 changed files with 136 additions and 149 deletions

View File

@@ -24,10 +24,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
set
{
if (!SetProperty(ref _mindType, value))
{
RaisePropertyChanged(nameof(MindType));
}
SetProperty(ref _mindType, value);
}
}
@@ -40,10 +37,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
set
{
if (!SetProperty(ref _mindTheme, value))
{
RaisePropertyChanged(nameof(MindTheme));
}
SetProperty(ref _mindTheme, value);
}
}
@@ -310,24 +304,6 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
}
private ICommand _changeMindTypeCommand;
public ICommand ChangeMindTypeCommand
{
get
{
return this._changeMindTypeCommand ?? (this._changeMindTypeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedChangeMindTypeCommand));
}
}
private ICommand _changeMindThemeCommand;
public ICommand ChangeMindThemeCommand
{
get
{
return this._changeMindThemeCommand ?? (this._changeMindThemeCommand = new SimpleCommand(ExecuteEnable, this.ExecutedChangeMindThemeCommand));
}
}
private ICommand _clearThemeCommand;
public ICommand ClearThemeCommand
{
@@ -445,27 +421,42 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
#endregion
#region
private bool isSelecting;
#region
protected override void DiagramViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.DiagramViewModel_PropertyChanged(sender, e);
if (e.PropertyName == nameof(MindType))
{
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{
ChangeMindType((MindType)valuePropertyChangedEventArgs.OldValue, (MindType)valuePropertyChangedEventArgs.NewValue);
}
}
else if (e.PropertyName == nameof(MindTheme))
{
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{
ChangeMindTheme((MindTheme)valuePropertyChangedEventArgs.OldValue, (MindTheme)valuePropertyChangedEventArgs.NewValue);
}
}
}
protected override void Item_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.Item_PropertyChanged(sender, e);
if (e.PropertyName == "IsSelected")
{
isSelecting = true;
if (e is ValuePropertyChangedEventArgs valuePropertyChangedEventArgs)
{
LinkInfo = new LinkInfo(MindSelectedItem?.LinkInfo);
ImageInfo = new ImageInfo(MindSelectedItem?.ImageInfo);
Remark = MindSelectedItem?.Remark;
if (MindSelectedItem != null)
{
MindType = MindSelectedItem.MindType;
MindTheme = MindSelectedItem.MindTheme;
}
_mindType = MindSelectedItem?.MindType ?? RootItems.FirstOrDefault()?.MindType ?? MindType.Mind;
_mindTheme = MindSelectedItem?.MindTheme ?? RootItems.FirstOrDefault()?.MindTheme ?? MindTheme.SkyBlue;
RaisePropertyChanged(nameof(MindType));
RaisePropertyChanged(nameof(MindTheme));
}
isSelecting = false;
}
}
}
#endregion
@@ -711,8 +702,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
{
List<MindNode> newitems = new List<MindNode>();
DoCommandManager.DoNewCommand(this.ToString(),
() =>
{
() => {
var content = window.ContentString;
var lines = content.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries);
MindNode lastnode = node;
@@ -1087,76 +1077,79 @@ namespace AIStudio.Wpf.Mind.ViewModels
#endregion
#region
private void ExecutedChangeMindTypeCommand(object obj)
private void ChangeMindType(MindType oldMindType, MindType newMindType)
{
if (isSelecting) return;
var oldMindType = MindType;
if (obj is MindType mindType && mindType != oldMindType)
List<MindNode> roots;
if (RootItems.Count == 1)//只有一个的时候
{
var roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList();
if (roots.Count > 0)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
roots.ForEach(p => p.MindType = mindType);
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
roots.ForEach(p => p.MindType = oldMindType);
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitLayout(true); });
Items.OfType<MindNode>().ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
});
}
roots = RootItems.ToList();
}
else
{
roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList();
}
if (roots.Count > 0)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
roots.ForEach(p => p.MindType = newMindType);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitLayout(true); });
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
roots.ForEach(p => p.MindType = oldMindType);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitLayout(true); });
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.InitConnectionLayout(); });
roots.ForEach(p => p.UpdatedLayout());
});
}
}
private void ExecutedChangeMindThemeCommand(object obj)
private void ChangeMindTheme(MindTheme oldMindTheme, MindTheme newMindTheme)
{
if (isSelecting) return;
var oldmindTheme = MindTheme;
if (obj is MindTheme mindTheme && mindTheme != oldmindTheme)
List<MindNode> roots;
if (RootItems.Count == 1)//只有一个的时候
{
var roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList();
if (roots.Count > 0)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
var mindThemeModel = MindThemeHelper.GetTheme(mindTheme);
if (mindThemeModel?.Dark == true)
{
PageBackground = Colors.Black;
}
else
{
PageBackground = Colors.White;
}
MindTheme = mindTheme;
roots.ForEach(p => p.MindTheme = MindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
var mindThemeModel = MindThemeHelper.GetTheme(oldmindTheme);
if (mindThemeModel?.Dark == true)
{
PageBackground = Colors.Black;
}
else
{
PageBackground = Colors.White;
}
MindTheme = oldmindTheme;
roots.ForEach(p => p.MindTheme = MindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.UpdatedLayout());
});
}
roots = RootItems.ToList();
}
else
{
roots = MindSelectedItems.Select(p => p.RootNode).Distinct().ToList();
}
if (roots.Count > 0)
{
DoCommandManager.DoNewCommand(this.ToString(),
() => {
var mindThemeModel = MindThemeHelper.GetTheme(newMindTheme);
if (mindThemeModel?.Dark == true)
{
PageBackground = Colors.Black;
}
else
{
PageBackground = Colors.White;
}
roots.ForEach(p => p.MindTheme = newMindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.UpdatedLayout());
},
() => {
var mindThemeModel = MindThemeHelper.GetTheme(oldMindTheme);
if (mindThemeModel?.Dark == true)
{
PageBackground = Colors.Black;
}
else
{
PageBackground = Colors.White;
}
roots.ForEach(p => p.MindTheme = oldMindTheme);
roots.SelectMany(p => p.GetChildren(true)).ToList().ForEach(item => { item.ThemeChange(); });
roots.ForEach(p => p.UpdatedLayout());
});
}
}