fix: i18n of gtk msgbox buttons (#19904)

* fix: i18n of gtk msgbox buttons

similar to #19756 (12df0e8) but for messageboxes

* refactor: DRY the gtk+ button mnemonics

* fix: don't compile gtk_util on non-Linux platforms

rename from `gtk_util.[cc,h]` to `util_gtk.[cc,h]` so that it gets
picked up by the `extra_source_filters` rule in `BUILD.gn`.

* fix: make linter happy

It really shows that I cannot build locally atm... :P
This commit is contained in:
Charles Kerr 2019-08-27 09:57:12 -05:00 committed by GitHub
parent 2542c51c48
commit 7e61cd0dfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 32 deletions

View file

@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "shell/browser/ui/file_dialog.h"
#include "shell/browser/ui/util_gtk.h"
#include "base/callback.h"
#include "base/files/file_util.h"
@ -21,27 +22,6 @@ DialogSettings::~DialogSettings() = default;
namespace {
// Copied from L40-L55 in
// https://cs.chromium.org/chromium/src/chrome/browser/ui/libgtkui/select_file_dialog_impl_gtk.cc
#if GTK_CHECK_VERSION(3, 90, 0)
// GTK stock items have been deprecated. The docs say to switch to using the
// strings "_Open", etc. However this breaks i18n. We could supply our own
// internationalized strings, but the "_" in these strings is significant: it's
// the keyboard shortcut to select these actions. TODO(thomasanderson): Provide
// internationalized strings when GTK provides support for it.
const char kOkLabel[] = "_Ok";
const char kCancelLabel[] = "_Cancel";
const char kOpenLabel[] = "_Open";
const char kSaveLabel[] = "_Save";
#else
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
const char* const kOkLabel = GTK_STOCK_OK;
const char* const kCancelLabel = GTK_STOCK_CANCEL;
const char* const kOpenLabel = GTK_STOCK_OPEN;
const char* const kSaveLabel = GTK_STOCK_SAVE;
G_GNUC_END_IGNORE_DEPRECATIONS
#endif
static const int kPreviewWidth = 256;
static const int kPreviewHeight = 512;
@ -66,18 +46,18 @@ class FileChooserDialog {
: parent_(
static_cast<electron::NativeWindowViews*>(settings.parent_window)),
filters_(settings.filters) {
const char* confirm_text = kOkLabel;
const char* confirm_text = gtk_util::kOkLabel;
if (!settings.button_label.empty())
confirm_text = settings.button_label.c_str();
else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
confirm_text = kOpenLabel;
confirm_text = gtk_util::kOpenLabel;
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
confirm_text = kSaveLabel;
confirm_text = gtk_util::kSaveLabel;
dialog_ = gtk_file_chooser_dialog_new(
settings.title.c_str(), NULL, action, kCancelLabel, GTK_RESPONSE_CANCEL,
confirm_text, GTK_RESPONSE_ACCEPT, NULL);
settings.title.c_str(), NULL, action, gtk_util::kCancelLabel,
GTK_RESPONSE_CANCEL, confirm_text, GTK_RESPONSE_ACCEPT, NULL);
if (parent_) {
parent_->SetEnabled(false);
libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow());