Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy/paste of shapes #409

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Services/ActionManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class Akira.Services.ActionManager : Object {
public const string ACTION_FLIP_V = "action_flip_v";
public const string ACTION_ESCAPE = "action_escape";
public const string ACTION_SHORTCUTS = "action_shortcuts";
public const string ACTION_COPY = "action_copy";
public const string ACTION_PASTE = "action_paste";

public static Gee.MultiMap<string, string> action_accelerators = new Gee.HashMultiMap<string, string> ();
public static Gee.MultiMap<string, string> typing_accelerators = new Gee.HashMultiMap<string, string> ();
Expand Down Expand Up @@ -101,6 +103,8 @@ public class Akira.Services.ActionManager : Object {
{ ACTION_FLIP_V, action_flip_v },
{ ACTION_ESCAPE, action_escape },
{ ACTION_SHORTCUTS, action_shortcuts },
{ ACTION_COPY, action_copy },
{ ACTION_PASTE, action_paste },
};

public ActionManager (Akira.Application akira_app, Akira.Window window) {
Expand Down Expand Up @@ -136,6 +140,8 @@ public class Akira.Services.ActionManager : Object {
action_accelerators.set (ACTION_MOVE_BOTTOM, "<Control><Shift>Down");
action_accelerators.set (ACTION_FLIP_H, "<Control>bracketleft");
action_accelerators.set (ACTION_FLIP_V, "<Control>bracketright");
typing_accelerators.set (ACTION_COPY, "<Control>c");
typing_accelerators.set (ACTION_PASTE, "<Control>v");
action_accelerators.set (ACTION_SHORTCUTS, "F1");

typing_accelerators.set (ACTION_ESCAPE, "Escape");
Expand Down Expand Up @@ -342,6 +348,35 @@ public class Akira.Services.ActionManager : Object {
window.main_window.main_canvas.canvas.selected_bound_manager.delete_selection ();
}

private void action_copy () {
// If mouse click adds the selected item to list then we don't need this method

// var selected_item = window.main_window.main_canvas.canvas.selected_bound_manager.selected_items.nth_data (0);
// window.main_window.main_canvas.canvas.selected_bound_manager.add_item_to_selection (selected_item as Akira.Lib.Models.CanvasItem);
// bool output = window.main_windows.main_canvas.canvasselected_bound_manager.get_selected();
//window.event_bus.insert_item ("rectangle");
}

private void action_paste () {
// Got the list of selected items
var list = window.main_window.main_canvas.canvas.selected_bound_manager.selected_items.copy();
var selected_item = list.nth_data (0); // this is wrong but don't know the intializing statement in vala, just working
// iterate over the list to find the selected item
for (var i = 0; i < list.length (); i++) {
if (list.nth_data (i).selected == true) {
selected_item = list.nth_data (i);
break; // not good coding please improve
}
}

if(selected_item != null) {
window.items_manager.set_item_to_insert (selected_item.name);
window.items_manager.insert_item (selected_item.relative_x, selected_item.relative_y);
window.main_window.main_canvas.canvas.selected_bound_manager.add_item_to_selection (selected_item as Akira.Lib.Models.CanvasItem);
}

}

private void action_flip_h () {
window.event_bus.flip_item ();
}
Expand Down