-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
411f7ca
commit ff27f39
Showing
25 changed files
with
1,032 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
MintPlayer.BrowserDialog.Demo/MintPlayer.BrowserDialog.Demo.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,120 @@ | ||
using MintPlayer.IconUtils; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Data; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace MintPlayer.BrowserDialog | ||
|
||
namespace MintPlayer.BrowserDialog; | ||
|
||
public partial class BrowserDialog : Form | ||
{ | ||
public partial class BrowserDialog : Form | ||
public BrowserDialog() | ||
{ | ||
public BrowserDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
InitializeComponent(); | ||
} | ||
|
||
private void BrowserDialog_Load(object sender, EventArgs e) | ||
private void BrowserDialog_Load(object sender, EventArgs e) | ||
{ | ||
try | ||
{ | ||
try | ||
{ | ||
// Suspend the drawing of the listview | ||
lvBrowsers.SuspendLayout(); | ||
// Suspend the drawing of the listview | ||
lvBrowsers.SuspendLayout(); | ||
|
||
// Remove all items from the listview | ||
lvBrowsers.Items.Clear(); | ||
// Remove all items from the listview | ||
lvBrowsers.Items.Clear(); | ||
|
||
// Assign a new imagelist | ||
lvBrowsers.LargeImageList = new ImageList | ||
{ | ||
ImageSize = new Size(60, 60), | ||
ColorDepth = ColorDepth.Depth32Bit | ||
}; | ||
// Assign a new imagelist | ||
lvBrowsers.LargeImageList = new ImageList | ||
{ | ||
ImageSize = new Size(60, 60), | ||
ColorDepth = ColorDepth.Depth32Bit | ||
}; | ||
|
||
// Get all browsers on the system | ||
browsers = PlatformBrowser.PlatformBrowser.GetInstalledBrowsers(); | ||
// Get all browsers on the system | ||
browsers = PlatformBrowser.PlatformBrowser.GetInstalledBrowsers(); | ||
|
||
// Loop through all browsers | ||
for (var i = 0; i < browsers.Count; i++) | ||
{ | ||
var browser = browsers[i]; | ||
// Loop through all browsers | ||
for (var i = 0; i < browsers.Count; i++) | ||
{ | ||
var browser = browsers[i]; | ||
|
||
// Get image | ||
var icon = IconExtractor.Split(browser.IconPath)[browser.IconIndex < 0 ? 0 : browser.IconIndex]; | ||
var icons = IconExtractor.ExtractImagesFromIcon(icon); | ||
var largestSize = icons.Max(i => i.Width); | ||
var largestIcon = icons.LastOrDefault(i => i.Width == largestSize); | ||
// Get image | ||
var icon = IconExtractor.Split(browser.IconPath)[browser.IconIndex < 0 ? 0 : browser.IconIndex]; | ||
var icons = IconExtractor.ExtractImagesFromIcon(icon); | ||
var largestSize = icons.Max(i => i.Width); | ||
var largestIcon = icons.LastOrDefault(i => i.Width == largestSize); | ||
if (largestIcon != null) | ||
{ | ||
lvBrowsers.LargeImageList.Images.Add(largestIcon); | ||
|
||
lvBrowsers.Items.Add(new ListViewItem | ||
{ | ||
Text = browser.Name, | ||
Tag = browser.ExecutablePath.Trim('\"'), | ||
ImageIndex = i, | ||
}); | ||
} | ||
|
||
// Get default browser | ||
defaultBrowser = PlatformBrowser.PlatformBrowser.GetDefaultBrowser(browsers.ToList(), PlatformBrowser.Enums.eProtocolType.Http); | ||
|
||
// Select default browser | ||
if (browsers.Contains(defaultBrowser)) | ||
lvBrowsers.Items.Add(new ListViewItem | ||
{ | ||
var defaultBrowserListItem = lvBrowsers.Items[ | ||
browsers.IndexOf( | ||
browsers.FirstOrDefault(b => b.ExecutablePath == defaultBrowser.ExecutablePath) | ||
) | ||
]; | ||
defaultBrowserListItem.Focused = defaultBrowserListItem.Selected = true; | ||
} | ||
Text = browser.Name, | ||
Tag = browser.ExecutablePath.Trim('\"'), | ||
ImageIndex = i, | ||
}); | ||
} | ||
catch (Exception) | ||
{ | ||
// Don't interrupt the dialog | ||
} | ||
finally | ||
|
||
// Get default browser | ||
defaultBrowser = PlatformBrowser.PlatformBrowser.GetDefaultBrowser(browsers.ToList(), PlatformBrowser.Enums.EProtocolType.Http); | ||
|
||
// Select default browser | ||
if (browsers.Contains(defaultBrowser!)) | ||
{ | ||
lvBrowsers.ResumeLayout(); | ||
var defaultBrowserListItem = lvBrowsers.Items[ | ||
browsers.IndexOf( | ||
browsers.FirstOrDefault(b => b.ExecutablePath == defaultBrowser?.ExecutablePath)! | ||
) | ||
]; | ||
defaultBrowserListItem.Focused = defaultBrowserListItem.Selected = true; | ||
} | ||
} | ||
|
||
private void BrowserDialog_Shown(object sender, EventArgs e) | ||
catch (Exception) | ||
{ | ||
lvBrowsers.Focus(); | ||
// Don't interrupt the dialog | ||
} | ||
finally | ||
{ | ||
lvBrowsers.ResumeLayout(); | ||
} | ||
} | ||
|
||
private ReadOnlyCollection<PlatformBrowser.Browser> browsers = new ReadOnlyCollection<PlatformBrowser.Browser>(new List<PlatformBrowser.Browser>()); | ||
private PlatformBrowser.Browser defaultBrowser; | ||
public PlatformBrowser.Browser SelectedBrowser | ||
private void BrowserDialog_Shown(object sender, EventArgs e) | ||
{ | ||
lvBrowsers.Focus(); | ||
} | ||
|
||
private ReadOnlyCollection<PlatformBrowser.Browser> browsers = new ReadOnlyCollection<PlatformBrowser.Browser>(new List<PlatformBrowser.Browser>()); | ||
private PlatformBrowser.Browser? defaultBrowser; | ||
public PlatformBrowser.Browser? SelectedBrowser | ||
{ | ||
get | ||
{ | ||
get | ||
if (lvBrowsers.SelectedIndices.Count == 0) | ||
{ | ||
if (lvBrowsers.SelectedIndices.Count == 0) | ||
{ | ||
return null; | ||
} | ||
else | ||
{ | ||
return browsers[lvBrowsers.SelectedIndices[0]]; | ||
} | ||
return null; | ||
} | ||
set | ||
else | ||
{ | ||
lvBrowsers.SelectedIndices.Clear(); | ||
if (value == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (browsers.Any(b => b.Name == value.Name)) | ||
{ | ||
lvBrowsers.SelectedIndices.Add(browsers.IndexOf(value)); | ||
} | ||
return browsers[lvBrowsers.SelectedIndices[0]]; | ||
} | ||
} | ||
|
||
private void LvBrowsers_SelectedIndexChanged(object sender, EventArgs e) | ||
set | ||
{ | ||
btnOK.Enabled = lvBrowsers.SelectedItems.Count != 0; | ||
lvBrowsers.SelectedIndices.Clear(); | ||
if (value == null) | ||
{ | ||
return; | ||
} | ||
|
||
if (browsers.Any(b => b.Name == value.Name)) | ||
{ | ||
lvBrowsers.SelectedIndices.Add(browsers.IndexOf(value)); | ||
} | ||
} | ||
} | ||
|
||
private void LvBrowsers_SelectedIndexChanged(object sender, EventArgs e) | ||
{ | ||
btnOK.Enabled = lvBrowsers.SelectedItems.Count != 0; | ||
} | ||
|
||
} |
Oops, something went wrong.