Skip to content

Commit

Permalink
Add context menu options to all elements
Browse files Browse the repository at this point in the history
  • Loading branch information
sapoturge committed Oct 23, 2024
1 parent c40dab7 commit 53455a4
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/data/Circle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,23 @@ public class Circle : Element {
}

public override Gee.List<ContextOption> options () {
return new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
var opts = new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
new ContextOption.deleter (_("Delete Circle"), () => { request_delete(); }),
new ContextOption.action (_("Convert to Ellipse"), () => { replace (new Ellipse (x, y, r, r, fill, stroke, title, transform)); }),
new ContextOption.toggle (_("Show Transformation"), this, "transform_enabled")
});
if (transform_enabled && transform_applied) {
opts.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else if (transform_enabled) {
opts.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return opts;
}

public override int add_svg (Xml.Node* root, Xml.Node* defs, int pattern_index) {
Expand Down
14 changes: 13 additions & 1 deletion src/data/Ellipse.vala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public class Ellipse : Element {
}

public override Gee.List<ContextOption> options () {
return new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
var opts = new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
new ContextOption.deleter (_("Delete Ellipse"), () => { request_delete(); }),
new ContextOption.action (_("Convert to Path"), () => {
replace (new Path.with_pattern ({
Expand All @@ -223,6 +223,18 @@ public class Ellipse : Element {
}),
new ContextOption.toggle (_("Show Transformation"), this, "transform_enabled")
});
if (transform_enabled && transform_applied) {
opts.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else if (transform_enabled) {
opts.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return opts;
}

public override int add_svg (Xml.Node* root, Xml.Node* defs, int pattern_index) {
Expand Down
15 changes: 13 additions & 2 deletions src/data/Group.vala
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ public class Group : Element, Container {
}

public override Gee.List<ContextOption> options () {
// Groups have no inherent options.
return new Gee.ArrayList<ContextOption> ();
var opts = new Gee.ArrayList<ContextOption> ();
if (transform_applied) {
opts.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else {
opts.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return opts;
}
}
14 changes: 13 additions & 1 deletion src/data/Line.vala
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,25 @@ public class Line : Element {
}

public override Gee.List<ContextOption> options () {
return new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
var opts = new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
new ContextOption.deleter (_("Delete Line"), () => { request_delete(); }),
new ContextOption.action (_("Convert to Polyline"), () => {
replace (new Polyline ({start, end}, fill, stroke, title, transform));
}),
new ContextOption.toggle (_("Show Transformation"), this, "transform_enabled")
});
if (transform_enabled && transform_applied) {
opts.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else if (transform_enabled) {
opts.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return opts;
}

public override int add_svg (Xml.Node* root, Xml.Node* defs, int pattern_index) {
Expand Down
14 changes: 13 additions & 1 deletion src/data/Polygon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class Polygon : Element {
}

public override Gee.List<ContextOption> options () {
return new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
var opts = new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
new ContextOption.deleter (_("Delete Polygon"), () => { request_delete(); }),
new ContextOption.action (_("Convert to Path"), () => {
var segments = new PathSegment[] {};
Expand All @@ -166,6 +166,18 @@ public class Polygon : Element {
}),
new ContextOption.toggle (_("Show Transformation"), this, "transform_enabled")
});
if (transform_enabled && transform_applied) {
opts.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else if (transform_enabled) {
opts.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return opts;
}

public override int add_svg (Xml.Node* root, Xml.Node* defs, int pattern_index) {
Expand Down
14 changes: 13 additions & 1 deletion src/data/Polyline.vala
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class Polyline : Element {
}

public override Gee.List<ContextOption> options () {
return new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
var opts = new Gee.ArrayList<ContextOption>.wrap (new ContextOption[]{
new ContextOption.deleter (_("Delete Polyline"), () => { request_delete(); }),
new ContextOption.action (_("Close Loop"), () => {
var points = new Point[] {root_segment.start};
Expand All @@ -167,6 +167,18 @@ public class Polyline : Element {
}),
new ContextOption.toggle (_("Show Transformation"), this, "transform_enabled")
});
if (transform_enabled && transform_applied) {
opts.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else if (transform_enabled) {
opts.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return opts;
}

public override int add_svg (Xml.Node* root, Xml.Node* defs, int pattern_index) {
Expand Down
10 changes: 10 additions & 0 deletions src/data/Rectangle.vala
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ public class Rectangle : Element {
replace (new Polygon ({Point(x, y), Point(x+width, y), Point(x + width, y + height), Point(x, y + height)}, fill, stroke, title, transform));
}));
}
if (transform_enabled && transform_applied) {
options.add (new ContextOption.action (_("Revert View"), () => {
apply_transform (new Transform.identity(), null);
}));
} else if (transform_enabled) {
options.add (new ContextOption.action (_("Apply Transformation"), () => {
apply_transform (transform.invert (), this);
transform_applied = true;
}));
}

return options;
}
Expand Down

0 comments on commit 53455a4

Please sign in to comment.