[Kazehakase-cvs] CVS update: kazehakase/src

Zurück zum Archiv-Index

Hiroyuki Ikezoe ikezo****@users*****
Wed Jan 3 22:41:42 JST 2007


Index: kazehakase/src/kz-notebook.c
diff -u kazehakase/src/kz-notebook.c:1.3 kazehakase/src/kz-notebook.c:1.4
--- kazehakase/src/kz-notebook.c:1.3	Wed Jan  3 22:03:07 2007
+++ kazehakase/src/kz-notebook.c	Wed Jan  3 22:41:42 2007
@@ -49,17 +49,6 @@
 	{ "STRING",          0, TARGET_STRING}
 };
 
-static struct {
-	const gchar *pos;
-	const gchar *tab_act;
-	const gchar *sidebar_act;
-} positems[] = {
-	{"top",    "TabPosTop",    "SidebarPosTop"},
-	{"bottom", "TabPosBottom", "SidebarPosBottom"},
-	{"left",   "TabPosLeft",   "SidebarPosLeft"},
-	{"right",  "TabPosRight",  "SidebarPosRight"},
-};
-
 typedef struct _KzNotebookPrivate	KzNotebookPrivate;
 struct _KzNotebookPrivate
 {
@@ -355,3 +344,168 @@
 		GTK_NOTEBOOK_CLASS(kz_notebook_parent_class)->switch_page(notebook, page, page_num);
 }
 
