Commit 36357280 authored by Manish Singh's avatar Manish Singh
Browse files

app/Makefile.am app/errors.c app/errorconsole.[ch] app/app_procs.c

* app/Makefile.am
* app/errors.c
* app/errorconsole.[ch]
* app/app_procs.c
* app/appenv.h
* app/menus.c: error console implementation from Nuke <nuke@bayside.net>
Hooks to g_message

* app/fileops.c: honor message_handler while still setting filesel widget
sensitivity properly

-Yosh
parent ef3e0fa7
Tue Jul 28 14:03:57 PDT 1998 Manish Singh <yosh@gimp.org>
* app/Makefile.am
* app/errors.c
* app/errorconsole.[ch]
* app/app_procs.c
* app/appenv.h
* app/menus.c: error console implementation from Nuke
<nuke@bayside.net> Hooks to g_message
* app/fileops.c: honor message_handler while still setting
filesel widget sensitivity properly
Tue Jul 28 15:04:39 CDT 1998 Larry Ewing <lewing@gimp.org>
* app/gimpdrawable.h: reordered the GimpFillType enum,
......
......@@ -108,6 +108,8 @@ gimp_SOURCES = \
ellipse_select.h \
eraser.c \
eraser.h \
errorconsole.c \
errorconsole.h \
errors.c \
errors.h \
equalize.c \
......
......@@ -534,6 +534,7 @@ app_init (void)
render_setup (transparency_type, transparency_size);
tools_options_dialog_new ();
tools_select (RECT_SELECT);
/* FIXME: This needs to go in preferences */
message_handler = MESSAGE_BOX;
}
......
......@@ -39,7 +39,8 @@
typedef enum {
MESSAGE_BOX,
CONSOLE
CONSOLE,
ERROR_CONSOLE
} MessageHandlerType;
extern int no_interface;
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* errorconsole.c - text window for collecting error messages
* Copyright (C) 1998 Nick Fetchak <nuke@bayside.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "gtk/gtk.h"
#define ERRORS_ALL 0
#define ERRORS_SELECTION 1
void error_console_add (gchar *errormsg);
void error_console_show_callback (GtkWidget *widget,
gpointer data);
static GtkWidget *dialog;
static GtkWidget *text;
static gint
error_console_close_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
gdk_window_hide (dialog->window);
return TRUE;
}
gint
error_console_write_file (gchar *path, gint textscope)
{
gint fd;
gint text_length;
gint bytes_written;
gchar *text_contents;
GtkText *gtext;
gtext = GTK_TEXT(text);
fd = open (path, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
if (fd == -1)
return FALSE;
if (textscope == ERRORS_ALL)
{
text_contents =
gtk_editable_get_chars (GTK_EDITABLE (text), 0,
gtk_text_get_length (GTK_TEXT (text)));
}
else
{
gint selection_start, selection_end, temp;
selection_start = GTK_TEXT (text)->editable.selection_start_pos;
selection_end = GTK_TEXT (text)->editable.selection_end_pos;
if (selection_start > selection_end)
{
temp = selection_start;
selection_start = selection_end;
selection_end = temp;
}
text_contents = gtk_editable_get_chars (GTK_EDITABLE (text),
selection_start,
selection_end);
}
text_length = strlen (text_contents);
if (text_contents && (text_length > 0))
{
bytes_written = write (fd, text_contents, text_length);
g_free (text_contents);
close (fd);
if (bytes_written != text_length)
return FALSE;
else
return TRUE;
}
close (fd);
return TRUE;
}
static void
error_console_file_ok_callback (GtkWidget *widget, gpointer data)
{
GtkWidget *filesel;
gchar *filename;
gint textscope;
filesel = (GtkWidget *) data;
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (filesel));
textscope = (gint) gtk_object_get_user_data (GTK_OBJECT (filesel));
if (!error_console_write_file (filename, textscope))
{
GString *string;
g_string_new ("");
g_string_sprintf (string, "Error opening file %s: %s", filename, g_strerror (errno));
g_message (string->str);
g_string_free (string, TRUE);
}
else
gtk_widget_destroy (filesel);
}
static void
error_console_menu_callback (gint textscope)
{
GtkWidget *filesel;
if (!(GTK_TEXT (text)->editable.has_selection) && (textscope == ERRORS_SELECTION))
{
g_message ("Can't save, nothing selected!");
return;
}
filesel = gtk_file_selection_new ("Save error log to file...");
gtk_window_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);
gtk_window_set_wmclass (GTK_WINDOW (filesel), "save_errors", "Gimp");
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
"clicked", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (filesel));
gtk_object_set_user_data (GTK_OBJECT (filesel), (gpointer) textscope);
gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
"clicked", (GtkSignalFunc) error_console_file_ok_callback,
filesel);
gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
"delete_event", (GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (filesel));
gtk_widget_show (filesel);
}
static gint
text_clicked_callback (GtkWidget *widget,
GdkEventButton *event,
gpointer data)
{
GtkMenu *menu = (GtkMenu *) data;
GtkText *gtext;
gtext = GTK_TEXT (text);
if (event->button == 3)
{
gtk_signal_emit_stop_by_name (GTK_OBJECT (text), "button_press_event");
gtk_menu_popup(menu, NULL, NULL, NULL, NULL, event->button, time(NULL));
}
return TRUE;
}
static void
error_console_create_window (void)
{
GtkWidget *button;
GtkWidget *table;
GtkWidget *vscrollbar;
GtkWidget *menu;
GtkWidget *menuitem;
dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW (dialog), "GIMP Error console");
gtk_widget_set_usize (dialog, 250, 300);
gtk_window_set_policy (GTK_WINDOW(dialog), TRUE, TRUE, FALSE);
gtk_signal_connect (GTK_OBJECT (dialog), "delete_event",
(GtkSignalFunc) error_console_close_callback, NULL);
gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), 2);
gtk_container_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 2);
/* Action area */
button = gtk_button_new_with_label ("Close");
gtk_signal_connect (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) error_console_close_callback, NULL);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), button, TRUE, TRUE, 0);
gtk_widget_show (button);
menu = gtk_menu_new ();
menuitem = gtk_menu_item_new_with_label ("Write all errors to file...");
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect_object (GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) error_console_menu_callback,
(gpointer) ERRORS_ALL);
gtk_widget_show (menuitem);
menuitem = gtk_menu_item_new_with_label ("Write selection to file...");
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_signal_connect_object (GTK_OBJECT(menuitem), "activate",
(GtkSignalFunc) error_console_menu_callback,
(gpointer) ERRORS_SELECTION);
gtk_widget_show (menuitem);
table = gtk_table_new (2, 2, FALSE);
gtk_table_set_row_spacing (GTK_TABLE (table), 0, 2);
gtk_table_set_col_spacing (GTK_TABLE (table), 0, 2);
gtk_container_border_width (GTK_CONTAINER (table), 0);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table, TRUE, TRUE, 0);
gtk_widget_show (table);
/* The output text widget */
text = gtk_text_new (NULL, NULL);
gtk_text_set_editable (GTK_TEXT (text), FALSE);
gtk_text_set_word_wrap (GTK_TEXT (text), TRUE);
gtk_table_attach (GTK_TABLE (table), text, 0, 1, 0, 1,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_set_events (text, GDK_BUTTON_PRESS_MASK);
gtk_signal_connect (GTK_OBJECT (text), "button_press_event",
GTK_SIGNAL_FUNC (text_clicked_callback), GTK_MENU (menu));
gtk_widget_show (text);
vscrollbar = gtk_vscrollbar_new (GTK_TEXT (text)->vadj);
gtk_table_attach (GTK_TABLE (table), vscrollbar, 1, 2, 0, 1,
GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (vscrollbar);
gtk_widget_show (dialog);
}
void
error_console_add (gchar *errormsg)
{
if (!dialog)
error_console_create_window ();
gdk_window_show (dialog->window);
gdk_window_raise (dialog->window);
if (errormsg)
{
gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, errormsg, -1);
gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, "\n", -1);
}
}
void error_console_show_callback (GtkWidget *widget, gpointer data)
{
error_console_add (NULL);
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* errorconsole.h - text window for collecting error messages
* Copyright (C) 1998 Nick Fetchak <nuke@bayside.net>
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __ERRORCONSOLE_H__
#define __ERRORCONSOLE_H__
void error_console_add (gchar *errormsg);
void error_console_show_callback (GtkWidget *widget,
gpointer data);
#endif /* __ERRORCONSOLE_H__ */
......@@ -28,6 +28,7 @@
#include "appenv.h"
#include "app_procs.h"
#include "interface.h"
#include "errorconsole.h"
#include "errors.h"
extern char *prog_name;
......@@ -35,10 +36,23 @@ extern char *prog_name;
void
message_func (char *str)
{
if ((console_messages == FALSE) && (message_handler == MESSAGE_BOX))
message_box (str, NULL, NULL);
if (console_messages == FALSE)
switch (message_handler)
{
case MESSAGE_BOX:
message_box (str, NULL, NULL);
break;
case ERROR_CONSOLE:
error_console_add (str);
break;
default:
fprintf (stderr, "%s: %s\n", prog_name, str);
break;
}
else
fprintf (stderr, "%s: %s\n", prog_name, str);
fprintf (stderr, "%s: %s\n", prog_name, str);
}
void
......
......@@ -302,6 +302,13 @@ static PlugInProcDef *save_file_proc = NULL;
static GimpImage* the_gimage;
#define FILE_ERR_MESSAGE(str) G_STMT_START{ \
if (message_handler == MESSAGE_BOX) \
message_box ((str), file_message_box_close_callback, (void *) fs); \
else \
g_message (str); \
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE); }G_STMT_END
static void
file_message_box_close_callback (GtkWidget *w,
gpointer client_data)
......@@ -869,7 +876,7 @@ file_open_ok_callback (GtkWidget *w,
{
s = g_string_new ("Open failed: ");
g_string_append (s, raw_filename);
message_box (s->str, file_message_box_close_callback, (void *) fs);
FILE_ERR_MESSAGE (s->str);
g_string_free (s, TRUE);
}
......@@ -957,7 +964,7 @@ file_open_ok_callback (GtkWidget *w,
{
s = g_string_new ("Open failed: ");
g_string_append (s, temp);
message_box (s->str, file_message_box_close_callback, (void *) fs);
FILE_ERR_MESSAGE (s->str);
g_string_free (s, TRUE);
}
}
......@@ -1037,8 +1044,7 @@ file_save_ok_callback (GtkWidget *w,
g_string_append (s, raw_filename);
}
}
message_box (s->str, file_message_box_close_callback, (void *) fs);
FILE_ERR_MESSAGE (s->str);
g_string_free (s, TRUE);
}
......@@ -1135,12 +1141,12 @@ file_overwrite_yes_callback (GtkWidget *w,
else
{
GString* s;
GtkWidget *fs;
fs = filesave;
s = g_string_new ("Save failed: ");
g_string_append (s, overwrite_box->raw_filename);
message_box (s->str, file_message_box_close_callback, (void *) filesave);
FILE_ERR_MESSAGE (s->str);
g_string_free (s, TRUE);
}
......
......@@ -21,6 +21,7 @@
#include "appenv.h"
#include "colormaps.h"
#include "commands.h"
#include "errorconsole.h"
#include "fileops.h"
#include "general.h"
#include "gimprc.h"
......@@ -57,6 +58,7 @@ static GtkItemFactoryEntry toolbox_entries[] =
{ "/File/Dialogs/Input Devices...", NULL, dialogs_input_devices_cmd_callback, 0 },
{ "/File/Dialogs/Device Status...", NULL, dialogs_device_status_cmd_callback, 0 },
{ "/File/Dialogs/Document Index...", NULL, raise_idea_callback, 0 },
{ "/File/Dialogs/Error Console...", NULL, error_console_show_callback, 0 },
{ "/File/---", NULL, NULL, 0, "<Separator>" },
};
static guint n_toolbox_entries = sizeof (toolbox_entries) / sizeof (toolbox_entries[0]);
......
......@@ -21,6 +21,7 @@
#include "appenv.h"
#include "colormaps.h"
#include "commands.h"
#include "errorconsole.h"
#include "fileops.h"
#include "general.h"
#include "gimprc.h"
......@@ -57,6 +58,7 @@ static GtkItemFactoryEntry toolbox_entries[] =
{ "/File/Dialogs/Input Devices...", NULL, dialogs_input_devices_cmd_callback, 0 },
{ "/File/Dialogs/Device Status...", NULL, dialogs_device_status_cmd_callback, 0 },
{ "/File/Dialogs/Document Index...", NULL, raise_idea_callback, 0 },
{ "/File/Dialogs/Error Console...", NULL, error_console_show_callback, 0 },
{ "/File/---", NULL, NULL, 0, "<Separator>" },
};
static guint n_toolbox_entries = sizeof (toolbox_entries) / sizeof (toolbox_entries[0]);
......
......@@ -21,6 +21,7 @@
#include "appenv.h"
#include "colormaps.h"
#include "commands.h"
#include "errorconsole.h"
#include "fileops.h"
#include "general.h"
#include "gimprc.h"
......@@ -57,6 +58,7 @@ static GtkItemFactoryEntry toolbox_entries[] =
{ "/File/Dialogs/Input Devices...", NULL, dialogs_input_devices_cmd_callback, 0 },
{ "/File/Dialogs/Device Status...", NULL, dialogs_device_status_cmd_callback, 0 },
{ "/File/Dialogs/Document Index...", NULL, raise_idea_callback, 0 },
{ "/File/Dialogs/Error Console...", NULL, error_console_show_callback, 0 },
{ "/File/---", NULL, NULL, 0, "<Separator>" },
};
static guint n_toolbox_entries = sizeof (toolbox_entries) / sizeof (toolbox_entries[0]);
......
......@@ -21,6 +21,7 @@
#include "appenv.h"
#include "colormaps.h"
#include "commands.h"
#include "errorconsole.h"
#include "fileops.h"
#include "general.h"
#include "gimprc.h"
......@@ -57,6 +58,7 @@ static GtkItemFactoryEntry toolbox_entries[] =
{ "/File/Dialogs/Input Devices...", NULL, dialogs_input_devices_cmd_callback, 0 },
{ "/File/Dialogs/Device Status...", NULL, dialogs_device_status_cmd_callback, 0 },
{ "/File/Dialogs/Document Index...", NULL, raise_idea_callback, 0 },
{ "/File/Dialogs/Error Console...", NULL, error_console_show_callback, 0 },
{ "/File/---", NULL, NULL, 0, "<Separator>" },
};
static guint n_toolbox_entries = sizeof (toolbox_entries) / sizeof (toolbox_entries[0]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment