Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ public void Dispose()
public CancellationToken CancellationToken { get { return TaskManager.Token; } }
public ITaskManager TaskManager { get; protected set; }
public IGitClient GitClient { get; protected set; }


protected TaskScheduler UIScheduler { get; private set; }
protected SynchronizationContext SynchronizationContext { get; private set; }
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }

public ISettings LocalSettings { get; protected set; }
public ISettings SystemSettings { get; protected set; }
public ISettings UserSettings { get; protected set; }
public IUsageTracker UsageTracker { get; protected set; }

protected TaskScheduler UIScheduler { get; private set; }
protected SynchronizationContext SynchronizationContext { get; private set; }
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }
}
}
1 change: 1 addition & 0 deletions src/GitHub.Api/Git/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IRepository : IEquatable<IRepository>
ITask SetupRemote(string remoteName, string remoteUrl);
ITask Pull();
ITask Push();
ITask Fetch();
ITask Revert(string changeset);
ITask ListLocks();
ITask RequestLock(string file);
Expand Down
5 changes: 5 additions & 0 deletions src/GitHub.Api/Git/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public ITask Push()
return repositoryManager.Push(CurrentRemote.Value.Name, CurrentBranch);
}

public ITask Fetch()
{
return repositoryManager.Fetch(CurrentRemote.Value.Name);
}

