Fix memory leaks when using GdkPixbuf, PangoFontDescription and some
strings. Capitalize main window title. Add ui_widget_modify_font_from_string(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1089 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
ad37f83878
commit
533d61fb68
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
2006-12-13 Nick Treleaven <nick.treleaven@btinternet.com>
|
||||
|
||||
* src/ui_utils.h, src/about.c, src/treeviews.c, src/msgwindow.c,
|
||||
src/callbacks.c, src/keyfile.c, src/document.c, src/prefs.c,
|
||||
src/main.c, src/ui_utils.c:
|
||||
Fix memory leaks when using GdkPixbuf, PangoFontDescription and some
|
||||
strings.
|
||||
Capitalize main window title.
|
||||
Add ui_widget_modify_font_from_string().
|
||||
|
||||
|
||||
2006-12-12 Enrico Tröger <enrico.troeger@uvena.de>
|
||||
|
||||
* src/document.c, src/geany.h, src/keyfile.c, src/sciwrappers.c,
|
||||
|
@ -148,6 +148,7 @@ static GtkWidget *create_dialog(void)
|
||||
icon = ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE);
|
||||
gtk_image_set_from_pixbuf(GTK_IMAGE(header_image), icon);
|
||||
gtk_window_set_icon(GTK_WINDOW(dialog), icon);
|
||||
g_object_unref(icon); // free our reference
|
||||
|
||||
// create notebook
|
||||
notebook = gtk_notebook_new();
|
||||
|
@ -1592,7 +1592,11 @@ on_insert_date_activate (GtkMenuItem *menuitem,
|
||||
else
|
||||
{
|
||||
// set default value
|
||||
if (utils_str_equal("", app->custom_date_format)) app->custom_date_format = g_strdup("%d.%m.%Y");
|
||||
if (utils_str_equal("", app->custom_date_format))
|
||||
{
|
||||
g_free(app->custom_date_format);
|
||||
app->custom_date_format = g_strdup("%d.%m.%Y");
|
||||
}
|
||||
|
||||
dialogs_show_input(_("Custom Date Format"),
|
||||
_("Enter here a custom date and time format. You can use any conversion specifiers which can be used with the ANSI C strftime function. See \"man strftime\" for more information."),
|
||||
|
@ -676,7 +676,7 @@ int document_open_file(gint idx, const gchar *filename, gint pos, gboolean reado
|
||||
|
||||
doc_list[idx].mtime = st.st_mtime; // get the modification time from file and keep it
|
||||
doc_list[idx].changed = FALSE;
|
||||
doc_list[idx].file_name = g_strdup(utf8_filename);
|
||||
g_free(doc_list[idx].encoding); // if reloading, free old encoding
|
||||
doc_list[idx].encoding = enc;
|
||||
doc_list[idx].has_bom = bom;
|
||||
store_saved_encoding(idx); // store the opened encoding for undo/redo
|
||||
|
@ -700,6 +700,8 @@ void configuration_read_filetype_extensions()
|
||||
else g_strfreev(list);
|
||||
}
|
||||
|
||||
g_free(sysconfigfile);
|
||||
g_free(userconfigfile);
|
||||
g_key_file_free(sysconfig);
|
||||
g_key_file_free(userconfig);
|
||||
}
|
||||
|
12
src/main.c
12
src/main.c
@ -550,7 +550,14 @@ gint main(gint argc, gchar **argv)
|
||||
#endif
|
||||
configuration_read_filetype_extensions();
|
||||
|
||||
gtk_window_set_icon(GTK_WINDOW(app->window), ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE));
|
||||
// set window icon
|
||||
{
|
||||
GdkPixbuf *pb;
|
||||
|
||||
pb = ui_new_pixbuf_from_inline(GEANY_IMAGE_LOGO, FALSE);
|
||||
gtk_window_set_icon(GTK_WINDOW(app->window), pb);
|
||||
g_object_unref(pb); // free our reference
|
||||
}
|
||||
|
||||
// registering some basic events
|
||||
g_signal_connect(G_OBJECT(app->window), "delete_event", G_CALLBACK(on_exit_clicked), NULL);
|
||||
@ -680,6 +687,7 @@ void main_quit()
|
||||
g_free(app->configdir);
|
||||
g_free(app->datadir);
|
||||
g_free(app->docdir);
|
||||
g_free(app->custom_date_format);
|
||||
g_free(app->editor_font);
|
||||
g_free(app->tagbar_font);
|
||||
g_free(app->msgwin_font);
|
||||
@ -692,6 +700,8 @@ void main_quit()
|
||||
g_free(app->tools_make_cmd);
|
||||
g_free(app->tools_term_cmd);
|
||||
g_free(app->tools_browser_cmd);
|
||||
g_free(app->tools_print_cmd);
|
||||
g_free(app->tools_grep_cmd);
|
||||
while (! g_queue_is_empty(app->recent_queue))
|
||||
{
|
||||
g_free(g_queue_pop_tail(app->recent_queue));
|
||||
|
@ -83,6 +83,7 @@ void msgwin_prepare_status_tree_view(void)
|
||||
{
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
PangoFontDescription *pfd;
|
||||
|
||||
msgwindow.store_status = gtk_list_store_new(2, GDK_TYPE_COLOR, G_TYPE_STRING);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(msgwindow.tree_status), GTK_TREE_MODEL(msgwindow.store_status));
|
||||
@ -93,7 +94,10 @@ void msgwin_prepare_status_tree_view(void)
|
||||
|
||||
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(msgwindow.tree_status), FALSE);
|
||||
|
||||
gtk_widget_modify_font(msgwindow.tree_status, pango_font_description_from_string(app->msgwin_font));
|
||||
pfd = pango_font_description_from_string(app->msgwin_font);
|
||||
gtk_widget_modify_font(msgwindow.tree_status, pfd);
|
||||
pango_font_description_free(pfd);
|
||||
|
||||
g_signal_connect(G_OBJECT(msgwindow.tree_status), "button-press-event",
|
||||
G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_STATUS));
|
||||
|
||||
@ -107,6 +111,7 @@ void msgwin_prepare_msg_tree_view(void)
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeSelection *select;
|
||||
PangoFontDescription *pfd;
|
||||
|
||||
msgwindow.store_msg = gtk_list_store_new(4, G_TYPE_INT, G_TYPE_INT, GDK_TYPE_COLOR, G_TYPE_STRING);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(msgwindow.tree_msg), GTK_TREE_MODEL(msgwindow.store_msg));
|
||||
@ -117,7 +122,10 @@ void msgwin_prepare_msg_tree_view(void)
|
||||
|
||||
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(msgwindow.tree_msg), FALSE);
|
||||
|
||||
gtk_widget_modify_font(msgwindow.tree_msg, pango_font_description_from_string(app->msgwin_font));
|
||||
pfd = pango_font_description_from_string(app->msgwin_font);
|
||||
gtk_widget_modify_font(msgwindow.tree_msg, pfd);
|
||||
pango_font_description_free(pfd);
|
||||
|
||||
// use button-release-event so the selection has changed (connect_after button-press-event doesn't work)
|
||||
g_signal_connect(G_OBJECT(msgwindow.tree_msg), "button-release-event",
|
||||
G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_MESSAGE));
|
||||
@ -135,6 +143,7 @@ void msgwin_prepare_compiler_tree_view(void)
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeSelection *select;
|
||||
PangoFontDescription *pfd;
|
||||
|
||||
msgwindow.store_compiler = gtk_list_store_new(2, GDK_TYPE_COLOR, G_TYPE_STRING);
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(msgwindow.tree_compiler), GTK_TREE_MODEL(msgwindow.store_compiler));
|
||||
@ -145,7 +154,10 @@ void msgwin_prepare_compiler_tree_view(void)
|
||||
|
||||
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(msgwindow.tree_compiler), FALSE);
|
||||
|
||||
gtk_widget_modify_font(msgwindow.tree_compiler, pango_font_description_from_string(app->msgwin_font));
|
||||
pfd = pango_font_description_from_string(app->msgwin_font);
|
||||
gtk_widget_modify_font(msgwindow.tree_compiler, pfd);
|
||||
pango_font_description_free(pfd);
|
||||
|
||||
// use button-release-event so the selection has changed (connect_after button-press-event doesn't work)
|
||||
g_signal_connect(G_OBJECT(msgwindow.tree_compiler), "button-release-event",
|
||||
G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_COMPILER));
|
||||
|
20
src/prefs.c
20
src/prefs.c
@ -726,14 +726,13 @@ void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
|
||||
for (i = 0; i < doc_array->len; i++)
|
||||
{
|
||||
if (doc_list[i].is_valid && GTK_IS_WIDGET(doc_list[i].tag_tree))
|
||||
gtk_widget_modify_font(doc_list[i].tag_tree,
|
||||
pango_font_description_from_string(app->tagbar_font));
|
||||
ui_widget_modify_font_from_string(doc_list[i].tag_tree,
|
||||
app->tagbar_font);
|
||||
}
|
||||
if (GTK_IS_WIDGET(app->default_tag_tree))
|
||||
gtk_widget_modify_font(app->default_tag_tree,
|
||||
pango_font_description_from_string(app->tagbar_font));
|
||||
gtk_widget_modify_font(lookup_widget(app->window, "entry1"),
|
||||
pango_font_description_from_string(app->tagbar_font));
|
||||
ui_widget_modify_font_from_string(app->default_tag_tree, app->tagbar_font);
|
||||
ui_widget_modify_font_from_string(lookup_widget(app->window, "entry1"),
|
||||
app->tagbar_font);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
@ -741,12 +740,9 @@ void on_prefs_font_choosed(GtkFontButton *widget, gpointer user_data)
|
||||
if (strcmp(fontbtn, app->msgwin_font) == 0) break;
|
||||
g_free(app->msgwin_font);
|
||||
app->msgwin_font = g_strdup(fontbtn);
|
||||
gtk_widget_modify_font(msgwindow.tree_compiler,
|
||||
pango_font_description_from_string(app->msgwin_font));
|
||||
gtk_widget_modify_font(msgwindow.tree_msg,
|
||||
pango_font_description_from_string(app->msgwin_font));
|
||||
gtk_widget_modify_font(msgwindow.tree_status,
|
||||
pango_font_description_from_string(app->msgwin_font));
|
||||
ui_widget_modify_font_from_string(msgwindow.tree_compiler, app->msgwin_font);
|
||||
ui_widget_modify_font_from_string(msgwindow.tree_msg, app->msgwin_font);
|
||||
ui_widget_modify_font_from_string(msgwindow.tree_status, app->msgwin_font);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
|
@ -65,13 +65,17 @@ void treeviews_prepare_taglist(GtkWidget *tree, GtkTreeStore *store)
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeSelection *select;
|
||||
PangoFontDescription *pfd;
|
||||
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
column = gtk_tree_view_column_new_with_attributes(_("Symbols"), renderer, "text", 0, NULL);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);
|
||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree), FALSE);
|
||||
|
||||
gtk_widget_modify_font(tree, pango_font_description_from_string(app->tagbar_font));
|
||||
pfd = pango_font_description_from_string(app->tagbar_font);
|
||||
gtk_widget_modify_font(tree, pfd);
|
||||
pango_font_description_free(pfd);
|
||||
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store));
|
||||
g_signal_connect(G_OBJECT(tree), "button-press-event",
|
||||
G_CALLBACK(on_treeviews_button_press_event), GINT_TO_POINTER(TREEVIEW_SYMBOL));
|
||||
@ -285,6 +289,8 @@ void treeviews_prepare_openfiles()
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeSelection *select;
|
||||
PangoFontDescription *pfd;
|
||||
|
||||
tv.tree_openfiles = lookup_widget(app->window, "treeview6");
|
||||
|
||||
// store the short filename to show, and the index as reference
|
||||
@ -305,7 +311,10 @@ void treeviews_prepare_openfiles()
|
||||
|
||||
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tv.tree_openfiles), FALSE);
|
||||
|
||||
gtk_widget_modify_font(tv.tree_openfiles, pango_font_description_from_string(app->tagbar_font));
|
||||
pfd = pango_font_description_from_string(app->tagbar_font);
|
||||
gtk_widget_modify_font(tv.tree_openfiles, pfd);
|
||||
pango_font_description_free(pfd);
|
||||
|
||||
g_signal_connect(G_OBJECT(tv.tree_openfiles), "button-press-event",
|
||||
G_CALLBACK(on_treeviews_button_press_event), GINT_TO_POINTER(TREEVIEW_OPENFILES));
|
||||
|
||||
|
@ -139,15 +139,14 @@ void ui_set_window_title(gint index)
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
title = g_strdup_printf ("%s: %s %s",
|
||||
PACKAGE,
|
||||
(doc_list[index].file_name != NULL) ? g_filename_to_utf8(doc_list[index].file_name, -1, NULL, NULL, NULL) : _("untitled"),
|
||||
title = g_strdup_printf("Geany: %s %s",
|
||||
DOC_FILENAME(index),
|
||||
doc_list[index].changed ? _("(Unsaved)") : "");
|
||||
gtk_window_set_title(GTK_WINDOW(app->window), title);
|
||||
g_free(title);
|
||||
}
|
||||
else
|
||||
gtk_window_set_title(GTK_WINDOW(app->window), PACKAGE);
|
||||
gtk_window_set_title(GTK_WINDOW(app->window), "Geany");
|
||||
}
|
||||
|
||||
|
||||
@ -785,6 +784,7 @@ void ui_update_toolbar_items()
|
||||
}
|
||||
|
||||
|
||||
// Note: remember to unref the pixbuf once an image or window has added a reference.
|
||||
GdkPixbuf *ui_new_pixbuf_from_inline(gint img, gboolean small_img)
|
||||
{
|
||||
switch(img)
|
||||
@ -826,7 +826,13 @@ GdkPixbuf *ui_new_pixbuf_from_inline(gint img, gboolean small_img)
|
||||
|
||||
GtkWidget *ui_new_image_from_inline(gint img, gboolean small_img)
|
||||
{
|
||||
return gtk_image_new_from_pixbuf(ui_new_pixbuf_from_inline(img, small_img));
|
||||
GtkWidget *wid;
|
||||
GdkPixbuf *pb;
|
||||
|
||||
pb = ui_new_pixbuf_from_inline(img, small_img);
|
||||
wid = gtk_image_new_from_pixbuf(pb);
|
||||
g_object_unref(pb); // the image doesn't adopt our reference, so remove our ref.
|
||||
return wid;
|
||||
}
|
||||
|
||||
|
||||
@ -1215,3 +1221,13 @@ gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb)
|
||||
}
|
||||
|
||||
|
||||
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str)
|
||||
{
|
||||
PangoFontDescription *pfd;
|
||||
|
||||
pfd = pango_font_description_from_string(str);
|
||||
gtk_widget_modify_font(wid, pfd);
|
||||
pango_font_description_free(pfd);
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,4 +110,7 @@ typedef gboolean TVMatchCallback();
|
||||
|
||||
gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb);
|
||||
|
||||
|
||||
void ui_widget_modify_font_from_string(GtkWidget *wid, const gchar *str);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user