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

@@ -2171,17 +2171,12 @@
<Fluent:SplitButton.LargeIcon>
<iconPacks:PackIconRemixIcon Kind="MindMap" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Fluent:SplitButton.LargeIcon>
<ListBox x:Name="mindtype" Width="140" dd:EnumHelper.Enum="{x:Type dd:MindType}" SelectedItem="{Binding PageViewModel.DiagramViewModel.MindType,Mode=OneWay}">
<ListBox x:Name="mindtype" Width="140" dd:EnumHelper.Enum="{x:Type dd:MindType}" SelectedItem="{Binding PageViewModel.DiagramViewModel.MindType}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding .,Converter={StaticResource EnumDescriptionConverter}}" />
</DataTemplate>
</ListBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding PageViewModel.DiagramViewModel.ChangeMindTypeCommand}" CommandParameter="{Binding ElementName=mindtype,Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<Fluent:SplitButton.ToolTip>
<Fluent:ScreenTip Title="MindType"
@@ -2193,7 +2188,7 @@
<Fluent:SplitButton.LargeIcon>
<iconPacks:PackIconUnicons Kind="Palette" Foreground="{Binding PageViewModel.DiagramViewModel.MindTheme,Converter={StaticResource MindThemeFillBrushConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Fluent:SplitButton.LargeIcon>
<ListBox x:Name="mindtheme" dd:EnumHelper.Enum="{x:Type dd:MindTheme}" SelectedItem="{Binding PageViewModel.DiagramViewModel.MindTheme,Mode=OneWay}">
<ListBox x:Name="mindtheme" dd:EnumHelper.Enum="{x:Type dd:MindTheme}" SelectedItem="{Binding PageViewModel.DiagramViewModel.MindTheme}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2"/>
@@ -2206,11 +2201,6 @@
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding PageViewModel.DiagramViewModel.ChangeMindThemeCommand}" CommandParameter="{Binding ElementName=mindtheme,Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<Fluent:SplitButton.ToolTip>
<Fluent:ScreenTip Title="Theme"

View File

@@ -41,8 +41,8 @@ namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
{
this.ItemWidth = 150;
this.ItemHeight = 80;
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top));
connectors.Add(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom));
AddConnector(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Top));
AddConnector(new FullyCreatedConnectorInfo(this, ConnectorOrientation.Bottom));
}
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)

View File

@@ -207,7 +207,7 @@
<ControlTemplate x:Key="ConnectorDecoratorTemplate"
TargetType="{x:Type Control}">
<Grid Margin="-5">
<Grid Margin="{Binding ConnectorMargin}">
<dd:Connector
Content="{Binding LeftConnector}"
Cursor="Cross"

View File

@@ -40,10 +40,10 @@ namespace AIStudio.Wpf.DiagramDesigner
protected override void InitNew()
{
connectors.Add(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Top));
connectors.Add(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
connectors.Add(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Left));
connectors.Add(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Right));
AddConnector(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Top));
AddConnector(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Bottom));
AddConnector(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Left));
AddConnector(new FullyCreatedConnectorInfo(this.Root, this, ConnectorOrientation.Right));
}
protected override void LoadDesignerItemViewModel(SelectableItemBase designerbase)
@@ -221,7 +221,7 @@ namespace AIStudio.Wpf.DiagramDesigner
RaisePropertyChanged(nameof(PhysicalItemHeight));
}
}
}
}
[DisplayName("ItemWidth(mm)")]
[Browsable(true)]
@@ -265,6 +265,19 @@ namespace AIStudio.Wpf.DiagramDesigner
}
}
private double _connectorMargin = -4;
public double ConnectorMargin
{
get
{
return _connectorMargin;
}
set
{
SetProperty(ref _connectorMargin, value);
}
}
private bool _showConnectors = false;
public bool ShowConnectors
{
@@ -573,6 +586,7 @@ namespace AIStudio.Wpf.DiagramDesigner
if (!connectors.Contains(connector))
{
connectors.Add(connector);
ConnectorMargin = 0 - connector.ConnectorWidth / 2;
}
}

View File

@@ -1050,10 +1050,12 @@ namespace AIStudio.Wpf.DiagramDesigner
{
Mediator.Instance.Register(this);
Items.CollectionChanged += Items_CollectionChanged;
var zoomValueChangedSubscription = WhenPropertyChanged.Where(o => o.ToString() == nameof(ZoomValue)).Throttle(TimeSpan.FromMilliseconds(100)).Subscribe(OnZoomValueChanged);//Sample
this.PropertyChanged += DiagramViewModel_PropertyChanged;
BuildMenuOptions();
}
public DiagramViewModel(DiagramItem diagramItem) : this()
{
DiagramType = diagramItem.DiagramType;
@@ -1161,6 +1163,11 @@ namespace AIStudio.Wpf.DiagramDesigner
#endregion
#region
protected virtual void DiagramViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
}
private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)

