Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit b49fac9

Browse files
Moving toolbar from HistoryView to Window
1 parent 41f4b6a commit b49fac9

File tree

2 files changed

+222
-214
lines changed

2 files changed

+222
-214
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 7 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -305,33 +305,12 @@ public void ScrollTo(int index, float offset = 0f)
305305
[Serializable]
306306
class HistoryView : Subview
307307
{
308-
private const string PullButton = "Pull";
309-
private const string PullButtonCount = "Pull (<b>{0}</b>)";
310-
private const string PushButton = "Push";
311-
private const string PushButtonCount = "Push (<b>{0}</b>)";
312-
private const string PullConfirmTitle = "Pull Changes?";
313-
private const string PullConfirmDescription = "Would you like to pull changes from remote '{0}'?";
314-
private const string PullConfirmYes = "Pull";
315-
private const string PullConfirmCancel = "Cancel";
316-
private const string PushConfirmTitle = "Push Changes?";
317-
private const string PushConfirmDescription = "Would you like to push changes to remote '{0}'?";
318-
private const string PushConfirmYes = "Push";
319-
private const string PushConfirmCancel = "Cancel";
320308
private const string CommitDetailsTitle = "Commit details";
321309
private const string ClearSelectionButton = "×";
322-
private const string PublishButton = "Publish";
323-
private const string FetchActionTitle = "Fetch Changes";
324-
private const string FetchButtonText = "Fetch";
325-
private const string FetchFailureDescription = "Could not fetch changes";
326310

327311
[NonSerialized] private bool currentLogHasUpdate;
328-
[NonSerialized] private bool currentRemoteHasUpdate;
329312
[NonSerialized] private bool currentTrackingStatusHasUpdate;
330313

331-
[SerializeField] private bool hasItemsToCommit;
332-
[SerializeField] private bool hasRemote;
333-
[SerializeField] private string currentRemoteName;
334-
335314
[SerializeField] private HistoryControl historyControl;
336315
[SerializeField] private GitLogEntry selectedEntry = GitLogEntry.Default;
337316

@@ -340,13 +319,11 @@ class HistoryView : Subview
340319
[SerializeField] private List<GitLogEntry> logEntries = new List<GitLogEntry>();
341320

342321
[SerializeField] private int statusAhead;
343-
[SerializeField] private int statusBehind;
344322

345323
[SerializeField] private ChangesTree treeChanges = new ChangesTree { IsSelectable = false, DisplayRootNode = false };
346324

347-
[SerializeField] private CacheUpdateEvent lastCurrentRemoteChangedEvent;
348325
[SerializeField] private CacheUpdateEvent lastLogChangedEvent;
349-
[SerializeField] private CacheUpdateEvent lastAheadBehindChangedEvent;
326+
[SerializeField] private CacheUpdateEvent lastTrackingStatusChangedEvent;
350327

351328
public override void OnEnable()
352329
{
@@ -387,68 +364,6 @@ public override void OnFocusChanged()
387364

388365
public override void OnGUI()
389366
{
390-
// History toolbar
391-
GUILayout.BeginHorizontal(EditorStyles.toolbar);
392-
{
393-
GUILayout.FlexibleSpace();
394-
395-
if (hasRemote)
396-
{
397-
EditorGUI.BeginDisabledGroup(currentRemoteName == null);
398-
{
399-
// Fetch button
400-
var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
401-
if (fetchClicked)
402-
{
403-
Fetch();
404-
}
405-
406-
// Pull button
407-
var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
408-
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
409-
410-
if (pullClicked &&
411-
EditorUtility.DisplayDialog(PullConfirmTitle,
412-
String.Format(PullConfirmDescription, currentRemoteName),
413-
PullConfirmYes,
414-
PullConfirmCancel)
415-
)
416-
{
417-
Pull();
418-
}
419-
}
420-
EditorGUI.EndDisabledGroup();
421-
422-
// Push button
423-
EditorGUI.BeginDisabledGroup(currentRemoteName == null || statusBehind != 0);
424-
{
425-
var pushButtonText = statusAhead > 0 ? String.Format(PushButtonCount, statusAhead) : PushButton;
426-
var pushClicked = GUILayout.Button(pushButtonText, Styles.HistoryToolbarButtonStyle);
427-
428-
if (pushClicked &&
429-
EditorUtility.DisplayDialog(PushConfirmTitle,
430-
String.Format(PushConfirmDescription, currentRemoteName),
431-
PushConfirmYes,
432-
PushConfirmCancel)
433-
)
434-
{
435-
Push();
436-
}
437-
}
438-
EditorGUI.EndDisabledGroup();
439-
}
440-
else
441-
{
442-
// Publishing a repo
443-
var publishedClicked = GUILayout.Button(PublishButton, Styles.HistoryToolbarButtonStyle);
444-
if (publishedClicked)
445-
{
446-
PopupWindow.OpenWindow(PopupWindow.PopupViewType.PublishView);
447-
}
448-
}
449-
}
450-
GUILayout.EndHorizontal();
451-
452367
var rect = GUILayoutUtility.GetLastRect();
453368
if (historyControl != null)
454369
{
@@ -569,11 +484,11 @@ private void RevertCommit()
569484
}
570485
}
571486

572-
private void RepositoryTrackingOnStatusChanged(CacheUpdateEvent cacheUpdateEvent)
487+
private void RepositoryOnTrackingStatusChanged(CacheUpdateEvent cacheUpdateEvent)
573488
{
574-
if (!lastAheadBehindChangedEvent.Equals(cacheUpdateEvent))
489+
if (!lastTrackingStatusChangedEvent.Equals(cacheUpdateEvent))
575490
{
576-
lastAheadBehindChangedEvent = cacheUpdateEvent;
491+
lastTrackingStatusChangedEvent = cacheUpdateEvent;
577492
currentTrackingStatusHasUpdate = true;
578493
Redraw();
579494
}
@@ -589,26 +504,15 @@ private void RepositoryOnLogChanged(CacheUpdateEvent cacheUpdateEvent)
589504
}
590505
}
591506

592-
private void RepositoryOnCurrentRemoteChanged(CacheUpdateEvent cacheUpdateEvent)
593-
{
594-
if (!lastCurrentRemoteChangedEvent.Equals(cacheUpdateEvent))
595-
{
596-
lastCurrentRemoteChangedEvent = cacheUpdateEvent;
597-
currentRemoteHasUpdate = true;
598-
Redraw();
599-
}
600-
}
601-
602507
private void AttachHandlers(IRepository repository)
603508
{
604509
if (repository == null)
605510
{
606511
return;
607512
}
608513

609-
repository.TrackingStatusChanged += RepositoryTrackingOnStatusChanged;
514+
repository.TrackingStatusChanged += RepositoryOnTrackingStatusChanged;
610515
repository.LogChanged += RepositoryOnLogChanged;
611-
repository.CurrentRemoteChanged += RepositoryOnCurrentRemoteChanged;
612516
}
613517

614518
private void DetachHandlers(IRepository repository)
@@ -618,16 +522,14 @@ private void DetachHandlers(IRepository repository)
618522
return;
619523
}
620524

