Skip to content

Commit

Permalink
Merge pull request #2894 from VsVim/dev/nosami/fix-2893
Browse files Browse the repository at this point in the history
[Mac] Fix window management in VSMac 8.10+
  • Loading branch information
nosami committed May 29, 2021
2 parents 5fdb893 + 06afa63 commit 5124ebc
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions Src/VimMac/WindowManagement.cs
Expand Up @@ -53,29 +53,48 @@ private static string GetTabFileName(object tab)
return fileName;
}

private static Notebook ToNotebook(object obj)
private static Notebook ToNotebook(object container)
{
var notebookType = obj.GetType();
var childrenProperty = notebookType.GetProperty("Children", instanceFlags);
var children = (object[])childrenProperty.GetValue(obj);
bool isActiveNotebook = false;
int currentTab = 0;

if (children.Length > 0)
{
var tabstrip = children[0];
var tabstripType = tabstrip.GetType();
isActiveNotebook = (bool)tabstripType.GetProperty("IsActiveNotebook").GetValue(tabstrip);
}
var notebookType = container.GetType();
bool isActiveNotebook = IsActiveNotebook(container, notebookType);

currentTab = (int)notebookType.GetProperty("CurrentTabIndex", instanceFlags).GetValue(obj);
int currentTab = (int)notebookType.GetProperty("CurrentTabIndex", instanceFlags).GetValue(container);

var tabs = (IEnumerable<object>)notebookType.GetProperty("Tabs", instanceFlags).GetValue(obj);
var tabs = (IEnumerable<object>)notebookType.GetProperty("Tabs", instanceFlags).GetValue(container);

var files = tabs.Select(GetTabFileName).ToImmutableArray();

return new Notebook(isActiveNotebook, currentTab, files);
}

private static bool IsActiveNotebook(object container, Type notebookType)
{
var tabStripControllerProperty = notebookType.GetProperty("TabStripController", instanceFlags);

bool isActiveNotebook = false;
Type tabStripType;

if (tabStripControllerProperty != null)
{
var tabStripController = tabStripControllerProperty.GetValue(container);
// VSMac 8.10+
tabStripType = tabStripControllerProperty.PropertyType;
isActiveNotebook = (bool)tabStripType.GetProperty("IsActiveNotebook").GetValue(tabStripController);
}
else
{
// VSMac 8.9 and earlier
var childrenProperty = notebookType.GetProperty("Children", instanceFlags);
var children = (object[])childrenProperty.GetValue(container);

if (children.Length > 0)
{
var tabStrip = children[0];
tabStripType = tabStrip.GetType();
isActiveNotebook = (bool)tabStripType.GetProperty("IsActiveNotebook").GetValue(tabStrip);
}
}
return isActiveNotebook;
}
}
}

0 comments on commit 5124ebc

Please sign in to comment.