Commit c193cf30 authored by Paolo Maggi's avatar Paolo Maggi Committed by Paolo Maggi

new function

2002-02-22  Paolo Maggi  <maggi@athena.polito.it>

	* gedit-mdi.[ch](gedit_mdi_clear_active_window_statusbar):
	new function

	* gedit-file.c (gedit_file_close): call
	gedit_mdi_clear_active_window_statusbar
	(gedit_file_close_all): ditto

	* gedit-document.c (gedit_document_get_untitled_number)
	(gedit_document_release_untitled_number): new function
	Now the untitled numbers are assigned in a smarter way
parent 59f25f66
2002-02-21 Paolo Maggi <maggi@athena.polito.it>
2002-02-22 Paolo Maggi <maggi@athena.polito.it>
* BUGS: Updated
* HACKING: Updated
2002-02-21 Paolo Maggi <maggi@athena.polito.it>
Name changed: gedit2->gedit
......
CVS guidelines for gedit.
CVS guidelines for gedit
========================
Please don't commit directly to the cvs unless you have been
Please don't commit directly to the CVS unless you have been
given the green light to commit freely to gedit, when in doubt
assume you haven't ;-).
Please send patches to maggi@athena.polito.it and eventually cc to
the gedit mailing list.
I will review them with much pleassure.
the gedit mailing list (you find the address on gedit.sourceforge.net).
I will review them with much pleasure.
If you are a translator feel free to mark strings for translation,
fix typos in the code etc.
fix typos in the code, etc.
Please send patches for build & configure in fixes too. We apreciate
your help, but we just want to review this fixes before applying.
Please send patches for build & configure in fixes too. I appreciate
very much your help, but I just want to review this fixes before applying.
Thanks
Paolo
2002-02-22 Paolo Maggi <maggi@athena.polito.it>
* gedit-mdi.[ch](gedit_mdi_clear_active_window_statusbar):
new function
* gedit-file.c (gedit_file_close): call
gedit_mdi_clear_active_window_statusbar
(gedit_file_close_all): ditto
* gedit-document.c (gedit_document_get_untitled_number)
(gedit_document_release_untitled_number): new function
Now the untitled numbers are assigned in a smarter way
2002-02-22 Paolo Maggi <maggi@athena.polito.it>
* gedit-file.c (gedit_file_new): active view grabs focus
......
......@@ -67,8 +67,6 @@ struct _GeditDocumentPrivate
GeditUndoManager *undo_manager;
};
static gint current_max_untitled_num = 0;
enum {
NAME_CHANGED,
SAVED,
......@@ -106,6 +104,52 @@ static gboolean gedit_document_auto_save_timeout (GeditDocument *doc);
static GtkTextBufferClass *parent_class = NULL;
static guint document_signals[LAST_SIGNAL] = { 0 };
static GHashTable* allocated_untitled_numbers = NULL;
static gint gedit_document_get_untitled_number (void);
static void gedit_document_release_untitled_number (gint n);
static gint
gedit_document_get_untitled_number (void)
{
gint i = 1;
gedit_debug (DEBUG_DOCUMENT, "");
if (allocated_untitled_numbers == NULL)
allocated_untitled_numbers = g_hash_table_new (NULL, NULL);
g_return_val_if_fail (allocated_untitled_numbers != NULL, -1);
while (TRUE)
{
if (g_hash_table_lookup (allocated_untitled_numbers, GINT_TO_POINTER (i)) == NULL)
{
g_hash_table_insert (allocated_untitled_numbers,
GINT_TO_POINTER (i),
GINT_TO_POINTER (i));
return i;
}
++i;
}
}
static void
gedit_document_release_untitled_number (gint n)
{
gboolean ret;
g_return_if_fail (allocated_untitled_numbers != NULL);
gedit_debug (DEBUG_DOCUMENT, "");
ret = g_hash_table_remove (allocated_untitled_numbers, GINT_TO_POINTER (n));
g_return_if_fail (ret);
}
GType
gedit_document_get_type (void)
......@@ -283,20 +327,19 @@ gedit_document_finalize (GObject *object)
if (document->priv->auto_save_timeout > 0)
g_source_remove (document->priv->auto_save_timeout);
if (document->priv->untitled_number > 0)
{
g_return_if_fail (document->priv->uri == NULL);
gedit_document_release_untitled_number (
document->priv->untitled_number);
}
if (document->priv->uri)
{
g_free (document->priv->uri);
document->priv->uri = NULL;
if (current_max_untitled_num == document->priv->untitled_number)
--current_max_untitled_num;
}
else
{
if (current_max_untitled_num == document->priv->untitled_number)
--current_max_untitled_num;
}
}
if (document->priv->last_searched_text)
g_free (document->priv->last_searched_text);
......@@ -328,7 +371,9 @@ gedit_document_new (void)
document = GEDIT_DOCUMENT (g_object_new (GEDIT_TYPE_DOCUMENT, NULL));
g_return_val_if_fail (document->priv != NULL, NULL);
document->priv->untitled_number = ++current_max_untitled_num;
document->priv->untitled_number = gedit_document_get_untitled_number ();
g_return_val_if_fail (document->priv->untitled_number > 0, NULL);
return document;
}
......@@ -338,9 +383,9 @@ gedit_document_new (void)
* @uri: the URI of the file that has to be loaded
* @error: return location for error or NULL
*
* Creates a new untitled document.
* Creates a new document.
*
* Return value: a new untitled document
* Return value: a new document
**/
GeditDocument*
gedit_document_new_with_uri (const gchar *uri, GError **error)
......@@ -762,7 +807,12 @@ gedit_document_set_uri (GeditDocument* doc, const gchar* uri)
g_free (doc->priv->uri);
doc->priv->uri = g_strdup (uri);
doc->priv->untitled_number = 0;
if (doc->priv->untitled_number > 0)
{
gedit_document_release_untitled_number (doc->priv->untitled_number);
doc->priv->untitled_number = 0;
}
g_signal_emit (G_OBJECT (doc), document_signals[NAME_CHANGED], 0);
}
......
......@@ -88,7 +88,7 @@ gedit_file_close (GtkWidget *view)
g_return_if_fail (child != NULL);
if (g_list_length (bonobo_mdi_child_get_views (child)) > 1)
{
{
ret = bonobo_mdi_remove_view (BONOBO_MDI (gedit_mdi), view, FALSE);
gedit_debug (DEBUG_COMMANDS, "View removed.");
}
......@@ -102,7 +102,10 @@ gedit_file_close (GtkWidget *view)
gedit_mdi_set_active_window_title (BONOBO_MDI (gedit_mdi));
if (bonobo_mdi_get_active_child (BONOBO_MDI (gedit_mdi)) == NULL)
{
gedit_mdi_set_active_window_verbs_sensitivity (BONOBO_MDI (gedit_mdi));
gedit_mdi_clear_active_window_statusbar (gedit_mdi);
}
}
void
......@@ -477,7 +480,10 @@ gedit_file_close_all (void)
ret = bonobo_mdi_remove_all (BONOBO_MDI (gedit_mdi), FALSE);
if (bonobo_mdi_get_active_child (BONOBO_MDI (gedit_mdi)) == NULL)
{
gedit_mdi_set_active_window_verbs_sensitivity (BONOBO_MDI (gedit_mdi));
gedit_mdi_clear_active_window_statusbar (gedit_mdi);
}
return ret;
}
......
......@@ -5,6 +5,7 @@
*
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
* Copyright (C) 2002 Paolo Maggi
*
* 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
......@@ -23,7 +24,7 @@
*/
/*
* Modified by the gedit Team, 1998-2001. See the AUTHORS file for a
* Modified by the gedit Team, 1998-2002. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*/
......@@ -907,6 +908,31 @@ void gedit_mdi_view_changed_handler (BonoboMDI *mdi, GtkWidget *old_view)
gedit_view_set_overwrite_mode_statusbar (active_view, status);
}
void
gedit_mdi_clear_active_window_statusbar (GeditMDI *mdi)
{
gpointer status;
BonoboWindow *win;
win = bonobo_mdi_get_active_window (BONOBO_MDI (mdi));
if (win == NULL)
return;
status = g_object_get_data (G_OBJECT (win), "CursorPosition");
g_return_if_fail (status != NULL);
g_return_if_fail (GTK_IS_STATUSBAR (status));
/* clear any previous message, underflow is allowed */
gtk_statusbar_pop (GTK_STATUSBAR (status), 0);
status = g_object_get_data (G_OBJECT (win), "OverwriteMode");
g_return_if_fail (status != NULL);
g_return_if_fail (GTK_IS_STATUSBAR (status));
/* clear any previous message, underflow is allowed */
gtk_statusbar_pop (GTK_STATUSBAR (status), 0);
}
void
gedit_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi)
{
......
......@@ -5,6 +5,7 @@
*
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
* Copyright (C) 2002 Paolo Maggi
*
* 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
......@@ -19,11 +20,11 @@
* 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. * *
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the gedit Team, 1998-2001. See the AUTHORS file for a
* Modified by the gedit Team, 1998-2002. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*/
......@@ -70,5 +71,7 @@ void gedit_mdi_update_ui_according_to_preferences (GeditMDI *mdi);
/* FIXME: should be static ??? */
void gedit_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi);
void gedit_mdi_clear_active_window_statusbar (GeditMDI *mdi);
#endif /* __GEDIT_MDI_H__ */
......@@ -830,7 +830,7 @@ gedit_view_set_cursor_position_statusbar (GeditView *view, GtkWidget* status)
gedit_debug (DEBUG_VIEW, "");
g_return_if_fail (GEDIT_IS_VIEW (view));
view->priv->cursor_position_statusbar = status;
if ((status != NULL) && (view->priv->document != NULL))
......
2002-02-22 Paolo Maggi <maggi@athena.polito.it>
* gedit-mdi.[ch](gedit_mdi_clear_active_window_statusbar):
new function
* gedit-file.c (gedit_file_close): call
gedit_mdi_clear_active_window_statusbar
(gedit_file_close_all): ditto
* gedit-document.c (gedit_document_get_untitled_number)
(gedit_document_release_untitled_number): new function
Now the untitled numbers are assigned in a smarter way
2002-02-22 Paolo Maggi <maggi@athena.polito.it>
* gedit-file.c (gedit_file_new): active view grabs focus
......
......@@ -67,8 +67,6 @@ struct _GeditDocumentPrivate
GeditUndoManager *undo_manager;
};
static gint current_max_untitled_num = 0;
enum {
NAME_CHANGED,
SAVED,
......@@ -106,6 +104,52 @@ static gboolean gedit_document_auto_save_timeout (GeditDocument *doc);
static GtkTextBufferClass *parent_class = NULL;
static guint document_signals[LAST_SIGNAL] = { 0 };
static GHashTable* allocated_untitled_numbers = NULL;
static gint gedit_document_get_untitled_number (void);
static void gedit_document_release_untitled_number (gint n);
static gint
gedit_document_get_untitled_number (void)
{
gint i = 1;
gedit_debug (DEBUG_DOCUMENT, "");
if (allocated_untitled_numbers == NULL)
allocated_untitled_numbers = g_hash_table_new (NULL, NULL);
g_return_val_if_fail (allocated_untitled_numbers != NULL, -1);
while (TRUE)
{
if (g_hash_table_lookup (allocated_untitled_numbers, GINT_TO_POINTER (i)) == NULL)
{
g_hash_table_insert (allocated_untitled_numbers,
GINT_TO_POINTER (i),
GINT_TO_POINTER (i));
return i;
}
++i;
}
}
static void
gedit_document_release_untitled_number (gint n)
{
gboolean ret;
g_return_if_fail (allocated_untitled_numbers != NULL);
gedit_debug (DEBUG_DOCUMENT, "");
ret = g_hash_table_remove (allocated_untitled_numbers, GINT_TO_POINTER (n));
g_return_if_fail (ret);
}
GType
gedit_document_get_type (void)
......@@ -283,20 +327,19 @@ gedit_document_finalize (GObject *object)
if (document->priv->auto_save_timeout > 0)
g_source_remove (document->priv->auto_save_timeout);
if (document->priv->untitled_number > 0)
{
g_return_if_fail (document->priv->uri == NULL);
gedit_document_release_untitled_number (
document->priv->untitled_number);
}
if (document->priv->uri)
{
g_free (document->priv->uri);
document->priv->uri = NULL;
if (current_max_untitled_num == document->priv->untitled_number)
--current_max_untitled_num;
}
else
{
if (current_max_untitled_num == document->priv->untitled_number)
--current_max_untitled_num;
}
}
if (document->priv->last_searched_text)
g_free (document->priv->last_searched_text);
......@@ -328,7 +371,9 @@ gedit_document_new (void)
document = GEDIT_DOCUMENT (g_object_new (GEDIT_TYPE_DOCUMENT, NULL));
g_return_val_if_fail (document->priv != NULL, NULL);
document->priv->untitled_number = ++current_max_untitled_num;
document->priv->untitled_number = gedit_document_get_untitled_number ();
g_return_val_if_fail (document->priv->untitled_number > 0, NULL);
return document;
}
......@@ -338,9 +383,9 @@ gedit_document_new (void)
* @uri: the URI of the file that has to be loaded
* @error: return location for error or NULL
*
* Creates a new untitled document.
* Creates a new document.
*
* Return value: a new untitled document
* Return value: a new document
**/
GeditDocument*
gedit_document_new_with_uri (const gchar *uri, GError **error)
......@@ -762,7 +807,12 @@ gedit_document_set_uri (GeditDocument* doc, const gchar* uri)
g_free (doc->priv->uri);
doc->priv->uri = g_strdup (uri);
doc->priv->untitled_number = 0;
if (doc->priv->untitled_number > 0)
{
gedit_document_release_untitled_number (doc->priv->untitled_number);
doc->priv->untitled_number = 0;
}
g_signal_emit (G_OBJECT (doc), document_signals[NAME_CHANGED], 0);
}
......
......@@ -88,7 +88,7 @@ gedit_file_close (GtkWidget *view)
g_return_if_fail (child != NULL);
if (g_list_length (bonobo_mdi_child_get_views (child)) > 1)
{
{
ret = bonobo_mdi_remove_view (BONOBO_MDI (gedit_mdi), view, FALSE);
gedit_debug (DEBUG_COMMANDS, "View removed.");
}
......@@ -102,7 +102,10 @@ gedit_file_close (GtkWidget *view)
gedit_mdi_set_active_window_title (BONOBO_MDI (gedit_mdi));
if (bonobo_mdi_get_active_child (BONOBO_MDI (gedit_mdi)) == NULL)
{
gedit_mdi_set_active_window_verbs_sensitivity (BONOBO_MDI (gedit_mdi));
gedit_mdi_clear_active_window_statusbar (gedit_mdi);
}
}
void
......@@ -477,7 +480,10 @@ gedit_file_close_all (void)
ret = bonobo_mdi_remove_all (BONOBO_MDI (gedit_mdi), FALSE);
if (bonobo_mdi_get_active_child (BONOBO_MDI (gedit_mdi)) == NULL)
{
gedit_mdi_set_active_window_verbs_sensitivity (BONOBO_MDI (gedit_mdi));
gedit_mdi_clear_active_window_statusbar (gedit_mdi);
}
return ret;
}
......
......@@ -5,6 +5,7 @@
*
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
* Copyright (C) 2002 Paolo Maggi
*
* 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
......@@ -23,7 +24,7 @@
*/
/*
* Modified by the gedit Team, 1998-2001. See the AUTHORS file for a
* Modified by the gedit Team, 1998-2002. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*/
......@@ -907,6 +908,31 @@ void gedit_mdi_view_changed_handler (BonoboMDI *mdi, GtkWidget *old_view)
gedit_view_set_overwrite_mode_statusbar (active_view, status);
}
void
gedit_mdi_clear_active_window_statusbar (GeditMDI *mdi)
{
gpointer status;
BonoboWindow *win;
win = bonobo_mdi_get_active_window (BONOBO_MDI (mdi));
if (win == NULL)
return;
status = g_object_get_data (G_OBJECT (win), "CursorPosition");
g_return_if_fail (status != NULL);
g_return_if_fail (GTK_IS_STATUSBAR (status));
/* clear any previous message, underflow is allowed */
gtk_statusbar_pop (GTK_STATUSBAR (status), 0);
status = g_object_get_data (G_OBJECT (win), "OverwriteMode");
g_return_if_fail (status != NULL);
g_return_if_fail (GTK_IS_STATUSBAR (status));
/* clear any previous message, underflow is allowed */
gtk_statusbar_pop (GTK_STATUSBAR (status), 0);
}
void
gedit_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi)
{
......
......@@ -5,6 +5,7 @@
*
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
* Copyright (C) 2002 Paolo Maggi
*
* 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
......@@ -19,11 +20,11 @@
* 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. * *
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the gedit Team, 1998-2001. See the AUTHORS file for a
* Modified by the gedit Team, 1998-2002. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*/
......@@ -70,5 +71,7 @@ void gedit_mdi_update_ui_according_to_preferences (GeditMDI *mdi);
/* FIXME: should be static ??? */
void gedit_mdi_set_active_window_verbs_sensitivity (BonoboMDI *mdi);
void gedit_mdi_clear_active_window_statusbar (GeditMDI *mdi);
#endif /* __GEDIT_MDI_H__ */
......@@ -830,7 +830,7 @@ gedit_view_set_cursor_position_statusbar (GeditView *view, GtkWidget* status)
gedit_debug (DEBUG_VIEW, "");
g_return_if_fail (GEDIT_IS_VIEW (view));
view->priv->cursor_position_statusbar = status;
if ((status != NULL) && (view->priv->document != NULL))
......
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