antiright-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Antiright-devel] antiright/gtkshell Makefile options.c undo.c


From: Jeffrey Bedard
Subject: [Antiright-devel] antiright/gtkshell Makefile options.c undo.c
Date: Tue, 11 Dec 2007 18:05:37 +0000

CVSROOT:        /sources/antiright
Module name:    antiright
Changes by:     Jeffrey Bedard <jefbed> 07/12/11 18:05:37

Modified files:
        gtkshell       : Makefile options.c undo.c 

Log message:
        Consolidate undo functions further.
        Begin work on hash table based command line option parsing.  

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/Makefile?cvsroot=antiright&r1=1.48&r2=1.49
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/options.c?cvsroot=antiright&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/antiright/gtkshell/undo.c?cvsroot=antiright&r1=1.2&r2=1.3

Patches:
Index: Makefile
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/Makefile,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49

Index: options.c
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/options.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- options.c   29 Nov 2007 18:22:44 -0000      1.33
+++ options.c   11 Dec 2007 18:05:37 -0000      1.34
@@ -89,6 +89,48 @@
 #define HANDLE(type)\
        gsh_handle_##type##_arguments(gsh, argc, argv, counter)
 
+static void
+tuple_callback(gpointer data)
+{
+       puts("callback succeeded");
+}
+
+static void
+add_label_cb(GSH * gsh, gint * counter, const gchar ** argv)
+{
+}
+
+static void
+add_updating_label_cb(GSH * gsh, gint * counter, const gchar ** argv)
+{
+}
+
+ARTupleVector *
+gsh_define_command_line_options()
+{
+       ARTupleVector * dictionary;
+
+#define ARTDEF(key, cb)\
+       $(dictionary, add, key, (const gchar *)cb);
+
+       dictionary=ARNEW(ar, ARTupleVector);
+       ARTDEF("-al", add_label_cb);
+       ARTDEF("-aul", add_updating_label_cb);
+       
+       return dictionary;
+}
+
+void
+gsh_handle_switch_argument(GSH * gsh, const gint argc, const gchar ** argv,
+       gint * counter, ARTupleVector * dict)
+{
+       void (*callback)(GSH *, gint *, const gchar **);
+       
+       callback=(void (*)(GSH *, gint *, const gchar **))
+               $(dict, find, argv[*counter]);
+       callback(gsh, counter, argv);
+}
+
 void
 gsh_handle_switch_arguments(GSH * gsh, const gint argc, const gchar **argv, 
        gint *counter)

Index: undo.c
===================================================================
RCS file: /sources/antiright/antiright/gtkshell/undo.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- undo.c      10 Dec 2007 15:13:24 -0000      1.2
+++ undo.c      11 Dec 2007 18:05:37 -0000      1.3
@@ -30,16 +30,6 @@
 /* BEGIN -- view.c extracts */
 static gint keyval;
 
-gint get_current_keyval(void)
-{
-       return keyval;
-}
-
-void clear_current_keyval(void)
-{
-       keyval = 0;
-}
-
 void scroll_to_cursor(GtkTextBuffer *buffer, gdouble within_margin)
 {
        gtk_text_view_scroll_to_mark(gsh_undo_text_view,
@@ -71,12 +61,12 @@
 static GList *redo_list = NULL;
 static GString *undo_gstr;
 static UndoInfo *ui_tmp;
-static gint modified_step;
+static guint modified_step;
 static guint prev_keyval;
 static gboolean seq_reserve = FALSE;
 
 static void 
-undo_flush_temporal_buffer(GtkTextBuffer *buffer);
+undo_flush_temporal_buffer(void);
 
 static GList 
 *undo_clear_info_list(GList *info_list)
@@ -90,7 +80,7 @@
 }
 
 static void 
-undo_append_undo_info(GtkTextBuffer *buffer, gchar command, 
+undo_append_undo_info(const gchar command, 
 gint start, gint end, gchar *str)
 {
        UndoInfo *ui = g_malloc(sizeof(UndoInfo));
@@ -123,7 +113,7 @@
        GtkTextIter start_iter, end_iter;
        gboolean seq_flag = FALSE;
        gchar *str;
-       gint keyval = get_current_keyval();
+       gint keyval = keyval;
        
        gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start);
        gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end);
@@ -174,7 +164,7 @@
                        gtk_widget_set_sensitive(redo_w, FALSE);
                        return;
                }
