Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
16 changes: 16 additions & 0 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BaseWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ private void OnGUI()
}
}

private void OnFocus()
{
HasFocus = true;
OnFocusChanged();
}

private void OnLostFocus()
{
HasFocus = false;
OnFocusChanged();
}

public virtual void OnFocusChanged()
{}

public virtual void OnDestroy()
{}

Expand All @@ -103,6 +118,7 @@ public virtual void OnSelectionChange()
public Rect Position { get { return position; } }
public IApplicationManager Manager { get; private set; }
public abstract bool IsBusy { get; }
public bool HasFocus { get; private set; }
public IRepository Repository { get { return inLayout ? cachedRepository : Environment.Repository; } }
public bool HasRepository { get { return Repository != null; } }
public IUser User { get { return cachedUser; } }
Expand Down
41 changes: 25 additions & 16 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,20 @@ public override void InitializeView(IView parent)
public override void OnEnable()
{
base.OnEnable();
TreeOnEnable();

var hasFocus = HasFocus;
if (treeLocals != null)
{
treeLocals.ViewHasFocus = hasFocus;
treeLocals.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
}

if (treeRemotes != null)
{
treeRemotes.ViewHasFocus = hasFocus;
treeRemotes.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
}

AttachHandlers(Repository);
Repository.CheckLocalAndRemoteBranchListChangedEvent(lastLocalAndRemoteBranchListChangedEvent);
}
Expand All @@ -85,6 +98,17 @@ public override void OnSelectionChange()
Redraw();
}

public override void OnFocusChanged()
{
base.OnFocusChanged();
if(treeLocals.ViewHasFocus != HasFocus || treeRemotes.ViewHasFocus != HasFocus)
{
treeLocals.ViewHasFocus = HasFocus;
treeRemotes.ViewHasFocus = HasFocus;
Redraw();
}
}

private void RepositoryOnLocalAndRemoteBranchListChanged(CacheUpdateEvent cacheUpdateEvent)
{
if (!lastLocalAndRemoteBranchListChangedEvent.Equals(cacheUpdateEvent))
Expand Down Expand Up @@ -163,21 +187,6 @@ private void BuildTree()
Redraw();
}

private void TreeOnEnable()
{
if (treeLocals != null)
{
treeLocals.OnEnable();
treeLocals.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
}

if (treeRemotes != null)
{
treeRemotes.OnEnable();
treeRemotes.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
}
}

