Пример #1
0
void
gb_view_stack_add (GtkContainer *container,
                   GtkWidget    *child)
{
  GbViewStack *self = (GbViewStack *)container;

  g_assert (GB_IS_VIEW_STACK (self));

  if (GB_IS_VIEW (child))
    {
      GtkWidget *controls;

      gtk_widget_set_sensitive (GTK_WIDGET (self->close_button), TRUE);
      gtk_widget_set_sensitive (GTK_WIDGET (self->document_button), TRUE);
      gtk_widget_set_visible (GTK_WIDGET (self->views_button), TRUE);

      self->focus_history = g_list_prepend (self->focus_history, child);
      controls = gb_view_get_controls (GB_VIEW (child));
      if (controls)
        gtk_container_add (GTK_CONTAINER (self->controls_stack), controls);
      gtk_container_add (GTK_CONTAINER (self->stack), child);
      gb_view_set_back_forward_list (GB_VIEW (child), self->back_forward_list);
      gb_view_stack_add_list_row (self, GB_VIEW (child));
      gtk_stack_set_visible_child (self->stack, child);
    }
  else
    {
      GTK_CONTAINER_CLASS (gb_view_stack_parent_class)->add (container, child);
    }
}
Пример #2
0
void
gb_view_stack_remove (GbViewStack *self,
                      GbView      *view)
{
  GtkWidget *controls;
  GtkWidget *focus_after_close = NULL;

  g_assert (GB_IS_VIEW_STACK (self));
  g_assert (GB_IS_VIEW (view));

  focus_after_close = g_list_nth_data (self->focus_history, 1);
  if (focus_after_close != NULL)
    g_object_ref (focus_after_close);

  gb_view_stack_remove_list_row (self, view);

  self->focus_history = g_list_remove (self->focus_history, view);
  controls = gb_view_get_controls (view);
  if (controls)
    gtk_container_remove (GTK_CONTAINER (self->controls_stack), controls);
  gtk_container_remove (GTK_CONTAINER (self->stack), GTK_WIDGET (view));

  if (focus_after_close != NULL)
    {
      gtk_stack_set_visible_child (self->stack, focus_after_close);
      gtk_widget_grab_focus (GTK_WIDGET (focus_after_close));
      g_clear_object (&focus_after_close);
    }
  else
    g_signal_emit (self, gSignals [EMPTY], 0);
}
Пример #3
0
void
gb_view_stack_set_active_view (GbViewStack *self,
                               GtkWidget   *active_view)
{
  g_return_if_fail (GB_IS_VIEW_STACK (self));
  g_return_if_fail (!active_view || GB_IS_VIEW (active_view));

  if (self->destroyed)
    return;

  if (self->active_view != active_view)
    {
      if (self->active_view)
        {
          if (self->title_binding)
            g_binding_unbind (self->title_binding);
          ide_clear_weak_pointer (&self->title_binding);
          if (self->modified_binding)
            g_binding_unbind (self->modified_binding);
          ide_clear_weak_pointer (&self->modified_binding);
          gtk_label_set_label (self->title_label, NULL);
          ide_clear_weak_pointer (&self->active_view);
          gtk_widget_hide (GTK_WIDGET (self->controls_stack));
        }

      if (active_view)
        {
          GtkWidget *controls;
          GBinding *binding;
          GActionGroup *group;

          ide_set_weak_pointer (&self->active_view, active_view);
          if (active_view != gtk_stack_get_visible_child (self->stack))
            gtk_stack_set_visible_child (self->stack, active_view);

          self->focus_history = g_list_remove (self->focus_history, active_view);
          self->focus_history = g_list_prepend (self->focus_history, active_view);

          binding = g_object_bind_property (active_view, "title",
                                            self->title_label, "label",
                                            G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
          ide_set_weak_pointer (&self->title_binding, binding);

          binding = g_object_bind_property (active_view, "modified",
                                            self->modified_label, "visible",
                                            G_BINDING_SYNC_CREATE);
          ide_set_weak_pointer (&self->modified_binding, binding);

          controls = gb_view_get_controls (GB_VIEW (active_view));
          if (controls)
            {
              gtk_stack_set_visible_child (self->controls_stack, controls);
              gtk_widget_show (GTK_WIDGET (self->controls_stack));
            }

          group = gtk_widget_get_action_group (active_view, "view");
          if (group)
            gtk_widget_insert_action_group (GTK_WIDGET (self), "view", group);

          gb_view_stack_move_top_list_row (self, GB_VIEW (active_view));
        }

      g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_ACTIVE_VIEW]);
    }
}
/**
 * gb_view_source_init:
 * @: (in): A #GbViewSource.
 *
 * Initializes the newly created #GbViewSource instance.
 */
static void
gb_view_source_init (GbViewSource *source)
{
    GbViewSourcePrivate *priv;
    GtkWidget *overlay;

    ENTRY;

    source->priv = priv =
                       G_TYPE_INSTANCE_GET_PRIVATE(source,
                               GB_TYPE_VIEW_SOURCE,
                               GbViewSourcePrivate);

    g_object_set(source,
                 "icon-name", GTK_STOCK_FILE,
                 "name", _("Unsaved Document"),
                 NULL);

    priv->buffer = gtk_source_buffer_new(NULL);
    g_signal_connect_swapped(priv->buffer,
                             "notify::cursor-position",
                             G_CALLBACK(gb_view_source_notify_cursor),
                             source);
    g_signal_connect_swapped(priv->buffer, "modified-changed",
                             G_CALLBACK(gb_view_source_buffer_modified_changed),
                             source);

    overlay = g_object_new(GTK_TYPE_OVERLAY,
                           "visible", TRUE,
                           NULL);
    g_signal_connect(overlay, "get-child-position",
                     G_CALLBACK(gb_view_source_position_progress),
                     NULL);
    gtk_container_add_with_properties(GTK_CONTAINER(source), overlay,
                                      "left-attach", 0,
                                      "width", 1,
                                      "top-attach", 0,
                                      "height", 1,
                                      NULL);

    priv->vpaned = g_object_new(GTK_TYPE_VPANED,
                                "visible", TRUE,
                                NULL);
    gtk_container_add(GTK_CONTAINER(overlay), priv->vpaned);

    priv->progress = g_object_new(GB_TYPE_PROGRESS_BAR,
                                  "visible", FALSE,
                                  NULL);
    gtk_overlay_add_overlay(GTK_OVERLAY(overlay), priv->progress);

    priv->scroller1 = g_object_new(gb_get_scrolled_window_gtype(),
                                   "expand", TRUE,
                                   "visible", TRUE,
                                   NULL);
    gtk_container_add_with_properties(GTK_CONTAINER(priv->vpaned), priv->scroller1,
                                      "shrink", FALSE,
                                      "resize", TRUE,
                                      NULL);

    priv->source1 = gb_view_source_create_source_view(source);
    gtk_container_add(GTK_CONTAINER(priv->scroller1), priv->source1);

    {
        GtkSourceLanguageManager *langs = gtk_source_language_manager_get_default();
        const gchar * const * ids = gtk_source_language_manager_get_language_ids(langs);
        GtkSourceLanguage *lang;
        const gchar *section;
        GHashTable *section_menu;
        GPtrArray *sorted;
        GtkWidget *controls = gb_view_get_controls(GB_VIEW(source));
        GtkWidget *menu;
        GtkWidget *mitem;
        GtkWidget *submenu;
        guint i;

        section_menu = g_hash_table_new(g_str_hash, g_str_equal);
        menu = gtk_menu_new();

        sorted = g_ptr_array_new();
        for (i = 0; ids[i]; i++) {
            lang = gtk_source_language_manager_get_language(langs, ids[i]);
            g_ptr_array_add(sorted, lang);
        }
        g_ptr_array_sort(sorted, lang_sort_func);
        for (i = 0; i < sorted->len; i++) {
            lang = g_ptr_array_index(sorted, i);
            section = gtk_source_language_get_section(lang);
            if (!(submenu = g_hash_table_lookup(section_menu, section))) {
                submenu = gtk_menu_new();
                mitem = g_object_new(GTK_TYPE_MENU_ITEM,
                                     "label", section,
                                     "submenu", submenu,
                                     "visible", TRUE,
                                     NULL);
                gtk_container_add(GTK_CONTAINER(menu), mitem);
                g_hash_table_insert(section_menu, (gchar*)section, submenu);
            }
            mitem = g_object_new(GTK_TYPE_MENU_ITEM,
                                 "label", gtk_source_language_get_name(lang),
                                 "visible", TRUE,
                                 NULL);
            g_signal_connect_swapped(mitem, "activate",
                                     G_CALLBACK(gb_view_source_lang_activate),
                                     source);
            g_object_set_data(G_OBJECT(mitem), "language-id",
                              (gchar *)gtk_source_language_get_id(lang));
            gtk_container_add(GTK_CONTAINER(submenu), mitem);
        }
        g_ptr_array_free(sorted, TRUE);

        priv->lang_combo = g_object_new(GB_TYPE_MENU_BUTTON,
                                        "hexpand", FALSE,
                                        "label", "",
                                        "menu", menu,
                                        "tooltip-text", _("Set source language."),
                                        "visible", TRUE,
                                        NULL);
        gb_widget_shrink_font(
            gb_menu_button_get_label_widget(
                GB_MENU_BUTTON(priv->lang_combo)));

        gtk_style_context_add_class(gtk_widget_get_style_context(priv->lang_combo),
                                    GB_STYLE_CLASS_TOP_BAR);
        gtk_container_add_with_properties(GTK_CONTAINER(controls), priv->lang_combo,
                                          "expand", FALSE,
                                          NULL);

        g_hash_table_unref(section_menu);
    }

    {
        GtkWidget *controls = gb_view_get_controls(GB_VIEW(source));
        GtkWidget *b;
        GtkWidget *item;
        GtkWidget *menu;
        GtkWidget *group = NULL;
        gboolean active;
        gchar *str;
        int tabs[] = { 2, 3, 4, 5, 8, 0 };
        int i;

        b = g_object_new(GB_TYPE_MENU_BUTTON,
                         "hexpand", FALSE,
                         "label", "4",
                         "tooltip-text", _("Set tab-character width."),
                         "visible", TRUE,
                         "width-request", 45,
                         NULL);

        menu = gtk_menu_new();
        for (i = 0; tabs[i]; i++) {
            str = g_strdup_printf("%d", tabs[i]);
            item = g_object_new(GTK_TYPE_RADIO_MENU_ITEM,
                                "group", group,
                                "label", str,
                                "visible", TRUE,
                                NULL);
            if (!group) {
                group = item;
            }
            active = (tabs[i] == gtk_source_view_get_tab_width(
                          GTK_SOURCE_VIEW(priv->source1)));
            g_object_set(item, "active", active, NULL);
            if (active) {
                g_object_set(b, "label", str, NULL);
            }
            g_signal_connect(item, "activate",
                             G_CALLBACK(gb_view_source_tab_size_activate),
                             source);
            gtk_container_add(GTK_CONTAINER(menu), item);
            g_free(str);
        }
        g_object_set(b, "menu", menu, NULL);

        item = g_object_new(GTK_TYPE_SEPARATOR_MENU_ITEM,
                            "visible", TRUE,
                            NULL);
        gtk_container_add(GTK_CONTAINER(menu), item);

        item = g_object_new(GTK_TYPE_CHECK_MENU_ITEM,
                            "active", TRUE,
                            "label", _("Use Spaces"),
                            "visible", TRUE,
                            NULL);
        g_signal_connect(item, "toggled",
                         G_CALLBACK(gb_view_source_spaces_toggled),
                         source);
        gtk_container_add(GTK_CONTAINER(menu), item);

        gb_widget_shrink_font(gb_menu_button_get_label_widget(GB_MENU_BUTTON(b)));
        gtk_style_context_add_class(gtk_widget_get_style_context(b),
                                    GB_STYLE_CLASS_TOP_BAR);
        gtk_container_add_with_properties(GTK_CONTAINER(controls), b,
                                          "expand", FALSE,
                                          NULL);
        priv->size_combo = b;
    }

    {
        GtkWidget *controls = gb_view_get_controls(GB_VIEW(source));
        GtkWidget *img;
        GtkWidget *b;

        img = g_object_new(GTK_TYPE_IMAGE,
                           "icon-name", "gb-split",
                           "icon-size", GTK_ICON_SIZE_MENU,
                           "visible", TRUE,
                           NULL);
        b = g_object_new(GTK_TYPE_TOGGLE_BUTTON,
                         "child", img,
                         "tooltip-text", _("Split the editor into two views."),
                         "visible", TRUE,
                         NULL);
        gtk_style_context_add_class(gtk_widget_get_style_context(b),
                                    GB_STYLE_CLASS_TOP_BAR);
        gtk_container_add_with_properties(GTK_CONTAINER(controls), b,
                                          "expand", FALSE,
                                          NULL);
        g_signal_connect(b, "toggled",
                         G_CALLBACK(split_toggled),
                         source);
    }

    {
        GtkWidget *hbox;
        GtkWidget *vp;
        GtkWidget *c;

        hbox = g_object_new(GTK_TYPE_HBOX,
                            "height-request", 30,
                            "visible", TRUE,
                            NULL);
        gtk_container_add_with_properties(GTK_CONTAINER(source), hbox,
                                          "height", 1,
                                          "left-attach", 0,
                                          "top-attach", 1,
                                          "width", 1,
                                          NULL);

        gtk_container_add(GTK_CONTAINER(hbox),
                          (c = g_object_new(GTK_TYPE_COMBO_BOX,
                                            "visible", TRUE,
                                            NULL)));
        gtk_style_context_add_class(gtk_widget_get_style_context(c),
                                    GB_STYLE_CLASS_BOTTOM_BAR);

        vp = g_object_new(GTK_TYPE_VIEWPORT,
                          "visible", TRUE,
                          NULL);
        gtk_style_context_add_class(gtk_widget_get_style_context(vp),
                                    GB_STYLE_CLASS_BOTTOM_BAR);
        gtk_container_add_with_properties(GTK_CONTAINER(hbox), vp,
                                          "expand", FALSE,
                                          "fill", TRUE,
                                          NULL);

        priv->pos_label = g_object_new(GTK_TYPE_LABEL,
                                       "label", _("Line 1, Column 1"),
                                       "visible", TRUE,
                                       "xalign", 1.0f,
                                       "xpad", 6,
                                       NULL);
        gb_widget_shrink_font(priv->pos_label);
        gtk_container_add(GTK_CONTAINER(vp), priv->pos_label);
    }

    priv->theme_handler =
        g_signal_connect_swapped(gtk_settings_get_default(),
                                 "notify::gtk-application-prefer-dark-theme",
                                 G_CALLBACK(gb_view_source_update_style),
                                 source);

    EXIT;
}