Skip to content

Commit

Permalink
Add "Duplicate" item to event right click
Browse files Browse the repository at this point in the history
  • Loading branch information
Jowan-Spooner committed Jan 7, 2024
1 parent 53615c4 commit 16a7a99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions addons/dialogic/Editor/Events/EventBlock/event_block.gd
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,6 @@ func _on_EventNode_gui_input(event:InputEvent) -> void:
popup.current_event = self
popup.popup_on_parent(Rect2(get_global_mouse_position(),Vector2()))
if resource.help_page_path == "":
popup.set_item_disabled(0, true)
popup.set_item_disabled(2, true)
else:
popup.set_item_disabled(0, false)
popup.set_item_disabled(2, false)
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ var current_event : Node = null

func _ready():
clear()
add_icon_item(get_theme_icon("Duplicate", "EditorIcons"), "Duplicate")
add_separator()
add_icon_item(get_theme_icon("Help", "EditorIcons"), "Documentation")
add_icon_item(get_theme_icon("CodeHighlighter", "EditorIcons"), "Open Code")
add_separator()
add_icon_item(get_theme_icon("ArrowUp", "EditorIcons"), "Move up")
add_icon_item(get_theme_icon("ArrowDown", "EditorIcons"), "Move down")
add_separator()
add_icon_item(get_theme_icon("Remove", "EditorIcons"), "Delete")

var menu_background := StyleBoxFlat.new()
menu_background.bg_color = get_parent().get_theme_color("base_color", "Editor")
add_theme_stylebox_override('panel', menu_background)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,18 +888,22 @@ func indent_events() -> void:
func _on_event_popup_menu_index_pressed(index:int) -> void:
var item :Control = %EventPopupMenu.current_event
if index == 0:
if not item in selected_items:
selected_items = [item]
duplicate_selected()
elif index == 2:
if not item.resource.help_page_path.is_empty():
OS.shell_open(item.resource.help_page_path)
elif index == 1:
elif index == 3:
find_parent('EditorView').plugin_reference.get_editor_interface().set_main_screen_editor('Script')
find_parent('EditorView').plugin_reference.get_editor_interface().edit_script(item.resource.get_script(), 1, 1)
elif index == 3 or index == 4:
if index == 3:
elif index == 5 or index == 6:
if index == 5:
offset_blocks_by_index(selected_items, -1)
else:
offset_blocks_by_index(selected_items, +1)

elif index == 6:
elif index == 8:
var events_indexed := get_events_indexed([item])
TimelineUndoRedo.create_action("[D] Deleting 1 event.")
TimelineUndoRedo.add_do_method(delete_events_indexed.bind(events_indexed))
Expand Down Expand Up @@ -939,6 +943,16 @@ func _on_right_sidebar_resized():
#################### SHORTCUTS #################################################
################################################################################

func duplicate_selected() -> void:
if len(selected_items) > 0:
var events := get_events_indexed(selected_items).values()
var at_index: int = selected_items[-1].get_index()+1
TimelineUndoRedo.create_action("[D] Duplicate "+str(len(events))+" event(s).")
TimelineUndoRedo.add_do_method(add_events_at_index.bind(events, at_index))
TimelineUndoRedo.add_undo_method(delete_events_at_index.bind(at_index, len(events)))
TimelineUndoRedo.commit_action()


func _input(event:InputEvent) -> void:
# we protect this with is_visible_in_tree to not
# invoke a shortcut by accident
Expand Down Expand Up @@ -1063,13 +1077,7 @@ func _input(event:InputEvent) -> void:
get_viewport().set_input_as_handled()

"Ctrl+D":
if len(selected_items) > 0:
var events := get_events_indexed(selected_items).values()
var at_index :int= selected_items[-1].get_index()
TimelineUndoRedo.create_action("[D] Duplicate "+str(len(events))+" event(s).")
TimelineUndoRedo.add_do_method(add_events_at_index.bind(events, at_index))
TimelineUndoRedo.add_undo_method(delete_events_at_index.bind(at_index, len(events)))
TimelineUndoRedo.commit_action()
duplicate_selected()
get_viewport().set_input_as_handled()

"Alt+Up", "Option+Up":
Expand Down

0 comments on commit 16a7a99

Please sign in to comment.