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(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1053 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
d7778ce761
commit
1edaaa3d6c
10
ChangeLog
10
ChangeLog
@ -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@btinternet.com>
|
||||
|
@ -1141,6 +1141,7 @@ on_set_file_readonly1_toggled (GtkCheckMenuItem *checkmenuitem,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -165,27 +165,10 @@ void document_set_text_changed(gint idx)
|
||||
{
|
||||
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 @@ static gint document_create_new_sci(const gchar *filename)
|
||||
{
|
||||
ScintillaObject *sci;
|
||||
PangoFontDescription *pfd;
|
||||
gchar *title, *fname;
|
||||
GtkTreeIter iter;
|
||||
gchar *fname;
|
||||
gint new_idx;
|
||||
document *this;
|
||||
gint tabnum;
|
||||
@ -297,22 +279,6 @@ static gint document_create_new_sci(const gchar *filename)
|
||||
sci_set_line_numbers(sci, app->show_linenumber_margin, 0);
|
||||
sci_set_lines_wrapped(sci, app->pref_editor_line_breaking);
|
||||
|
||||
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));
|
||||
@ -320,7 +286,14 @@ static gint document_create_new_sci(const gchar *filename)
|
||||
g_signal_connect((GtkWidget*) sci, "button-press-event",
|
||||
G_CALLBACK(on_editor_button_press_event), GINT_TO_POINTER(new_idx));
|
||||
|
||||
ui_close_buttons_toggle();
|
||||
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);
|
||||
|
||||
this->tag_store = NULL;
|
||||
this->tag_tree = NULL;
|
||||
|
||||
// store important pointers in the tab list
|
||||
this->file_name = (filename) ? g_strdup(filename) : NULL;
|
||||
@ -328,7 +301,6 @@ static gint document_create_new_sci(const gchar *filename)
|
||||
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 @@ static gint document_create_new_sci(const gchar *filename)
|
||||
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 @@ gboolean document_remove(guint page_num)
|
||||
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 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado
|
||||
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 @@ static void document_redo_add(gint idx, guint type, gpointer data)
|
||||
}
|
||||
|
||||
|
||||
/* 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)
|
||||
|
@ -224,4 +224,7 @@ void document_redo(gint idx);
|
||||
|
||||
void document_undo_add(gint idx, guint type, gpointer data);
|
||||
|
||||
|
||||
GdkColor *document_get_status(gint idx);
|
||||
|
||||
#endif
|
||||
|
@ -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 @@ static void tab_count_changed()
|
||||
}
|
||||
|
||||
|
||||
/* 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 @@ gint notebook_new_tab(gint doc_idx, const gchar *title, GtkWidget *page)
|
||||
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 @@ gint notebook_new_tab(gint doc_idx, const gchar *title, GtkWidget *page)
|
||||
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(app->notebook), page, TRUE);
|
||||
}
|
||||
#endif
|
||||
g_free(title);
|
||||
return tabnum;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -316,45 +316,25 @@ void treeviews_prepare_openfiles()
|
||||
}
|
||||
|
||||
|
||||
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 @@ void treeviews_openfiles_update_all()
|
||||
{
|
||||
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 @@ void treeviews_openfiles_update_all()
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,13 +54,13 @@ void treeviews_init_tag_list(gint idx);
|
||||
|
||||
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();
|
||||
|
||||
|
@ -1160,3 +1160,23 @@ void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,4 +102,7 @@ void ui_hbutton_box_copy_layout(GtkButtonBox *master, GtkButtonBox *copy);
|
||||
|
||||
void ui_combo_box_add_to_history(GtkComboBox *combo, const gchar *text);
|
||||
|
||||
|
||||
void ui_update_tab_status(gint idx);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user