~ubuntu-branches/ubuntu/maverick/conglomerate/maverick

« back to all changes in this revision

Viewing changes to src/cong-command.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-08 05:07:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051108050706-bcg60nwqf1z3w0d6
Tags: 0.9.1-1ubuntu1
* Resynchronise with Debian (Closes: #4397).
  - Thanks, Jordan Mantha.

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
 
114
114
/**
115
115
 * cong_command_private_new:
116
 
 * @doc:
117
 
 * @description:
118
 
 * @consolidation_id:
119
 
 *
120
 
 * TODO: Write me
121
 
 * Returns:
 
116
 * @doc: The #CongDocument upon which the command is to act.
 
117
 * @description: Human-readable, translated name for this command, as it will appear in the undo/redo history
 
118
 * widget
 
119
 * @consolidation_id: A string ID (or NULL) for this command to allow multiple similar commands to be consolidated into 
 
120
 * a single command.  For example, multiple characters being typed at the keboard can be merged into a single "Typing" command.
 
121
 * 
 
122
 * Should only be called by the internals of #CongDocument; if you wish to create a #CongCommand you should call cong_document_begin_command()
 
123
 * instead.
 
124
 *
 
125
 * Returns:  the new #CongCommand
 
126
 *
122
127
 */
123
128
CongCommand*
124
129
cong_command_private_new (CongDocument *doc,
148
153
 
149
154
/**
150
155
 * cong_command_get_description:
151
 
 * @command:
 
156
 * @command: a command
152
157
 *
153
 
 * TODO: Write me
154
 
 * Returns:
 
158
 * Returns: the human-readable description of this command
155
159
 */
156
160
const gchar*
157
161
cong_command_get_description (CongCommand *command)
163
167
 
164
168
/**
165
169
 * cong_command_get_consolidation_id:
166
 
 * @command:
167
 
 *
168
 
 * TODO: Write me
169
 
 * Returns:
 
170
 * @command:  The relevant #CongCommand 
 
171
 *
 
172
 * Gets the ID (or NULL) of the command used for consolidating multiple similar operations into a single entry in the undo/redo history
 
173
 *
 
174
 * Returns: a constant string, or NULL if no merging is to occur
170
175
 */
171
176
const gchar*
172
177
cong_command_get_consolidation_id (CongCommand *command)
178
183
 
179
184
/**
180
185
 * cong_command_undo:
181
 
 * @command:
 
186
 * @command: a command
182
187
 *
183
 
 * TODO: Write me
 
188
 * Undoes the command.  All modifications contained within the command are undone from the document (in reverse order), the document's "is-modified" flag is set to whatever it was when the command was created.
184
189
 */
185
190
void
186
191
cong_command_undo (CongCommand *command)
190
195
 
191
196
        g_return_if_fail (IS_CONG_COMMAND(command));
192
197
 
193
 
        g_message ("cong_command_undo(\"%s\")", cong_command_get_description(command));
 
198
        /* g_message ("cong_command_undo(\"%s\")", cong_command_get_description(command)); */
194
199
 
195
200
        PRIVATE(command)->has_ever_been_undone = TRUE;
196
201
 
222
227
 * cong_command_redo:
223
228
 * @command:
224
229
 *
225
 
 * TODO: Write me
 
230
 * Redoes a command that has previously been undone.  Replays all the modifications on the document in order from start to finish.
226
231
 */
227
232
void
228
233
cong_command_redo (CongCommand *command)
232
237
 
233
238
        g_return_if_fail (IS_CONG_COMMAND(command));
234
239
 
235
 
        g_message ("cong_command_redo(\"%s\")", cong_command_get_description(command));
 
240
        /* g_message ("cong_command_redo(\"%s\")", cong_command_get_description(command)); */
236
241
 
237
242
        doc = cong_command_get_document (command);
238
243
 
256
261
}
257
262
 
258
263
/**
259
 
 * cong_command_merge:
260
 
 * @dst:
261
 
 * @src:
262
 
 *
263
 
 * TODO: Write me
 
264
 * cong_command_merge: *
 
265
 * @dst: The #CongCommand into which the modifications are to be added
 
266
 * @src: The #CongCommand from which the modifications are to be taken
 
267
 *
 
268
 * Takes all of the modifications from @src and places them on the end of @dst.  Only to be used by the internals of the undo/redo management
 
269
 *
264
270
 */
265
271
void
266
272
cong_command_merge (CongCommand *dst,
275
281
        PRIVATE(src)->list_of_modification = NULL;
276
282
}
277
283
 
278
 
 
 
284
/**
 
285
 * cong_command_has_ever_been_undone: *
 
286
 * @cmd:
 
287
 *
 
288
 * A function used by the command consolidation/merging system.  If you undo then redo a command,
 
289
 * further similar operations should get separate entries in the undo/redo histroy, rather than being
 
290
 * merged.
 
291
 *
 
292
 * Returns: A #gboolean, answering the question "has this command ever been undone?"
 
293
 */
279
294
gboolean
280
295
cong_command_has_ever_been_undone (CongCommand *cmd)
281
296
{
422
437
void 
423
438
cong_command_add_node_set_text (CongCommand *cmd, 
424
439
                                CongNodePtr node, 
425
 
                                const xmlChar *new_content)
 
440
                                const gchar *new_content)
426
441
{
427
442
        CongModification *modification;
428
443
        
450
465
cong_command_add_node_set_attribute (CongCommand *cmd, 
451
466
                                     CongNodePtr node, 
452
467
                                     xmlNs *ns_ptr,
453
 
                                     const xmlChar *name, 
454
 
                                     const xmlChar *value)
 
468
                                     const gchar *name, 
 
469
                                     const gchar *value)
455
470
{
456
471
        CongModification *modification;
457
472
        
480
495
cong_command_add_node_remove_attribute (CongCommand *cmd, 
481
496
                                        CongNodePtr node, 
482
497
                                        xmlNs *ns_ptr,
483
 
                                        const xmlChar *name)
 
498
                                        const gchar *name)
484
499
{
485
500
        CongModification *modification;
486
501
        
812
827
/**
813
828
 * cong_command_add_delete_range:
814
829
 * @cmd:
815
 
 * @range:
816
 
 *
817
 
 * TODO: Write me
 
830
 * @range: a range within the document; both start and end must have the same parent, so that proper nesting is maintained
 
831
 *
 
832
 * Utility function to add a series of modifications to the given command.
 
833
 *
 
834
 * Deletes the given range within the document (can include multiple nodes).  Updates cursor and selection accordingly.
818
835
 */
819
836
void 
820
837
cong_command_add_delete_range (CongCommand *cmd,
924
941
                        } else {
925
942
                        
926
943
                                /* Split up textual content of node: */
927
 
                                gchar *text_before = g_strndup (loc0.node->content, loc0.byte_offset);
 
944
                                gchar *text_before = g_strndup ((gchar*)loc0.node->content, loc0.byte_offset);
928
945
 
929
946
                                gchar *new_text = g_strdup_printf("%s%s",text_before, loc1.node->content + loc1.byte_offset);
930
947
 
964
981
 * cong_command_add_delete_selection:
965
982
 * @cmd:
966
983
 *
967
 
 * TODO: Write me
 
984
 * Utility function to add a series of modifications to the given command.
 
985
 *
 
986
 * Deletes the current selection within the document, updating cursor and selection accordingly.
968
987
 */
969
988
void 
970
989
cong_command_add_delete_selection (CongCommand *cmd)
994
1013
/**
995
1014
 * cong_command_add_insert_text_at_cursor:
996
1015
 * @cmd:
997
 
 * @string:
998
 
 *
999
 
 * TODO: Write me
 
1016
 * @string: a UTF-8 string
 
1017
 *
 
1018
 * Utility function to add a series of modifications to the given command.
 
1019
 *
 
1020
 * Inserts the given text at the cursor, moving the cursor to the end of the inserted text.
1000
1021
 */
1001
1022
void 
1002
1023
cong_command_add_insert_text_at_cursor (CongCommand *cmd, 
1006
1027
        CongCursor *curs;
1007
1028
        CongLocation old_cursor_loc;
1008
1029
        CongLocation new_cursor_loc;
1009
 
        xmlChar *new_content;
 
1030
        gchar *initial_part;
 
1031
        gchar *new_content;
1010
1032
        int byte_length;
1011
1033
 
1012
1034
        g_return_if_fail (IS_CONG_COMMAND (cmd));
1029
1051
 
1030
1052
        byte_length = strlen(string);
1031
1053
 
1032
 
        new_content = xmlStrndup(old_cursor_loc.node->content, old_cursor_loc.byte_offset);
1033
 
        CONG_VALIDATE_UTF8(new_content);
1034
 
 
1035
 
        new_content = xmlStrcat(new_content, string);
1036
 
        CONG_VALIDATE_UTF8(new_content);
1037
 
 
1038
 
        CONG_VALIDATE_UTF8(old_cursor_loc.node->content+old_cursor_loc.byte_offset);
1039
 
        new_content = xmlStrcat(new_content, old_cursor_loc.node->content+old_cursor_loc.byte_offset);
1040
 
        CONG_VALIDATE_UTF8(new_content);
 
1054
        initial_part = g_strndup ((const gchar*)old_cursor_loc.node->content, old_cursor_loc.byte_offset);
 
1055
        CONG_VALIDATE_UTF8(initial_part);
 
1056
 
 
1057
        CONG_VALIDATE_UTF8((const gchar*)old_cursor_loc.node->content+old_cursor_loc.byte_offset);
 
1058
 
 
1059
        new_content = g_strconcat (initial_part,
 
1060
                                   string, 
 
1061
                                   (const gchar*)old_cursor_loc.node->content+old_cursor_loc.byte_offset, 
 
1062
                                   NULL);
 
1063
        CONG_VALIDATE_UTF8(new_content);
 
1064
        g_free (initial_part);
1041
1065
 
1042
1066
        cong_command_add_node_set_text (cmd, 
1043
1067
                                        old_cursor_loc.node,
1044
1068
                                        new_content);
1045
 
        xmlFree(new_content);
 
1069
        g_free (new_content);
1046
1070
 
1047
 
        new_cursor_loc.byte_offset += byte_length;              
1048
 
        CONG_VALIDATE_UTF8(new_cursor_loc.node->content+new_cursor_loc.byte_offset);
 
1071
        new_cursor_loc.byte_offset += byte_length;
 
1072
        CONG_VALIDATE_UTF8((const gchar*)new_cursor_loc.node->content+new_cursor_loc.byte_offset);
1049
1073
 
1050
1074
        cong_command_add_cursor_change (cmd,
1051
1075
                                        &new_cursor_loc);
1150
1174
        } else if (len2==0) {
1151
1175
                d = cong_node_new_textual (node_type, "", doc);
1152
1176
        } else {
1153
 
                xmlChar* new_text = g_strndup(loc->node->content, len1); /* FIXME:  char type conversion? */
 
1177
                gchar* new_text = g_strndup((const gchar*)loc->node->content, len1);
1154
1178
 
1155
1179
                /* Make split representation */
1156
 
                d = cong_node_new_textual_len (node_type, xml_frag_data_nice(loc->node) + len1, len2, doc); /* FIXME: check char ptr arithmetic; UTF8? */
 
1180
                d = cong_node_new_textual_len (node_type, cong_node_safe_get_content(loc->node) + len1, len2, doc); /* FIXME: check char ptr arithmetic; UTF8? */
1157
1181
 
1158
1182
                /* Shrink original node */
1159
1183
                cong_command_add_node_set_text(cmd, 
1196
1220
 
1197
1221
        } else if (location->node == affected_node) {
1198
1222
 
1199
 
                location->byte_offset += strlen(affected_node->prev->content);
 
1223
                location->byte_offset += strlen((const char*)affected_node->prev->content);
1200
1224
 
1201
1225
                return TRUE;
1202
1226
        }
1242
1266
 * cong_command_add_merge_adjacent_text_nodes:
1243
1267
 * @cmd:
1244
1268
 *
1245
 
 * TODO: Write me
 
1269
 * Utility function to add a series of modifications to the given command.
 
1270
 * 
 
1271
 * Searches the entire document, looking for text nodes adjacent to other text nodes, merging them together.
1246
1272
 */
1247
1273
void
1248
1274
cong_command_add_merge_adjacent_text_nodes (CongCommand *cmd)
1265
1291
 * @cmd:
1266
1292
 * @node:
1267
1293
 *
1268
 
 * TODO: Write me
 
1294
 * Utility function to add a series of modifications to the given command.
 
1295
 * 
 
1296
 * Searches direct children of the given node, looking for text nodes adjacent to other text nodes, merging them together.
1269
1297
 */
1270
1298
void
1271
1299
cong_command_add_merge_adjacent_text_children_of_node (CongCommand *cmd, 
1317
1345
 * @cmd:
1318
1346
 * @node:
1319
1347
 *
1320
 
 * TODO: Write me
 
1348
 * Utility function to add a series of modifications to the given command.
 
1349
 * 
 
1350
 * Splits the selected nodes as necessary and adds as a child of the input node
 
1351
 *
1321
1352
 * Returns:
1322
1353
 */
1323
1354
CongNodePtr
1499
1530
        return FALSE;
1500
1531
}
1501
1532
 
1502
 
/* Splits a data node in 3 and returns pointer to the middle one */
1503
1533
/**
1504
1534
 * cong_command_add_node_split3:
1505
1535
 * @cmd:
1507
1537
 * @c0:
1508
1538
 * @c1:
1509
1539
 *
1510
 
 * TODO: Write me
1511
 
 * Returns:
 
1540
 * Utility function to add a series of modifications to the given command.
 
1541
 *
 
1542
 * Splits a text or comment node into 3 nodes, and returns a pointer to the middle one
 
1543
 *
 
1544
 * Returns: the middle node of the three newly-created nodes
1512
1545
 */
1513
1546
CongNodePtr
1514
1547
cong_command_add_node_split3 (CongCommand *cmd, 
1539
1572
        len3 = cong_node_get_length(node) - c1;
1540
1573
 
1541
1574
        /* Make split representation */
1542
 
        d1 = cong_node_new_textual_len (node_type, xml_frag_data_nice(node), len1, doc); /* FIXME:  audit the char types here, and the char pointer arithmetic. UTF8? */
1543
 
        d2 = cong_node_new_textual_len (node_type, xml_frag_data_nice(node) + len1, len2, doc);
1544
 
        d3 = cong_node_new_textual_len (node_type, xml_frag_data_nice(node) + len1 + len2, len3, doc);
 
1575
        d1 = cong_node_new_textual_len (node_type, cong_node_safe_get_content(node), len1, doc); /* FIXME:  audit the char types here, and the char pointer arithmetic. UTF8? */
 
1576
        d2 = cong_node_new_textual_len (node_type, cong_node_safe_get_content(node) + len1, len2, doc);
 
1577
        d3 = cong_node_new_textual_len (node_type, cong_node_safe_get_content(node) + len1 + len2, len3, doc);
1545
1578
 
1546
1579
        cong_document_begin_edit(doc);
1547
1580
 
1580
1613
/**
1581
1614
 * cong_command_add_remove_tag:
1582
1615
 * @cmd:
1583
 
 * @node:
1584
 
 *
1585
 
 * TODO: Write me
 
1616
 * @node: a node
 
1617
 *
 
1618
 * Utility function to add a series of modifications to the given command.
 
1619
 *
 
1620
 * Removes the given node from the tree, moving all of its children into the space it occupied.
1586
1621
 */
1587
1622
void 
1588
1623
cong_command_add_remove_tag (CongCommand *cmd,
1651
1686
 
1652
1687
/**
1653
1688
 * cong_command_add_set_external_dtd:
1654
 
 * @cmd:
1655
 
 * @root_element:
 
1689
 * @cmd: a command
 
1690
 * @root_element: the root element of the document
1656
1691
 * @public_id:
1657
1692
 * @system_id:
1658
1693
 *
1659
 
 * TODO: Write me
 
1694
 * Utility function to add a series of modifications to the given command.
 
1695
 * 
 
1696
 * Sets an external DTD on the document, or removes it if NULL is given
1660
1697
 */
1661
1698
void
1662
1699
cong_command_add_set_external_dtd (CongCommand *cmd,