Skip to content

Commit 6c445ac

Browse files
committed
3-20 first release!
1 parent c29339d commit 6c445ac

File tree

12 files changed

+213
-119
lines changed

12 files changed

+213
-119
lines changed

YDock/DragManager.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ private void AfterDrag()
196196
_isDragOverRoot = false;
197197
BaseDropPanel.ActiveVisual = null;
198198
BaseDropPanel.CurrentRect = null;
199+
CommandManager.InvalidateRequerySuggested();
199200
}
200201
#endregion
201202

@@ -216,9 +217,11 @@ private void _InitDragItem()
216217
var _parent = _layoutGroup.View.DockViewParent as LayoutGroupPanel;
217218
var _mode = _parent.Direction == Direction.LeftToRight ? AttachMode.Left : AttachMode.Top;
218219
if (_parent.Direction == Direction.None)
219-
_mode = AttachMode.None;
220+
_mode = AttachMode.None;
220221
var _index = _parent.IndexOf(_layoutGroup.View);
221-
_layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent, _index, _mode);
222+
if (_parent.Children.Count - 1 > _index)
223+
_layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent.Children[_index + 2] as INotifyDisposable, _index, _mode);
224+
else _layoutGroup.AttachObj = new AttachObject(_layoutGroup, _parent.Children[_index - 2] as INotifyDisposable, _index, _mode);
222225
#endregion
223226

224227
//这里移动的一定是AnchorSideGroup,故将其从父级LayoutGroupPanel移走,但不Dispose留着构造浮动窗口
@@ -380,7 +383,9 @@ private void _InitDragItem()
380383
if (_parent.Direction == Direction.None)
381384
_mode = AttachMode.None;
382385
var _index = _parent.IndexOf(group.View);
383-
group.AttachObj = new AttachObject(group, _parent, _index, _mode);
386+
if (_parent.Children.Count - 1 > _index)
387+
group.AttachObj = new AttachObject(group, _parent.Children[_index + 2] as INotifyDisposable, _index, _mode);
388+
else group.AttachObj = new AttachObject(group, _parent.Children[_index - 2] as INotifyDisposable, _index, _mode);
384389
#endregion
385390

386391
//这里移动的一定是AnchorSideGroup,故将其从父级LayoutGroupPanel移走,但不Dispose留着构造浮动窗口

