SF.net SVN: geany:[3279] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Wed Nov 26 13:15:54 UTC 2008
Revision: 3279
http://geany.svn.sourceforge.net/geany/?rev=3279&view=rev
Author: ntrel
Date: 2008-11-26 13:15:53 +0000 (Wed, 26 Nov 2008)
Log Message:
-----------
Add 'Tools->Configuration Files' menu with items to open
filetype_extensions.conf and ignore.tags. These files are also
reloaded automatically when saved.
- Code changes:
Make app->configdir a realpath().
Add ui_add_config_file_menu_item().
Add utils_build_path(), similar to g_build_path() but (re)using a
fixed buffer, so the result is never freed.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/filetypes.c
trunk/src/geany.h
trunk/src/main.c
trunk/src/symbols.c
trunk/src/ui_utils.c
trunk/src/ui_utils.h
trunk/src/utils.c
trunk/src/utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/ChangeLog 2008-11-26 13:15:53 UTC (rev 3279)
@@ -1,3 +1,17 @@
+2008-11-26 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/utils.c, src/ui_utils.h, src/utils.h, src/geany.h,
+ src/filetypes.c, src/main.c, src/symbols.c, src/ui_utils.c:
+ Add 'Tools->Configuration Files' menu with items to open
+ filetype_extensions.conf and ignore.tags. These files are also
+ reloaded automatically when saved.
+ - Code changes:
+ Make app->configdir a realpath().
+ Add ui_add_config_file_menu_item().
+ Add utils_build_path(), similar to g_build_path() but (re)using a
+ fixed buffer, so the result is never freed.
+
+
2008-11-25 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/main.c, src/symbols.c, src/symbols.h:
Modified: trunk/src/filetypes.c
===================================================================
--- trunk/src/filetypes.c 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/filetypes.c 2008-11-26 13:15:53 UTC (rev 3279)
@@ -40,6 +40,8 @@
#include "utils.h"
#include "sciwrappers.h"
#include "ui_utils.h"
+#include "keyfile.h"
+#include "geanyobject.h"
#include <stdlib.h>
@@ -583,6 +585,25 @@
}
+static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
+{
+ g_return_if_fail(NZV(doc->real_path));
+
+ if (utils_str_equal(doc->real_path,
+ utils_build_path(app->configdir, "filetype_extensions.conf", NULL)))
+ configuration_read_filetype_extensions();
+}
+
+
+static void setup_config_file_menus(void)
+{
+ ui_add_config_file_menu_item(
+ utils_build_path(app->configdir, "filetype_extensions.conf", NULL), NULL, NULL);
+
+ g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);
+}
+
+
#define create_sub_menu(menu, item, title) \
(menu) = gtk_menu_new(); \
(item) = gtk_menu_item_new_with_mnemonic((title)); \
@@ -645,6 +666,7 @@
{
filetypes_init_types();
create_set_filetype_menu();
+ setup_config_file_menus();
}
Modified: trunk/src/geany.h
===================================================================
--- trunk/src/geany.h 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/geany.h 2008-11-26 13:15:53 UTC (rev 3279)
@@ -64,6 +64,7 @@
{
gboolean debug_mode; /**< @c TRUE if debug messages should be printed. */
/** User configuration directory, usually @c ~/.config/geany.
+ * This is a full path read by @ref tm_get_real_path().
* @note Plugin configuration files should be saved as:
* @code g_build_path(G_DIR_SEPARATOR_S, geany->app->configdir, "plugins", "pluginname",
* "file.conf"); @endcode */
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/main.c 2008-11-26 13:15:53 UTC (rev 3279)
@@ -544,6 +544,7 @@
{
app->configdir = g_build_filename(g_get_user_config_dir(), "geany", NULL);
}
+ setptr(app->configdir, tm_get_real_path(app->configdir));
#ifdef GEANY_DEBUG
if (generate_datafiles)
Modified: trunk/src/symbols.c
===================================================================
--- trunk/src/symbols.c 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/symbols.c 2008-11-26 13:15:53 UTC (rev 3279)
@@ -50,6 +50,7 @@
#include "ui_utils.h"
#include "editor.h"
#include "sciwrappers.h"
+#include "geanyobject.h"
const guint TM_GLOBAL_TYPE_MASK =
@@ -1774,9 +1775,23 @@
}
+static void on_document_save(G_GNUC_UNUSED GObject *object, GeanyDocument *doc)
+{
+ g_return_if_fail(NZV(doc->real_path));
+
+ if (utils_str_equal(doc->real_path,
+ utils_build_path(app->configdir, "ignore.tags", NULL)))
+ load_c_ignore_tags();
+}
+
+
void symbols_init(void)
{
create_taglist_popup_menu();
+
+ ui_add_config_file_menu_item(utils_build_path(app->configdir, "ignore.tags", NULL),
+ NULL, NULL);
+ g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL);
}
Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/ui_utils.c 2008-11-26 13:15:53 UTC (rev 3279)
@@ -67,6 +67,7 @@
GtkWidget *redo_items[3];
GtkWidget *undo_items[3];
GtkWidget *save_buttons[4];
+ GtkWidget *config_files_menu;
}
widgets;
@@ -1564,6 +1565,64 @@
}
+static void on_config_file_clicked(GtkWidget *widget, gpointer user_data)
+{
+ const gchar *file_name = user_data;
+
+ if (g_file_test(file_name, G_FILE_TEST_EXISTS))
+ document_open_file(file_name, FALSE, NULL, NULL);
+ else
+ {
+ gchar *utf8 = utils_get_utf8_from_locale(file_name);
+
+ document_new_file(utf8, NULL, NULL);
+ g_free(utf8);
+ }
+}
+
+
+/* @note You should connect to the "document-save" signal yourself to detect
+ * if the user has just saved the config file, reloading it. */
+void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label,
+ GtkContainer *parent)
+{
+ GtkWidget *item;
+
+ if (!parent)
+ parent = GTK_CONTAINER(widgets.config_files_menu);
+
+ if (!label)
+ {
+ gchar *base_name;
+
+ base_name = g_path_get_basename(real_path);
+ item = gtk_menu_item_new_with_label(base_name);
+ g_free(base_name);
+ }
+ else
+ item = gtk_menu_item_new_with_mnemonic(label);
+
+ gtk_widget_show(item);
+ gtk_container_add(parent, item);
+ g_signal_connect(item, "activate", G_CALLBACK(on_config_file_clicked),
+ /* this memory is kept */
+ g_strdup(real_path));
+}
+
+
+static void create_config_files_menu(void)
+{
+ GtkWidget *menu, *item;
+
+ widgets.config_files_menu = menu = gtk_menu_new();
+
+ item = ui_image_menu_item_new(GTK_STOCK_FILE, _("C_onfiguration Files"));
+ gtk_widget_show(item);
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu);
+ gtk_container_add(GTK_CONTAINER(main_widgets.tools_menu), item);
+}
+
+
void ui_init(void)
{
ui_widgets.statusbar = lookup_widget(main_widgets.window, "statusbar");
@@ -1593,6 +1652,7 @@
widgets.undo_items[2] = lookup_widget(main_widgets.window, "toolbutton_undo");
init_document_widgets();
+ create_config_files_menu();
}
Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/ui_utils.h 2008-11-26 13:15:53 UTC (rev 3279)
@@ -172,7 +172,10 @@
void ui_init(void);
+void ui_add_config_file_menu_item(const gchar *real_path, const gchar *label,
+ GtkContainer *parent);
+
void ui_set_statusbar(gboolean log, const gchar *format, ...) G_GNUC_PRINTF (2, 3);
void ui_update_statusbar(GeanyDocument *doc, gint pos);
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/utils.c 2008-11-26 13:15:53 UTC (rev 3279)
@@ -1518,3 +1518,35 @@
#endif
return result;
}
+
+
+/* Similar to g_build_path() but (re)using a fixed buffer, so never free it.
+ * This assumes a small enough resulting string length to be kept without freeing,
+ * but this should be the case for filenames. */
+const gchar *utils_build_path(const gchar *first, ...)
+{
+ static GString *buffer;
+ const gchar *str;
+ va_list args;
+
+ if (!buffer)
+ buffer = g_string_new(first);
+ else
+ g_string_assign(buffer, first);
+
+ va_start(args, first);
+ while (1)
+ {
+ str = va_arg(args, const gchar *);
+ if (!str)
+ break;
+
+ g_string_append_c(buffer, G_DIR_SEPARATOR);
+ g_string_append(buffer, str);
+ }
+ va_end(args);
+
+ return buffer->str;
+}
+
+
Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h 2008-11-25 12:09:08 UTC (rev 3278)
+++ trunk/src/utils.h 2008-11-26 13:15:53 UTC (rev 3279)
@@ -141,4 +141,6 @@
gint utils_str_casecmp(const gchar *s1, const gchar *s2);
+const gchar *utils_build_path(const gchar *first, ...) G_GNUC_NULL_TERMINATED;
+
#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