* gnoemoe/gm-world.c: set world name from path when options

couldn't be succesfully loaded
	* gnoemoe/gm-editor.c: allways write \n (also on last line)
	* gnoemoe/gm-options.c: set file path even if it couldn't be
	loaded so that when there is no options file it will be 
	saved correctly. return false when loading fails
	* gnoemoe/widgets/gm-external-view.c: use default gnome
	terminal when terminal is needed
	* gnoemoe/widgets/gm-world-tab.c: fix tab close button
This commit is contained in:
Jesse van den Kieboom 2006-08-12 15:07:27 +00:00
parent 4084be6076
commit e7bf115295
6 changed files with 187 additions and 33 deletions

View File

@ -1,3 +1,18 @@
2006-12-08 Jesse van den Kieboom <jesse@icecrew.nl>
* gnoemoe/gm-world.c: set world name from path when options
couldn't be succesfully loaded
* gnoemoe/gm-editor.c: allways write \n (also on last line)
* gnoemoe/gm-options.c: set file path even if it couldn't be
loaded so that when there is no options file it will be
saved correctly. return false when loading fails
* gnoemoe/widgets/gm-external-view.c: use default gnome
terminal when terminal is needed
* gnoemoe/widgets/gm-world-tab.c: fix tab close buttons
2006-12-08 Jesse van den Kieboom <jesse@icecrew.nl>
* gnoemoe/gm-support.c: fixed the tab close button
* gnoemoe/gm-pixbuf.c: fixed warning on creating save close button
2006-18-06 Jesse van den Kieboom <jesse@icecrew.nl>
* gnoemoe/gm-world.c: added static to functions, added flushing history
to disk

View File

@ -254,11 +254,9 @@ gm_editor_write_lines(GmEditor *editor) {
break;
}
if (line->next) {
if (write(fd, "\n", 1) == -1) {
gm_debug_msg(DEBUG_ALWAYS, "Writing failed");
break;
}
if (write(fd, "\n", 1) == -1) {
gm_debug_msg(DEBUG_ALWAYS, "Writing failed");
break;
}
}

View File