YDock/Model/Element/DockElement.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,14 @@ public void ToDock()
331331
if (!CanDock) return;
332332
if (_container != null)
333333
{
334-
//默认向下停靠
335-
if (Side == DockSide.None)
336-
Side = DockSide.Bottom;
337-
338334
Mode = DockMode.Normal;
339-
340335
var dockManager = DockManager;
341336
var group = _container as LayoutGroup;
342-
if (group.AttachObj != null)
343-
group.AttachObj.AttachTo();
344-
else
337+
if (group.AttachObj == null || !group.AttachObj.AttachTo())
345338
{
339+
//默认向下停靠
340+
if (Side == DockSide.None)
341+
Side = DockSide.Bottom;
346342
_container.Detach(this);
347343
_container = null;
348344
_ToRoot(dockManager);

YDock/Model/Layout/AttachObject.cs

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,77 @@ internal INotifyDisposable Parent
3232

3333
private AttachMode _mode;
3434

35-
internal void AttachTo()
35+
internal bool AttachTo()
3636
{
37-
if (_parent is AnchorSideGroupControl)
37+
if (_parent is BaseGroupControl)
3838
{
39-
var _group = (_parent as AnchorSideGroupControl).Model as LayoutGroup;
40-
var _children = _relativeObj.Children.ToList();
41-
_children.Reverse();
42-
_relativeObj.Dispose();
43-
foreach (var child in _children)
44-
_group.Attach(child, _index);
39+
if (_mode == AttachMode.None)
40+
{
41+
var _group = (_parent as BaseGroupControl).Model as ILayoutGroup;
42+
var _children = _relativeObj.Children.ToList();
43+
_children.Reverse();
44+
_relativeObj.Dispose();
45+
foreach (var child in _children)
46+
_group.Attach(child, Math.Min(_index, _group.Children.Count() - 1));
47+
}
48+
else
49+
{
50+
var targetctrl = _parent as AnchorSideGroupControl;
51+
if (targetctrl.DockViewParent != null)
52+
{
53+
if (_relativeObj.View == null)
54+
new AnchorSideGroupControl(_relativeObj);
55+
var ctrl = _relativeObj.View as AnchorSideGroupControl;
56+
if (ctrl.TryDeatchFromParent(false))
57+
{
58+
switch (_mode)
59+
{
60+
case AttachMode.Left:
61+
targetctrl.AttachTo(targetctrl.DockViewParent as LayoutGroupPanel, ctrl, DropMode.Left);
62+
break;
63+
case AttachMode.Top:
64+
targetctrl.AttachTo(targetctrl.DockViewParent as LayoutGroupPanel, ctrl, DropMode.Top);
65+
break;
66+
case AttachMode.Right:
67+
targetctrl.AttachTo(targetctrl.DockViewParent as LayoutGroupPanel, ctrl, DropMode.Right);
68+
break;
69+
case AttachMode.Bottom:
70+
targetctrl.AttachTo(targetctrl.DockViewParent as LayoutGroupPanel, ctrl, DropMode.Bottom);
71+
break;
72+
}
73+
}
74+
else return false;
75+
}
76+
else return false;
77+
Dispose();
78+
}
4579
}
4680
if (_parent is LayoutGroupPanel)
4781
{
48-
var panel = _parent as LayoutGroupPanel;
4982
if (_relativeObj.View == null)
5083
new AnchorSideGroupControl(_relativeObj);
5184
var ctrl = _relativeObj.View as AnchorSideGroupControl;
52-
if (ctrl.TryDeatchFromParent(false))
53-
panel.AttachChild(_relativeObj.View, _mode, _index);
85+
if (_mode == AttachMode.None)
86+
{
87+
var panel = _parent as LayoutGroupPanel;
88+
if (ctrl.TryDeatchFromParent(false))
89+
panel.AttachChild(_relativeObj.View, _mode, Math.Min(_index, panel.Children.Count - 1));
90+
else return false;
91+
}
92+
else
93+
{
94+
var panel = (_parent as LayoutGroupPanel).DockViewParent as LayoutGroupPanel;
95+
if (panel != null)
96+
{
97+
if (ctrl.TryDeatchFromParent(false))
98+
panel.AttachChild(_relativeObj.View, _mode, Math.Min(_index, panel.Children.Count - 1));
99+
else return false;
100+
}
101+
else return false;
102+
}
54103
Dispose();
55104
}
105+
return true;
56106
}
57107

58108
private void OnDisposed(object sender, EventArgs e)

YDock/Model/Layout/BaseLayoutGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void MoveTo(int src, int des)
151151

152152
public void RaisePropertyChanged(string propertyName)
153153
{
154-
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
154+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
155155
}
156156

157157
public virtual void SetActive(IDockElement element)

YDock/Model/Layout/LayoutGroup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ public override void SetActive(IDockElement element)
6363
(_view as TabControl).SelectedIndex = IndexOf(element);
6464
else//_view不存在则要创建新的_view
6565
{
66-
if (_attachObj != null)
67-
_attachObj.AttachTo();
68-
else
66+
if (_attachObj == null || !_attachObj.AttachTo())
6967
{
7068
if (this is LayoutDocumentGroup)
7169
{

YDock/Themes/generic.xaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -963,16 +963,18 @@
963963
<RowDefinition Height="32"/>
964964
<RowDefinition Height="*"/>
965965
</Grid.RowDefinitions>
966-
<StackPanel x:Name="Header_Title_Image" Orientation="Horizontal">
967-
<Image Source="{Binding RelativeSource={RelativeSource TemplatedParent},Path=DockManager.DockImageSource}"/>
968-
<TextBlock Margin="5,0,0,0" VerticalAlignment="Center" FontSize="12" TextTrimming="CharacterEllipsis" Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=DockManager.DockTitle}"/>
969-
</StackPanel>
970-
<StackPanel x:Name="HeaderPanel" FlowDirection="RightToLeft" Orientation="Horizontal">
971-
<Button Height="24" Style="{StaticResource Window_Close}" Command="{x:Static command:GlobalCommands.CloseCommand}"/>
972-
<Button x:Name="Maximize_Btn" Height="24" Style="{StaticResource Window_Maximize}" Command="{x:Static command:GlobalCommands.MaximizeCommand}"/>
973-
<Button x:Name="Restore_Btn" Height="24" Visibility="Collapsed" Style="{StaticResource Window_Restore}" Command="{x:Static command:GlobalCommands.RestoreCommand}"/>
974-
<Button Style="{StaticResource Window_Minimize}" Command="{x:Static command:GlobalCommands.MinimizeCommand}"/>
975-
</StackPanel>
966+
<DockPanel x:Name="PART_Header">
967+
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal">
968+
<Image Source="{Binding RelativeSource={RelativeSource TemplatedParent},Path=DockManager.DockImageSource}"/>
969+
<TextBlock Margin="5,0,0,0" VerticalAlignment="Center" FontSize="12" TextTrimming="CharacterEllipsis" Text="{Binding RelativeSource={RelativeSource TemplatedParent},Path=DockManager.DockTitle}"/>
970+
</StackPanel>
971+
<StackPanel DockPanel.Dock="Right" FlowDirection="RightToLeft" Orientation="Horizontal">
972+
<Button Height="24" Style="{StaticResource Window_Close}" Command="{x:Static command:GlobalCommands.CloseCommand}"/>
973+
<Button x:Name="Maximize_Btn" Height="24" Style="{StaticResource Window_Maximize}" Command="{x:Static command:GlobalCommands.MaximizeCommand}"/>
974+
<Button x:Name="Restore_Btn" Height="24" Visibility="Collapsed" Style="{StaticResource Window_Restore}" Command="{x:Static command:GlobalCommands.RestoreCommand}"/>
975+
<Button Style="{StaticResource Window_Minimize}" Command="{x:Static command:GlobalCommands.MinimizeCommand}"/>
976+
</StackPanel>
977+
</DockPanel>
976978
<AdornerDecorator Grid.Row="1">
977979
<Border Padding="6,0,6,6">
978980
<ContentPresenter Content="{TemplateBinding Content}"/>

YDock/View/Control/AnchorSideGroupControl.cs

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -63,81 +63,86 @@ public override void OnDrop(DragItem source)
6363
}
6464
else panel = DockViewParent as LayoutGroupPanel;
6565

66-
int index = panel.Children.IndexOf(this);
67-
switch (DropMode)
68-
{
69-
case DropMode.Left:
70-
if (panel.Direction == Direction.UpToDown)
66+
AttachTo(panel, child, DropMode);
67+
}
68+
else base.OnDrop(source);
69+
(source.RelativeObj as BaseFloatWindow).Close();
70+
}
71+
72+
public void AttachTo(LayoutGroupPanel panel, IDockView source, DropMode mode)
73+
{
74+
int index = panel.Children.IndexOf(this);
75+
switch (mode)
76+
{
77+
case DropMode.Left:
78+
if (panel.Direction == Direction.UpToDown)
79+
{
80+
var _subpanel = new LayoutGroupPanel(Model.Side)
7181
{
72-
var _subpanel = new LayoutGroupPanel(Model.Side)
73-
{
74-
Direction = Direction.LeftToRight,
75-
DesiredWidth = ActualWidth,
76-
DesiredHeight = ActualHeight,
77-
IsAnchorPanel = true
78-
};
79-
panel._DetachChild(this);
80-
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
81-
_subpanel._AttachChild(this, 0);
82-
_subpanel.AttachChild(child, AttachMode.Left, 0);
83-
}
84-
else panel._AttachChild(child, index);
85-
break;
86-
case DropMode.Top:
87-
if (panel.Direction == Direction.LeftToRight)
82+
Direction = Direction.LeftToRight,
83+
DesiredWidth = ActualWidth,
84+
DesiredHeight = ActualHeight,
85+
IsAnchorPanel = true
86+
};
87+
panel._DetachChild(this);
88+
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
89+
_subpanel._AttachChild(this, 0);
90+
_subpanel.AttachChild(source, AttachMode.Left, 0);
91+
}
92+
else panel._AttachChild(source, index);
93+
break;
94+
case DropMode.Top:
95+
if (panel.Direction == Direction.LeftToRight)
96+
{
97+
var _subpanel = new LayoutGroupPanel(Model.Side)
8898
{
89-
var _subpanel = new LayoutGroupPanel(Model.Side)
90-
{
91-
Direction = Direction.UpToDown,
92-
DesiredWidth = ActualWidth,
93-
DesiredHeight = ActualHeight,
94-
IsAnchorPanel = true
95-
};
96-
panel._DetachChild(this);
97-
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
98-
_subpanel._AttachChild(this, 0);
99-
_subpanel.AttachChild(child, AttachMode.Top, 0);
100-
}
101-
else panel._AttachChild(child, index);
102-
break;
103-
case DropMode.Right:
104-
if (panel.Direction == Direction.UpToDown)
99+
Direction = Direction.UpToDown,
100+
DesiredWidth = ActualWidth,
101+
DesiredHeight = ActualHeight,
102+
IsAnchorPanel = true
103+
};
104+
panel._DetachChild(this);
105+
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
106+
_subpanel._AttachChild(this, 0);
107+
_subpanel.AttachChild(source, AttachMode.Top, 0);
108+
}
109+
else panel._AttachChild(source, index);
110+
break;
111+
case DropMode.Right:
112+
if (panel.Direction == Direction.UpToDown)
113+
{
114+
var _subpanel = new LayoutGroupPanel(Model.Side)
105115
{
106-
var _subpanel = new LayoutGroupPanel(Model.Side)
107-
{
108-
Direction = Direction.LeftToRight,
109-
DesiredWidth = ActualWidth,
110-
DesiredHeight = ActualHeight,
111-
IsAnchorPanel = true
112-
};
113-
panel._DetachChild(this);
114-
_subpanel._AttachChild(this, 0);
115-
_subpanel.AttachChild(child, AttachMode.Right, 1);
116-
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
117-
}
118-
else panel._AttachChild(child, index + 1);
119-
break;
120-
case DropMode.Bottom:
121-
if (panel.Direction == Direction.LeftToRight)
116+
Direction = Direction.LeftToRight,
117+
DesiredWidth = ActualWidth,
118+
DesiredHeight = ActualHeight,
119+
IsAnchorPanel = true
120+
};
121+
panel._DetachChild(this);
122+
_subpanel._AttachChild(this, 0);
123+
_subpanel.AttachChild(source, AttachMode.Right, 1);
124+
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
125+
}
126+
else panel._AttachChild(source, index + 1);
127+
break;
128+
case DropMode.Bottom:
129+
if (panel.Direction == Direction.LeftToRight)
130+
{
131+
var _subpanel = new LayoutGroupPanel(Model.Side)
122132
{
123-
var _subpanel = new LayoutGroupPanel(Model.Side)
124-
{
125-
Direction = Direction.UpToDown,
126-
DesiredWidth = ActualWidth,
127-
DesiredHeight = ActualHeight,
128-
IsAnchorPanel = true
129-
};
130-
panel._DetachChild(this);
131-
_subpanel._AttachChild(this, 0);
132-
_subpanel.AttachChild(child, AttachMode.Bottom, 1);
133-
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
134-
}
135-
else panel._AttachChild(child, index + 1);
136-
break;
137-
}
133+
Direction = Direction.UpToDown,
134+
DesiredWidth = ActualWidth,
135+
DesiredHeight = ActualHeight,
136+
IsAnchorPanel = true
137+
};
138+
panel._DetachChild(this);
139+
_subpanel._AttachChild(this, 0);
140+
_subpanel.AttachChild(source, AttachMode.Bottom, 1);
141+
panel._AttachChild(_subpanel, Math.Min(index, panel.Count));
142+
}
143+
else panel._AttachChild(source, index + 1);
144+
break;
138145
}
139-
else base.OnDrop(source);
140-
(source.RelativeObj as BaseFloatWindow).Close();
141146
}
142147
}
143148
}

YDock/View/Control/BaseGroupControl.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ public bool TryDeatchFromParent(bool isDispose = true)
199199
{
200200
if (DockViewParent is ILayoutPanel)
201201
{
202-
var panel = DockViewParent as ILayoutPanel;
203-
if (panel.IsDocumentPanel && panel.Count == 1)
202+
if ((DockViewParent as ILayoutPanel).IsDocumentPanel)
204203
return false;
205204
}
206205
var parent = Parent;

0 commit comments

Comments
 (0)