Skip to content

Commit d6795a2

Browse files
committed
Remove CreateAndAddItem and CreateAndAddSubmenu methods
Deprecated convenience methods for creating and adding menu items and submenus have been removed from the Menu class and C API. Example usage in main.c has been updated to use separate creation, configuration, and addition steps for submenu items.
1 parent 41685a6 commit d6795a2

File tree

7 files changed

+3
-234
lines changed

7 files changed

+3
-234
lines changed

examples/tray_icon_c_example/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ int main() {
151151

152152
// Create submenu item and add to main menu
153153
native_menu_item_t submenu_item =
154-
native_menu_create_and_add_submenu(menu, "More Options", submenu);
154+
native_menu_item_create("More Options", NATIVE_MENU_ITEM_TYPE_SUBMENU);
155155
if (submenu_item) {
156+
native_menu_item_set_submenu(submenu_item, submenu);
157+
native_menu_add_item(menu, submenu_item);
156158
printf("Created submenu with %zu items\n",
157159
native_menu_get_item_count(submenu));
158160
}

src/capi/menu_c.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,67 +1067,7 @@ bool native_menu_remove_listener(native_menu_t menu, int listener_id) {
10671067
}
10681068
}
10691069

1070-
native_menu_item_t native_menu_create_and_add_item(
1071-
native_menu_t menu,
1072-
const char* text,
1073-
native_menu_item_type_t type) {
1074-
if (!menu || !text)
1075-
return nullptr;
1076-
1077-
try {
1078-
// Verify menu exists in global storage
1079-
auto menu_it = g_menus.find(menu);
1080-
if (menu_it == g_menus.end())
1081-
return nullptr;
1082-
1083-
auto menu_ptr = static_cast<Menu*>(menu);
1084-
auto item = menu_ptr->CreateAndAddItem(text);
1085-
if (item) {
1086-
if (type != NATIVE_MENU_ITEM_TYPE_NORMAL) {
1087-
// The CreateAndAddItem only creates normal items, so we need to handle
1088-
// other types differently For now, just return the normal item - this
1089-
// could be enhanced later
1090-
}
1091-
// Store the created item in global storage
1092-
void* item_handle = item.get();
1093-
g_menu_items[item_handle] = item;
1094-
return static_cast<native_menu_item_t>(item_handle);
1095-
}
1096-
return nullptr;
1097-
} catch (...) {
1098-
return nullptr;
1099-
}
1100-
}
11011070

1102-
native_menu_item_t native_menu_create_and_add_submenu(native_menu_t menu,
1103-
const char* text,
1104-
native_menu_t submenu) {
1105-
if (!menu || !text || !submenu)
1106-
return nullptr;
1107-
1108-
try {
1109-
// Verify menu exists in global storage
1110-
auto menu_it = g_menus.find(menu);
1111-
if (menu_it == g_menus.end())
1112-
return nullptr;
1113-
1114-
auto menu_ptr = static_cast<Menu*>(menu);
1115-
// Get the shared_ptr from global storage instead of creating a new one
1116-
auto submenu_it = g_menus.find(submenu);
1117-
if (submenu_it != g_menus.end()) {
1118-
auto item = menu_ptr->CreateAndAddSubmenu(text, submenu_it->second);
1119-
if (item) {
1120-
// Store the created item in global storage
1121-
void* item_handle = item.get();
1122-
g_menu_items[item_handle] = item;
1123-
return static_cast<native_menu_item_t>(item_handle);
1124-
}
1125-
}
1126-
return nullptr;
1127-
} catch (...) {
1128-
return nullptr;
1129-
}
1130-
}
11311071

11321072
// Utility functions
11331073

src/capi/menu_c.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -577,29 +577,7 @@ int native_menu_add_listener(native_menu_t menu,
577577
FFI_PLUGIN_EXPORT
578578
bool native_menu_remove_listener(native_menu_t menu, int listener_id);
579579

580-
/**
581-
* Create and add a menu item in one operation
582-
* @param menu The menu
583-
* @param text The item text
584-
* @param type The item type
585-
* @return The created menu item handle
586-
*/
587-
FFI_PLUGIN_EXPORT
588-
native_menu_item_t native_menu_create_and_add_item(native_menu_t menu,
589-
const char* text,
590-
native_menu_item_type_t type);
591580

592-
/**
593-
* Create and add a submenu item in one operation
594-
* @param menu The menu
595-
* @param text The item text
596-
* @param submenu The submenu to attach
597-
* @return The created menu item handle
598-
*/
599-
FFI_PLUGIN_EXPORT
600-
native_menu_item_t native_menu_create_and_add_submenu(native_menu_t menu,
601-
const char* text,
602-
native_menu_t submenu);
603581

604582
/**
605583
* Utility functions

src/menu.h

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -733,57 +733,7 @@ class Menu : public EventEmitter, public NativeObjectProvider {
733733
*/
734734
bool IsEnabled() const;
735735

736-
/**
737-
* @brief Create a standard menu item and add it to the menu.
738-
*
739-
* Convenience method that creates a normal menu item with the given
740-
* text and adds it to the menu in one operation.
741-
*
742-
* @param text The text for the menu item
743-
* @return Shared pointer to the created and added menu item
744-
*/
745-
std::shared_ptr<MenuItem> CreateAndAddItem(const std::string& text);
746736

747-
/**
748-
* @brief Create a menu item with icon and add it to the menu.
749-
*
750-
* Convenience method that creates a normal menu item with text and icon
751-
* and adds it to the menu in one operation.
752-
*
753-
* @param text The text for the menu item
754-
* @param icon The icon for the menu item (file path or base64 data, optional)
755-
* @return Shared pointer to the created and added menu item
756-
*/
757-
std::shared_ptr<MenuItem> CreateAndAddItem(const std::string& text,
758-
const std::optional<std::string>& icon);
759-
760-
/**
761-
* @brief Create a submenu item and add it to the menu.
762-
*
763-
* Convenience method that creates a submenu item and adds it to the menu.
764-
*
765-
* @param text The text for the submenu item
766-
* @param submenu The submenu to attach
767-
* @return Shared pointer to the created and added submenu item
768-
*/
769-
std::shared_ptr<MenuItem> CreateAndAddSubmenu(const std::string& text,
770-
std::shared_ptr<Menu> submenu);
771-
772-
/**
773-
* @brief Emit a menu opened event.
774-
*
775-
* This is primarily used by platform implementations to
776-
* emit events when a menu has been opened.
777-
*/
778-
void EmitOpenedEvent();
779-
780-
/**
781-
* @brief Emit a menu closed event.
782-
*
783-
* This is primarily used by platform implementations to
784-
* emit events when a menu has been closed.
785-
*/
786-
void EmitClosedEvent();
787737

788738
protected:
789739
/**

src/platform/linux/menu_linux.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -426,42 +426,10 @@ bool Menu::IsEnabled() const {
426426
return pimpl_->enabled_;
427427
}
428428

429-
std::shared_ptr<MenuItem> Menu::CreateAndAddItem(const std::string& text) {
430-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Normal);
431-
AddItem(item);
432-
return item;
433-
}
434-
435-
std::shared_ptr<MenuItem> Menu::CreateAndAddItem(
436-
const std::string& text,
437-
const std::optional<std::string>& icon) {
438-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Normal);
439-
if (icon.has_value()) {
440-
item->SetIcon(icon);
441-
}
442-
AddItem(item);
443-
return item;
444-
}
445429

446-
std::shared_ptr<MenuItem> Menu::CreateAndAddSubmenu(
447-
const std::string& text,
448-
std::shared_ptr<Menu> submenu) {
449-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Submenu);
450-
item->SetSubmenu(submenu);
451-
AddItem(item);
452-
return item;
453-
}
454430

455431
void* Menu::GetNativeObjectInternal() const {
456432
return (void*)pimpl_->gtk_menu_;
457433
}
458434

459-
void Menu::EmitOpenedEvent() {
460-
// TODO: Implement menu opened event emission for GTK
461-
}
462-
463-
void Menu::EmitClosedEvent() {
464-
// TODO: Implement menu closed event emission for GTK
465-
}
466-
467435
} // namespace nativeapi

src/platform/macos/menu_macos.mm

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -877,47 +877,10 @@ - (void)menuDidClose:(NSMenu*)menu {
877877
return pimpl_->enabled_;
878878
}
879879

880-
std::shared_ptr<MenuItem> Menu::CreateAndAddItem(const std::string& text) {
881-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Normal);
882-
AddItem(item);
883-
return item;
884-
}
885-
886-
std::shared_ptr<MenuItem> Menu::CreateAndAddItem(const std::string& text,
887-
const std::optional<std::string>& icon) {
888-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Normal);
889-
if (icon.has_value()) {
890-
item->SetIcon(icon);
891-
}
892-
AddItem(item);
893-
return item;
894-
}
895880

896-
std::shared_ptr<MenuItem> Menu::CreateAndAddSubmenu(const std::string& text,
897-
std::shared_ptr<Menu> submenu) {
898-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Submenu);
899-
item->SetSubmenu(submenu);
900-
AddItem(item);
901-
return item;
902-
}
903881

904882
void* Menu::GetNativeObjectInternal() const {
905883
return (__bridge void*)pimpl_->ns_menu_;
906884
}
907885

908-
void Menu::EmitOpenedEvent() {
909-
// This method is kept for compatibility but events are now handled through blocks
910-
// Call the block if it exists
911-
if (pimpl_->delegate_.openedBlock) {
912-
pimpl_->delegate_.openedBlock(id);
913-
}
914-
}
915-
916-
void Menu::EmitClosedEvent() {
917-
// This method is kept for compatibility but events are now handled through blocks
918-
// Call the block if it exists
919-
if (pimpl_->delegate_.closedBlock) {
920-
pimpl_->delegate_.closedBlock(id);
921-
}
922-
}
923886
} // namespace nativeapi

src/platform/windows/menu_windows.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -530,42 +530,10 @@ bool Menu::IsEnabled() const {
530530
return pimpl_->enabled_;
531531
}
532532

533-
std::shared_ptr<MenuItem> Menu::CreateAndAddItem(const std::string& text) {
534-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Normal);
535-
AddItem(item);
536-
return item;
537-
}
538-
539-
std::shared_ptr<MenuItem> Menu::CreateAndAddItem(
540-
const std::string& text,
541-
const std::optional<std::string>& icon) {
542-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Normal);
543-
if (icon.has_value()) {
544-
item->SetIcon(icon);
545-
}
546-
AddItem(item);
547-
return item;
548-
}
549533

550-
std::shared_ptr<MenuItem> Menu::CreateAndAddSubmenu(
551-
const std::string& text,
552-
std::shared_ptr<Menu> submenu) {
553-
auto item = std::make_shared<MenuItem>(text, MenuItemType::Submenu);
554-
item->SetSubmenu(submenu);
555-
AddItem(item);
556-
return item;
557-
}
558534

559535
void* Menu::GetNativeObjectInternal() const {
560536
return pimpl_->hmenu_;
561537
}
562538

563-
void Menu::EmitOpenedEvent() {
564-
EmitSync<MenuOpenedEvent>(id);
565-
}
566-
567-
void Menu::EmitClosedEvent() {
568-
EmitSync<MenuClosedEvent>(id);
569-
}
570-
571539
} // namespace nativeapi

0 commit comments

Comments
 (0)