~indicator-applet-developers/unity-gtk-module/trunk.14.04

« back to all changes in this revision

Viewing changes to lib/unity-gtk-menu-item.c

  • Committer: Tarmac
  • Author(s): William Hua
  • Date: 2014-03-06 18:14:36 UTC
  • mfrom: (314.1.8 gtk-enable-mnemonics)
  • Revision ID: tarmac-20140306181436-8rsi9ox0h5ifows9
Filter out mnemonics when the gtk-enable-mnemonics setting is cleared. Workaround for LP: #1282782. Fixes: https://bugs.launchpad.net/bugs/1282782.

Approved by Sebastien Bacher, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
#include "unity-gtk-menu-item-private.h"
21
21
#include "unity-gtk-action-group-private.h"
 
22
#include <string.h>
22
23
 
23
24
G_DEFINE_TYPE (UnityGtkMenuItem,
24
25
               unity_gtk_menu_item,
307
308
  g_return_if_fail (parent_shell != NULL);
308
309
  g_warn_if_fail (object == menu_item);
309
310
 
310
 
  unity_gtk_menu_shell_handle_item_notify (parent_shell, item, pspec);
 
311
  unity_gtk_menu_shell_handle_item_notify (parent_shell, item, g_param_spec_get_name (pspec));
311
312
}
312
313
 
313
314
static void
368
369
}
369
370
 
370
371
static void
 
372
unity_gtk_menu_item_finalize (GObject *object)
 
373
{
 
374
  UnityGtkMenuItem *item;
 
375
 
 
376
  g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (object));
 
377
 
 
378
  item = UNITY_GTK_MENU_ITEM (object);
 
379
 
 
380
  g_free (item->label);
 
381
  item->label = NULL;
 
382
 
 
383
  G_OBJECT_CLASS (unity_gtk_menu_item_parent_class)->finalize (object);
 
384
}
 
385
 
 
386
static void
371
387
unity_gtk_menu_item_class_init (UnityGtkMenuItemClass *klass)
372
388
{
373
389
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
374
390
 
375
391
  object_class->dispose = unity_gtk_menu_item_dispose;
 
392
  object_class->finalize = unity_gtk_menu_item_finalize;
376
393
}
377
394
 
378
395
static void
416
433
          GtkWidget *submenu = gtk_menu_item_get_submenu (menu_item);
417
434
 
418
435
          if (submenu != NULL)
419
 
            item->child_shell = unity_gtk_menu_shell_new (GTK_MENU_SHELL (submenu));
 
436
            item->child_shell = unity_gtk_menu_shell_new_internal (GTK_MENU_SHELL (submenu));
420
437
        }
421
438
 
422
439
      item->child_shell_valid = TRUE;
461
478
    }
462
479
}
463
480
 
 
481
static gchar *
 
482
g_strdup_no_mnemonics (const gchar *str)
 
483
{
 
484
  if (str != NULL)
 
485
    {
 
486
      gchar *string;
 
487
      gchar *out;
 
488
      const gchar *in;
 
489
      gboolean underscore;
 
490
 
 
491
      string = g_malloc (strlen (str) + 1);
 
492
      out = string;
 
493
      underscore = FALSE;
 
494
 
 
495
      for (in = str; *in != '\0'; in++)
 
496
        {
 
497
          if (*in != '_')
 
498
            {
 
499
              underscore = FALSE;
 
500
              *out++ = *in;
 
501
            }
 
502
          else
 
503
            {
 
504
              if (!underscore)
 
505
                underscore = TRUE;
 
506
              else
 
507
                {
 
508
                  /* double underscores are not accelerator markers */
 
509
                  underscore = FALSE;
 
510
                  *out++ = '_';
 
511
                  *out++ = '_';
 
512
                }
 
513
            }
 
514
        }
 
515
 
 
516
      /* trailing underscores are not accelerator markers */
 
517
      if (underscore)
 
518
        *out++ = '_';
 
519
 
 
520
      *out++ = '\0';
 
521
 
 
522
      return string;
 
523
    }
 
524
 
 
525
  return NULL;
 
526
}
 
527
 
464
528
const gchar *
465
529
unity_gtk_menu_item_get_label (UnityGtkMenuItem *item)
466
530
{
467
 
  const gchar *label;
468
 
 
469
531
  g_return_val_if_fail (UNITY_GTK_IS_MENU_ITEM (item), NULL);
470
532
  g_return_val_if_fail (item->menu_item != NULL, NULL);
471
533
 
472
 
  label = gtk_menu_item_get_label (item->menu_item);
473
 
 
474
 
  if (label != NULL && label[0] != '\0')
 
534
  if (item->label == NULL)
475
535
    {
476
 
      if (GTK_IS_IMAGE_MENU_ITEM (item->menu_item))
 
536
      const gchar *label = gtk_menu_item_get_label (item->menu_item);
 
537
 
 
538
      if (label != NULL && label[0] != '\0')
477
539
        {
478
 
          GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (item->menu_item);
479
 
 
480
 
          if (gtk_image_menu_item_get_use_stock (image_menu_item))
 
540
          if (GTK_IS_IMAGE_MENU_ITEM (item->menu_item))
481
541
            {
482
 
              GtkStockItem stock_item;
483
 
 
484
 
              if (gtk_stock_lookup (label, &stock_item))
485
 
                label = stock_item.label;
 
542
              GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (item->menu_item);
 
543
 
 
544
              if (gtk_image_menu_item_get_use_stock (image_menu_item))
 
545
                {
 
546
                  GtkStockItem stock_item;
 
547
 
 
548
                  if (gtk_stock_lookup (label, &stock_item))
 
549
                    label = stock_item.label;
 
550
                }
486
551
            }
487
552
        }
 
553
 
 
554
      if (label == NULL || label[0] == '\0')
 
555
        label = gtk_menu_item_get_nth_label (item->menu_item, 0);
 
556
 
 
557
      if (label != NULL && label[0] != '\0')
 
558
        {
 
559
          if (item->parent_shell == NULL || item->parent_shell->has_mnemonics)
 
560
            item->label = g_strdup (label);
 
561
          else
 
562
            item->label = g_strdup_no_mnemonics (label);
 
563
        }
488
564
    }
489
565
 
490
 
  if (label == NULL || label[0] == '\0')
491
 
    label = gtk_menu_item_get_nth_label (item->menu_item, 0);
492
 
 
493
 
  return label != NULL && label[0] != '\0' ? label : NULL;
 
566
  return item->label;
494
567
}
495
568
 
496
569
GIcon *