using UnityEditor; using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Perforce.P4; using log4net; namespace P4Connect { public static class Menus { private static readonly ILog log = LogManager.GetLogger(typeof(Menus)); // Cached values for the menu validation pass public static List<string> SelectedPaths; public static bool MenuValid; private static string _lastSelection; private static bool _serverRequest; /// <summary> /// Menu Validation Common Function /// Caches assetPath list in SelectedPaths /// </summary> /// <returns>true if this menu is enabled</returns> public static bool MenuValidation() { if (!Config.CheckStatusForMenus || ! Config.PerforceEnabled) { return false; } SelectedPaths = Utils.GetSelectedAssetPaths().ToList(); string pathNames = Logger.StringEnumerationToString(SelectedPaths); if (pathNames != _lastSelection) { // log.Debug("Selection Now: " + pathNames); MenuValid = false; _lastSelection = pathNames; if (SelectedPaths.Count < Config.CheckStatusForMenusMaxItems) { if (!_serverRequest) { SelectedPaths.PrepareAssetStatuses(); // request that any Defaults get updated (async request) _serverRequest = true; // Only one request for all Menu Validations } MenuValid = true; Icons.UpdateDisplay(); } } return MenuValid; } #region Perforce Menus [MenuItem("Assets/Perforce/Refresh", true, 100)] public static bool ProjectViewCanRefresh() { return Config.ValidConfiguration; } [MenuItem("Assets/Perforce/Refresh", false, 100)] public static void ProjectViewRefresh() { // This command will go to the server to re-download everything in the selection, synchronously Engine.PerformConnectionOperation(con => { AssetStatusCache.GetAssetMetaData(con, Utils.GetSelectedAssetPaths().AddDirectoryWildcards()); }, false); Icons.UpdateDisplay(); } [MenuItem("Assets/Perforce/Add to Depot", true, 100)] public static bool ProjectViewCanAddToDepot() { if (! MenuValidation()) return false; foreach (string t in SelectedPaths) { if (Utils.IsDirectory(t) || AssetStatusCache.GetCachedAssetStatus(t).IsAddable()) { return true; } } return false; } [MenuItem("Assets/Perforce/Add to Depot", false, 100)] public static void ProjectViewAddToDepot() { if (!Config.ValidConfiguration) return; List<string> addFiles = new List<string>(); // Grab the statuses of all the items in the selection // If any directories (wildcards) explode into child paths // For each entry, check file status to see if it is addable foreach (string t in SelectedPaths.ExplodeAssetPaths().InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); // Add files not in the depot, add files which are in Perforce but deleted previously, if (status.IsAddable()) { addFiles.Add(t); } } var addFilesArray = addFiles.ToArray(); var count = Engine.CreateAssets(addFilesArray).Count; Debug.Log("Add to Depot - " + (count > 0 ? count.ToString() : "No") + " Assets created"); } [MenuItem("Assets/Perforce/Checkout", true, 100)] public static bool ProjectViewCanCheckoutAsset() { if (!MenuValidation()) return false; foreach (string t in SelectedPaths) { if (Utils.IsDirectory(t) || AssetStatusCache.GetCachedAssetStatus(t).IsEditable()) { return true; } } return false; } [MenuItem("Assets/Perforce/Checkout", false, 100)] public static void ProjectViewCheckoutAsset() { if (!Config.ValidConfiguration) return; List<string> checkoutFiles = new List<string>(); foreach (string t in SelectedPaths.InitializeAssetStatuses()) { if (Utils.IsDirectory(t) || AssetStatusCache.GetCachedAssetStatus(t).IsEditable()) { checkoutFiles.Add(t); } } var count = Engine.CheckoutAssets(checkoutFiles.ToArray()).Count; Debug.Log("Checkout - " + (count > 0 ? count.ToString() : "No") + " Assets checked out"); } [MenuItem("Assets/Perforce/Lock", true, 100)] public static bool ProjectViewCanLockAsset() { if (!MenuValidation()) return false; foreach (string t in SelectedPaths) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsLockable() || Utils.IsDirectory(t)) { return true; } } return false; } [MenuItem("Assets/Perforce/Lock", false, 100)] public static void ProjectViewLockAsset() { if (!Config.ValidConfiguration) return; List<string> lockFiles = new List<string>(); foreach (string t in SelectedPaths.ExplodeAssetPaths().InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsLockable()) { lockFiles.Add(t); } } var count = Engine.LockAssets(lockFiles.ToArray()).Count; Debug.Log("Lock - " + (count > 0 ? count.ToString() : "No") + " Assets locked"); } [MenuItem("Assets/Perforce/Unlock", true, 100)] public static bool ProjectViewCanUnlockAsset() { if (!MenuValidation()) return false; foreach (string t in SelectedPaths) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsUnlockable() || Utils.IsDirectory(t)) { return true; } } return false; } [MenuItem("Assets/Perforce/Unlock", false, 100)] public static void ProjectViewUnlockAsset() { if (!Config.ValidConfiguration) return; List<string> unlockFiles = new List<string>(); foreach (string t in SelectedPaths.ExplodeAssetPaths().InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsUnlockable()) { unlockFiles.Add(t); } } var count = Engine.UnlockAssets(unlockFiles.ToArray()).Count; Debug.Log("Unlock - " + (count > 0 ? count.ToString() : "No") + " Assets unlocked"); } [MenuItem("Assets/Perforce/Get Latest Revision", true, 100)] public static bool ProjectViewCanGetLatest() { return Config.ValidConfiguration; } [MenuItem("Assets/Perforce/Get Latest Revision", false, 100)] public static void ProjectViewGetLatest() { if (!Config.ValidConfiguration) return; int count = 0; List<string> getLatestFiles = new List<string>(); // Grab all the items in the selection, add directory wildcards if needed var paths = Utils.GetSelectedAssetPaths().AddDirectoryWildcards(); foreach (var f in paths.InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(f); if (status.IsOnServer() || Utils.IsDirectory(f)) { getLatestFiles.Add(f); } } if (getLatestFiles.Any()) { count = Engine.GetLatestAssets(getLatestFiles.ToArray(), false).Count; } Debug.Log("P4Connect - Get Latest Revision - " + (count > 0 ? count.ToString() : "No") + " Assets updated"); } [MenuItem("Assets/Perforce/Force Get Latest Revision", true, 100)] public static bool ProjectViewCanForceGetLatest() { return Config.ValidConfiguration; } [MenuItem("Assets/Perforce/Force Get Latest Revision", false, 100)] public static void ProjectViewForceGetLatest() { if (!Config.ValidConfiguration) return; int count = 0; List<string> getLatestFiles = new List<string>(); // Grab all the items in the selection, add directory wildcards if needed var paths = Utils.GetSelectedAssetPaths().AddDirectoryWildcards(); foreach (var f in paths.InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(f); if (status.IsOnServer() || Utils.IsDirectory(f)) { getLatestFiles.Add(f); } } // Grab the statuses of all the items in the selection if (getLatestFiles.Any()) { // Build a string of the names StringBuilder builder = new StringBuilder(); builder.AppendLine("Are you sure you want to force-get the latest revision of the following assets?"); builder.AppendLine(); foreach (string path in getLatestFiles) { builder.AppendLine(path); } if (EditorUtility.DisplayDialog("P4Connect - Force Get Latest", builder.ToString(), "Yes", "No")) { count = Engine.GetLatestAssets(getLatestFiles.ToArray(), true).Count; } Debug.Log("P4Connect - Force Get Latest Revision - " + (count > 0 ? count.ToString() : "No") + " Assets updated"); } } [MenuItem("Assets/Perforce/Diff against Have-Revision", true, 100)] public static bool ProjectViewCanDiffAsset() { if (!MenuValidation()) return false; foreach (string t in SelectedPaths) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsOnServer() || Utils.IsDirectory(t)) { return true; } } return false; } [MenuItem("Assets/Perforce/Diff against Have-Revision", false, 100)] public static void ProjectViewDiffAsset() { if (!Config.ValidConfiguration) return; List<string> diffFiles = new List<string>(); foreach (string t in SelectedPaths.InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsOnServer() || Utils.IsDirectory(t)) { diffFiles.Add(t); } } foreach (string file in diffFiles) { if (Utils.IsDirectory(file)) Utils.LaunchDiffAgainstHaveRev(Utils.MetaFromAsset(file)); else Utils.LaunchDiffAgainstHaveRev(file); } } [MenuItem("Assets/Perforce/Revert if Unchanged", true, 100)] public static bool ProjectViewCanRevertIfUnchanged() { return ProjectViewCanRevertAsset(); } [MenuItem("Assets/Perforce/Revert if Unchanged", false, 100)] public static void ProjectViewRevertAssetIfUnchanged() { if (!Config.ValidConfiguration) return; List<string> assetsToRevert = new List<string>(); foreach (string t in SelectedPaths.InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsMarked() || Utils.IsDirectory(t)) { assetsToRevert.Add(t); } } int count = Engine.RevertAssets(assetsToRevert.ToArray(), false).Count; Debug.Log("P4Connect - Revert if Unchanged - " + (count > 0 ? count.ToString() : "No") + " Assets reverted"); } [MenuItem("Assets/Perforce/Revert", true, 100)] public static bool ProjectViewCanRevertAsset() { if (!MenuValidation()) return false; foreach (string t in SelectedPaths) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (status.IsMarked() || Utils.IsDirectory(t)) { return true; } } return false; } [MenuItem("Assets/Perforce/Revert", false, 100)] public static void ProjectViewRevertAsset() { if (!Config.ValidConfiguration) return; List<string> revertFiles = new List<string>(); foreach (string t in SelectedPaths.InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (Utils.IsDirectory(t) || status.IsMarked()) { revertFiles.Add(t); } } // Build a string of the names StringBuilder builder = new StringBuilder(); builder.AppendLine("Are you sure you want to revert the following assets?"); builder.AppendLine(); foreach (string path in revertFiles) { builder.AppendLine(path); } if (EditorUtility.DisplayDialog("P4Connect - Revert", builder.ToString(), "Yes", "No")) { var count = Engine.RevertAssets(revertFiles.ToArray(), true).Count; Debug.Log("Revert - " + (count > 0 ? count.ToString() : "No") + " Assets reverted"); } } [MenuItem("Assets/Perforce/Commit...", true, 100)] public static bool ProjectViewCanCommitAsset() { if (!MenuValidation()) return false; foreach (string t in SelectedPaths) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (!Utils.IsDirectory(t) && status.IsMarked() && status.LockState != LockState.TheirLock) { return true; } } return false; } [MenuItem("Assets/Perforce/Commit...", false, 100)] public static void ProjectViewCommitAsset() { if (!Config.ValidConfiguration) return; List<string> commitFiles = new List<string>(); foreach (string t in SelectedPaths.InitializeAssetStatuses()) { var status = AssetStatusCache.GetCachedAssetStatus(t); if (!Utils.IsDirectory(t) && status.IsMarked()) { commitFiles.Add(t); } } var count = commitFiles.Count; Debug.Log("Commit - " + (count > 0 ? count.ToString() : "No") + " Assets to commit"); if (count == 0) return; // Show the pending changes window and select only the files in the commit list PendingChanges window = EditorWindow.GetWindow(typeof(PendingChanges), false, "Perforce") as PendingChanges; if (window != null) window.SelectAssets(commitFiles); } #if DEBUG [MenuItem("Assets/Perforce/Reconcile", false, 100)] public static void ProjectViewReconcile() { List<FileSpec> fsl; // Grab all the items in the selection var paths = Utils.GetSelectedAssetPaths().ToList(); if (paths.Count > 0) { fsl = FileSpec.DepotSpecList(paths.AddDirectoryWildcards().ToArray()).ToList(); } else { fsl = new List<FileSpec> { FileSpec.DepotSpec(Config.DepotProjectRoot) }; } Engine.PerformConnectionOperation(con => { ReconcileCmdFlags flags = ReconcileCmdFlags.AddEditDelete | ReconcileCmdFlags.PreviewOnly; Options options = new Options(flags, -1); //List<FileSpec> fsl = new List<FileSpec> { FileSpec.DepotSpec(Config.DepotProjectRoot) }; IList<ReconcileEntry> entries = Engine.Reconcile(con, fsl, options); if (entries == null) { Debug.Log("No Reconcile Results"); } else { Debug.Log("rs: " + Logger.ReconcileEntryListToString(entries)); foreach (var entry in entries) { string path = entry.ToAssetPath(); AssetStatus stat = AssetStatusCache.GetCachedAssetStatus(path); AssetStatusCache.AssetStatusFromReconcileEntry(stat, entry); Debug.Log("as: " + stat.ToStringNullSafe() ); } } }); } #endif #endregion } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 21852 | cswiedler | Branch //guest/cswiedler/p4connect | ||
//guest/perforce_software/p4connect/main/src/P4Connect/P4Connect/P4Connect.Menus.cs | |||||
#7 | 20581 | Norman Morse |
Add P4Connect.Skin Fixed issues in ChangeManager Renamed ChangeLists to ChangeListsWindow. |
||
#6 | 20275 | Norman Morse |
Update source to match 2016.2 patch 2 release Much thrashing of source during refactor. Proper caching of asset statuses, reducing fstats issued. Some bug fixes by Liz Lam Cleanup of Pending changes, rework of initialization and play/stop play transitions |
||
#5 | 18462 | Norman Morse |
Final Changes needed for 2016.1 release New Icons. New Icon Packaging. Unity 4 compatibility changes. |
||
#4 | 18418 | Norman Morse |
Many changes from the dev branch. Icons are packaged differently. Style Sheet is created / used New ConnectionWizard Dialog New PasswordDialog Generate -a tickets Update version to 2016.1.0.0 |
||
#3 | 16485 | Norman Morse |
Asynchronous status requests Update release notes Minor cleanup |
||
#2 | 16413 | Norman Morse | Code cleanup | ||
#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.Menus.cs | |||||
#8 | 16117 | Norman Morse |
Fix for EditorPrefs related Disconnection. Cleaned up some code. Removed Spurious Comments Initialize Config from within Main |
||
#7 | 15424 | Norman Morse |
Fixed exceptions in Dialogs. Updated release Notes. Added checks to menus for PerforceEnabled |
||
#6 | 15401 | Norman Morse |
Fixed serialization of Config so P4Connect remains connected after a Game Run Cleaned up some menus. |
||
#5 | 15383 | Norman Morse |
Improved Diagnostics, cleaned up unnecessary log output Moved some Dialog Initialization to OnEnable() Fixed Unity 5.1.1 incompatibilities Added Operation support for In Depot Deleted files |
||
#4 | 15244 | Norman Morse |
Better Directory support in "add" "get latest" "refresh" and other commands. Improved Project Root detection Various Bug Fixes and Clean up |
||
#3 | 15079 | Norman Morse |
Rewrote AssetStatusCache to Cache AssetStatuses and FileMetaData Fixed Edge conditions on Engine Operations Change Debug output defaults. Will now Checkout files which request to be "added" but which already exist in perforce. Output P4Connect version to log on initialization. |
||
#2 | 14193 | Norman Morse |
GA.7 release Refactor Pending Changes Resolve Submit issues. Fixed Menu entries. Handle mismatched file and meta states. |
||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |