mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-08-21 03:54:07 +02:00
.github
Application
Browser
Adapters
Bridge
Data
Handling
Filters
General
BrowserProcessHandler.cs
FileDialogHandler.cs
JavaScriptDialogHandler.cs
LifeSpanHandler.cs
ContextMenuBase.cs
ContextMenuBrowser.cs
ContextMenuGuide.cs
ContextMenuNotification.cs
DragHandlerBrowser.cs
KeyboardHandlerBase.cs
KeyboardHandlerBrowser.cs
KeyboardHandlerNotification.cs
RequestHandlerBase.cs
RequestHandlerBrowser.cs
ResourceHandlerFactory.cs
ResourceHandlerNotification.cs
Notification
FormBrowser.Designer.cs
FormBrowser.cs
FormBrowser.resx
TrayIcon.Designer.cs
TrayIcon.cs
TweetDeckBrowser.cs
Configuration
Controls
Dialogs
Management
Plugins
Properties
Resources
Updates
Utils
bld
lib
subprocess
video
.gitattributes
.gitignore
LICENSE.md
Program.cs
README.md
Reporter.cs
TweetDuck.csproj
TweetDuck.sln
TweetDuck.sln.DotSettings
packages.config
62 lines
2.5 KiB
C#
62 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using CefSharp;
|
|
|
|
namespace TweetDuck.Browser.Handling.General{
|
|
sealed class FileDialogHandler : IDialogHandler{
|
|
public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, CefFileDialogFlags flags, string title, string defaultFilePath, List<string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback){
|
|
if (mode == CefFileDialogMode.Open || mode == CefFileDialogMode.OpenMultiple){
|
|
string allFilters = string.Join(";", acceptFilters.SelectMany(ParseFileType).Where(filter => !string.IsNullOrEmpty(filter)).Select(filter => "*" + filter));
|
|
|
|
using(OpenFileDialog dialog = new OpenFileDialog{
|
|
AutoUpgradeEnabled = true,
|
|
DereferenceLinks = true,
|
|
Multiselect = mode == CefFileDialogMode.OpenMultiple,
|
|
Title = "Open Files",
|
|
Filter = $"All Supported Formats ({allFilters})|{allFilters}|All Files (*.*)|*.*"
|
|
}){
|
|
if (dialog.ShowDialog() == DialogResult.OK){
|
|
string ext = Path.GetExtension(dialog.FileName)?.ToLower();
|
|
callback.Continue(acceptFilters.FindIndex(filter => ParseFileType(filter).Contains(ext)), dialog.FileNames.ToList());
|
|
}
|
|
else{
|
|
callback.Cancel();
|
|
}
|
|
|
|
callback.Dispose();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
else{
|
|
callback.Dispose();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private static IEnumerable<string> ParseFileType(string type){
|
|
if (string.IsNullOrEmpty(type)){
|
|
return new string[0];
|
|
}
|
|
|
|
if (type[0] == '.'){
|
|
return new string[]{ type };
|
|
}
|
|
|
|
switch(type){
|
|
case "image/jpeg": return new string[]{ ".jpg", ".jpeg" };
|
|
case "image/png": return new string[]{ ".png" };
|
|
case "image/gif": return new string[]{ ".gif" };
|
|
case "image/webp": return new string[]{ ".webp" };
|
|
case "video/mp4": return new string[]{ ".mp4" };
|
|
case "video/quicktime": return new string[]{ ".mov", ".qt" };
|
|
}
|
|
|
|
System.Diagnostics.Debugger.Break();
|
|
return new string[0];
|
|
}
|
|
}
|
|
}
|