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<ChangeListEntry> { 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<int, bool> opened; // Add menu named "Perforce Changes" 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.ValidConfiguration) { _CurrentInstance.CheckInit(); } else { _CurrentInstance.Clear(); } _CurrentInstance.Repaint(); } } Vector2 _ScrollVector; string _ChangeListDescription; public ChangeLists() { Init(); } void Init() { _CurrentInstance = this; opened = new Dictionary<int, bool>(); ChangeManager.RefreshAll(); } void CheckInit() { if (_CurrentInstance != this) { Init(); } } public void OnDestroy() { _CurrentInstance = null; Clear(); } void Clear() { _ScrollVector = Vector2.zero; } void OnOperationPerformed(PerforceConnection aConnection) { ChangeManager.RefreshAll(); Repaint(); } void Update() { if (!Config.ValidConfiguration) { this.Close(); Debug.Log("Closed ChangeLists window because Connection is invalid"); } } 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.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.ValidConfiguration) { IList<Changelist> _changes = ChangeManager.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<PendingAssetAndMeta> newSelection = new HashSet<PendingAssetAndMeta>(); //foreach (var change in _PendingChanges) //{ // if (!_CurrentSelectedChanges.Contains(change)) // { // newSelection.Add(change); // } //} //_CurrentSelectedChanges = newSelection; evt.Use(); Repaint(); } } } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 21852 | cswiedler | Branch //guest/cswiedler/p4connect | ||
//guest/perforce_software/p4connect/dev/shelves/src/P4Connect/P4Connect/P4Connect.ChangeLists.cs | |||||
#1 | 17331 | Norman Morse | Dev branch for Shelves | ||
//guest/perforce_software/p4connect/main/src/P4Connect/P4Connect/P4Connect.ChangeLists.cs | |||||
#1 | 16209 | Norman Morse | Move entire source tree into "main" branch so workshop code will act correctly. | ||
//guest/perforce_software/p4connect/src/P4Connect/P4Connect/P4Connect.ChangeLists.cs | |||||
#4 | 14193 | Norman Morse |
GA.7 release Refactor Pending Changes Resolve Submit issues. Fixed Menu entries. Handle mismatched file and meta states. |
||
#3 | 12568 | Norman Morse | Fixed some error handling during Perforce Configuration | ||
#2 | 12565 | Norman Morse |
Integrated from Dev Branch Made ChangeManager into Static Class. Improved close window behavior for when connection is invalid Fixed localOpenFiles not updating on submit |
||
#1 | 12512 | Norman Morse | Integrate from Dev branch, preparing for Beta3 release | ||
//guest/norman_morse/dev/p4connect/src/P4Connect/P4Connect/P4Connect.ChangeLists.cs | |||||
#3 | 12501 | Norman Morse |
Rewrote Configuration Window. Provided buttons to read values and to save configurations. Removed P4Config settings, replaced with P4Config button and reports to Debug.Log() Removed SaveConfigurationAsset Setting, replaced with "Save as Asset" button. Made Connection Configuration read only while connected. Made dialogs disappear if they become disconnected during OnGui() Bumped Beta Value. |
||
#2 | 12480 | Norman Morse |
Fixed crash in logging. Worked on UI issues. Cleaned up some connection usage. Still looking for the problem with pending changes. |
||
#1 | 12445 | Norman Morse |
Integrated log4net and nunit into P4Connect. Still need cleanup and debugging, good enough for dev tree Also added ChangeManager and ChangeLists Classes for future use with multiple changes. |