Пример #1
0
 public bool OnFileDialog(IWebBrowser chromiumWebBrowser, IBrowser browser
                          , CefFileDialogMode mode, CefFileDialogFlags flags
                          , string title, string defaultFilePath
                          , List <string> acceptFilters, int selectedAcceptFilter
                          , IFileDialogCallback callback)
 {
     return(true);
 }
Пример #2
0
 /// <inheritdoc/>
 bool IDialogHandler.OnFileDialog(
     IWebBrowser chromiumWebBrowser,
     IBrowser browser,
     CefFileDialogMode mode,
     CefFileDialogFlags flags,
     string title,
     string defaultFilePath,
     List <string> acceptFilters,
     int selectedAcceptFilter,
     IFileDialogCallback callback)
 {
     return(OnFileDialog(chromiumWebBrowser, browser, mode, flags, title, defaultFilePath, acceptFilters, selectedAcceptFilter, callback));
 }
        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);
            }
        }
Пример #4
0
        public bool OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, CefFileDialogFlags flags, string title, string defaultFilePath, List <string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
        {
            callback.Continue(selectedAcceptFilter, new List <string> {
                Path.GetRandomFileName()
            });

            return(true);
        }
Пример #5
0
        public bool OnFileDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, CefFileDialogMode mode, CefFileDialogFlags flags, string title, string defaultFilePath, List <string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
        {
            try
            {
                var files = new List <FsFile>();
                if (CefFileDialogMode.OpenFolder == (mode & CefFileDialogMode.OpenFolder))
                {
                    using (var dialog = new FolderBrowserDialog()
                    {
                        SelectedPath = defaultFilePath.DefaultIfNullOrWhiteSpace(_app.LastFileDialogDirectory)
                    })
                    {
                        if (!string.IsNullOrWhiteSpace(title))
                        {
                            dialog.Description = title;
                        }

                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            var dir = new DirectoryInfo(dialog.SelectedPath);

                            _app.LastFileDialogDirectory = dir.FullName;

                            files.Add(new FsFile()
                            {
                                Name         = dir.Name,
                                Path         = dir.FullName,
                                Type         = "directory",
                                LastModified = (long)Utils.ConvertToUnixTimestamp(dir.LastWriteTime)
                            });
                            OsEvent.Emit(replyMsgName, null, false, files);
                            callback.Continue(selectedAcceptFilter, new List <string> {
                                dialog.SelectedPath
                            });
                        }
                        else
                        {
                            OsEvent.Emit(replyMsgName, null, true, files);
                            callback.Cancel();
                        }
                    }
                }
                else
                {
                    var filter = string.Join("|", acceptFilters.Select(ext =>
                    {
                        if (string.IsNullOrWhiteSpace(ext))
                        {
                            return("");
                        }

                        var fileType = Utils.GetFileType(ext);

                        if (string.IsNullOrWhiteSpace(fileType))
                        {
                            // Maybe the accept type is already a mime type
                            fileType = ext;
                            ext      = Utils.GetFileTypeExtension(fileType);

                            if (string.IsNullOrWhiteSpace(ext))
                            {
                                return("");
                            }
                        }

                        return($"{fileType}|*{ext}");
                    }));

                    if (string.IsNullOrWhiteSpace(filter))
                    {
                        filter = "All Files|*.*";
                    }

                    using (var dialog = new OpenFileDialog
                    {
                        Multiselect = CefFileDialogMode.OpenMultiple == (mode & CefFileDialogMode.OpenMultiple),
                        Title = title,
                        Filter = filter,
                        InitialDirectory = defaultFilePath.DefaultIfNullOrWhiteSpace(_app.LastFileDialogDirectory),
                        FilterIndex = selectedAcceptFilter
                    })
                    {
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            if (dialog.FileNames != null)
                            {
                                files = dialog.FileNames.Select(f =>
                                {
                                    var file = new FileInfo(f);

                                    return(new FsFile()
                                    {
                                        Name = file.Name,
                                        Path = file.FullName,
                                        Size = file.Length,
                                        Type = Utils.GetMimeType(file.Extension),
                                        LastModified = (long)Utils.ConvertToUnixTimestamp(file.LastWriteTime)
                                    });
                                }).ToList();

                                if (files.Count > 0)
                                {
                                    _app.LastFileDialogDirectory = Path.GetDirectoryName(files.Last().Path);
                                }
                            }
                            OsEvent.Emit(replyMsgName, null, false, files);
                            callback.Continue(selectedAcceptFilter, dialog.FileNames.ToList());
                        }
                        else
                        {
                            OsEvent.Emit(replyMsgName, null, true, files);
                            callback.Cancel();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                OsEvent.Emit(replyMsgName, e);
            }

            return(true);
        }
Пример #6
0
        public bool OnFileDialog(IWebBrowser webBrowser, IBrowser browser, CefFileDialogMode mode, CefFileDialogFlags flags, string title, string defaultFilePath, List <string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
        {
            var args = new DialogRequestedEventArgs
            {
                Element     = ToElement(mode),
                InitialPath = defaultFilePath,
                Operation   = ToOperation(mode),
                Title       = title
            };

            Task.Run(() =>
            {
                DialogRequested?.Invoke(args);

                using (callback)
                {
                    if (args.Success)
                    {
                        callback.Continue(selectedAcceptFilter, new List <string> {
                            args.FullPath
                        });
                    }
                    else
                    {
                        callback.Cancel();
                    }
                }
            });

            return(true);
        }
Пример #7
0
 bool IDialogHandler.OnFileDialog(IWebBrowser browserControl, IBrowser browser, CefFileDialogMode mode, CefFileDialogFlags flags, string title, string defaultFilePath, List <string> acceptFilters, int selectedAcceptFilter, IFileDialogCallback callback)
 {
     if (OwnerWebView.DisableFileDialogs)
     {
         return(true);
     }
     return(false);
 }