A game about forced loneliness, made by TACStudios
at master 273 lines 8.3 kB view raw
1using System.Collections; 2 3using UnityEditor; 4using UnityEngine; 5 6using Codice.Client.BaseCommands; 7using Codice.Client.Commands; 8using Codice.CM.Common; 9using PlasticGui; 10using PlasticGui.WorkspaceWindow.Update; 11using Unity.PlasticSCM.Editor.UI; 12using Unity.PlasticSCM.Editor.UI.Progress; 13using Unity.PlasticSCM.Editor.UI.Tree; 14 15namespace Unity.PlasticSCM.Editor.Developer.UpdateReport 16{ 17 internal class UpdateReportDialog : 18 PlasticDialog, 19 IUpdateReportDialog 20 { 21 protected override Rect DefaultRect 22 { 23 get 24 { 25 var baseRect = base.DefaultRect; 26 return new Rect(baseRect.x, baseRect.y, 810, 385); 27 } 28 } 29 30 internal static ResponseType ShowReportDialog( 31 WorkspaceInfo wkInfo, 32 IList reportLines, 33 EditorWindow parentWindow) 34 { 35 UpdateReportDialog dialog = Create( 36 wkInfo, 37 reportLines, 38 new ProgressControlsForDialogs()); 39 40 return dialog.RunModal(parentWindow); 41 } 42 43 protected override void SaveSettings() 44 { 45 TreeHeaderSettings.Save(mPathsListView.multiColumnHeader.state, 46 UnityConstants.DEVELOPER_UPDATE_REPORT_TABLE_SETTINGS_NAME); 47 } 48 49 protected override void OnModalGUI() 50 { 51 Title(PlasticLocalization.GetString(PlasticLocalization.Name.UpdateResultsTitle)); 52 53 Paragraph(PlasticLocalization.GetString(PlasticLocalization.Name.UpdateResultsError)); 54 55 DoListArea( 56 mPathsListView, 57 mErrorDetailsSplitterState); 58 59 GUILayout.Space(10); 60 61 DoSelectAllArea(); 62 63 GUILayout.BeginHorizontal(); 64 GUILayout.Space(4); 65 DrawProgressForDialogs.For( 66 mProgressControls.ProgressData); 67 GUILayout.Space(4); 68 GUILayout.EndHorizontal(); 69 70 GUILayout.Space(2); 71 72 DoButtonsArea(mIsAnyLineChecked); 73 74 mProgressControls.ForcedUpdateProgress(this); 75 } 76 77 protected override string GetTitle() 78 { 79 return PlasticLocalization.GetString( 80 PlasticLocalization.Name.UpdateResultsTitle); 81 } 82 83 void IUpdateReportDialog.Reload() 84 { 85 SetReportLines(mReportLines); 86 } 87 88 void OnCheckedReportLineChanged() 89 { 90 mIsAnyLineChecked = 91 mPathsListView.IsAnyLineChecked(); 92 mAreAllLinesChecked = 93 mPathsListView.AreAllLinesChecked(); 94 } 95 96 void DoListArea( 97 UpdateReportListView errorsListView, 98 object splitterState) 99 { 100 EditorGUILayout.BeginVertical(); 101 PlasticSplitterGUILayout.BeginHorizontalSplit(splitterState); 102 103 DoErrorsListViewArea(errorsListView); 104 DoErrorDetailsTextArea(errorsListView.GetSelectedError()); 105 106 PlasticSplitterGUILayout.EndHorizontalSplit(); 107 EditorGUILayout.EndVertical(); 108 } 109 110 static void DoErrorsListViewArea( 111 UpdateReportListView errorsListView) 112 { 113 Rect treeRect = GUILayoutUtility.GetRect(0, 100000, 0, 100000); 114 115 errorsListView.OnGUI(treeRect); 116 } 117 118 void DoErrorDetailsTextArea(ReportLine selectedReportLine) 119 { 120 string errorDetailsText = selectedReportLine == null ? 121 string.Empty : selectedReportLine.Message; 122 123 EditorGUILayout.BeginVertical(); 124 125 GUILayout.Space(8); 126 GUILayout.Label(PlasticLocalization.GetString(PlasticLocalization.Name.ProblemColumn)); 127 128 mErrorDetailsScrollPosition = GUILayout.BeginScrollView( 129 mErrorDetailsScrollPosition); 130 131 GUILayout.TextArea( 132 errorDetailsText, UnityStyles.TextFieldWithWrapping, 133 GUILayout.ExpandHeight(true)); 134 135 GUILayout.EndScrollView(); 136 137 EditorGUILayout.EndVertical(); 138 } 139 140 void DoSelectAllArea() 141 { 142 bool toggleValue = GUILayout.Toggle( 143 mAreAllLinesChecked, 144 PlasticLocalization.GetString( 145 PlasticLocalization.Name.SelectAll)); 146 147 if (toggleValue != mAreAllLinesChecked && toggleValue) 148 { 149 mPathsListView.CheckAllLines(); 150 return; 151 } 152 153 if (toggleValue != mAreAllLinesChecked && !toggleValue) 154 { 155 mPathsListView.UnCheckAllLines(); 156 return; 157 } 158 } 159 160 void DoButtonsArea(bool areUpdateButtonsEneabled) 161 { 162 using (new EditorGUILayout.HorizontalScope()) 163 { 164 DoRetryUpdateButton(areUpdateButtonsEneabled); 165 DoUpdateForcedButton(areUpdateButtonsEneabled); 166 167 GUILayout.FlexibleSpace(); 168 169 DoCloseButton(); 170 } 171 } 172 173 void DoRetryUpdateButton(bool isEnabled) 174 { 175 GUI.enabled = isEnabled; 176 177 bool pressed = NormalButton(PlasticLocalization.GetString( 178 PlasticLocalization.Name.RetryUpdate)); 179 180 GUI.enabled = true; 181 182 if (!pressed) 183 return; 184 185 SelectiveUpdateOperation.SelectiveUpdate( 186 mWkInfo, mReportLines, mPathsListView.GetCheckedLines(), 187 UpdateFlags.None, this, mProgressControls); 188 } 189 190 void DoUpdateForcedButton(bool isEnabled) 191 { 192 GUI.enabled = isEnabled; 193 194 bool pressed = NormalButton(PlasticLocalization.GetString( 195 PlasticLocalization.Name.UpdateForced)); 196 197 GUI.enabled = true; 198 199 if (!pressed) 200 return; 201 202 SelectiveUpdateOperation.SelectiveUpdate( 203 mWkInfo, mReportLines, mPathsListView.GetCheckedLines(), 204 UpdateFlags.Forced, this, mProgressControls); 205 } 206 207 void DoCloseButton() 208 { 209 if (!NormalButton(PlasticLocalization.GetString( 210 PlasticLocalization.Name.CloseButton))) 211 return; 212 213 CancelButtonAction(); 214 } 215 216 static UpdateReportDialog Create( 217 WorkspaceInfo wkInfo, 218 IList reportLines, 219 ProgressControlsForDialogs progressControls) 220 { 221 var instance = CreateInstance<UpdateReportDialog>(); 222 instance.mWkInfo = wkInfo; 223 instance.mReportLines = reportLines; 224 instance.mProgressControls = progressControls; 225 instance.mEscapeKeyAction = instance.CloseButtonAction; 226 instance.BuildComponents(wkInfo); 227 instance.SetReportLines(reportLines); 228 return instance; 229 } 230 231 void SetReportLines(IList reportLines) 232 { 233 mReportLines = reportLines; 234 235 mPathsListView.BuildModel(reportLines); 236 mPathsListView.Reload(); 237 mAreAllLinesChecked = false; 238 } 239 240 void BuildComponents(WorkspaceInfo wkInfo) 241 { 242 mErrorDetailsSplitterState = PlasticSplitterGUILayout.InitSplitterState( 243 new float[] { 0.50f, 0.50f }, 244 new int[] { 100, 100 }, 245 new int[] { 100000, 100000 } 246 ); 247 248 UpdateReportListHeaderState errorsListHeaderState = 249 UpdateReportListHeaderState.GetDefault(); 250 TreeHeaderSettings.Load(errorsListHeaderState, 251 UnityConstants.DEVELOPER_UPDATE_REPORT_TABLE_SETTINGS_NAME, 252 UnityConstants.UNSORT_COLUMN_ID); 253 254 mPathsListView = new UpdateReportListView( 255 wkInfo, 256 errorsListHeaderState, 257 OnCheckedReportLineChanged); 258 259 mPathsListView.Reload(); 260 } 261 262 bool mIsAnyLineChecked = false; 263 bool mAreAllLinesChecked = false; 264 UpdateReportListView mPathsListView; 265 266 object mErrorDetailsSplitterState; 267 Vector2 mErrorDetailsScrollPosition; 268 269 WorkspaceInfo mWkInfo; 270 IList mReportLines; 271 ProgressControlsForDialogs mProgressControls; 272 } 273}