added redo

Wed, 26 Mar 2014 15:53:43 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 26 Mar 2014 15:53:43 +0100
changeset 8
84a541c6e093
parent 7
431dde3c5fbe
child 9
e70e855cea89
child 10
6f263196f916

added redo

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/text.c file | annotate | diff | comparison | revisions
--- a/application/main.c	Tue Mar 25 20:25:09 2014 +0100
+++ b/application/main.c	Wed Mar 26 15:53:43 2014 +0100
@@ -82,11 +82,13 @@
 void action_undo(UiEvent *event, void *data) {
     printf("undo\n");
     TestWindowData *wd = event->window;
-    //ui_text_undo(&wd->text);
+    ui_text_undo(&wd->text);
 }
 
 void action_redo(UiEvent *event, void *data) {
     printf("redo\n");
+    TestWindowData *wd = event->window;
+    ui_text_redo(&wd->text);
 }
 
 
@@ -101,7 +103,7 @@
     ui_menuitem("Dokument 1", action_doc1, NULL);
     ui_menuitem("Dokument 2", action_doc2, NULL);
     ui_menuseparator();
-    //ui_checkitem_nv("Check", "check1");
+    ui_checkitem_nv("Check", "check1");
     ui_menuitem("Close", action_close, NULL);
     
     
@@ -123,7 +125,7 @@
     
     printf("create window\n");
     UiObject *window = ui_window("Mod0", NULL);
-    TestWindowData *wdata = malloc(sizeof(TestWindowData));
+    TestWindowData *wdata = calloc(1, sizeof(TestWindowData));
     window->window = wdata;
     
     TestDocument *doc1 = ui_document_new(sizeof(TestDocument));
--- a/ui/gtk/text.c	Tue Mar 25 20:25:09 2014 +0100
+++ b/ui/gtk/text.c	Wed Mar 26 15:53:43 2014 +0100
@@ -130,7 +130,6 @@
         return;
     }
     
-    printf("insert\n");
     if(mgr->cur) {
         UcxList *elm = mgr->cur->next;
         while(elm) {
@@ -185,7 +184,6 @@
         return;
     }
     
-    printf("delete\n");
     if(mgr->cur) {
         UcxList *elm = mgr->cur->next;
         while(elm) {
@@ -280,5 +278,39 @@
 }
 
 void ui_text_redo(UiText *value) {
+    UiUndoMgr *mgr = value->undomgr;
     
+    UcxList *elm = NULL;
+    if(mgr->cur) {
+        if(mgr->cur->next) {
+            elm = mgr->cur->next;
+        }
+    } else if(mgr->begin) {
+        elm = mgr->begin;
+    }
+    
+    if(elm) {
+        UiTextBufOp *op = elm->data;
+        mgr->event = 0;
+        switch(op->type) {
+            case UI_TEXTBUF_INSERT: {
+                GtkTextIter begin;
+                GtkTextIter end;
+                gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start);
+                gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end);
+                gtk_text_buffer_insert(value->obj, &begin, op->text, op->len);
+                break;
+            }
+            case UI_TEXTBUF_DELETE: {
+                GtkTextIter begin;
+                GtkTextIter end;
+                gtk_text_buffer_get_iter_at_offset(value->obj, &begin, op->start);
+                gtk_text_buffer_get_iter_at_offset(value->obj, &end, op->end);
+                gtk_text_buffer_delete(value->obj, &begin, &end);
+                break;
+            }
+        }
+        mgr->event = 1;
+        mgr->cur = elm;
+    }
 }

mercurial