From f819c5ba44023769d5c8512cdf489d001c1da09d Mon Sep 17 00:00:00 2001 From: Alex Merry Date: Thu, 19 Apr 2012 13:22:42 +0100 Subject: Edges can now be reversed easily --- tikzit/src/gtk/Menu.h | 2 ++ tikzit/src/gtk/Menu.m | 18 ++++++++++++++++++ tikzit/src/gtk/TikzDocument.h | 1 + tikzit/src/gtk/TikzDocument.m | 8 +++++++- 4 files changed, 28 insertions(+), 1 deletion(-) (limited to 'tikzit/src/gtk') diff --git a/tikzit/src/gtk/Menu.h b/tikzit/src/gtk/Menu.h index 024c9e0..5a364e4 100644 --- a/tikzit/src/gtk/Menu.h +++ b/tikzit/src/gtk/Menu.h @@ -39,6 +39,8 @@ GtkAction *pasteAction; GtkAction **nodeSelBasedActions; guint nodeSelBasedActionCount; + GtkAction **edgeSelBasedActions; + guint edgeSelBasedActionCount; GtkAction **selBasedActions; guint selBasedActionCount; } diff --git a/tikzit/src/gtk/Menu.m b/tikzit/src/gtk/Menu.m index ea2e333..37ab87c 100644 --- a/tikzit/src/gtk/Menu.m +++ b/tikzit/src/gtk/Menu.m @@ -224,6 +224,12 @@ static void flip_vert_cb (GtkAction *action, MainWindow *window) { [pool drain]; } +static void reverse_edges_cb (GtkAction *action, MainWindow *window) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [[window activeDocument] reverseSelectedEdges]; + [pool drain]; +} + static void bring_forward_cb (GtkAction *action, MainWindow *window) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [[window activeDocument] bringSelectionForward]; @@ -375,6 +381,7 @@ static const gchar ui_info[] = " " " " " " +" " " " " " " " @@ -561,6 +568,9 @@ static GtkActionEntry document_entries[] = { { "FlipVert", NULL, N_("Flip nodes _vertically"), NULL, N_("Flip the selected nodes vertically"), G_CALLBACK (flip_vert_cb) }, + { "ReverseEdges", NULL, N_("Rever_se edges"), NULL, + N_("Reverse the selected edges"), G_CALLBACK (reverse_edges_cb) }, + { "SendToBack", NULL, N_("Send to _back"), NULL, N_("Send the selected nodes and edges to the back of the graph"), G_CALLBACK (send_to_back_cb) }, @@ -764,6 +774,9 @@ create_recent_chooser_menu () nodeSelBasedActions[1] = gtk_action_group_get_action (documentActions, "Copy"); nodeSelBasedActions[2] = gtk_action_group_get_action (documentActions, "FlipHoriz"); nodeSelBasedActions[3] = gtk_action_group_get_action (documentActions, "FlipVert"); + edgeSelBasedActionCount = 1; + edgeSelBasedActions = g_new (GtkAction*, edgeSelBasedActionCount); + edgeSelBasedActions[0] = gtk_action_group_get_action (documentActions, "ReverseEdges"); selBasedActionCount = 2; selBasedActions = g_new (GtkAction*, selBasedActionCount); selBasedActions[0] = gtk_action_group_get_action (documentActions, "Delete"); @@ -820,6 +833,11 @@ create_recent_chooser_menu () gtk_action_set_sensitive (nodeSelBasedActions[i], hasSelectedNodes); } } + for (int i = 0; i < edgeSelBasedActionCount; ++i) { + if (edgeSelBasedActions[i]) { + gtk_action_set_sensitive (edgeSelBasedActions[i], hasSelectedEdges); + } + } for (int i = 0; i < selBasedActionCount; ++i) { if (selBasedActions[i]) { gtk_action_set_sensitive (selBasedActions[i], hasSelectedNodes || hasSelectedEdges); diff --git a/tikzit/src/gtk/TikzDocument.h b/tikzit/src/gtk/TikzDocument.h index ddeaf29..79a9b17 100644 --- a/tikzit/src/gtk/TikzDocument.h +++ b/tikzit/src/gtk/TikzDocument.h @@ -152,6 +152,7 @@ - (void) insertGraph:(Graph*)g; - (void) flipSelectedNodesHorizontally; - (void) flipSelectedNodesVertically; +- (void) reverseSelectedEdges; - (void) bringSelectionForward; - (void) bringSelectionToFront; - (void) sendSelectionBackward; diff --git a/tikzit/src/gtk/TikzDocument.m b/tikzit/src/gtk/TikzDocument.m index a5f1d9f..2016d2a 100644 --- a/tikzit/src/gtk/TikzDocument.m +++ b/tikzit/src/gtk/TikzDocument.m @@ -726,7 +726,13 @@ } } -// FIXME: undo +- (void) reverseSelectedEdges { + if ([[pickSupport selectedEdges] count] > 0) { + GraphChange *change = [graph reverseEdges:[pickSupport selectedEdges]]; + [self completedGraphChange:change withName:@"Reverse edges"]; + } +} + - (void) bringSelectionForward { BOOL hasNodeSelection = [[pickSupport selectedNodes] count] > 0; BOOL hasEdgeSelection = [[pickSupport selectedEdges] count] > 0; -- cgit v1.2.3