public CTL_TodoObject(string lineContent, int lineNb, CTL_TodoFile file, CTL_KeywordObject keyworkRef) { sNeedRefreshDisplayedElementsList = true; mLinkedKeyword = keyworkRef; mFile = file; mLineContent = lineContent; mLineNumber = lineNb; if (!CTL_Settings.CaseSensitive) { mMessage = lineContent.Substring(lineContent.ToLower().IndexOf(keyworkRef.KeySearch) + keyworkRef.KeySearch.Length); } else { mMessage = lineContent.Substring(lineContent.IndexOf(keyworkRef.KeySearch) + keyworkRef.KeySearch.Length); } mMessage = mMessage.Trim(); if (mMessage.StartsWith(":")) { mMessage = mMessage.Substring(1); mMessage = mMessage.Trim(); } if (string.IsNullOrEmpty(mMessage)) { mMessage = keyworkRef.Key; } Register(); }
public void RemoveKeyword(CTL_KeywordObject obj) { if (mKeywords.Contains(obj)) { mKeywords.Remove(obj); } ValidateKeywords(); CTL_Settings.sShouldSave = true; CTL_MainWindow.sNeedRefreshAuto = true; }
public void MoveElementToPosInList(CTL_KeywordObject obj, int pos) { if (mKeywords.Contains(obj)) { mKeywords.Remove(obj); } mKeywords.Insert(pos, obj); CTL_Settings.sShouldSave = true; CTL_MainWindow.sNeedRefreshAuto = true; }
public static List <CTL_TodoObject> GetObjectsForKeyword(CTL_KeywordObject keywordObj) { List <CTL_TodoObject> toReturn = new List <CTL_TodoObject>(); for (int i = 0; i < sTodoObjects.Count; i++) { if (sTodoObjects[i].mLinkedKeyword == keywordObj) { toReturn.Add(sTodoObjects[i]); } } return(toReturn); }
public void AddKeyword(string keyword = "", bool needFocus = false, bool generateRandomColor = false) { CTL_KeywordObject newObj = new CTL_KeywordObject(); newObj.Key = keyword; newObj.mNeedFocus = needFocus; if (generateRandomColor) { newObj.Color = CTL_Tools.GenerateRandomKeywordColor(); } mKeywords.Add(newObj); KeywordModified(newObj, true); CTL_Settings.sShouldSave = true; CTL_MainWindow.sNeedRefreshAuto = true; }
public void LoadFromString(string saveStr) { string[] splitted = saveStr.Split(SEPARATOR); for (int i = 0; i < splitted.Length; i++) { if (!string.IsNullOrEmpty(splitted[0])) { mKeywords.Add(CTL_KeywordObject.LoadFromString(splitted[i])); } } if (mKeywords.Count == 0) { CTL_KeywordObject baseKeyword = new CTL_KeywordObject(); mKeywords.Add(baseKeyword); baseKeyword.Key = "TODO"; baseKeyword.Color = new Color(.75f, 1f, .75f); //CTL_Tools.GenerateRandomKeywordColor(); baseKeyword = new CTL_KeywordObject(); mKeywords.Add(baseKeyword); baseKeyword.Key = "VISUAL"; baseKeyword.Color = new Color(1f, .6f, 1f); //CTL_Tools.GenerateRandomKeywordColor(); baseKeyword = new CTL_KeywordObject(); mKeywords.Add(baseKeyword); baseKeyword.Key = "OPTIM"; baseKeyword.Color = new Color(.75f, .75f, 1f); //CTL_Tools.GenerateRandomKeywordColor(); baseKeyword = new CTL_KeywordObject(); mKeywords.Add(baseKeyword); baseKeyword.Key = "FIX"; baseKeyword.Color = new Color(1f, .5f, .5f); //CTL_Tools.GenerateRandomKeywordColor(); baseKeyword = new CTL_KeywordObject(); mKeywords.Add(baseKeyword); baseKeyword.Key = "AUDIO"; baseKeyword.Color = new Color(1f, 1f, .5f); //CTL_Tools.GenerateRandomKeywordColor(); CTL_Settings.sShouldSave = true; } }
public bool KeywordModified(CTL_KeywordObject modifiedObj, bool modifNeedRefreshList) { CTL_Settings.sShouldSave = true; if (modifNeedRefreshList) { CTL_MainWindow.sNeedRefreshAuto = true; } /* * for (int i = 0; i < mKeywords.Count; i++) * { * if (mKeywords[i].SimilarKey(modifiedObj)) * { * modifiedObj.Valid = false; * break; * } * }*/ ValidateKeywords(); return(modifiedObj.Valid); }
public static CTL_KeywordObject LoadFromString(string str) { CTL_KeywordObject obj = new CTL_KeywordObject(); string[] splitted = str.Split(SEPARATOR); try { obj.Key = splitted[0]; ColorUtility.TryParseHtmlString(splitted[1], out obj.mColor); bool.TryParse(splitted[2], out obj.mVisible); bool.TryParse(splitted[3], out obj.mValid); if (obj.mColor.a == 0) { obj.mColor.a = 1; } } catch (Exception) { obj.mValid = false; } return(obj); }
//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 bool SimilarKey(CTL_KeywordObject other) { return((CTL_Settings.CaseSensitive && Key == other.Key) || (!CTL_Settings.CaseSensitive && Key.ToLower() == other.Key.ToLower())); }
public int GetKeywordId(CTL_KeywordObject obj) { return(mKeywords.IndexOf(obj)); }