← Back to team overview

gnusim8085-devel team mailing list archive

Tabbed editor interface

 

Hi Everyone,

I have been working on a tabbed interface for the editor for past few days. Is it worth the effort? Does anyone think it will be useful?

I am attaching the patch here of whatever I have achieved till now. The basic interface is ready but some underlying features have to be implemented such as closing a file on closing a tab :P

Thanks,
-- Debjit
=== modified file 'src/callbacks.c'
--- src/callbacks.c	2010-08-17 15:33:32 +0000
+++ src/callbacks.c	2010-08-18 06:23:49 +0000
@@ -634,6 +634,20 @@
 }
 
 void
+on_main_notebook_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data) {
+	if (b_get_state () != B_STATE_DEBUG)
+		gui_app_switch_editor(g_object_get_data(G_OBJECT(gtk_notebook_get_nth_page(notebook, page_num)), "editor"));
+}
+
+void
+close_tab (GtkButton *button, GtkNotebook *notebook) {
+  gint page;
+
+  page = GPOINTER_TO_INT( g_object_get_data( G_OBJECT( button ), "page" ) );
+  gtk_notebook_remove_page( notebook, page );
+}
+
+void
 on_io_list_start_clicked (GtkButton * button, gpointer user_data)
 {
   GtkWidget *start_entry;

=== modified file 'src/callbacks.h'
--- src/callbacks.h	2010-08-17 15:33:32 +0000
+++ src/callbacks.h	2010-08-18 06:26:22 +0000
@@ -128,6 +128,10 @@
 
 G_MODULE_EXPORT void on_mem_list_start_changed (GtkEntry *entry, gpointer user_data);
 
+G_MODULE_EXPORT void on_main_notebook_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data); 
+
+G_MODULE_EXPORT void close_tab (GtkButton *button, GtkNotebook *notebook);
+
 G_MODULE_EXPORT void on_io_list_start_clicked (GtkButton * button, gpointer user_data);
 
 G_MODULE_EXPORT void on_io_list_start_changed (GtkEntry * entry, gpointer user_data);

=== modified file 'src/file-op-gio.c'
--- src/file-op-gio.c	2010-06-22 14:03:39 +0000
+++ src/file-op-gio.c	2010-08-15 22:09:07 +0000
@@ -183,19 +183,21 @@
 \n\
 \n\
 hlt";
-
+/*
   if (gtk_text_buffer_get_modified ((GtkTextBuffer *)app->editor->buffer))
     {
       if (!file_op_confirm_save())
           return;
     }
-  
+*/ 
   if (G_UNLIKELY (file_name))
 	{
 	  g_string_free (file_name, TRUE);
 	  file_name = NULL;
 	}
 
+  gui_app_switch_editor(gui_editor_new ());
+
   /* Set template text */
   gui_editor_set_text (app->editor, template);
   gui_editor_goto_line (app->editor, 11);

=== modified file 'src/file-op.c'
--- src/file-op.c	2010-06-22 14:03:39 +0000
+++ src/file-op.c	2010-08-17 07:31:15 +0000
@@ -74,6 +74,7 @@
 	  g_string_append (gstr, buf);
 	}
 
+	gui_app_switch_editor (gui_editor_new_with_file (fn));
   gui_editor_set_text (app->editor, gstr->str);
   gtk_text_buffer_set_modified ((GtkTextBuffer *)app->editor->buffer, FALSE);
 
@@ -188,19 +189,20 @@
 \n\
 \n\
 hlt";
-
+/*
   if (gtk_text_buffer_get_modified ((GtkTextBuffer *)app->editor->buffer))
     {
       if (!file_op_confirm_save())
           return;
     }
-  
+*/  
   if (G_UNLIKELY (file_name))
 	{
 	  g_string_free (file_name, TRUE);
 	  file_name = NULL;
 	}
-
+	
+  gui_app_switch_editor(gui_editor_new ());
   /* Set template text */
   gui_editor_set_text (app->editor, template);
   gui_editor_goto_line (app->editor, 11);

=== modified file 'src/gui-app.c'
--- src/gui-app.c	2010-06-22 14:03:39 +0000
+++ src/gui-app.c	2010-08-15 22:09:07 +0000
@@ -36,16 +36,13 @@
   app->window_main = create_window_main ();
   gtk_window_maximize (GTK_WINDOW (app->window_main));
 
