void ide_workbench_remove_perspective (IdeWorkbench *self, IdePerspective *perspective) { guint n_items; guint i; g_assert (IDE_IS_WORKBENCH (self)); g_assert (IDE_IS_PERSPECTIVE (perspective)); g_assert (gtk_widget_get_parent (GTK_WIDGET (perspective)) == GTK_WIDGET (self->perspectives_stack)); n_items = g_list_model_get_n_items (G_LIST_MODEL (self->perspectives)); for (i = 0; i < n_items; i++) { g_autoptr(IdePerspective) item = NULL; item = g_list_model_get_item (G_LIST_MODEL (self->perspectives), i); if (item == perspective) { g_list_store_remove (self->perspectives, i); break; } } gtk_container_remove (GTK_CONTAINER (self->perspectives_stack), GTK_WIDGET (perspective)); }
gint ide_perspective_get_priority (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), 0); return IDE_PERSPECTIVE_GET_IFACE (self)->get_priority (self); }
void ide_workbench_set_visible_perspective (IdeWorkbench *self, IdePerspective *perspective) { GActionGroup *actions; GtkStack *stack; gchar *id; g_return_if_fail (IDE_IS_WORKBENCH (self)); g_return_if_fail (IDE_IS_PERSPECTIVE (perspective)); stack = GTK_STACK (gtk_widget_get_ancestor (GTK_WIDGET (perspective), GTK_TYPE_STACK)); id = ide_perspective_get_id (perspective); if (!ide_str_equal0 (gtk_stack_get_visible_child_name (stack), id)) { gtk_stack_set_visible_child_name (stack, id); gtk_stack_set_visible_child_name (self->titlebar_stack, id); } g_free (id); actions = ide_perspective_get_actions (perspective); gtk_widget_insert_action_group (GTK_WIDGET (self), "perspective", actions); if ((stack == self->perspectives_stack) && !ide_str_equal0 (gtk_stack_get_visible_child_name (self->top_stack), "perspectives")) { gtk_stack_set_visible_child_name (self->top_stack, "perspectives"); g_timeout_add (1000 + gtk_stack_get_transition_duration (self->top_stack), remove_early_perspectives, g_object_ref (self)); } }
/** * ide_perspective_get_id: * @self: An #IdePerspective * * This interface method is used to identify the perspective. It should be a short * internal name, such as "editor" which should not be translated. Internally, the * default implementation of this method will return the name of the instances #GType. * * This value should be unique per workspace. * * Returns: (nullable): A string identifier for the perspective. */ gchar * ide_perspective_get_id (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), NULL); return IDE_PERSPECTIVE_GET_IFACE (self)->get_id (self); }
/** * ide_perspective_get_titlebar: * @self: An #IdePerspective. * * This interface method should return a #GtkWidget suitable for being embedded as the * titlebar for the application. If you return %NULL from this method, a suitable titlebar * will be created for you. * * You may use #IdeHeaderBar for a base implementation to save you the trouble of * creating a titlebar similar to other perspectives in Builder. * * Returns: (transfer none) (nullable): A #GtkWidget or %NULL. */ GtkWidget * ide_perspective_get_titlebar (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), NULL); return IDE_PERSPECTIVE_GET_IFACE (self)->get_titlebar (self); }
/** * ide_perspective_get_actions: * @self: An #IdePerspective. * * This interface method should retrieve a #GActionGroup associated with the * perspective, if necessary. The #GActionGroup will automatically be * registered with the "perspective" action prefix while the perspective is * active. A perspective is "active" when it is currently displayed in the * workbench. * * Returns: (nullable) (transfer full): A #GActionGroup or %NULL. */ GActionGroup * ide_perspective_get_actions (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), NULL); return IDE_PERSPECTIVE_GET_IFACE (self)->get_actions (self); }
/** * ide_perspective_get_needs_attention: * @self: An #IdePerspective. * * This interface method returns %TRUE if the interface needs attention. * * One such use of this would be to indicate that contents within a perspective have * changed since the user last focused the perspective. This should also be implemented * with a boolean property named "needs-attention". If you call g_object_notify() (or one * of its variants), the notifcation visual will be rendered with your icon. * * Returns: %TRUE if the perspective needs attention. */ gboolean ide_perspective_get_needs_attention (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), FALSE); return IDE_PERSPECTIVE_GET_IFACE (self)->get_needs_attention (self); }
/** * ide_perspective_agree_to_shutdown: * @self: An #IdePerspective. * * This interface method is called when the workbench would like to shutdown. * If the perspective needs to focus and ask the user a question, this is the place * to do so. You may run a #GtkDialog using gtk_dialog_run() or simply focus your * perspective and return %FALSE. * * Returns: %TRUE to allow the workbench to continue shutting down. */ gboolean ide_perspective_agree_to_shutdown (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), FALSE); return IDE_PERSPECTIVE_GET_IFACE (self)->agree_to_shutdown (self); }
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); } }
/** * ide_perspective_set_fullscreen: * @self: An #IdePerspective. * @fullscreen: If fullscreen mode should be activated. * * This interface method is used to notify the perspective that it is going into * fullscreen mode. The #IdeWorkbench will notify the perspective before it is displayed. */ void ide_perspective_set_fullscreen (IdePerspective *self, gboolean fullscreen) { g_return_if_fail (IDE_IS_PERSPECTIVE (self)); IDE_PERSPECTIVE_GET_IFACE (self)->set_fullscreen (self, fullscreen); }
/** * ide_perspective_is_early: * * If %TRUE, the perspective can be used before loading a project. */ gboolean ide_perspective_is_early (IdePerspective *self) { g_return_val_if_fail (IDE_IS_PERSPECTIVE (self), FALSE); if (IDE_PERSPECTIVE_GET_IFACE (self)->is_early) return IDE_PERSPECTIVE_GET_IFACE (self)->is_early (self); return FALSE; }
/** * ide_perspective_views_foreach: * @self: An #IdePerspective. * @callback: (scope call): A #GtkCallback. * @user_data: user data for @callback. * * This interface method is used to iterate all #IdeLayoutView's that are descendents of @self. */ void ide_perspective_views_foreach (IdePerspective *self, GtkCallback callback, gpointer user_data) { g_return_if_fail (IDE_IS_PERSPECTIVE (self)); g_return_if_fail (callback != NULL); IDE_PERSPECTIVE_GET_IFACE (self)->views_foreach (self, callback, user_data); }
/** * ide_workbench_get_visible_perspective: * @self: An #IdeWorkbench. * * Gets the current perspective. * * Returns: (transfer none): An #IdePerspective. */ IdePerspective * ide_workbench_get_visible_perspective (IdeWorkbench *self) { GtkWidget *visible_child; g_return_val_if_fail (IDE_IS_WORKBENCH (self), NULL); visible_child = gtk_stack_get_visible_child (self->top_stack); if (IDE_IS_PERSPECTIVE (visible_child)) return IDE_PERSPECTIVE (visible_child); return IDE_PERSPECTIVE (gtk_stack_get_visible_child (self->perspectives_stack)); }
static void ide_workbench_views_foreach_cb (GtkWidget *widget, gpointer user_data) { struct { GtkCallback callback; gpointer user_data; } *closure = user_data; g_assert (IDE_IS_PERSPECTIVE (widget)); g_assert (closure != NULL); g_assert (closure->callback != NULL); ide_perspective_views_foreach (IDE_PERSPECTIVE (widget), closure->callback, closure->user_data); }
static void ide_workbench_notify_perspective_set (PeasExtensionSet *set, PeasPluginInfo *plugin_info, PeasExtension *exten, gpointer user_data) { IdeWorkbenchAddin *addin = (IdeWorkbenchAddin *)exten; IdePerspective *perspective = user_data; g_assert (PEAS_IS_EXTENSION_SET (set)); g_assert (plugin_info != NULL); g_assert (IDE_IS_WORKBENCH_ADDIN (addin)); g_assert (IDE_IS_PERSPECTIVE (perspective)); ide_workbench_addin_perspective_set (addin, perspective); }
void ide_workbench_remove_perspective (IdeWorkbench *self, IdePerspective *perspective) { const gchar *id; GtkWidget *titlebar; g_assert (IDE_IS_WORKBENCH (self)); g_assert (IDE_IS_PERSPECTIVE (perspective)); g_assert (gtk_widget_get_parent (GTK_WIDGET (perspective)) == GTK_WIDGET (self->perspectives_stack)); id = ide_perspective_get_id (perspective); titlebar = gtk_stack_get_child_by_name (self->titlebar_stack, id); gtk_container_remove (GTK_CONTAINER (self->titlebar_stack), titlebar); gtk_container_remove (GTK_CONTAINER (self->perspectives_stack), GTK_WIDGET (perspective)); }
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); }
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); } }
static void ide_workbench_show_parents (GtkWidget *widget) { GtkWidget *parent; g_assert (GTK_IS_WIDGET (widget)); parent = gtk_widget_get_parent (widget); if (IDE_IS_LAYOUT_PANE (widget)) pnl_dock_revealer_set_reveal_child (PNL_DOCK_REVEALER (widget), TRUE); if (IDE_IS_PERSPECTIVE (widget)) ide_workbench_set_visible_perspective (ide_widget_get_workbench (widget), IDE_PERSPECTIVE (widget)); if (GTK_IS_STACK (parent)) gtk_stack_set_visible_child (GTK_STACK (parent), widget); if (parent != NULL) ide_workbench_show_parents (parent); }
void ide_workbench_set_visible_perspective (IdeWorkbench *self, IdePerspective *perspective) { g_autofree gchar *id = NULL; GActionGroup *actions = NULL; const gchar *current_id; GtkWidget *titlebar; guint restore_duration = 0; g_return_if_fail (IDE_IS_WORKBENCH (self)); g_return_if_fail (IDE_IS_PERSPECTIVE (perspective)); /* * If we can detect that this is the first transition to the editor, * and that our window is not yet displayed, we can avoid the transition * duration altogether. This is handy when first opening a window with * a project loaded, as used by self->disable_greeter. */ if (self->disable_greeter && IDE_IS_EDITOR_PERSPECTIVE (perspective) && !self->did_initial_editor_transition) { self->did_initial_editor_transition = TRUE; restore_duration = gtk_stack_get_transition_duration (self->perspectives_stack); gtk_stack_set_transition_duration (self->perspectives_stack, 0); } current_id = gtk_stack_get_visible_child_name (self->perspectives_stack); id = ide_perspective_get_id (perspective); if (!ide_str_equal0 (current_id, id)) gtk_stack_set_visible_child_name (self->perspectives_stack, id); titlebar = gtk_stack_get_child_by_name (self->header_stack, id); if (titlebar != NULL) gtk_stack_set_visible_child (self->header_stack, titlebar); else gtk_stack_set_visible_child (self->header_stack, GTK_WIDGET (self->header_bar)); actions = ide_perspective_get_actions (perspective); gtk_widget_insert_action_group (GTK_WIDGET (self), "perspective", actions); /* * If we are transitioning to the editor the first time, we can * remove the early perspectives (greeter, etc). */ if (IDE_IS_EDITOR_PERSPECTIVE (perspective)) remove_early_perspectives (self); gtk_widget_set_visible (GTK_WIDGET (self->perspective_menu_button), !ide_perspective_is_early (perspective)); if (self->addins != NULL) peas_extension_set_foreach (self->addins, ide_workbench_notify_perspective_set, perspective); g_clear_object (&actions); if (restore_duration != 0) gtk_stack_set_transition_duration (self->perspectives_stack, restore_duration); /* Notify the application to possibly update actions such * as the preferences state. */ ide_application_actions_update (IDE_APPLICATION_DEFAULT); }