📄 umlshow.cs
字号:
for ( int nIndex = ( currentDisplayElementList.Count - 1 ) ; nIndex >= 0 ; nIndex -- )
{
itemData = (ElementData) currentDisplayElementList[nIndex];
this.DrawItem( g, itemData, ptOffset );
}
}
//*********************** Mouse Event Receive here **********************//
/// <summary>
/// From the mouse click to ensure which object has been double clicked
/// </summary>
/// <param name="pt"></param>
/// <returns></returns>
public ElementData OnMouseLeftClick( Point pt )
{
ElementData elementData = null;
for( int nIndex = 0; nIndex < currentDisplayElementList.Count; nIndex ++ )
{
ItemDrawState itemState;
elementData = (ElementData) currentDisplayElementList[nIndex];
itemState = (ItemDrawState) elementData.ExtendDataObject;
Point ptCurrent = new Point( itemState.Position.X, itemState.Position.Y );
ptCurrent.Offset(parentForm.AutoScrollPosition.X, parentForm.AutoScrollPosition.Y );
Rectangle rect = new Rectangle( ptCurrent,
new Size( (int) itemState.GetSize(elementData.ElementType).Width,
(int) itemState.GetSize(elementData.ElementType).Height ) );
if( rect.Contains( pt ) )
{
currentDisplayElementList.RemoveAt( nIndex );
currentDisplayElementList.Insert( 0, elementData );
return elementData;
}
}
return null;
}
/// <summary>
/// From the mouse click to ensure which object has been clicked
/// If double clicked and if the object which has been selected is a namespace
/// move to show namespace contained element
/// </summary>
/// <param name="pt"></param>
/// <returns></returns>
public ElementData OnMouseLeftDoubleClick( Point pt )
{
ElementData elementData = null;
for( int nIndex = 0; nIndex < currentDisplayElementList.Count; nIndex ++ )
{
ItemDrawState itemState;
elementData = (ElementData) currentDisplayElementList[nIndex];
itemState = (ItemDrawState) elementData.ExtendDataObject;
Point ptCurrent = new Point( itemState.Position.X, itemState.Position.Y );
ptCurrent.Offset(parentForm.AutoScrollPosition.X, parentForm.AutoScrollPosition.Y );
Rectangle rect = new Rectangle( ptCurrent,
new Size( (int) itemState.GetSize(elementData.ElementType).Width,
(int) itemState.GetSize(elementData.ElementType).Height ) );
if( rect.Contains( pt ) )
{
// if clicked item is a namespace then change to deep level
if( elementData.ElementType == enumElementType.elementTypeNameSpace )
{
//************ MODIFY HERE *****************//
// Combin all the same namespace
// i create a temp namespace that contain all
// the elements in the same namespace //
// Change Reason : Prevent to display the same namespace many times
if( currentDisplayPackage.Equals( codeData ) )
{
NameSpaceData newData = new NameSpaceData();
//
for( int nSolutionIndex = 0; nSolutionIndex < codeData.SolutionList.Count; nSolutionIndex ++ )
{
SolutionData sluData = (SolutionData)codeData.SolutionList[nSolutionIndex];
for( int nProjectIndex = 0; nProjectIndex < sluData.Element.Count ; nProjectIndex ++ )
{
ProjectData prjData = (ProjectData)sluData.Element[nProjectIndex];
for( int nProjectItemIndex = 0; nProjectItemIndex < prjData.Element.Count; nProjectItemIndex ++ )
{
ProjectItemData prjItemData = (ProjectItemData)prjData.Element[nProjectItemIndex];
CodeModelData codeModelData = (CodeModelData)prjItemData.Element[0];
CodeElementsData codeElementsData = (CodeElementsData)codeModelData.Element[0];
for( int nElementIndex = 0; nElementIndex < codeElementsData.Element.Count; nElementIndex ++ )
{
ElementData tempData = (ElementData)codeElementsData.Element[nElementIndex];
// Combin
if( (tempData.Name == elementData.Name) &&
(tempData.ElementType == elementData.ElementType) )
{
newData.Name = tempData.Name;
newData.ElementType= tempData.ElementType;
newData.DocComment = tempData.DocComment;
newData.Parent = tempData.Parent;
for( int j = 0; j < tempData.Element.Count; j ++ )
{
newData.Element.Add( tempData.Element[j] );
}
}
}
}
}
}
currentDisplayPackage = newData;
}
else
{
ElementData currentShowData = (ElementData)currentDisplayPackage;
NameSpaceData newData = new NameSpaceData();
for( int i = 0; i < currentShowData.Element.Count; i ++ )
{
ElementData tempData = (ElementData) currentShowData.Element[i];
// Combin
if( (tempData.Name == elementData.Name) &&
(tempData.ElementType == elementData.ElementType) )
{
newData.Name = tempData.Name;
newData.ElementType= tempData.ElementType;
newData.DocComment = tempData.DocComment;
newData.Parent = tempData.Parent;
for( int j = 0; j < tempData.Element.Count; j ++ )
{
newData.Element.Add( tempData.Element[j] );
}
}
}
newData.Parent = currentShowData;
currentDisplayPackage = newData;
}
// Change currentDisplayPakcage will cause
// reset the currentDislplay elements list
currentDisplayElementList.RemoveRange( 0, currentDisplayElementList.Count );
// then add all the elements of current display package to the list
ElementData currentPackage = (ElementData) currentDisplayPackage;
ElementData itemData;
// Used to count the autoscroll range
int nMaxX = 0;
int nMaxY = 0;
Graphics g = parentForm.CreateGraphics();
for( int i = 0; i < currentPackage.Element.Count; i ++ )
{
itemData = (ElementData) currentPackage.Element[i];
// That's means we must calculate it's first position
if( itemData.ExtendDataObject == null )
{
ItemDrawState itemDrawState = new ItemDrawState();
int nLeftEdge = spaceCount;
for( int k = 0; k < currentDisplayElementList.Count; k ++ )
{
ElementData tempData = (ElementData) currentDisplayElementList[k];
ItemDrawState tempState = (ItemDrawState)tempData.ExtendDataObject;
//*** NOW ,ONLY SUPPORT
// CLASS
// INTERFACE
// STRUCT
// NAMESPACE
// So...
if( ( tempData.ElementType == enumElementType.elementTypeClass ) ||
( tempData.ElementType == enumElementType.elementTypeInterface ) ||
( tempData.ElementType == enumElementType.elementTypeStruct ) ||
( tempData.ElementType == enumElementType.elementTypeNameSpace ) )
nLeftEdge += (int) tempState.GetSize( tempData.ElementType ).Width + spaceCount;
}
itemDrawState.Position.X = nLeftEdge;
itemDrawState.Position.Y = spaceCount;
itemData.ExtendDataObject = itemDrawState;
AutoCalculateElementSize( g, itemData );
}
ItemDrawState temp = (ItemDrawState)itemData.ExtendDataObject;
if( nMaxX < (temp.Position.X + (int)temp.GetSize(itemData.ElementType).Width) )
nMaxX = (temp.Position.X + (int)temp.GetSize(itemData.ElementType).Width);
if( nMaxY < (temp.Position.Y + (int)temp.GetSize(itemData.ElementType).Height) )
nMaxY = (temp.Position.Y + (int)temp.GetSize(itemData.ElementType).Height);
//**Why can't use this statement???**?//
// Faint!!!!
/*
int curX = temp.Position.X + (int)temp.GetSize(itemData.ElementType).Width;
int curY = temp.Position.Y + (int)temp.GetSize(itemData.ElementType).Height;
nMaxX > curX ? nMaxX : curX;
nMaxY > curY ? nMaxY : curY;
*/
///**********************MODIFY*****************///
///For prevent display more same namespace
bool bFind = false;
for( int j = 0; j < currentDisplayElementList.Count ; j ++ )
{
if( ((ElementData)currentDisplayElementList[j]).Name == itemData.Name )
bFind = true;
}
if( !bFind )
{
currentDisplayElementList.Add( itemData );
}
}
// Set the range
parentForm.AutoScrollMinSize = new Size( nMaxX + spaceCount, nMaxY + spaceCount );
}
return elementData;
}
}
return null;
}
/// <summary>
/// Get the element from position
/// </summary>
/// <param name="pt"></param>
/// <returns></returns>
public ElementData GetElementFromPosition( Point pt )
{
ElementData elementData = null;
for( int nIndex = 0; nIndex < currentDisplayElementList.Count; nIndex ++ )
{
ItemDrawState itemState;
elementData = (ElementData) currentDisplayElementList[nIndex];
itemState = (ItemDrawState) elementData.ExtendDataObject;
Point ptCurrent = new Point( itemState.Position.X, itemState.Position.Y );
ptCurrent.Offset(parentForm.AutoScrollPosition.X, parentForm.AutoScrollPosition.Y );
Rectangle rect = new Rectangle( ptCurrent,
new Size( (int) itemState.GetSize(elementData.ElementType).Width,
(int) itemState.GetSize(elementData.ElementType).Height ) );
if( rect.Contains( pt ) )
{
return elementData;
}
}
return null;
}
/// <summary>
/// Right button clicked some element
/// which will cause display a contenx menu to show item action
/// </summary>
/// <param name="pt"></param>
/// <returns></returns>
public ElementData OnMouseRightClick( Point pt )
{
ElementData elementData = null;
for( int nIndex = 0; nIndex < currentDisplayElementList.Count; nIndex ++ )
{
ItemDrawState itemState;
elementData = (ElementData) currentDisplayElementList[nIndex];
itemState = (ItemDrawState) elementData.ExtendDataObject;
Point ptCurrent = new Point( itemState.Position.X, itemState.Position.Y );
ptCurrent.Offset(parentForm.AutoScrollPosition.X, parentForm.AutoScrollPosition.Y );
Rectangle rect = new Rectangle( ptCurrent,
new Size( (int) itemState.GetSize(elementData.ElementType).Width,
(int) itemState.GetSize(elementData.ElementType).Height ) );
if( rect.Contains( pt ) )
{
return elementData;
}
}
return null;
}
/// <summary>
/// Cause to display upper level object
/// </summary>
/// <returns>Return false means there is no upper level</returns>
public bool UpperLevel()
{
if( currentDisplayPackage == null || codeData == null ) return false;
if( currentDisplayPackage.Equals( codeData ) ) return false;
ElementData elementData = (ElementData)currentDisplayPackage;
ElementData parentData = (ElementData)elementData.Parent;
this.currentDisplayElementList.RemoveRange( 0, currentDisplayElementList.Count );
if( parentData.ElementType == enumElementType.elementTypeCodeElements )
{
// Parent is Root
/*
// here is ModelData
ElementData tempData = (ElementData) parentData.Parent;
// Here is ProjectItemData
tempDate = (ElementData) tempData.Parent;
// Here is ProjectData
tempData = (ElementData) tempData.Parent;
// Here is SolutionData
tempData = (ElementData) tempData.Parent;
*/
this.Initialize();
}
else if( parentData.ElementType == enumElementType.elementTypeNameSpace )
{
// Parent SHOULD NOT ROOT package, so....
currentDisplayPackage = parentData;
Graphics g = parentForm.CreateGraphics();
for( int nElementIndex = 0; nElementIndex < parentData.Element.Count; nElementIndex ++ )
{
ElementData itemData = (ElementData)parentData.Element[nElementIndex];
// Used to count the autoscroll range
int nMaxX = 0;
int nMaxY = 0;
// That's means we must calculate it's first position
if( itemData.ExtendDataObject == null )
{
ItemDrawState itemDrawState = new ItemDrawState();
int nLeftEdge = spaceCount;
for( int nIndex = 0; nIndex < currentDisplayElementList.Count; nIndex ++ )
{
ElementData tempData = (ElementData) currentDisplayElementList[nIndex];
ItemDrawState tempState = (ItemDrawState)tempData.ExtendDataObject;
nLeftEdge += (int) tempState.GetSize( tempData.ElementType ).Width + spaceCount;
}
itemDrawState.Position.X = nLeftEdge;
itemDrawState.Position.Y = spaceCount;
itemData.ExtendDataObject = itemDraw
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -