static void
gb_view_stack_hierarchy_changed (GtkWidget *widget,
                                 GtkWidget *old_toplevel)
{
  GbViewStack *self = (GbViewStack *)widget;
  GtkWidget *toplevel;

  g_assert (GB_IS_VIEW_STACK (self));

  if (GB_IS_WORKBENCH (old_toplevel))
    {
      g_signal_handlers_disconnect_by_func (old_toplevel,
                                            G_CALLBACK (gb_view_stack_on_workbench_unload),
                                            self);
    }

  toplevel = gtk_widget_get_toplevel (widget);

  if (GB_IS_WORKBENCH (toplevel))
    {
      g_signal_connect (toplevel,
                        "unload",
                        G_CALLBACK (gb_view_stack_on_workbench_unload),
                        self);
    }
}
static void
gb_command_provider_set_workbench (GbCommandProvider *provider,
                                   GbWorkbench       *workbench)
{
  GbCommandProviderPrivate *priv = gb_command_provider_get_instance_private (provider);

  g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider));
  g_return_if_fail (!workbench || GB_IS_WORKBENCH (workbench));

  if (priv->workbench != workbench)
    {
      if (priv->workbench)
        {
          gb_command_provider_disconnect (provider, workbench);
          g_object_remove_weak_pointer (G_OBJECT (priv->workbench),
                                        (gpointer *)&priv->workbench);
          priv->workbench = NULL;
        }

      if (workbench)
        {
          priv->workbench = workbench;
          g_object_add_weak_pointer (G_OBJECT (priv->workbench),
                                     (gpointer *)&priv->workbench);
          gb_command_provider_connect (provider, workbench);
        }

      g_object_notify_by_pspec (G_OBJECT (provider),
                                gParamSpecs [PROP_WORKBENCH]);
  }
}
Beispiel #3
0
/**
 * gb_widget_get_workbench:
 *
 * Returns: (transfer none) (type GbWorkbench*): A #GbWorkbench or %NULL.
 */
GbWorkbench *
gb_widget_get_workbench (GtkWidget *widget)
{
    GtkWidget *toplevel;

    g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);

    if (GB_IS_WORKBENCH (widget))
        return GB_WORKBENCH (widget);

    toplevel = gtk_widget_get_toplevel (widget);

    if (GB_IS_WORKBENCH (toplevel))
        return GB_WORKBENCH (toplevel);

    return NULL;
}
static void
gb_terminal_respawn (GbTerminalView *self,
                     VteTerminal    *terminal)
{
  g_autoptr(GPtrArray) args = NULL;
  g_autofree gchar *workpath = NULL;
  GtkWidget *toplevel;
  GError *error = NULL;
  IdeContext *context;
  IdeVcs *vcs;
  GFile *workdir;
  GPid child_pid;
  gint64 now;

  g_assert (GB_IS_TERMINAL_VIEW (self));

  vte_terminal_reset (terminal, TRUE, TRUE);

  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
  if (!GB_IS_WORKBENCH (toplevel))
    return;

  /* Prevent flapping */
  now = g_get_monotonic_time ();
  if ((now - self->last_respawn) < (G_USEC_PER_SEC / 10))
    return;
  self->last_respawn = now;

  context = gb_workbench_get_context (GB_WORKBENCH (toplevel));
  vcs = ide_context_get_vcs (context);
  workdir = ide_vcs_get_working_directory (vcs);
  workpath = g_file_get_path (workdir);

  args = g_ptr_array_new_with_free_func (g_free);
  g_ptr_array_add (args, vte_get_user_shell ());
  g_ptr_array_add (args, NULL);

  vte_terminal_spawn_sync (terminal,
                           VTE_PTY_DEFAULT | VTE_PTY_NO_LASTLOG | VTE_PTY_NO_UTMP | VTE_PTY_NO_WTMP,
                           workpath,
                           (gchar **)args->pdata,
                           NULL,
                           G_SPAWN_DEFAULT,
                           NULL,
                           NULL,
                           &child_pid,
                           NULL,
                           &error);

  if (error != NULL)
    {
      g_warning ("%s", error->message);
      g_clear_error (&error);
      return;
    }

  vte_terminal_watch_child (terminal, child_pid);
}
static void
gb_command_provider_disconnect (GbCommandProvider *provider,
                                GbWorkbench       *workbench)
{
  g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider));
  g_return_if_fail (GB_IS_WORKBENCH (workbench));

  g_signal_handlers_disconnect_by_func (workbench,
                                        G_CALLBACK (on_workbench_set_focus),
                                        provider);
}
static void
gb_command_provider_connect (GbCommandProvider *provider,
                             GbWorkbench       *workbench)
{
  g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider));
  g_return_if_fail (GB_IS_WORKBENCH (workbench));

  g_signal_connect_object (workbench,
                           "set-focus",
                           G_CALLBACK (on_workbench_set_focus),
                           provider,
                           G_CONNECT_SWAPPED);
}
static void
gb_view_stack_on_workbench_unload (GbWorkbench *workbench,
                                   IdeContext  *context,
                                   GbViewStack *self)
{
  IdeBackForwardList *back_forward_list;

  g_assert (GB_IS_WORKBENCH (workbench));
  g_assert (IDE_IS_CONTEXT (context));
  g_assert (GB_IS_VIEW_STACK (self));

  if (self->back_forward_list)
    {
      back_forward_list = ide_context_get_back_forward_list (context);
      ide_back_forward_list_merge (back_forward_list, self->back_forward_list);
    }
}
static void
on_workbench_set_focus (GbCommandProvider *provider,
                        GtkWidget         *widget,
                        GbWorkbench       *workbench)
{
  g_return_if_fail (GB_IS_COMMAND_PROVIDER (provider));
  g_return_if_fail (GB_IS_WORKBENCH (workbench));
  g_return_if_fail (!widget || GTK_IS_WIDGET (widget));

  /* walk the hierarchy to find a tab */
  if (widget)
    while (!GB_IS_VIEW (widget))
      if (!(widget = gtk_widget_get_parent (widget)))
        break;

  if (GB_IS_VIEW (widget))
    gb_command_provider_set_active_view (provider,
                                         GB_VIEW (widget));
}
static void
gb_search_box_workbench_set_focus (GbSearchBox *self,
                                   GtkWidget   *focus,
                                   GbWorkbench *workbench)
{
  g_return_if_fail (GB_IS_SEARCH_BOX (self));
  g_return_if_fail (!focus || GTK_IS_WIDGET (focus));
  g_return_if_fail (GB_IS_WORKBENCH (workbench));

  if (!focus ||
      (!gtk_widget_is_ancestor (focus, GTK_WIDGET (self)) &&
       !gtk_widget_is_ancestor (focus, GTK_WIDGET (self->popover))))
    {
      gtk_entry_set_text (GTK_ENTRY (self->entry), "");
    }
  else
    {
      gb_search_box_popover_set_visible (self, TRUE);
    }
}
static void
gb_project_tree_actions_open (GSimpleAction *action,
                              GVariant      *variant,
                              gpointer       user_data)
{
  GbProjectTree *self = user_data;
  GbWorkbench *workbench;
  GbTreeNode *selected;
  GObject *item;

  g_assert (GB_IS_PROJECT_TREE (self));

  workbench = gb_widget_get_workbench (GTK_WIDGET (self));
  g_assert (GB_IS_WORKBENCH (workbench));

  if (!(selected = gb_tree_get_selected (GB_TREE (self))) ||
      !(item = gb_tree_node_get_item (selected)))
    return;

  item = gb_tree_node_get_item (selected);

  if (IDE_IS_PROJECT_FILE (item))
    {
      GFileInfo *file_info;
      GFile *file;

      file_info = ide_project_file_get_file_info (IDE_PROJECT_FILE (item));
      if (!file_info)
        return;

      if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_DIRECTORY)
        return;

      file = ide_project_file_get_file (IDE_PROJECT_FILE (item));
      if (!file)
        return;

      gb_workbench_open (workbench, file);
    }
}
static void
gb_search_box_map (GtkWidget *widget)
{
  GbSearchBox *self = (GbSearchBox *)widget;
  GtkWidget *toplevel;

  g_return_if_fail (GB_IS_SEARCH_BOX (self));

  GTK_WIDGET_CLASS (gb_search_box_parent_class)->map (widget);

  gtk_widget_set_sensitive (GTK_WIDGET (self->button), FALSE);
  toplevel = gtk_widget_get_toplevel (widget);

  if (GB_IS_WORKBENCH (toplevel))
    {
      gb_set_weak_pointer (toplevel, &self->workbench);
      self->set_focus_handler =
        g_signal_connect_object (toplevel,
                                 "set-focus",
                                 G_CALLBACK (gb_search_box_workbench_set_focus),
                                 self,
                                 G_CONNECT_SWAPPED | G_CONNECT_AFTER);
    }
}