File size: 10,643 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | using UnityEditor;
using UnityEngine;
using Codice.Client.BaseCommands.EventTracking;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.Diff;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.Tool;
namespace Unity.PlasticSCM.Editor.Views.Diff
{
internal class DiffTreeViewMenu
{
internal interface IMetaMenuOperations
{
bool SelectionHasMeta();
void DiffMeta();
void HistoryMeta();
}
internal DiffTreeViewMenu(
IDiffTreeViewMenuOperations operations,
IMetaMenuOperations metaMenuOperations)
{
mOperations = operations;
mMetaMenuOperations = metaMenuOperations;
BuildComponents();
}
internal void Popup()
{
GenericMenu menu = new GenericMenu();
UpdateMenuItems(menu);
menu.ShowAsContext();
}
internal bool ProcessKeyActionIfNeeded(Event e)
{
DiffTreeViewMenuOperations operationToExecute = GetMenuOperation(e);
if (operationToExecute == DiffTreeViewMenuOperations.None)
return false;
SelectedDiffsGroupInfo info =
mOperations.GetSelectedDiffsGroupInfo();
DiffTreeViewMenuOperations operations =
DiffTreeViewMenuUpdater.GetAvailableMenuOperations(info);
if (!operations.HasFlag(operationToExecute))
return false;
ProcessMenuOperation(operationToExecute);
return true;
}
void SaveRevisionAsMenuItem_Click()
{
mOperations.SaveRevisionAs();
}
void DiffMenuItem_Click()
{
mOperations.Diff();
}
void DiffMetaMenuItem_Click()
{
mMetaMenuOperations.DiffMeta();
}
void HistoryMenuItem_Click()
{
mOperations.History();
}
void HistoryMetaMenuItem_Click()
{
mMetaMenuOperations.HistoryMeta();
}
void RevertMenuItem_Click()
{
mOperations.RevertChanges();
}
void UndeleteMenuItem_Click()
{
mOperations.Undelete();
}
void UndeleteToSpecifiedPathMenuItem_Click()
{
mOperations.UndeleteToSpecifiedPaths();
}
void UpdateMenuItems(GenericMenu menu)
{
SelectedDiffsGroupInfo groupInfo =
mOperations.GetSelectedDiffsGroupInfo();
DiffTreeViewMenuOperations operations =
DiffTreeViewMenuUpdater.GetAvailableMenuOperations(groupInfo);
if (operations == DiffTreeViewMenuOperations.None)
{
menu.AddDisabledItem(GetNoActionMenuItemContent());
return;
}
bool isMultipleSelection = groupInfo.SelectedItemsCount > 1;
bool selectionHasMeta = mMetaMenuOperations.SelectionHasMeta();
if (operations.HasFlag(DiffTreeViewMenuOperations.SaveAs))
menu.AddItem(mSaveRevisionAsMenuItemContent, false, SaveRevisionAsMenuItem_Click);
if (operations.HasFlag(DiffTreeViewMenuOperations.Diff))
menu.AddItem(mDiffMenuItemContent, false, DiffMenuItem_Click);
else
menu.AddDisabledItem(mDiffMenuItemContent, false);
if (mMetaMenuOperations.SelectionHasMeta())
{
if (operations.HasFlag(DiffTreeViewMenuOperations.Diff))
menu.AddItem(mDiffMetaMenuItemContent, false, DiffMetaMenuItem_Click);
else
menu.AddDisabledItem(mDiffMetaMenuItemContent);
}
menu.AddSeparator(string.Empty);
if (operations.HasFlag(DiffTreeViewMenuOperations.History))
menu.AddItem(mViewHistoryMenuItemContent, false, HistoryMenuItem_Click);
else
menu.AddDisabledItem(mViewHistoryMenuItemContent, false);
if (mMetaMenuOperations.SelectionHasMeta())
{
if (operations.HasFlag(DiffTreeViewMenuOperations.History))
menu.AddItem(mViewHistoryMetaMenuItemContent, false, HistoryMetaMenuItem_Click);
else
menu.AddDisabledItem(mViewHistoryMetaMenuItemContent, false);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.RevertChanges))
{
menu.AddSeparator(string.Empty);
mRevertMenuItemContent.text = GetRevertMenuItemText(
isMultipleSelection,
selectionHasMeta);
menu.AddItem(mRevertMenuItemContent, false, RevertMenuItem_Click);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.Undelete) ||
operations.HasFlag(DiffTreeViewMenuOperations.UndeleteToSpecifiedPaths))
{
menu.AddSeparator(string.Empty);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.Undelete))
{
mUndeleteMenuItemContent.text = GetUndeleteMenuItemText(
isMultipleSelection,
selectionHasMeta);
menu.AddItem(mUndeleteMenuItemContent, false, UndeleteMenuItem_Click);
}
if (operations.HasFlag(DiffTreeViewMenuOperations.UndeleteToSpecifiedPaths))
{
mUndeleteToSpecifiedPathMenuItemContent.text = GetUndeleteToSpecifiedPathMenuItemText(
isMultipleSelection,
selectionHasMeta);
menu.AddItem(mUndeleteToSpecifiedPathMenuItemContent, false, UndeleteToSpecifiedPathMenuItem_Click);
}
}
GUIContent GetNoActionMenuItemContent()
{
if (mNoActionMenuItemContent == null)
{
mNoActionMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.
Name.NoActionMenuItem));
}
return mNoActionMenuItemContent;
}
static string GetRevertMenuItemText(
bool isMultipleSelection,
bool selectionHasMeta)
{
if (selectionHasMeta && !isMultipleSelection)
return PlasticLocalization.GetString(PlasticLocalization.Name.UndoThisChangePlusMeta);
return isMultipleSelection ?
PlasticLocalization.GetString(PlasticLocalization.Name.UndoSelectedChanges) :
PlasticLocalization.GetString(PlasticLocalization.Name.UndoThisChange);
}
static string GetUndeleteMenuItemText(
bool isMultipleSelection,
bool selectionHasMeta)
{
if (selectionHasMeta && !isMultipleSelection)
return PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisionPlusMeta);
return isMultipleSelection ?
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteSelectedRevisions) :
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisions);
}
static string GetUndeleteToSpecifiedPathMenuItemText(
bool isMultipleSelection,
bool selectionHasMeta)
{
if (selectionHasMeta && !isMultipleSelection)
return PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisionPlusMetaPath);
return isMultipleSelection ?
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteSelectedRevisionsPaths) :
PlasticLocalization.GetString(PlasticLocalization.Name.UndeleteRevisionPath);
}
void ProcessMenuOperation(DiffTreeViewMenuOperations operationToExecute)
{
if (operationToExecute == DiffTreeViewMenuOperations.SaveAs)
{
SaveRevisionAsMenuItem_Click();
return;
}
if (operationToExecute == DiffTreeViewMenuOperations.Diff)
{
DiffMenuItem_Click();
return;
}
if (operationToExecute == DiffTreeViewMenuOperations.History)
{
HistoryMenuItem_Click();
}
}
static DiffTreeViewMenuOperations GetMenuOperation(Event e)
{
if (Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.D))
return DiffTreeViewMenuOperations.Diff;
if (Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.H))
return DiffTreeViewMenuOperations.History;
return DiffTreeViewMenuOperations.None;
}
void BuildComponents()
{
mSaveRevisionAsMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMenuItemSaveRevisionAs));
mDiffMenuItemContent = new GUIContent(
string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMenuItem),
GetPlasticShortcut.ForDiff()));
mDiffMetaMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMetaMenuItem));
mViewHistoryMenuItemContent = new GUIContent(
string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.ViewHistoryMenuItem),
GetPlasticShortcut.ForHistory()));
mViewHistoryMetaMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.ViewHistoryMetaMenuItem));
mRevertMenuItemContent = new GUIContent();
mUndeleteMenuItemContent = new GUIContent();
mUndeleteToSpecifiedPathMenuItemContent = new GUIContent();
}
GUIContent mNoActionMenuItemContent;
GUIContent mSaveRevisionAsMenuItemContent;
GUIContent mDiffMenuItemContent;
GUIContent mDiffMetaMenuItemContent;
GUIContent mViewHistoryMenuItemContent;
GUIContent mViewHistoryMetaMenuItemContent;
GUIContent mRevertMenuItemContent;
GUIContent mUndeleteMenuItemContent;
GUIContent mUndeleteToSpecifiedPathMenuItemContent;
readonly IDiffTreeViewMenuOperations mOperations;
readonly IMetaMenuOperations mMetaMenuOperations;
}
} |