View File

@@ -416,32 +416,22 @@
</TabItem>
<TabItem Header="外观" Height="30" Width="50">
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="mindtype" dd:EnumHelper.Enum="{x:Type models:MindType}" SelectedItem="{Binding MindType, Mode=OneWay}" Style="{StaticResource FlatComboBoxStyle}">
<ComboBox x:Name="mindtype" dd:EnumHelper.Enum="{x:Type models:MindType}" SelectedItem="{Binding MindType}" Style="{StaticResource FlatComboBoxStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding .,Converter={StaticResource EnumDescriptionConverter}}" VerticalAlignment="Center" />
</DataTemplate>
</ComboBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ChangeMindTypeCommand}" CommandParameter="{Binding ElementName=mindtype,Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Line Margin="2,0" X1="0" Y1="0" X2="0" Y2="100" StrokeDashArray="1" Stroke="Gray" StrokeThickness="1"></Line>
<ComboBox x:Name="mindtheme" dd:EnumHelper.Enum="{x:Type models:MindTheme}" SelectedItem="{Binding MindTheme, Mode=OneWay}" Style="{StaticResource FlatComboBox2ColumnStyle}">
<ComboBox x:Name="mindtheme" dd:EnumHelper.Enum="{x:Type models:MindTheme}" SelectedItem="{Binding MindTheme}" Style="{StaticResource FlatComboBox2ColumnStyle}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Border CornerRadius="3" Background="{Binding .,Converter={StaticResource MindThemeFillBrushConverter}}" Padding="5">
<TextBlock Foreground="{Binding .,Converter={StaticResource MindThemeFontBrushConverter}}" Text="{Binding .,Converter={StaticResource EnumDescriptionConverter}}" VerticalAlignment="Center" />
</Border>
</Border>
</DataTemplate>
</ComboBox.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ChangeMindThemeCommand}" CommandParameter="{Binding ElementName=mindtheme,Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
<Line Margin="2,0" X1="0" Y1="0" X2="0" Y2="100" StrokeDashArray="1" Stroke="Gray" StrokeThickness="1"></Line>
<Button Style="{StaticResource FlatButtonStyle}" Command="{Binding ResetLayoutCommand}">

View File

@@ -40,7 +40,7 @@
</Style>
<ControlTemplate x:Key="MindNodeLevelStyle" TargetType="{x:Type ContentControl}">
<Grid>
<Grid>
<Grid.ContextMenu>
<ContextMenu ItemsSource="{Binding MenuOptions}">
<ContextMenu.ItemContainerStyle>
@@ -57,12 +57,12 @@
</ContextMenu>
</Grid.ContextMenu>
<Grid>
<Grid>
<Border BorderThickness="{Binding BorderThickness}"
BorderBrush="{Binding ColorViewModel.LineColor,Converter={StaticResource ColorBrushConverter}}"
Background="{Binding ColorViewModel.FillColor,Converter={StaticResource ColorBrushConverter}}"
CornerRadius="{Binding CornerRadius}"
IsHitTestVisible="False">
IsHitTestVisible="False">
</Border>
<Grid>
<Grid.RowDefinitions>

View File

@@ -108,15 +108,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
ICommand RemoveTagCommand
{
get;
}
ICommand ChangeMindTypeCommand
{
get;
}
ICommand ChangeMindThemeCommand
{
get;
}
}
ICommand ClearThemeCommand
{
get;

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());
});
}
}

View File

@@ -77,6 +77,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
EnabledForConnection = false;
AlwayForResized = true;
CustomText = true;
IsInnerConnector = true;
AddChildCommand = (Root as IMindDiagramViewModel)?.AddChildCommand;
AddParentCommand = (Root as IMindDiagramViewModel)?.AddParentCommand;
@@ -100,8 +101,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
var layout = TypeHelper.GetType(this.MindType.ToString() + "Layout");
MindLayout = layout != null ? (System.Activator.CreateInstance(layout) as IMindLayout) : new MindLayout();
this.PropertyChanged -= this.Item_PropertyChanged;
IsInnerConnector = true;
this.PropertyChanged -= this.Item_PropertyChanged;
MindLayout.Appearance(this, MindTheme, initAppearance);
this.PropertyChanged += this.Item_PropertyChanged;
}
@@ -348,6 +348,7 @@ namespace AIStudio.Wpf.Mind.ViewModels
}
private string _remark;
[Browsable(true)]
public string Remark
{
get