621-
repository.TrackingStatusChanged -= RepositoryTrackingOnStatusChanged;
525+
repository.TrackingStatusChanged -= RepositoryOnTrackingStatusChanged;
622526
repository.LogChanged -= RepositoryOnLogChanged;
623-
repository.CurrentRemoteChanged -= RepositoryOnCurrentRemoteChanged;
624527
}
625528

626529
private void ValidateCachedData(IRepository repository)
627530
{
628531
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.GitLog, lastLogChangedEvent);
629-
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.GitAheadBehind, lastAheadBehindChangedEvent);
630-
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.RepositoryInfo, lastCurrentRemoteChangedEvent);
532+
repository.CheckAndRaiseEventsIfCacheNewer(CacheType.GitAheadBehind, lastTrackingStatusChangedEvent);
631533
}
632534

633535
private void MaybeUpdateData()
@@ -637,25 +539,11 @@ private void MaybeUpdateData()
637539
return;
638540
}
639541

640-
if (currentRemoteHasUpdate)
641-
{
642-
currentRemoteHasUpdate = false;
643-
644-
var currentRemote = Repository.CurrentRemote;
645-
hasRemote = currentRemote.HasValue;
646-
currentRemoteName = hasRemote ? currentRemote.Value.Name : "placeholder";
647-
}
648-
649542
if (currentTrackingStatusHasUpdate)
650543
{
651544
currentTrackingStatusHasUpdate = false;
652545

653546
statusAhead = Repository.CurrentAhead;
654-
statusBehind = Repository.CurrentBehind;
655-
656-
var currentChanges = Repository.CurrentChanges;
657-
hasItemsToCommit = currentChanges != null
658-
&& currentChanges.Any(entry => entry.Status != GitFileStatus.Ignored && !entry.Staged);
659547
}
660548

661549
if (currentLogHasUpdate)
@@ -683,75 +571,6 @@ private void BuildHistoryControl()
683571
}
684572
}
685573

686-
private void Pull()
687-
{
688-
if (hasItemsToCommit)
689-
{
690-
EditorUtility.DisplayDialog("Pull", "You need to commit your changes before pulling.", "Cancel");
691-
}
692-
else
693-
{
694-
Repository
695-
.Pull()
696-
.FinallyInUI((success, e) => {
697-
if (success)
698-
{
699-
TaskManager.Run(UsageTracker.IncrementHistoryViewToolbarPull);
700-
701-
EditorUtility.DisplayDialog(Localization.PullActionTitle,
702-
String.Format(Localization.PullSuccessDescription, currentRemoteName),
703-
Localization.Ok);
704-
}
705-
else
706-
{
707-
EditorUtility.DisplayDialog(Localization.PullActionTitle,
708-
Localization.PullFailureDescription,
709-
Localization.Ok);
710-
}
711-
})
712-
.Start();
713-
}
714-
}
715-
716-
private void Push()
717-
{
718-
Repository
719-
.Push()
720-
.FinallyInUI((success, e) => {
721-
if (success)
722-
{
723-
TaskManager.Run(UsageTracker.IncrementHistoryViewToolbarPush);
724-
725-
EditorUtility.DisplayDialog(Localization.PushActionTitle,
726-
String.Format(Localization.PushSuccessDescription, currentRemoteName),
727-
Localization.Ok);
728-
}
729-
else
730-
{
731-
EditorUtility.DisplayDialog(Localization.PushActionTitle,
732-
Localization.PushFailureDescription,
733-
Localization.Ok);
734-
}
735-
})
736-
.Start();
737-
}
738-
739-
private void Fetch()
740-
{
741-
Repository
742-
.Fetch()
743-
.FinallyInUI((success, e) => {
744-
if (!success)
745-
{
746-
TaskManager.Run(UsageTracker.IncrementHistoryViewToolbarFetch);
747-
748-
EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription,
749-
Localization.Ok);
750-
}
751-
})
752-
.Start();
753-
}
754-
755574
private void BuildTree()
756575
{
757576
treeChanges.PathSeparator = Environment.FileSystem.DirectorySeparatorChar.ToString();

0 commit comments

Comments
 (0)