private void OnButtonBarGUI()
{
if (mode == BranchesMode.Default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;

namespace GitHub.Unity
{
Expand Down Expand Up @@ -38,6 +39,7 @@ public bool IsLocked
[Serializable]
public class ChangesTree : Tree<ChangesTreeNode, GitStatusEntryTreeData>
{
[SerializeField] public ChangesTreeNodeDictionary assets = new ChangesTreeNodeDictionary();
[SerializeField] public ChangesTreeNodeDictionary folders = new ChangesTreeNodeDictionary();
[SerializeField] public ChangesTreeNodeDictionary checkedFileNodes = new ChangesTreeNodeDictionary();

Expand All @@ -47,8 +49,11 @@ public class ChangesTree : Tree<ChangesTreeNode, GitStatusEntryTreeData>
[SerializeField] public bool displayRootNode = true;
[SerializeField] public bool isSelectable = true;
[SerializeField] public bool isCheckable = false;
[SerializeField] public bool isUsingGlobalSelection = false;
[SerializeField] private List<ChangesTreeNode> nodes = new List<ChangesTreeNode>();
[SerializeField] private ChangesTreeNode selectedNode = null;
[NonSerialized] private bool viewHasFocus;
[NonSerialized] private Object lastActivatedObject;

public override string Title
{
Expand Down Expand Up @@ -92,9 +97,21 @@ public override ChangesTreeNode SelectedNode
set
{
selectedNode = value;
if (value != null && selectionObject)

if (!IsUsingGlobalSelection)
{
return;
}

var activeObject = selectedNode != null
? AssetDatabase.LoadMainAssetAtPath(selectedNode.Path)
: null;

lastActivatedObject = activeObject;

if (TreeHasFocus)
{
Selection.activeObject = selectionObject;
Selection.activeObject = activeObject;
}
}
}
Expand All @@ -104,6 +121,18 @@ protected override List<ChangesTreeNode> Nodes
get { return nodes; }
}

public bool IsUsingGlobalSelection
{
get { return isUsingGlobalSelection; }
set { isUsingGlobalSelection = value; }
}

public override bool ViewHasFocus
{
get { return viewHasFocus; }
set { viewHasFocus = value; }
}

public void UpdateIcons(Texture2D folderIcon)
{
var needsLoad = FolderIcon == null;
Expand Down Expand Up @@ -186,19 +215,33 @@ protected override ChangesTreeNode CreateTreeNode(string path, string label, int
CheckState = isChecked ? CheckState.Checked : CheckState.Empty,
GitFileStatus = gitFileStatus,
ProjectPath = projectPath,
IsLocked = isLocked
IsLocked = isLocked,
};

if (isFolder && level >= 0)
{
folders.Add(node.Path, node);
}

if (IsUsingGlobalSelection)
{
if (node.Path != null)
{
var assetGuid = AssetDatabase.AssetPathToGUID(node.Path);

if (!string.IsNullOrEmpty(assetGuid))
{
assets.Add(assetGuid, node);
}
}
}

return node;
}

protected override void OnClear()
{
assets.Clear();
folders.Clear();
checkedFileNodes.Clear();
}
Expand All @@ -222,5 +265,26 @@ protected override void AddCheckedNode(ChangesTreeNode node)
{
checkedFileNodes.Add(((ITreeNode)node).Path, node);
}

public bool OnSelectionChange()
{
if (IsUsingGlobalSelection && !TreeHasFocus)
{
ChangesTreeNode assetNode = null;

if (Selection.activeObject != lastActivatedObject)
{
var activeAssetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
var activeAssetGuid = AssetDatabase.AssetPathToGUID(activeAssetPath);

assets.TryGetValue(activeAssetGuid, out assetNode);
}

SelectedNode = assetNode;
return true;
}

return false;
}
}
}
37 changes: 25 additions & 12 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ChangesView : Subview
[SerializeField] private string currentBranch = "[unknown]";

[SerializeField] private Vector2 treeScroll;
[SerializeField] private ChangesTree treeChanges = new ChangesTree { DisplayRootNode = false, IsCheckable = true };
[SerializeField] private ChangesTree treeChanges = new ChangesTree { DisplayRootNode = false, IsCheckable = true, IsUsingGlobalSelection = true };

[SerializeField] private HashSet<string> gitLocks;
[SerializeField] private List<GitStatusEntry> gitStatusEntries;
Expand All @@ -42,7 +42,13 @@ class ChangesView : Subview
public override void OnEnable()
{
base.OnEnable();
TreeOnEnable();

if (treeChanges != null)
{
treeChanges.ViewHasFocus = HasFocus;
treeChanges.UpdateIcons(Styles.FolderIcon);
}

AttachHandlers(Repository);
Repository.CheckCurrentBranchChangedEvent(lastCurrentBranchChangedEvent);
Repository.CheckStatusEntriesChangedEvent(lastStatusEntriesChangedEvent);
Expand Down Expand Up @@ -105,7 +111,23 @@ public override void OnGUI()
public override void OnSelectionChange()
{
base.OnSelectionChange();
Redraw();
if (treeChanges.OnSelectionChange())
{
Redraw();
}
}

public override void OnFocusChanged()
{
Logger.Debug("OnFocusChanged: {0}", HasFocus);

base.OnFocusChanged();
var hasFocus = HasFocus;
if (treeChanges.ViewHasFocus != hasFocus)
{
treeChanges.ViewHasFocus = hasFocus;
Redraw();
}
}

private void OnTreeGUI(Rect rect)
Expand Down Expand Up @@ -217,15 +239,6 @@ private void BuildTree()
Redraw();
}

private void TreeOnEnable()
{
if (treeChanges != null)
{
treeChanges.OnEnable();
treeChanges.UpdateIcons(Styles.FolderIcon);
}
}

private void OnCommitDetailsAreaGUI()
{
GUILayout.BeginHorizontal();
Expand Down
28 changes: 18 additions & 10 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,13 @@ class HistoryView : Subview
public override void OnEnable()
{
base.OnEnable();
TreeOnEnable();

if (treeChanges != null)
{
treeChanges.ViewHasFocus = HasFocus;
treeChanges.UpdateIcons(Styles.FolderIcon);
}

AttachHandlers(Repository);

if (Repository != null)
Expand All @@ -374,6 +380,17 @@ public override void OnDataUpdate()
MaybeUpdateData();
}

public override void OnFocusChanged()
{
base.OnFocusChanged();
var hasFocus = HasFocus;
if (treeChanges.ViewHasFocus != hasFocus)
{
treeChanges.ViewHasFocus = hasFocus;
Redraw();
}
}

public override void OnGUI()
{
// History toolbar
Expand Down Expand Up @@ -721,15 +738,6 @@ private void BuildTree()
Redraw();
}

private void TreeOnEnable()
{
if (treeChanges != null)
{
treeChanges.OnEnable();
treeChanges.UpdateIcons(Styles.FolderIcon);
}
}

public override bool IsBusy
{
get { return false; }
Expand Down
1 change: 1 addition & 0 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ interface IView
bool HasUser { get; }
IApplicationManager Manager { get; }
bool IsBusy { get; }
bool HasFocus { get; }
}
}
9 changes: 7 additions & 2 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ public virtual void OnDataUpdate()
{}

public virtual void OnGUI()
{}
{ }

public virtual void OnSelectionChange()
{}
{ }

public virtual void OnFocusChanged()
{ }

public virtual void Refresh()
{
Expand All @@ -54,6 +57,7 @@ public virtual void Finish(bool result)
public bool HasRepository { get { return Parent.HasRepository; } }
public IUser User { get { return Parent.User; } }
public bool HasUser { get { return Parent.HasUser; } }
public bool HasFocus { get { return Parent != null && Parent.HasFocus; } }
public abstract bool IsBusy { get; }
protected ITaskManager TaskManager { get { return Manager.TaskManager; } }
protected IGitClient GitClient { get { return Manager.GitClient; } }
Expand All @@ -64,6 +68,7 @@ public virtual void Finish(bool result)
public Vector2 Size { get; protected set; }

private ILogging logger;

protected ILogging Logger
{
get
Expand Down
Loading