|
| 1 | +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. |
| 2 | + |
| 3 | +#if UNITY_EDITOR |
| 4 | +using System; |
| 5 | +using System.IO; |
| 6 | +using UnityEditor; |
| 7 | + |
| 8 | +namespace CandyCoded.GitStatus |
| 9 | +{ |
| 10 | + |
| 11 | + public static class GitMenuItems |
| 12 | + { |
| 13 | + |
| 14 | + private const int PRIORITY = 5000; |
| 15 | + |
| 16 | + private static string GetSelectedPath() |
| 17 | + { |
| 18 | + |
| 19 | + return Path.Combine(Environment.CurrentDirectory, AssetDatabase.GetAssetPath(Selection.activeObject)); |
| 20 | + |
| 21 | + } |
| 22 | + |
| 23 | + [MenuItem("Assets/Discard Changes", false, PRIORITY)] |
| 24 | + private static void DiscardChanges() |
| 25 | + { |
| 26 | + |
| 27 | + Git.DiscardChanges(GetSelectedPath()); |
| 28 | + |
| 29 | + } |
| 30 | + |
| 31 | + [MenuItem("Assets/Discard Changes", true, PRIORITY)] |
| 32 | + private static bool ValidateDiscardChanges() |
| 33 | + { |
| 34 | + |
| 35 | + return Selection.activeObject && File.Exists(GetSelectedPath()); |
| 36 | + |
| 37 | + } |
| 38 | + |
| 39 | + [MenuItem("Assets/Discard All Changes", false, PRIORITY)] |
| 40 | + private static void DiscardAllChanges() |
| 41 | + { |
| 42 | + |
| 43 | + if (EditorUtility.DisplayDialog( |
| 44 | + "Discard all changes", |
| 45 | + $"Are you sure you want to discard all changes in {Selection.activeObject.name}?", |
| 46 | + "Yes", |
| 47 | + "Cancel")) |
| 48 | + { |
| 49 | + |
| 50 | + Git.DiscardChanges(GetSelectedPath()); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + [MenuItem("Assets/Discard All Changes", true, PRIORITY)] |
| 57 | + private static bool ValidateDiscardAllChanges() |
| 58 | + { |
| 59 | + |
| 60 | + return Selection.activeObject && Directory.Exists(GetSelectedPath()); |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | +} |
| 67 | + |
| 68 | +#endif |
0 commit comments