-  app->editor = gui_editor_new ();
-  gui_editor_show (app->editor);
-
   /* add editor */
-  container = lookup_widget (app->window_main, "main_vbox_center");
+/*  container = lookup_widget (app->window_main, "main_editor_notebook");
   g_assert (container);
 
-  gtk_box_pack_start_defaults (GTK_BOX (container),
+  gtk_container_add (GTK_CONTAINER (container),
 							   app->editor->scroll);
-
+*/
   /* dim */
   //gtk_window_get_size(app->window_main, &w, &h);
 
@@ -92,6 +89,12 @@
 }
 
 void
+gui_app_switch_editor (GUIEditor *editor)
+{
+	app->editor = editor;
+}
+
+void
 gui_app_show_msg (GtkMessageType type, gchar *msg)
 {
   GtkWidget *dialog;

=== modified file 'src/gui-app.h'
--- src/gui-app.h	2010-06-22 14:03:39 +0000
+++ src/gui-app.h	2010-08-15 22:09:07 +0000
@@ -45,6 +45,7 @@
 void gui_app_new (void);
 void gui_app_destroy (void);
 void gui_app_show (void);
+void gui_app_switch_editor (GUIEditor *editor);
 
 extern GUIApp *app;
 

=== modified file 'src/gui-editor.c'
--- src/gui-editor.c	2010-06-22 14:03:39 +0000
+++ src/gui-editor.c	2010-08-19 01:51:26 +0000
@@ -20,6 +20,8 @@
 */
 
 #include "gui-editor.h"
+#include "gui-app.h"
+#include "callbacks.h"
 
 GUIEditor *
 gui_editor_new (void)
@@ -34,13 +36,21 @@
   self->buffer = GTK_SOURCE_BUFFER (gtk_source_buffer_new (NULL));
 
   self->widget = gtk_source_view_new_with_buffer (GTK_SOURCE_BUFFER(self->buffer));
-
   self->scroll = gtk_scrolled_window_new (NULL, NULL);
 
   gtk_container_add (GTK_CONTAINER (self->scroll), self->widget);
+  GtkWidget *container = lookup_widget (app->window_main, "main_editor_notebook");
+  g_assert (container);
 
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (self->scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
+  gint page_num = gtk_notebook_append_page (GTK_NOTEBOOK(container), self->scroll, NULL);	
+  g_assert(page_num > -1);
+	gtk_notebook_set_tab_label (GTK_NOTEBOOK(container), self->scroll, gui_editor_create_tab_label (_("Untitled"), container, page_num));
+	gtk_notebook_set_scrollable (GTK_NOTEBOOK(container), TRUE);
+	g_object_set_data (G_OBJECT(self->scroll), "editor", self);
+
+  gtk_widget_draw(GTK_WIDGET(container), NULL);
   gui_editor_set_font (self, DEFAULT_EDITOR_FONT);
 
   self->hltag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER(self->buffer),
@@ -85,10 +95,24 @@
 #endif
 	  g_object_unref (pixbuf);
 	}
+	gui_editor_show (self);
+	gtk_notebook_set_current_page (GTK_NOTEBOOK(container), page_num);
 
   return self;
 }
 
+GUIEditor *
+gui_editor_new_with_file (gchar * fn)
+{
+	GUIEditor *self  = gui_editor_new ();
+  GtkWidget *container = lookup_widget (app->window_main, "main_editor_notebook");
+  g_assert (container);
+	gchar *file = g_strrstr (fn, "/");
+	gint page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK(container));
+	gtk_notebook_set_tab_label (GTK_NOTEBOOK(container), self->scroll,gui_editor_create_tab_label (++file, container, page_num));
+	return self;
+}
+
 void
 gui_editor_show (GUIEditor * self)
 {
@@ -373,3 +397,34 @@
   return pixbuf;
 }
 
