Skip to content

Commit

Permalink
Fixed #225 with ExplorerBrowser failing when added to designer window.
Browse files Browse the repository at this point in the history
  • Loading branch information
dahall committed Jul 21, 2021
1 parent 22afda9 commit d14609c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Windows.Forms/Controls/ExplorerBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -710,16 +710,16 @@ public int ThumbnailSize
{
get
{
using var fv2 = ComReleaserFactory.Create(GetFolderView2());
fv2.Item?.GetViewModeAndIconSize(out _, out thumbnailSize);
var fv2 = GetFolderView2();
fv2?.GetViewModeAndIconSize(out _, out thumbnailSize);
return thumbnailSize;
}
set
{
using var fv2 = ComReleaserFactory.Create(GetFolderView2());
if (fv2.Item is null) return;
fv2.Item.GetViewModeAndIconSize(out var fvm, out _);
fv2.Item.SetViewModeAndIconSize(fvm, thumbnailSize = value);
var fv2 = GetFolderView2();
if (fv2 is null) return;
fv2.GetViewModeAndIconSize(out var fvm, out _);
fv2.SetViewModeAndIconSize(fvm, thumbnailSize = value);
}
}

Expand Down Expand Up @@ -822,17 +822,17 @@ public void Navigate(ShellItem shellItem, ExplorerBrowserNavigationItemCategory
/// <summary>Selects all items in the current view.</summary>
public void SelectAll()
{
using var fv2 = ComReleaserFactory.Create(GetFolderView2());
if (fv2.Item is null) return;
for (var i = 0; i < fv2.Item.ItemCount(SVGIO.SVGIO_ALLVIEW); i++)
fv2.Item.SelectItem(i, SVSIF.SVSI_SELECT);
var fv2 = GetFolderView2();
if (fv2 is null) return;
for (var i = 0; i < fv2.ItemCount(SVGIO.SVGIO_ALLVIEW); i++)
fv2.SelectItem(i, SVSIF.SVSI_SELECT);
}

/// <summary>Unselects all items in the current view.</summary>
public void UnselectAll()
{
using var fv2 = ComReleaserFactory.Create(GetFolderView2());
fv2.Item?.SelectItem(-1, SVSIF.SVSI_DESELECTOTHERS);
var fv2 = GetFolderView2();
fv2?.SelectItem(-1, SVSIF.SVSI_DESELECTOTHERS);
}

HRESULT ICommDlgBrowser3.GetCurrentFilter(StringBuilder pszFileSpec, int cchFileSpec) => HRESULT.S_OK;
Expand Down Expand Up @@ -955,8 +955,8 @@ internal IShellItemArray GetItemsArray(SVGIO opt)
{
try
{
using var fv2 = ComReleaserFactory.Create(GetFolderView2());
return fv2.Item?.Items<IShellItemArray>(opt);
var fv2 = GetFolderView2();
return fv2?.Items<IShellItemArray>(opt);
}
catch { return null; }
}
Expand Down Expand Up @@ -1132,8 +1132,8 @@ protected override void OnSizeChanged(EventArgs e)

private FOLDERVIEWMODE GetCurrentViewMode()
{
using var fv2 = ComReleaserFactory.Create(GetFolderView2());
return fv2.Item?.GetCurrentViewMode() ?? 0;
var fv2 = GetFolderView2();
return fv2?.GetCurrentViewMode() ?? 0;
}

private bool IsContentFlagSet(ExplorerBrowserContentSectionOptions flag) => folderSettings.fFlags.IsFlagSet((FOLDERFLAGS)flag);
Expand Down Expand Up @@ -1433,8 +1433,8 @@ public int Count
{
get
{
using var fv2 = ComReleaserFactory.Create(eb?.GetFolderView2());
return fv2.Item?.ItemCount(option) ?? 0;
var fv2 = eb?.GetFolderView2();
return fv2?.ItemCount(option) ?? 0;
}
}

Expand Down
3 changes: 3 additions & 0 deletions Windows.Forms/Vanara.Windows.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ BitmapProperty, BoolProperty, CloakingSource, CollapsiblePanelBorderCondition, C
<None Remove="Controls\ExplorerBrowser.bmp" />
<None Remove="Controls\ShellNamespaceTreeControl.bmp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Theraot.Core" Version="3.2.5" Condition=" $(TargetFramework.StartsWith('net2')) Or $(TargetFramework.StartsWith('net3')) Or $(TargetFramework.StartsWith('net4')) " />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net2')) Or $(TargetFramework.StartsWith('net3')) Or $(TargetFramework.StartsWith('net4')) ">
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
Expand Down

0 comments on commit d14609c

Please sign in to comment.