[almanah] Don't display the Add Definition dialogue for pre-existing definition texts
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [almanah] Don't display the Add Definition dialogue for pre-existing definition texts
- Date: Sun, 10 May 2009 13:55:22 -0400 (EDT)
commit 55f441eb5e93c8fcfdb76b449c9f30c191d2f4ae
Author: Philip Withnall <philip tecnocode co uk>
Date: Sun May 10 09:18:19 2009 +0100
Don't display the Add Definition dialogue for pre-existing definition texts
---
src/main-window.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/main-window.c b/src/main-window.c
index 0b0f83a..9bbfcc4 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -445,6 +445,7 @@ add_definition_to_current_entry (AlmanahMainWindow *self)
AlmanahMainWindowPrivate *priv = self->priv;
GtkTextIter start_iter, end_iter;
gchar *text;
+ AlmanahDefinition *definition;
g_assert (priv->entry_buffer != NULL);
g_assert (gtk_text_buffer_get_char_count (priv->entry_buffer) != 0);
@@ -454,6 +455,19 @@ add_definition_to_current_entry (AlmanahMainWindow *self)
text = gtk_text_buffer_get_text (priv->entry_buffer, &start_iter, &end_iter, FALSE);
+ /* If the definition already exists, don't display the dialogue */
+ definition = almanah_storage_manager_get_definition (almanah->storage_manager, text);
+ if (definition != NULL) {
+ g_object_unref (definition);
+
+ /* Add a GtkTextTag to the GtkTextBuffer to mark the definition */
+ gtk_text_buffer_apply_tag_by_name (priv->entry_buffer, "definition", &start_iter, &end_iter);
+ gtk_text_buffer_set_modified (priv->entry_buffer, TRUE);
+
+ g_free (text);
+ return;
+ }
+
/* Create the Add Definition dialogue if it doesn't already exist */
if (almanah->add_definition_dialog == NULL)
almanah->add_definition_dialog = GTK_WIDGET (almanah_add_definition_dialog_new ());
@@ -464,8 +478,6 @@ add_definition_to_current_entry (AlmanahMainWindow *self)
gtk_widget_show_all (almanah->add_definition_dialog);
if (gtk_dialog_run (GTK_DIALOG (almanah->add_definition_dialog)) == GTK_RESPONSE_OK) {
- AlmanahDefinition *definition;
-
definition = almanah_add_definition_dialog_get_definition (ALMANAH_ADD_DEFINITION_DIALOG (almanah->add_definition_dialog));
if (definition == NULL)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]