Skip to content

Commit

Permalink
Enrich code comment and adjust format
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Oct 8, 2023
1 parent b365fd1 commit b3c786a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
50 changes: 21 additions & 29 deletions src/details/QCefViewPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,15 +584,22 @@ QCefViewPrivate::onRunCefContextMenu(QPoint pos, CefRefPtr<CefRunContextMenuCall
}

void
QCefViewPrivate::onFileDialog(CefRefPtr<CefBrowser> browser,
CefBrowserHost::FileDialogMode mode,
QCefViewPrivate::onCefContextMenuDismissed()
{
osr.contextMenuCallback_ = nullptr;
}

void
QCefViewPrivate::onFileDialog(CefBrowserHost::FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
CefRefPtr<CefFileDialogCallback> callback)
{
Q_Q(QCefView);
QFileDialog dialog;

// create dialog and set mode
QFileDialog dialog(q_ptr);
if (mode == FILE_DIALOG_OPEN) {
dialog.setFileMode(QFileDialog::ExistingFile);
} else if (mode == FILE_DIALOG_OPEN_MULTIPLE) {
Expand All @@ -606,28 +613,15 @@ QCefViewPrivate::onFileDialog(CefRefPtr<CefBrowser> browser,
callback->Cancel();
return;
}
QString title_str;

// set title
QString caption;
if (!title.empty()) {
title_str = title.ToString().c_str();
} else {
switch (mode) {
case FILE_DIALOG_OPEN:
title_str = "Open File";
break;
case FILE_DIALOG_OPEN_MULTIPLE:
title_str = "Open Files";
break;
case FILE_DIALOG_OPEN_FOLDER:
title_str = "Open Folder";
break;
case FILE_DIALOG_SAVE:
title_str = "Save File";
break;
default:
break;
}
caption = title.ToString().c_str();
dialog.setWindowTitle(caption);
}
dialog.setWindowTitle(title_str);

// set initial folder
if (!default_file_path.empty() && mode == FILE_DIALOG_SAVE) {
QDir dir(QString::fromStdString(default_file_path.ToString()));
if (dir.exists()) {
Expand All @@ -636,13 +630,17 @@ QCefViewPrivate::onFileDialog(CefRefPtr<CefBrowser> browser,
dialog.setDirectory(QDir::homePath());
}
}

// set accepted file types
if (!accept_filters.empty()) {
QStringList filters;
for (const auto& filter : accept_filters) {
filters << "*" + QString::fromStdString(filter.ToString());
}
dialog.setNameFilter(QString("(%1)").arg(filters.join(" ")));
}

// execute the dialog
if (dialog.exec()) {
std::vector<CefString> file_paths;
auto selected_files = dialog.selectedFiles();
Expand All @@ -655,12 +653,6 @@ QCefViewPrivate::onFileDialog(CefRefPtr<CefBrowser> browser,
}
}

void
QCefViewPrivate::onCefContextMenuDismissed()
{
osr.contextMenuCallback_ = nullptr;
}

bool
QCefViewPrivate::hasDevTools()
{
Expand Down
7 changes: 3 additions & 4 deletions src/details/QCefViewPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,14 @@ public slots:

void onRunCefContextMenu(QPoint pos, CefRefPtr<CefRunContextMenuCallback> callback);

void onFileDialog(CefRefPtr<CefBrowser> browser,
CefBrowserHost::FileDialogMode mode,
void onCefContextMenuDismissed();

void onFileDialog(CefBrowserHost::FileDialogMode mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
CefRefPtr<CefFileDialogCallback> callback);

void onCefContextMenuDismissed();

bool hasDevTools();

void showDevTools();
Expand Down

0 comments on commit b3c786a

Please sign in to comment.