G_MODULE_EXPORT void
gw_addvocabularywindow_definitions_event_after_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
{

    GwAddVocabularyWindow *window;
    GwAddVocabularyWindowPrivate *priv;
    GtkTextIter start, end;
    GtkTextBuffer *buffer;
    gboolean valid;
    gboolean activate;

    window = GW_ADDVOCABULARYWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_ADDVOCABULARYWINDOW));
    g_return_if_fail (window != NULL);
    priv = window->priv;

    if (priv->pasted == TRUE) { priv->pasted = FALSE; return; }

    buffer = gtk_text_view_get_buffer (priv->definitions_textview);
    gtk_text_buffer_get_start_iter (buffer, &start);
    gtk_text_buffer_get_end_iter (buffer, &end);

    if (priv->definitions_text != NULL) g_free (priv->definitions_text);
    priv->definitions_text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
    activate = (strchr (priv->definitions_text, '\n') != NULL);
    g_strstrip (priv->definitions_text);

    gchar *source_ptr, *target_ptr;
    source_ptr = target_ptr = priv->definitions_text;
    while (*target_ptr != '\0')
    {
      if (*target_ptr == '\n') target_ptr++;
      else if (source_ptr == target_ptr)
      {
        source_ptr = ++target_ptr;
      }
      else
      {
        *(source_ptr++) = *(target_ptr++);
      }
    }
    *source_ptr = '\0';

    valid = gw_addvocabularywindow_validate (window);

    if (activate)
    {
      G_GNUC_EXTENSION g_signal_handlers_block_by_func (widget, gw_addvocabularywindow_definitions_event_after_cb, data);
      gtk_text_buffer_set_text (buffer, priv->definitions_text, -1);
      G_GNUC_EXTENSION g_signal_handlers_unblock_by_func (widget, gw_addvocabularywindow_definitions_event_after_cb, data);
      if (valid)
      {
        gtk_button_clicked (priv->add_button);
      }
    }
}
G_MODULE_EXPORT void
gw_addvocabularywindow_furigana_changed_cb (GtkWidget *widget, gpointer data)
{
    GwAddVocabularyWindow *window;
    GwAddVocabularyWindowPrivate *priv;

    window = GW_ADDVOCABULARYWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_ADDVOCABULARYWINDOW));
    g_return_if_fail (window != NULL);
    priv = window->priv;

    if (priv->furigana_text != NULL) g_free (priv->furigana_text);
    priv->furigana_text = g_strdup (gtk_entry_get_text (priv->furigana_entry));
    g_strstrip (priv->furigana_text);

    gw_addvocabularywindow_validate (window);
}
G_MODULE_EXPORT void
gw_addvocabularywindow_list_changed_cb (GtkWidget *widget, gpointer data)
{
    GwAddVocabularyWindow *window;
    GwAddVocabularyWindowPrivate *priv;
    GtkEntry *entry;

    window = GW_ADDVOCABULARYWINDOW (gtk_widget_get_ancestor (GTK_WIDGET (data), GW_TYPE_ADDVOCABULARYWINDOW));
    g_return_if_fail (window != NULL);
    priv = window->priv;
    entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (priv->vocabulary_list_combobox)));

    if (priv->list_text != NULL) g_free (priv->list_text);
    priv->list_text = g_strdup (gtk_entry_get_text (entry));
    g_strstrip (priv->list_text);

    gw_addvocabularywindow_validate (window);
}
Example #4
0
void
gw_addvocabularywindow_focus_add_button (GwAddVocabularyWindow *window)
{
    if (gw_addvocabularywindow_validate (window))
      gtk_widget_grab_focus (GTK_WIDGET (window->priv->add_button));
}