Added a filter to the open dialog
This commit is contained in:
parent
5afa144cd1
commit
b15aed82c4
|
@ -380,24 +380,22 @@ void xmleditor_expand_all(XMLEditor * xmleditor)
|
||||||
static void _open_document_node(XMLEditor * xmleditor, XMLNode * node,
|
static void _open_document_node(XMLEditor * xmleditor, XMLNode * node,
|
||||||
GtkTreeIter * parent);
|
GtkTreeIter * parent);
|
||||||
|
|
||||||
void xmleditor_open(XMLEditor * xmleditor, char const * filename)
|
int xmleditor_open(XMLEditor * xmleditor, char const * filename)
|
||||||
{
|
{
|
||||||
XMLDocument * doc;
|
XMLDocument * doc;
|
||||||
|
|
||||||
/* FIXME handle errors */
|
/* FIXME handle errors */
|
||||||
gtk_tree_store_clear(xmleditor->store);
|
gtk_tree_store_clear(xmleditor->store);
|
||||||
if(filename == NULL)
|
if(filename == NULL)
|
||||||
return;
|
return xmleditor_open_dialog(xmleditor);
|
||||||
if(xmleditor->xml != NULL)
|
if(xmleditor->xml != NULL)
|
||||||
xml_delete(xmleditor->xml);
|
xml_delete(xmleditor->xml);
|
||||||
if((xmleditor->xml = xml_new(NULL, filename)) == NULL)
|
if((xmleditor->xml = xml_new(NULL, filename)) == NULL)
|
||||||
{
|
return -xmleditor_error(xmleditor, error_get(), 1);
|
||||||
xmleditor_error(xmleditor, error_get(), 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if((doc = xml_get_document(xmleditor->xml)) != NULL)
|
if((doc = xml_get_document(xmleditor->xml)) != NULL)
|
||||||
_open_document_node(xmleditor, doc->root, NULL);
|
_open_document_node(xmleditor, doc->root, NULL);
|
||||||
_new_set_title(xmleditor); /* XXX make it a generic private function */
|
_new_set_title(xmleditor); /* XXX make it a generic private function */
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _open_document_node(XMLEditor * xmleditor, XMLNode * node,
|
static void _open_document_node(XMLEditor * xmleditor, XMLNode * node,
|
||||||
|
@ -445,9 +443,11 @@ static void _open_document_node(XMLEditor * xmleditor, XMLNode * node,
|
||||||
|
|
||||||
|
|
||||||
/* xmleditor_open_dialog */
|
/* xmleditor_open_dialog */
|
||||||
void xmleditor_open_dialog(XMLEditor * xmleditor)
|
int xmleditor_open_dialog(XMLEditor * xmleditor)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
GtkWidget * dialog;
|
GtkWidget * dialog;
|
||||||
|
GtkFileFilter * filter;
|
||||||
char * filename = NULL;
|
char * filename = NULL;
|
||||||
|
|
||||||
dialog = gtk_file_chooser_dialog_new(_("Open file..."),
|
dialog = gtk_file_chooser_dialog_new(_("Open file..."),
|
||||||
|
@ -455,14 +455,23 @@ void xmleditor_open_dialog(XMLEditor * xmleditor)
|
||||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
|
||||||
|
filter = gtk_file_filter_new();
|
||||||
|
gtk_file_filter_set_name(filter, _("XML files"));
|
||||||
|
gtk_file_filter_add_mime_type(filter, "text/xml");
|
||||||
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
||||||
|
filter = gtk_file_filter_new();
|
||||||
|
gtk_file_filter_set_name(filter, _("All files"));
|
||||||
|
gtk_file_filter_add_pattern(filter, "*");
|
||||||
|
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
||||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
|
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
|
||||||
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(
|
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(
|
||||||
dialog));
|
dialog));
|
||||||
gtk_widget_destroy(dialog);
|
gtk_widget_destroy(dialog);
|
||||||
if(filename == NULL)
|
if(filename == NULL)
|
||||||
return;
|
return -1;
|
||||||
xmleditor_open(xmleditor, filename);
|
ret = xmleditor_open(xmleditor, filename);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
|
/* Copyright (c) 2010-2012 Pierre Pronchery <khorben@defora.org> */
|
||||||
/* This file is part of DeforaOS Desktop XMLEditor */
|
/* This file is part of DeforaOS Desktop XMLEditor */
|
||||||
/* This program is free software; you can redistribute it and/or modify
|
/* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
# include <gtk/gtk.h>
|
# include <gtk/gtk.h>
|
||||||
|
|
||||||
|
|
||||||
/* Editor */
|
/* XMLEditor */
|
||||||
/* types */
|
/* types */
|
||||||
typedef struct _XMLEditor XMLEditor;
|
typedef struct _XMLEditor XMLEditor;
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ void xmleditor_about(XMLEditor * xmleditor);
|
||||||
int xmleditor_error(XMLEditor * xmleditor, char const * message, int ret);
|
int xmleditor_error(XMLEditor * xmleditor, char const * message, int ret);
|
||||||
|
|
||||||
gboolean xmleditor_close(XMLEditor * xmleditor);
|
gboolean xmleditor_close(XMLEditor * xmleditor);
|
||||||
void xmleditor_open(XMLEditor * xmleditor, char const * filename);
|
int xmleditor_open(XMLEditor * xmleditor, char const * filename);
|
||||||
void xmleditor_open_dialog(XMLEditor * xmleditor);
|
int xmleditor_open_dialog(XMLEditor * xmleditor);
|
||||||
|
|
||||||
void xmleditor_collapse_all(XMLEditor * xmleditor);
|
void xmleditor_collapse_all(XMLEditor * xmleditor);
|
||||||
void xmleditor_expand_all(XMLEditor * xmleditor);
|
void xmleditor_expand_all(XMLEditor * xmleditor);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user