Revision: 2177
http://geany.svn.sourceforge.net/geany/?rev=2177&view=rev
Author: eht16
Date: 2008-01-16 08:50:10 -0800 (Wed, 16 Jan 2008)
Log Message:
-----------
Add encodings_get_charset_from_index() and make it available through plugin API.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/encodings.c
trunk/src/encodings.h
trunk/src/plugindata.h
trunk/src/plugins.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/ChangeLog 2008-01-16 16:50:10 UTC (rev 2177)
@@ -3,6 +3,9 @@
* geany.glade, src/interface.c, src/keyfile.c, src/prefs.c,
src/project.c, src/project.h:
Add option for project session files support.
+ * src/encodings.c, src/encodings.h, src/plugindata.h, src/plugins.c:
+ Add encodings_get_charset_from_index() and make it available through
+ plugin API.
2008-01-16 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: trunk/src/encodings.c
===================================================================
--- trunk/src/encodings.c 2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/encodings.c 2008-01-16 16:50:10 UTC (rev 2177)
@@ -172,13 +172,32 @@
const GeanyEncoding *encodings_get_from_index(gint idx)
{
- g_return_val_if_fail(idx >= 0, NULL);
- g_return_val_if_fail(idx < GEANY_ENCODINGS_MAX, NULL);
+ g_return_val_if_fail(idx >= 0 && idx < GEANY_ENCODINGS_MAX, NULL);
return &encodings[idx];
}
+/*
+ * gtk_status_icon_get_stock:
+ * @idx: #GeanyEncodingIndex to retrieve the corresponding character set
+ *
+ * Gets the character set name of the specified index e.g. for use with
+ * document_set_encoding.
+ *
+ * Return value: charset according to idx,
+ * or %NULL if the index is invalid.
+ *
+ * Since: 0.13
+ */
+const gchar* encodings_get_charset_from_index(gint idx)
+{
+ g_return_val_if_fail(idx >= 0 && idx < GEANY_ENCODINGS_MAX, NULL);
+
+ return encodings[idx].charset;
+}
+
+
gchar *encodings_to_string(const GeanyEncoding* enc)
{
g_return_val_if_fail(enc != NULL, NULL);
@@ -387,10 +406,21 @@
}
-/* Converts a string from the given charset to UTF-8.
- * If fast is set, no further checks are performed. */
+/*
+ * encodings_convert_to_utf8_from_charset:
+ * @buffer: the input string to convert
+ * @size: the length of the string, or -1 if the string is nul-terminated
+ * @charset: the charset to be used for conversion
+ * @fast: TRUE to only convert the input and skip extended checks on the converted string
+ *
+ * Tries to convert @buffer into UTF-8 encoding from the encoding specified with @charset.
+ * If @fast is not set, additional checks to validate the converted string are performed.
+ *
+ * Return value: If the conversion was successful, a newly allocated nul-terminated string,
+ * which must be freed with g_free(). Otherwise %NULL.
+ */
gchar *encodings_convert_to_utf8_from_charset(const gchar *buffer, gsize size,
- const gchar *charset, gboolean fast)
+ const gchar *charset, gboolean fast)
{
gchar *utf8_content = NULL;
GError *conv_error = NULL;
@@ -432,6 +462,18 @@
}
+/*
+ * encodings_convert_to_utf8:
+ * @buffer: the input string to convert
+ * @size: the length of the string, or -1 if the string is nul-terminated.
+ * @used_encoding: return location of the detected encoding of the input string, or %NULL
+ *
+ * Tries to convert @buffer into UTF-8 encoding and store the detected original encoding in
+ * @used_encoding.
+ *
+ * Return value: If the conversion was successful, a newly allocated nul-terminated string,
+ * which must be freed with g_free(). Otherwise %NULL.
+ */
gchar *encodings_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_encoding)
{
gchar *locale_charset = NULL;
@@ -442,6 +484,11 @@
gboolean check_locale = FALSE;
guint i;
+ if ((gint)size == -1)
+ {
+ size = strlen(buffer);
+ }
+
#ifdef HAVE_REGCOMP
// first try to read the encoding from the file content
for (i = 0; i < G_N_ELEMENTS(pregs) && ! check_regex; i++)
Modified: trunk/src/encodings.h
===================================================================
--- trunk/src/encodings.h 2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/encodings.h 2008-01-16 16:50:10 UTC (rev 2177)
@@ -62,6 +62,7 @@
gchar* encodings_to_string(const GeanyEncoding* enc);
const gchar* encodings_get_charset(const GeanyEncoding* enc);
+const gchar* encodings_get_charset_from_index(gint idx);
void encodings_select_radio_item(const gchar *charset);
Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h 2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/plugindata.h 2008-01-16 16:50:10 UTC (rev 2177)
@@ -93,7 +93,7 @@
/* The API version should be incremented whenever any plugin data types below are
* modified or appended to. */
-static const gint api_version = 38;
+static const gint api_version = 39;
/* The ABI version should be incremented whenever existing fields in the plugin
* data types below have to be changed or reordered. It should stay the same if fields
@@ -330,9 +330,10 @@
typedef struct EncodingFuncs
{
- gchar* (*convert_to_utf8) (const gchar *buffer, gsize size, gchar **used_encoding);
- gchar* (*convert_to_utf8_from_charset) (const gchar *buffer, gsize size,
- const gchar *charset, gboolean fast);
+ gchar* (*convert_to_utf8) (const gchar *buffer, gsize size, gchar **used_encoding);
+ gchar* (*convert_to_utf8_from_charset) (const gchar *buffer, gsize size,
+ const gchar *charset, gboolean fast);
+ const gchar* (*get_charset_from_index) (gint idx);
}
EncodingFuncs;
Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c 2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/plugins.c 2008-01-16 16:50:10 UTC (rev 2177)
@@ -178,7 +178,8 @@
static EncodingFuncs encoding_funcs = {
&encodings_convert_to_utf8,
- &encodings_convert_to_utf8_from_charset
+ &encodings_convert_to_utf8_from_charset,
+ &encodings_get_charset_from_index
};
static KeybindingFuncs keybindings_funcs = {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 2173
http://geany.svn.sourceforge.net/geany/?rev=2173&view=rev
Author: ntrel
Date: 2008-01-14 09:46:21 -0800 (Mon, 14 Jan 2008)
Log Message:
-----------
Add coding note about not writing long functions with a lot of variables and/or scopes. Some other minor changes.
Modified Paths:
--------------
trunk/HACKING
Modified: trunk/HACKING
===================================================================
--- trunk/HACKING 2008-01-14 17:30:59 UTC (rev 2172)
+++ trunk/HACKING 2008-01-14 17:46:21 UTC (rev 2173)
@@ -24,9 +24,9 @@
File organization
-----------------
-We aim to use callbacks.c only for Glade callbacks.
+callbacks.c is just for Glade callbacks.
Avoid adding code to geany.h if it will fit better elsewhere.
-See the src/*.c files for descriptions.
+See the top of each src/*.c file for a brief description of what it's for.
Glade
-----
@@ -41,13 +41,18 @@
Coding
------
-Use static functions where possible.
-Try to use GLib types and functions - e.g. g_free instead of free and
-try to use only GLib 2.6 and GTK 2.6 functions. At least for the moment,
-we want to keep the minimum requirement for GTK at 2.6. We currently try
-to support the old GCC 2.9.x compiler, so we always declare variables
-before statements. You can use -Wdeclaration-after-statement in your
-./configure CFLAGS to warn about this.
+Don't write long functions with a lot of variables and/or scopes - break
+them down into smaller static functions where possible. This makes code
+much easier to read and maintain.
+Use GLib types and functions - e.g. g_free instead of free.
+Your code should build against GLib 2.6 and GTK 2.6. At least for the
+moment, we want to keep the minimum requirement for GTK at 2.6 (of
+course, you can use the GTK_CHECK_VERSION macro to protect code using
+later versions).
+We currently try to support the old GCC 2.9.x compiler,
+so we always declare variables before statements. You can use
+-Wdeclaration-after-statement in your ./configure CFLAGS to warn about
+this.
Style
-----
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 2171
http://geany.svn.sourceforge.net/geany/?rev=2171&view=rev
Author: eht16
Date: 2008-01-13 09:50:04 -0800 (Sun, 13 Jan 2008)
Log Message:
-----------
Save project session file list when project is closed.
Don't load default session files in a second instance after a project was closed.
Fix not updating symbol list (and other things) when changing tabs after a project was opened or closed in a second instance.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/keyfile.c
trunk/src/project.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-01-13 10:13:15 UTC (rev 2170)
+++ trunk/ChangeLog 2008-01-13 17:50:04 UTC (rev 2171)
@@ -1,3 +1,13 @@
+2008-01-13 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
+
+ * src/keyfile.c, src/project.c:
+ Save project session file list when project is closed.
+ Don't load default session files in a second instance after a project
+ was closed.
+ Fix not updating symbol list (and other things) when changing tabs
+ after a project was opened or closed in a second instance.
+
+
2008-01-12 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/keyfile.c:
Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c 2008-01-13 10:13:15 UTC (rev 2170)
+++ trunk/src/keyfile.c 2008-01-13 17:50:04 UTC (rev 2171)
@@ -807,13 +807,18 @@
}
-// open session files
+/* Open session files
+ * Note: notebook page switch handler and adding to recent files list is always disabled
+ * for all files opened within this function */
gboolean configuration_open_files()
{
gint i;
guint pos;
gboolean ret = FALSE, failure = FALSE;
+ // necessary to set it to TRUE for project session support
+ main_status.opening_session_files = TRUE;
+
document_delay_colourise();
i = prefs.tab_order_ltr ? 0 : (session_files->len - 1);
@@ -885,9 +890,8 @@
/// TODO if session_notebook_page is equal to the current notebook tab(the last opened)
/// the notebook switch page callback isn't triggered and e.g. menu items are not updated
gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook), session_notebook_page);
- // reset status to leave in any case with the same state as when entering
- main_status.opening_session_files = TRUE;
}
+ main_status.opening_session_files = FALSE;
return ret;
}
Modified: trunk/src/project.c
===================================================================
--- trunk/src/project.c 2008-01-13 10:13:15 UTC (rev 2170)
+++ trunk/src/project.c 2008-01-13 17:50:04 UTC (rev 2171)
@@ -300,6 +300,9 @@
ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name);
+ // use write_config() to save project session files
+ write_config(FALSE);
+
g_free(app->project->name);
g_free(app->project->description);
g_free(app->project->file_name);
@@ -317,7 +320,7 @@
}
// after closing all tabs let's open the tabs found in the default config
- if (open_default == TRUE)
+ if (open_default == TRUE && cl_options.load_session)
{
configuration_reload_default_session();
configuration_open_files();
@@ -675,7 +678,7 @@
g_free(tmp);
#endif
}
- write_config();
+ write_config(TRUE);
if (new_project)
ui_set_statusbar(TRUE, _("Project \"%s\" created."), p->name);
else
@@ -884,7 +887,7 @@
// save current (non-project) session (it could has been changed since program startup)
configuration_save_default_session();
- // fetch session files too
+ // read session files so they can be opened with configuration_open_files()
configuration_load_session_files(config);
if (geany_object)
@@ -898,8 +901,12 @@
}
-// Returns: TRUE if project file was written successfully.
-static gboolean write_config()
+/* Write the project settings as well as the project session files into its configuration files.
+ * emit_signal defines whether the project-save signal should be emitted. When write_config()
+ * is called while closing a project, this is used to skip emitting the signal because
+ * project-close will be emitted afterwards.
+ * Returns: TRUE if project file was written successfully. */
+static gboolean write_config(gboolean emit_signal)
{
GeanyProject *p;
GKeyFile *config;
@@ -932,7 +939,7 @@
/// TODO maybe it is useful to store relative file names if base_path is relative
configuration_save_session_files(config);
- if (geany_object)
+ if (geany_object && emit_signal)
{
g_signal_emit_by_name(geany_object, "project-save", config);
}
@@ -1002,7 +1009,7 @@
NVL(local_prefs.project_file_path, ""));
if (project != NULL)
- write_config(); // to store project session files
+ write_config(TRUE); // to store project session files
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.