@ -214,7 +214,7 @@ gm_options_save_as(GmOptions *options, gchar const *filename) {
gm_options_save(options);
}
void
gboolean
gm_options_load(GmOptions *options, gchar const *filename) {
xmlDocPtr doc;
xmlNodePtr root;
@ -222,9 +222,12 @@ gm_options_load(GmOptions *options, gchar const *filename) {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: loading options (%s)!",
filename);
g_free(options->priv->filepath);
options->priv->filepath = g_strdup(filename);
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: file does not exist");
return;
return FALSE;
}
doc = xmlParseFile(filename);
@ -232,20 +235,20 @@ gm_options_load(GmOptions *options, gchar const *filename) {
if (doc == NULL) {
gm_debug_msg(DEBUG_DEFAULT,
"GmOptions.load: error on parsing options file");
return;
return FALSE;
}
root = xmlDocGetRootElement(doc);
if (root == NULL) {
xmlFreeDoc(doc);
return;
return FALSE;
}
if (xmlStrcmp(root->name, (const xmlChar *)(XML_ROOT_NAME))) {
gm_debug_msg(DEBUG_DEFAULT, "GmOptions.load: invalid root node");
xmlFreeDoc(doc);
return;
return FALSE;
}
for (root = root->xmlChildrenNode; root; root = root->next) {
@ -255,9 +258,7 @@ gm_options_load(GmOptions *options, gchar const *filename) {
}
xmlFreeDoc(doc);
g_free(options->priv->filepath);
options->priv->filepath = g_strdup(filename);
return TRUE;
}
void

View File

@ -402,7 +402,7 @@ gm_world_load_input_history(GmWorld *world) {
}
}
g_string_free(str, TRUE);
g_string_free(str, TRUE);
fclose(f);
} else {
gm_debug_msg(DEBUG_DEFAULT, "GmWorld.LoadInputHistory: could not "
@ -519,7 +519,8 @@ GmWorld *
gm_world_new(gchar *path) {
GmWorld *world = GM_WORLD(g_object_new(GM_TYPE_WORLD, NULL));
gchar *options_path;
gchar *basename;
if (path != NULL) {
options_path = g_strconcat(path, G_DIR_SEPARATOR_S, "settings.xml", NULL);
@ -531,7 +532,13 @@ gm_world_new(gchar *path) {
"settings for %s", path);
_gm_options_check_old_options(options_path);
gm_options_load(world->priv->options, options_path);
if (!gm_options_load(world->priv->options, options_path)) {
/* Set the name then */
basename = g_path_get_basename(path);
gm_options_set(world->priv->options, "name", basename);
g_free(basename);
}
if (strlen(gm_options_get(world->priv->options, "charset")) == 0) {
gm_options_set(world->priv->options, "charset",

View File

@ -2,7 +2,9 @@
#include <sys/stat.h>
#include <unistd.h>
#include <libgnome/libgnome.h>
#include <gconf/gconf-client.h>
#include <stdlib.h>
#include <string.h>
#include "gm-external-view.h"
#include "gm-debug.h"
@ -65,13 +67,143 @@ gm_external_view_spawn(GmExternalView *view, gchar **argv) {
}
}
typedef struct {
gchar const *terminal;
gchar const *arguments;
} Terminal;
static Terminal terminals[] = {
{"gnome-terminal", "--disable-factory"},
{"gnome-terminal.wrapper", "--disable-factory"},
{NULL, NULL}
};
static gchar *
resolve_file(gchar const *file) {
GSList *paths = NULL;
GSList *item;
gchar *resolve;
gchar *prog;
prog = g_find_program_in_path(file);
while (prog && g_file_test(prog, G_FILE_TEST_IS_SYMLINK)) {
paths = g_slist_prepend(paths, prog);
resolve = g_file_read_link(prog, NULL);
if (g_slist_find_custom(paths, resolve, (GCompareFunc)strcmp)) {
prog = NULL;
g_free(resolve);
break;
}
prog = resolve;
}
for (item = paths; item; item = item->next)
if (item->data != prog)
g_free(item->data);
g_slist_free(paths);
return prog;
}
static Terminal *
find_terminal(gchar const *term) {
gchar *prog;
gchar *basename;
Terminal *terminal;
prog = resolve_file(term);
if (prog) {
basename = g_path_get_basename(prog);
g_message("%s", basename);
for (terminal = terminals; terminal->terminal != NULL; ++terminal)
if (strcmp(terminal->terminal, basename) == 0)
break;
g_free(basename);
g_free(prog);
if (terminal->terminal)
return terminal;
}
return NULL;
}
static gchar **
build_terminal_command(gchar const *editor_command) {
GConfClient *client;
gchar *term;
gchar *term_extra_args = NULL;
gchar *term_args = NULL;
gchar **spawn_command = NULL;
Terminal *terminal;
gchar **argv;
gint argc;
gint i;
client = gconf_client_get_default();
term = gconf_client_get_string(client,
"/desktop/gnome/applications/terminal/exec", NULL);
if (term != NULL)
term_extra_args = gconf_client_get_string(client,
"/desktop/gnome/applications/terminal/exec_arg", NULL);
else {
term = g_strdup(getenv("TERM"));
if (term == NULL)
term = g_strdup("xterm");
term_extra_args = g_strdup("-e");
}
terminal = find_terminal(term);
if (terminal)
term_args = (gchar *)(terminal->arguments);
if (term_args || (term_extra_args && *term_extra_args != '\0')) {
term_args = g_strdup_printf("%s %s %s", term_args ? term_args : "",
term_extra_args ? term_extra_args : "", editor_command);
if (g_shell_parse_argv(term_args, &argc, &argv, NULL)) {
spawn_command = g_new0(gchar *, argc + 2);
spawn_command[0] = term;
for (i = 0; i < argc; ++i)
spawn_command[i + 1] = argv[i];
g_free(argv);
}
g_free(term_args);
}
g_free(term_extra_args);
g_object_unref(client);
for (i = 0; spawn_command[i]; ++i)
printf("'%s' ", spawn_command[i]);
printf("\n");
return spawn_command;
}
GmExternalView *
gm_external_view_new(GmWorld *world, GmEditor *editor) {
GmExternalView *obj = g_new0(GmExternalView, 1);
gchar *spawn_command[4] = {NULL, NULL, NULL, NULL};
gchar **av, *command;
gint an;
gchar **spawn_command = NULL;
gchar *filename;
gchar *command;
gint argc;
GmOptions *options = gm_app_options(gm_app_instance());
obj->world = world;
@ -84,26 +216,21 @@ gm_external_view_new(GmWorld *world, GmEditor *editor) {
GNOME_VFS_MONITOR_FILE,
(GnomeVFSMonitorCallback)on_gm_external_view_file_changed, obj);
filename = g_shell_quote(obj->filename);
command = g_strconcat(gm_options_get(options, "editor_alternative"),
" ", obj->filename, NULL);
" ", filename, NULL);
g_free(filename);
if (gm_options_get_int(options, "editor_needs_terminal")) {
spawn_command[0] = getenv("TERM");
if (spawn_command[0] == NULL) {
spawn_command[0] = "xterm";
}
spawn_command[1] = "-e";
spawn_command[2] = command;
gm_external_view_spawn(obj, spawn_command);
spawn_command = build_terminal_command(command);
} else {
g_shell_parse_argv(command, &an, &av, NULL);
gm_external_view_spawn(obj, av);
g_shell_parse_argv(command, &argc, &spawn_command, NULL);
}
gm_external_view_spawn(obj, spawn_command);
g_strfreev(spawn_command);
g_free(command);
obj->child_watch = g_child_watch_add(obj->pid,
(GChildWatchFunc)on_gm_external_view_exited, obj);

View File

@ -83,6 +83,7 @@ gm_world_tab_create_interface(GmWorldTab *obj) {
GtkWidget *image, *label, *button, *image_button;
GtkSettings *settings;
gint w, h;
GtkRcStyle *rcstyle;
image = gtk_image_new();
label = gtk_label_new("");
@ -98,13 +99,18 @@ gm_world_tab_create_interface(GmWorldTab *obj) {
gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click(GTK_BUTTON(button), FALSE);
rcstyle = gtk_rc_style_new();
rcstyle->xthickness = rcstyle->ythickness = 0;
gtk_widget_modify_style(button, rcstyle);
gtk_rc_style_unref(rcstyle);
gtk_container_add(GTK_CONTAINER(button), image_button);
gtk_box_pack_start(GTK_BOX(obj), image, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(obj), label, FALSE, FALSE, 0);
gtk_box_pack_end(GTK_BOX(obj), button, FALSE, FALSE, 0);
gtk_box_set_spacing(GTK_BOX(obj), 6);
gtk_box_set_spacing(GTK_BOX(obj), 3);
obj->priv->image = GTK_IMAGE(image);
obj->priv->label = GTK_LABEL(label);