static void present_greeter_with_surface (GSimpleAction *action, GVariant *param, gpointer user_data) { GbpGreeterApplicationAddin *self = user_data; g_autoptr(IdeWorkbench) workbench = NULL; IdeGreeterWorkspace *workspace; const gchar *name; g_assert (!action || G_IS_SIMPLE_ACTION (action)); g_assert (!param || g_variant_is_of_type (param, G_VARIANT_TYPE_STRING)); g_assert (GBP_IS_GREETER_APPLICATION_ADDIN (self)); g_assert (IDE_IS_APPLICATION (self->application)); workbench = ide_workbench_new (); ide_application_add_workbench (self->application, workbench); workspace = ide_greeter_workspace_new (self->application); ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace)); if (param != NULL && (name = g_variant_get_string (param, NULL)) && !ide_str_empty0 (name)) ide_workspace_set_visible_surface_name (IDE_WORKSPACE (workspace), name); ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace)); }
static void gb_project_tree_actions_move_to_trash (GSimpleAction *action, GVariant *param, gpointer user_data) { GbProjectTree *self = user_data; GbWorkbench *workbench; IdeContext *context; IdeProject *project; GbTreeNode *node; GFile *file; GObject *item; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (GB_IS_PROJECT_TREE (self)); workbench = gb_widget_get_workbench (GTK_WIDGET (self)); context = gb_workbench_get_context (workbench); project = ide_context_get_project (context); if (!(node = gb_tree_get_selected (GB_TREE (self))) || !(item = gb_tree_node_get_item (node)) || !IDE_IS_PROJECT_FILE (item) || !(file = ide_project_file_get_file (IDE_PROJECT_FILE (item)))) return; ide_project_trash_file_async (project, file, NULL, gb_project_tree_actions__trash_file_cb, g_object_ref (self)); }
static void gstyle_color_widget_actions_rename (GSimpleAction *action, GVariant *variant, gpointer user_data) { GstyleColorWidget *self = (GstyleColorWidget *)user_data; GtkWidget *popover; GstyleColor *color; const gchar *name; g_assert (GSTYLE_IS_COLOR_WIDGET (self)); g_assert (G_IS_SIMPLE_ACTION (action)); color = gstyle_color_widget_get_color (self); name = gstyle_color_get_name (color); popover = g_object_new (GSTYLE_TYPE_RENAME_POPOVER, "label", _("Color name"), "name", name, "message", _("Enter a new name for the color"), NULL); gtk_popover_set_relative_to (GTK_POPOVER (popover), GTK_WIDGET (self)); g_signal_connect_swapped (popover, "closed", G_CALLBACK (contextual_popover_closed_cb), self); g_signal_connect_swapped (popover, "renamed", G_CALLBACK (rename_popover_entry_renamed_cb), self); gtk_popover_popup (GTK_POPOVER (popover)); }
static void ide_editor_surface_actions_close_all (GSimpleAction *action, GVariant *param, gpointer user_data) { IdeEditorSurface *self = user_data; g_autoptr(GPtrArray) views = NULL; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_SURFACE (self)); /* First collect all the views and hold a reference to them * so that we do not need to worry about contains being destroyed * as we work through the list. */ views = g_ptr_array_new_full (0, g_object_unref); ide_grid_foreach_page (self->grid, collect_pages, views); for (guint i = 0; i < views->len; i++) { IdePage *view = g_ptr_array_index (views, i); /* TODO: Should we allow suspending the close with * agree_to_close_async()? */ gtk_widget_destroy (GTK_WIDGET (view)); } }
static void find_in_files_action (GSimpleAction *action, GVariant *param, gpointer user_data) { GbpGrepTreeAddin *self = user_data; g_autoptr(GFile) file = NULL; IdeProjectFile *project_file; IdeTreeNode *node; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (GBP_IS_GREP_TREE_ADDIN (self)); g_assert (self->tree != NULL); g_assert (IDE_IS_TREE (self->tree)); if ((node = ide_tree_get_selected_node (self->tree)) && ide_tree_node_holds (node, IDE_TYPE_PROJECT_FILE) && (project_file = ide_tree_node_get_item (node)) && (file = ide_project_file_ref_file (project_file))) { gboolean is_dir = ide_project_file_is_directory (project_file); GtkPopover *popover; popover = g_object_new (GBP_TYPE_GREP_POPOVER, "file", file, "is-directory", is_dir, "position", GTK_POS_RIGHT, NULL); g_signal_connect_after (popover, "closed", G_CALLBACK (popover_closed_cb), NULL); ide_tree_show_popover_at_node (self->tree, node, popover); } }
static void gbp_retab_editor_page_addin_action (GSimpleAction *action, GVariant *variant, gpointer user_data) { GbpRetabEditorPageAddin *self = user_data; IdeSourceView *source_view; GtkTextBuffer *buffer; IdeCompletion *completion; guint tab_width; gint start_line; gint end_line; gint indent; GtkTextIter begin; GtkTextIter end; gboolean editable; gboolean to_spaces; g_assert (GBP_IS_RETAB_EDITOR_PAGE_ADDIN (self)); g_assert (G_IS_SIMPLE_ACTION (action)); buffer = GTK_TEXT_BUFFER (ide_editor_page_get_buffer (self->editor_view)); source_view = ide_editor_page_get_view (self->editor_view); g_assert (IDE_IS_SOURCE_VIEW (source_view)); editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (source_view)); completion = ide_source_view_get_completion (IDE_SOURCE_VIEW (source_view)); tab_width = gtk_source_view_get_tab_width(GTK_SOURCE_VIEW (source_view)); to_spaces = gtk_source_view_get_insert_spaces_instead_of_tabs(GTK_SOURCE_VIEW (source_view)); if (!editable) return; gtk_text_buffer_get_selection_bounds (buffer, &begin, &end); gtk_text_iter_order (&begin, &end); if (!gtk_text_iter_equal (&begin, &end) && gtk_text_iter_starts_line (&end)) gtk_text_iter_backward_char (&end); start_line = gtk_text_iter_get_line (&begin); end_line = gtk_text_iter_get_line (&end); ide_completion_block_interactive (completion); gtk_text_buffer_begin_user_action (buffer); for (gint line = start_line; line <= end_line; ++line) { indent = get_buffer_range_indent (buffer, line, to_spaces); if (indent > 0) gbp_retab_editor_page_addin_retab (buffer, line, tab_width, indent, to_spaces); } gtk_text_buffer_end_user_action (buffer); ide_completion_unblock_interactive (completion); }
static void ide_editor_perspective_actions_open_file (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorPerspective *self = user_data; GtkFileChooserNative *chooser; IdeWorkbench *workbench; gint ret; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); if (workbench == NULL) { g_warning ("Failed to locate workbench"); return; } chooser = gtk_file_chooser_native_new (_("Open File"), GTK_WINDOW (workbench), GTK_FILE_CHOOSER_ACTION_OPEN, _("Open"), _("Cancel")); gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), FALSE); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser), TRUE); ret = gtk_native_dialog_run (GTK_NATIVE_DIALOG (chooser)); if (ret == GTK_RESPONSE_ACCEPT) { g_autoptr(GPtrArray) ar = NULL; GSList *files; ar = g_ptr_array_new_with_free_func (g_object_unref); files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (chooser)); for (const GSList *iter = files; iter; iter = iter->next) g_ptr_array_add (ar, iter->data); g_slist_free (files); if (ar->len > 0) ide_workbench_open_files_async (workbench, (GFile **)ar->pdata, ar->len, "editor", IDE_WORKBENCH_OPEN_FLAGS_NONE, NULL, NULL, NULL); } gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser)); }
static void new_window (GSimpleAction *action, GVariant *param, gpointer user_data) { GbpGreeterApplicationAddin *self = user_data; g_assert (!action || G_IS_SIMPLE_ACTION (action)); g_assert (GBP_IS_GREETER_APPLICATION_ADDIN (self)); g_assert (IDE_IS_APPLICATION (self->application)); present_greeter_with_surface (NULL, NULL, self); }
static void clone_repo_cb (GSimpleAction *action, GVariant *param, gpointer user_data) { g_autoptr(GVariant) clone_param = NULL; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (GBP_IS_GREETER_APPLICATION_ADDIN (user_data)); clone_param = g_variant_take_ref (g_variant_new_string ("clone")); present_greeter_with_surface (NULL, clone_param, user_data); }
static void set_tab_state (GSimpleAction *action, GVariant *state, gpointer user_data) { PnlTabStrip *self = user_data; PnlTabStripPrivate *priv = pnl_tab_strip_get_instance_private (self); PnlTab *tab = NULL; const GList *iter; GList *list; gint stateval; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (PNL_IS_TAB_STRIP (self)); g_assert (state != NULL); g_assert (g_variant_is_of_type (state, G_VARIANT_TYPE_INT32)); g_simple_action_set_state (action, state); stateval = g_variant_get_int32 (state); list = gtk_container_get_children (GTK_CONTAINER (priv->stack)); for (iter = list; iter != NULL; iter = iter->next) { GtkWidget *child = iter->data; gint position = 0; gtk_container_child_get (GTK_CONTAINER (priv->stack), GTK_WIDGET (child), "position", &position, NULL); if (position == stateval) { tab = g_object_get_data (G_OBJECT (child), "PNL_TAB"); gtk_stack_set_visible_child (priv->stack, child); break; } } /* * When clicking an active toggle button, we get the state callback but then * the toggle button disables the checked state. So ensure it stays on by * manually setting the state. */ if (PNL_IS_TAB (tab)) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tab), TRUE); g_list_free (list); }
static void gb_editor_view_actions_reveal (GSimpleAction *action, GVariant *param, gpointer user_data) { GbEditorView *self = user_data; GbWorkbench *workbench; IdeFile *file; GFile *gfile; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (GB_IS_EDITOR_VIEW (self)); file = ide_buffer_get_file (IDE_BUFFER (self->document)); gfile = ide_file_get_file (file); workbench = gb_widget_get_workbench (GTK_WIDGET (self)); gb_workbench_reveal_file (workbench, gfile); }
static void ide_primary_workspace_actions_update_dependencies (GSimpleAction *action, GVariant *param, gpointer user_data) { IdePrimaryWorkspace *self = user_data; g_autoptr(PeasExtensionSet) set = NULL; g_autoptr(IdeNotification) notif = NULL; g_autoptr(IdeTask) task = NULL; UpdateDependencies *state; IdeContext *context; g_assert (IDE_IS_MAIN_THREAD ()); g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_PRIMARY_WORKSPACE (self)); context = ide_widget_get_context (GTK_WIDGET (self)); notif = ide_notification_new (); ide_notification_set_title (notif, _("Updating Dependencies…")); ide_notification_set_body (notif, _("Builder is updating your projects configured dependencies.")); ide_notification_set_icon_name (notif, "software-update-available-symbolic"); ide_notification_set_has_progress (notif, TRUE); ide_notification_set_progress_is_imprecise (notif, TRUE); ide_notification_attach (notif, IDE_OBJECT (context)); state = g_slice_new0 (UpdateDependencies); state->n_active = 0; state->notif = g_object_ref (notif); task = ide_task_new (self, NULL, NULL, NULL); ide_task_set_source_tag (task, ide_primary_workspace_actions_update_dependencies); ide_task_set_task_data (task, state, update_dependencies_free); set = peas_extension_set_new (peas_engine_get_default (), IDE_TYPE_DEPENDENCY_UPDATER, NULL); peas_extension_set_foreach (set, ide_primary_workspace_actions_update_dependencies_cb, task); if (state->n_active == 0) ide_task_return_boolean (task, TRUE); }
static void action_set (GActionGroup *group, const gchar *action_name, const gchar *first_param, ...) { GAction *action; va_list args; g_assert (G_IS_ACTION_GROUP (group)); g_assert (G_IS_ACTION_MAP (group)); action = g_action_map_lookup_action (G_ACTION_MAP (group), action_name); g_assert (G_IS_SIMPLE_ACTION (action)); va_start (args, first_param); g_object_set_valist (G_OBJECT (action), first_param, args); va_end (args); }
static void ide_editor_perspective_actions_new_file (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorPerspective *self = user_data; IdeWorkbench *workbench; IdeContext *context; IdeBufferManager *bufmgr; IdeBuffer *buffer; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_PERSPECTIVE (self)); workbench = ide_widget_get_workbench (GTK_WIDGET (self)); context = ide_workbench_get_context (workbench); bufmgr = ide_context_get_buffer_manager (context); buffer = ide_buffer_manager_create_temporary_buffer (bufmgr); g_clear_object (&buffer); }
static void gstyle_color_widget_actions_remove (GSimpleAction *action, GVariant *variant, gpointer user_data) { GstyleColorWidget *self = (GstyleColorWidget *)user_data; GtkWidget *ancestor; GstylePalette *selected_palette; GstyleColor *color; g_assert (GSTYLE_IS_COLOR_WIDGET (self)); g_assert (G_IS_SIMPLE_ACTION (action)); ancestor = gtk_widget_get_ancestor (GTK_WIDGET (self), GSTYLE_TYPE_PALETTE_WIDGET); if (ancestor != NULL) { color = gstyle_color_widget_get_color (self); selected_palette = gstyle_palette_widget_get_selected_palette (GSTYLE_PALETTE_WIDGET (ancestor)); if (selected_palette != NULL && color != NULL) gstyle_palette_remove (selected_palette, color); } }
static void ide_editor_surface_actions_new_file (GSimpleAction *action, GVariant *variant, gpointer user_data) { IdeEditorSurface *self = user_data; IdeBufferManager *bufmgr; IdeContext *context; g_assert (G_IS_SIMPLE_ACTION (action)); g_assert (IDE_IS_EDITOR_SURFACE (self)); context = ide_widget_get_context (GTK_WIDGET (self)); bufmgr = ide_buffer_manager_from_context (context); ide_buffer_manager_load_file_async (bufmgr, NULL, IDE_BUFFER_OPEN_FLAGS_NONE, NULL, NULL, NULL, NULL); }
static void open_project (GSimpleAction *action, GVariant *param, gpointer user_data) { GbpGreeterApplicationAddin *self = user_data; g_autoptr(IdeWorkbench) workbench = NULL; IdeGreeterWorkspace *workspace; g_assert (!action || G_IS_SIMPLE_ACTION (action)); g_assert (!param || g_variant_is_of_type (param, G_VARIANT_TYPE_STRING)); g_assert (GBP_IS_GREETER_APPLICATION_ADDIN (self)); g_assert (IDE_IS_APPLICATION (self->application)); workbench = ide_workbench_new (); ide_application_add_workbench (self->application, workbench); workspace = ide_greeter_workspace_new (self->application); ide_workbench_add_workspace (workbench, IDE_WORKSPACE (workspace)); ide_workbench_focus_workspace (workbench, IDE_WORKSPACE (workspace)); dzl_gtk_widget_action (GTK_WIDGET (workspace), "win", "open", NULL); }