SF.net SVN: geany: [1053] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Tue Dec 5 10:37:36 UTC 2006
Revision: 1053
http://svn.sourceforge.net/geany/?rev=1053&view=rev
Author: ntrel
Date: 2006-12-05 02:37:36 -0800 (Tue, 05 Dec 2006)
Log Message:
-----------
Show read-only notebook tabs in green.
Add document_get_status() to get the tab colour for the document.
Use ui_update_tab_status() to update notebook tabs and open files
treeview items.
Avoid using GtkTreeIter struct as treeviews function arguments.
Remove unneeded arguments for treeviews_openfiles_add(),
notebook_new_tab().
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/document.c
trunk/src/document.h
trunk/src/notebook.c
trunk/src/notebook.h
trunk/src/treeviews.c
trunk/src/treeviews.h
trunk/src/ui_utils.c
trunk/src/ui_utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/ChangeLog 2006-12-05 10:37:36 UTC (rev 1053)
@@ -2,6 +2,16 @@
* src/socket.c:
Prevent Valgrind warning with unlink(NULL).
+ * src/ui_utils.h, src/treeviews.c, src/callbacks.c, src/notebook.c,
+ src/treeviews.h, src/notebook.h, src/document.c, src/document.h,
+ src/ui_utils.c:
+ Show read-only notebook tabs in green.
+ Add document_get_status() to get the tab colour for the document.
+ Use ui_update_tab_status() to update notebook tabs and open files
+ treeview items.
+ Avoid using GtkTreeIter struct as treeviews function arguments.
+ Remove unneeded arguments for treeviews_openfiles_add(),
+ notebook_new_tab().
2006-12-04 Nick Treleaven <nick.treleaven at btinternet.com>
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/callbacks.c 2006-12-05 10:37:36 UTC (rev 1053)
@@ -1141,6 +1141,7 @@
if (idx == -1 || ! doc_list[idx].is_valid) return;
doc_list[idx].readonly = ! doc_list[idx].readonly;
sci_set_readonly(doc_list[idx].sci, doc_list[idx].readonly);
+ ui_update_tab_status(idx);
ui_update_statusbar(idx, -1);
}
}
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/document.c 2006-12-05 10:37:36 UTC (rev 1053)
@@ -165,27 +165,10 @@
{
if (DOC_IDX_VALID(idx) && ! app->quitting)
{
- // changes the colour of the tab text according to the status
- static GdkColor red = {0, 65535, 0, 0};
- static GtkStyle *style = NULL;
-
- if (style == NULL) // use and store default foreground colour
- style = gtk_rc_get_style(doc_list[idx].tab_label);
-
- gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_NORMAL,
- (doc_list[idx].changed) ? &red : &(style->fg[GTK_STATE_NORMAL]));
- gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_ACTIVE,
- (doc_list[idx].changed) ? &red : &(style->fg[GTK_STATE_ACTIVE]));
-
+ ui_update_tab_status(idx);
ui_save_buttons_toggle(doc_list[idx].changed);
ui_set_window_title(idx);
ui_update_statusbar(idx, -1);
- if (doc_list[idx].file_name != NULL)
- {
- gchar *basename = g_path_get_basename(doc_list[idx].file_name);
- treeviews_openfiles_update(doc_list[idx].iter, basename, doc_list[idx].changed);
- g_free(basename);
- }
}
}
@@ -251,8 +234,7 @@
{
ScintillaObject *sci;
PangoFontDescription *pfd;
- gchar *title, *fname;
- GtkTreeIter iter;
+ gchar *fname;
gint new_idx;
document *this;
gint tabnum;
@@ -297,38 +279,28 @@
sci_set_line_numbers(sci, app->show_linenumber_margin, 0);
sci_set_lines_wrapped(sci, app->pref_editor_line_breaking);
+ // signal for insert-key(works without too, but to update the right status bar)
+/* g_signal_connect((GtkWidget*) sci, "key-press-event",
+ G_CALLBACK(keybindings_got_event), GINT_TO_POINTER(new_idx));
+*/ // signal for the popup menu
+ g_signal_connect((GtkWidget*) sci, "button-press-event",
+ G_CALLBACK(on_editor_button_press_event), GINT_TO_POINTER(new_idx));
+
pfd = pango_font_description_from_string(app->editor_font);
fname = g_strdup_printf("!%s", pango_font_description_get_family(pfd));
document_set_font(new_idx, fname, pango_font_description_get_size(pfd) / PANGO_SCALE);
pango_font_description_free(pfd);
g_free(fname);
- title = (filename) ? g_path_get_basename(filename) : g_strdup(GEANY_STRING_UNTITLED);
- tabnum = notebook_new_tab(new_idx, title, GTK_WIDGET(sci));
- gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), tabnum);
-
- iter = treeviews_openfiles_add(new_idx, title, FALSE);
- g_free(title);
-
this->tag_store = NULL;
this->tag_tree = NULL;
- // signal for insert-key(works without too, but to update the right status bar)
-/* g_signal_connect((GtkWidget*) sci, "key-press-event",
- G_CALLBACK(keybindings_got_event), GINT_TO_POINTER(new_idx));
-*/ // signal for the popup menu
- g_signal_connect((GtkWidget*) sci, "button-press-event",
- G_CALLBACK(on_editor_button_press_event), GINT_TO_POINTER(new_idx));
-
- ui_close_buttons_toggle();
-
// store important pointers in the tab list
this->file_name = (filename) ? g_strdup(filename) : NULL;
this->encoding = NULL;
this->saved_encoding.encoding = NULL;
this->saved_encoding.has_bom = FALSE;
this->tm_file = NULL;
- this->iter = iter;
this->file_type = NULL;
this->mtime = 0;
this->changed = FALSE;
@@ -338,8 +310,15 @@
this->line_breaking = app->pref_editor_line_breaking;
this->use_auto_indention = app->pref_editor_use_auto_indention;
this->has_tags = FALSE;
- this->is_valid = TRUE;
+ treeviews_openfiles_add(new_idx); // sets this->iter
+
+ tabnum = notebook_new_tab(new_idx);
+ gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), tabnum);
+
+ ui_close_buttons_toggle();
+
+ this->is_valid = TRUE; // do this last to prevent UI updating with NULL items.
g_assert(doc_list[new_idx].sci == sci);
return new_idx;
}
@@ -357,12 +336,7 @@
return FALSE;
}
notebook_remove_page(page_num);
- treeviews_openfiles_remove(doc_list[idx].iter);
- if (GTK_IS_WIDGET(doc_list[idx].tag_tree))
- {
- //g_object_unref(doc_list[idx].tag_tree); // no need to unref when destroying?
- gtk_widget_destroy(doc_list[idx].tag_tree);
- }
+ treeviews_remove_document(idx);
msgwin_status_add(_("File %s closed."), DOC_FILENAME(idx));
g_free(doc_list[idx].encoding);
g_free(doc_list[idx].saved_encoding.encoding);
@@ -736,8 +710,8 @@
document_undo_clear(idx);
}
- document_set_text_changed(idx);
- ui_document_show_hide(idx); //update the document menu
+ document_set_text_changed(idx); // also updates tab state
+ ui_document_show_hide(idx); // update the document menu
g_free(data);
@@ -1805,6 +1779,23 @@
}
+/* Gets the status colour of the document, or NULL if default widget
+ * colouring should be used. */
+GdkColor *document_get_status(gint idx)
+{
+ static GdkColor red = {0, 0xFFFF, 0, 0};
+ static GdkColor green = {0, 0, 0x7FFF, 0};
+ GdkColor *color = NULL;
+
+ if (doc_list[idx].changed)
+ color = &red;
+ else if (doc_list[idx].readonly)
+ color = &green;
+
+ return color; // return pointer to static GdkColor.
+}
+
+
// useful debugging function (usually debug macros aren't enabled)
#ifdef GEANY_DEBUG
document *doc(gint idx)
Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/document.h 2006-12-05 10:37:36 UTC (rev 1053)
@@ -224,4 +224,7 @@
void document_undo_add(gint idx, guint type, gpointer data);
+
+GdkColor *document_get_status(gint idx);
+
#endif
Modified: trunk/src/notebook.c
===================================================================
--- trunk/src/notebook.c 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/notebook.c 2006-12-05 10:37:36 UTC (rev 1053)
@@ -26,6 +26,7 @@
#include "document.h"
#include "ui_utils.h"
#include "treeviews.h"
+#include "support.h"
#define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab"
@@ -294,16 +295,21 @@
}
-/* Returns index of notebook page, or -1 on error */
-gint notebook_new_tab(gint doc_idx, const gchar *title, GtkWidget *page)
+/* Returns page number of notebook page, or -1 on error */
+gint notebook_new_tab(gint doc_idx)
{
GtkWidget *hbox, *but;
GtkWidget *align;
gint tabnum;
+ gchar *title;
document *this = &(doc_list[doc_idx]);
+ GtkWidget *page;
g_return_val_if_fail(doc_idx >= 0 && this != NULL, -1);
+ page = GTK_WIDGET(this->sci);
+ title = g_path_get_basename(DOC_FILENAME(doc_idx));
+
this->tab_label = gtk_label_new(title);
hbox = gtk_hbox_new(FALSE, 0);
@@ -325,11 +331,11 @@
gtk_misc_set_alignment(GTK_MISC(this->tabmenu_label), 0.0, 0);
if (app->tab_order_ltr)
- tabnum = gtk_notebook_append_page_menu(GTK_NOTEBOOK(app->notebook),
- GTK_WIDGET(page), hbox, this->tabmenu_label);
+ tabnum = gtk_notebook_append_page_menu(GTK_NOTEBOOK(app->notebook), page,
+ hbox, this->tabmenu_label);
else
- tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(app->notebook),
- GTK_WIDGET(page), hbox, this->tabmenu_label, 0);
+ tabnum = gtk_notebook_insert_page_menu(GTK_NOTEBOOK(app->notebook), page,
+ hbox, this->tabmenu_label, 0);
tab_count_changed();
@@ -344,6 +350,7 @@
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(app->notebook), page, TRUE);
}
#endif
+ g_free(title);
return tabnum;
}
Modified: trunk/src/notebook.h
===================================================================
--- trunk/src/notebook.h 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/notebook.h 2006-12-05 10:37:36 UTC (rev 1053)
@@ -26,8 +26,8 @@
void notebook_init();
-/* Returns index of notebook page, or -1 on error */
-gint notebook_new_tab(gint doc_idx, const gchar *title, GtkWidget *page);
+/* Returns page number of notebook page, or -1 on error */
+gint notebook_new_tab(gint doc_idx);
// Always use this instead of gtk_notebook_remove_page().
void notebook_remove_page(gint page_num);
Modified: trunk/src/treeviews.c
===================================================================
--- trunk/src/treeviews.c 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/treeviews.c 2006-12-05 10:37:36 UTC (rev 1053)
@@ -316,45 +316,25 @@
}
-GtkTreeIter treeviews_openfiles_add(gint idx, const gchar *string, gboolean changed)
+// Also sets doc_list[idx].iter.
+void treeviews_openfiles_add(gint idx)
{
- GtkTreeIter iter;
- static GdkColor black = {0, 0, 0, 0};
- static GdkColor red = {0, 65535, 0, 0};
- GdkColor *colour;
+ GtkTreeIter *iter = &doc_list[idx].iter;
- if (changed)
- colour = &red;
- else
- colour = &black;
-
-
- gtk_list_store_append(tv.store_openfiles, &iter);
- gtk_list_store_set(tv.store_openfiles, &iter, 0, string, 1, idx, 2, colour, -1);
-
- return iter;
+ gtk_list_store_append(tv.store_openfiles, iter);
+ treeviews_openfiles_update(idx);
}
-// I think this wrapper function is useful
-void treeviews_openfiles_remove(GtkTreeIter iter)
+void treeviews_openfiles_update(gint idx)
{
- gtk_list_store_remove(tv.store_openfiles, &iter);
-}
+ gchar *basename;
+ GdkColor *color = document_get_status(idx);
-
-void treeviews_openfiles_update(GtkTreeIter iter, const gchar *string, gboolean changed)
-{
- static GdkColor black = {0, 0, 0, 0};
- static GdkColor red = {0, 65535, 0, 0};
- GdkColor *colour;
-
- if (changed)
- colour = &red;
- else
- colour = &black;
-
- gtk_list_store_set(tv.store_openfiles, &iter, 0, string, 2, colour, -1);
+ basename = g_path_get_basename(DOC_FILENAME(idx));
+ gtk_list_store_set(tv.store_openfiles, &doc_list[idx].iter,
+ 0, basename, 1, idx, 2, color, -1);
+ g_free(basename);
}
@@ -362,7 +342,6 @@
{
guint i;
gint idx;
- gchar *shortname;
gtk_list_store_clear(tv.store_openfiles);
for (i = 0; i < (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)); i++)
@@ -370,13 +349,20 @@
idx = document_get_n_idx(i);
if (! doc_list[idx].is_valid) continue;
- if (doc_list[idx].file_name == NULL)
- shortname = g_strdup(GEANY_STRING_UNTITLED);
- else
- shortname = g_path_get_basename(doc_list[idx].file_name);
+ treeviews_openfiles_add(idx);
+ }
+}
- doc_list[idx].iter = treeviews_openfiles_add(idx, shortname, doc_list[idx].changed);
- g_free(shortname);
+
+void treeviews_remove_document(gint idx)
+{
+ GtkTreeIter *iter = &doc_list[idx].iter;
+
+ gtk_list_store_remove(tv.store_openfiles, iter);
+
+ if (GTK_IS_WIDGET(doc_list[idx].tag_tree))
+ {
+ gtk_widget_destroy(doc_list[idx].tag_tree);
}
}
Modified: trunk/src/treeviews.h
===================================================================
--- trunk/src/treeviews.h 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/treeviews.h 2006-12-05 10:37:36 UTC (rev 1053)
@@ -54,13 +54,13 @@
void treeviews_prepare_openfiles();
-GtkTreeIter treeviews_openfiles_add(gint idx, const gchar *string, gboolean changed);
+void treeviews_openfiles_add(gint idx);
-void treeviews_openfiles_update(GtkTreeIter iter, const gchar *string, gboolean changed);
+void treeviews_openfiles_update(gint idx);
void treeviews_openfiles_update_all();
-void treeviews_openfiles_remove(GtkTreeIter iter);
+void treeviews_remove_document(gint idx);
void treeviews_create_openfiles_popup_menu();
Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/ui_utils.c 2006-12-05 10:37:36 UTC (rev 1053)
@@ -1160,3 +1160,23 @@
gtk_tree_path_free(path);
}
+
+/* Changes the color of the notebook tab text and open files items according to
+ * document status. */
+void ui_update_tab_status(gint idx)
+{
+ GdkColor *color = document_get_status(idx);
+ static GtkStyle *style = NULL;
+
+ if (style == NULL) // use and store default foreground colour
+ style = gtk_rc_get_style(doc_list[idx].tab_label);
+
+ gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_NORMAL,
+ color ? color : &(style->fg[GTK_STATE_NORMAL]));
+ gtk_widget_modify_fg(doc_list[idx].tab_label, GTK_STATE_ACTIVE,
+ color ? color : &(style->fg[GTK_STATE_ACTIVE]));
+
+ treeviews_openfiles_update(idx);
+}
+
+
Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h 2006-12-05 10:23:51 UTC (rev 1052)
+++ trunk/src/ui_utils.h 2006-12-05 10:37:36 UTC (rev 1053)
@@ -102,4 +102,7 @@
void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text);
+
+void ui_update_tab_status(gint idx);
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list