protected Vector2 FileListView(GUIContent label, Vector2 scrollPos, FilterDelegate filter, ChangeTypeDelegate changeTypeFetcher, WholeFileCommand cmd, ListSelectionState selectionCache) { int id = GUIUtility.GetControlID(FocusType.Passive); ListView state = (ListView)GUIUtility.GetStateObject(typeof(ListView), id); state.controlID = id; state.selection = selectionCache; Event current = Event.current; bool isChanged = false; GUILayout.Label(label, GitStyles.BoldLabel, GUIHelper.NoExpandWidth); Rect listPosition = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GitStyles.FileListBox); if (changes != null) { for (int i = 0; i < changes.Length; i++) { if (filter(changes[i])) { isChanged = isChanged || ShowFile(state, changes[i].path, changeTypeFetcher(changes[i]), cmd); } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); switch (current.type) { case EventType.MouseDown: if (listPosition.Contains(current.mousePosition)) { GUIUtility.hotControl = id; GUIUtility.keyboardControl = id; current.Use(); } else { if (GUIUtility.keyboardControl == id) { GUIUtility.keyboardControl = 0; } } break; case EventType.MouseUp: if (GUIUtility.hotControl == id) { // Done dragging... GUIUtility.hotControl = 0; current.Use(); } break; } state.hasFocus = GUIUtility.keyboardControl == id; if (!state.hasFocus) { state.selection.Clear(); } if (isChanged) { GUI.changed = true; current.Use(); } return(scrollPos); }
protected bool ShowFile(ListView state, string path, GitWrapper.ChangeType status, WholeFileCommand cmd) { Event current = Event.current; bool isChanged = false; bool isSelected = state.selection.IsSelected(path); GUIStyle style = isSelected ? (panelHasFocus && state.hasFocus ? GitStyles.FileLabelSelected : GitStyles.FileLabelSelectedUnfocused) : GitStyles.FileLabel; GUIContent tmp = null; if(!iconCache.ContainsKey(path)) { tmp = new GUIContent() { image = AssetDatabase.GetCachedIcon(path), text = null }; if(tmp.image == null) tmp.image = DEFAULT_FILE_ICON; iconCache[path] = tmp; } tmp = (GUIContent)iconCache[path]; GUILayout.BeginHorizontal(); GUILayout.Label(tmp, style, ICON_WIDTH, ITEM_HEIGHT); Rect iconPosition = GUILayoutUtility.GetLastRect(); Color c = GUI.contentColor; GUI.contentColor = ColorForChangeType(status); Rect labelPosition = EditorGUILayout.BeginVertical(style, MAX_ITEM_HEIGHT); GUILayout.FlexibleSpace(); GUILayout.Label(path, style); GUILayout.Space(ITEM_BASELINE); EditorGUILayout.EndVertical(); GUI.contentColor = c; GUILayout.EndHorizontal(); if(current.type == EventType.MouseDown) { if(iconPosition.Contains(current.mousePosition)) { isChanged = true; cmd(status, path); state.selection.Unselect(path); } else if(labelPosition.Contains(current.mousePosition)) { isChanged = true; isSelected = !isSelected; bool addToSelection = false, rangeSelection = false; if(Event.current.command && Application.platform == RuntimePlatform.OSXEditor) addToSelection = true; else if(Event.current.control && Application.platform == RuntimePlatform.WindowsEditor) addToSelection = true; if(Event.current.shift) rangeSelection = true; if(!addToSelection && !rangeSelection) state.selection.Clear(); state.selection.Set(path, isSelected); // TODO: For range selection we need the list of files, index of last selection, etc. } } return isChanged; }
protected bool ShowFile(ListView state, string path, GitWrapper.ChangeType status, WholeFileCommand cmd) { Event current = Event.current; bool isChanged = false; bool isSelected = state.selection.IsSelected(path); GUIStyle style = isSelected ? (panelHasFocus && state.hasFocus ? GitStyles.FileLabelSelected : GitStyles.FileLabelSelectedUnfocused) : GitStyles.FileLabel; GUIContent tmp = null; if (!iconCache.ContainsKey(path)) { tmp = new GUIContent() { image = AssetDatabase.GetCachedIcon(path), text = null }; if (tmp.image == null) { tmp.image = DEFAULT_FILE_ICON; } iconCache[path] = tmp; } tmp = (GUIContent)iconCache[path]; GUILayout.BeginHorizontal(); GUILayout.Label(tmp, style, ICON_WIDTH, ITEM_HEIGHT); Rect iconPosition = GUILayoutUtility.GetLastRect(); Color c = GUI.contentColor; GUI.contentColor = ColorForChangeType(status); Rect labelPosition = EditorGUILayout.BeginVertical(style, MAX_ITEM_HEIGHT); GUILayout.FlexibleSpace(); GUILayout.Label(path, style); GUILayout.Space(ITEM_BASELINE); EditorGUILayout.EndVertical(); GUI.contentColor = c; GUILayout.EndHorizontal(); if (current.type == EventType.MouseDown) { if (iconPosition.Contains(current.mousePosition)) { isChanged = true; cmd(status, path); state.selection.Unselect(path); } else if (labelPosition.Contains(current.mousePosition)) { isChanged = true; isSelected = !isSelected; bool addToSelection = false, rangeSelection = false; if (Event.current.command && Application.platform == RuntimePlatform.OSXEditor) { addToSelection = true; } else if (Event.current.control && Application.platform == RuntimePlatform.WindowsEditor) { addToSelection = true; } if (Event.current.shift) { rangeSelection = true; } if (!addToSelection && !rangeSelection) { state.selection.Clear(); } state.selection.Set(path, isSelected); // TODO: For range selection we need the list of files, index of last selection, etc. } } return(isChanged); }
protected Vector2 FileListView(GUIContent label, Vector2 scrollPos, FilterDelegate filter, ChangeTypeDelegate changeTypeFetcher, WholeFileCommand cmd, ListSelectionState selectionCache) { int id = GUIUtility.GetControlID(FocusType.Passive); ListView state = (ListView)GUIUtility.GetStateObject(typeof(ListView), id); state.controlID = id; state.selection = selectionCache; Event current = Event.current; bool isChanged = false; GUILayout.Label(label, GitStyles.BoldLabel, GUIHelper.NoExpandWidth); Rect listPosition = EditorGUILayout.BeginVertical(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GitStyles.FileListBox); if(changes != null) { for(int i = 0; i < changes.Length; i++) { if(filter(changes[i])) { isChanged = isChanged || ShowFile(state, changes[i].path, changeTypeFetcher(changes[i]), cmd); } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); switch(current.type) { case EventType.MouseDown: if(listPosition.Contains(current.mousePosition)) { GUIUtility.hotControl = id; GUIUtility.keyboardControl = id; current.Use(); } else { if(GUIUtility.keyboardControl == id) { GUIUtility.keyboardControl = 0; } } break; case EventType.MouseUp: if(GUIUtility.hotControl == id) { // Done dragging... GUIUtility.hotControl = 0; current.Use(); } break; } state.hasFocus = GUIUtility.keyboardControl == id; if(!state.hasFocus) { state.selection.Clear(); } if(isChanged) { GUI.changed = true; current.Use(); } return scrollPos; }