public void SetSorting(int index, bool ascending) { if (CTL_MainWindow.sIsRefreshing) { return; } if (index < 0 || index > mColumns.Length) { return; } switch ((eColumnType)index) { case eColumnType.KEYWORD: CTL_TodoObject.SortByKeyword(ascending); break; case eColumnType.COMMENT: CTL_TodoObject.SortByMessage(ascending); break; case eColumnType.FILE_NAME: CTL_TodoObject.SortByFileName(ascending); break; case eColumnType.LINE_NUMBER: CTL_TodoObject.SortByLineNumber(ascending); break; } CTL_Settings.SaveColumnSort(index, ascending); }
public void Clear() { for (int i = 0; i < mTodoObjects.Count; i++) { mTodoObjects[i].Clear(); } CTL_TodoObject.ClearRegisteredItems(); mTodoObjects.Clear(); }
//CTL...DRAW tooltip comment element void DrawElementTooltip(Rect elementRect, Rect windowRect, CTL_TodoObject obj) { //CTL...todo : if hold modifier key : more detailed tooltip ? Rect drawingRect; float paddingRight = 20; string contentStr = ""; if (CTL_Settings.DisplayKeywordInCommentTooltip) { contentStr += obj.mLinkedKeyword.Key + "\n"; } contentStr += obj.mLineContent; if (CTL_Settings.DisplayFilenameAndLineInCommentTooltip) { contentStr += "\n" + obj.mFile.mName + " (L:" + obj.mLineNumber + ")"; } GUIContent _content = new GUIContent(contentStr); GUIStyle _style = new GUIStyle(EditorStyles.textArea); _style.fixedWidth = (windowRect.width - paddingRight) * .8f; _style.wordWrap = true; float calculedHeight = _style.CalcHeight(_content, _style.fixedWidth); Vector2 _widthHeight = new Vector2(_style.fixedWidth, calculedHeight); float _topDecal = elementRect.y - _widthHeight.y; if (_topDecal < 0) { //CTL...tooltip hit the top, draw it under drawingRect = new Rect(mScrollPosMainTab.x + windowRect.width - _widthHeight.x - paddingRight, elementRect.y + elementRect.height, _widthHeight.x, _widthHeight.y); } else { //CTL...toltip displayed on top of element drawingRect = new Rect(mScrollPosMainTab.x + windowRect.width - _widthHeight.x - paddingRight, elementRect.y - _widthHeight.y, _widthHeight.x, _widthHeight.y); } EditorGUI.LabelField(drawingRect, _content, _style); }
//CTL...DRAW panel main void DrawMainPanel() { if (sIsRefreshing) { string msg = sRefreshStepName; float progressDisplayed = CTL_RefreshWorker.GetTotalProgress(); Rect progressBarRect = new Rect(position.width * .125f, position.height * .4f, position.width * .75f, 20); Rect progressBarTextRect = new Rect(position.width * .125f, position.height * .4f, position.width * .75f, 20); EditorGUI.ProgressBar(progressBarRect, progressDisplayed, msg); EditorGUI.LabelField(progressBarTextRect, GetRefreshProgressPercent() + "%", new GUIStyle("label") { alignment = TextAnchor.MiddleRight }); return; } if (sProgressBarNeedClear) { if (Event.current.type == EventType.Repaint) { sProgressBarNeedClear = false; } return; } Rect headerRect = mMultiColumnHeader_TodoObjects.Draw(position, CTL_Styles.HEADER_HEIGHT, mScrollPosMainTab.x); GUILayout.Space(headerRect.height); mScrollPosMainTab = EditorGUILayout.BeginScrollView(mScrollPosMainTab); float headerWidth = mMultiColumnHeader_TodoObjects.GetHeaderWidth(); CTL_TodoObject.GenerateDisplayedElementListIfNeeded(); EditorGUILayout.LabelField("", GUILayout.Width(headerWidth - 8)); //CTL...space only horizontal GUIStyle style = new GUIStyle(); style.border = new RectOffset(0, 0, 0, 0); EditorGUILayout.BeginVertical(style); GUILayout.Space(CTL_Styles.MAIN_TAB_ELEMENT_HEIGHT * (CTL_TodoObject.sDisplayedElementList.Count - 1)); int startElement = (int)mScrollPosMainTab.y / CTL_Styles.MAIN_TAB_ELEMENT_HEIGHT; int totalHeight = 0; int hoveredElementId = -1; Rect hoveredElementRect = new Rect();; Rect curElemRect; //CTL...draw only visible elements for (int i = startElement; i < CTL_TodoObject.sDisplayedElementList.Count; i++) { curElemRect = DrawElement(CTL_TodoObject.sDisplayedElementList[i], i * CTL_Styles.MAIN_TAB_ELEMENT_HEIGHT, position.width, headerWidth); totalHeight += (int)curElemRect.height; if (curElemRect.Contains(Event.current.mousePosition)) { hoveredElementId = i; hoveredElementRect = new Rect(curElemRect); } if (totalHeight > position.height - CTL_Styles.HEADER_HEIGHT - CTL_Styles.MAIN_TAB_MCH_HEIGHT) { break; } } if (hoveredElementId >= 0 && CTL_Settings.EnableCommentTooltip && Event.current.modifiers == CTL_Settings.DisplayTooltipModifier) { DrawElementTooltip(hoveredElementRect, position, CTL_TodoObject.sDisplayedElementList[hoveredElementId]); } EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); }
//CTL...DRAW single comment element Rect DrawElement(CTL_TodoObject obj, int startY, float windowWidth, float headerWidth) { float curMaxHeight = CTL_Styles.MAIN_TAB_ELEMENT_HEIGHT; Rect colRect; GUIContent guiContent = new GUIContent(); CTL_Styles.sStyle_Main_ElementLabel.alignment = TextAnchor.MiddleLeft; float maxWidth = windowWidth; if (headerWidth > maxWidth) { maxWidth = headerWidth; } Rect fullElem = new Rect(0, startY, maxWidth, curMaxHeight); GUI.DrawTexture(fullElem, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1f, obj.mLinkedKeyword.Color, 0, 0); //CTL...draw hover if (fullElem.Contains(Event.current.mousePosition)) { GUI.DrawTexture(fullElem, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1f, new Color(1, 1, 1, .3f), 0, 0); } GUI.DrawTexture(new Rect(0, startY, maxWidth, 1), Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1f, new Color(.5f, .5f, .5f, .5f), 0, 0); bool jumpedToLine = false; bool triedJumpToLine = false; float x = 0; if (mMultiColumnHeader_TodoObjects.IsColumnVisible(CTL_MCH_TodoObject.eColumnType.KEYWORD)) { colRect = mMultiColumnHeader_TodoObjects.GetDrawRect(CTL_MCH_TodoObject.eColumnType.KEYWORD); guiContent.text = obj.mLinkedKeyword.Key; if (GUI.Button(new Rect(x, startY, colRect.width - CTL_Styles.sStyle_Main_ElementLabel.contentOffset.x, curMaxHeight), guiContent, CTL_Styles.sStyle_Main_ElementLabel) && Event.current.modifiers == CTL_Settings.CommentClickModifier_OpenFile) { triedJumpToLine = true; jumpedToLine = obj.JumpToLine(); } x += colRect.width; } if (mMultiColumnHeader_TodoObjects.IsColumnVisible(CTL_MCH_TodoObject.eColumnType.COMMENT)) { colRect = mMultiColumnHeader_TodoObjects.GetDrawRect(CTL_MCH_TodoObject.eColumnType.COMMENT); guiContent.text = obj.mMessage; if (GUI.Button(new Rect(x, startY, colRect.width - CTL_Styles.sStyle_Main_ElementLabel.contentOffset.x, curMaxHeight), guiContent, CTL_Styles.sStyle_Main_ElementLabel) && Event.current.modifiers == CTL_Settings.CommentClickModifier_OpenFile) { triedJumpToLine = true; jumpedToLine = obj.JumpToLine(); } x += colRect.width; } if (mMultiColumnHeader_TodoObjects.IsColumnVisible(CTL_MCH_TodoObject.eColumnType.FILE_NAME)) { colRect = mMultiColumnHeader_TodoObjects.GetDrawRect(CTL_MCH_TodoObject.eColumnType.FILE_NAME); guiContent.text = obj.mFile.mName; if (GUI.Button(new Rect(x, startY, colRect.width - CTL_Styles.sStyle_Main_ElementLabel.contentOffset.x, curMaxHeight), guiContent, CTL_Styles.sStyle_Main_ElementLabel) && Event.current.modifiers == CTL_Settings.CommentClickModifier_OpenFile) { //CTL...todo : on click item select file in project OR open menu asking if you want to exclude file triedJumpToLine = true; jumpedToLine = obj.JumpToLine(); } x += colRect.width; } if (mMultiColumnHeader_TodoObjects.IsColumnVisible(CTL_MCH_TodoObject.eColumnType.LINE_NUMBER)) { colRect = mMultiColumnHeader_TodoObjects.GetDrawRect(CTL_MCH_TodoObject.eColumnType.LINE_NUMBER); guiContent.text = obj.mLineNumber.ToString(); CTL_Styles.sStyle_Main_ElementLabel.alignment = TextAnchor.MiddleRight; if (GUI.Button(new Rect(x, startY, colRect.width - CTL_Styles.sStyle_Main_ElementLabel.contentOffset.x, curMaxHeight), guiContent, CTL_Styles.sStyle_Main_ElementLabel) && Event.current.modifiers == CTL_Settings.CommentClickModifier_OpenFile) { triedJumpToLine = true; jumpedToLine = obj.JumpToLine(); } x += colRect.width; } if (triedJumpToLine && !jumpedToLine) { Debug.LogWarning("Error opening file " + obj.mFile.mRelativePath + " at line " + obj.mLineNumber); } return(fullElem); }
//CTL...DRAW panel keywords void DrawKeywordsListPanel() { CTL_KeywordObject toDelete = null; bool itemNeedFocus = false; Rect elementRect; List <Rect> elementsRects = new List <Rect>(); int draggedId = 0; Rect draggedElementRect = new Rect(); CTL_KeywordObject currentObject; CTL_KeywordObject dragedElem = null; mScrollPosKeywordsTab = EditorGUILayout.BeginScrollView(mScrollPosKeywordsTab); for (int i = 0; i < CTL_Settings.KeywordsList.mKeywords.Count; i++) { currentObject = CTL_Settings.KeywordsList.mKeywords[i]; if (currentObject.mIsDragged) { GUI.backgroundColor = new Color(0, 0, 0, .1f); GUI.color = new Color(0, 0, 0, .1f); draggedId = i; } else { GUI.backgroundColor = Color.white; GUI.color = Color.white; } elementRect = EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); elementsRects.Add(new Rect(elementRect)); if (GUILayout.Button(currentObject.Visible?CTL_Styles.sGUIC_Keywords_VisibilityToogleON: CTL_Styles.sGUIC_Keywords_VisibilityToogleOFF, GUILayout.Width(30))) { currentObject.Visible = !currentObject.Visible; } currentObject.Color = EditorGUILayout.ColorField(new GUIContent(), currentObject.Color, true, true, false, GUILayout.Width(40)); if (currentObject.Valid) { GUI.backgroundColor = Color.white; } else { GUI.backgroundColor = new Color(1f, .25f, .4f, .4f); } if (currentObject.mNeedFocus) { currentObject.mNeedFocus = false; GUI.SetNextControlName("itemNeedFocus"); itemNeedFocus = true; } currentObject.Key = GUILayout.TextField(currentObject.Key, GUILayout.Width(100)); if (itemNeedFocus) { EditorGUI.FocusTextInControl("itemNeedFocus"); } GUI.backgroundColor = Color.white; GUILayout.Label(currentObject.Valid ? new GUIContent() : CTL_Styles.sGUIC_ManageKeyword_InvalidWarning, GUILayout.Width(30)); if (GUILayout.Button("DELETE")) { toDelete = currentObject; } GUILayout.FlexibleSpace(); int objLinked = CTL_TodoObject.GetObjectsForKeyword(currentObject).Count; CTL_Styles.sGUIC_Keywords_CommentCountTooltip.text = "[" + objLinked.ToString() + "]"; GUILayout.Label(CTL_Styles.sGUIC_Keywords_CommentCountTooltip); EditorGUILayout.EndHorizontal(); if (/*!mIsDragging && */ elementRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && Event.current.button == 0) { currentObject.mIsDragged = true; mDragOffset = Event.current.mousePosition.y - elementRect.y; } if (currentObject.mIsDragged) { draggedElementRect = new Rect(elementRect); mIsDragging = true; dragedElem = currentObject; } } EditorGUILayout.EndScrollView(); GUI.backgroundColor = Color.white; GUI.color = Color.white; if (mIsDragging && elementsRects.Count > 0) { //CTL...move the shadow rect draggedElementRect.y = Event.current.mousePosition.y - mDragOffset; GUI.backgroundColor = Color.black; GUIStyle style = new GUIStyle(EditorStyles.helpBox); style.contentOffset = new Vector2(80, 0); EditorGUI.LabelField(draggedElementRect, dragedElem.Key, style); GUI.backgroundColor = Color.white; //CTL...determine closest element top int closestId = -1; float closestDist = 0; float curDist = 0; float curElemMiddlePos = (draggedElementRect.y + draggedElementRect.height / 2); List <Rect> scrollAdaptedRect = new List <Rect>(); for (int i = 0; i < elementsRects.Count; i++) { Rect rect = elementsRects[i]; rect.y += CTL_Styles.HEADER_HEIGHT; rect.y -= mScrollPosKeywordsTab.y; scrollAdaptedRect.Add(rect); } for (int i = 0; i < scrollAdaptedRect.Count; i++) { //CTL...If we go up in the list, we want to use the top pos of the other element, else, the bot pos if (draggedId > i) { curDist = Mathf.Abs((scrollAdaptedRect[i].y) - curElemMiddlePos); } else { curDist = Mathf.Abs((scrollAdaptedRect[i].y + (scrollAdaptedRect[i].height)) - curElemMiddlePos); } if (closestId < 0 || closestDist > curDist) { closestId = i; closestDist = curDist; } } //CTL...draw dropper pos if (draggedId != closestId) { Rect dropperRect = new Rect(scrollAdaptedRect[closestId]); //CTL...If we go up in the list, we want to use the top pos of the other element, else, the bot pos if (draggedId < closestId) { dropperRect.y += scrollAdaptedRect[closestId].height; } //CTL...draw the bar with a small fade fx dropperRect.height = 1; dropperRect.y -= 0; EditorGUI.DrawRect(dropperRect, new Color(0, 0, 0, .25f)); dropperRect.height = 3; dropperRect.y -= 1; EditorGUI.DrawRect(dropperRect, new Color(0, 0, 0, .25f)); dropperRect.height = 5; dropperRect.y -= 1; dropperRect.x += 1; dropperRect.width -= 2; EditorGUI.DrawRect(dropperRect, new Color(0, 0, 0, .25f)); } //CTL...mouse up check int controlId = GUIUtility.GetControlID(FocusType.Passive); Event evt = Event.current; if (evt.GetTypeForControl(controlId) == EventType.MouseDown && evt.button == 0) { GUIUtility.hotControl = controlId; } if (evt.GetTypeForControl(controlId) == EventType.MouseUp && evt.button == 0) { GUIUtility.hotControl = 0; mIsDragging = false; CTL_KeywordObject draggedObj = CTL_Settings.KeywordsList.GetDraggedObject(); if (draggedObj != null) { draggedObj.mIsDragged = false; //CTL...MOVE ITEM if (draggedId != closestId) { CTL_Settings.KeywordsList.MoveElementToPosInList(draggedObj, closestId); } CTL_Settings.KeywordsList.ClearAllDraggedObjects(); } evt.Use(); } } if (toDelete != null) { CTL_Settings.KeywordsList.RemoveKeyword(toDelete); } if (CTL_Settings.DEBUG_MODE) { if (GUILayout.Button("Add MULTIPLE Keys")) { for (int i = 0; i < 20; i++) { CTL_Settings.KeywordsList.AddKeyword("", true, true); } } } if (GUILayout.Button("Add Key")) { CTL_Settings.KeywordsList.AddKeyword("", true, true); } }
public void AddObject(CTL_TodoObject obj) { mTodoObjects.Add(obj); }