Commit 6049fdbb authored by Chema Celorio's avatar Chema Celorio Committed by Jose Maria Celorio

new function. It verifies that the user has the fonts required.

2000-06-14  Chema Celorio  <chema@celorio.com>

	* print.c (gedit_print_verify_fonts): new function. It verifies
	that the user has the fonts required.
	(print_set_pji): fix a stupid bug, close 13922.

	* window.c (doc_swaphc_cb): add error dialogs.
	if the file is allready open, don't open it again
	set it's view active.

	* search.c (dump_search_state): remove unused enums
	SEARCH_IN_PROGRESS_COUNT_LINES & _REPLACE

2000-06-13  Chema Celorio  <chema@celorio.com>

	* utils.h (gedit_debug): add debug_window macro

	* gedit.c: add "gint debug_window"

	* document.c (gedit_document_load): convert the file_list->data
	to a full_pathname.

	* file.c (gedit_file_convert_to_full_pathname): new function to convert
	the file_name passed as argument to a full path name.
	* file.h: add prototype

	* recent.c: rename functions for consistency with the rest
	of the code.

	* prefs.c (gedit_load_settings): compose mdi string from
	enum and not use a number.

	* file.c (file_close_cb): after closing a doc, set the
	title.

	* document.c (gedit_mdi_init): don't display "gedit "VERSION
	in the title window, since gedit_document_set_title is not.
	If you want to add the version number to the title window
	pleas also add it to the function gedit_docuemnt_set_title.

	* view.c (gedit_view_remove_cb): after removing a view, set
	the title again.
parent f88866ed
- Design questions ?
Design questions ?
- Should we enable the split window ?
- is document.c the place to have mdi_ini ?
......@@ -16,34 +16,46 @@
open, gedit will not exit
[X] Add undo data "replace" and gedit_document_replace() function
[X] You should only be able to open 1 prefrences window
[ ] Update README, HACKING, gedit.spec.in, AUTHORS etc..
[ ] Add an Untitled file saved to the Recent file list
[X] Add an Untitled file saved to the Recent file list
[X] After view_remove the main window title does not get updated
[X] After closing a doc the main window title does not get updated
[X] Fix the recent files feature, there are still some loose ends.
[X] use full path so that we can locate the files when gedit is
executed from another directory
[X] When saving and Untitled Document or "Saving as" add the doc
to the list
[Xs] If a document can't be loaded from the recent list because
of whatever reason, remove it.
[ ] When swapping .c & .h files display error dialogs to the user
If the file is allready open, do not open it again, just set it's
view as active
[ ] Try to fix the line & column pos
*** maybe the next text widget will fix this.***
[ ] Fix the problem with the Main window title when switching
between different views of the same document
[ ] After view_remove the main window title does not get updated
between different views or docs, it flashes.
*** mailed jaka ***
[ ] Update README, HACKING, gedit.spec.in, AUTHORS etc..
*** yak! ****
[ ] The word wrapping preference in the prefs. dialog box does not
modify the editor behaivor
*** new text widget ??? ****
** Eric **
[ ] New Documentation
** Roberto **
[ ] Insert Shell Output plugin
[~] Insert Shell Output plugin
[ ] Add to the diff plugin the ability to make the diff from
an open document in gedit.
[ ] Shade & Unshade the Undo & Redo buttons.
** Unclaimed **
[ ] check for the existence of sendmail and of diff. If they are
no found ask the user for the location and set it in settings->sendmail
& settings->diff. Same thing for the browse plugin
[ ] Fix the recent files feature, there are still some loose ends.
[ ] use full path so that we can locate the files when gedit is executed from another directory
[ ] When savin and Untitled Document or "Saving as" add the doc to the list
[ ] If a document can't be loaded from the recent list because of whatever reason, remove it.
[ ] Split screen ???
Should we re-enable it ? Maybe.
[ ] If you close a doc, the title of the window is set to gedit $version
and not gedit $ Document. When switching docs the Title is set twice
and flashes.
----------------------------------------------------------------------
gedit 0.7.9
......
AC_INIT(src/gedit.c)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(gedit, 0.7.9)
AM_INIT_AUTOMAKE(gedit, 0.7.9b)
AM_MAINTAINER_MODE
AM_ACLOCAL_INCLUDE(macros)
......
2000-06-14 Chema Celorio <chema@celorio.com>
* print.c (gedit_print_verify_fonts): new function. It verifies
that the user has the fonts required.
(print_set_pji): fix a stupid bug, close 13922.
* window.c (doc_swaphc_cb): add error dialogs.
if the file is allready open, don't open it again
set it's view active.
* search.c (dump_search_state): remove unused enums
SEARCH_IN_PROGRESS_COUNT_LINES & _REPLACE
2000-06-13 Chema Celorio <chema@celorio.com>
* utils.h (gedit_debug): add debug_window macro
* gedit.c: add "gint debug_window"
* document.c (gedit_document_load): convert the file_list->data
to a full_pathname.
* file.c (gedit_file_convert_to_full_pathname): new function to convert
the file_name passed as argument to a full path name.
* file.h: add prototype
* recent.c: rename functions for consistency with the rest
of the code.
* prefs.c (gedit_load_settings): compose mdi string from
enum and not use a number.
* file.c (file_close_cb): after closing a doc, set the
title.
* document.c (gedit_mdi_init): don't display "gedit "VERSION
in the title window, since gedit_document_set_title is not.
If you want to add the version number to the title window
pleas also add it to the function gedit_docuemnt_set_title.
* view.c (gedit_view_remove_cb): after removing a view, set
the title again.
2000-06-13 Chema Celorio <chema@celorio.com>
* file.c: finish fixing the BUG in which gedit will not
......
......@@ -102,13 +102,8 @@ tab_rgt_cb (GtkWidget *widget, gpointer cbwindow)
}
void
filenames_dropped (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *selection_data,
guint info,
guint time)
filenames_dropped (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
GtkSelectionData *selection_data, guint info, guint time)
{
GList *names, *tmp_list;
......
......@@ -443,10 +443,6 @@ remove_child_cb (GnomeMDI *mdi, Document *doc)
switch (ret)
{
case 0:
/* FIXME : If the user selects YES
treat as if he had selected CANCEL
because we don't want him to loose his
data. This is anoying, I know. Chema*/
return file_save_document (doc);
case 1:
return TRUE;
......@@ -455,7 +451,7 @@ remove_child_cb (GnomeMDI *mdi, Document *doc)
return FALSE;
}
}
return TRUE;
}
......@@ -558,8 +554,11 @@ void
gedit_mdi_init (void)
{
gedit_debug ("", DEBUG_DOCUMENT);
mdi = GNOME_MDI (gnome_mdi_new ("gedit", "gedit "VERSION));
/*
mdi = GNOME_MDI (gnome_mdi_new ("gedit", "gedit "VESION));
*/
mdi = GNOME_MDI (gnome_mdi_new ("gedit", "gedit "));
mdi->tab_pos = settings->tab_pos;
......@@ -586,7 +585,7 @@ gedit_mdi_init (void)
void
gedit_document_load ( GList *file_list)
{
Document *doc;
gchar *file_name;
gedit_debug ("", DEBUG_DOCUMENT);
......@@ -595,15 +594,14 @@ gedit_document_load ( GList *file_list)
/* create a file for each document in the parameter list */
for (;file_list; file_list = file_list->next)
{
if (g_file_exists (file_list->data))
{
doc = gedit_document_new_with_title (file_list->data);
gedit_file_open (doc, file_list->data);
}
file_name = gedit_file_convert_to_full_pathname (file_list->data);
if (g_file_exists (file_name))
gedit_document_new_with_file ((gchar *) file_name);
else
{
gedit_file_create_popup ((guchar *) file_list->data);
}
gedit_file_create_popup ((guchar *) file_name);
g_free (file_name);
}
if (gedit_document_current()==NULL)
......@@ -623,14 +621,11 @@ gedit_document_set_title (Document *doc)
{
gchar *title;
gchar *docname;
/*
gint i;
View *nth_view;
*/
gedit_debug ("", DEBUG_DOCUMENT);
g_return_if_fail (doc != NULL);
if (doc == NULL)
return;
docname = GNOME_MDI_CHILD (doc)->name;
......@@ -639,18 +634,9 @@ gedit_document_set_title (Document *doc)
else
title = g_strdup_printf ("gedit: %s", docname);
/*
for (i = 0; i < g_list_length (doc->views); i++)
{
nth_view = g_list_nth_data (doc->views, i);
if (nth_view == view_exclude)
continue;
gedit_view_insert (nth_view, position, text, length);
}
*/
gtk_window_set_title (gedit_window_active(), title);
g_free (title);
}
......@@ -69,6 +69,10 @@ static void cancel_cb (GtkWidget *w, gpointer cbdata);
static void gedit_close_all_flag_status (guchar *function);
static void gedit_close_all_flag_verify (guchar *function);
gchar * gedit_file_convert_to_full_pathname (const gchar * fname);
/* TODO : add flash on all operations ....Chema*/
/* what happens when you open the same doc
twice. I think we should add another view
......@@ -100,8 +104,10 @@ gedit_file_open (Document *doc, gchar *fname)
if (stat(fname, &stats) || !S_ISREG(stats.st_mode))
{
gnome_app_error (gedit_window_active_app(), _("An error was encountered while opening the file."
"\nPlease make sure the file exists."));
gchar *errstr = g_strdup_printf (_("An error was encountered while opening the file \"%s\"."
"\nPlease make sure the file exists."), fname);
gnome_app_error (gedit_window_active_app(), errstr);
g_free (errstr);
return 1;
}
......@@ -154,8 +160,8 @@ gedit_file_open (Document *doc, gchar *fname)
g_free (tmp_buf);
gedit_flash_va ("%s %s", _(MSGBAR_FILE_OPENED), fname);
recent_add (fname);
recent_update (gedit_window_active_app());
gedit_recent_add (fname);
gedit_recent_update (gedit_window_active_app());
gedit_debug ("end", DEBUG_FILE);
......@@ -348,18 +354,20 @@ gedit_file_stdin (Document *doc)
guint pos = 0;
View *view;
gedit_debug ("", DEBUG_FILE);
gedit_debug ("start", DEBUG_FILE);
fstat(STDIN_FILENO, &stats);
if (stats.st_size == 0)
{
gedit_debug ("size = 0. end", DEBUG_FILE);
return 1;
}
if ((tmp_buf = g_new0 (gchar, GEDIT_STDIN_BUFSIZE+1)) == NULL)
{
gnome_app_error (mdi->active_window, _("Could not allocate the required memory."));
gedit_debug ("mem alloc error. end", DEBUG_FILE);
return 1;
}
......@@ -558,7 +566,7 @@ static void
gedit_file_save_as_ok_sel (GtkWidget *w, gpointer cbdata)
{
Document *doc;
gchar *filename;
gchar *file_name;
gint i;
View *nth_view;
......@@ -573,17 +581,17 @@ gedit_file_save_as_ok_sel (GtkWidget *w, gpointer cbdata)
if (!doc)
return;
filename = g_strdup(gtk_file_selection_get_filename (GTK_FILE_SELECTION(save_file_selector)));
file_name = g_strdup(gtk_file_selection_get_filename (GTK_FILE_SELECTION(save_file_selector)));
gtk_widget_hide (GTK_WIDGET (save_file_selector));
save_file_selector = NULL;
if (g_file_exists (filename))
if (g_file_exists (file_name))
{
guchar * msg;
GtkWidget *msgbox;
gint ret;
msg = g_strdup_printf (_("``%s'' is about to be overwritten. Do you want to continue ?"), filename);
msg = g_strdup_printf (_("``%s'' is about to be overwritten. Do you want to continue ?"), file_name);
msgbox = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES,
GNOME_STOCK_BUTTON_NO, GNOME_STOCK_BUTTON_CANCEL, NULL);
gnome_dialog_set_default (GNOME_DIALOG (msgbox), 2);
......@@ -603,16 +611,14 @@ gedit_file_save_as_ok_sel (GtkWidget *w, gpointer cbdata)
}
}
if (gedit_file_save(doc, filename) != 0)
if (gedit_file_save(doc, file_name) != 0)
{
gedit_flash (_("Error saving file!"));
g_free (filename);
g_free (file_name);
gedit_close_all_flag_clear();
return;
}
g_free (filename);
/* If file save was succesfull, then we should turn the readonly flag off */
for (i = 0; i < g_list_length (doc->views); i++)
{
......@@ -620,6 +626,14 @@ gedit_file_save_as_ok_sel (GtkWidget *w, gpointer cbdata)
gedit_view_set_readonly (nth_view, FALSE);
}
/* Add the saved as file to the recent files ( history ) menu */
gedit_recent_add (file_name);
gedit_recent_update (gedit_window_active_app());
gedit_flash_va ("%s %s", _(MSGBAR_FILE_SAVED), file_name);
g_free (file_name);
gedit_close_all_flag_status ("gedit_file_save_ok_sel");
switch (gedit_close_all_flag){
case GEDIT_CLOSE_ALL_FLAG_NORMAL:
......@@ -645,6 +659,9 @@ file_close_cb (GtkWidget *widget, gpointer cbdata)
if (mdi->active_child == NULL)
return;
gnome_mdi_remove_child (mdi, mdi->active_child, FALSE);
gedit_document_set_title (gedit_document_current());
}
void
......@@ -683,7 +700,7 @@ file_quit_cb (GtkWidget *widget, gpointer cbdata)
gtk_object_destroy (GTK_OBJECT (mdi));
gedit_save_settings ();
history_write_config ();
gedit_recent_history_write_config ();
gtk_main_quit ();
}
......@@ -812,3 +829,80 @@ gedit_close_all_flag_verify (guchar *function)
g_warning ("The close all flag was set !!!!! Func: %s", function);
}
/**
* gedit_file_convert_to_full_pathname: convert a file_name to a full path
* @file_name_to_convert: the file name to convert
*
*
Test strings
1. /home/user/./dir/././././file.txt /home/user/dir/file.txt
2. /home/user/cvs/gedit/../../docs/file.txt /home/user/docs/file.txt
3. File name in: /home/chema/cvs/gedit/../../cvs/../docs/././././././temp_32avo.txt
File name out: /home/chema/docs/temp_32avo.txt
*
*
* Return Value: a pointer to a allocated string. The calling function is responsible
* o freeing the string
**/
gchar *
gedit_file_convert_to_full_pathname (const gchar * file_name_to_convert)
{
gint file_name_in_length;
gchar *file_name_in;
gchar *file_name_out;
gint i, j=0;
g_return_val_if_fail (file_name_to_convert != NULL, NULL);
if (g_path_is_absolute(file_name_to_convert))
{
file_name_in = g_strdup (file_name_to_convert);
}
else
{
file_name_in = g_strdup_printf ("%s/%s",
g_get_current_dir(),
file_name_to_convert);
}
file_name_in_length = strlen (file_name_in);
file_name_out = g_malloc (file_name_in_length + 1);
g_return_val_if_fail (file_name_in[0] == '/', NULL);
for (i = 0; i < file_name_in_length - 1; i++)
{
/* remove all the "../" from file_name */
if (file_name_in[i] == '.' && file_name_in[i+1] == '.')
{
if (i < file_name_in_length-1)
if (file_name_in[i+2] == '/')
{
i+=2;
/* Remove the last directory in file_name_out */
j--;
while (file_name_out [j-1] != '/')
j--;
j--;
}
}
/* remove all the "./"'s from file_name */
if (file_name_in[i] == '.' && file_name_in[i+1] == '/')
{
i++;
continue;
}
file_name_out [j++] = file_name_in [i];
}
file_name_out [j++] = file_name_in [i];
file_name_out [j] = '\0';
return file_name_out;
}
......@@ -55,6 +55,9 @@ void file_close_all_cb (GtkWidget *widget, gpointer cbdata);
void file_revert_cb (GtkWidget *widget, gpointer cbdata);
void gedit_close_all_flag_clear (void);
gchar * gedit_file_convert_to_full_pathname (const gchar * fname);
#endif /* __FILE_H__ */
......@@ -47,6 +47,7 @@ gint debug_file = 0;
gint debug_document = 0;
gint debug_commands = 0;
gint debug_recent = 0;
gint debug_window = 0;
#ifdef HAVE_LIBGNORBA
......
......@@ -263,23 +263,6 @@ GnomeUIInfo gedit_settings_menu[] =
GNOMEUIINFO_END
};
GnomeUIInfo gedit_window_menu[] =
{
GNOMEUIINFO_MENU_NEW_WINDOW_ITEM (window_new_cb, NULL),
/*FIXME GNOMEUIINFO_MENU_CLOSE_WINDOW_ITEM(window_close_cb,
NULL),*/
/* GNOMEUIINFO_SEPARATOR,
{ GNOME_APP_UI_ITEM, N_("_Document List"),
N_("Display the document list"),
files_list_popup, (gpointer) GE_DATA, NULL,
GNOME_APP_PIXMAP_NONE, NULL, 'L', GDK_CONTROL_MASK, NULL },*/
GNOMEUIINFO_END
};
GnomeUIInfo gedit_docs_menu[] =
{
GNOMEUIINFO_END
......@@ -311,7 +294,6 @@ GnomeUIInfo gedit_menu[] =
0, 0, NULL
},
GNOMEUIINFO_MENU_SETTINGS_TREE (gedit_settings_menu),
/* GNOMEUIINFO_MENU_WINDOWS_TREE (gedit_window_menu), disabled by Chema */
GNOMEUIINFO_MENU_FILES_TREE (gedit_docs_menu),
GNOMEUIINFO_MENU_HELP_TREE (gedit_help_menu),
......
......@@ -33,7 +33,7 @@
#include "commands.h"
#include "document.h"
#include "utils.h"
#include "window.h"
Preferences *settings = NULL;
......@@ -66,8 +66,8 @@ gedit_save_settings (void)
gnome_config_set_int ("fgg", settings->fg[1]);
gnome_config_set_int ("fgb", settings->fg[2]);
if (GTK_IS_WIDGET (mdi->active_window))
gdk_window_get_size (GTK_WIDGET (mdi->active_window)->window,
if (GTK_IS_WIDGET (gedit_window_active()))
gdk_window_get_size (GTK_WIDGET (gedit_window_active())->window,
&settings->width, &settings->height);
gnome_config_set_int ("width", (gint) settings->width);
gnome_config_set_int ("height", (gint) settings->height);
......@@ -114,6 +114,7 @@ prefs_determine_use_fontset (void)
void
gedit_load_settings (void)
{
gchar * mdi_mode_string;
gedit_debug ("Loading preferencesn", DEBUG_PREFS);
if (!settings)
......@@ -125,7 +126,9 @@ gedit_load_settings (void)
gnome_config_push_prefix ("/gedit/Global/");
settings->tab_pos = gnome_config_get_int ("tab_pos=2");
settings->mdi_mode = gnome_config_get_int ("mdi_mode=42");
mdi_mode_string = g_strdup_printf ("mdi_mode=%i", GNOME_MDI_NOTEBOOK);
settings->mdi_mode = gnome_config_get_int (mdi_mode_string);
g_free (mdi_mode_string);
settings->auto_indent = gnome_config_get_bool ("auto_indent");
settings->word_wrap = gnome_config_get_bool ("word_wrap");
......
......@@ -33,6 +33,7 @@
#include "commands.h"
#include "prefs.h"
#include "utils.h"
#include "window.h"
#include <libgnomeprint/gnome-printer.h>
#include <libgnomeprint/gnome-print.h>
......@@ -105,9 +106,13 @@ static void print_end_page (PrintJobInfo *pji);
static void print_end_job (GnomePrintContext *pc);
static void preview_destroy_cb (GtkObject *obj, PrintJobInfo *pji);
static void print_pji_destroy (PrintJobInfo *pji);
static void print_set_pji ( PrintJobInfo * pji, Document *doc);
static gint print_set_pji ( PrintJobInfo * pji, Document *doc);
static gint gedit_print_verify_fonts (void);
#define GEDIT_PRINT_BODY_FONT "Courier"
#define GEDIT_PRINT_HEADER_FONT "Helvetica"
/**
* file_print_cb:
* @widget:
......@@ -143,7 +148,10 @@ file_print_cb (GtkWidget *widget, gpointer data, gint file_printpreview)
/* We need to calculate the number of pages before running
the dialog, so load pji with info now */
print_set_pji (pji, doc);
if (!print_set_pji (pji, doc))
{
return;
}
/* file_print preview is a false when preview is requested */
if (file_printpreview)
......@@ -451,21 +459,84 @@ print_ps_line (PrintJobInfo * pji, gint line, gint first_line)
{
char * number_text = g_strdup_printf ("%i",line);
GnomeFont *temp_font = gnome_font_new (pji->font_name, 6);
g_assert (pji->font_name!=NULL);
g_return_if_fail (temp_font != NULL);
gnome_print_setfont (pji->pc, temp_font);
gnome_print_moveto (pji->pc, pji->margin_left - pji->margin_numbers, y);
gnome_print_show (pji->pc, number_text);
g_free (number_text);
gtk_object_unref (GTK_OBJECT(temp_font));
print_setfont (pji);
}
}
static void
/**
* gedit_print_verify_fonts:
* @void:
*
* verify that the fonts that we are going to use are available
*
* Return Value:
**/
static gint
gedit_print_verify_fonts (void)
{
GnomeFont *test_font;
guchar * test_font_name;
gedit_debug ("", DEBUG_PRINT);
/* Courier */
test_font_name = g_strdup (GEDIT_PRINT_BODY_FONT);
test_font = gnome_font_new (test_font_name, 10);
if (test_font==NULL)
{
gchar *errstr = g_strdup_printf (_("gedit could not find the font \"%s\".\n"
"gedit is unable to print without this font installed."),
test_font_name);
gnome_app_error (gedit_window_active_app(), errstr);
g_free (errstr);
return FALSE;
}
gtk_object_unref (GTK_OBJECT (test_font));
g_free (test_font_name);
/* Helvetica */
test_font_name = g_strdup (GEDIT_PRINT_HEADER_FONT);
test_font = gnome_font_new (test_font_name, 10);
if (test_font==NULL)
{
gchar *errstr = g_strdup_printf (_("gedit could not find the font \"%s\".\n"
"gedit is unable to print without this font installed."),
test_font_name);
gnome_app_error (gedit_window_active_app(), errstr);
g_free (errstr);
return FALSE;
}
gtk_object_unref (GTK_OBJECT (test_font));
g_free (test_font_name);
return TRUE;
}
/**
* print_set_pji:
* @pji:
* @doc:
*
*
*
* Return Value: TRUE on success and FALSE on error
**/
static gint
print_set_pji (PrintJobInfo * pji, Document *doc)
{
gedit_debug ("", DEBUG_PRINT);
if (!gedit_print_verify_fonts())
return FALSE;
pji->view = gedit_view_current();
pji->doc = doc;
pji->buffer_size = gtk_text_get_length(GTK_TEXT(pji->view->text));
......@@ -503,7 +574,7 @@ print_set_pji (PrintJobInfo * pji, Document *doc)