aboutsummaryrefslogtreecommitdiffstats
path: root/src/androidmenu.c
diff options
context:
space:
mode:
authorPo Lu2023-07-20 11:21:25 +0800
committerPo Lu2023-07-20 11:21:25 +0800
commit7e8904e796807e3b8bfc20ed45135c53d8a86f50 (patch)
treece88ecb39d19e0f677989b80ad908611831b47e5 /src/androidmenu.c
parent4d3442ebad5cb1e1005cd5eca7e91c95e767ed65 (diff)
downloademacs-7e8904e796807e3b8bfc20ed45135c53d8a86f50.tar.gz
emacs-7e8904e796807e3b8bfc20ed45135c53d8a86f50.zip
Use context menu header titles on Android
* java/org/gnu/emacs/EmacsContextMenu.java (EmacsContextMenu): New field `title'. (addSubmenu): New arg TITLE. Set that field. (expandTo): Set MENU's header title if it's a context menu. * src/androidmenu.c (android_init_emacs_context_menu): Adjust signature of `createContextMenu'. (android_menu_show): Use TITLE instead of pane titles if there's only one pane.
Diffstat (limited to 'src/androidmenu.c')
-rw-r--r--src/androidmenu.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/androidmenu.c b/src/androidmenu.c
index 75710486c75..94e3f646b44 100644
--- a/src/androidmenu.c
+++ b/src/androidmenu.c
@@ -101,7 +101,8 @@ android_init_emacs_context_menu (void)
101 eassert (menu_class.c_name); 101 eassert (menu_class.c_name);
102 102
103 FIND_METHOD_STATIC (create_context_menu, "createContextMenu", 103 FIND_METHOD_STATIC (create_context_menu, "createContextMenu",
104 "()Lorg/gnu/emacs/EmacsContextMenu;"); 104 "(Ljava/lang/String;)"
105 "Lorg/gnu/emacs/EmacsContextMenu;");
105 106
106 FIND_METHOD (add_item, "addItem", "(ILjava/lang/String;ZZZ" 107 FIND_METHOD (add_item, "addItem", "(ILjava/lang/String;ZZZ"
107 "Ljava/lang/String;Z)V"); 108 "Ljava/lang/String;Z)V");
@@ -269,12 +270,26 @@ android_menu_show (struct frame *f, int x, int y, int menuflags,
269 /* Push the first local frame. */ 270 /* Push the first local frame. */
270 android_push_local_frame (); 271 android_push_local_frame ();
271 272
273 /* Set title_string to a Java string containing TITLE if non-nil.
274 If the menu consists of more than one pane, replace the title
275 with the pane header item so that the menu looks consistent. */
276
277 title_string = NULL;
278 if (STRINGP (title) && menu_items_n_panes < 2)
279 title_string = android_build_string (title);
280
272 /* Push the first local frame for the context menu. */ 281 /* Push the first local frame for the context menu. */
273 method = menu_class.create_context_menu; 282 method = menu_class.create_context_menu;
274 current_context_menu = context_menu 283 current_context_menu = context_menu
275 = (*android_java_env)->CallStaticObjectMethod (android_java_env, 284 = (*android_java_env)->CallStaticObjectMethod (android_java_env,
276 menu_class.class, 285 menu_class.class,
277 method); 286 method,
287 title_string);
288
289 /* Delete the unused title reference. */
290
291 if (title_string)
292 ANDROID_DELETE_LOCAL_REF (title_string);
278 293
279 /* Push the second local frame for temporaries. */ 294 /* Push the second local frame for temporaries. */
280 count1 = SPECPDL_INDEX (); 295 count1 = SPECPDL_INDEX ();
@@ -322,6 +337,13 @@ android_menu_show (struct frame *f, int x, int y, int menuflags,
322 i += 1; 337 i += 1;
323 else if (EQ (AREF (menu_items, i), Qt)) 338 else if (EQ (AREF (menu_items, i), Qt))
324 { 339 {
340 /* If the menu contains a single pane, then the pane is
341 actually TITLE. Don't duplicate the text within the
342 context menu title. */
343
344 if (menu_items_n_panes < 2)
345 goto next_item;
346
325 /* This is a new pane. Switch back to the topmost context 347 /* This is a new pane. Switch back to the topmost context
326 menu. */ 348 menu. */
327 if (current_context_menu != context_menu) 349 if (current_context_menu != context_menu)
@@ -348,6 +370,7 @@ android_menu_show (struct frame *f, int x, int y, int menuflags,
348 android_exception_check (); 370 android_exception_check ();
349 ANDROID_DELETE_LOCAL_REF (temp); 371 ANDROID_DELETE_LOCAL_REF (temp);
350 372
373 next_item:
351 i += MENU_ITEMS_PANE_LENGTH; 374 i += MENU_ITEMS_PANE_LENGTH;
352 } 375 }
353 else 376 else