Class: Glimmer::Gladiator::TextEditor
- Inherits:
-
Object
- Object
- Glimmer::Gladiator::TextEditor
- Includes:
- UI::CustomWidget
- Defined in:
- lib/views/glimmer/gladiator/text_editor.rb
Instance Attribute Summary collapse
-
#text_proxy ⇒ Object
readonly
Returns the value of attribute text_proxy.
Instance Method Summary collapse
- #bump_font_height_down ⇒ Object
- #bump_font_height_up ⇒ Object
- #extract_char(event) ⇒ Object
- #font_datum ⇒ Object
- #load_content ⇒ Object
- #load_line_numbers_text_content ⇒ Object
- #load_text_content ⇒ Object
- #restore_font_height ⇒ Object
- #text_widget ⇒ Object
- #update_font_height(new_font_height) ⇒ Object
Instance Attribute Details
#text_proxy ⇒ Object (readonly)
Returns the value of attribute text_proxy.
29 30 31 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 29 def text_proxy @text_proxy end |
Instance Method Details
#bump_font_height_down ⇒ Object
221 222 223 224 225 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 221 def bump_font_height_down @original_font_height ||= font_datum.height new_font_height = (font_datum.height - 1) == 0 ? font_datum.height : (font_datum.height - 1) update_font_height(new_font_height) end |
#bump_font_height_up ⇒ Object
215 216 217 218 219 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 215 def bump_font_height_up @original_font_height ||= font_datum.height new_font_height = font_datum.height + 1 update_font_height(new_font_height) end |
#extract_char(event) ⇒ Object
97 98 99 100 101 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 97 def extract_char(event) event.keyCode.chr rescue => e nil end |
#font_datum ⇒ Object
241 242 243 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 241 def font_datum @text_proxy.font.font_data.first end |
#load_content ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 107 def load_content if !@initialized && !Gladiator.startup load_line_numbers_text_content load_text_content @initialized = true end end |
#load_line_numbers_text_content ⇒ Object
115 116 117 118 119 120 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 115 def load_line_numbers_text_content @line_numbers_text.content { text bind(self, 'file.line_numbers_content') top_pixel bind(self, 'file.top_pixel', read_only: true) } end |
#load_text_content ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 122 def load_text_content @text_proxy.content { text bind(self, 'file.content') selection_count bind(self, 'file.selection_count') caret_position bind(self, 'file.caret_position') top_pixel bind(self, 'file.top_pixel') # key_binding swt(:ctrl, :home), ST::TEXT_START # This seems to make the caret disappear on Windows so disabling for now and relying on key event instead on_focus_lost { file&.write_dirty_content } on_verify_key { |key_event| if (Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && extract_char(key_event) == 'z') || (key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'y') key_event.doit = !Command.redo(file) elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'z' key_event.doit = !Command.undo(file) elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'a' key_event..selectAll elsif (OS.mac? && key_event.keyCode == swt(:home)) || (!OS.mac? && Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :ctrl) && key_event.keyCode == swt(:home)) file.home key_event.doit = false elsif (OS.mac? && key_event.keyCode == swt(:home)) || (!OS.mac? && Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :ctrl) && key_event.keyCode == swt(:end)) file.end key_event.doit = false elsif !OS.mac? && Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :shift) && key_event.keyCode == swt(:home) file.select_to_start_of_line key_event.doit = false elsif !OS.mac? && Glimmer::SWT::SWTProxy.include?(key_event.stateMask, :shift) && key_event.keyCode == swt(:end) file.select_to_end_of_line key_event.doit = false elsif (OS.mac? && key_event.stateMask == swt(:ctrl) && extract_char(key_event) == 'a') || (!OS.mac? && key_event.keyCode == swt(:home)) file.start_of_line key_event.doit = false elsif (OS.mac? && key_event.stateMask == swt(:ctrl) && extract_char(key_event) == 'e') || (!OS.mac? && key_event.keyCode == swt(:end)) file.end_of_line key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == '/' Command.do(file, :comment_line!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'k' Command.do(file, :kill_line!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == 'd' Command.do(file, :duplicate_line!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == '[' Command.do(file, :outdent!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == ']' Command.do(file, :indent!) key_event.doit = false elsif Glimmer::SWT::SWTProxy.include?(key_event.stateMask, COMMAND_KEY, :shift) && key_event.keyCode == swt(:cr) Command.do(file, :prefix_new_line!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:cr) Command.do(file, :insert_new_line!) key_event.doit = false elsif key_event.keyCode == swt(:page_up) file.page_up key_event.doit = false elsif key_event.keyCode == swt(:page_down) file.page_down key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:arrow_up) Command.do(file, :move_up!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && key_event.keyCode == swt(:arrow_down) Command.do(file, :move_down!) key_event.doit = false elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == '=' bump_font_height_up elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == '-' bump_font_height_down elsif key_event.stateMask == swt(COMMAND_KEY) && extract_char(key_event) == '0' restore_font_height end } on_verify_text { |verify_event| # TODO convert these into File commands to support Undo/Redo case verify_event.text when "\n" if file.selection_count.to_i == 0 verify_event.text += file.current_line_indentation end # TODO implement this to borrowed line of code from Glimmer Meta-Sample # verify_event.text += ' '*2 if line.strip.end_with?('{') || line.strip.match(/do[ ]+([|][^|]+[|])?$/) || line.start_with?('class') || line.start_with?('module') || line.strip.start_with?('def') when "\t" Command.do(file, :indent!) verify_event.doit = false end } } end |
#restore_font_height ⇒ Object
227 228 229 230 231 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 227 def restore_font_height return if @original_font_height.nil? update_font_height(@original_font_height) @original_font_height = nil end |
#text_widget ⇒ Object
103 104 105 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 103 def @text_proxy. end |
#update_font_height(new_font_height) ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/views/glimmer/gladiator/text_editor.rb', line 233 def update_font_height(new_font_height) return if new_font_height.nil? @text_proxy.font = {name: font_datum.name, height: new_font_height, style: font_datum.style} @line_numbers_text&.font = {name: font_datum.name, height: new_font_height, style: font_datum.style} @body_root.shell_proxy.layout(true, true) @body_root.shell_proxy.pack_same_size end |