+static gint 
+get_insert_tab_position (KzNotebook *notebook)
+{
+	gchar pos_str[256];
+	gint pos = -1;
+
+	KZ_CONF_GET("Tab", "new_tab_position", pos_str, STRING);
+	
+	if (!pos_str || !strcasecmp(pos_str, "last"))
+	{
+		pos = -1;
+	}
+	else if (!strcasecmp(pos_str, "first"))
+	{
+		pos = 0;
+	}
+	else if (!strcasecmp(pos_str, "left"))
+	{
+		pos = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
+	}
+	else if (!strcasecmp(pos_str, "right"))
+	{
+		pos = 1 + gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
+	}
+	else if (!strcasecmp(pos_str, "unread_right"))
+	{
+		gint i = 1 + gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
+		gint num = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));
+		
+		if (i > num)
+		{
+			pos = -1;
+		}
+		else
+		{
+			while (i < num)
+			{
+				GtkWidget *kzembed;
+				GtkWidget *label;
+				KzTabLabelState state;
+
+				kzembed = GTK_WIDGET(gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), i));
+				label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),
+								   kzembed);
+				state = kz_tab_label_get_state(KZ_TAB_LABEL(label));
+				if (state == KZ_TAB_LABEL_STATE_NORMAL)
+					break;
+				i++;
+			}
+			pos = i;
+		}
+	}
+
+	return pos;
+}
+
+KzTabLabel *
+kz_notebook_open_new_tab (KzNotebook *notebook, KzEmbed *embed, KzTabLabel *label)
+{
+	gint pos;
+	GtkWidget *sibembed;
+	KzTabLabel *sibtab;
+
+	pos = get_insert_tab_position (notebook);
+
+	gtk_notebook_insert_page(GTK_NOTEBOOK(notebook),
+				 GTK_WIDGET(embed),
+				 GTK_WIDGET(label),
+				 pos);			
+	sibembed = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), pos);
+	sibtab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),
+			      sibembed));
+
+	return sibtab;
+}
+
+gboolean
+kz_notebook_close_tab (KzNotebook *notebook, GtkWidget *widget)
+{
+	gchar *ret_page = NULL;
+	KzTabLabel *kztab = NULL;
+	KzWindow *kz = notebook->kz;
+	GtkWidget *next = NULL;
+	kztab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),
+							widget));
+	GtkWidget *current = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
+						       gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)));
+
+	if (kztab && kz_tab_label_get_lock(kztab))
+	{
+		/* kztab is locked, so return without closing tab */
+		return FALSE;
+	}
+	else if (current != widget)
+	{
+		/* close tab which is not current , so there is nothing to consider */
+		goto CLOSE_TAB;
+	}
+
+	ret_page = KZ_CONF_GET_STR("Tab", "page_to_return_when_close");
+	if (ret_page && !strcmp(ret_page, "last_shown"))
+	{
+		GList *node;
+		const GList *list;
+		
+		list = kz_window_get_view_history(kz);
+		if (list &&
+		    (node = g_list_next(list)))
+		{
+			next = node->data;
+		}
+	}
+	else if (ret_page && !strcmp(ret_page, "last_created"))
+	{
+		const GList *node;
+
+		node = kz_window_get_open_history(kz);
+		for (; node && !next; node = g_list_next(node))
+		{
+			if (current != node->data)
+				next = node->data;
+		}
+	}
+	else if (ret_page && !strcmp(ret_page, "prev_tab"))
+	{
+		gtk_notebook_prev_page(GTK_NOTEBOOK(notebook));
+	}
+	else if (ret_page && !strcmp(ret_page, "next_tab"))
+	{
+		gtk_notebook_next_page(GTK_NOTEBOOK(notebook));
+	}
+
+	if (next)
+	{
+		gint num;
+
+		num = gtk_notebook_page_num
+			(GTK_NOTEBOOK(notebook),
+			 GTK_WIDGET(next));
+		gtk_notebook_set_current_page
+			(GTK_NOTEBOOK(notebook), num);
+	}
+CLOSE_TAB:
+	g_free(ret_page);
+	gtk_widget_destroy(widget);
+
+	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)) == 0)
+		gtk_window_set_title(GTK_WINDOW(kz), _("Kazehakase"));
+	return TRUE;
+}
+
+gboolean
+kz_notebook_close_all_tab (KzNotebook *notebook)
+{
+	gint n_pages, i;
+
+	n_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));
+	for (i = n_pages - 1; i >= 0; i--)
+	{
+		GtkWidget *widget = gtk_notebook_get_nth_page(notebook, i);
+		gtk_widget_destroy(widget);
+	}
+	return TRUE;
+}
+
Index: kazehakase/src/kz-notebook.h
diff -u kazehakase/src/kz-notebook.h:1.1 kazehakase/src/kz-notebook.h:1.2
--- kazehakase/src/kz-notebook.h:1.1	Wed Jan  3 09:40:53 2007
+++ kazehakase/src/kz-notebook.h	Wed Jan  3 22:41:42 2007
@@ -30,8 +30,11 @@
 	GtkNotebookClass parent_class;
 };
 
-GType      kz_notebook_get_type          (void) G_GNUC_CONST;
-GtkWidget *kz_notebook_new               (KzWindow *kz);
+GType       kz_notebook_get_type          (void) G_GNUC_CONST;
+GtkWidget  *kz_notebook_new               (KzWindow *kz);
+KzTabLabel *kz_notebook_open_new_tab	  (KzNotebook *notebook, KzEmbed *embed, KzTabLabel *label);
+gboolean    kz_notebook_close_tab	  (KzNotebook *notebook, GtkWidget *widget);
+gboolean    kz_notebook_close_all_tab     (KzNotebook *notebook);
 
 G_END_DECLS
 
Index: kazehakase/src/kz-window.c
diff -u kazehakase/src/kz-window.c:1.292 kazehakase/src/kz-window.c:1.293
--- kazehakase/src/kz-window.c:1.292	Wed Jan  3 22:03:07 2007
+++ kazehakase/src/kz-window.c	Wed Jan  3 22:41:42 2007
@@ -897,72 +897,14 @@
 	return GTK_WIDGET(kzembed);
 }
 
