Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
Handles disposed windows when they are closed while the windows loop
Browse files Browse the repository at this point in the history
Fixes VSTS #999372 - System.ObjectDisposedException exception in Foundation.NSObject.get_SuperHandle()
  • Loading branch information
netonjm authored and monojenkins committed Dec 3, 2019
1 parent 251bc47 commit 3d51fd4
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,38 @@ internal class OpenWindowListHandler : CommandHandler
protected override void Update (CommandArrayInfo info)
{
foreach (Components.Window window in IdeApp.CommandService.TopLevelWindowStack) {

string title = null;
bool hasTopLevel = false;

try {
title = window.Title;
hasTopLevel = window.HasTopLevelFocus;
#if !WINDOWS
//we don't want include hidden windows
if (!window.IsRealized || !window.IsVisible || Components.Mac.GtkMacInterop.IsGdkQuartzWindow (window))
continue;
//we don't want include hidden windows
if (!window.IsRealized || !window.IsVisible || Components.Mac.GtkMacInterop.IsGdkQuartzWindow (window))
continue;
#endif
} catch (System.ObjectDisposedException) {
//this means the window was closed while the loop then we want continue to next element
continue;
}


//Create CommandInfo object
var commandInfo = new CommandInfo ();
commandInfo.Text = window.Title.Replace ("_", "__").Replace ("-", "\u2013").Replace (" \u2013 " + BrandingService.ApplicationName, "");
commandInfo.Text = title.Replace ("_", "__").Replace ("-", "\u2013").Replace (" \u2013 " + BrandingService.ApplicationName, "");

if (string.IsNullOrEmpty (commandInfo.Text)) {
commandInfo.Text = GettextCatalog.GetString ("No description");
}

if (window.HasTopLevelFocus)
if (hasTopLevel)
commandInfo.Checked = true;
commandInfo.Description = GettextCatalog.GetString ("Activate window '{0}'", commandInfo.Text);

//Add menu item
info.Add (commandInfo, window.Title);
info.Add (commandInfo, title);
}
}

Expand Down

0 comments on commit 3d51fd4

Please sign in to comment.