A game about forced loneliness, made by TACStudios
at master 273 lines 8.2 kB view raw
1using System; 2using System.Collections.Generic; 3 4using UnityEditor; 5using UnityEngine; 6 7using Codice.Client.BaseCommands; 8using Codice.CM.Common; 9using GluonGui.WorkspaceWindow.Views.WorkspaceExplorer.Explorer; 10using PlasticGui; 11using Unity.PlasticSCM.Editor.UI; 12using Unity.PlasticSCM.Editor.UI.Tree; 13 14namespace Unity.PlasticSCM.Editor.Gluon.UpdateReport 15{ 16 internal class UpdateReportDialog : PlasticDialog 17 { 18 protected override Rect DefaultRect 19 { 20 get 21 { 22 var baseRect = base.DefaultRect; 23 return new Rect(baseRect.x, baseRect.y, 800, 400); 24 } 25 } 26 27 internal static UpdateReportResult ShowUpdateReport( 28 WorkspaceInfo wkInfo, 29 List<ErrorMessage> errors, 30 EditorWindow parentWindow) 31 { 32 UpdateReportDialog dialog = Create(wkInfo, errors); 33 34 ResponseType dialogResult = dialog.RunModal(parentWindow); 35 36 UpdateReportResult result = dialog.GetUpdateReportResult(); 37 38 result.Result = dialogResult == ResponseType.Ok; 39 return result; 40 } 41 42 protected override void SaveSettings() 43 { 44 TreeHeaderSettings.Save(mUpdateReportListView.multiColumnHeader.state, 45 UnityConstants.GLUON_UPDATE_REPORT_TABLE_SETTINGS_NAME); 46 } 47 48 protected override void OnModalGUI() 49 { 50 Title(PlasticLocalization.GetString( 51 PlasticLocalization.Name.UpdateResultsTitle)); 52 53 Paragraph(PlasticLocalization.GetString( 54 PlasticLocalization.Name.UpdateResultsExplanation)); 55 56 DoUpdateReportArea( 57 mUpdateReportListView, mErrorDetailsSplitterState); 58 59 GUILayout.Space(10); 60 61 DoSelectAllArea(); 62 63 GUILayout.Space(20); 64 65 DoButtonsArea(mIsUpdateForcedButtonEnabled); 66 } 67 68 protected override string GetTitle() 69 { 70 return PlasticLocalization.GetString( 71 PlasticLocalization.Name.UpdateResultsTitle); 72 } 73 74 void OnCheckedErrorChanged() 75 { 76 mIsUpdateForcedButtonEnabled = 77 mUpdateReportListView.IsAnyErrorChecked(); 78 mIsSelectAllToggleChecked = 79 mUpdateReportListView.AreAllErrorsChecked(); 80 } 81 82 UpdateReportResult GetUpdateReportResult() 83 { 84 return new UpdateReportResult 85 { 86 UpdateForcedPaths = mUpdateReportListView.GetCheckedPaths(), 87 UnaffectedErrors = mUpdateReportListView.GetUncheckedErrors() 88 }; 89 } 90 91 static void UpdateUpdateReportList( 92 UpdateReportListView updateReportListView, 93 List<ErrorMessage> errorMessages) 94 { 95 updateReportListView.BuildModel(errorMessages); 96 97 updateReportListView.Reload(); 98 } 99 100 static string GetErrorDetailsText( 101 ErrorMessage selectedErrorMessage) 102 { 103 if (selectedErrorMessage == null) 104 return string.Empty; 105 106 return string.Format("{0}:{1}{2}", 107 selectedErrorMessage.Path, 108 Environment.NewLine, 109 selectedErrorMessage.Error); 110 } 111 112 void DoUpdateReportArea( 113 UpdateReportListView updateReportListView, 114 object splitterState) 115 { 116 PlasticSplitterGUILayout.BeginHorizontalSplit(splitterState); 117 118 DoUpdateReportViewArea(updateReportListView); 119 120 DoErrorDetailsTextArea(updateReportListView.GetSelectedError()); 121 122 PlasticSplitterGUILayout.EndHorizontalSplit(); 123 } 124 125 static void DoUpdateReportViewArea( 126 UpdateReportListView updateReportListView) 127 { 128 Rect treeRect = GUILayoutUtility.GetRect(0, 100000, 0, 100000); 129 130 updateReportListView.OnGUI(treeRect); 131 } 132 133 void DoErrorDetailsTextArea( 134 ErrorMessage selectedErrorMessage) 135 { 136 string errorDetailsText = 137 GetErrorDetailsText(selectedErrorMessage); 138 139 mErrorDetailsScrollPosition = GUILayout.BeginScrollView( 140 mErrorDetailsScrollPosition); 141 142 GUILayout.TextArea( 143 errorDetailsText, UnityStyles.TextFieldWithWrapping, 144 GUILayout.ExpandHeight(true)); 145 146 GUILayout.EndScrollView(); 147 } 148 149 void DoSelectAllArea() 150 { 151 bool wasChecked = mIsSelectAllToggleChecked; 152 153 bool isChecked = EditorGUILayout.ToggleLeft( 154 PlasticLocalization.GetString( 155 PlasticLocalization.Name.SelectAll), 156 wasChecked); 157 158 if (!wasChecked && isChecked) 159 { 160 mIsSelectAllToggleChecked = true; 161 mUpdateReportListView.CheckAllLines(); 162 return; 163 } 164 165 if (wasChecked && !isChecked) 166 { 167 mIsSelectAllToggleChecked = false; 168 mUpdateReportListView.UncheckAllLines(); 169 return; 170 } 171 } 172 173 void DoButtonsArea(bool isUpdateForcedButtonEnabled) 174 { 175 using (new EditorGUILayout.HorizontalScope()) 176 { 177 GUILayout.FlexibleSpace(); 178 179 if (Application.platform == RuntimePlatform.WindowsEditor) 180 { 181 DoUpdateForcedButton(isUpdateForcedButtonEnabled); 182 DoCloseButton(); 183 return; 184 } 185 186 DoCloseButton(); 187 DoUpdateForcedButton(isUpdateForcedButtonEnabled); 188 } 189 } 190 191 void DoUpdateForcedButton(bool isEnabled) 192 { 193 GUI.enabled = isEnabled; 194 195 mEnterKeyAction = GetEnterKeyAction(isEnabled); 196 197 bool pressed = AcceptButton(PlasticLocalization.GetString( 198 PlasticLocalization.Name.UpdateForced)); 199 200 GUI.enabled = true; 201 202 if (!pressed) 203 return; 204 205 OkButtonAction(); 206 } 207 208 void DoCloseButton() 209 { 210 if (!NormalButton(PlasticLocalization.GetString( 211 PlasticLocalization.Name.CloseButton))) 212 return; 213 214 CloseButtonAction(); 215 } 216 217 Action GetEnterKeyAction(bool isEnabled) 218 { 219 if (isEnabled) 220 return OkButtonAction; 221 222 return null; 223 } 224 225 void BuildComponents(WorkspaceInfo wkInfo) 226 { 227 UpdateReportListHeaderState updateReportListHeaderState = 228 UpdateReportListHeaderState.GetDefault(); 229 TreeHeaderSettings.Load(updateReportListHeaderState, 230 UnityConstants.GLUON_UPDATE_REPORT_TABLE_SETTINGS_NAME, 231 UnityConstants.UNSORT_COLUMN_ID); 232 233 mUpdateReportListView = new UpdateReportListView( 234 wkInfo, updateReportListHeaderState, 235 OnCheckedErrorChanged); 236 mUpdateReportListView.Reload(); 237 } 238 239 static UpdateReportDialog Create( 240 WorkspaceInfo wkInfo, 241 List<ErrorMessage> errors) 242 { 243 var instance = CreateInstance<UpdateReportDialog>(); 244 instance.mWkInfo = wkInfo; 245 instance.mErrors = errors; 246 instance.mEscapeKeyAction = instance.CloseButtonAction; 247 248 instance.BuildComponents(instance.mWkInfo); 249 250 instance.mErrorDetailsSplitterState = PlasticSplitterGUILayout.InitSplitterState( 251 new float[] { 0.50f, 0.50f }, 252 new int[] { 100, 100 }, 253 new int[] { 100000, 100000 } 254 ); 255 256 UpdateUpdateReportList( 257 instance.mUpdateReportListView, 258 instance.mErrors); 259 260 return instance; 261 } 262 263 bool mIsSelectAllToggleChecked; 264 bool mIsUpdateForcedButtonEnabled; 265 object mErrorDetailsSplitterState; 266 Vector2 mErrorDetailsScrollPosition; 267 268 UpdateReportListView mUpdateReportListView; 269 270 List<ErrorMessage> mErrors; 271 WorkspaceInfo mWkInfo; 272 } 273}