Commit 2ab27ef1 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg
Browse files

generalize and fix leak. (cb_add_clicked) : generalize. (cb_select_row) :

2001-11-01  Jody Goldberg <jgoldberg@home.com>

	* dialog-autocorrect.c (cb_remove_clicked) : generalize and fix leak.
	(cb_add_clicked) : generalize.
	(cb_select_row) : generalize.
	(autocorrect_init_exception_list) : new.
	(exceptions_callback) : clean up slightly.
	(ac_button_toggled) : simplify.
	(ac_dialog_toggle_init) : new.
	(dialog_autocorrect) : simplify.  Rather than saving the content
          and restoring on cancel, only store the new values on <OK>.

2001-11-01  Jody Goldberg <jgoldberg@home.com>

	* src/workbook-edit.c (entry_changed) : autocomplete is in the wbv now.
	(wbcg_edit_start) : ditto.

	* src/sheet-style.c (rstyle_apply) : fix some silliness in the new
	  code, but more work to come.

	* src/commands.c (cmd_set_text) : Yay! autocorrect is no longer tied
	  to the gui.

	* src/application.c (application_init) : Init autocorrection.

	* src/workbook-view.c (wb_view_set_arg) : add do_auto_completion.
	  Make this a per workbook-view, persistent attribute.  We still
	  initialize from gnome-config, butthis should make things easier
	  for users.
	(wb_view_get_arg) : ditto.
	(workbook_view_class_init) : ditto.
parent a383aea0
2001-11-01 Jody Goldberg <jgoldberg@home.com>
* src/workbook-edit.c (entry_changed) : autocomplete is in the wbv now.
(wbcg_edit_start) : ditto.
* src/sheet-style.c (rstyle_apply) : fix some silliness in the new
code, but more work to come.
* src/commands.c (cmd_set_text) : Yay! autocorrect is no longer tied
to the gui.
* src/application.c (application_init) : Init autocorrection.
* src/workbook-view.c (wb_view_set_arg) : add do_auto_completion.
Make this a per workbook-view, persistent attribute. We still
initialize from gnome-config, butthis should make things easier
for users.
(wb_view_get_arg) : ditto.
(workbook_view_class_init) : ditto.
2001-11-01 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* src/GNOME_Gnumeric.xml, src/worbook-control-gui.c: Added Filter
......
......@@ -14,6 +14,9 @@ Jody:
* Improve formula guru.
* Support scrollwheel in a larger area.
* Fix Edit -> Fill -> Autofill
* Improve dbf importer.
* Make autocorrect non-modal and cleaner.
* Make autocompletion a view attribute, with a gui.
Jukka:
* Lots of documentation added.
......
2001-11-01 Jody Goldberg <jgoldberg@home.com>
* src/workbook-edit.c (entry_changed) : autocomplete is in the wbv now.
(wbcg_edit_start) : ditto.
* src/sheet-style.c (rstyle_apply) : fix some silliness in the new
code, but more work to come.
* src/commands.c (cmd_set_text) : Yay! autocorrect is no longer tied
to the gui.
* src/application.c (application_init) : Init autocorrection.
* src/workbook-view.c (wb_view_set_arg) : add do_auto_completion.
Make this a per workbook-view, persistent attribute. We still
initialize from gnome-config, butthis should make things easier
for users.
(wb_view_get_arg) : ditto.
(workbook_view_class_init) : ditto.
2001-11-01 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* src/GNOME_Gnumeric.xml, src/worbook-control-gui.c: Added Filter
......
2001-11-01 Jody Goldberg <jgoldberg@home.com>
* src/workbook-edit.c (entry_changed) : autocomplete is in the wbv now.
(wbcg_edit_start) : ditto.
* src/sheet-style.c (rstyle_apply) : fix some silliness in the new
code, but more work to come.
* src/commands.c (cmd_set_text) : Yay! autocorrect is no longer tied
to the gui.
* src/application.c (application_init) : Init autocorrection.
* src/workbook-view.c (wb_view_set_arg) : add do_auto_completion.
Make this a per workbook-view, persistent attribute. We still
initialize from gnome-config, butthis should make things easier
for users.
(wb_view_get_arg) : ditto.
(workbook_view_class_init) : ditto.
2001-11-01 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* src/GNOME_Gnumeric.xml, src/worbook-control-gui.c: Added Filter
......
2001-11-01 Jody Goldberg <jgoldberg@home.com>
* src/workbook-edit.c (entry_changed) : autocomplete is in the wbv now.
(wbcg_edit_start) : ditto.
* src/sheet-style.c (rstyle_apply) : fix some silliness in the new
code, but more work to come.
* src/commands.c (cmd_set_text) : Yay! autocorrect is no longer tied
to the gui.
* src/application.c (application_init) : Init autocorrection.
* src/workbook-view.c (wb_view_set_arg) : add do_auto_completion.
Make this a per workbook-view, persistent attribute. We still
initialize from gnome-config, butthis should make things easier
for users.
(wb_view_get_arg) : ditto.
(workbook_view_class_init) : ditto.
2001-11-01 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* src/GNOME_Gnumeric.xml, src/worbook-control-gui.c: Added Filter
......
......@@ -54,7 +54,6 @@ src/dialogs/advanced-filter.glade
src/dialogs/analysis-tools.glade
src/dialogs/anova-one.glade
src/dialogs/anova-two.glade
src/dialogs/autocorrect-exceptions.glade
src/dialogs/autocorrect.glade
src/dialogs/autoformat.glade
src/dialogs/autosave-prompt.glade
......
......@@ -27,6 +27,8 @@ GNUMERIC_BASE = \
application.h \
auto-format.c \
auto-format.h \
auto-correct.c \
auto-correct.h \
cell.h \
cell.c \
cell-draw.c \
......
......@@ -3,13 +3,8 @@
*
* Author:
* Jody Goldberg <jgoldberg@home.com>
*
*/
#include <config.h>
#include <gtk/gtk.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-config.h>
#include <libgnomeui/gnome-stock.h>
#include "application.h"
#include "clipboard.h"
#include "selection.h"
......@@ -18,6 +13,7 @@
#include "workbook.h"
#include "sheet.h"
#include "sheet-private.h"
#include "auto-correct.h"
#include "pixmaps/menu-print-preview.xpm"
#include "pixmaps/print-preview.xpm"
......@@ -105,6 +101,11 @@
#include "pixmaps/24_show_detail.xpm"
#include "pixmaps/24_hide_detail.xpm"
#include <gtk/gtk.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-config.h>
#include <libgnomeui/gnome-stock.h>
typedef struct
{
/* Clipboard */
......@@ -278,6 +279,8 @@ application_init (void)
*/
app.auto_expr_recalc_lag = gnome_config_get_int ("AutoExprRecalcLag=200");
gnome_config_pop_prefix ();
autocorrect_init ();
}
static GList *workbook_list = NULL;
......
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* auto-correct.c:
*
* Author:
* Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
*
* (C) Copyright 2000, 2001 by Jukka-Pekka Iivonen <iivonen@iki.fi>
*/
#include <config.h>
#include "auto-correct.h"
#include <ctype.h>
#include <string.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-config.h>
static struct {
gboolean init_caps : 1;
gboolean first_letter : 1;
gboolean names_of_days : 1;
gboolean caps_lock : 1;
gboolean replace : 1;
struct {
GList *first_letter;
GList *init_caps;
} exceptions;
} autocorrect;
void
autocorrect_init (void)
{
gnome_config_push_prefix ("Gnumeric/AutoCorrect/");
autocorrect.init_caps = gnome_config_get_bool ("init_caps=true");
autocorrect.first_letter = gnome_config_get_bool ("first_letter=true");
autocorrect.names_of_days = gnome_config_get_bool ("names_of_days=true");
autocorrect.caps_lock = gnome_config_get_bool ("caps_lock=true");
autocorrect.replace = gnome_config_get_bool ("replace=true");
gnome_config_pop_prefix ();
/* TODO */
autocorrect.exceptions.first_letter = NULL;
autocorrect.exceptions.init_caps = NULL;
}
void
autocorrect_store_config (void)
{
gnome_config_push_prefix ("Gnumeric/AutoCorrect/");
gnome_config_set_bool ("init_caps", autocorrect.init_caps);
gnome_config_set_bool ("first_letter", autocorrect.first_letter);
gnome_config_set_bool ("names_of_days", autocorrect.names_of_days);
gnome_config_set_bool ("caps_lock", autocorrect.caps_lock);
gnome_config_set_bool ("replace", autocorrect.replace);
gnome_config_pop_prefix ();
}
gboolean
autocorrect_get_feature (AutoCorrectFeature feature)
{
switch (feature) {
case AC_INIT_CAPS : return autocorrect.init_caps;
case AC_FIRST_LETTER : return autocorrect.first_letter;
case AC_NAMES_OF_DAYS : return autocorrect.names_of_days;
case AC_CAPS_LOCK : return autocorrect.caps_lock;
case AC_REPLACE : return autocorrect.replace;
default :
g_warning ("Invalid autocorrect feature %d.", feature);
};
return TRUE;
}
void
autocorrect_set_feature (AutoCorrectFeature feature, gboolean val)
{
switch (feature) {
case AC_INIT_CAPS : autocorrect.init_caps = val; break;
case AC_FIRST_LETTER : autocorrect.first_letter = val; break;
case AC_NAMES_OF_DAYS : autocorrect.names_of_days = val;break;
case AC_CAPS_LOCK : autocorrect.caps_lock = val; break;
case AC_REPLACE : autocorrect.replace = val; break;
default :
g_warning ("Invalid autocorrect feature %d.", feature);
};
}
GList *
autocorrect_get_exceptions (AutoCorrectFeature feature)
{
switch (feature) {
case AC_INIT_CAPS : return autocorrect.exceptions.init_caps;
case AC_FIRST_LETTER : return autocorrect.exceptions.first_letter;
default :
g_warning ("Invalid autocorrect feature %d.", feature);
};
return NULL;
}
void
autocorrect_set_exceptions (AutoCorrectFeature feature, GList *list)
{
switch (feature) {
case AC_INIT_CAPS : autocorrect.exceptions.init_caps = list; break;
case AC_FIRST_LETTER : autocorrect.exceptions.first_letter = list; break;
default :
g_warning ("Invalid autocorrect feature %d.", feature);
};
}
/* Add the name of the days on your language if they are always capitalized.
*/
static char const * const autocorrect_day [] = {
/* English */
"monday", "tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday", NULL
};
char *
autocorrect_tool (char const *command)
{
unsigned char *s;
unsigned char *ucommand = (unsigned char *)g_strdup (command);
gint i, len;
len = strlen (ucommand);
if (autocorrect.init_caps) {
for (s = ucommand; *s; s++) {
skip_ic_correct:
if (isupper (*s) && isupper (s[1])) {
if (islower (s[2])) {
GList *c = autocorrect.exceptions.init_caps;
while (c != NULL) {
guchar *a = (guchar *)c->data;
if (strncmp (s, a, strlen (a))
== 0) {
s++;
goto skip_ic_correct;
}
c = c->next;
}
s[1] = tolower (s[1]);
} else
while (!isspace(*s))
++s;
}
}
}
if (autocorrect.first_letter) {
unsigned char *p;
for (s = ucommand; *s; s = p+1) {
skip_first_letter:
p = strchr(s, '.');
if (p == NULL)
break;
while (isspace(*s))
++s;
if (islower (*s) && (s == ucommand || isspace (s[-1]))) {
GList *cur = autocorrect.exceptions.first_letter;
for ( ; cur != NULL; cur = cur->next) {
guchar *t, *c = (guchar *)cur->data;
gint l = strlen (c);
gint spaces = 0;
for (t = s - 1; t >= ucommand; t--)
if (isspace (*t))
++spaces;
else
break;
if (s - ucommand > l + spaces &&
strncmp(s-l-spaces, c, l) == 0) {
s = p + 1;
goto skip_first_letter;
}
}
*s = toupper (*s);
}
}
}
if (autocorrect.names_of_days)
for (i = 0; autocorrect_day[i] != NULL; i++) {
do {
s = strstr (ucommand, autocorrect_day[i]);
if (s != NULL)
*s = toupper (*s);
} while (s != NULL);
}
if (autocorrect.caps_lock)
if (len > 1 && islower (ucommand[0]) && isupper (ucommand[1]))
for (i = 0; i < len; i++)
if (isalpha (ucommand[i])) {
if (isupper (ucommand[i]))
ucommand[i] = tolower (ucommand[i]);
else
ucommand[i] = toupper (ucommand[i]);
}
return ucommand;
}
#ifndef DIALOG_AUTOCORRECT_H
#define DIALOG_AUTOCORRECT_H
#ifndef AUTO_CORRECT_H
#define AUTO_CORRECT_H
#include "gnumeric.h"
char *autocorrect_tool (const char *command);
typedef enum {
AC_INIT_CAPS,
AC_FIRST_LETTER,
AC_NAMES_OF_DAYS,
AC_CAPS_LOCK,
AC_REPLACE,
AC_MAX_FEATURE
} AutoCorrectFeature;
#endif /* DIALOG_AUTOCORRECT_H */
void autocorrect_init (void);
void autocorrect_store_config (void);
gboolean autocorrect_get_feature (AutoCorrectFeature feat);
void autocorrect_set_feature (AutoCorrectFeature feat, gboolean val);
GList *autocorrect_get_exceptions (AutoCorrectFeature feat);
void autocorrect_set_exceptions (AutoCorrectFeature feat, GList *list);
char *autocorrect_tool (char const *input);
#endif /* AUTO_CORRECT_H */
......@@ -44,9 +44,8 @@
#include "selection.h"
#include "datetime.h"
#include "colrow.h"
#include "dialogs.h"
#include "style-border.h"
#include "dialogs/dialog-autocorrect.h"
#include "auto-correct.h"
#include "sheet-autofill.h"
#include "mstyle.h"
#include "search.h"
......@@ -638,8 +637,6 @@ cmd_set_text (WorkbookControl *wbc,
return TRUE;
}
/* FIXME : abstract this */
/* From src/dialogs/dialog-autocorrect.c */
corrected_text = autocorrect_tool (new_text);
obj = gtk_type_new (CMD_SET_TEXT_TYPE);
......
2001-11-01 Jody Goldberg <jgoldberg@home.com>
* dialog-autocorrect.c (cb_remove_clicked) : generalize and fix leak.
(cb_add_clicked) : generalize.
(cb_select_row) : generalize.
(autocorrect_init_exception_list) : new.
(exceptions_callback) : clean up slightly.
(ac_button_toggled) : simplify.
(ac_dialog_toggle_init) : new.
(dialog_autocorrect) : simplify. Rather than saving the content
and restoring on cancel, only store the new values on <OK>.
2001-11-01 Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
* dialog-autosave.c (dialog_autosave): Fixed the help button.
......
......@@ -29,7 +29,6 @@ base_files = \
dialog-advanced-filter.c \
dialog-analysis-tools.c \
dialog-autocorrect.c \
dialog-autocorrect.h \
dialog-autoformat.c \
dialog-autosave.c \
dialog-cell-comment.c \
......@@ -79,7 +78,6 @@ glade_DATA = \
analysis-tools.glade \
anova-one.glade \
anova-two.glade \
autocorrect-exceptions.glade \
autocorrect.glade \
autoformat.glade \
autosave-prompt.glade \
......
<?xml version="1.0"?>
<GTK-Interface>
<project>
<name>Project3</name>
<program_name>project3</program_name>
<directory></directory>
<source_directory>src</source_directory>
<pixmaps_directory>pixmaps</pixmaps_directory>
<language>C</language>
<gnome_support>True</gnome_support>
<gettext_support>True</gettext_support>
</project>
<widget>
<class>GnomeDialog</class>
<name>AutoCorrectExceptions</name>
<visible>False</visible>
<title>AutoCorrect Exceptions</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox1</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHButtonBox</class>
<child_name>GnomeDialog:action_area</child_name>
<name>dialog-action_area1</name>
<layout_style>GTK_BUTTONBOX_END</layout_style>
<spacing>8</spacing>
<child_min_width>85</child_min_width>
<child_min_height>27</child_min_height>
<child_ipad_x>7</child_ipad_x>
<child_ipad_y>0</child_ipad_y>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>True</fill>
<pack>GTK_PACK_END</pack>
</child>
<widget>
<class>GtkButton</class>
<name>button1</name>
<can_default>True</can_default>
<has_default>True</has_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_OK</stock_button>
</widget>
<widget>
<class>GtkButton</class>
<name>button3</name>
<can_default>True</can_default>
<can_focus>True</can_focus>
<stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button>
</widget>
</widget>
<widget>
<class>GtkNotebook</class>
<name>notebook1</name>
<can_focus>True</can_focus>
<show_tabs>True</show_tabs>
<show_border>True</show_border>
<tab_pos>GTK_POS_TOP</tab_pos>
<scrollable>False</scrollable>
<tab_hborder>2</tab_hborder>
<tab_vborder>2</tab_vborder>
<popup_enable>False</popup_enable>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkHBox</class>
<name>hbox1</name>
<border_width>4</border_width>
<homogeneous>False</homogeneous>
<spacing>4</spacing>
<widget>
<class>GtkVBox</class>
<name>vbox1</name>
<homogeneous>False</homogeneous>
<spacing>4</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkLabel</class>
<name>label3</name>
<label>_Do not capitalize after:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>0.5</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<focus_target>entry1</focus_target>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
<widget>
<class>GtkVBox</class>
<name>vbox2</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
<widget>
<class>GtkEntry</class>
<name>entry1</name>
<can_focus>True</can_focus>
<has_focus>True</has_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<padding>0</padding>
<expand>False</expand>
<fill>False</fill>
</child>
</widget>
</widget>
<widget>
<class>GtkScrolledWindow</class>
<name>scrolledwindow3</name>
<hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy>
<vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy>