Skip to content

Commit 585e871

Browse files
committed
Rename MenuItem 'text' parameter to 'label'
Refactored MenuItem constructors and related API to use 'label' instead of 'text' for clarity and consistency. Updated all usages and documentation comments to reflect this change across C API, Linux, and macOS platform implementations.
1 parent d2b297a commit 585e871

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

src/capi/menu_c.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ static native_menu_item_state_t convert_menu_item_state(MenuItemState state) {
140140

141141
// MenuItem C API Implementation
142142

143-
native_menu_item_t native_menu_item_create(const char* text, native_menu_item_type_t type) {
144-
if (!text)
143+
native_menu_item_t native_menu_item_create(const char* label, native_menu_item_type_t type) {
144+
if (!label)
145145
return nullptr;
146146

147147
try {
148-
auto item = std::make_shared<MenuItem>(text, convert_menu_item_type(type));
148+
auto item = std::make_shared<MenuItem>(label, convert_menu_item_type(type));
149149
void* handle = item.get();
150150

151151
// Store the shared_ptr in the registry to keep the object alive
@@ -235,18 +235,18 @@ char* native_menu_item_get_label(native_menu_item_t item) {
235235

236236
try {
237237
auto menu_item = static_cast<MenuItem*>(item);
238-
auto textOpt = menu_item->GetLabel();
238+
auto labelOpt = menu_item->GetLabel();
239239

240-
if (!textOpt.has_value()) {
240+
if (!labelOpt.has_value()) {
241241
return nullptr;
242242
}
243243

244-
const std::string& text = textOpt.value();
244+
const std::string& label = labelOpt.value();
245245

246246
// Allocate C string and copy content
247-
char* result = static_cast<char*>(malloc(text.length() + 1));
247+
char* result = static_cast<char*>(malloc(label.length() + 1));
248248
if (result) {
249-
strcpy(result, text.c_str());
249+
strcpy(result, label.c_str());
250250
}
251251
return result;
252252
} catch (...) {

src/capi/menu_c.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ typedef enum {
140140

141141
/**
142142
* Create a new menu item
143-
* @param text The display text for the menu item
143+
* @param label The display label for the menu item
144144
* @param type The type of menu item to create
145145
* @return Menu item handle, or NULL if creation failed
146146
*/
147147
FFI_PLUGIN_EXPORT
148-
native_menu_item_t native_menu_item_create(const char* text, native_menu_item_type_t type);
148+
native_menu_item_t native_menu_item_create(const char* label, native_menu_item_type_t type);
149149

150150
/**
151151
* Create a separator menu item

src/menu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class MenuItem : public EventEmitter<MenuEvent>, public NativeObjectProvider {
193193
* auto checkbox = std::make_shared<MenuItem>("Word Wrap", MenuItemType::Checkbox);
194194
* ```
195195
*/
196-
MenuItem(const std::string& text = "", MenuItemType type = MenuItemType::Normal);
196+
MenuItem(const std::string& label = "", MenuItemType type = MenuItemType::Normal);
197197

198198
/**
199199
* @brief Constructor that wraps an existing platform-specific menu item.
@@ -312,7 +312,7 @@ class MenuItem : public EventEmitter<MenuEvent>, public NativeObjectProvider {
312312
*
313313
* The accelerator allows users to trigger the menu item using
314314
* keyboard shortcuts. The accelerator is typically displayed
315-
* next to the menu item text.
315+
* next to the menu item label.
316316
*
317317
* @param accelerator The keyboard accelerator to set
318318
*

src/platform/linux/menu_linux.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class MenuItem::Impl {
8383
std::shared_ptr<Menu> submenu_;
8484
};
8585

86-
MenuItem::MenuItem(const std::string& text, MenuItemType type) {
86+
MenuItem::MenuItem(const std::string& label, MenuItemType type) {
8787
MenuItemId id = IdAllocator::Allocate<MenuItem>();
8888
GtkWidget* gtk_item = nullptr;
8989

@@ -92,22 +92,22 @@ MenuItem::MenuItem(const std::string& text, MenuItemType type) {
9292
gtk_item = gtk_separator_menu_item_new();
9393
break;
9494
case MenuItemType::Checkbox:
95-
gtk_item = gtk_check_menu_item_new_with_label(text.c_str());
95+
gtk_item = gtk_check_menu_item_new_with_label(label.c_str());
9696
break;
9797
case MenuItemType::Radio:
98-
gtk_item = gtk_radio_menu_item_new_with_label(nullptr, text.c_str());
98+
gtk_item = gtk_radio_menu_item_new_with_label(nullptr, label.c_str());
9999
break;
100100
case MenuItemType::Normal:
101101
case MenuItemType::Submenu:
102102
default:
103-
gtk_item = gtk_menu_item_new_with_label(text.c_str());
103+
gtk_item = gtk_menu_item_new_with_label(label.c_str());
104104
break;
105105
}
106106

107107
pimpl_ = std::unique_ptr<Impl>(new Impl(id, gtk_item, type));
108108

109-
if (!text.empty()) {
110-
pimpl_->title_ = text;
109+
if (!label.empty()) {
110+
pimpl_->title_ = label;
111111
} else {
112112
pimpl_->title_.reset();
113113
}

src/platform/macos/menu_macos.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ - (void)menuDidClose:(NSMenu*)menu {
247247
};
248248

249249
// MenuItem implementation
250-
MenuItem::MenuItem(const std::string& text, MenuItemType type) {
250+
MenuItem::MenuItem(const std::string& label, MenuItemType type) {
251251
MenuItemId id = IdAllocator::Allocate<MenuItem>();
252252
NSMenuItem* ns_item = nullptr;
253253

@@ -260,7 +260,7 @@ - (void)menuDidClose:(NSMenu*)menu {
260260
case MenuItemType::Radio:
261261
case MenuItemType::Submenu:
262262
default:
263-
ns_item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:text.c_str()]
263+
ns_item = [[NSMenuItem alloc] initWithTitle:[NSString stringWithUTF8String:label.c_str()]
264264
action:nil
265265
keyEquivalent:@""];
266266
break;
@@ -269,7 +269,7 @@ - (void)menuDidClose:(NSMenu*)menu {
269269
pimpl_ = std::make_unique<Impl>(id, ns_item, type);
270270
objc_setAssociatedObject(ns_item, kMenuItemIdKey, [NSNumber numberWithUnsignedInt:id],
271271
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
272-
pimpl_->label_ = text.empty() ? std::nullopt : std::optional<std::string>(text);
272+
pimpl_->label_ = label.empty() ? std::nullopt : std::optional<std::string>(label);
273273

274274
// 设置默认的 Block 处理器,直接发送事件
275275
pimpl_->ns_menu_item_target_.clickedBlock = ^(MenuItemId item_id) {

0 commit comments

Comments
 (0)