-static gint 
-get_insert_tab_position (KzWindow *kz)
-{
-	gchar pos_str[256];
-	gint pos = -1;
-
-	KZ_CONF_GET("Tab", "new_tab_position", pos_str, STRING);
-	
-	if (!pos_str || !strcasecmp(pos_str, "last"))
-	{
-		pos = -1;
-	}
-	else if (!strcasecmp(pos_str, "first"))
-	{
-		pos = 0;
-	}
-	else if (!strcasecmp(pos_str, "left"))
-	{
-		pos = gtk_notebook_get_current_page(GTK_NOTEBOOK(kz->notebook));
-	}
-	else if (!strcasecmp(pos_str, "right"))
-	{
-		pos = 1 + gtk_notebook_get_current_page(GTK_NOTEBOOK(kz->notebook));
-	}
-	else if (!strcasecmp(pos_str, "unread_right"))
-	{
-		gint i = 1 + gtk_notebook_get_current_page(GTK_NOTEBOOK(kz->notebook));
-		gint num = gtk_notebook_get_n_pages(GTK_NOTEBOOK(kz->notebook));
-		
-		if (i > num)
-		{
-			pos = -1;
-		}
-		else
-		{
-			while (i < num)
-			{
-				GtkWidget *kzembed;
-				GtkWidget *label;
-				KzTabLabelState state;
-
-				kzembed = GTK_WIDGET(KZ_WINDOW_NTH_PAGE(kz, i));
-				label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(kz->notebook),
-								   kzembed);
-				state = kz_tab_label_get_state(KZ_TAB_LABEL(label));
-				if (state == KZ_TAB_LABEL_STATE_NORMAL)
-					break;
-				i++;
-			}
-			pos = i;
-		}
-	}
-
-	return pos;
-}
-
 
 GtkWidget *
 kz_window_open_new_tab_with_parent (KzWindow *kz, const gchar *url,
 				    GtkWidget *parent)
 {
 	KzEmbed *kzembed;
-	GtkWidget *sibembed;
 	KzTabLabel *kztab, *sibtab;
 	GNode *node, *parent_node;
-	gint pos;
 	KzWindowPrivate *priv;
 	
 	g_return_val_if_fail(KZ_IS_WINDOW(kz), NULL);
@@ -975,18 +917,8 @@
 	gtk_widget_show(GTK_WIDGET(kzembed));
 	gtk_widget_show(GTK_WIDGET(kztab));
 
-	pos = get_insert_tab_position (kz);
-
-	gtk_notebook_insert_page(GTK_NOTEBOOK(kz->notebook),
-				 GTK_WIDGET(kzembed),
-				 GTK_WIDGET (kztab),
-				 pos);			
-
+	sibtab = kz_notebook_open_new_tab(KZ_NOTEBOOK(kz->notebook), kzembed, kztab);
 	/* insert tab bookmark */
-	sibembed = gtk_notebook_get_nth_page(GTK_NOTEBOOK(kz->notebook), pos);
-	sibtab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(kz->notebook),
-			      sibembed));
-
 	kz_bookmark_insert_before(kz->tabs, 
 				  kztab->history,
 				  sibtab->history);
