using UnityEngine; using UnityEditor; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Perforce.P4; namespace P4Connect { public class ChangeListEntry : IComparable { public Changelist change; public ChangeListEntry(Changelist c) { change = c; show_children = true; } public void Refresh(Connection con) { change.initialize(con); } public int CompareTo(ChangeListEntry entry) { return this.change.Id.CompareTo(entry.change.Id); } private bool show_children; public bool ShowChildren { get { return show_children; } set { show_children = value; } } public static string ChangeIdToString(int id) { if (id <= 0) return "default"; return id.ToString(); } } public class ChangeLists : EditorWindow { const float spaceBeforeIcon = 8.0f; const float iconSize = 20.0f; const float col_width_change = 50.0f; const float col_width_desc = 250f; const float col_width_files = 50f; const float col_width_shelves = 50f; const float col_width_user = 100f; const float col_width_workspace = 100f; const double DoubleClickTime = 500; // ms static ChangeLists _CurrentInstance; Dictionary opened; // Add menu named "Perforce" to the Window menu [MenuItem("Window/Perforce Changes", false, 1000)] public static void ShowWindow() { // Get existing open window or if none, make a new one: ChangeLists window = EditorWindow.GetWindow(typeof(ChangeLists), false, "P4Changes") as ChangeLists; //window.title = "Perforce Changes"; //window.name = "P4Changes"; } public static void UpdateDisplay() { if (_CurrentInstance != null) { if (Config.PerforceEnabled) { _CurrentInstance.CheckInit(); } else { _CurrentInstance.Clear(); } _CurrentInstance.Repaint(); } } Vector2 _ScrollVector; string _ChangeListDescription; public ChangeLists() { Init(); } void Init() { _CurrentInstance = this; opened = new Dictionary(); ChangeManager.GetInstance.RefreshAll(); } void CheckInit() { if (_CurrentInstance != this) { Init(); } } public void OnDestroy() { _CurrentInstance = null; Clear(); } void Clear() { _ScrollVector = Vector2.zero; } void OnOperationPerformed(PerforceConnection aConnection) { ChangeManager.GetInstance.RefreshAll(); Repaint(); } int fileCnt(Changelist change) { if (change.Files != null) return (change.Files.Count); return 0; } int shelveCount(Changelist change) { if (change.ShelvedFiles != null) return (change.ShelvedFiles.Count); return 0; } string changeIdString(int change_id) { if (change_id < 0) return "default"; return change_id.ToString(); } void OnGUI() { CheckInit(); Event evt = Event.current; // Header GUIStyle changelistStyle = new GUIStyle(EditorStyles.toolbarButton); changelistStyle.normal.textColor = Color.grey; changelistStyle.alignment = TextAnchor.MiddleLeft; // Buttons GUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUI.BeginDisabledGroup(!Config.ValidConfiguration); GUILayout.Label("Pending Changelists ", changelistStyle, GUILayout.Width(200.0f)); if (GUILayout.Button("Refresh", EditorStyles.toolbarButton)) { ChangeManager.GetInstance.RefreshAll(); } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Help", EditorStyles.toolbarButton)) { System.Diagnostics.Process.Start("http://www.perforce.com/perforce/doc.current/manuals/p4connectguide/index.html"); } if (GUILayout.Button("Settings...", EditorStyles.toolbarButton)) { Config.ShowWindow(); } GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(!Config.ValidConfiguration); GUILayout.BeginHorizontal(); _ScrollVector = GUILayout.BeginScrollView(_ScrollVector); // Header GUIStyle HeaderStyle = new GUIStyle(EditorStyles.miniButtonMid); HeaderStyle.normal.textColor = Color.white; HeaderStyle.padding = new RectOffset(0, 0, 0, 0); HeaderStyle.margin = new RectOffset(0, 0, 0, 0); HeaderStyle.overflow = new RectOffset(0, 0, 0, 0); GUIStyle HeaderButtons = new GUIStyle(EditorStyles.miniButtonMid); HeaderButtons.alignment = TextAnchor.MiddleLeft; HeaderStyle.padding = new RectOffset(0, 0, 0, 2); HeaderButtons.margin = new RectOffset(0, 0, 0, 0); HeaderButtons.overflow = new RectOffset(0, 0, 0, 2); GUIStyle ToggleStyle = new GUIStyle(EditorStyles.toggle); RectOffset margin = ToggleStyle.margin; margin.top = 0; margin.bottom = 0; ToggleStyle.margin = margin; GUIStyle normalStyle = new GUIStyle(GUIStyle.none); normalStyle.padding = new RectOffset(0, 0, 0, 0); normalStyle.margin = new RectOffset(0, 0, 0, 0); normalStyle.border = new RectOffset(0, 0, 0, 0); GUILayout.BeginHorizontal(HeaderStyle); { if (GUILayout.Button("", HeaderButtons, GUILayout.Width(spaceBeforeIcon))) { } if (GUILayout.Button("", HeaderButtons, GUILayout.Width(iconSize))) { } if (GUILayout.Button("ChangeId", HeaderButtons, GUILayout.Width(col_width_change))) { } if (GUILayout.Button("Description", HeaderButtons, GUILayout.MinWidth(col_width_desc))) { } GUILayout.FlexibleSpace(); if (GUILayout.Button("Files", HeaderButtons, GUILayout.Width(col_width_files))) { } if (GUILayout.Button("Shelves", HeaderButtons, GUILayout.Width(col_width_shelves))) { } if (GUILayout.Button("User", HeaderButtons, GUILayout.Width(col_width_user))) { } if (GUILayout.Button("Workspace", HeaderButtons, GUILayout.Width(col_width_workspace))) { } GUILayout.Space(32.0f); } GUILayout.EndHorizontal(); if (Config.PerforceEnabled) { IList _changes = ChangeManager.GetInstance.Changelists; if (_changes.Count <= 0) { GUILayout.BeginHorizontal(normalStyle); GUILayout.Label("no changelists", GUILayout.Width(400.0f)); GUILayout.EndHorizontal(); } else { // Add all the items foreach (Changelist change in _changes) { if (!opened.ContainsKey(change.Id)) { opened.Add(change.Id, false); } GUILayout.BeginHorizontal(normalStyle); Rect position = GUILayoutUtility.GetRect(spaceBeforeIcon, spaceBeforeIcon, iconSize, iconSize, normalStyle); opened[change.Id] = EditorGUI.Foldout(position, opened[change.Id], "", true); // Fetch the changelist's icon and draw it Texture changeIcon = Icons.GetChangelistIcon(change); GUILayout.Label(changeIcon, GUILayout.Width(iconSize), GUILayout.Height(iconSize)); GUILayout.Label(changeIdString(change.Id), GUILayout.Width(col_width_change)); GUILayout.Label(change.Description, GUILayout.Width(col_width_desc)); GUILayout.FlexibleSpace(); int fcnt = fileCnt(change); int scnt = shelveCount(change); GUILayout.Label(fcnt.ToString(), GUILayout.Width(col_width_files)); GUILayout.Label(scnt.ToString(), GUILayout.Width(col_width_shelves)); GUILayout.Label(change.OwnerName, GUILayout.MinWidth(col_width_user)); GUILayout.Label(change.ClientId, GUILayout.Width(col_width_workspace)); GUILayout.EndHorizontal(); if (opened[change.Id]) { foreach (FileMetaData fd in change.Files) { GUILayout.BeginHorizontal(normalStyle); GUILayout.Space(spaceBeforeIcon); GUILayout.Label(fd.DepotPath.ToString()); GUILayout.FlexibleSpace(); GUILayout.Label(fd.Action.ToString()); GUILayout.EndHorizontal(); } if (change.Shelved && change.ShelvedFiles != null) { GUILayout.Label("Shelves:"); foreach (ShelvedFile sf in change.ShelvedFiles) { GUILayout.BeginHorizontal(normalStyle); GUILayout.Space(spaceBeforeIcon); GUILayout.Label(sf.Path.ToString()); GUILayout.FlexibleSpace(); GUILayout.Label(sf.Action.ToString()); GUILayout.EndHorizontal(); } } } } } } GUILayout.EndScrollView(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); if (!Config.PerforceEnabled) { EditorGUILayout.HelpBox("Perforce integration is disabled", MessageType.Info); } else if (!Config.ValidConfiguration) { EditorGUILayout.HelpBox("Change Lists are unavailable because your settings are invalid.\nPlease go to Edit->Perforce Settings to update them.", MessageType.Warning); } EditorGUI.BeginDisabledGroup(!Config.ValidConfiguration); GUILayout.Label("Description", EditorStyles.boldLabel); GUI.SetNextControlName("DescriptionBox"); _ChangeListDescription = EditorGUILayout.TextArea(_ChangeListDescription, GUILayout.MinHeight(50.0f)); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); //int assetCount = 0; //int fileCount = 0; //GetSelectedCounts(out assetCount, out fileCount); //GUILayout.Label(assetCount.ToString() + " assets selected (" + fileCount.ToString() + " files)"); //EditorGUI.BeginDisabledGroup(_ChangeListDescription == null || _ChangeListDescription.Length == 0 ); //if (GUILayout.Button("Submit Selected")) //{ // SubmitFiles(); //} //EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); // Handle key events if (evt.isKey) { if (evt.type == EventType.KeyDown) { if (evt.keyCode == KeyCode.Return) { //// Toggle all selected changes to the new state of the selected item //bool itemChecked = _CheckedFiles[_LastSelectedChange.EffectiveFilePath]; //foreach (var ch in _CurrentSelectedChanges) //{ // _CheckedFiles[ch.EffectiveFilePath] = !itemChecked; //} evt.Use(); Repaint(); } else if (evt.keyCode == KeyCode.DownArrow) { // Update highlight //_LastSelectedChange = GetNextPendingChange(_LastSelectedChange); //// Handle shift selection //if ((evt.modifiers & EventModifiers.Shift) == 0 && (evt.modifiers & EventModifiers.Control) == 0) //{ // _CurrentSelectedChanges.Clear(); //} //_CurrentSelectedChanges.Add(_LastSelectedChange); evt.Use(); Repaint(); } else if (evt.keyCode == KeyCode.UpArrow) { //_LastSelectedChange = GetPrevPendingChange(_LastSelectedChange); //if ((evt.modifiers & EventModifiers.Shift) == 0 && (evt.modifiers & EventModifiers.Control) == 0) //{ // _CurrentSelectedChanges.Clear(); //} //_CurrentSelectedChanges.Add(_LastSelectedChange); evt.Use(); Repaint(); } else if (evt.keyCode == KeyCode.A) { //_CurrentSelectedChanges.Clear(); //foreach (var change in _PendingChanges) //{ // _CurrentSelectedChanges.Add(change); //} evt.Use(); Repaint(); } else if (evt.keyCode == KeyCode.D) { //reach (var change in _CurrentSelectedChanges) // // Utils.LaunchDiffAgainstHaveRev(change.EffectiveFilePath); // evt.Use(); Repaint(); } else if (evt.keyCode == KeyCode.I) { //HashSet newSelection = new HashSet(); //foreach (var change in _PendingChanges) //{ // if (!_CurrentSelectedChanges.Contains(change)) // { // newSelection.Add(change); // } //} //_CurrentSelectedChanges = newSelection; evt.Use(); Repaint(); } } } } } }