SF.net SVN: geany: [919] trunk
eht16 at users.sourceforge.net
eht16 at xxxxx
Mon Oct 23 00:05:50 UTC 2006
Revision: 919
http://svn.sourceforge.net/geany/?rev=919&view=rev
Author: eht16
Date: 2006-10-22 17:05:42 -0700 (Sun, 22 Oct 2006)
Log Message:
-----------
Added drop down box to the file open dialog to select an encoding.
Added possibility to open a file without any character set conversions.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/dialogs.c
trunk/src/document.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-10-22 17:30:24 UTC (rev 918)
+++ trunk/ChangeLog 2006-10-23 00:05:42 UTC (rev 919)
@@ -9,6 +9,10 @@
Let the Find, Replace and FIF dialogs use the word at current cursor
position if there is no selection.
* src/filetypes.c: Added shebang detection for D files (dmd).
+ * src/callbacks.c, src/dialogs.c, src/document.c:
+ Added drop down box to the file open dialog to select an encoding.
+ Added possibility to open a file without any character set
+ conversions (could already fix #1580456, have to be continued).
2006-10-22 Nick Treleaven <nick.treleaven at btinternet.com>
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2006-10-22 17:30:24 UTC (rev 918)
+++ trunk/src/callbacks.c 2006-10-23 00:05:42 UTC (rev 919)
@@ -747,11 +747,19 @@
{
GSList *filelist;
GSList *flist;
- gint ft_id = gtk_combo_box_get_active(GTK_COMBO_BOX(lookup_widget(GTK_WIDGET(dialog), "filetype_combo")));
+ gint filetype_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(
+ lookup_widget(GTK_WIDGET(dialog), "filetype_combo")));
+ gint encoding_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(
+ lookup_widget(GTK_WIDGET(dialog), "encoding_combo")));
filetype *ft = NULL;
+ gchar *charset = NULL;
gboolean ro = (response == GTK_RESPONSE_APPLY); // View clicked
- if (ft_id >= 0 && ft_id < GEANY_FILETYPES_ALL) ft = filetypes[ft_id];
+ if (filetype_idx >= 0 && filetype_idx < GEANY_FILETYPES_ALL) ft = filetypes[filetype_idx];
+ if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX)
+ charset = encodings[encoding_idx].charset;
+ else if (encoding_idx == GEANY_ENCODINGS_MAX)
+ charset = "none";
filelist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(app->open_filesel));
flist = filelist;
@@ -759,7 +767,7 @@
{
if (g_file_test((gchar*) flist->data, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
{
- document_open_file(-1, (gchar*) flist->data, 0, ro, ft, NULL);
+ document_open_file(-1, (gchar*) flist->data, 0, ro, ft, charset);
}
g_free(flist->data);
flist = flist->next;
Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c 2006-10-22 17:30:24 UTC (rev 918)
+++ trunk/src/dialogs.c 2006-10-23 00:05:42 UTC (rev 919)
@@ -45,6 +45,7 @@
#include "utils.h"
#include "ui_utils.h"
#include "keybindings.h"
+#include "encodings.h"
#ifndef G_OS_WIN32
@@ -64,10 +65,11 @@
of all we create it if it hasn't already been created. */
if (app->open_filesel == NULL)
{
- GtkWidget *combo;
+ GtkWidget *filetype_combo, *encoding_combo;
GtkWidget *viewbtn;
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
gint i;
+ gchar *encoding_string;
app->open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(app->window),
GTK_FILE_CHOOSER_ACTION_OPEN, NULL, NULL);
@@ -96,23 +98,32 @@
// add checkboxes and filename entry
gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(app->open_filesel),
add_file_open_extra_widget());
- combo = lookup_widget(app->open_filesel, "filetype_combo");
+ filetype_combo = lookup_widget(app->open_filesel, "filetype_combo");
// add FileFilters(start with "All Files")
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
filetypes_create_file_filter(filetypes[GEANY_FILETYPES_ALL]));
for (i = 0; i < GEANY_MAX_FILE_TYPES - 1; i++)
{
- if (filetypes[i])
- {
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo), filetypes[i]->title);
- gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
+ gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), filetypes[i]->title);
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(app->open_filesel),
filetypes_create_file_filter(filetypes[i]));
- }
}
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Detect by file extension "));
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo), GEANY_MAX_FILE_TYPES - 1);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), _("Detect by file extension"));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(filetype_combo), GEANY_MAX_FILE_TYPES - 1);
+ // fill encoding combo box
+ encoding_combo = lookup_widget(app->open_filesel, "encoding_combo");
+ for (i = 0; i < GEANY_ENCODINGS_MAX; i++)
+ {
+ encoding_string = encodings_to_string(&encodings[i]);
+ gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), encoding_string);
+ g_free(encoding_string);
+ }
+ gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), _("Do not any conversion"));
+ gtk_combo_box_append_text(GTK_COMBO_BOX(encoding_combo), _("Detect from file"));
+ gtk_combo_box_set_active(GTK_COMBO_BOX(encoding_combo), GEANY_ENCODINGS_MAX + 1);
+
g_signal_connect((gpointer) app->open_filesel, "selection-changed",
G_CALLBACK(on_file_open_selection_changed), NULL);
g_signal_connect ((gpointer) app->open_filesel, "delete_event",
@@ -146,53 +157,76 @@
#ifndef G_OS_WIN32
static GtkWidget *add_file_open_extra_widget()
{
- GtkWidget *vbox;
- GtkWidget *lbox;
- GtkWidget *ebox;
- GtkWidget *hbox;
- GtkWidget *file_entry;
- GtkSizeGroup *size_group;
- GtkWidget *align;
- GtkWidget *check_hidden;
- GtkWidget *filetype_label;
- GtkWidget *filetype_combo;
+ GtkWidget *vbox, *table, *file_entry, *check_hidden;
+ GtkWidget *filetype_ebox, *filetype_label, *filetype_combo;
+ GtkWidget *encoding_ebox, *encoding_label, *encoding_combo;
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(app->window, "tooltips"));
vbox = gtk_vbox_new(FALSE, 6);
- align = gtk_alignment_new(1.0, 0.0, 0.0, 0.0);
+ table = gtk_table_new(2, 4, FALSE);
+
+ // line 1 with checkbox and encoding combo
check_hidden = gtk_check_button_new_with_mnemonic(_("Show _hidden files"));
+ gtk_button_set_focus_on_click(GTK_BUTTON(check_hidden), FALSE);
gtk_widget_show(check_hidden);
- gtk_container_add(GTK_CONTAINER(align), check_hidden);
- gtk_box_pack_start(GTK_BOX(vbox), align, FALSE, FALSE, 0);
- gtk_button_set_focus_on_click(GTK_BUTTON(check_hidden), FALSE);
+ gtk_table_attach(GTK_TABLE(table), check_hidden, 0, 1, 0, 1,
+ (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
+ (GtkAttachOptions) (0), 0, 5);
- lbox = gtk_hbox_new(FALSE, 12);
+ // spacing
+ gtk_table_attach(GTK_TABLE(table), gtk_label_new(""), 1, 2, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 5, 5);
+
+ encoding_label = gtk_label_new(_("Set encoding:"));
+ gtk_misc_set_alignment(GTK_MISC(encoding_label), 1, 0);
+ gtk_table_attach(GTK_TABLE(table), encoding_label, 2, 3, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 4, 5);
+ // the ebox is for the tooltip, because gtk_combo_box can't show tooltips
+ encoding_ebox = gtk_event_box_new();
+ encoding_combo = gtk_combo_box_new_text();
+ gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(encoding_combo), 3);
+ gtk_tooltips_set_tip(tooltips, encoding_ebox,
+ _("Explicitly defines an encoding for the file, if it would not be detected. This is useful when you know that the encoding of a file cannot be detected correctly by Geany.\nNote if you choose multiple files, they will all be opened with the chosen encoding."), NULL);
+ gtk_container_add(GTK_CONTAINER(encoding_ebox), encoding_combo);
+ gtk_table_attach(GTK_TABLE(table), encoding_ebox, 3, 4, 0, 1,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 5);
+
+ // line 2 with filename entry and filetype combo
file_entry = gtk_entry_new();
gtk_widget_show(file_entry);
- gtk_box_pack_start(GTK_BOX(lbox), file_entry, TRUE, TRUE, 0);
//gtk_editable_set_editable(GTK_EDITABLE(file_entry), FALSE);
gtk_entry_set_activates_default(GTK_ENTRY(file_entry), TRUE);
+ gtk_table_attach(GTK_TABLE(table), file_entry, 0, 1, 1, 2,
+ (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
+ (GtkAttachOptions) (0), 0, 5);
- // the ebox is for the tooltip, because gtk_combo_box doesn't show a tooltip for unknown reason
- ebox = gtk_event_box_new();
- hbox = gtk_hbox_new(FALSE, 6);
+ // spacing
+ gtk_table_attach(GTK_TABLE(table), gtk_label_new(""), 1, 2, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 5, 5);
+
filetype_label = gtk_label_new(_("Set filetype:"));
+ gtk_misc_set_alignment(GTK_MISC(filetype_label), 1, 0);
+ gtk_table_attach(GTK_TABLE(table), filetype_label, 2, 3, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 4, 5);
+ // the ebox is for the tooltip, because gtk_combo_box can't show tooltips
+ filetype_ebox = gtk_event_box_new();
filetype_combo = gtk_combo_box_new_text();
- gtk_tooltips_set_tip(tooltips, ebox,
+ gtk_tooltips_set_tip(tooltips, filetype_ebox,
_("Explicitly defines a filetype for the file, if it would not be detected by filename extension.\nNote if you choose multiple files, they will all be opened with the chosen filetype."), NULL);
- gtk_box_pack_start(GTK_BOX(hbox), filetype_label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(hbox), filetype_combo, FALSE, FALSE, 0);
- gtk_container_add(GTK_CONTAINER(ebox), hbox);
- gtk_box_pack_start(GTK_BOX(lbox), ebox, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(vbox), lbox, FALSE, FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(filetype_ebox), filetype_combo);
+ gtk_table_attach(GTK_TABLE(table), filetype_ebox, 3, 4, 1, 2,
+ (GtkAttachOptions) (GTK_FILL),
+ (GtkAttachOptions) (0), 0, 5);
+
+ gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
gtk_widget_show_all(vbox);
- size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
- gtk_size_group_add_widget(GTK_SIZE_GROUP(size_group), check_hidden);
- gtk_size_group_add_widget(GTK_SIZE_GROUP(size_group), filetype_combo);
- g_object_unref(G_OBJECT(size_group)); // auto destroy the size group
-
g_signal_connect((gpointer) file_entry, "activate",
G_CALLBACK(on_file_open_entry_activate), NULL);
g_signal_connect((gpointer) check_hidden, "toggled",
@@ -204,6 +238,8 @@
gtk_widget_ref(check_hidden), (GDestroyNotify)gtk_widget_unref);
g_object_set_data_full(G_OBJECT(app->open_filesel), "filetype_combo",
gtk_widget_ref(filetype_combo), (GDestroyNotify)gtk_widget_unref);
+ g_object_set_data_full(G_OBJECT(app->open_filesel), "encoding_combo",
+ gtk_widget_ref(encoding_combo), (GDestroyNotify)gtk_widget_unref);
return vbox;
}
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2006-10-22 17:30:24 UTC (rev 918)
+++ trunk/src/document.c 2006-10-23 00:05:42 UTC (rev 919)
@@ -606,7 +606,6 @@
if (! g_file_get_contents(locale_filename, &data, &size, &err))
#endif
{
- //msgwin_status_add(_("Could not open file %s (%s)"), utf8_filename, g_strerror(err->code));
msgwin_status_add(err->message);
g_error_free(err);
g_free(utf8_filename);
@@ -614,11 +613,18 @@
return -1;
}
- /* Determine character encoding and convert to utf-8*/
- if (reload && forced_enc != NULL)
+ /* Determine character encoding and convert to UTF-8 */
+ if (forced_enc != NULL)
{
- if (! handle_forced_encoding(&data, &size, forced_enc, &enc, &bom))
+ // the encoding should be ignored(requested by user), so open the file "as it is"
+ if (utils_strcmp(forced_enc, "none"))
{
+ /// TODO enc = NULL breaks several tests, e.g. encodings_select_radio_item. Will be fixed soon.
+ bom = FALSE;
+ enc = NULL;
+ }
+ else if (! handle_forced_encoding(&data, &size, forced_enc, &enc, &bom))
+ {
msgwin_status_add(_("The file \"%s\" is not valid %s."), utf8_filename, forced_enc);
utils_beep();
g_free(data);
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