@@ -1019,92 +951,20 @@
 void
 kz_window_close_tab (KzWindow *kz, GtkWidget *widget)
 {
-	gchar *ret_page = NULL;
-	KzEmbed *next = NULL;
-	KzTabLabel *kztab = NULL;
-	KzWindowPrivate *priv;
-	
 	g_return_if_fail(KZ_IS_WINDOW(kz));
 	g_return_if_fail(GTK_IS_WIDGET(widget));
 
-	priv = KZ_WINDOW_GET_PRIVATE (kz);
-	kztab = KZ_TAB_LABEL(gtk_notebook_get_tab_label(GTK_NOTEBOOK(kz->notebook),
-							widget));
-	if (kztab && kz_tab_label_get_lock(kztab)) {
-/* kztab is locked, so return without closing tab */
-		return;
-
-	} else if (KZ_WINDOW_CURRENT_PAGE(kz) != widget) {
-/* close tab which is not current , so there is nothing to consider */
-		goto CLOSE_TAB;
-
-	}
-
-	ret_page = KZ_CONF_GET_STR("Tab", "page_to_return_when_close");
-	if (ret_page && !strcmp(ret_page, "last_shown"))
-	{
-		GList *node;
-
-		if (priv->view_hist &&
-		    (node = g_list_next(priv->view_hist)))
-		{
-			next = node->data;
-		}
-	}
-	else if (ret_page && !strcmp(ret_page, "last_created"))
-	{
-		GList *node;
-
-		node = priv->open_hist;
-		for (; node && !next; node = g_list_next(node))
-		{
-			if (KZ_WINDOW_CURRENT_PAGE(kz) != node->data)
-				next = node->data;
-		}
-	}
-	else if (ret_page && !strcmp(ret_page, "prev_tab"))
-	{
-		gtk_notebook_prev_page(GTK_NOTEBOOK(kz->notebook));
-	}
-	else if (ret_page && !strcmp(ret_page, "next_tab"))
-	{
-		gtk_notebook_next_page(GTK_NOTEBOOK(kz->notebook));
-	}
-
-	if (next)
-	{
-		gint num;
-
-		num = gtk_notebook_page_num
-			(GTK_NOTEBOOK(kz->notebook),
-			 GTK_WIDGET(next));
-		gtk_notebook_set_current_page
-			(GTK_NOTEBOOK(kz->notebook), num);
-	}
-
-CLOSE_TAB:
-	g_free(ret_page);
-	gtk_widget_destroy(widget);
-
-	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(kz->notebook)) == 0)
-		gtk_window_set_title(GTK_WINDOW(kz), _("Kazehakase"));
+	kz_notebook_close_tab(KZ_NOTEBOOK(kz->notebook), widget);
 }
 
 
 void
 kz_window_close_all_tab(KzWindow *kz)
 {
-	gint n_pages, i;
-
 	g_return_if_fail(KZ_IS_WINDOW(kz));
 
 	kz_session_freeze(KZ_SESSION(KZ_GET_CURRENT_SESSION));
-	n_pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(kz->notebook));
-	for (i = n_pages - 1; i >= 0; i--)
-	{
-		GtkWidget *widget = GTK_WIDGET(KZ_WINDOW_NTH_PAGE(kz, i));
-		gtk_widget_destroy(widget);
-	}
+	kz_notebook_close_all_tab(KZ_NOTEBOOK(kz->notebook));
 	kz_session_thaw(KZ_SESSION(KZ_GET_CURRENT_SESSION));
 }
 
@@ -2953,3 +2813,14 @@
 	}
 }
 
+const GList *
+kz_window_get_view_history (KzWindow *kz)
+{
+	return KZ_WINDOW_GET_PRIVATE(kz)->view_hist;
+}
+
+const GList *
+kz_window_get_open_history (KzWindow *kz)
+{
+	return KZ_WINDOW_GET_PRIVATE(kz)->open_hist;
+}
Index: kazehakase/src/kz-window.h
diff -u kazehakase/src/kz-window.h:1.73 kazehakase/src/kz-window.h:1.74
--- kazehakase/src/kz-window.h:1.73	Tue Jan  2 09:30:42 2007
+++ kazehakase/src/kz-window.h	Wed Jan  3 22:41:42 2007
@@ -136,6 +136,8 @@
 						      const gchar *name);
 gboolean          kz_window_activate_tabpop_action   (KzWindow    *kz,
 						      const gchar *name);
+const GList      *kz_window_get_view_history	     (KzWindow    *kz);
+const GList      *kz_window_get_open_history	     (KzWindow    *kz);
 
 const KzEmbedEventMouse *
 		  kz_window_get_mouse_event_info     (KzWindow    *kz);


More information about the Kazehakase-cvs mailing list
Zurück zum Archiv-Index