Exemplo n.º 1
0
EditorFlags start_editor_from_filelist_full(const gchar *key, GList *list, const gchar *working_directory, EditorCallback cb, gpointer data)
{
	EditorFlags error;
	EditorDescription *editor;
	if (!key) return EDITOR_ERROR_EMPTY;

	editor = g_hash_table_lookup(editors, key);

	if (!editor) return EDITOR_ERROR_EMPTY;
	if (!list && !(editor->flags & EDITOR_NO_PARAM)) return EDITOR_ERROR_NO_FILE;

	error = editor_command_parse(editor, list, TRUE, NULL);

	if (EDITOR_ERRORS(error)) return error;

	error |= editor_command_start(editor, editor->name, list, working_directory, cb, data);

	if (EDITOR_ERRORS(error))
		{
		gchar *text = g_strdup_printf(_("%s\n\"%s\""), editor_get_error_str(error), editor->file);

		file_util_warning_dialog(_("Invalid editor command"), text, GTK_STOCK_DIALOG_ERROR, NULL);
		g_free(text);
		}

	return EDITOR_ERRORS(error);
}
Exemplo n.º 2
0
static gint collection_save_confirmed(FileDialog *fd, gint overwrite, CollectionData *cd)
{
	gchar *buf;

	if (isdir(fd->dest_path))
		{
		buf = g_strdup_printf(_("Specified path:\n%s\nis a folder, collections are files"), fd->dest_path);
		file_util_warning_dialog(_("Invalid filename"), buf, GTK_STOCK_DIALOG_INFO, GENERIC_DIALOG(fd)->dialog);
		g_free(buf);
		return FALSE;
		}

	if (!overwrite && isfile(fd->dest_path))
		{
		GenericDialog *gd;

		gd = file_util_gen_dlg(_("Overwrite File"), "GQview", "dlg_confirm",
					GENERIC_DIALOG(fd)->dialog, TRUE,
					collection_confirm_cancel_cb, fd);

		generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION,
					   _("Overwrite existing file?"), fd->dest_path);

		generic_dialog_add_button(gd, GTK_STOCK_OK, _("_Overwrite"), collection_confirm_ok_cb, TRUE);

		gtk_widget_show(gd->dialog);

		return TRUE;
		}

	if (!collection_save(cd, fd->dest_path))
		{
		buf = g_strdup_printf(_("Failed to save the collection:\n%s"), fd->dest_path);
		file_util_warning_dialog(_("Save Failed"), buf, GTK_STOCK_DIALOG_ERROR, GENERIC_DIALOG(fd)->dialog);
		g_free(buf);
		}

	collection_unref(cd);
	file_dialog_sync_history(fd, TRUE);

	if (fd->type == DIALOG_SAVE_CLOSE) collection_window_close_by_collection(cd);
	file_dialog_close(fd);

	return TRUE;
}
Exemplo n.º 3
0
static gboolean editor_window_save(EditorWindow *ew)
{
	gchar *dir;
	gchar *path;
	gchar *text;
	GtkTextIter start, end;
	GError *error = NULL;
	gboolean ret = TRUE;
	const gchar *name = gtk_entry_get_text(GTK_ENTRY(ew->entry));
	
	if (!name || !name[0]) 
		{
		file_util_warning_dialog(_("Can't save"), _("Please specify file name."), GTK_STOCK_DIALOG_ERROR, NULL);
		return FALSE;
		}
	
	gtk_text_buffer_get_bounds(ew->buffer, &start, &end);
	text = gtk_text_buffer_get_text(ew->buffer, &start, &end, FALSE);

	dir = g_build_filename(get_rc_dir(), "applications", NULL);
	path = g_build_filename(dir, name, NULL);

	if (!recursive_mkdir_if_not_exists(dir, 0755))
		{
		file_util_warning_dialog(_("Can't save"), _("Could not create directory"), GTK_STOCK_DIALOG_ERROR, NULL);
		ret = FALSE;
		}

	if (ret && !g_file_set_contents(path, text, -1, &error)) 
		{
		file_util_warning_dialog(_("Can't save"), error->message, GTK_STOCK_DIALOG_ERROR, NULL);
		g_error_free(error);
		ret = FALSE;
		}
	
	g_free(path);
	g_free(dir);
	g_free(text);
	layout_editors_reload_start();
	/* idle function is not needed, everything should be cached */
	layout_editors_reload_finish(); 
	return ret;
}
Exemplo n.º 4
0
static void real_collection_button_pressed(FileDialog *fd, gpointer data, gint append)
{
	CollectionData *cd = data;
	gboolean err = FALSE;
	gchar *text = NULL;

	if (!isname(fd->dest_path))
		{
		err = TRUE;
		text = g_strdup_printf(_("No such file '%s'."), fd->dest_path);
		}
	if (!err && isdir(fd->dest_path))
		{
		err = TRUE;
		text = g_strdup_printf(_("'%s' is a directory, not a collection file."), fd->dest_path);
		}
	if (!err && !access_file(fd->dest_path, R_OK))
		{
		err = TRUE;
		text = g_strdup_printf(_("You do not have read permissions on the file '%s'."), fd->dest_path);
		}

	if (err) {
		if  (text)
			{
			file_util_warning_dialog(_("Can not open collection file"), text, GTK_STOCK_DIALOG_ERROR, NULL);
			g_free(text);
		}
		return;
	}

	if (append)
		{
		collection_load(cd, fd->dest_path, TRUE);
		collection_unref(cd);
		}
	else
		{
		collection_window_new(fd->dest_path);
		}

	file_dialog_sync_history(fd, TRUE);
	file_dialog_close(fd);
}
Exemplo n.º 5
0
void collection_dialog_save_as(gchar *path, CollectionData *cd)
{
#if 0
	if (!cd->list)
		{
		GtkWidget *parent = NULL;
		CollectWindow *cw;

		cw = collection_window_find(cd);
		if (cw) parent = cw->window;
		file_util_warning_dialog(_("Collection empty"),
					 _("The current collection is empty, save aborted."),
					 GTK_STOCK_DIALOG_INFO, parent);
		return;
		}
#endif

	if (!path) path = cd->path;
	if (!path) path = cd->name;

	collection_save_or_load_dialog(path, DIALOG_SAVE, cd);
}