Implement RunFileChooser
This commit is contained in:
parent
7d15aa2321
commit
0f5a058bdd
1 changed files with 39 additions and 0 deletions
|
@ -9,8 +9,10 @@
|
||||||
#include "atom/browser/ui/file_dialog.h"
|
#include "atom/browser/ui/file_dialog.h"
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/files/file_enumerator.h"
|
#include "base/files/file_enumerator.h"
|
||||||
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
|
#include "ui/shell_dialogs/selected_file_info.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -24,6 +26,43 @@ WebDialogHelper::~WebDialogHelper() {
|
||||||
|
|
||||||
void WebDialogHelper::RunFileChooser(content::WebContents* web_contents,
|
void WebDialogHelper::RunFileChooser(content::WebContents* web_contents,
|
||||||
const content::FileChooserParams& params) {
|
const content::FileChooserParams& params) {
|
||||||
|
std::vector<ui::SelectedFileInfo> result;
|
||||||
|
if (params.mode == content::FileChooserParams::Save) {
|
||||||
|
base::FilePath path;
|
||||||
|
if (file_dialog::ShowSaveDialog(window_,
|
||||||
|
base::UTF16ToUTF8(params.title),
|
||||||
|
params.default_file_name,
|
||||||
|
file_dialog::Filters(),
|
||||||
|
&path))
|
||||||
|
result.push_back(ui::SelectedFileInfo(path, path));
|
||||||
|
} else {
|
||||||
|
int flags = file_dialog::FILE_DIALOG_CREATE_DIRECTORY;
|
||||||
|
switch (params.mode) {
|
||||||
|
case content::FileChooserParams::OpenMultiple:
|
||||||
|
flags |= file_dialog::FILE_DIALOG_MULTI_SELECTIONS;
|
||||||
|
case content::FileChooserParams::Open:
|
||||||
|
flags |= file_dialog::FILE_DIALOG_OPEN_FILE;
|
||||||
|
break;
|
||||||
|
case content::FileChooserParams::UploadFolder:
|
||||||
|
flags |= file_dialog::FILE_DIALOG_OPEN_DIRECTORY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NOTREACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<base::FilePath> paths;
|
||||||
|
if (file_dialog::ShowOpenDialog(window_,
|
||||||
|
base::UTF16ToUTF8(params.title),
|
||||||
|
params.default_file_name,
|
||||||
|
file_dialog::Filters(),
|
||||||
|
flags,
|
||||||
|
&paths))
|
||||||
|
for (auto& path : paths)
|
||||||
|
result.push_back(ui::SelectedFileInfo(path, path));
|
||||||
|
}
|
||||||
|
|
||||||
|
web_contents->GetRenderViewHost()->FilesSelectedInChooser(
|
||||||
|
result, params.mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebDialogHelper::EnumerateDirectory(content::WebContents* web_contents,
|
void WebDialogHelper::EnumerateDirectory(content::WebContents* web_contents,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue