📄 restore.cs
字号:
// Try and place more accurately according to other edge Zones
if (beforeAllIndex > beforeIndex)
beforeIndex = beforeAllIndex;
// Check against limits
if (beforeIndex >= max)
beforeIndex = max - 1;
dm.Container.Controls.SetChildIndex(newZ, beforeIndex + 1);
}
else
{
// Try and place more accurately according to other edge Zones
if (afterAllIndex < afterIndex)
afterIndex = afterAllIndex;
// Check against limits
if (afterIndex <= min)
afterIndex = min + 1;
if (afterIndex > min)
dm.Container.Controls.SetChildIndex(newZ, afterIndex);
else
{
// Set the Zone to be the least important of our Zones
dm.ReorderZoneToInnerMost(newZ);
}
}
dm.Container.ResumeLayout();
}
public override void SaveInternalToXml(XmlTextWriter xmlOut)
{
base.SaveInternalToXml(xmlOut);
xmlOut.WriteStartElement("Position");
xmlOut.WriteAttributeString("Size", ConversionHelper.SizeToString(_size));
xmlOut.WriteAttributeString("Location", ConversionHelper.PointToString(_location));
xmlOut.WriteEndElement();
_best.SaveToXml("Best", xmlOut);
_next.SaveToXml("Next", xmlOut);
_previous.SaveToXml("Previous", xmlOut);
_nextAll.SaveToXml("NextAll", xmlOut);
_previousAll.SaveToXml("PreviousAll", xmlOut);
}
public override void LoadInternalFromXml(XmlTextReader xmlIn, int formatVersion)
{
base.LoadInternalFromXml(xmlIn, formatVersion);
// Move to next xml node
if (!xmlIn.Read())
throw new ArgumentException("Could not read in next expected node");
// Check it has the expected name
if (xmlIn.Name != "Position")
throw new ArgumentException("Node 'Position' expected but not found");
// Grab raw position information
string attrSize = xmlIn.GetAttribute(0);
string attrLocation = xmlIn.GetAttribute(1);
// Convert from string to proper types
_size = ConversionHelper.StringToSize(attrSize);
_location = ConversionHelper.StringToPoint(attrLocation);
_best.LoadFromXml("Best", xmlIn);
_next.LoadFromXml("Next", xmlIn);
_previous.LoadFromXml("Previous", xmlIn);
_nextAll.LoadFromXml("NextAll", xmlIn);
_previousAll.LoadFromXml("PreviousAll", xmlIn);
}
}
public class RestoreContentFloatingAffinity : RestoreContentState
{
// Instance fields
protected Size _size;
protected Point _location;
protected StringCollection _best;
protected StringCollection _associates;
public RestoreContentFloatingAffinity()
: base()
{
// Must always point to valid reference
_best = new StringCollection();
_associates = new StringCollection();
}
public RestoreContentFloatingAffinity(Restore child,
State state,
Content content,
StringCollection best,
StringCollection associates)
: base(child, state, content)
{
// Remember parameters
_best = best;
_associates = associates;
_size = content.DisplaySize;
_location = content.DisplayLocation;
// Remove target from collection of friends
if (_best.Contains(content.Title))
_best.Remove(content.Title);
// Remove target from collection of associates
if (_associates.Contains(content.Title))
_associates.Remove(content.Title);
}
public override void PerformRestore(DockingManager dm)
{
// Grab a list of all floating forms
Form[] owned = dm.Container.FindForm().OwnedForms;
FloatingForm target = null;
// Find the match to one of our best friends
foreach(Form f in owned)
{
FloatingForm ff = f as FloatingForm;
if (ff != null)
{
if (ZoneHelper.ContentNames(ff.Zone).Contains(_best))
{
target = ff;
break;
}
}
}
// If no friends then try associates as second best option
if (target == null)
{
// Find the match to one of our best friends
foreach(Form f in owned)
{
FloatingForm ff = f as FloatingForm;
if (ff != null)
{
if (ZoneHelper.ContentNames(ff.Zone).Contains(_associates))
{
target = ff;
break;
}
}
}
}
// If we found a friend/associate, then restore to it
if (target != null)
{
// We should have a child and be able to restore to its Zone
_child.PerformRestore(target.Zone);
}
else
{
// Restore its location/size
_content.DisplayLocation = _location;
_content.DisplaySize = _size;
// Use the docking manage method to create us a new Floating Window at correct size/location
dm.AddContentWithState(_content, State.Floating);
}
}
public override void SaveInternalToXml(XmlTextWriter xmlOut)
{
base.SaveInternalToXml(xmlOut);
xmlOut.WriteStartElement("Position");
xmlOut.WriteAttributeString("Size", ConversionHelper.SizeToString(_size));
xmlOut.WriteAttributeString("Location", ConversionHelper.PointToString(_location));
xmlOut.WriteEndElement();
_best.SaveToXml("Best", xmlOut);
_associates.SaveToXml("Associates", xmlOut);
}
public override void LoadInternalFromXml(XmlTextReader xmlIn, int formatVersion)
{
base.LoadInternalFromXml(xmlIn, formatVersion);
// Move to next xml node
if (!xmlIn.Read())
throw new ArgumentException("Could not read in next expected node");
// Check it has the expected name
if (xmlIn.Name != "Position")
throw new ArgumentException("Node 'Position' expected but not found");
// Grab raw position information
string attrSize = xmlIn.GetAttribute(0);
string attrLocation = xmlIn.GetAttribute(1);
// Convert from string to proper types
_size = ConversionHelper.StringToSize(attrSize);
_location = ConversionHelper.StringToPoint(attrLocation);
_best.LoadFromXml("Best", xmlIn);
_associates.LoadFromXml("Associates", xmlIn);
}
}
public class RestoreZoneAffinity : RestoreContent
{
// Instance fields
protected Decimal _space;
protected StringCollection _best;
protected StringCollection _next;
protected StringCollection _previous;
public RestoreZoneAffinity()
: base()
{
// Default state
_space = 50m;
// Must always point to valid reference
_best = new StringCollection();
_next = new StringCollection();
_previous = new StringCollection();
}
public RestoreZoneAffinity(Restore child,
Content content,
StringCollection best,
StringCollection next,
StringCollection previous)
: base(child, content)
{
// Remember parameters
_best = best;
_next = next;
_previous = previous;
if (content.Visible)
_space = content.ParentWindowContent.ZoneArea;
else
_space = 50m;
}
public override void PerformRestore(Zone z)
{
int count = z.Windows.Count;
int beforeIndex = - 1;
int afterIndex = count;
// Find the match to one of our best friends
for(int index=0; index<count; index++)
{
WindowContent wc = z.Windows[index] as WindowContent;
if (wc != null)
{
// If this WindowContent contains a best friend, then add ourself here as well
if (wc.Contents.Contains(_best))
{
if (_child == null)
{
// If we do not have a Restore object for the Window then just add
// into the WindowContent at the end of the existing Contents
wc.Contents.Add(_content);
}
else
{
// Get the child to restore as best as possible inside WindowContent
_child.PerformRestore(wc);
}
return;
}
// If the WindowContent contains a Content previous to the target
if (wc.Contents.Contains(_previous))
{
if (index > beforeIndex)
beforeIndex = index;
}
// If the WindowContent contains a Content next to the target
if (wc.Contents.Contains(_next))
{
if (index < afterIndex)
afterIndex = index;
}
}
}
// If we get here then we did not find any best friends, this
// means we need to create a new WindowContent to host the Content.
Window newW = z.DockingManager.CreateWindowForContent(_content);
ZoneSequence zs = z as ZoneSequence;
// If this is inside a ZoneSequence instance
if (zs != null)
{
// Do not reposition the Windows on the .Insert but instead ignore the
// reposition and let it happen in the .ModifyWindowSpace. This reduces
// the flicker that would occur otherwise
zs.SuppressReposition();
}
// Need to find the best place in the order for the Content, start by
// looking for the last 'previous' content and place immediately after it
if (beforeIndex >= 0)
{
// Great, insert after it
z.Windows.Insert(beforeIndex + 1, newW);
}
else
{
// No joy, so find the first 'next' content and place just before it, if
// none are found then just add to the end of the collection.
z.Windows.Insert(afterIndex, newW);
}
// If this is inside a ZoneSequence instance
if (zs != null)
{
// We want to try and allocate the correct Zone space
zs.ModifyWindowSpace(newW, _space);
}
}
public override void SaveInternalToXml(XmlTextWriter xmlOut)
{
base.SaveInternalToXml(xmlOut);
xmlOut.WriteStartElement("Space");
xmlOut.WriteAttributeString("Value", _space.ToString());
xmlOut.WriteEndElement();
_best.SaveToXml("Best", xmlOut);
_next.SaveToXml("Next", xmlOut);
_previous.SaveToXml("Previous", xmlOut);
}
public override void LoadInternalFromXml(XmlTextReader xmlIn, int formatVersion)
{
base.LoadInternalFromXml(xmlIn, formatVersion);
// Move to next xml node
if (!xmlIn.Read())
throw new ArgumentException("Could not read in next expected node");
// Check it has the expected name
if (xmlIn.Name != "Space")
throw new ArgumentException("Node 'Space' expected but not found");
// Grab raw position information
string attrSpace = xmlIn.GetAttribute(0);
// Convert from string to proper type
_space = Decimal.Parse(attrSpace);
_best.LoadFromXml("Best", xmlIn);
_next.LoadFromXml("Next", xmlIn);
_previous.LoadFromXml("Previous", xmlIn);
}
}
public class RestoreWindowContent : RestoreContent
{
// Instance fields
protected bool _selected;
protected StringCollection _next;
protected StringCollection _previous;
public RestoreWindowContent()
: base()
{
// Must always point to valid reference
_selected = false;
_next = new StringCollection();
_previous = new StringCollection();
}
public RestoreWindowContent(Restore child,
Content content,
StringCollection next,
StringCollection previous,
bool selected)
: base(child, content)
{
// Remember parameters
_selected = selected;
_next = next;
_previous = previous;
}
public override void PerformRestore(Window w)
{
// We are only ever called for a WindowContent object
WindowContent wc = w as WindowContent;
int bestIndex = -1;
foreach(String s in _previous)
{
if (wc.Contents.Contains(s))
{
int previousIndex = wc.Contents.IndexOf(wc.Contents[s]);
if (previousIndex > bestIndex)
bestIndex = previousIndex;
}
}
// Did we find a previous Content?
if (bestIndex >= 0)
{
// Great, insert after it
wc.Contents.Insert(bestIndex + 1, _content);
}
else
{
bestIndex = wc.Contents.Count;
foreach(String s in _next)
{
if (wc.Contents.Contains(s))
{
int nextIndex = wc.Contents.IndexOf(wc.Contents[s]);
if (nextIndex < bestIndex)
bestIndex = nextIndex;
}
}
// Insert before the found entry (or at end if non found)
wc.Contents.Insert(bestIndex, _content);
}
// Should this content become selected?
if (_selected)
_content.BringToFront();
}
public override void SaveInternalToXml(XmlTextWriter xmlOut)
{
base.SaveInternalToXml(xmlOut);
_next.SaveToXml("Next", xmlOut);
_previous.SaveToXml("Previous", xmlOut);
xmlOut.WriteStartElement("Selected");
xmlOut.WriteAttributeString("Value", _selected.ToString());
xmlOut.WriteEndElement();
}
public override void LoadInternalFromXml(XmlTextReader xmlIn, int formatVersion)
{
base.LoadInternalFromXml(xmlIn, formatVersion);
_next.LoadFromXml("Next", xmlIn);
_previous.LoadFromXml("Previous", xmlIn);
// _selected added in version 4 format
if (formatVersion >= 4)
{
// Move to next xml node
if (!xmlIn.Read())
throw new ArgumentException("Could not read in next expected node");
// Check it has the expected name
if (xmlIn.Name != "Selected")
throw new ArgumentException("Node 'Selected' expected but not found");
// Convert attribute value to boolean value
_selected = Convert.ToBoolean(xmlIn.GetAttribute(0));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -