summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Merry <dev@randomguy3.me.uk>2012-04-19 13:22:42 +0100
committerAlex Merry <dev@randomguy3.me.uk>2012-05-04 10:14:38 +0100
commitf819c5ba44023769d5c8512cdf489d001c1da09d (patch)
tree7fc1d801672e04b40ee6f82f2409adea4c2a780f
parentec48fc2bcce2483d89eb51a185c5826a8fcc7c6c (diff)
Edges can now be reversed easily
-rw-r--r--tikzit/NEWS1
-rw-r--r--tikzit/src/common/Graph.h7
-rw-r--r--tikzit/src/common/Graph.m19
-rw-r--r--tikzit/src/common/GraphChange.h9
-rw-r--r--tikzit/src/common/GraphChange.m10
-rw-r--r--tikzit/src/gtk/Menu.h2
-rw-r--r--tikzit/src/gtk/Menu.m18
-rw-r--r--tikzit/src/gtk/TikzDocument.h1
-rw-r--r--tikzit/src/gtk/TikzDocument.m8
9 files changed, 70 insertions, 5 deletions
diff --git a/tikzit/NEWS b/tikzit/NEWS
index fdac837..1811ac4 100644
--- a/tikzit/NEWS
+++ b/tikzit/NEWS
@@ -12,6 +12,7 @@ tikzit 0.8 (2012-01-??):
* Nodes and edges have consistent ordering, and this can be
changed with Edge->Arrange
* Edges now have colours
+ * Edges can now be reversed easily
tikzit 0.7 (2011-12-06):
* Add bounding box support
diff --git a/tikzit/src/common/Graph.h b/tikzit/src/common/Graph.h
index c680219..f5d8bed 100644
--- a/tikzit/src/common/Graph.h
+++ b/tikzit/src/common/Graph.h
@@ -278,6 +278,13 @@
- (GraphChange*)shiftNodes:(id<NSFastEnumeration>)ns byPoint:(NSPoint)p;
/*!
+ @brief Reverse the given edges
+ @param es the edges to reverse
+ @result A <tt>GraphChange</tt> recording this action.
+ */
+- (GraphChange*)reverseEdges:(NSSet *)es;
+
+/*!
@brief Insert the given graph into this one. Used for copy
and paste.
@param g a graph.
diff --git a/tikzit/src/common/Graph.m b/tikzit/src/common/Graph.m
index d04751a..27c2ebb 100644
--- a/tikzit/src/common/Graph.m
+++ b/tikzit/src/common/Graph.m
@@ -247,9 +247,7 @@
- (GraphChange*)removeEdges:(NSSet *)es {
[graphLock lock];
- NSEnumerator *en = [es objectEnumerator];
- Edge *e;
- while ((e = [en nextObject])) {
+ for (Edge *e in es) {
[edges removeObject:e];
}
dirty = YES;
@@ -272,6 +270,16 @@
return [GraphChange shiftNodes:nodeSet byPoint:p];
}
+- (GraphChange*)reverseEdges:(NSSet *)es {
+ [graphLock lock];
+ for (Edge *e in es) {
+ [e reverse];
+ }
+ dirty = YES;
+ [graphLock unlock];
+ return [GraphChange reverseEdges:es];
+}
+
- (int)indexOfNode:(Node *)node {
return [nodes indexOfObject:node];
}
@@ -633,6 +641,11 @@
case NodesFlip:
[self flipNodes:[ch affectedNodes] horizontal:[ch horizontal]];
break;
+ case EdgesReverse:
+ for (Edge *e in [[ch affectedEdges] objectEnumerator]) {
+ [e reverse];
+ }
+ break;
case BoundingBoxChange:
[self setBoundingBox:[ch nwBoundingBox]];
break;
diff --git a/tikzit/src/common/GraphChange.h b/tikzit/src/common/GraphChange.h
index cb4ca09..ef56005 100644
--- a/tikzit/src/common/GraphChange.h
+++ b/tikzit/src/common/GraphChange.h
@@ -33,6 +33,7 @@ typedef enum {
EdgesPropertyChange,
NodesShift,
NodesFlip,
+ EdgesReverse,
BoundingBoxChange,
GraphPropertyChange,
NodeOrderChange,
@@ -291,7 +292,6 @@ typedef enum {
*/
+ (GraphChange*)shiftNodes:(NSSet*)ns byPoint:(NSPoint)p;
-
/*!
@brief Construct a horizontal or vertical flip of a set of nodes.
@param ns the affected nodes.
@@ -301,6 +301,13 @@ typedef enum {
+ (GraphChange*)flipNodes:(NSSet*)ns horizontal:(BOOL)b;
/*!
+ @brief Construct a reversal of a set of edges.
+ @param es the affected edges.
+ @result A reverse of a set of edges.
+ */
++ (GraphChange*)reverseEdges:(NSSet*)es;
+
+/*!
@brief Construct a bounding box change
@param oldBB the old bounding box
@param newBB the new bounding box
diff --git a/tikzit/src/common/GraphChange.m b/tikzit/src/common/GraphChange.m
index 9707a19..c52a46d 100644
--- a/tikzit/src/common/GraphChange.m
+++ b/tikzit/src/common/GraphChange.m
@@ -90,6 +90,9 @@
inverse->affectedNodes = [affectedNodes retain];
[inverse setHorizontal:[self horizontal]];
break;
+ case EdgesReverse:
+ inverse->affectedEdges = [affectedEdges retain];
+ break;
case BoundingBoxChange:
inverse->oldBoundingBox = nwBoundingBox;
inverse->nwBoundingBox = oldBoundingBox;
@@ -197,6 +200,13 @@
return [gc autorelease];
}
++ (GraphChange*)reverseEdges:(NSSet*)es {
+ GraphChange *gc = [[GraphChange alloc] init];
+ [gc setChangeType:EdgesReverse];
+ [gc setAffectedEdges:es];
+ return [gc autorelease];
+}
+
+ (GraphChange*)changeBoundingBoxFrom:(NSRect)oldBB to:(NSRect)newBB {
GraphChange *gc = [[GraphChange alloc] init];
[gc setChangeType:BoundingBoxChange];
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[] =
" <separator/>"
" <menuitem action='FlipVert'/>"
" <menuitem action='FlipHoriz'/>"
+" <menuitem action='ReverseEdges'/>"
" <separator/>"
" <menu action='Arrange'>"
" <menuitem action='SendToBack'/>"
@@ -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;