1998-07-11 04:35:57 +08:00
|
|
|
/* docindex.c - Creates the window used by the document index in go and gimp.
|
1998-07-08 17:04:33 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Chris Lahey.
|
|
|
|
*
|
|
|
|
* 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, 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.
|
|
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "docindexif.h"
|
|
|
|
#include "docindex.h"
|
1999-08-22 19:45:31 +08:00
|
|
|
#include "gimpdnd.h"
|
1999-05-07 22:21:38 +08:00
|
|
|
#include "gimprc.h"
|
1999-02-21 07:20:54 +08:00
|
|
|
|
1999-03-07 21:23:06 +08:00
|
|
|
#include "libgimp/gimpenv.h"
|
1999-07-10 19:53:42 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1999-03-07 21:23:06 +08:00
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
idea_manager *ideas = NULL;
|
|
|
|
static GList *idea_list = NULL; /* of gchar *. */
|
1998-08-16 17:04:03 +08:00
|
|
|
static gint x = 0, y = 0, width = 0, height = 0;
|
1998-07-08 17:04:33 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static GtkTargetEntry drag_types[] =
|
|
|
|
{
|
|
|
|
GIMP_TARGET_URI_LIST
|
1998-10-20 06:01:25 +08:00
|
|
|
};
|
1999-08-22 19:45:31 +08:00
|
|
|
static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types[0]);
|
1998-07-08 17:04:33 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static void create_idea_list (void);
|
|
|
|
void docindex_configure_drop_on_widget (GtkWidget * widget);
|
|
|
|
void docindex_cell_configure_drop_on_widget (GtkWidget * widget);
|
1998-12-24 03:42:58 +08:00
|
|
|
|
1998-07-08 17:04:33 +08:00
|
|
|
|
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
docindex_dnd_filenames_dropped (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
1998-10-20 06:01:25 +08:00
|
|
|
GtkSelectionData *selection_data,
|
1999-08-22 19:45:31 +08:00
|
|
|
guint info,
|
|
|
|
guint time)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1998-10-20 06:01:25 +08:00
|
|
|
gint len;
|
|
|
|
gchar *data;
|
|
|
|
gchar *end;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
switch (info)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
case GIMP_DND_TYPE_URI_LIST:
|
1998-10-20 06:36:01 +08:00
|
|
|
data = (gchar *) selection_data->data;
|
1998-10-20 06:01:25 +08:00
|
|
|
len = selection_data->length;
|
1999-08-22 19:45:31 +08:00
|
|
|
while (len > 0)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
end = strstr (data, "\x0D\x0A");
|
|
|
|
if (end != NULL)
|
1998-10-20 06:01:25 +08:00
|
|
|
*end = 0;
|
1999-08-22 19:45:31 +08:00
|
|
|
if (*data != '#')
|
1998-10-20 06:36:01 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gchar *filename = strchr (data, ':');
|
|
|
|
if (filename != NULL)
|
1998-10-20 06:36:01 +08:00
|
|
|
filename ++;
|
|
|
|
else
|
|
|
|
filename = data;
|
1999-08-22 19:45:31 +08:00
|
|
|
open_file_in_position (filename, -1);
|
1998-10-20 06:36:01 +08:00
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
if (end)
|
1998-10-20 06:01:25 +08:00
|
|
|
{
|
|
|
|
len -= end - data + 2;
|
|
|
|
data = end + 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
len = 0;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
1998-10-20 06:01:25 +08:00
|
|
|
break;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
return;
|
1998-10-20 06:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
docindex_configure_drop_on_widget (GtkWidget * widget)
|
1998-10-20 06:01:25 +08:00
|
|
|
{
|
|
|
|
gtk_drag_dest_set (widget,
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
drag_types, n_drag_types,
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (widget), "drag_data_received",
|
|
|
|
GTK_SIGNAL_FUNC (docindex_dnd_filenames_dropped),
|
|
|
|
NULL);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
docindex_cell_dnd_filenames_dropped (GtkWidget *widget,
|
|
|
|
GdkDragContext *context,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
1998-10-20 06:01:25 +08:00
|
|
|
GtkSelectionData *selection_data,
|
1999-08-22 19:45:31 +08:00
|
|
|
guint info,
|
|
|
|
guint time)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1998-10-20 06:01:25 +08:00
|
|
|
gint len;
|
|
|
|
gchar *data;
|
|
|
|
gchar *end;
|
1999-08-22 19:45:31 +08:00
|
|
|
gint position = g_list_index (GTK_TREE (ideas->tree)->children, widget);
|
1998-10-20 06:01:25 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
switch (info)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
case GIMP_DND_TYPE_URI_LIST:
|
1998-10-20 06:36:01 +08:00
|
|
|
data = (gchar *) selection_data->data;
|
1998-10-20 06:01:25 +08:00
|
|
|
len = selection_data->length;
|
1999-08-22 19:45:31 +08:00
|
|
|
while (len > 0)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
end = strstr (data, "\x0D\x0A");
|
|
|
|
if (end != NULL)
|
1998-10-20 06:01:25 +08:00
|
|
|
*end = 0;
|
1999-08-22 19:45:31 +08:00
|
|
|
if (*data != '#')
|
1998-10-20 06:36:01 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gchar *filename = strchr (data, ':');
|
|
|
|
if (filename != NULL)
|
1998-10-20 06:36:01 +08:00
|
|
|
filename ++;
|
|
|
|
else
|
|
|
|
filename = data;
|
1999-08-22 19:45:31 +08:00
|
|
|
open_file_in_position (filename, position);
|
1998-10-20 06:36:01 +08:00
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
if (end)
|
1998-10-20 06:01:25 +08:00
|
|
|
{
|
|
|
|
len -= end - data + 2;
|
|
|
|
data = end + 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
len = 0;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
1998-10-20 06:01:25 +08:00
|
|
|
break;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
return;
|
1998-10-20 06:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
docindex_cell_configure_drop_on_widget (GtkWidget *widget)
|
1998-10-20 06:01:25 +08:00
|
|
|
{
|
|
|
|
gtk_drag_dest_set (widget,
|
|
|
|
GTK_DEST_DEFAULT_MOTION |
|
|
|
|
GTK_DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
GTK_DEST_DEFAULT_DROP,
|
|
|
|
drag_types, n_drag_types,
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (widget), "drag_data_received",
|
|
|
|
GTK_SIGNAL_FUNC (docindex_cell_dnd_filenames_dropped),
|
|
|
|
NULL);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1998-12-24 03:42:58 +08:00
|
|
|
gboolean
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_window_delete_event_callback (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (! exit_from_go ())
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
save_idea_manager (ideas);
|
|
|
|
create_idea_list ();
|
|
|
|
g_free (ideas);
|
1998-07-11 04:35:57 +08:00
|
|
|
ideas = 0;
|
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1998-07-08 17:04:33 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_hide_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (ideas || idea_list || width || height)
|
|
|
|
save_idea_manager (ideas);
|
1998-07-11 04:35:57 +08:00
|
|
|
|
|
|
|
/* False if exitting */
|
1999-08-22 19:45:31 +08:00
|
|
|
if ((! exit_from_go ()) && ideas)
|
1998-07-08 18:29:09 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
create_idea_list ();
|
|
|
|
gtk_widget_destroy (ideas->window);
|
|
|
|
g_free (ideas);
|
1998-07-08 18:29:09 +08:00
|
|
|
ideas = 0;
|
|
|
|
}
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
open_idea_window (void)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
make_idea_window (-1, -1);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
load_from_list (gpointer data,
|
|
|
|
gpointer data_null)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_add_in_position ((gchar *) data, -1);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
|
1999-05-07 22:21:38 +08:00
|
|
|
FILE *
|
|
|
|
idea_manager_parse_init (/* RETURNS: */
|
1999-08-22 19:45:31 +08:00
|
|
|
gint *window_x,
|
|
|
|
gint *window_y,
|
|
|
|
gint *window_width,
|
|
|
|
gint *window_height)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1998-07-11 04:35:57 +08:00
|
|
|
FILE *fp = NULL;
|
1998-07-08 17:04:33 +08:00
|
|
|
gchar *desktopfile;
|
1998-07-11 04:35:57 +08:00
|
|
|
|
1999-05-07 22:21:38 +08:00
|
|
|
desktopfile = gimp_personal_rc_file ("ideas");
|
1999-08-22 19:45:31 +08:00
|
|
|
fp = fopen (desktopfile, "r");
|
|
|
|
g_free (desktopfile);
|
1998-07-11 04:35:57 +08:00
|
|
|
|
1999-05-07 22:21:38 +08:00
|
|
|
/* Read in persistant desktop information. */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (fp)
|
1999-05-07 22:21:38 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
*window_x = getinteger (fp);
|
|
|
|
*window_y = getinteger (fp);
|
|
|
|
*window_width = getinteger (fp);
|
|
|
|
*window_height = getinteger (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
1999-05-07 22:21:38 +08:00
|
|
|
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
gchar *
|
|
|
|
idea_manager_parse_line (FILE * fp)
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gint length;
|
1999-05-07 22:21:38 +08:00
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
length = getinteger (fp);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (!feof (fp) && !ferror (fp))
|
1999-05-07 22:21:38 +08:00
|
|
|
{
|
|
|
|
filename = g_malloc0 (length + 1);
|
|
|
|
filename[fread (filename, 1, length, fp)] = 0;
|
|
|
|
clear_white (fp);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
load_idea_manager (idea_manager *ideas)
|
1999-05-07 22:21:38 +08:00
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
|
|
|
|
|
|
|
if ( ! idea_list )
|
|
|
|
fp = idea_manager_parse_init (&x, &y, &width, &height);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (idea_list || fp)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_widget_set_usize (ideas->window, width, height);
|
|
|
|
gtk_widget_show (ideas->window);
|
|
|
|
gtk_widget_set_uposition (ideas->window, x, y);
|
|
|
|
gtk_idle_add (reset_usize, ideas->window);
|
|
|
|
if (fp)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1998-07-11 04:35:57 +08:00
|
|
|
gchar *title;
|
1999-08-22 19:45:31 +08:00
|
|
|
clear_white (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
|
1999-05-07 22:21:38 +08:00
|
|
|
while ((title = idea_manager_parse_line (fp)))
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_add_in_position (title, -1);
|
|
|
|
g_free (title);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
fclose (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
g_list_foreach (idea_list, load_from_list, NULL);
|
|
|
|
g_list_foreach (idea_list, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (idea_list);
|
1998-07-11 04:35:57 +08:00
|
|
|
idea_list = 0;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_widget_show (ideas->window);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
save_to_ideas (gpointer data,
|
|
|
|
gpointer user_data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gchar *title = GTK_LABEL (GTK_BIN ((GtkWidget *) data)->child)->label;
|
|
|
|
|
|
|
|
fprintf ((FILE *) user_data, "%d %s\n", strlen (title), title);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
save_list_to_ideas (gpointer data,
|
|
|
|
gpointer user_data)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
|
|
|
gchar *title = (gchar *) data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
fprintf ((FILE *) user_data, "%d %s\n", strlen (title), title);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-08-22 19:45:31 +08:00
|
|
|
save_idea_manager (idea_manager *ideas)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
gchar *desktopfile;
|
|
|
|
|
|
|
|
/* open persistant desktop file. */
|
1999-03-07 20:56:03 +08:00
|
|
|
desktopfile = gimp_personal_rc_file ("ideas");
|
1999-08-22 19:45:31 +08:00
|
|
|
fp = fopen (desktopfile, "w");
|
|
|
|
g_free (desktopfile);
|
1998-07-08 17:04:33 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (fp)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (ideas)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gint x, y, width, height;
|
1998-07-11 04:35:57 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
gdk_window_get_geometry (ideas->window->window,
|
|
|
|
&x, &y, &width, &height, NULL);
|
|
|
|
gdk_window_get_origin (ideas->window->window, &x, &y);
|
|
|
|
|
|
|
|
fprintf (fp, "%d %d %d %d\n", x, y, width, height);
|
|
|
|
|
|
|
|
g_list_foreach (GTK_TREE (ideas->tree)->children, save_to_ideas, fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (idea_list)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
fprintf (fp, "%d %d %d %d\n", x, y, width, height);
|
|
|
|
|
|
|
|
g_list_foreach (idea_list, save_list_to_ideas, fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
fclose (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
save_to_list (gpointer data,
|
|
|
|
gpointer null_data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gchar *title = g_strdup (GTK_LABEL (GTK_BIN ((GtkWidget *) data)->child)->label);
|
|
|
|
idea_list = g_list_append (idea_list, title);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
create_idea_list (void)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gdk_window_get_geometry (ideas->window->window,
|
|
|
|
&x, &y, &width, &height, NULL);
|
|
|
|
gdk_window_get_origin (ideas->window->window, &x, &y);
|
1998-07-11 04:35:57 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (idea_list)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
g_list_foreach (idea_list, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (idea_list);
|
1998-07-11 04:35:57 +08:00
|
|
|
idea_list = 0;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
g_list_foreach (GTK_TREE (ideas->tree)->children, save_to_list, NULL);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
static gint
|
1999-08-22 19:45:31 +08:00
|
|
|
open_or_raise_callback (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer func_data )
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (GTK_IS_TREE_ITEM (widget) &&
|
|
|
|
event->type == GDK_2BUTTON_PRESS)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
open_or_raise (GTK_LABEL (GTK_BIN (widget)->child )->label);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
void
|
|
|
|
raise_idea_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (ideas)
|
|
|
|
gdk_window_raise (ideas->window->window);
|
1998-07-08 17:04:33 +08:00
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
open_idea_window ();
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static void
|
|
|
|
check_needed (gpointer data,
|
|
|
|
gpointer user_data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *widget = (GtkWidget *) data;
|
|
|
|
struct bool_char_pair *pair = (struct bool_char_pair *) user_data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (strcmp (pair->string, GTK_LABEL (GTK_BIN (widget)->child )->label) == 0)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
pair->boole = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static void
|
|
|
|
check_needed_list (gpointer data,
|
|
|
|
gpointer user_data)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
|
|
|
struct bool_char_pair *pair = (struct bool_char_pair *) user_data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (strcmp (pair->string, (gchar *) data ) == 0)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
|
|
|
pair->boole = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static void
|
|
|
|
idea_add_in_position_with_select (gchar *title,
|
|
|
|
gint position,
|
|
|
|
gboolean select )
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *treeitem;
|
|
|
|
struct bool_char_pair pair;
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
pair.boole = FALSE;
|
|
|
|
pair.string = title;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (ideas)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
g_list_foreach (GTK_TREE (ideas->tree)->children, check_needed, &pair);
|
|
|
|
|
|
|
|
if (! pair.boole)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
treeitem = gtk_tree_item_new_with_label (title);
|
|
|
|
if (position < 0)
|
|
|
|
gtk_tree_append (GTK_TREE (ideas->tree), treeitem);
|
1998-07-08 17:04:33 +08:00
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_tree_insert (GTK_TREE (ideas->tree), treeitem, position);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (treeitem),
|
1998-07-08 17:04:33 +08:00
|
|
|
"button_press_event",
|
1999-08-22 19:45:31 +08:00
|
|
|
GTK_SIGNAL_FUNC (open_or_raise_callback),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
docindex_cell_configure_drop_on_widget (treeitem);
|
|
|
|
|
|
|
|
gtk_widget_show (treeitem);
|
|
|
|
|
|
|
|
if (select)
|
|
|
|
gtk_tree_select_item (GTK_TREE (ideas->tree),
|
|
|
|
gtk_tree_child_position (GTK_TREE (ideas->tree ), treeitem));
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
}
|
1998-07-11 04:35:57 +08:00
|
|
|
else
|
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (! idea_list)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
|
|
|
gchar *desktopfile;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
/* open persistant desktop file. */
|
1999-03-07 20:56:03 +08:00
|
|
|
desktopfile = gimp_personal_rc_file ("ideas");
|
1999-08-22 19:45:31 +08:00
|
|
|
fp = fopen (desktopfile, "r");
|
|
|
|
g_free (desktopfile);
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
/* Read in persistant desktop information. */
|
1999-08-22 19:45:31 +08:00
|
|
|
if (fp)
|
|
|
|
{
|
1998-07-11 04:35:57 +08:00
|
|
|
gchar *title;
|
|
|
|
gint length;
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
x = getinteger (fp);
|
|
|
|
y = getinteger (fp);
|
|
|
|
width = getinteger (fp);
|
|
|
|
height = getinteger (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
clear_white (fp);
|
|
|
|
|
|
|
|
while (!feof (fp) && !ferror (fp))
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
length = getinteger (fp);
|
|
|
|
title = g_malloc0 (length + 1);
|
|
|
|
title[fread (title, 1, length, fp)] = 0;
|
|
|
|
idea_list = g_list_append (idea_list, g_strdup (title));
|
|
|
|
g_free (title);
|
|
|
|
clear_white (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
fclose (fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
g_list_foreach (idea_list, check_needed_list, &pair);
|
|
|
|
|
|
|
|
if (! pair.boole)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
if (position < 0)
|
|
|
|
idea_list = g_list_append (idea_list, g_strdup (title));
|
1998-07-11 04:35:57 +08:00
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_list = g_list_insert (idea_list, g_strdup (title), position);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
}
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
void
|
|
|
|
idea_add (gchar *title)
|
|
|
|
{
|
|
|
|
idea_add_in_position (title, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
idea_add_in_position (gchar *title,
|
|
|
|
gint position)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_add_in_position_with_select (title, position, TRUE);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static gint
|
|
|
|
idea_move (GtkWidget *widget,
|
|
|
|
gint distance,
|
|
|
|
gboolean select)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gint orig_position = g_list_index (GTK_TREE (ideas->tree)->children, widget);
|
1998-07-08 17:04:33 +08:00
|
|
|
gint position = orig_position + distance;
|
|
|
|
gchar *title;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (position < 0)
|
1998-07-08 17:04:33 +08:00
|
|
|
position = 0;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (position >= g_list_length (GTK_TREE (ideas->tree)->children))
|
|
|
|
position = g_list_length (GTK_TREE (ideas->tree)->children) - 1;
|
|
|
|
|
|
|
|
if (position != orig_position)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
title = g_strdup (GTK_LABEL (GTK_BIN (widget)->child )->label);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (ideas->tree), widget);
|
|
|
|
idea_add_in_position_with_select (title, position, select);
|
|
|
|
g_free (title);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
1999-08-22 19:45:31 +08:00
|
|
|
|
1998-07-08 17:04:33 +08:00
|
|
|
return position - orig_position;
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static void
|
|
|
|
idea_remove (GtkWidget *widget)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
gint position = g_list_index (GTK_TREE (ideas->tree )->children, widget);
|
|
|
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (ideas->tree), widget);
|
|
|
|
|
|
|
|
if (g_list_length (GTK_TREE (ideas->tree)->children) - 1 < position)
|
|
|
|
position = g_list_length (GTK_TREE (ideas->tree)->children) - 1;
|
|
|
|
|
|
|
|
gtk_tree_select_item (GTK_TREE (ideas->tree), position);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
void
|
|
|
|
idea_up_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (GTK_TREE (ideas->tree)->selection)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
selected = GTK_TREE (ideas->tree)->selection->data;
|
|
|
|
if (idea_move (selected, -1, TRUE) != -1)
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (ideas->status), ideas->contextid,
|
|
|
|
_("This file cannot be moved up."));
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (ideas->status), ideas->contextid,
|
|
|
|
_("There's no selection to move up."));
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
void
|
|
|
|
idea_down_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (GTK_TREE (ideas->tree)->selection)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
selected = GTK_TREE (ideas->tree)->selection->data;
|
|
|
|
if (idea_move (selected, 1, TRUE) != 1)
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (ideas->status), ideas->contextid,
|
|
|
|
_("This file cannot be moved down."));
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (ideas->status), ideas->contextid,
|
|
|
|
_("There's no selection to move down."));
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
void
|
|
|
|
idea_remove_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (GTK_TREE (ideas->tree)->selection)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
selected = GTK_TREE (ideas->tree)->selection->data;
|
|
|
|
idea_remove (selected);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
else
|
1999-08-22 19:45:31 +08:00
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (ideas->status), ideas->contextid,
|
|
|
|
_("There's no selection to remove."));
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
1998-07-11 04:35:57 +08:00
|
|
|
|
|
|
|
void
|
1998-08-16 17:04:03 +08:00
|
|
|
close_idea_window( void )
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_hide_callback (NULL, NULL);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|