void
gdict_sidebar_remove_page (GdictSidebar *sidebar,
			   const gchar  *page_id)
{
  GdictSidebarPrivate *priv;
  SidebarPage *page;
  GList *children, *l;
  
  g_return_if_fail (GDICT_IS_SIDEBAR (sidebar));
  g_return_if_fail (page_id != NULL);

  priv = sidebar->priv;
  
  if ((page = g_hash_table_lookup (priv->pages_by_id, page_id)) == NULL)
    {
      g_warning ("Attempting to remove a page from the sidebar with "
		 "id `%s', but there is no page with this id. Aborting...",
		 page_id);
      return;
    }

  children = gtk_container_get_children (GTK_CONTAINER (priv->menu));
  for (l = children; l != NULL; l = l->next)
    {
      GtkWidget *menu_item = l->data;

      if (menu_item == page->menu_item)
        {
          gtk_container_remove (GTK_CONTAINER (priv->menu), menu_item);
	  break;
	}
    }
  g_list_free (children);

  gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), page->index);

  g_hash_table_remove (priv->pages_by_id, page->id);
  priv->pages = g_slist_remove (priv->pages, page);

  sidebar_page_free (page);

  /* select the first page, if present */
  page = priv->pages->data;
  if (page)
    {
      if (gtk_widget_get_realized (priv->menu))
        gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->menu),
                                    page->menu_item);
      gtk_label_set_text (GTK_LABEL (priv->label), page->name);
      gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page->index);
    }
  else
    gtk_widget_hide (GTK_WIDGET (sidebar));
}
void
gdict_sidebar_add_page (GdictSidebar *sidebar,
			const gchar  *page_id,
			const gchar  *page_name,
			GtkWidget    *page_widget)
{
  GdictSidebarPrivate *priv;
  SidebarPage *page;
  GtkWidget *menu_item;
  
  g_return_if_fail (GDICT_IS_SIDEBAR (sidebar));
  g_return_if_fail (page_id != NULL);
  g_return_if_fail (page_name != NULL);
  g_return_if_fail (GTK_IS_WIDGET (page_widget));

  priv = sidebar->priv;
  
  if (g_hash_table_lookup (priv->pages_by_id, page_id))
    {
      g_warning ("Attempting to add a page to the sidebar with "
		 "id `%s', but there already is a page with the "
		 "same id.  Aborting...",
		 page_id);
      return;
    }

  /* add the page inside the page list */
  page = sidebar_page_new (page_id, page_name, page_widget);
  
  priv->pages = g_slist_append (priv->pages, page);
  g_hash_table_insert (priv->pages_by_id, page->id, page);

  page->index = gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
		  			  page_widget,
					  NULL);

  /* add the menu item for the page */
  menu_item = gtk_image_menu_item_new_with_label (page_name);
  g_object_set_qdata_full (G_OBJECT (menu_item),
			   sidebar_page_id_quark,
                           g_strdup (page_id),
			   (GDestroyNotify) g_free);
  g_signal_connect (menu_item, "activate",
		    G_CALLBACK (gdict_sidebar_menu_item_activate),
		    sidebar);
  gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), menu_item);
  gtk_widget_show (menu_item);
  page->menu_item = menu_item;

  if (gtk_widget_get_realized (priv->menu))
    gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->menu), menu_item);
  gtk_label_set_text (GTK_LABEL (priv->label), page_name);
  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page->index);
}
Beispiel #3
0
const gchar *
gdict_sidebar_current_page (GdictSidebar *sidebar)
{
  GdictSidebarPrivate *priv;
  gint index;
  SidebarPage *page;

  g_return_val_if_fail (GDICT_IS_SIDEBAR (sidebar), NULL);

  priv = sidebar->priv;

  index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
  page = g_slist_nth_data (priv->pages, index);
  g_assert (page != NULL);

  return page->id;
}
Beispiel #4
0
void
gdict_sidebar_view_page (GdictSidebar *sidebar,
			 const gchar  *page_id)
{
  GdictSidebarPrivate *priv;
  SidebarPage *page;

  g_return_if_fail (GDICT_IS_SIDEBAR (sidebar));
  g_return_if_fail (page_id != NULL);

  priv = sidebar->priv;
  page = g_hash_table_lookup (priv->pages_by_id, page_id);
  if (!page)
    return;

  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), page->index);
  gtk_label_set_text (GTK_LABEL (priv->label), page->name);
  gtk_menu_shell_select_item (GTK_MENU_SHELL (priv->menu), page->menu_item);
}