CefDialogHandler.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Implement this interface to handle dialog events. The methods of this class
  10. /// will be called on the browser process UI thread.
  11. /// </summary>
  12. public abstract unsafe partial class CefDialogHandler
  13. {
  14. private int on_file_dialog(cef_dialog_handler_t* self, cef_browser_t* browser, CefFileDialogMode mode, cef_string_t* title, cef_string_t* default_file_path, cef_string_list* accept_filters, int selected_accept_filter, cef_file_dialog_callback_t* callback)
  15. {
  16. CheckSelf(self);
  17. var mBrowser = CefBrowser.FromNative(browser);
  18. var mTitle = cef_string_t.ToString(title);
  19. var mDefaultFilePath = cef_string_t.ToString(default_file_path);
  20. var mAcceptFilters = cef_string_list.ToArray(accept_filters);
  21. var mCallback = CefFileDialogCallback.FromNative(callback);
  22. var result = OnFileDialog(mBrowser, mode, mTitle, mDefaultFilePath, mAcceptFilters, selected_accept_filter, mCallback);
  23. return result ? 1 : 0;
  24. }
  25. /// <summary>
  26. /// Called to run a file chooser dialog. |mode| represents the type of dialog
  27. /// to display. |title| to the title to be used for the dialog and may be empty
  28. /// to show the default title ("Open" or "Save" depending on the mode).
  29. /// |default_file_path| is the path with optional directory and/or file name
  30. /// component that should be initially selected in the dialog. |accept_filters|
  31. /// are used to restrict the selectable file types and may any combination of
  32. /// (a) valid lower-cased MIME types (e.g. "text/*" or "image/*"),
  33. /// (b) individual file extensions (e.g. ".txt" or ".png"), or (c) combined
  34. /// description and file extension delimited using "|" and ";" (e.g.
  35. /// "Image Types|.png;.gif;.jpg"). |selected_accept_filter| is the 0-based
  36. /// index of the filter that should be selected by default. To display a custom
  37. /// dialog return true and execute |callback| either inline or at a later time.
  38. /// To display the default dialog return false.
  39. /// </summary>
  40. protected virtual bool OnFileDialog(CefBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, string[] acceptFilters, int selectedAcceptFilter, CefFileDialogCallback callback)
  41. {
  42. return false;
  43. }
  44. }
  45. }