Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mac] Fix window management in VSMac 8.10+ #2894

Merged
merged 1 commit into from
May 29, 2021
Merged
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
49 changes: 34 additions & 15 deletions Src/VimMac/WindowManagement.cs
Original file line number Diff line number Diff line change
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;
}
}
}