-               undo_append_undo_info(buffer, ui_tmp->command, 
+               undo_append_undo_info(ui_tmp->command, 
                        ui_tmp->start, ui_tmp->end, 
                        g_strdup(undo_gstr->str));
                undo_gstr = g_string_erase(undo_gstr, 0, -1);
@@ -194,19 +184,19 @@
                g_string_append(undo_gstr, str);
        } 
        else 
-               undo_append_undo_info(buffer, command, start, 
+               undo_append_undo_info(command, start, 
                        end, g_strdup(str));
        
        redo_list = undo_clear_info_list(redo_list);
        prev_keyval = keyval;
-       clear_current_keyval();
+       keyval=0;
        gtk_widget_set_sensitive(undo_w, TRUE);
        gtk_widget_set_sensitive(redo_w, FALSE);
 }
 
 static void 
 cb_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter, 
-       gchar *str, gint len)
+       const gchar *str)
 {
        gint start, end;
        
@@ -228,7 +218,7 @@
        start = gtk_text_iter_get_offset(start_iter);
        end = gtk_text_iter_get_offset(end_iter);
        
-       if (get_current_keyval() == GDK_BackSpace)
+       if (keyval == GDK_BackSpace)
                command = BS;
        else
                command = DEL;
@@ -236,15 +226,6 @@
 }
 
 static void 
-undo_reset_modified_step(GtkTextBuffer *buffer)
-{
-       undo_flush_temporal_buffer(buffer);
-       modified_step = g_list_length(undo_list);
-DV(g_print("undo_reset_modified_step: Reseted modified_step by %d\n", 
-       modified_step));
-}
-
-static void 
 undo_check_modified_step(GtkTextBuffer *buffer)
 {
        gboolean flag;
@@ -262,7 +243,7 @@
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                G_CALLBACK(cb_delete_range), NULL);
 DV(g_print("begin-user-action(unblock_func)"));
-DV(g_print(": keyval = 0x%X\n", get_current_keyval()));
+DV(g_print(": keyval = 0x%X\n", keyval));
 }
 
 static void 
@@ -276,20 +257,6 @@
 }
 
 void 
-undo_clear_all(GtkTextBuffer *buffer)
-{
-       undo_list = undo_clear_info_list(undo_list);
-       redo_list = undo_clear_info_list(redo_list);
-       undo_reset_modified_step(buffer);
-       gtk_widget_set_sensitive(undo_w, FALSE);
-       gtk_widget_set_sensitive(redo_w, FALSE);
-       
-       ui_tmp->command = INS;
-       undo_gstr = g_string_erase(undo_gstr, 0, -1);
-       prev_keyval = 0;
-}
-
-void 
 gsh_undo_init(GtkWidget *view, 
        GtkWidget *undo_button, 
        GtkWidget *redo_button)
@@ -313,34 +280,42 @@
        ui_tmp = g_malloc(sizeof(UndoInfo));
        undo_gstr = g_string_new("");
        
-       undo_clear_all(buffer);
-}
+       /* Clear undo history and state.  */
+       undo_list = undo_clear_info_list(undo_list);
+       redo_list = undo_clear_info_list(redo_list);
+       /* Reset modified step.  */
+       undo_flush_temporal_buffer();
+       modified_step = g_list_length(undo_list);
+       /* Set widget receptiveness.  */
+       gtk_widget_set_sensitive(undo_w, FALSE);
+       gtk_widget_set_sensitive(redo_w, FALSE);
 
-#if 0 /* Unused */
-static void 
-undo_set_sequency_reserve(void)
-{
-       seq_reserve = TRUE;
+       ui_tmp->command = INS;
+       undo_gstr = g_string_erase(undo_gstr, 0, -1);
+       prev_keyval = 0;
 }
-#endif /* 0 */
 
 static void 
-undo_flush_temporal_buffer(GtkTextBuffer *buffer)
+undo_flush_temporal_buffer(void)
 {
        if (undo_gstr->len) {
-               undo_append_undo_info(buffer, ui_tmp->command,
+               undo_append_undo_info(ui_tmp->command,
                        ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str));
                undo_gstr = g_string_erase(undo_gstr, 0, -1);
        }
 }
 
-static gboolean 
-undo_undo_real(GtkTextBuffer *buffer)
+void
+gsh_undo_undo(GtkTextBuffer *buffer)
 {
+       gboolean sentinel = FALSE;
+       do
+       {
        GtkTextIter start_iter, end_iter;
        UndoInfo *ui;
        
-       undo_flush_temporal_buffer(buffer);
+               sentinel=FALSE; 
+               undo_flush_temporal_buffer();
        if (g_list_length(undo_list)) 
        {
                ui = g_list_last(undo_list)->data;
@@ -363,28 +338,41 @@
                        g_list_last(undo_list));
 DV(g_print("cb_edit_undo: undo left = %d, redo left = %d\n",
 g_list_length(undo_list), g_list_length(redo_list)));
-               if (g_list_length(undo_list)) {
+               if (g_list_length(undo_list)) 
+               {
                        if (((UndoInfo *)g_list_last(undo_list)->data)->seq)
-                               return TRUE;
-               } else
+                               sentinel=TRUE;
+               } 
+               else
                        gtk_widget_set_sensitive(undo_w, FALSE);
+               if(!sentinel)
+               {
                gtk_widget_set_sensitive(redo_w, TRUE);
-               if (ui->command == DEL)
+                       if(ui->command == DEL)
                        gtk_text_buffer_get_iter_at_offset(buffer, 
                                &start_iter, ui->start);
                gtk_text_buffer_place_cursor(buffer, &start_iter);
                scroll_to_cursor(buffer, 0.05);
        }
+       }
+               if(!sentinel)
        undo_check_modified_step(buffer);
-       return FALSE;
+       } while(sentinel);
 }
 
-gboolean undo_redo_real(GtkTextBuffer *buffer)
+void
+gsh_undo_redo(GtkTextBuffer *buffer)
 {
+       gboolean sentinel=FALSE;
+
+       do
+       {
        GtkTextIter start_iter, end_iter;
        UndoInfo *ri;
        
-       if (g_list_length(redo_list)) {
+               sentinel=FALSE;
+               if (g_list_length(redo_list)) 
+               {
                ri = g_list_last(redo_list)->data;
                gtk_text_buffer_get_iter_at_offset(buffer, 
                        &start_iter, ri->start);
@@ -402,31 +390,28 @@
                undo_list = g_list_append(undo_list, ri);
                redo_list = g_list_delete_link(redo_list, 
                        g_list_last(redo_list));
-DV(g_print("cb_edit_redo: undo left = %d, redo left = %d\n",
-g_list_length(undo_list), g_list_length(redo_list)));
+                       DV(g_print("cb_edit_redo: undo left = %d, "
+                               "redo left = %d\n", g_list_length(undo_list), 
+                               g_list_length(redo_list)));
                if (ri->seq) 
                {
                        undo_set_sequency(TRUE);
-                       return TRUE;
+                               sentinel=TRUE;
                }
+                       else
+                       {
                if (!g_list_length(redo_list))
-                       gtk_widget_set_sensitive(redo_w, FALSE);
+                                       gtk_widget_set_sensitive(redo_w, 
+                                               FALSE);
                gtk_widget_set_sensitive(undo_w, TRUE);
-               gtk_text_buffer_place_cursor(buffer, &start_iter);
+                               gtk_text_buffer_place_cursor(buffer, 
+                                       &start_iter);
                scroll_to_cursor(buffer, 0.05);
        }
+               }
+               if(!sentinel)
        undo_check_modified_step(buffer);
-       return FALSE;
+       } while(sentinel);
 }
 
-void 
-gsh_undo_undo(GtkTextBuffer *buffer)
-{
-       while (undo_undo_real(buffer)) {};
-}
 
-void 
-gsh_undo_redo(GtkTextBuffer *buffer)
-{
-       while (undo_redo_real(buffer)) {};
-}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]