+GtkWidget *
+gui_editor_create_tab_label (const gchar * text, GtkWidget *notebook, gint page) {
+	GtkWidget *hbox, *label, *button, *image;
+	GtkRcStyle *style;
+
+	hbox = gtk_hbox_new (FALSE, 3);
+	label = gtk_label_new (text);
+	gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+	
+	button = gtk_button_new();
+  gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
+  gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+  GTK_WIDGET_UNSET_FLAGS (button, GTK_CAN_DEFAULT | GTK_CAN_FOCUS);
+  gtk_widget_set_tooltip_text (button, _("Close this tab"));
+  g_object_set_data( G_OBJECT( button ), "page", GINT_TO_POINTER( page ) );
+  g_signal_connect( G_OBJECT( button ), "clicked",
+                    G_CALLBACK( close_tab ),
+                    GTK_NOTEBOOK( notebook ) );
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+	style = gtk_rc_style_new ();
+	style->xthickness = style->ythickness = 0;
+	gtk_widget_modify_style (button, style);
+	g_object_unref (G_OBJECT(style));
+	
+  image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
+  gtk_container_add (GTK_CONTAINER (button), image);
+
+  gtk_widget_show_all( hbox );
+
+  return( hbox ); 
+}

=== modified file 'src/gui-editor.h'
--- src/gui-editor.h	2010-06-22 14:03:39 +0000
+++ src/gui-editor.h	2010-08-18 06:14:24 +0000
@@ -44,6 +44,7 @@
 #define MARKER_BREAKPOINT   (const gchar*) "breakpoint"
 #define HIGHLIGHT_TAG   (const gchar*) "hl_tag"
 #define COLOUR_BG_HL   (const gchar*) "#00FFFF"
+#define MAX_TABS	256
 
 G_BEGIN_DECLS typedef struct
 {
@@ -71,6 +72,7 @@
 } GUIEditor;
 
 GUIEditor *gui_editor_new (void);
+GUIEditor *gui_editor_new_with_file (gchar * fn);
 void gui_editor_show (GUIEditor * self);
 void gui_editor_destroy (GUIEditor * self);
 
@@ -106,5 +108,8 @@
 GdkPixbuf *
 gui_editor_get_stock_icon (GtkWidget *widget, const gchar *stock_id, GtkIconSize size);
 
+GtkWidget *
+gui_editor_create_tab_label (const gchar * text, GtkWidget *notebook, gint page);
+
 G_END_DECLS
 #endif /* __GUI_EDITOR_H__ */

=== modified file 'src/interface.c'
--- src/interface.c	2010-08-17 15:33:32 +0000
+++ src/interface.c	2010-08-18 05:41:59 +0000
@@ -273,6 +273,7 @@
   GtkWidget *main_progressbar;
   GtkWidget *main_statusbar;
   GtkWidget *status_box;
+  GtkWidget *main_editor_notebook;
   GtkWidget *main_memory_frame;
   GtkWidget *label177;
   GtkWidget *label178;
@@ -859,6 +860,10 @@
   hbox24 = gtk_hbox_new (FALSE, 0);
   gtk_widget_show (hbox24);
   gtk_box_pack_start (GTK_BOX (main_vbox_center), hbox24, FALSE, FALSE, 5);
+  
+  main_editor_notebook = gtk_notebook_new ();
+  gtk_widget_show (main_editor_notebook);
+  gtk_box_pack_start (GTK_BOX (main_vbox_center), main_editor_notebook, TRUE, TRUE, 5);
 
   label147 = gtk_label_new (_("Load me at"));
   gtk_widget_show (label147);
@@ -1095,6 +1100,10 @@
                     G_CALLBACK (on_io_list_start_changed),
                     NULL);
 
+  g_signal_connect ((gpointer) main_editor_notebook, "switch-page",
+                    G_CALLBACK (on_main_notebook_switch_page),
+                    NULL);
+
   /* Store pointers to all widgets, for use by lookup_widget(). */
   GLADE_HOOKUP_OBJECT_NO_REF (window_main, window_main, "window_main");
   GLADE_HOOKUP_OBJECT (window_main, vbox1, "vbox1");
@@ -1196,6 +1205,7 @@
   GLADE_HOOKUP_OBJECT (window_main, main_vpaned_data, "main_vpaned_data");
   GLADE_HOOKUP_OBJECT (window_main, main_vbox_center, "main_vbox_center");
   GLADE_HOOKUP_OBJECT (window_main, hbox24, "hbox24");
+  GLADE_HOOKUP_OBJECT (window_main, main_editor_notebook, "main_editor_notebook");
   GLADE_HOOKUP_OBJECT (window_main, label147, "label147");
   GLADE_HOOKUP_OBJECT (window_main, main_entry_sa, "main_entry_sa");
   GLADE_HOOKUP_OBJECT (window_main, notebook5, "notebook5");


Follow ups