Commit 2fc2ef22 authored by Jacob Leach's avatar Jacob Leach

Converted the diff plugin to the new plugin system. Made

dialog-about.c, split the "recently used files" code into
recent.[ch].  Other bug fixes and cleanups.
parent 83288db9
......@@ -133,8 +133,10 @@ help/C/Makefile
help/no/Makefile
pixmaps/Makefile
plugins/Makefile
plugins/diff/Makefile
plugins/email/Makefile
plugins/sample/Makefile
plugins/reverse/Makefile
plugins/time/Makefile
src/Makefile
src/dialogs/Makefile
......
......@@ -27,31 +27,32 @@ gedit_SOURCES = \
gedit.c \
commands.c \
commands.h \
window.c \
window.h \
view.c \
view.h \
document.c \
document.h \
undo.c \
undo.h \
file.c \
file.h \
utils.c \
utils.h \
gedit.h \
menus.c \
menus.h \
plugin.c \
plugin.h \
prefs.c \
prefs.h \
about.c \
about.h \
print.c \
print.h \
plugin.c \
plugin.h \
gedit.h \
menus.c \
menus.h \
recent.c \
recent.h \
search.c \
search.h
search.h \
undo.c \
undo.h \
utils.c \
utils.h \
view.c \
view.h \
window.c \
window.h
gedit_LDADD = \
dialogs/libdialogs.a \
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* vi:set ts=8 sts=0 sw=8:
*
/*
* gedit
*
* This program is free software; you can redistribute it and/or modify
......@@ -20,7 +19,6 @@
#include <config.h>
#include <gnome.h>
#include <libgnome/gnome-history.h>
#include <unistd.h>
#define __need_sigset_t
......@@ -43,8 +41,6 @@
static gint file_saveas_destroy(GtkWidget *w, GtkWidget **sel);
static gint file_cancel_sel (GtkWidget *w, GtkFileSelection *fs);
static void file_sel_destroy (GtkWidget *w, GtkFileSelection *fs);
static void recent_update_menus (GnomeApp *app, GList *recent_files);
static void recent_cb (GtkWidget *w, gedit_data *data);
/* static GtkWidget *open_fs, *save_fs; */
GtkWidget *col_label;
......@@ -489,191 +485,12 @@ void
edit_selall_cb (GtkWidget *widget, gpointer data)
{
gtk_editable_select_region(GTK_EDITABLE(VIEW (mdi->active_view)->text), 0,
gtk_text_get_length( GTK_TEXT(VIEW (mdi->active_view)->text)));
gtk_text_get_length (GTK_TEXT(VIEW (mdi->active_view)->text)));
gnome_app_flash (mdi->active_window, MSGBAR_SELECT_ALL);
}
/**
* recent_update:
* @app:
*
* Grabs the list of recently used documents, then updates the menus by
* calling recent_update_menus(). Should be called after each addition
* to the recent documents list.
**/
void
recent_update (GnomeApp *app)
{
GList *filelist = NULL;
GList *gnome_recent_list;
GnomeHistoryEntry histentry;
char *filename;
int i, j;
int nrecentdocs = 0;
filelist = NULL;
gnome_recent_list = gnome_history_get_recently_used ();
if (g_list_length (gnome_recent_list) > 0)
{
for (i = g_list_length (gnome_recent_list) - 1; i >= 0; i--)
{
histentry = g_list_nth_data (gnome_recent_list, i);
if (strcmp ("gedit", histentry->creator) == 0)
{
/* This is to make sure you don't have more than one
file of the same name in the recent list
*/
if (g_list_length (filelist) > 0)
{
for (j = g_list_length (filelist) - 1; j >= 0; j--)
{
if (strcmp (histentry->filename, g_list_nth_data (filelist, j)) == 0)
{
filelist = g_list_remove (filelist, g_list_nth_data (filelist, j));
nrecentdocs--;
}
}
}
filename = g_malloc0 (strlen (histentry->filename) + 1);
strcpy (filename, histentry->filename);
filelist = g_list_append (filelist, filename);
nrecentdocs++;
/* For recent-directories, not yet fully implemented...
end_path = strrchr (histentry->filename, '/');
if (end_path) {
for (i = 0; i < strlen (histentry->filename); i++)
if ((histentry->filename + i) == end_path)
break;
directory = g_malloc0 (i + 2);
strcat (directory, histentry->filename, i);
}
*/
if (nrecentdocs == MAX_RECENT)
/* if (g_list_length (filelist) == MAX_RECENT) */
break;
}
}
}
gnome_history_free_recently_used_list (gnome_recent_list);
recent_update_menus (app, filelist);
}
/* Actually updates the recent-used menu... */
static void
recent_update_menus (GnomeApp *app, GList *recent_files)
{
GnomeUIInfo *menu;
gedit_data *data;
gchar *path;
int i;
g_return_if_fail (app != NULL);
if (settings->num_recent)
gnome_app_remove_menu_range (app, _("_File/"), 6, settings->num_recent + 1);
if (recent_files == NULL)
return;
/* insert a separator at the beginning */
menu = g_malloc0 (2 * sizeof (GnomeUIInfo));
path = g_new (gchar, strlen (_("_File")) + strlen ("<Separator>") + 3 );
sprintf (path, "%s/%s", _("_File"), "<Separator>");
menu->type = GNOME_APP_UI_SEPARATOR;
(menu + 1)->type = GNOME_APP_UI_ENDOFINFO;
gnome_app_insert_menus (GNOME_APP(app), path, menu);
for (i = g_list_length (recent_files) - 1; i >= 0; i--)
{
menu = g_malloc0 (2 * sizeof (GnomeUIInfo));
data = g_malloc0 (sizeof (gedit_data));
data->temp1 = g_strdup (g_list_nth_data (recent_files, i));
menu->label = g_new (gchar, strlen (g_list_nth_data (recent_files, i)) + 5);
sprintf (menu->label, "_%i. %s", i+1, (gchar*)g_list_nth_data (recent_files, i));
menu->type = GNOME_APP_UI_ITEM;
menu->hint = NULL;
menu->moreinfo = (gpointer) recent_cb;
menu->user_data = data;
menu->unused_data = NULL;
menu->pixmap_type = 0;
menu->pixmap_info = NULL;
menu->accelerator_key = 0;
(menu + 1)->type = GNOME_APP_UI_ENDOFINFO;
gnome_app_insert_menus (GNOME_APP(app), path, menu);
g_free (g_list_nth_data (recent_files, i));
}
g_free (menu);
settings->num_recent = g_list_length (recent_files);
g_list_free (recent_files);
g_free (path);
}
/* Callback for a users click on one of the recent docs in the File menu */
static void
recent_cb (GtkWidget *widget, gedit_data *data)
{
Document *doc = gedit_document_current ();
g_return_if_fail (data != NULL);
if (doc)
{
if (doc->filename || VIEW(mdi->active_view)->changed)
{
doc = gedit_document_new_with_file (data->temp1);
gnome_mdi_add_child (mdi, GNOME_MDI_CHILD (doc));
gnome_mdi_add_view (mdi, GNOME_MDI_CHILD (doc));
}
else
{
/* FIXME.jel: add some conditional check and
an else to handle the case where the file
in the recent menu fails to open
(deleted/moved/new permissions) */
gedit_file_open (doc, data->temp1);
}
}
}
/**
* recent_add:
* @filename: Filename of document to add to the recently accessed list
*
* Record a file in GNOME's recent documents database
**/
void
recent_add (char *filename)
{
g_return_if_fail (filename != NULL);
gnome_history_recently_used (filename, "text/plain",
"gedit", "gedit document");
}
void
options_toggle_split_screen_cb (GtkWidget *widget, gpointer data)
......
/* vi:set ts=8 sts=0 sw=8:
*
/*
* gedit
*
* This program is free software; you can redistribute it and/or modify
......@@ -16,15 +15,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __COMMANDS_H__
#define __COMMANDS_H__
#include "gedit.h"
#ifndef MAX_RECENT
#define MAX_RECENT 4
#endif
/* File Ops */
void file_quit_cb (GtkWidget *widget, gpointer cbdata);
......@@ -67,22 +61,18 @@ extern void scrollbar_auto_cb (GtkWidget *widget, gpointer cbwindow);
/* Auto indent */
extern void auto_indent_toggle_cb(GtkWidget *w, gpointer cbdata);
extern void auto_indent_toggle_cb (GtkWidget *w, gpointer cbdata);
/* DND */
extern void filenames_dropped (GtkWidget * widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time);
/* Recent documents */
extern void recent_add (char *filename);
extern void recent_update (GnomeApp *app);
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time);
extern void options_toggle_split_screen_cb (GtkWidget *widget, gpointer data);
extern void options_toggle_status_bar_cb (GtkWidget *widget, gpointer data);
......
......@@ -11,11 +11,12 @@ INCLUDES = \
noinst_LIBRARIES = libdialogs.a
libdialogs_a_SOURCES = \
dialog-about.c \
dialog-replace.c \
dialog-find-line.c
glade_DATA = \
about.glade \
find-line.glade
find-line.glade \
replace.glade
EXTRA_DIST = $(glade_DATA)
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* gedit - About dialog
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <gnome.h>
#include <glade/glade.h>
/**
* gedit_about:
*
* Show the user the information about the program and its authors.
*/
void
dialog_about (void)
{
#if 0
GladeXML *gui = glade_xml_new ("/home/elerium/cvs/gedit/src/dialogs/about.glade", NULL);
if (!gui)
{
g_warning ("Could not find about.glade");
return;
}
gtk_widget_show (glade_xml_get_widget (gui, "about"));
gtk_object_destroy (GTK_OBJECT (gui));
#else
static GtkWidget *about;
const gchar *authors[] = {
"Alex Roberts",
"Evan Lawrence",
"http://gedit.pn.org",
"",
N_("With special thanks to:"),
" Will LaShell, Chris Lahey, Andy Kahn,",
" Miguel de Icaza, Martin Baulig,",
" Thomas Holmgren, Martijn van Beers",
NULL
};
if (about != NULL)
{
gdk_window_show (about->window);
gdk_window_raise (about->window);
return;
}
about = gnome_about_new ("gedit", VERSION,
_("(C) 1998, 1999 Alex Roberts and Evan Lawrence"),
authors,
_("gedit is a small and lightweight text "
"editor for GNOME/Gtk+"),
"gedit-logo.png");
gtk_signal_connect (GTK_OBJECT (about), "destroy",
GTK_SIGNAL_FUNC (gtk_widget_destroyed), &about);
gtk_widget_show (about);
#endif
}
......@@ -4,6 +4,9 @@
* Author:
* Jason Leach <leach@wam.umd.edu>
*
* TODO:
* [ ] revert back to non-glade, this dialog is too small to get anything
* from it.
*/
#include <config.h>
......@@ -28,12 +31,12 @@ create_line_dialog (void)
GNOME_STOCK_BUTTON_CANCEL,
NULL);
hbox = gtk_hbox_new (FALSE, 0);
hbox = gtk_hbox_new (TRUE, 0);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox,
FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new (_("Line number"));
label = gtk_label_new (_("Line number: "));
gtk_box_pack_start (GTK_BOX (hbox), label,
FALSE, FALSE, 0);
gtk_widget_show (label);
......@@ -73,27 +76,34 @@ find_line_clicked_cb (GtkWidget *widget, gint button, Document *doc)
gnome_dialog_close (GNOME_DIALOG (widget));
}
void
find_line_cb (GtkWidget *widget, gpointer data)
dialog_find_line (void)
{
#if 1
GladeXML *gui = glade_xml_new (GEDIT_GLADEDIR
"/find-line.glade",
NULL);
GtkWidget *dialog;
GtkWidget *spinb;
GtkAdjustment *adj;
Document *doc = gedit_document_current ();
GladeXML *gui = glade_xml_new (GEDIT_GLADEDIR
"/find-line.glade",
NULL);
if (!gui)
{
g_warning ("Could not find find-line.glade");
g_warning ("Could not find find-line.glade, reinstall gedit.");
return;
}
dialog = glade_xml_get_widget (gui, "dialog");
spinb = glade_xml_get_widget (gui, "spinb");
if (!dialog || !spinb)
{
g_print ("Corrupted find-line.glade detected, reinstall gedit.");
return;
}
gtk_object_set_data (GTK_OBJECT (dialog), "spinb", spinb);
adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (spinb));
......
......@@ -18,13 +18,12 @@
static GtkWidget *replace_dialog;
static GtkWidget* create_replace_dialog (void);
static void replace_clicked_cb (GtkWidget *widget, gint button, Document *doc);
static void clicked_cb (GtkWidget *widget, gint button, Document *doc);
static gint ask_replace (void);
void
dialog_replace (GtkWidget *widget, gpointer data)
dialog_replace (void)
{
Document *doc;
......@@ -34,12 +33,13 @@ dialog_replace (GtkWidget *widget, gpointer data)
replace_dialog = create_replace_dialog ();
gtk_signal_connect (GTK_OBJECT (replace_dialog), "clicked",
GTK_SIGNAL_FUNC (replace_clicked_cb), doc);
GTK_SIGNAL_FUNC (clicked_cb), doc);
gtk_widget_show (replace_dialog);
}
/* Callback on the dialog's "clicked" signal */
static void
replace_clicked_cb (GtkWidget *widget, gint button, Document *doc)
clicked_cb (GtkWidget *widget, gint button, Document *doc)
{
GtkWidget *datalink;
gint pos, dowhat = 0;
......@@ -83,7 +83,7 @@ replace_clicked_cb (GtkWidget *widget, gint button, Document *doc)
else
{
gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
GTK_SIGNAL_FUNC (replace_clicked_cb),
GTK_SIGNAL_FUNC (clicked_cb),
doc);
gnome_dialog_close (GNOME_DIALOG (widget));
}
......
#ifndef __DIALOGS_H__
#define __DIALOGS_H__
#include <gnome.h>
void dialog_replace (GtkWidget, gpointer data);
void dialog_about (void);
void dialog_find_line (void);
void dialog_replace (void);
#endif /* __DIALOGS_H__ */
......@@ -61,18 +61,18 @@ gedit_document_get_type (void)
if (!doc_type)
{
static const GtkTypeInfo doc_info =
{
"Document",
sizeof (Document),
sizeof (DocumentClass),
(GtkClassInitFunc) gedit_document_class_init,
(GtkObjectInitFunc) gedit_document_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
static const GtkTypeInfo doc_info =
{
"Document",
sizeof (Document),
sizeof (DocumentClass),
(GtkClassInitFunc) gedit_document_class_init,
(GtkObjectInitFunc) gedit_document_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
doc_type = gtk_type_unique (gnome_mdi_child_get_type (), &doc_info);
doc_type = gtk_type_unique (gnome_mdi_child_get_type (), &doc_info);
}
return doc_type;
......@@ -85,7 +85,7 @@ gedit_document_create_view (GnomeMDIChild *child)
new_view = gedit_view_new (DOCUMENT (child));
gedit_view_set_font (VIEW(new_view), settings->font);
gedit_view_set_font (VIEW (new_view), settings->font);
gtk_widget_queue_resize (GTK_WIDGET (new_view));
return new_view;
......@@ -94,22 +94,13 @@ gedit_document_create_view (GnomeMDIChild *child)
static void
gedit_document_destroy (GtkObject *obj)
{
Document *doc;
Document *doc = DOCUMENT (obj);
doc = DOCUMENT (obj);
g_free (doc->filename);
g_string_free (doc->buf, TRUE);
if (doc->buf)
g_free (doc->buf->str);
doc->buf = NULL;
if (doc->undo)
g_list_free (doc->undo);
if (doc->redo)
g_list_free (doc->redo);
g_list_free (doc->undo);
g_list_free (doc->redo);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy)(GTK_OBJECT (doc));
......@@ -180,14 +171,13 @@ gedit_document_new (void)
{
Document *doc;
/* FIXME: Blarg!! */
doc = gtk_type_new (gedit_document_get_type ());
if (doc)
{
gnome_mdi_child_set_name (GNOME_MDI_CHILD(doc),
gnome_mdi_child_set_name (GNOME_MDI_CHILD (doc),
gedit_get_document_tab_name());
doc->buf = g_string_sized_new (64);
doc->buf = g_string_sized_new (256);
return doc;
}
......@@ -210,7 +200,7 @@ gedit_document_new_with_title (gchar *title)
gnome_mdi_child_set_name (GNOME_MDI_CHILD(doc),
title);
doc->buf = g_string_sized_new (64);
doc->buf = g_string_sized_new (256);
return doc;
}
......@@ -376,7 +366,7 @@ remove_child_cb (GnomeMDI *mdi, Document *doc)
void
gedit_mdi_init (void)
{
mdi = GNOME_MDI (gnome_mdi_new ("gedit", GEDIT_ID));
mdi = GNOME_MDI (gnome_mdi_new ("gedit", "gedit "VERSION));
gnome_config_push_prefix ("/gedit/Global/");
mdi->tab_pos = gnome_config_get_int ("tab_pos=2");
......
......@@ -79,6 +79,6 @@ void add_view_cb (GnomeMDI *mdi, Document *doc);
gint add_child_cb (GnomeMDI *mdi, Document *doc);
gchar* gedit_get_document_tab_name (void);
void gedit_mdi_init (void);
#endif /* __GEDIT_DOCUMENT_H__ */