コード例 #1
0
static void
ide_editor_spell__widget_mapped_cb (IdeEditorSpellWidget *self)
{
  GActionGroup *group = NULL;
  GtkWidget *widget = GTK_WIDGET (self->view);
  g_autoptr (GVariant) value = NULL;

  g_assert (IDE_IS_EDITOR_SPELL_WIDGET (self));

  while ((group == NULL) && (widget != NULL))
    {
      group = gtk_widget_get_action_group (widget, "view");
      widget = gtk_widget_get_parent (widget);
    }

  if (group != NULL &&
      NULL != (self->view_spellchecking_action = g_action_map_lookup_action (G_ACTION_MAP (group),
                                                                             "spellchecking")))
    {
      value = g_action_get_state (self->view_spellchecking_action);
      self->view_spellchecker_set = g_variant_get_boolean (value);
      gtk_switch_set_active (GTK_SWITCH (self->highlight_switch), self->view_spellchecker_set);
    }

  jump_to_next_misspelled_word (self);
}
コード例 #2
0
static gboolean
gstyle_color_widget_key_pressed_cb (GstyleColorWidget *self,
                                    GdkEventKey       *event)
{
  GtkWidget *ancestor;
  GActionGroup *group;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (event != NULL);

  if (event->type != GDK_KEY_PRESS)
    return GDK_EVENT_PROPAGATE;

  ancestor = gtk_widget_get_ancestor (GTK_WIDGET (self), GSTYLE_TYPE_PALETTE_WIDGET);
  if (event->keyval == GDK_KEY_F2 && ancestor != NULL)
    {
      group = gtk_widget_get_action_group (GTK_WIDGET (self), "gstyle-color-widget-menu");
      if (group != NULL)
        g_action_group_activate_action (group, "rename", NULL);

      return GDK_EVENT_STOP;
    }

  return GDK_EVENT_PROPAGATE;
}
コード例 #3
0
ファイル: irc-application.c プロジェクト: TingPing/irc-client
static void
irc_application_focus_context (GSimpleAction *action, GVariant *param, gpointer data)
{
	IrcApplication *self = IRC_APPLICATION(data);
	IrcApplicationPrivate *priv = irc_application_get_instance_private (IRC_APPLICATION(self));
	GActionGroup *actions = gtk_widget_get_action_group (GTK_WIDGET(priv->main_window), "context");
	g_assert (actions != NULL);
	g_action_group_activate_action (actions, "focus", param);
}
コード例 #4
0
void
fsearch_window_actions_update   (FsearchApplicationWindow *self)
{
    GtkTreeSelection *selection = fsearch_application_window_get_listview_selection (self);
    GtkTreeView *treeview = gtk_tree_selection_get_tree_view (selection);

    gint num_rows = 0;
    if (treeview) {
        GtkTreeModel *model = gtk_tree_view_get_model (treeview);
        if (model) {
            num_rows = gtk_tree_model_iter_n_children (model, NULL);
        }
    }

    GActionGroup *group = gtk_widget_get_action_group (GTK_WIDGET (self), "win");
    g_assert (G_IS_SIMPLE_ACTION_GROUP (group));

    gint num_rows_selected = gtk_tree_selection_count_selected_rows (selection);
    action_set_enabled (group, "select_all", num_rows);
    action_set_enabled (group, "deselect_all", num_rows_selected);
    action_set_enabled (group, "invert_selection", num_rows_selected);
    action_set_enabled (group, "copy_clipboard", num_rows_selected);
    action_set_enabled (group, "cut_clipboard", num_rows_selected);
    action_set_enabled (group, "delete_selection", num_rows_selected);
    action_set_enabled (group, "open", num_rows_selected);
    action_set_enabled (group, "open_with", num_rows_selected);
    action_set_enabled (group, "open_with_other", FALSE);
    action_set_enabled (group, "open_folder", num_rows_selected);
    action_set_enabled (group, "focus_search", TRUE);
    action_set_enabled (group, "toggle_focus", TRUE);
    action_set_enabled (group, "hide_window", TRUE);
    action_set_enabled (group, "update_database", TRUE);
    action_set_enabled (group, "show_menubar", TRUE);
    action_set_enabled (group, "show_statusbar", TRUE);
    action_set_enabled (group, "show_filter", TRUE);
    action_set_enabled (group, "show_search_button", TRUE);
    action_set_enabled (group, "show_name_column", FALSE);
    action_set_enabled (group, "show_path_column", TRUE);
    action_set_enabled (group, "show_type_column", TRUE);
    action_set_enabled (group, "show_size_column", TRUE);
    action_set_enabled (group, "show_modified_column", TRUE);

    FsearchConfig *config = fsearch_application_get_config (FSEARCH_APPLICATION_DEFAULT);
    action_set_active_bool (group, "show_menubar", config->show_menubar);
    action_set_active_bool (group, "show_statusbar", config->show_statusbar);
    action_set_active_bool (group, "show_filter", config->show_filter);
    action_set_active_bool (group, "show_search_button", config->show_search_button);
    action_set_active_bool (group, "search_in_path", config->search_in_path);
    action_set_active_bool (group, "search_mode", config->enable_regex);
    action_set_active_bool (group, "match_case", config->match_case);
    action_set_active_bool (group, "show_name_column", true);
    action_set_active_bool (group, "show_path_column", config->show_path_column);
    action_set_active_bool (group, "show_type_column", config->show_type_column);
    action_set_active_bool (group, "show_size_column", config->show_size_column);
    action_set_active_bool (group, "show_modified_column", config->show_modified_column);
}
コード例 #5
0
static void
update_replace_actions_sensitivity (IdeEditorFrame *self)
{
  GtkSourceSearchContext *search_context;
  GtkSourceSearchSettings *search_settings;
  GtkTextBuffer *buffer;
  GtkTextIter start;
  GtkTextIter end;
  const gchar *search_text;
  const gchar *replace_text;
  gint pos;
  gint count;
  gboolean enable_replace;
  gboolean enable_replace_all;
  gboolean replace_regex_valid;
  g_autoptr(GError) regex_error = NULL;
  g_autoptr(GError) replace_regex_error = NULL;
  GActionGroup *group;
  GAction *replace_action;
  GAction *replace_all_action;

  g_assert (IDE_IS_EDITOR_FRAME (self));

  search_context = ide_source_view_get_search_context (self->source_view);
  search_settings = gtk_source_search_context_get_settings (search_context);
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
  gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer), &start, &end);
  replace_text = gtk_entry_get_text (GTK_ENTRY (self->replace_entry));

  /* Gather enough info to determine if Replace or Replace All would make sense */
  search_text = gtk_entry_get_text (GTK_ENTRY (self->search_entry));
  pos = gtk_source_search_context_get_occurrence_position (search_context, &start, &end);
  count = gtk_source_search_context_get_occurrences_count (search_context);
  regex_error = gtk_source_search_context_get_regex_error (search_context);
  replace_regex_valid = gtk_source_search_settings_get_regex_enabled (search_settings) ?
                        g_regex_check_replacement (replace_text, NULL, &replace_regex_error) :
                        TRUE;

  enable_replace = (!ide_str_empty0 (search_text) &&
                    regex_error == NULL &&
                    replace_regex_valid &&
                    pos > 0);

  enable_replace_all = (!ide_str_empty0 (search_text) &&
                        regex_error == NULL &&
                        replace_regex_valid &&
                        count > 0);

  group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry");
  replace_action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace");
  replace_all_action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace-all");

  g_simple_action_set_enabled (G_SIMPLE_ACTION (replace_action), enable_replace);
  g_simple_action_set_enabled (G_SIMPLE_ACTION (replace_all_action), enable_replace_all);
}
コード例 #6
0
ファイル: fsearch_window.c プロジェクト: cboxdoerfer/fsearch
static gboolean
on_listview_key_press_event (GtkWidget *widget,
                             GdkEventKey  *event,
                             gpointer   user_data)
{
    if (event->state & GDK_CONTROL_MASK) {
        if ((event->keyval == GDK_KEY_Return)
            || (event->keyval == GDK_KEY_KP_Enter)) {
            GActionGroup *group = gtk_widget_get_action_group (GTK_WIDGET (user_data), "win");
            g_action_group_activate_action (group, "open_folder", NULL);
            return TRUE;
        }
        else if (event->keyval == GDK_KEY_c) {
            GActionGroup *group = gtk_widget_get_action_group (GTK_WIDGET (user_data), "win");
            g_action_group_activate_action (group, "copy_clipboard", NULL);
            return TRUE;
        }
    }
    return FALSE;
}
コード例 #7
0
static void
gbp_retab_editor_page_addin_unload (IdeEditorPageAddin *addin,
                             IdeEditorPage      *view)
{
  GActionGroup *group;

  g_assert (GBP_IS_RETAB_EDITOR_PAGE_ADDIN (addin));
  g_assert (IDE_IS_EDITOR_PAGE (view));

  group = gtk_widget_get_action_group (GTK_WIDGET (view), "editor-page");
  g_action_map_remove_action (G_ACTION_MAP (group), "retab");
}
コード例 #8
0
static void
popup_targets_received (GtkClipboard     *clipboard,
                        GtkSelectionData *data,
                        gpointer          user_data)
{
  PopupInfo *popup_info = user_data;
  g_autoptr(IdeTerminal) self = NULL;
  g_autoptr(GdkEvent) event = NULL;
  IdeTerminalPrivate *priv;

  g_assert (popup_info != NULL);
  g_assert (IDE_IS_TERMINAL (popup_info->terminal));

  self = g_steal_pointer (&popup_info->terminal);
  priv = ide_terminal_get_instance_private (self);
  event = g_steal_pointer (&popup_info->event);

  if (gtk_widget_get_realized (GTK_WIDGET (self)))
    {
      DzlWidgetActionGroup *group;
      GMenu *menu;
      gboolean clipboard_contains_text;
      gboolean have_selection;

      clipboard_contains_text = gtk_selection_data_targets_include_text (data);
      have_selection = vte_terminal_get_has_selection (VTE_TERMINAL (self));

      g_clear_pointer (&priv->popup_menu, gtk_widget_destroy);

      priv->url = vte_terminal_match_check_event (VTE_TERMINAL (self), event, NULL);

      menu = dzl_application_get_menu_by_id (DZL_APPLICATION_DEFAULT, "ide-terminal-view-popup-menu");
      priv->popup_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));

      group = DZL_WIDGET_ACTION_GROUP (gtk_widget_get_action_group (GTK_WIDGET (self), "terminal"));

      dzl_widget_action_group_set_action_enabled (group, "copy-link-address", priv->url != NULL);
      dzl_widget_action_group_set_action_enabled (group, "open-link", priv->url != NULL);
      dzl_widget_action_group_set_action_enabled (group, "copy-clipboard", have_selection);
      dzl_widget_action_group_set_action_enabled (group, "paste-clipboard", clipboard_contains_text);

      dzl_gtk_widget_add_style_class (priv->popup_menu, GTK_STYLE_CLASS_CONTEXT_MENU);
      gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu), GTK_WIDGET (self), popup_menu_detach);

      g_signal_emit (self, signals[POPULATE_POPUP], 0, priv->popup_menu);

      gtk_menu_popup_at_pointer (GTK_MENU (priv->popup_menu), event);
    }

  g_slice_free (PopupInfo, popup_info);
}
コード例 #9
0
static void
gstyle_color_widget_on_drag_data_delete (GtkWidget      *widget,
                                         GdkDragContext *context)
{
  GstyleColorWidget *self = (GstyleColorWidget *)widget;
  GActionGroup *group;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GDK_IS_DRAG_CONTEXT (context));

  group = gtk_widget_get_action_group (GTK_WIDGET (self), "gstyle-color-widget-menu");
  if (group != NULL)
    g_action_group_activate_action (group, "remove", NULL);
}
コード例 #10
0
static void
popover_button_remove_clicked_cb (GstyleColorWidget *self,
                                  GdkEvent          *event,
                                  GtkButton         *button)
{
  GActionGroup *group;

  g_assert (GSTYLE_IS_COLOR_WIDGET (self));
  g_assert (GTK_IS_BUTTON (button));

  group = gtk_widget_get_action_group (GTK_WIDGET (self), "gstyle-color-widget-menu");
  if (group != NULL)
    g_action_group_activate_action (group, "remove", NULL);
}
コード例 #11
0
static void
activate_action (GtkWidget   *widget,
                 const gchar *prefix,
                 const gchar *action_name,
                 GVariant    *parameter)
{
    GApplication *app;
    GtkWidget *toplevel;
    GActionGroup *group = NULL;

    g_return_if_fail (GTK_IS_WIDGET (widget));
    g_return_if_fail (prefix);
    g_return_if_fail (action_name);

    g_print ("activate!\n");

    app = g_application_get_default ();
    toplevel = gtk_widget_get_toplevel (widget);

    while ((group == NULL) && (widget != NULL))
    {
        group = gtk_widget_get_action_group (widget, prefix);
        widget = gtk_widget_get_parent (widget);
    }

    if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
        group = G_ACTION_GROUP (toplevel);

    if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
        group = G_ACTION_GROUP (app);

    if (group)
    {
        if (g_action_group_has_action (group, action_name))
        {
            g_print ("Activating %s.%s\n", prefix, action_name);
            g_action_group_activate_action (group, action_name, parameter);
            return;
        }
    }

    if (parameter && g_variant_is_floating (parameter))
    {
        parameter = g_variant_ref_sink (parameter);
        g_variant_unref (parameter);
    }

    g_warning ("Failed to resolve action %s.%s", prefix, action_name);
}
コード例 #12
0
static void
gbp_retab_editor_page_addin_load (IdeEditorPageAddin *addin,
                           IdeEditorPage      *view)
{
  GbpRetabEditorPageAddin *self = (GbpRetabEditorPageAddin *)addin;
  GActionGroup *group;

  g_assert (GBP_IS_RETAB_EDITOR_PAGE_ADDIN (addin));
  g_assert (IDE_IS_EDITOR_PAGE (view));

  self->editor_view = view;

  group = gtk_widget_get_action_group (GTK_WIDGET (view), "editor-page");
  g_action_map_add_action_entries (G_ACTION_MAP (group), actions, G_N_ELEMENTS (actions), self);
}
コード例 #13
0
ファイル: fsearch_window.c プロジェクト: cboxdoerfer/fsearch
static gboolean
toggle_action_on_2button_press (GdkEventButton *event, const char *action, gpointer user_data)
{
    if (event->button == GDK_BUTTON_PRIMARY
        && event->type == GDK_2BUTTON_PRESS) {
        GActionGroup *group = gtk_widget_get_action_group (GTK_WIDGET (user_data), "win");
        GVariant *state = g_action_group_get_action_state (group, action);
        g_action_group_change_action_state (group,
                                            action,
                                            g_variant_new_boolean (!g_variant_get_boolean (state)));
        g_variant_unref (state);
        return TRUE;
    }
    return FALSE;
}
コード例 #14
0
static void
ide_editor_frame__search_populate_popup (IdeEditorFrame *self,
                                         GtkWidget      *popup,
                                         GdTaggedEntry  *entry)
{
  g_assert (IDE_IS_EDITOR_FRAME (self));
  g_assert (GTK_IS_WIDGET (popup));
  g_assert (GD_IS_TAGGED_ENTRY (entry));

  if (GTK_IS_MENU_SHELL (popup))
    {
      GMenu *menu;
      GActionGroup *group;
      GAction *action;
      GtkEntryBuffer *buffer;
      GtkClipboard *clipboard;
      gboolean clipboard_contains_text;
      gboolean entry_has_selection;

      group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry");

      menu = ide_application_get_menu_by_id (IDE_APPLICATION_DEFAULT, "ide-editor-frame-search-menu");
      gtk_menu_shell_bind_model (GTK_MENU_SHELL (popup), G_MENU_MODEL (menu), NULL, TRUE);

      clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD);
      clipboard_contains_text = gtk_clipboard_wait_is_text_available (clipboard);

      action = g_action_map_lookup_action (G_ACTION_MAP (group), "paste-clipboard");
      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), clipboard_contains_text);

      entry_has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), NULL, NULL);

      action = g_action_map_lookup_action (G_ACTION_MAP (group), "cut-clipboard");
      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), entry_has_selection);

      action = g_action_map_lookup_action (G_ACTION_MAP (group), "copy-clipboard");
      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), entry_has_selection);

      action = g_action_map_lookup_action (G_ACTION_MAP (group), "delete-selection");
      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), entry_has_selection);

      action = g_action_map_lookup_action (G_ACTION_MAP (group), "select-all");
      buffer = gtk_entry_get_buffer (GTK_ENTRY (self->search_entry));
      g_simple_action_set_enabled (G_SIMPLE_ACTION (action), gtk_entry_buffer_get_length (buffer) > 0);
    }
}
コード例 #15
0
static gboolean
egg_empty_state_action (GtkWidget   *widget,
                        const gchar *prefix,
                        const gchar *action_name,
                        GVariant    *parameter)
{
  GtkWidget *toplevel;
  GApplication *app;
  GActionGroup *group = NULL;

  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
  g_return_val_if_fail (prefix, FALSE);
  g_return_val_if_fail (action_name, FALSE);

  app = g_application_get_default ();
  toplevel = gtk_widget_get_toplevel (widget);

  while ((group == NULL) && (widget != NULL))
    {
      group = gtk_widget_get_action_group (widget, prefix);
      widget = gtk_widget_get_parent (widget);
    }

  if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
    group = G_ACTION_GROUP (toplevel);

  if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
    group = G_ACTION_GROUP (app);

  if (group && g_action_group_has_action (group, action_name))
    {
      g_action_group_activate_action (group, action_name, parameter);
      return TRUE;
    }

  if (parameter && g_variant_is_floating (parameter))
    {
      parameter = g_variant_ref_sink (parameter);
      g_variant_unref (parameter);
    }

  g_warning ("Failed to locate action %s.%s", prefix, action_name);

  return FALSE;
}
コード例 #16
0
ファイル: test-panel.c プロジェクト: matthiasclasen/panel-gtk
gint
main (gint   argc,
      gchar *argv[])
{
  GtkBuilder *builder = NULL;
  GtkWindow *window = NULL;
  GActionGroup *group;
  GtkWidget *dockbin;
  GtkWidget *dockoverlay;
  GtkCssProvider *provider;
  GError *error = NULL;

  gtk_init (&argc, &argv);

  provider = gtk_css_provider_new ();
  gtk_css_provider_load_from_path (provider, "test-panel.css", &error);
  g_assert_no_error (error);
  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                             GTK_STYLE_PROVIDER (provider),
                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  builder = gtk_builder_new ();
  gtk_builder_add_callback_symbol (builder, "toggle_all", G_CALLBACK (toggle_all));
  gtk_builder_add_from_file (builder, "test-panel.ui", &error);
  g_assert_no_error (error);

  window = GTK_WINDOW (gtk_builder_get_object (builder, "window"));
  g_signal_connect (window, "delete-event", gtk_main_quit, NULL);

  dockoverlay = GTK_WIDGET (gtk_builder_get_object (builder, "dockoverlay"));
  _pnl_dock_item_printf (PNL_DOCK_ITEM (dockoverlay));

  dockbin = GTK_WIDGET (gtk_builder_get_object (builder, "dockbin"));
  group = gtk_widget_get_action_group (dockbin, "dockbin");
  gtk_widget_insert_action_group (GTK_WIDGET (window), "dockbin", group);

  gtk_builder_connect_signals (builder, dockbin);

  gtk_window_present (window);
  gtk_main ();

  g_clear_object (&builder);

  return 0;
}
コード例 #17
0
void
gb_project_tree_actions_update (GbProjectTree *self)
{
  GActionGroup *group;
  GbTreeNode *selection;
  GObject *item = NULL;

  IDE_ENTRY;

  g_assert (GB_IS_PROJECT_TREE (self));

  group = gtk_widget_get_action_group (GTK_WIDGET (self), "project-tree");
  g_assert (G_IS_SIMPLE_ACTION_GROUP (group));

  selection = gb_tree_get_selected (GB_TREE (self));
  if (selection != NULL)
    item = gb_tree_node_get_item (selection);

  action_set (group, "new-file",
              "enabled", (IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)),
              NULL);
  action_set (group, "new-directory",
              "enabled", (IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)),
              NULL);
  action_set (group, "open",
              "enabled", (IDE_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
              NULL);
  action_set (group, "open-with-editor",
              "enabled", (IDE_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
              NULL);
  action_set (group, "open-containing-folder",
              "enabled", (IDE_IS_PROJECT_FILE (item) || IDE_IS_PROJECT_FILES (item)),
              NULL);
  action_set (group, "rename-file",
              "enabled", IDE_IS_PROJECT_FILE (item),
              NULL);
  action_set (group, "move-to-trash",
              "enabled", (IDE_IS_PROJECT_FILE (item) && !project_file_is_directory (item)),
              NULL);

  IDE_EXIT;
}
コード例 #18
0
void
gstyle_color_panel_actions_init (GstyleColorPanel *self)
{
  g_autoptr (GSimpleActionGroup) pages_group = NULL;
  GActionGroup *palette_widget_actions_group;

  pages_group = g_simple_action_group_new ();
  g_action_map_add_action_entries (G_ACTION_MAP (pages_group), ColorPanelPagesPrefsActions,
                                   G_N_ELEMENTS (ColorPanelPagesPrefsActions), self);
  gtk_widget_insert_action_group (GTK_WIDGET (self), "gstyle-pages-prefs", G_ACTION_GROUP (pages_group));

  if (self->palette_widget != NULL)
    {
      palette_widget_actions_group = gtk_widget_get_action_group (GTK_WIDGET (self->palette_widget), "gstyle-palettes-prefs");
      if (palette_widget_actions_group != NULL)
        gtk_widget_insert_action_group (GTK_WIDGET (self),
                                        "gstyle-palettes-prefs",
                                        palette_widget_actions_group);
    }
}
コード例 #19
0
static void
ide_editor_frame_actions_find_replace (GSimpleAction *action,
                                       GVariant      *variant,
                                       gpointer       user_data)
{
  GActionGroup *frame_group;
  GAction *replace_options_action;
  g_autoptr (GVariant) replace_options_variant = NULL;
  IdeEditorFrame *self = user_data;

  g_assert (IDE_IS_EDITOR_FRAME (self));

  if (NULL != (frame_group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry")) &&
      NULL != (replace_options_action = g_action_map_lookup_action (G_ACTION_MAP (frame_group), "toggle-search-replace")))
    {
      replace_options_variant = g_variant_new_boolean (TRUE);
      ide_editor_frame_actions_find (action, variant, user_data);
      ide_editor_frame_actions_toggle_search_replace (G_SIMPLE_ACTION (replace_options_action), replace_options_variant, user_data);
    }
}
コード例 #20
0
ファイル: ephy-notebook.c プロジェクト: GNOME/epiphany
static void
ephy_notebook_rebuild_tab_menu (EphyNotebook *notebook)
{
  GMenuItem *item;
  const char *text;
  char *ellipsized_text;
  int num_pages;
  GtkWidget *window;
  GActionGroup *group;
  GAction *action;
  gint current_page;

  g_menu_remove_all (notebook->tab_menu);

  num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));

  /* TODO: Add favicon as well. Will have to ditch GMenu. :( */
  for (int i = 0; i < num_pages; i++) {
    text = get_nth_tab_label_text (GTK_NOTEBOOK (notebook), i);
    ellipsized_text = ellipsize_tab_label (text);
    item = g_menu_item_new (ellipsized_text, NULL);
    g_menu_item_set_action_and_target (item, "win.show-tab", "u", (guint)i, NULL);
    g_menu_append_item (notebook->tab_menu, item);
    g_free (ellipsized_text);
    g_object_unref (item);
  }

  current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
  if (current_page < 0)
    return;

  window = gtk_widget_get_toplevel (GTK_WIDGET (notebook));
  group = gtk_widget_get_action_group (window, "win");
  /* Is window being destroyed? */
  if (group == NULL)
    return;

  action = g_action_map_lookup_action (G_ACTION_MAP (group), "show-tab");
  g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_uint32 ((guint32)current_page));
}
コード例 #21
0
static void
ide_editor_frame_actions_exit_search (GSimpleAction *action,
                                      GVariant      *state,
                                      gpointer       user_data)
{
  IdeEditorFrame *self = user_data;
  GtkTextBuffer *buffer;
  GActionGroup *group;
  GAction *replace_action;
  GAction *replace_all_action;

  g_assert (IDE_IS_EDITOR_FRAME (self));

  /* stash the search string for later */
  g_free (self->previous_search_string);
  g_object_get (self->search_entry, "text", &self->previous_search_string, NULL);

  /* disable the replace and replace all actions */
  group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry");
  replace_action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace");
  replace_all_action = g_action_map_lookup_action (G_ACTION_MAP (group), "replace-all");
  g_simple_action_set_enabled (G_SIMPLE_ACTION (replace_action), FALSE);
  g_simple_action_set_enabled (G_SIMPLE_ACTION (replace_all_action), FALSE);

  /* clear the highlights in the source view */
  ide_source_view_clear_search (self->source_view);

  /* disable rubberbanding and ensure insert mark is on screen */
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->source_view));
  ide_source_view_set_rubberband_search (self->source_view, FALSE);
  ide_source_view_scroll_mark_onscreen (self->source_view,
                                        gtk_text_buffer_get_insert (buffer),
                                        TRUE,
                                        0.5,
                                        0.5);

  /* finally we can focus the source view */
  gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
}
コード例 #22
0
void
gb_editor_view_actions_update (GbEditorView *self)
{
  GtkSourceLanguage *language;
  const gchar *lang_id = NULL;
  GActionGroup *group;
  GAction *action;
  gboolean enabled;

  g_assert (GB_IS_EDITOR_VIEW (self));

  group = gtk_widget_get_action_group (GTK_WIDGET (self), "view");
  if (!G_IS_SIMPLE_ACTION_GROUP (group))
    return;

  /* update preview sensitivity */
  language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (self->document));
  if (language)
    lang_id = gtk_source_language_get_id (language);
  enabled = ((g_strcmp0 (lang_id, "html") == 0) ||
             (g_strcmp0 (lang_id, "markdown") == 0));
  action = g_action_map_lookup_action (G_ACTION_MAP (group), "preview");
  g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
}
コード例 #23
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]);
    }
}
コード例 #24
0
void
ide_editor_frame_set_document (IdeEditorFrame *self,
                               IdeBuffer      *buffer)
{
  GtkSourceSearchContext *search_context;
  GtkSourceSearchSettings *search_settings;
  GtkTextMark *mark;
  GtkTextIter iter;
  GActionGroup *group;

  g_return_if_fail (IDE_IS_EDITOR_FRAME (self));
  g_return_if_fail (IDE_IS_BUFFER (buffer));

  gtk_text_view_set_buffer (GTK_TEXT_VIEW (self->source_view), GTK_TEXT_BUFFER (buffer));

  g_signal_connect_object (buffer,
                           "notify::busy",
                           G_CALLBACK (ide_editor_frame_update_ruler),
                           self,
                           G_CONNECT_SWAPPED);

  self->cursor_moved_handler =
    g_signal_connect (buffer,
                      "cursor-moved",
                      G_CALLBACK (on_cursor_moved),
                      self);
  mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (buffer));
  gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (buffer), &iter, mark);
  on_cursor_moved (buffer, &iter, self);

  /*
   * Sync search entry with the search settings.
   */
  search_context = ide_source_view_get_search_context (self->source_view);
  search_settings = gtk_source_search_context_get_settings (search_context);
  g_object_bind_property_full (self->search_entry, "text", search_settings, "search-text",
                               (G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL),
                               search_text_transform_to, search_text_transform_from,
                               self, NULL);
  g_signal_connect_object (search_context,
                           "notify::occurrences-count",
                           G_CALLBACK (ide_editor_frame_on_search_occurrences_notify),
                           self,
                           G_CONNECT_SWAPPED);

  g_signal_connect_object (search_context,
                           "notify::regex-error",
                           G_CALLBACK (on_regex_error_changed),
                           self,
                           G_CONNECT_SWAPPED);

  /*
   * Add search option property actions
   */
  group = gtk_widget_get_action_group (GTK_WIDGET (self->search_frame), "search-entry");
  ide_editor_frame_add_search_actions (self, group);

  g_signal_connect_object (search_settings,
                           "notify::search-text",
                           G_CALLBACK (on_search_text_changed),
                           self,
                           G_CONNECT_SWAPPED);

  g_signal_connect_object (search_settings,
                           "notify::regex-enabled",
                           G_CALLBACK (on_regex_enabled_changed),
                           self,
                           G_CONNECT_SWAPPED);

  g_signal_connect_object (self->replace_entry,
                           "notify::text",
                           G_CALLBACK (on_replace_text_changed),
                           self,
                           G_CONNECT_SWAPPED);

  /* Setup a callback so the replace-confirm action can work properly. */
  self->pending_replace_confirm = 0;
  g_signal_connect_object (self->search_revealer,
                           "notify::child-revealed",
                           G_CALLBACK (search_revealer_on_child_revealed_changed),
                           self,
                           G_CONNECT_SWAPPED);
}