From 6727ba7a7f47e5395e80541470505ef937b896a9 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 28 Jan 2019 07:51:55 -0800 Subject: [PATCH 1/3] feat: add window removeMenu() method --- atom/browser/api/atom_api_top_level_window.cc | 8 ++++++++ atom/browser/api/atom_api_top_level_window.h | 1 + docs/api/browser-window.md | 7 +++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index b42b0b996f847..431f120dc1a21 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -659,6 +659,13 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { } } +void TopLevelWindow::RemoveMenu() { + mate::Handle menu; + + menu_.Reset(); + window_->SetMenu(nullptr); +} + void TopLevelWindow::SetParentWindow(v8::Local value, mate::Arguments* args) { if (IsModal()) { @@ -1103,6 +1110,7 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate, .SetMethod("setContentProtection", &TopLevelWindow::SetContentProtection) .SetMethod("setFocusable", &TopLevelWindow::SetFocusable) .SetMethod("setMenu", &TopLevelWindow::SetMenu) + .SetMethod("removeMenu", &TopLevelWindow::RemoveMenu) .SetMethod("setParentWindow", &TopLevelWindow::SetParentWindow) .SetMethod("setBrowserView", &TopLevelWindow::SetBrowserView) .SetMethod("addBrowserView", &TopLevelWindow::AddBrowserView) diff --git a/atom/browser/api/atom_api_top_level_window.h b/atom/browser/api/atom_api_top_level_window.h index 32f28a0c8e09b..21e29181713b0 100644 --- a/atom/browser/api/atom_api_top_level_window.h +++ b/atom/browser/api/atom_api_top_level_window.h @@ -165,6 +165,7 @@ class TopLevelWindow : public mate::TrackableObject, void SetContentProtection(bool enable); void SetFocusable(bool focusable); void SetMenu(v8::Isolate* isolate, v8::Local menu); + void RemoveMenu(); void SetParentWindow(v8::Local value, mate::Arguments* args); virtual void SetBrowserView(v8::Local value); virtual void AddBrowserView(v8::Local value); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index b3b6f3fcab2b7..4a975c201a525 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1308,8 +1308,11 @@ Same as `webContents.reload`. * `menu` Menu | null -Sets the `menu` as the window's menu bar, setting it to `null` will remove the -menu bar. +Sets the `menu` as the window's menu bar, setting it to `null` will remove the menu bar. + +#### `win.removeMenu()` _Linux_ _Windows_ + +Remove the window's menu bar. #### `win.setProgressBar(progress[, options])` From 78a65d7462db17d3ae9afb957ea71af57e0ea39a Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 28 Jan 2019 09:50:37 -0800 Subject: [PATCH 2/3] chore: remove original method from docs and code --- atom/browser/api/atom_api_top_level_window.cc | 3 --- docs/api/breaking-changes.md | 11 ++++++++++- docs/api/browser-window.md | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index 431f120dc1a21..45e888a2bc25f 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -650,9 +650,6 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) { menu_.Reset(isolate, menu.ToV8()); window_->SetMenu(menu->model()); - } else if (value->IsNull()) { - menu_.Reset(); - window_->SetMenu(nullptr); } else { isolate->ThrowException( v8::Exception::TypeError(mate::StringToV8(isolate, "Invalid Menu"))); diff --git a/docs/api/breaking-changes.md b/docs/api/breaking-changes.md index fa4f84f8757f0..1121fb49fee55 100644 --- a/docs/api/breaking-changes.md +++ b/docs/api/breaking-changes.md @@ -8,6 +8,15 @@ The `FIXME` string is used in code comments to denote things that should be fixe # Planned Breaking API Changes (6.0) +## `win.setMenu(null)` + +```js +// Deprecated +win.setMenu(null) +// Replace with +win.removeMenu() +``` + ## `electron.screen` in renderer process ```js @@ -64,7 +73,7 @@ A new API, `protocol.registerSchemesAsPrivileged` has been added and should be u # Planned Breaking API Changes (4.0) -The following list includes the breaking API changes planned for Electron 4.0. +The following list includes the breaking API changes made in Electron 4.0. ## `app.makeSingleInstance` diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 4a975c201a525..4ed4e611b9d25 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1308,7 +1308,7 @@ Same as `webContents.reload`. * `menu` Menu | null -Sets the `menu` as the window's menu bar, setting it to `null` will remove the menu bar. +Sets the `menu` as the window's menu bar. #### `win.removeMenu()` _Linux_ _Windows_ From 2a5fdf538c7c5e76038b8b1108afd369b08afa46 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 30 Jan 2019 18:54:27 -0800 Subject: [PATCH 3/3] retain backwards compatibility --- atom/browser/api/atom_api_top_level_window.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index 45e888a2bc25f..431f120dc1a21 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -650,6 +650,9 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local value) { mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) { menu_.Reset(isolate, menu.ToV8()); window_->SetMenu(menu->model()); + } else if (value->IsNull()) { + menu_.Reset(); + window_->SetMenu(nullptr); } else { isolate->ThrowException( v8::Exception::TypeError(mate::StringToV8(isolate, "Invalid Menu")));