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.
|
|
|
|
*/
|
2000-05-05 22:53:38 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
#include <ctype.h>
|
1998-07-08 17:04:33 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
1999-02-21 07:20:54 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2000-05-05 21:29:46 +08:00
|
|
|
#include "dialog_handler.h"
|
1999-02-21 07:20:54 +08:00
|
|
|
#include "docindex.h"
|
2000-05-07 00:35:21 +08:00
|
|
|
#include "fileops.h"
|
2000-05-07 03:25:53 +08:00
|
|
|
#include "gimpui.h"
|
1999-08-22 19:45:31 +08:00
|
|
|
#include "gimpdnd.h"
|
2000-05-07 03:25:53 +08:00
|
|
|
#include "ops_buttons.h"
|
2000-05-05 22:53:38 +08:00
|
|
|
#include "session.h"
|
1999-02-21 07:20:54 +08:00
|
|
|
|
1999-03-07 21:23:06 +08:00
|
|
|
#include "libgimp/gimpenv.h"
|
2000-05-05 22:53:38 +08:00
|
|
|
|
1999-07-10 19:53:42 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
1999-03-07 21:23:06 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
#include "pixmaps/folder.xpm"
|
|
|
|
#include "pixmaps/raise.xpm"
|
|
|
|
#include "pixmaps/lower.xpm"
|
|
|
|
#include "pixmaps/delete.xpm"
|
|
|
|
|
2000-05-05 22:53:38 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *list;
|
|
|
|
} IdeaManager;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean boole;
|
|
|
|
gchar *string;
|
|
|
|
gpointer data;
|
|
|
|
} BoolCharPair;
|
|
|
|
|
|
|
|
|
|
|
|
/* forward declarations */
|
1998-07-08 17:04:33 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void create_idea_list (void);
|
|
|
|
static void idea_add_in_position (gchar *label,
|
|
|
|
gint position);
|
|
|
|
static void open_idea_window (void);
|
2000-05-07 03:25:53 +08:00
|
|
|
static void open_or_raise (gchar *file_name,
|
|
|
|
gboolean try_raise);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
static void idea_open_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void idea_open_or_raise_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2000-05-07 00:35:21 +08:00
|
|
|
static void idea_up_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2000-05-07 03:25:53 +08:00
|
|
|
static void idea_to_top_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2000-05-07 00:35:21 +08:00
|
|
|
static void idea_down_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2000-05-07 03:25:53 +08:00
|
|
|
static void idea_to_bottom_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2000-05-07 00:35:21 +08:00
|
|
|
static void idea_remove_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void idea_hide_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static void load_idea_manager (IdeaManager *ideas);
|
|
|
|
static void save_idea_manager (IdeaManager *ideas);
|
|
|
|
|
|
|
|
static void clear_white (FILE *fp);
|
|
|
|
static gint getinteger (FILE *fp);
|
|
|
|
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
/* local variables */
|
|
|
|
|
|
|
|
static IdeaManager *ideas = NULL;
|
|
|
|
static GList *idea_list = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/* the ops buttons */
|
|
|
|
static GtkSignalFunc open_ext_callbacks[] =
|
|
|
|
{
|
|
|
|
idea_open_or_raise_callback, file_open_callback, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkSignalFunc raise_ext_callbacks[] =
|
|
|
|
{
|
|
|
|
idea_to_top_callback, NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkSignalFunc lower_ext_callbacks[] =
|
|
|
|
{
|
|
|
|
idea_to_bottom_callback, NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static OpsButton ops_buttons[] =
|
|
|
|
{
|
|
|
|
{ folder_xpm, idea_open_callback, open_ext_callbacks,
|
|
|
|
N_("Open the selected entry\n"
|
|
|
|
"<Shift> Raise window if already open\n"
|
|
|
|
"<Control> Load Image dialog"), NULL,
|
|
|
|
NULL, 0 },
|
|
|
|
{ raise_xpm, idea_up_callback, raise_ext_callbacks,
|
|
|
|
N_("Move the selected entry up in the index\n"
|
|
|
|
"<Shift> To top"), NULL,
|
|
|
|
NULL, 0 },
|
|
|
|
{ lower_xpm, idea_down_callback, lower_ext_callbacks,
|
|
|
|
N_("Move the selected entry down in the index\n"
|
|
|
|
"<Shift> To bottom"), NULL,
|
|
|
|
NULL, 0 },
|
|
|
|
{ delete_xpm, idea_remove_callback, NULL,
|
|
|
|
N_("Remove the selected entry from the index"), NULL,
|
|
|
|
NULL, 0 },
|
|
|
|
{ NULL, NULL, NULL, NULL, NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* dnd stuff */
|
|
|
|
|
|
|
|
static GtkTargetEntry drag_types[] =
|
|
|
|
{
|
|
|
|
GIMP_TARGET_URI_LIST,
|
|
|
|
GIMP_TARGET_TEXT_PLAIN,
|
|
|
|
GIMP_TARGET_NETSCAPE_URL
|
|
|
|
};
|
|
|
|
static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types[0]);
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
|
|
|
document_index_create (void)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
if (ideas)
|
|
|
|
gdk_window_raise (ideas->window->window);
|
|
|
|
else
|
|
|
|
open_idea_window ();
|
|
|
|
}
|
1998-10-20 06:01:25 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
void
|
|
|
|
document_index_free (void)
|
|
|
|
{
|
|
|
|
idea_hide_callback (NULL, NULL);
|
1998-10-20 06:01:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-05-07 00:35:21 +08:00
|
|
|
idea_add (gchar *title)
|
1998-10-20 06:01:25 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
idea_add_in_position (title, 0);
|
|
|
|
}
|
1998-10-20 06:01:25 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
FILE *
|
|
|
|
idea_manager_parse_init (void)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
gchar *desktopfile;
|
|
|
|
|
|
|
|
desktopfile = gimp_personal_rc_file ("ideas");
|
|
|
|
fp = fopen (desktopfile, "r");
|
|
|
|
g_free (desktopfile);
|
|
|
|
|
|
|
|
return fp;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
gchar *
|
|
|
|
idea_manager_parse_line (FILE * fp)
|
|
|
|
{
|
|
|
|
gint length;
|
|
|
|
gchar *filename;
|
|
|
|
|
|
|
|
length = getinteger (fp);
|
|
|
|
|
|
|
|
if (!feof (fp) && !ferror (fp))
|
|
|
|
{
|
|
|
|
filename = g_malloc0 (length + 1);
|
|
|
|
filename[fread (filename, 1, length, fp)] = 0;
|
|
|
|
clear_white (fp);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* local functions */
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
2000-05-05 22:53:38 +08:00
|
|
|
load_idea_manager (IdeaManager *ideas)
|
1999-05-07 22:21:38 +08:00
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
|
|
|
|
2000-05-05 22:53:38 +08:00
|
|
|
if (! idea_list)
|
|
|
|
fp = idea_manager_parse_init ();
|
1999-05-07 22:21:38 +08:00
|
|
|
|
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_show (ideas->window);
|
2000-05-05 22:53:38 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (fp)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
1998-07-11 04:35:57 +08:00
|
|
|
gchar *title;
|
2000-05-05 22:53:38 +08:00
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
clear_white (fp);
|
2000-05-05 22:53:38 +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
|
2000-05-07 00:35:21 +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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
title = GTK_LABEL (GTK_BIN (data)->child)->label;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
2000-05-05 22:53:38 +08:00
|
|
|
save_idea_manager (IdeaManager *ideas)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
FILE *fp;
|
1998-07-08 17:04:33 +08:00
|
|
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
g_list_foreach (GTK_LIST (ideas->list)->children, save_to_ideas, fp);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
2000-05-07 00:35:21 +08:00
|
|
|
else if (idea_list)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
title = g_strdup (GTK_LABEL (GTK_BIN (data)->child)->label);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
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
|
|
|
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
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
g_list_foreach (GTK_LIST (ideas->list)->children, save_to_list, NULL);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
1998-07-11 04:35:57 +08:00
|
|
|
static gint
|
2000-05-07 03:25:53 +08:00
|
|
|
list_item_callback (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
gpointer data)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
if (GTK_IS_LIST_ITEM (widget) &&
|
1999-08-22 19:45:31 +08:00
|
|
|
event->type == GDK_2BUTTON_PRESS)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 03:25:53 +08:00
|
|
|
open_or_raise (GTK_LABEL (GTK_BIN (widget)->child)->label, FALSE);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
BoolCharPair *pair;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
pair = (BoolCharPair *) user_data;
|
|
|
|
|
|
|
|
if (strcmp (pair->string, GTK_LABEL (GTK_BIN (data)->child)->label) == 0)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
|
|
|
pair->boole = TRUE;
|
2000-05-07 00:35:21 +08:00
|
|
|
pair->data = data;
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
BoolCharPair *pair;
|
|
|
|
|
|
|
|
pair = (BoolCharPair *) user_data;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
if (strcmp (pair->string, (gchar *) data) == 0)
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
|
|
|
pair->boole = TRUE;
|
2000-05-07 00:35:21 +08:00
|
|
|
pair->data = data;
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static void
|
|
|
|
idea_add_in_position_with_select (gchar *title,
|
|
|
|
gint position,
|
2000-05-07 00:35:21 +08:00
|
|
|
gboolean select)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
BoolCharPair pair;
|
1998-07-08 17:04:33 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
pair.boole = FALSE;
|
1998-07-11 04:35:57 +08:00
|
|
|
pair.string = title;
|
2000-05-07 00:35:21 +08:00
|
|
|
pair.data = NULL;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (ideas)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
g_list_foreach (GTK_LIST (ideas->list)->children, check_needed, &pair);
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (! pair.boole)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
GtkWidget *listitem;
|
|
|
|
GList *list = NULL;
|
|
|
|
|
|
|
|
listitem = gtk_list_item_new_with_label (title);
|
|
|
|
list = g_list_append (list, listitem);
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
if (position < 0)
|
2000-05-07 00:35:21 +08:00
|
|
|
gtk_list_append_items (GTK_LIST (ideas->list), list);
|
1998-07-08 17:04:33 +08:00
|
|
|
else
|
2000-05-07 00:35:21 +08:00
|
|
|
gtk_list_insert_items (GTK_LIST (ideas->list), list, position);
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
gtk_signal_connect (GTK_OBJECT (listitem), "button_press_event",
|
2000-05-07 03:25:53 +08:00
|
|
|
GTK_SIGNAL_FUNC (list_item_callback),
|
1999-08-22 19:45:31 +08:00
|
|
|
NULL);
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
gtk_widget_show (listitem);
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (select)
|
2000-05-07 00:35:21 +08:00
|
|
|
gtk_list_item_select (GTK_LIST_ITEM (listitem));
|
|
|
|
}
|
|
|
|
else /* move entry to top */
|
|
|
|
{
|
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
title = g_strdup (GTK_LABEL (GTK_BIN (pair.data)->child)->label);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (ideas->list),
|
|
|
|
GTK_WIDGET (pair.data));
|
|
|
|
idea_add_in_position_with_select (title, 0, TRUE);
|
|
|
|
g_free (title);
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
FILE *fp;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
fp = idea_manager_parse_init ();
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (fp)
|
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
gchar *filename;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
while ((filename = idea_manager_parse_line (fp)))
|
1998-07-11 04:35:57 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
idea_list = g_list_append (idea_list, g_strdup (filename));
|
|
|
|
g_free (filename);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
2000-05-07 00:35:21 +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)
|
2000-05-07 00:35:21 +08:00
|
|
|
idea_list = g_list_prepend (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
|
|
|
}
|
2000-05-07 00:35:21 +08:00
|
|
|
else /* move entry to top */
|
|
|
|
{
|
|
|
|
idea_list = g_list_remove (idea_list, pair.data);
|
|
|
|
g_free (pair.data);
|
|
|
|
idea_list = g_list_prepend (idea_list, g_strdup (title));
|
|
|
|
}
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
|
|
|
raise_if_match (gpointer data,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GDisplay *gdisp;
|
|
|
|
BoolCharPair *pair;
|
|
|
|
|
|
|
|
gdisp = (GDisplay *) data;
|
|
|
|
pair = (BoolCharPair *) user_data;
|
|
|
|
|
|
|
|
if (gdisp->gimage->has_filename &&
|
|
|
|
strcmp (pair->string, gdisp->gimage->filename) == 0)
|
|
|
|
{
|
|
|
|
pair->boole = TRUE;
|
|
|
|
gdk_window_raise (gdisp->shell->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-05-07 03:25:53 +08:00
|
|
|
open_or_raise (gchar *file_name,
|
|
|
|
gboolean try_raise)
|
2000-05-07 00:35:21 +08:00
|
|
|
{
|
|
|
|
BoolCharPair pair;
|
|
|
|
|
|
|
|
pair.boole = FALSE;
|
|
|
|
pair.string = file_name;
|
|
|
|
pair.data = NULL;
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
if (try_raise)
|
|
|
|
{
|
|
|
|
gdisplays_foreach (raise_if_match, &pair);
|
|
|
|
|
|
|
|
if (! pair.boole)
|
|
|
|
{
|
|
|
|
file_open (file_name, file_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2000-05-07 00:35:21 +08:00
|
|
|
{
|
|
|
|
file_open (file_name, file_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* file parsing functions */
|
|
|
|
|
|
|
|
static gint
|
|
|
|
getinteger (FILE *fp)
|
|
|
|
{
|
|
|
|
gchar nextchar;
|
|
|
|
gint response = 0;
|
|
|
|
gboolean negative = FALSE;
|
|
|
|
|
|
|
|
while (isspace (nextchar = fgetc (fp)))
|
|
|
|
/* empty statement */ ;
|
|
|
|
|
|
|
|
if (nextchar == '-')
|
|
|
|
{
|
|
|
|
negative = TRUE;
|
|
|
|
while (isspace (nextchar = fgetc (fp)))
|
|
|
|
/* empty statement */ ;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; '0' <= nextchar && '9' >= nextchar; nextchar = fgetc (fp))
|
|
|
|
{
|
|
|
|
response *= 10;
|
|
|
|
response += nextchar - '0';
|
|
|
|
}
|
|
|
|
for (; isspace (nextchar); nextchar = fgetc (fp))
|
|
|
|
/* empty statement */ ;
|
|
|
|
|
|
|
|
ungetc (nextchar, fp);
|
|
|
|
if (negative)
|
|
|
|
response = -response;
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_white (FILE *fp)
|
|
|
|
{
|
|
|
|
gint nextchar;
|
|
|
|
|
|
|
|
while (isspace (nextchar = fgetc (fp)))
|
|
|
|
/* empty statement */ ;
|
|
|
|
|
|
|
|
if (nextchar != EOF)
|
|
|
|
ungetc (nextchar, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* toolbar / dialog callbacks */
|
|
|
|
|
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
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
gint orig_position;
|
|
|
|
gint position;
|
1998-07-08 17:04:33 +08:00
|
|
|
gchar *title;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
orig_position = g_list_index (GTK_LIST (ideas->list)->children, widget);
|
|
|
|
position = orig_position + distance;
|
|
|
|
|
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
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
if (position >= g_list_length (GTK_LIST (ideas->list)->children))
|
|
|
|
position = g_list_length (GTK_LIST (ideas->list)->children) - 1;
|
1999-08-22 19:45:31 +08:00
|
|
|
|
|
|
|
if (position != orig_position)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
title = g_strdup (GTK_LABEL (GTK_BIN (widget)->child)->label);
|
|
|
|
gtk_container_remove (GTK_CONTAINER (ideas->list), widget);
|
1999-08-22 19:45:31 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
static void
|
|
|
|
idea_open_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
|
|
|
|
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
|
|
|
{
|
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
|
|
|
open_or_raise (GTK_LABEL (GTK_BIN (selected)->child)->label, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_open_callback (widget, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
idea_open_or_raise_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
|
|
|
|
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
|
|
|
{
|
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
|
|
|
open_or_raise (GTK_LABEL (GTK_BIN (selected)->child)->label, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_open_callback (widget, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-22 19:45:31 +08:00
|
|
|
static 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
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
2000-05-05 22:53:38 +08:00
|
|
|
idea_move (selected, -1, TRUE);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
static void
|
|
|
|
idea_to_top_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
|
|
|
|
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
|
|
|
{
|
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
|
|
|
idea_move (selected, - g_list_length (GTK_LIST (ideas->list)->children),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
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
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
2000-05-05 22:53:38 +08:00
|
|
|
idea_move (selected, 1, TRUE);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
static void
|
|
|
|
idea_to_bottom_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *selected;
|
|
|
|
|
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
|
|
|
{
|
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
|
|
|
idea_move (selected, g_list_length (GTK_LIST (ideas->list)->children),
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
|
|
|
idea_remove (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gint position;
|
|
|
|
|
|
|
|
position = g_list_index (GTK_LIST (ideas->list)->children, widget);
|
|
|
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (ideas->list), widget);
|
|
|
|
|
|
|
|
if (g_list_length (GTK_LIST (ideas->list)->children) - 1 < position)
|
|
|
|
position = g_list_length (GTK_LIST (ideas->list)->children) - 1;
|
|
|
|
|
|
|
|
gtk_list_select_item (GTK_LIST (ideas->list), position);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-08-22 19:45:31 +08:00
|
|
|
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
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
1998-07-08 17:04:33 +08:00
|
|
|
{
|
2000-05-07 00:35:21 +08:00
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
1999-08-22 19:45:31 +08:00
|
|
|
idea_remove (selected);
|
1998-07-08 17:04:33 +08:00
|
|
|
}
|
|
|
|
}
|
1998-07-11 04:35:57 +08:00
|
|
|
|
2000-05-07 00:35:21 +08:00
|
|
|
static void
|
|
|
|
idea_hide_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
if (ideas || idea_list)
|
|
|
|
save_idea_manager (ideas);
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
/* False if exiting */
|
2000-05-07 00:35:21 +08:00
|
|
|
if (ideas)
|
|
|
|
{
|
|
|
|
create_idea_list ();
|
|
|
|
dialog_unregister (ideas->window);
|
|
|
|
session_get_window_info (ideas->window, &document_index_session_info);
|
|
|
|
gtk_widget_destroy (ideas->window);
|
|
|
|
g_free (ideas);
|
|
|
|
ideas = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
static void
|
|
|
|
ops_buttons_update (GtkWidget *widget,
|
|
|
|
gpointer data)
|
2000-05-07 00:35:21 +08:00
|
|
|
{
|
2000-05-07 03:25:53 +08:00
|
|
|
GtkWidget *selected = NULL;
|
|
|
|
gint length = 0;
|
|
|
|
gint index = -1;
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
length = g_list_length (GTK_LIST (ideas->list)->children);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
if (GTK_LIST (ideas->list)->selection)
|
|
|
|
{
|
|
|
|
selected = GTK_LIST (ideas->list)->selection->data;
|
|
|
|
index = g_list_index (GTK_LIST (ideas->list)->children, selected);
|
|
|
|
}
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
#define SET_OPS_SENSITIVE(button,condition) \
|
|
|
|
gtk_widget_set_sensitive (ops_buttons[(button)].widget, \
|
|
|
|
(condition) != 0)
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
SET_OPS_SENSITIVE (1, selected && index > 0);
|
|
|
|
SET_OPS_SENSITIVE (2, selected && index < (length - 1));
|
|
|
|
SET_OPS_SENSITIVE (3, selected);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
#undef SET_OPS_SENSITIVE
|
2000-05-07 00:35:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
open_idea_window (void)
|
|
|
|
{
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *scrolled_win;
|
2000-05-07 03:25:53 +08:00
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button_box;
|
|
|
|
gint i;
|
2000-05-07 00:35:21 +08:00
|
|
|
|
|
|
|
ideas = g_new0 (IdeaManager, 1);
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
ideas->window = gimp_dialog_new (_("Document Index"), "docindex",
|
|
|
|
gimp_standard_help_func,
|
|
|
|
"dialogs/document_index.html",
|
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, TRUE, FALSE,
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
_("Close"), idea_hide_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, TRUE,
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_drag_dest_set (ideas->window,
|
|
|
|
GTK_DEST_DEFAULT_ALL,
|
|
|
|
drag_types, n_drag_types,
|
|
|
|
GDK_ACTION_COPY);
|
|
|
|
|
|
|
|
gimp_dnd_file_dest_set (ideas->window);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
dialog_register (ideas->window);
|
|
|
|
session_set_window_geometry (ideas->window, &document_index_session_info,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
main_vbox = gtk_vbox_new (FALSE, 4);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 4);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (ideas->window)->vbox),
|
|
|
|
main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
|
|
|
/* Scrolled window */
|
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), scrolled_win, TRUE, TRUE, 0);
|
|
|
|
gtk_widget_show (scrolled_win);
|
|
|
|
|
|
|
|
/* Setup list */
|
|
|
|
ideas->list = gtk_list_new ();
|
|
|
|
gtk_list_set_selection_mode (GTK_LIST (ideas->list), GTK_SELECTION_BROWSE);
|
|
|
|
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
ideas->list);
|
|
|
|
gtk_widget_show (ideas->list);
|
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
/* The ops buttons */
|
|
|
|
hbox = gtk_hbox_new (FALSE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (hbox);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
button_box = ops_button_box_new (ops_buttons, OPS_BUTTON_NORMAL);
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button_box, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (button_box);
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
for (i = 0; ; i++)
|
|
|
|
{
|
|
|
|
if (ops_buttons[i].widget == NULL)
|
|
|
|
break;
|
2000-05-07 00:35:21 +08:00
|
|
|
|
2000-05-07 03:25:53 +08:00
|
|
|
gtk_misc_set_padding (GTK_MISC (GTK_BIN (ops_buttons[i].widget)->child),
|
|
|
|
8, 0);
|
|
|
|
}
|
2000-05-07 00:35:21 +08:00
|
|
|
|
|
|
|
/* Load and Show window */
|
|
|
|
load_idea_manager (ideas);
|
2000-05-07 03:25:53 +08:00
|
|
|
|
|
|
|
gtk_signal_connect_after (GTK_OBJECT (ideas->list), "selection_changed",
|
|
|
|
GTK_SIGNAL_FUNC (ops_buttons_update),
|
|
|
|
NULL);
|
|
|
|
ops_buttons_update (NULL, NULL);
|
1998-07-11 04:35:57 +08:00
|
|
|
}
|