OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence | 2 * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence |
3 * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi | 3 * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi |
4 * Copyright (C) 2002-2005 Paolo Maggi | 4 * Copyright (C) 2002-2005 Paolo Maggi |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2.1 of the License, or (at your option) any later version. | 9 * version 2.1 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 * from the action list (freeing the list or resizing it) */ | 111 * from the action list (freeing the list or resizing it) */ |
112 GtkSourceUndoAction *modified_action; | 112 GtkSourceUndoAction *modified_action; |
113 }; | 113 }; |
114 | 114 |
115 enum { | 115 enum { |
116 CAN_UNDO, | 116 CAN_UNDO, |
117 CAN_REDO, | 117 CAN_REDO, |
118 LAST_SIGNAL | 118 LAST_SIGNAL |
119 }; | 119 }; |
120 | 120 |
| 121 #if !defined(NDEBUG) |
| 122 static void |
| 123 print_state(GtkSourceUndoManager* um) |
| 124 { |
| 125 fprintf(stderr, "\n***\n"); |
| 126 GList* actions = um->priv->actions; |
| 127 |
| 128 for (; actions; actions = g_list_next(actions)) { |
| 129 GtkSourceUndoAction* act = actions->data; |
| 130 fprintf(stderr, "* type = %s\n", act->action_type == GTK_SOURCE_UNDO_ACTION_
DELETE ? |
| 131 "delete" : "insert"); |
| 132 |
| 133 fprintf(stderr, "\ttext = %s\n", act->action_type == GTK_SOURCE_UNDO_ACTION_
DELETE |
| 134 ? act->action.delete.text : act->action.insert.text); |
| 135 fprintf(stderr, "\torder = %d\n", act->order_in_group); |
| 136 } |
| 137 |
| 138 fprintf(stderr, "* next redo: %d\n", um->priv->next_redo); |
| 139 fprintf(stderr, "* num of groups: %d\n", um->priv->num_of_groups); |
| 140 fprintf(stderr, "* actions in group: %d\n", um->priv->actions_in_current_group
); |
| 141 } |
| 142 #endif |
| 143 |
121 static void gtk_source_undo_manager_class_init(GtkSourceUndoManagerClass *klass)
; | 144 static void gtk_source_undo_manager_class_init(GtkSourceUndoManagerClass *klass)
; |
122 static void gtk_source_undo_manager_init(GtkSourceUndoManager *um); | 145 static void gtk_source_undo_manager_init(GtkSourceUndoManager *um); |
123 static void gtk_source_undo_manager_finalize(GObject *object); | 146 static void gtk_source_undo_manager_finalize(GObject *object); |
124 | 147 |
125 static void gtk_source_undo_manager_insert_text_handler(GtkTextBuffer *buffer, | 148 static void gtk_source_undo_manager_insert_text_handler(GtkTextBuffer *buffer, |
126 GtkTextIter *pos, | 149 GtkTextIter *pos, |
127 const gchar *text, | 150 const gchar *text, |
128 gint length, | 151 gint length, |
129 GtkSourceUndoManager *um); | 152 GtkSourceUndoManager *um); |
130 static void gtk_source_undo_manager_delete_range_handler(GtkTextBuffer *buffer, | 153 static void gtk_source_undo_manager_delete_range_handler(GtkTextBuffer *buffer, |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 GList *l; | 640 GList *l; |
618 | 641 |
619 l = um->priv->actions; | 642 l = um->priv->actions; |
620 | 643 |
621 while(l != NULL) | 644 while(l != NULL) |
622 { | 645 { |
623 GtkSourceUndoAction *action = l->data; | 646 GtkSourceUndoAction *action = l->data; |
624 | 647 |
625 if(action->order_in_group == 1) | 648 if(action->order_in_group == 1) |
626 --um->priv->num_of_groups; | 649 --um->priv->num_of_groups; |
| 650 um->priv->actions_in_current_group = action->order_in_group - 1; |
627 | 651 |
628 if(action->modified) | 652 if(action->modified) |
629 um->priv->modified_action = INVALID; | 653 um->priv->modified_action = INVALID; |
630 | 654 |
631 gtk_source_undo_action_free(action); | 655 gtk_source_undo_action_free(action); |
632 | 656 |
633 l = g_list_next(l); | 657 l = g_list_next(l); |
634 } | 658 } |
635 | 659 |
636 g_list_free(um->priv->actions); | 660 g_list_free(um->priv->actions); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 804 |
781 if(um->priv->actions == NULL) | 805 if(um->priv->actions == NULL) |
782 return; | 806 return; |
783 | 807 |
784 for(i = 0; i < n; i++) | 808 for(i = 0; i < n; i++) |
785 { | 809 { |
786 GtkSourceUndoAction *action = g_list_first(um->priv->actions)->data; | 810 GtkSourceUndoAction *action = g_list_first(um->priv->actions)->data; |
787 | 811 |
788 if(action->order_in_group == 1) | 812 if(action->order_in_group == 1) |
789 --um->priv->num_of_groups; | 813 --um->priv->num_of_groups; |
| 814 um->priv->actions_in_current_group = action->order_in_group - 1; |
790 | 815 |
791 if(action->modified) | 816 if(action->modified) |
792 um->priv->modified_action = INVALID; | 817 um->priv->modified_action = INVALID; |
793 | 818 |
794 gtk_source_undo_action_free(action); | 819 gtk_source_undo_action_free(action); |
795 | 820 |
796 um->priv->actions = g_list_delete_link(um->priv->actions, | 821 um->priv->actions = g_list_delete_link(um->priv->actions, |
797 um->priv->actions); | 822 um->priv->actions); |
798 | 823 |
799 if(um->priv->actions == NULL) | 824 if(um->priv->actions == NULL) |
(...skipping 20 matching lines...) Expand all Loading... |
820 | 845 |
821 last = g_list_last(um->priv->actions); | 846 last = g_list_last(um->priv->actions); |
822 undo_action =(GtkSourceUndoAction*) last->data; | 847 undo_action =(GtkSourceUndoAction*) last->data; |
823 | 848 |
824 do | 849 do |
825 { | 850 { |
826 GList *tmp; | 851 GList *tmp; |
827 | 852 |
828 if(undo_action->order_in_group == 1) | 853 if(undo_action->order_in_group == 1) |
829 --um->priv->num_of_groups; | 854 --um->priv->num_of_groups; |
| 855 um->priv->actions_in_current_group = undo_action->order_in_group - 1; |
830 | 856 |
831 if(undo_action->modified) | 857 if(undo_action->modified) |
832 um->priv->modified_action = INVALID; | 858 um->priv->modified_action = INVALID; |
833 | 859 |
834 gtk_source_undo_action_free(undo_action); | 860 gtk_source_undo_action_free(undo_action); |
835 | 861 |
836 tmp = g_list_previous(last); | 862 tmp = g_list_previous(last); |
837 um->priv->actions = g_list_delete_link(um->priv->actions, last); | 863 um->priv->actions = g_list_delete_link(um->priv->actions, last); |
838 last = tmp; | 864 last = tmp; |
839 g_return_if_fail(last != NULL); | 865 g_return_if_fail(last != NULL); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 g_return_if_fail(list != NULL); | 1101 g_return_if_fail(list != NULL); |
1076 | 1102 |
1077 action =(GtkSourceUndoAction*) list->data; | 1103 action =(GtkSourceUndoAction*) list->data; |
1078 g_return_if_fail(action != NULL); | 1104 g_return_if_fail(action != NULL); |
1079 } | 1105 } |
1080 | 1106 |
1081 action->modified = TRUE; | 1107 action->modified = TRUE; |
1082 um->priv->modified_action = action; | 1108 um->priv->modified_action = action; |
1083 } | 1109 } |
1084 | 1110 |
OLD | NEW |