Skip to content

Commit c3d6841

Browse files
committed
Rename menu item text methods to label, update native accessors
1 parent df27acf commit c3d6841

File tree

8 files changed

+78
-78
lines changed

8 files changed

+78
-78
lines changed

src/capi/menu_c.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,27 +218,27 @@ native_menu_item_type_t native_menu_item_get_type(native_menu_item_t item) {
218218
}
219219
}
220220

221-
void native_menu_item_set_text(native_menu_item_t item, const char* text) {
222-
if (!item || !text)
221+
void native_menu_item_set_label(native_menu_item_t item, const char* label) {
222+
if (!item || !label)
223223
return;
224224

225225
try {
226226
auto menu_item = static_cast<MenuItem*>(item);
227-
menu_item->SetText(text);
227+
menu_item->SetLabel(label);
228228
} catch (...) {
229229
// Ignore exceptions
230230
}
231231
}
232232

233-
int native_menu_item_get_text(native_menu_item_t item,
234-
char* buffer,
235-
size_t buffer_size) {
233+
int native_menu_item_get_label(native_menu_item_t item,
234+
char* buffer,
235+
size_t buffer_size) {
236236
if (!item || !buffer || buffer_size == 0)
237237
return -1;
238238

239239
try {
240240
auto menu_item = static_cast<MenuItem*>(item);
241-
std::string text = menu_item->GetText();
241+
std::string text = menu_item->GetLabel();
242242

243243
if (text.length() >= buffer_size) {
244244
return -1;

src/capi/menu_c.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,22 +180,22 @@ FFI_PLUGIN_EXPORT
180180
native_menu_item_type_t native_menu_item_get_type(native_menu_item_t item);
181181

182182
/**
183-
* Set the text of a menu item
183+
* Set the label of a menu item
184184
* @param item The menu item
185-
* @param text The text to set
185+
* @param label The label to set
186186
*/
187187
FFI_PLUGIN_EXPORT
188-
void native_menu_item_set_text(native_menu_item_t item, const char* text);
188+
void native_menu_item_set_label(native_menu_item_t item, const char* label);
189189

190190
/**
191-
* Get the text of a menu item
191+
* Get the label of a menu item
192192
* @param item The menu item
193-
* @param buffer Buffer to store the text (caller allocated)
193+
* @param buffer Buffer to store the label (caller allocated)
194194
* @param buffer_size Size of the buffer
195-
* @return Length of the text, or -1 if buffer too small
195+
* @return Length of the label, or -1 if buffer too small
196196
*/
197197
FFI_PLUGIN_EXPORT
198-
int native_menu_item_get_text(native_menu_item_t item, char* buffer, size_t buffer_size);
198+
int native_menu_item_get_label(native_menu_item_t item, char* buffer, size_t buffer_size);
199199

200200
/**
201201
* Set the icon of a menu item

src/menu.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,28 +235,28 @@ class MenuItem : public EventEmitter {
235235
MenuItemType GetType() const;
236236

237237
/**
238-
* @brief Set the display text for the menu item.
238+
* @brief Set the display label for the menu item.
239239
*
240-
* The text is what appears in the menu. On some platforms,
240+
* The label is what appears in the menu. On some platforms,
241241
* ampersand characters (&) can be used to indicate mnemonics
242242
* (keyboard navigation keys).
243243
*
244-
* @param text The text to display
244+
* @param label The label to display
245245
*
246246
* @example
247247
* ```cpp
248-
* item->SetText("&File"); // 'F' becomes the mnemonic on Windows/Linux
249-
* item->SetText("Open Recent");
248+
* item->SetLabel("&File"); // 'F' becomes the mnemonic on Windows/Linux
249+
* item->SetLabel("Open Recent");
250250
* ```
251251
*/
252-
void SetText(const std::string& text);
252+
void SetLabel(const std::string& label);
253253

254254
/**
255-
* @brief Get the current display text of the menu item.
255+
* @brief Get the current display label of the menu item.
256256
*
257-
* @return The current text as a string
257+
* @return The current label as a string
258258
*/
259-
std::string GetText() const;
259+
std::string GetLabel() const;
260260

261261
/**
262262
* @brief Set the icon for the menu item.
@@ -455,7 +455,7 @@ class MenuItem : public EventEmitter {
455455
*
456456
* @return Pointer to the native menu item object
457457
*/
458-
void* GetNativeItem() const;
458+
void* GetNativeObject() const;
459459

460460
/**
461461
* @brief Emit a menu item selected event.
@@ -816,7 +816,7 @@ class Menu : public EventEmitter {
816816
*
817817
* @return Pointer to the native menu object
818818
*/
819-
void* GetNativeMenu() const;
819+
void* GetNativeObject() const;
820820

821821
/**
822822
* @brief Emit a menu opened event.

src/platform/linux/menu_linux.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ MenuItemType MenuItem::GetType() const {
9090
return pimpl_->type_;
9191
}
9292

93-
void MenuItem::SetText(const std::string& text) {
94-
pimpl_->title_ = text;
93+
void MenuItem::SetLabel(const std::string& label) {
94+
pimpl_->title_ = label;
9595
if (pimpl_->gtk_menu_item_ && pimpl_->type_ != MenuItemType::Separator) {
96-
gtk_menu_item_set_label(GTK_MENU_ITEM(pimpl_->gtk_menu_item_), text.c_str());
96+
gtk_menu_item_set_label(GTK_MENU_ITEM(pimpl_->gtk_menu_item_), label.c_str());
9797
}
9898
}
9999

100-
std::string MenuItem::GetText() const {
100+
std::string MenuItem::GetLabel() const {
101101
return pimpl_->title_;
102102
}
103103

@@ -186,7 +186,7 @@ int MenuItem::GetRadioGroup() const {
186186
void MenuItem::SetSubmenu(std::shared_ptr<Menu> submenu) {
187187
pimpl_->submenu_ = submenu;
188188
if (pimpl_->gtk_menu_item_ && submenu) {
189-
gtk_menu_item_set_submenu(GTK_MENU_ITEM(pimpl_->gtk_menu_item_), (GtkWidget*)submenu->GetNativeMenu());
189+
gtk_menu_item_set_submenu(GTK_MENU_ITEM(pimpl_->gtk_menu_item_), (GtkWidget*)submenu->GetNativeObject());
190190
}
191191
}
192192

@@ -210,7 +210,7 @@ bool MenuItem::Trigger() {
210210
return false;
211211
}
212212

213-
void* MenuItem::GetNativeItem() const {
213+
void* MenuItem::GetNativeObject() const {
214214
return (void*)pimpl_->gtk_menu_item_;
215215
}
216216

@@ -264,9 +264,9 @@ Menu::~Menu() {
264264
}
265265

266266
void Menu::AddItem(std::shared_ptr<MenuItem> item) {
267-
if (pimpl_->gtk_menu_ && item && item->GetNativeItem()) {
267+
if (pimpl_->gtk_menu_ && item && item->GetNativeObject()) {
268268
pimpl_->items_.push_back(item);
269-
gtk_menu_shell_append(GTK_MENU_SHELL(pimpl_->gtk_menu_), (GtkWidget*)item->GetNativeItem());
269+
gtk_menu_shell_append(GTK_MENU_SHELL(pimpl_->gtk_menu_), (GtkWidget*)item->GetNativeObject());
270270
}
271271
}
272272

@@ -279,17 +279,17 @@ void Menu::InsertItem(size_t index, std::shared_ptr<MenuItem> item) {
279279
}
280280

281281
pimpl_->items_.insert(pimpl_->items_.begin() + index, item);
282-
if (pimpl_->gtk_menu_ && item->GetNativeItem()) {
283-
gtk_menu_shell_insert(GTK_MENU_SHELL(pimpl_->gtk_menu_), (GtkWidget*)item->GetNativeItem(), index);
282+
if (pimpl_->gtk_menu_ && item->GetNativeObject()) {
283+
gtk_menu_shell_insert(GTK_MENU_SHELL(pimpl_->gtk_menu_), (GtkWidget*)item->GetNativeObject(), index);
284284
}
285285
}
286286

287287
bool Menu::RemoveItem(std::shared_ptr<MenuItem> item) {
288-
if (pimpl_->gtk_menu_ && item && item->GetNativeItem()) {
288+
if (pimpl_->gtk_menu_ && item && item->GetNativeObject()) {
289289
auto it = std::find(pimpl_->items_.begin(), pimpl_->items_.end(), item);
290290
if (it != pimpl_->items_.end()) {
291291
pimpl_->items_.erase(it);
292-
gtk_container_remove(GTK_CONTAINER(pimpl_->gtk_menu_), (GtkWidget*)item->GetNativeItem());
292+
gtk_container_remove(GTK_CONTAINER(pimpl_->gtk_menu_), (GtkWidget*)item->GetNativeObject());
293293
return true;
294294
}
295295
}
@@ -355,7 +355,7 @@ std::vector<std::shared_ptr<MenuItem>> Menu::GetAllItems() const {
355355

356356
std::shared_ptr<MenuItem> Menu::FindItemByText(const std::string& text, bool case_sensitive) const {
357357
for (const auto& item : pimpl_->items_) {
358-
std::string item_text = item->GetText();
358+
std::string item_text = item->GetLabel();
359359
if (case_sensitive) {
360360
if (item_text == text) {
361361
return item;
@@ -430,7 +430,7 @@ std::shared_ptr<MenuItem> Menu::CreateAndAddSubmenu(const std::string& text, std
430430
return item;
431431
}
432432

433-
void* Menu::GetNativeMenu() const {
433+
void* Menu::GetNativeObject() const {
434434
return (void*)pimpl_->gtk_menu_;
435435
}
436436

src/platform/linux/tray_icon_linux.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace nativeapi {
1313
class TrayIcon::Impl {
1414
public:
1515
Impl(GtkStatusIcon* tray) : gtk_status_icon_(tray), title_(""), tooltip_(""), context_menu_(nullptr) {}
16-
16+
1717
GtkStatusIcon* gtk_status_icon_;
1818
std::shared_ptr<Menu> context_menu_; // Store menu shared_ptr to keep it alive
1919
std::string title_; // GTK StatusIcon doesn't have title, so we store it
@@ -50,32 +50,32 @@ void TrayIcon::SetIcon(std::string icon) {
5050
size_t pos = icon.find("base64,");
5151
if (pos != std::string::npos) {
5252
std::string base64Icon = icon.substr(pos + 7);
53-
53+
5454
// Decode base64 data
5555
gsize decoded_len;
5656
guchar* decoded_data = g_base64_decode(base64Icon.c_str(), &decoded_len);
57-
57+
5858
if (decoded_data) {
5959
// Create pixbuf from decoded data
6060
GInputStream* stream = g_memory_input_stream_new_from_data(
6161
decoded_data, decoded_len, g_free);
6262
GError* error = nullptr;
6363
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_stream(stream, nullptr, &error);
64-
64+
6565
if (pixbuf && !error) {
6666
// Scale pixbuf to appropriate size (24x24 is common for tray icons)
6767
GdkPixbuf* scaled_pixbuf = gdk_pixbuf_scale_simple(
6868
pixbuf, 24, 24, GDK_INTERP_BILINEAR);
69-
69+
7070
gtk_status_icon_set_from_pixbuf(pimpl_->gtk_status_icon_, scaled_pixbuf);
71-
71+
7272
g_object_unref(scaled_pixbuf);
7373
g_object_unref(pixbuf);
7474
} else if (error) {
7575
std::cerr << "Error loading icon from base64: " << error->message << std::endl;
7676
g_error_free(error);
7777
}
78-
78+
7979
g_object_unref(stream);
8080
}
8181
}
@@ -117,7 +117,7 @@ void TrayIcon::SetContextMenu(std::shared_ptr<Menu> menu) {
117117
pimpl_->context_menu_ = menu;
118118

119119
// Note: Full GTK integration would need to connect popup-menu signal
120-
// and show the GTK menu from the Menu object's GetNativeMenu()
120+
// and show the GTK menu from the Menu object's GetNativeObject()
121121
}
122122

123123
std::shared_ptr<Menu> TrayIcon::GetContextMenu() {
@@ -126,20 +126,20 @@ std::shared_ptr<Menu> TrayIcon::GetContextMenu() {
126126

127127
Rectangle TrayIcon::GetBounds() {
128128
Rectangle bounds = {0, 0, 0, 0};
129-
129+
130130
if (pimpl_->gtk_status_icon_) {
131131
GdkScreen* screen;
132132
GdkRectangle area;
133133
GtkOrientation orientation;
134-
134+
135135
if (gtk_status_icon_get_geometry(pimpl_->gtk_status_icon_, &screen, &area, &orientation)) {
136136
bounds.x = area.x;
137137
bounds.y = area.y;
138138
bounds.width = area.width;
139139
bounds.height = area.height;
140140
}
141141
}
142-
142+
143143
return bounds;
144144
}
145145

@@ -167,7 +167,7 @@ bool TrayIcon::IsVisible() {
167167
}
168168

169169
bool TrayIcon::ShowContextMenu(double x, double y) {
170-
if (!pimpl_->context_menu_ || !pimpl_->context_menu_->GetNativeMenu()) {
170+
if (!pimpl_->context_menu_ || !pimpl_->context_menu_->GetNativeObject()) {
171171
return false;
172172
}
173173

@@ -177,7 +177,7 @@ bool TrayIcon::ShowContextMenu(double x, double y) {
177177
}
178178

179179
bool TrayIcon::ShowContextMenu() {
180-
if (!pimpl_->context_menu_ || !pimpl_->context_menu_->GetNativeMenu()) {
180+
if (!pimpl_->context_menu_ || !pimpl_->context_menu_->GetNativeObject()) {
181181
return false;
182182
}
183183

@@ -211,4 +211,4 @@ void TrayIcon::HandleDoubleClick() {
211211
}
212212
}
213213

214-
} // namespace nativeapi
214+
} // namespace nativeapi

0 commit comments

Comments
 (0)