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

Commit 4af80f7

Browse files
Functionality to make global selection optional
1 parent 7dce10d commit 4af80f7

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,11 @@ private void TreeOnEnable()
179179
{
180180
if (treeLocals != null)
181181
{
182-
treeLocals.OnEnable();
183182
treeLocals.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
184183
}
185184

186185
if (treeRemotes != null)
187186
{
188-
treeRemotes.OnEnable();
189187
treeRemotes.UpdateIcons(Styles.ActiveBranchIcon, Styles.BranchIcon, Styles.FolderIcon, Styles.GlobeIcon);
190188
}
191189
}

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using UnityEditor;
55
using UnityEngine;
6+
using Object = UnityEngine.Object;
67

78
namespace GitHub.Unity
89
{
@@ -47,8 +48,10 @@ public class ChangesTree : Tree<ChangesTreeNode, GitStatusEntryTreeData>
4748
[SerializeField] public bool displayRootNode = true;
4849
[SerializeField] public bool isSelectable = true;
4950
[SerializeField] public bool isCheckable = false;
51+
[SerializeField] public bool isUsingGlobalSelection = false;
5052
[SerializeField] private List<ChangesTreeNode> nodes = new List<ChangesTreeNode>();
5153
[SerializeField] private ChangesTreeNode selectedNode = null;
54+
[NonSerialized] private Object lastActiveObject;
5255

5356
public override string Title
5457
{
@@ -92,6 +95,27 @@ public override ChangesTreeNode SelectedNode
9295
set
9396
{
9497
selectedNode = value;
98+
99+
if (!IsUsingGlobalSelection)
100+
{
101+
return;
102+
}
103+
104+
Object activeObject = null;
105+
if (selectedNode != null)
106+
{
107+
var projectPath = selectedNode.ProjectPath;
108+
if (projectPath.StartsWith("Assets"))
109+
{
110+
var assetGuid = AssetDatabase.AssetPathToGUID(projectPath);
111+
activeObject = !string.IsNullOrEmpty(assetGuid)
112+
? AssetDatabase.LoadMainAssetAtPath(projectPath)
113+
: null;
114+
}
115+
}
116+
117+
lastActiveObject = activeObject;
118+
Selection.activeObject = activeObject;
95119
}
96120
}
97121

@@ -100,6 +124,12 @@ protected override List<ChangesTreeNode> Nodes
100124
get { return nodes; }
101125
}
102126

127+
public bool IsUsingGlobalSelection
128+
{
129+
get { return isUsingGlobalSelection; }
130+
set { isUsingGlobalSelection = value; }
131+
}
132+
103133
public void UpdateIcons(Texture2D folderIcon)
104134
{
105135
var needsLoad = FolderIcon == null;
@@ -218,5 +248,16 @@ protected override void AddCheckedNode(ChangesTreeNode node)
218248
{
219249
checkedFileNodes.Add(((ITreeNode)node).Path, node);
220250
}
251+
252+
public override Rect Render(Rect treeDisplayRect, Vector2 scroll, Action<ChangesTreeNode> singleClick = null, Action<ChangesTreeNode> doubleClick = null,
253+
Action<ChangesTreeNode> rightClick = null)
254+
{
255+
if (IsUsingGlobalSelection && lastActiveObject != null && Selection.activeObject != lastActiveObject)
256+
{
257+
SelectedNode = null;
258+
}
259+
260+
return base.Render(treeDisplayRect, scroll, singleClick, doubleClick, rightClick);
261+
}
221262
}
222263
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ private void TreeOnEnable()
227227
{
228228
if (treeChanges != null)
229229
{
230-
treeChanges.OnEnable();
231230
treeChanges.UpdateIcons(Styles.FolderIcon);
232231
}
233232
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public abstract class Tree<TNode, TData>: TreeBase<TNode, TData>
3232
public bool IsInitialized { get { return Nodes != null && Nodes.Count > 0 && !String.IsNullOrEmpty(Nodes[0].Path); } }
3333
public bool RequiresRepaint { get; private set; }
3434

35-
public Rect Render(Rect treeDisplayRect, Vector2 scroll, Action<TNode> singleClick = null, Action<TNode> doubleClick = null, Action<TNode> rightClick = null)
35+
public virtual Rect Render(Rect treeDisplayRect, Vector2 scroll, Action<TNode> singleClick = null, Action<TNode> doubleClick = null, Action<TNode> rightClick = null)
3636
{
3737
controlId = GUIUtility.GetControlID(FocusType.Keyboard);
3838
var treeHasFocus = GUIUtility.keyboardControl == controlId;
@@ -322,11 +322,6 @@ protected void LoadNodeIcons()
322322
SetNodeIcon(treeNode);
323323
}
324324
}
325-
326-
public void OnEnable()
327-
{
328-
329-
}
330325
}
331326

332327
[Serializable]

0 commit comments

Comments
 (0)