public ITask Revert(string changeset)
{
return repositoryManager.Revert(changeset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ApplicationManager(IMainThreadSynchronizationContext synchronizationConte

protected override void SetupMetrics()
{

new ActionTask(CancellationToken,
() => SetupMetrics(Environment.UnityVersion, ApplicationCache.Instance.FirstRun))
{ Affinity = TaskAffinity.UI }
Expand All @@ -33,7 +34,7 @@ protected override void InitializeUI()
{
Logger.Trace("Restarted {0}", Environment.Repository);
ProjectWindowInterface.Initialize(Environment.Repository);
var view = Window.GetView();
var view = Window.GetWindow();
if (view != null)
view.Initialize(this);
}
Expand Down
3 changes: 1 addition & 2 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace GitHub.Unity
[InitializeOnLoad]
class EntryPoint : ScriptableObject
{
private static ApplicationManager appManager;

// this may run on the loader thread if it's an appdomain restart
static EntryPoint()
{
Expand Down Expand Up @@ -69,6 +67,7 @@ private static bool ServerCertificateValidationCallback(object sender, X509Certi
return true;
}

private static ApplicationManager appManager;
public static IApplicationManager ApplicationManager
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public override void InitializeView(IView parent)
need2fa = busy = false;
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
}

public override void OnGUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,45 @@ public static IView Open(Action<bool> onClose = null)
return authWindow;
}

public override void OnGUI()
public override void Initialize(IApplicationManager applicationManager)
{
base.Initialize(applicationManager);
if (authView == null)
{
CreateViews();
}
authView.OnGUI();
}

public override void Refresh()
{
authView.Refresh();
authView = new AuthenticationView();
authView.InitializeView(this);
}

public override void OnEnable()
{
base.OnEnable();

// Set window title
titleContent = new GUIContent(Title, Styles.SmallLogo);
authView.OnEnable();
}

Utility.UnregisterReadyCallback(CreateViews);
Utility.RegisterReadyCallback(CreateViews);

Utility.UnregisterReadyCallback(ShowActiveView);
Utility.RegisterReadyCallback(ShowActiveView);
public override void OnDisable()
{
base.OnDisable();
authView.OnDisable();
}

private void CreateViews()
public override void OnUI()
{
if (authView == null)
authView = new AuthenticationView();
base.OnUI();
authView.OnGUI();
}

Initialize(EntryPoint.ApplicationManager);
authView.InitializeView(this);
public override void Refresh()
{
base.Refresh();
authView.Refresh();
}

private void ShowActiveView()
public override void OnSelectionChange()
{
authView.OnShow();
Refresh();
base.OnSelectionChange();
authView.OnSelectionChange();
}

public override void Finish(bool result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public override void InitializeView(IView parent)
targetMode = mode;
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository != null)
{
Repository.OnLocalBranchListChanged += RunRefreshEmbeddedOnMainThread;
Expand All @@ -55,9 +55,9 @@ public override void OnShow()
}
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
if (Repository != null)
{
Repository.OnLocalBranchListChanged -= RunRefreshEmbeddedOnMainThread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public override void InitializeView(IView parent)
tree.InitializeView(this);
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository == null)
return;

Expand All @@ -44,9 +44,9 @@ public override void OnShow()
Repository.Refresh();
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
if (Repository == null)
return;
Repository.OnRepositoryChanged -= RunStatusUpdateOnMainThread;
Expand Down
49 changes: 36 additions & 13 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class HistoryView : Subview
private const string ClearSelectionButton = "×";
private const string NoRepoTitle = "No Git repository found for this project";
private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others.";
private const string FetchActionTitle = "Fetch Changes";
private const string FetchButtonText = "Fetch";
private const string FetchFailureDescription = "Could not fetch changes";
private const string FetchConfirmTitle = "Fetch Changes?";
private const string FetchConfirmDescription = "Would you like to fetch changes from remote '{0}'?";
private const string FetchConfirmYes = "Fetch";
private const string FetchConfirmCancel = "Cancel";
private const int HistoryExtraItemCount = 10;
private const float MaxChangelistHeightRatio = .2f;

Expand Down Expand Up @@ -59,19 +66,14 @@ class HistoryView : Subview
[SerializeField] private List<GitLogEntry> history = new List<GitLogEntry>();
[SerializeField] private bool isBusy;

public override void Initialize(IApplicationManager applicationManager)
public override void InitializeView(IView parent)
{
base.Initialize(applicationManager);
base.InitializeView(parent);

if (Manager != null)
{
UpdateLog();
}
}

public override void InitializeView(IView parent)
{
Logger.Trace("InitializeView(IView)");
base.InitializeView(parent);

lastWidth = Position.width;
selectionIndex = newSelectionIndex = -1;
Expand All @@ -86,9 +88,9 @@ public override void InitializeView(IView parent)
}
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository != null)
{
Repository.OnCommitChanged += UpdateLogOnMainThread;
Expand All @@ -97,9 +99,9 @@ public override void OnShow()
UpdateLog();
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
if (Repository != null)
{
Repository.OnCommitChanged -= UpdateLogOnMainThread;
Expand Down Expand Up @@ -321,8 +323,14 @@ public void OnEmbeddedGUI()

GUILayout.FlexibleSpace();

GUI.enabled = currentRemote != null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should get into the habit of using EditorGUI.Begin/EndDisabledGroup rather than setting GUI.enabled directly. Those utility methods handle nesting properly. (There's also EditorGUI.DisabledScope, for an IDisposable way of doing things.)

var fetchClicked = GUILayout.Button(FetchButtonText, Styles.HistoryToolbarButtonStyle);
GUI.enabled = true;
if (fetchClicked)
{
Fetch();
}

// Pull / Push buttons
var pullButtonText = statusBehind > 0 ? String.Format(PullButtonCount, statusBehind) : PullButton;
GUI.enabled = currentRemote != null;
var pullClicked = GUILayout.Button(pullButtonText, Styles.HistoryToolbarButtonStyle);
Expand Down Expand Up @@ -738,6 +746,21 @@ private void Push()
.Start();
}

private void Fetch()
{
var remote = Repository.CurrentRemote.HasValue ? Repository.CurrentRemote.Value.Name : String.Empty;
Repository
.Fetch()
.FinallyInUI((success, e) => {
if (!success)
{
EditorUtility.DisplayDialog(FetchActionTitle, FetchFailureDescription,
Localization.Ok);
}
})
.Start();
}

void drawTimelineRectAroundIconRect(Rect parentRect, Rect iconRect)
{
Color timelineBarColor = new Color(0.51F, 0.51F, 0.51F, 0.2F);
Expand Down
3 changes: 2 additions & 1 deletion src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace GitHub.Unity
{
interface IView
{
void Initialize(IApplicationManager applicationManager);
void OnEnable();
void OnDisable();
void Refresh();
void Redraw();
Rect Position { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ private void Repository_OnActiveRemoteChanged(string remote)
UpdateRemote();
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository == null)
return;

Expand Down
Loading