Skip to content

Commit df27acf

Browse files
committed
Remove KeyboardAccelerator::ToString from menu code
Deleted the KeyboardAccelerator::ToString implementation from both macOS and Windows menu source files. This refactor likely moves accelerator string formatting elsewhere or eliminates unused code.
1 parent 555aa54 commit df27acf

File tree

2 files changed

+16
-42
lines changed

2 files changed

+16
-42
lines changed

src/platform/macos/menu_macos.mm

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,6 @@ - (void)menuDidClose:(NSMenu *)menu {
131131

132132
namespace nativeapi {
133133

134-
// KeyboardAccelerator implementation
135-
std::string KeyboardAccelerator::ToString() const {
136-
std::string result;
137-
138-
if (modifiers & Meta) result += "Ctrl+";
139-
if (modifiers & Alt) result += "Alt+";
140-
if (modifiers & Shift) result += "Shift+";
141-
if (modifiers & Ctrl) result += "Cmd+"; // On macOS, show as Cmd
142-
143-
result += key;
144-
return result;
145-
}
146-
147134
// MenuItem::Impl implementation
148135
class MenuItem::Impl {
149136
public:
@@ -616,13 +603,13 @@ - (void)menuDidClose:(NSMenu *)menu {
616603
pressure:1.0];
617604

618605
pimpl_->visible_ = true;
619-
606+
620607
@autoreleasepool {
621608
// Create a dummy view to avoid the nil warning
622609
NSView* dummyView = [[NSView alloc] init];
623610
[NSMenu popUpContextMenu:pimpl_->ns_menu_ withEvent:event forView:dummyView];
624611
}
625-
612+
626613
pimpl_->visible_ = false;
627614

628615
return true;

src/platform/windows/menu_windows.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,6 @@ std::pair<UINT, UINT> ConvertAccelerator(const KeyboardAccelerator& accelerator)
7474

7575
namespace nativeapi {
7676

77-
// KeyboardAccelerator implementation
78-
std::string KeyboardAccelerator::ToString() const {
79-
std::string result;
80-
81-
if (modifiers & Ctrl) result += "Ctrl+";
82-
if (modifiers & Alt) result += "Alt+";
83-
if (modifiers & Shift) result += "Shift+";
84-
if (modifiers & Meta) result += "Win+";
85-
86-
result += key;
87-
return result;
88-
}
89-
9077
// MenuItem::Impl implementation
9178
class MenuItem::Impl {
9279
public:
@@ -215,7 +202,7 @@ void MenuItem::RemoveAccelerator() {
215202
void MenuItem::SetEnabled(bool enabled) {
216203
pimpl_->enabled_ = enabled;
217204
if (pimpl_->parent_menu_) {
218-
EnableMenuItem(pimpl_->parent_menu_, pimpl_->menu_item_id_,
205+
EnableMenuItem(pimpl_->parent_menu_, pimpl_->menu_item_id_,
219206
enabled ? MF_ENABLED : MF_GRAYED);
220207
}
221208
}
@@ -237,7 +224,7 @@ bool MenuItem::IsVisible() const {
237224
void MenuItem::SetState(MenuItemState state) {
238225
if (pimpl_->type_ == MenuItemType::Checkbox || pimpl_->type_ == MenuItemType::Radio) {
239226
pimpl_->state_ = state;
240-
227+
241228
if (pimpl_->parent_menu_) {
242229
UINT checkState = MF_UNCHECKED;
243230
if (state == MenuItemState::Checked) {
@@ -255,7 +242,7 @@ void MenuItem::SetState(MenuItemState state) {
255242
otherItem->GetRadioGroup() == pimpl_->radio_group_) {
256243
otherItem->pimpl_->state_ = MenuItemState::Unchecked;
257244
if (otherItem->pimpl_->parent_menu_) {
258-
CheckMenuItem(otherItem->pimpl_->parent_menu_,
245+
CheckMenuItem(otherItem->pimpl_->parent_menu_,
259246
otherItem->pimpl_->menu_item_id_, MF_UNCHECKED);
260247
}
261248
}
@@ -348,7 +335,7 @@ std::shared_ptr<Menu> Menu::Create() {
348335
if (!hmenu) {
349336
return nullptr;
350337
}
351-
338+
352339
auto menu = std::shared_ptr<Menu>(new Menu());
353340
menu->pimpl_ = std::make_unique<Impl>(hmenu);
354341
menu->id = g_next_menu_id++;
@@ -379,7 +366,7 @@ void Menu::AddItem(std::shared_ptr<MenuItem> item) {
379366
if (!item) return;
380367

381368
pimpl_->items_.push_back(item);
382-
369+
383370
UINT flags = MF_STRING;
384371
if (item->GetType() == MenuItemType::Separator) {
385372
flags = MF_SEPARATOR;
@@ -388,17 +375,17 @@ void Menu::AddItem(std::shared_ptr<MenuItem> item) {
388375
} else if (item->GetType() == MenuItemType::Radio) {
389376
flags |= MF_UNCHECKED;
390377
}
391-
378+
392379
UINT_PTR menuId = item->id;
393380
HMENU subMenu = nullptr;
394381
if (item->GetSubmenu()) {
395382
subMenu = static_cast<HMENU>(item->GetSubmenu()->GetNativeMenu());
396383
flags |= MF_POPUP;
397384
menuId = reinterpret_cast<UINT_PTR>(subMenu);
398385
}
399-
386+
400387
AppendMenu(pimpl_->hmenu_, flags, menuId, item->GetText().c_str());
401-
388+
402389
// Update the item's impl with menu info
403390
item->pimpl_->parent_menu_ = pimpl_->hmenu_;
404391
item->pimpl_->menu_item_id_ = static_cast<UINT>(item->id);
@@ -413,14 +400,14 @@ void Menu::InsertItem(size_t index, std::shared_ptr<MenuItem> item) {
413400
}
414401

415402
pimpl_->items_.insert(pimpl_->items_.begin() + index, item);
416-
403+
417404
UINT flags = MF_STRING | MF_BYPOSITION;
418405
if (item->GetType() == MenuItemType::Separator) {
419406
flags = MF_SEPARATOR | MF_BYPOSITION;
420407
}
421-
408+
422409
InsertMenu(pimpl_->hmenu_, static_cast<UINT>(index), flags, item->id, item->GetText().c_str());
423-
410+
424411
item->pimpl_->parent_menu_ = pimpl_->hmenu_;
425412
item->pimpl_->menu_item_id_ = static_cast<UINT>(item->id);
426413
}
@@ -513,16 +500,16 @@ std::shared_ptr<MenuItem> Menu::FindItemByText(const std::string& text, bool cas
513500

514501
bool Menu::ShowAsContextMenu(double x, double y) {
515502
pimpl_->visible_ = true;
516-
503+
517504
POINT pt = {static_cast<int>(x), static_cast<int>(y)};
518505
HWND hwnd = GetActiveWindow();
519506
if (!hwnd) {
520507
hwnd = GetDesktopWindow();
521508
}
522-
509+
523510
// Show the context menu
524511
TrackPopupMenu(pimpl_->hmenu_, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, nullptr);
525-
512+
526513
pimpl_->visible_ = false;
527514
return true;
528515
}

0 commit comments

Comments
 (0)