Add --editable option to --text-info, and return edited textbuffer contents on dialog close.

This commit is contained in:
Mike Newman 2003-01-19 12:13:08 +00:00
parent 3eafefdeb0
commit 1e1dfef56e
5 changed files with 50 additions and 3 deletions

View File

@ -1,6 +1,8 @@
2003-01-19 Ole Laursen <olau@hardworking.dk>
2003-01-19 Mike Newman <mike@gtnorthern.demon.co.uk>
* configure.in: Added da to ALL_LINGUAS.
* src/main.c, src/text.c, src/zenity.h: add an --editable
option to --text-info. If set, return the contents of the
text buffer on dialog close.
2003-01-18 Glynn Foster <glynn.foster@sun.com>

View File

@ -629,6 +629,13 @@
</listitem>
</varlistentry>
<varlistentry>
<term><varname>--editable</varname></term>
<listitem>
<para>Allow the displayed text to be edited and returned when the dialog is closed.</para>
</listitem>
</varlistentry>
</variablelist>
<figure id="zenity-text-screenshot">

View File

@ -65,6 +65,7 @@ enum {
OPTION_PROGRESS,
OPTION_QUESTION,
OPTION_TEXTINFO,
OPTION_TEXTEDIT,
OPTION_WARNING,
OPTION_TITLE,
OPTION_ICON,
@ -517,6 +518,15 @@ struct poptOption text_options[] = {
N_("Open file"),
N_("FILENAME")
},
{
"editable",
'\0',
POPT_ARG_NONE,
NULL,
OPTION_TEXTEDIT,
N_("Allow changes to text"),
NULL
},
POPT_TABLEEND
};
@ -727,6 +737,7 @@ zenity_init_parsing_options (void) {
results->calendar_data->month = 0;
results->calendar_data->year = 0;
results->calendar_data->dialog_text = NULL;
results->text_data->editable = FALSE;
results->tree_data->separator = g_strdup ("/");
results->progress_data->percentage = -1;
results->progress_data->pulsate = FALSE;
@ -1108,6 +1119,19 @@ void zenity_parse_options_callback (poptContext ctx,
}
results->entry_data->visible = FALSE;
break;
case OPTION_TEXTEDIT:
if (results->mode != MODE_TEXTINFO) {
g_printerr (_("--editable is not supported for this dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
if (results->text_data->editable == TRUE) {
g_printerr (_("--editable given twice for the same dialog\n"));
zenity_free_parsing_options ();
exit (-1);
}
results->text_data->editable = TRUE;
break;
case OPTION_FILENAME:
case OPTION_TEXTFILE:

View File

@ -25,6 +25,8 @@
#include "zenity.h"
#include "util.h"
static ZenityTextData *zen_text_data;
static void zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data);
void
@ -35,6 +37,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
GtkWidget *text_view;
GtkTextBuffer *text_buffer;
zen_text_data = text_data;
glade_dialog = zenity_util_load_glade_file ("zenity_text_dialog");
if (glade_dialog == NULL) {
@ -63,7 +66,10 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
text_view = glade_xml_get_widget (glade_dialog, "zenity_text_view");
if (zenity_util_fill_file_buffer (text_buffer, text_data->uri))
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), text_buffer);
gtk_text_view_set_editable (GTK_TEXT_VIEW(text_view), text_data->editable);
if (text_data->editable) {
zen_text_data->buffer = text_buffer;
}
gtk_widget_show (dialog);
if (glade_dialog)
@ -79,6 +85,12 @@ zenity_text_dialog_response (GtkWidget *widget, int response, gpointer data)
switch (response) {
case GTK_RESPONSE_CLOSE:
if (zen_text_data->editable) {
GtkTextIter start,end;
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
g_printerr (gtk_text_buffer_get_text (zen_text_data->buffer, &start, &end, 0));
}
zen_data->exit_code = 0;
gtk_main_quit ();
break;

View File

@ -68,6 +68,8 @@ typedef struct {
typedef struct {
gchar *uri;
gboolean editable;
GtkTextBuffer *buffer;
} ZenityTextData;
typedef struct {