Module: Ruby2dAction
- Defined in:
- lib/mk_semi_lattice/ruby2d_action.rb
Class Method Summary collapse
- .auto_fp_modifier(parent_dir, file_path) ⇒ Object
- .double_click?(clicked_node, last_click_node, last_click_time) ⇒ Boolean
- .double_click_action(clicked_node, parent_dir) ⇒ Object
- .on_key_down(app, event) ⇒ Object
- .on_key_up(app, event) ⇒ Object
- .on_mouse_down(app, event, last_click_node, last_click_time, parent_dir) ⇒ Object
- .on_mouse_move(app, event) ⇒ Object
- .on_mouse_up(app) ⇒ Object
- .update_action(app) ⇒ Object
Class Method Details
.auto_fp_modifier(parent_dir, file_path) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 20 def self.auto_fp_modifier(parent_dir, file_path) pd = File.(parent_dir) fp = file_path.dup # file_pathが"./"で始まる場合は除去 fp = fp.sub(%r{\A\./}, '') # parent_dirのbasenameを取得 pd_base = File.basename(pd) # parent_dirのパスの中にfile_pathの先頭要素が含まれている場合は、重複しないようにする fp_first = fp.split(File::SEPARATOR).first if fp == pd_base # 完全一致ならparent_dir自身 pd elsif pd.include?(fp_first) && fp.start_with?(fp_first + File::SEPARATOR) # parent_dirのどこかにfile_pathの先頭要素が含まれている場合は、その要素以降をparent_dirに連結 idx = fp.index(File::SEPARATOR) rest = idx ? fp[idx+1..-1] : "" File.join(pd, rest) else File.(fp, pd) end end |
.double_click?(clicked_node, last_click_node, last_click_time) ⇒ Boolean
12 13 14 15 16 17 18 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 12 def self.double_click?(clicked_node, last_click_node, last_click_time) now = Time.now if last_click_node == clicked_node && last_click_time && (now - last_click_time < 0.4) return true, now end return false, now end |
.double_click_action(clicked_node, parent_dir) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 45 def self.double_click_action(clicked_node, parent_dir) comm = nil if clicked_node.file_path # URL判定 if clicked_node.file_path =~ /\Ahttps?:\/\// abs_path = clicked_node.file_path comm = "open '#{abs_path}'" else abs_path = if Pathname.new(clicked_node.file_path).absolute? clicked_node.file_path else auto_fp_modifier(parent_dir, clicked_node.file_path) end puts "[DEBUG] parent_dir: #{parent_dir}" puts "[DEBUG] file_path: #{clicked_node.file_path}" puts "[DEBUG] abs_path: #{abs_path}" puts "[DEBUG] config[open_terminal_command]: #{InitEnv::Config.conf['open_terminal_command']}" if File.directory?(abs_path) if RbConfig::CONFIG['host_os'] =~ /darwin/ comm = "open -a Terminal '#{abs_path}'" # comm = "osascript -e 'tell application \"Terminal\" to do script \"cd #{abs_path}; your_command_here\"'" elsif RbConfig::CONFIG['host_os'] =~ /debian/ comm = "gnome-terminal --working-directory='#{abs_path}'" # comm = "gnome-terminal --working-directory='#{abs_path}' -- bash -c 'your_command_here; exec bash'" else comm = InitEnv::Config.conf['open_terminal_command'] || "wt.exe -p Ubuntu-24.04 " comm += " --colorScheme 'Tango Light' -d '#{abs_path}'" # comm = "wt.exe -d '#{abs_path}' bash -c 'your_command_here; exec bash'" p ["comm", comm] end else comm = "open '#{abs_path}'" end end p ["comm", comm] puts comm InitEnv::Log.event("open", target_dir: abs_path, parent_dir: parent_dir) system comm else puts "no link error" end end |
.on_key_down(app, event) ⇒ Object
4 5 6 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 4 def self.on_key_down(app, event) app.shift_pressed = true if event.key.include?('shift') end |
.on_key_up(app, event) ⇒ Object
8 9 10 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 8 def self.on_key_up(app, event) app.shift_pressed = false if event.key.include?('shift') end |
.on_mouse_down(app, event, last_click_node, last_click_time, parent_dir) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 91 def self.on_mouse_down(app, event, last_click_node, last_click_time, parent_dir) mx, my = event.x, event.y shift_down = !!app.shift_pressed clicked_node = nil app.nodes.each do |n| if Math.hypot(n.x - mx, n.y - my) < 30 clicked_node = n if shift_down n.fixed = false n.color = NODE_COLOR app.selected = nil else app.selected = n if event. == :left n.fixed = true n.color = FIXED_COLOR end n.fixed = false if event. == :middle n.linked = true if event. == :right end end end # ダブルクリック判定とファイルオープン if clicked_node is_double, now = double_click?(clicked_node, last_click_node, last_click_time) double_click_action(clicked_node, parent_dir) if is_double return clicked_node, now end [last_click_node, last_click_time] end |
.on_mouse_move(app, event) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 127 def self.on_mouse_move(app, event) if app.selected app.selected.x = event.x app.selected.y = event.y end end |
.on_mouse_up(app) ⇒ Object
123 124 125 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 123 def self.on_mouse_up(app) app.selected = nil end |
.update_action(app) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/mk_semi_lattice/ruby2d_action.rb', line 134 def self.update_action(app) app.edges.each(&:relax) app.nodes.each { |n| n.relax(app.nodes) } app.nodes.each(&:update) app.edges.reverse.each(&:draw) app.nodes.reverse.each do |n| n.draw(app.selected == n) end end |