Exemplo n.º 1
0
void
ide_workbench_add_perspective (IdeWorkbench   *self,
                               IdePerspective *perspective)
{
  g_autofree gchar *accel= NULL;
  g_autofree gchar *icon_name = NULL;
  g_autofree gchar *id = NULL;
  g_autofree gchar *title = NULL;
  GtkWidget *titlebar;

  g_assert (IDE_IS_WORKBENCH (self));
  g_assert (IDE_IS_PERSPECTIVE (perspective));

  id = ide_perspective_get_id (perspective);
  title = ide_perspective_get_title (perspective);
  icon_name = ide_perspective_get_icon_name (perspective);
  titlebar = ide_perspective_get_titlebar (perspective);

  gtk_container_add_with_properties (GTK_CONTAINER (self->perspectives_stack),
                                     GTK_WIDGET (perspective),
                                     "icon-name", icon_name,
                                     "name", id,
                                     "needs-attention", FALSE,
                                     "title", title,
                                     NULL);

  if (titlebar != NULL)
    gtk_container_add_with_properties (GTK_CONTAINER (self->header_stack), titlebar,
                                       "name", id,
                                       NULL);

  if (!IDE_IS_GREETER_PERSPECTIVE (perspective))
    {
      guint position = 0;

      gtk_container_child_get (GTK_CONTAINER (self->perspectives_stack),
                               GTK_WIDGET (perspective),
                               "position", &position,
                               NULL);

      g_list_store_append (self->perspectives, perspective);
      g_list_store_sort (self->perspectives,
                         ide_workbench_compare_perspective,
                         NULL);
    }

  accel = ide_perspective_get_accelerator (perspective);

  if (accel != NULL)
    {
      const gchar *accel_map[] = { accel, NULL };
      g_autofree gchar *action_name = NULL;

      action_name = g_strdup_printf ("win.perspective('%s')", id);
      gtk_application_set_accels_for_action (GTK_APPLICATION (IDE_APPLICATION_DEFAULT),
                                             action_name, accel_map);

    }
}
Exemplo n.º 2
0
void
ide_workbench_add_perspective (IdeWorkbench   *self,
                               IdePerspective *perspective)
{
  g_autofree gchar *icon_name = NULL;
  g_autofree gchar *id = NULL;
  g_autofree gchar *title = NULL;
  GtkStack *stack;
  GtkWidget *titlebar;

  g_assert (IDE_IS_WORKBENCH (self));
  g_assert (IDE_IS_PERSPECTIVE (perspective));

  id = ide_perspective_get_id (perspective);
  title = ide_perspective_get_title (perspective);
  icon_name = ide_perspective_get_icon_name (perspective);

  if (ide_perspective_is_early (perspective))
    stack = self->top_stack;
  else
    stack = self->perspectives_stack;

  gtk_widget_set_hexpand (GTK_WIDGET (perspective), TRUE);

  gtk_container_add_with_properties (GTK_CONTAINER (stack),
                                     GTK_WIDGET (perspective),
                                     "icon-name", icon_name,
                                     "name", id,
                                     "needs-attention", FALSE,
                                     "title", title,
                                     NULL);

  titlebar = ide_perspective_get_titlebar (perspective);
  if (titlebar == NULL)
    titlebar = g_object_new (IDE_TYPE_WORKBENCH_HEADER_BAR,
                             "visible", TRUE,
                             NULL);

  gtk_container_add_with_properties (GTK_CONTAINER (self->titlebar_stack), titlebar,
                                     "name", id,
                                     NULL);

  ide_workbench_resort_perspectives (self);
}
Exemplo n.º 3
0
void
_ide_workbench_add_perspective_shortcut (IdeWorkbench   *self,
                                         IdePerspective *perspective)
{
  g_autofree gchar *accel= NULL;

  g_assert (IDE_IS_WORKBENCH (self));
  g_assert (IDE_IS_PERSPECTIVE (perspective));

  accel = ide_perspective_get_accelerator (perspective);

  if (accel != NULL)
    {
      DzlShortcutController *controller;
      g_autofree gchar *id = ide_perspective_get_id (perspective);
      g_autofree gchar *title = ide_perspective_get_title (perspective);
      g_autofree gchar *command_id = g_strdup_printf ("org.gnome.builder.workbench.perspective('%s')", id);
      g_autofree gchar *action_name = g_strdup_printf ("win.perspective('%s')", id);
      g_autofree gchar *shortcut_help = g_strdup_printf ("Switch to %s perspective", title);
      const DzlShortcutEntry workbench_shortcut_entry[] = {
        { command_id,
          0, NULL,
          NC_("shortcut window", "Workbench shortcuts"),
          NC_("shortcut window", "Perspectives"),
          NC_("shortcut window", shortcut_help) },
      };

      controller = dzl_shortcut_controller_find (GTK_WIDGET (self));

      dzl_shortcut_controller_add_command_action (controller,
                                                  command_id,
                                                  accel,
                                                  DZL_SHORTCUT_PHASE_GLOBAL,
                                                  action_name);

      dzl_shortcut_manager_add_shortcut_entries (NULL,
                                                 workbench_shortcut_entry,
                                                 G_N_ELEMENTS (workbench_shortcut_entry),
                                                 GETTEXT_PACKAGE);
    }
}