* New: meta commands
* New scroll function for Ncurses mode.
@@ -43,5 +43,10 @@ | ||
43 | 43 | def column |
44 | 44 | @col |
45 | 45 | end |
46 | + | |
47 | + def ==(other) | |
48 | + return nil if other.class != self.class | |
49 | + self.row == other.row && self.column == other.column | |
50 | + end | |
46 | 51 | end |
47 | 52 | end |
@@ -103,7 +103,29 @@ | ||
103 | 103 | end |
104 | 104 | |
105 | 105 | def cursor_physical_to_logical(p_cursor) |
106 | - | |
106 | + l_cursor = Edmaru::Cursor.new | |
107 | + | |
108 | + line_num = @buffer.lines.size | |
109 | + | |
110 | + for n in 0...line_num | |
111 | + l_cursor.row = n | |
112 | + l_cursor.column = 0 | |
113 | + start_p_cursor = cursor_logical_to_physical(l_cursor) | |
114 | + | |
115 | + l_cursor.column = @buffer.lines[n].size | |
116 | + end_p_cursor = cursor_logical_to_physical(l_cursor) | |
117 | + | |
118 | + if start_p_cursor.row <= p_cursor.row && | |
119 | + end_p_cursor.row >= p_cursor.row | |
120 | + l_cursor.column = 0 | |
121 | + l_cursor.column += | |
122 | + (p_cursor.row - start_p_cursor.row) * @max_column | |
123 | + l_cursor.column += p_cursor.column | |
124 | + return l_cursor | |
125 | + end | |
126 | + end | |
127 | + | |
128 | + return nil | |
107 | 129 | end |
108 | 130 | |
109 | 131 | #Refresh hte cursor. Move the cursor to the correct position. |
@@ -118,26 +140,11 @@ | ||
118 | 140 | p_cursor = cursor_logical_to_physical(@cursor) |
119 | 141 | |
120 | 142 | if (p_cursor.row - @p_start_row) >= @max_row |
121 | - # scroll down | |
122 | - if @max_row != 1 | |
123 | - @p_start_row += (@max_row / 2) | |
124 | - else | |
125 | - @p_start_row += 1 | |
126 | - end | |
127 | - | |
128 | - refresh | |
129 | - return | |
143 | + #ToDo: scroll to the appropriate position at once | |
144 | + scroll_down | |
130 | 145 | elsif (p_cursor.row - @p_start_row) < 0 && @p_start_row > 0 |
131 | - # scroll up | |
132 | - if @max_row != 1 | |
133 | - @p_start_row -= (@max_row / 2) | |
134 | - else | |
135 | - @p_start_row -= 1 | |
136 | - end | |
137 | - @p_start_row = 0 if @p_start_row < 0 | |
138 | - | |
139 | - refresh | |
140 | - return | |
146 | + #ToDo: scroll to the appropriate position at once | |
147 | + scroll_up | |
141 | 148 | end |
142 | 149 | |
143 | 150 | @win.move(p_cursor.row - @p_start_row, p_cursor.column) |
@@ -189,33 +196,83 @@ | ||
189 | 196 | |
190 | 197 | #Scroll down this window. |
191 | 198 | def scroll_down |
192 | -# @p_start_row += 1 | |
193 | - refresh | |
194 | -=begin | |
199 | + @view.hide_alert | |
195 | 200 | |
196 | - if (p_cursor_row - @p_start_row) >= @max_row | |
197 | - # scroll down | |
201 | + end_l_cursor = Edmaru::Cursor.new | |
202 | + end_l_cursor.row = @buffer.lines.size - 1 | |
203 | + end_l_cursor.column = @buffer.lines[end_l_cursor.row].size | |
204 | + | |
205 | + end_p_cursor = cursor_logical_to_physical(end_l_cursor) | |
206 | + end_p_row = end_p_cursor.row | |
207 | + | |
208 | + if @p_start_row + @max_row > end_p_row | |
209 | + @view.show_alert("End of buffer") | |
210 | + return | |
211 | + end | |
212 | + | |
213 | + prev_p_start_row = @p_start_row | |
214 | + if @max_row != 1 | |
215 | + @p_start_row += (@max_row / 2).to_i | |
216 | + else | |
217 | + @p_start_row += 1 | |
218 | + end | |
219 | + | |
220 | + if @p_start_row > end_p_row | |
221 | + @p_start_row = prev_p_start_row | |
222 | + end | |
223 | + | |
224 | + p_cursor = cursor_logical_to_physical(@cursor) | |
225 | + if p_cursor.row < @p_start_row | |
198 | 226 | if @max_row != 1 |
199 | - @p_start_row += (@max_row / 2) | |
227 | + p_cursor.row += (@max_row / 2).to_i | |
200 | 228 | else |
201 | - @p_start_row += 1 | |
229 | + p_cursor.row += 1 | |
202 | 230 | end |
231 | + p_cursor.column = 0 | |
232 | + l_cursor = cursor_physical_to_logical(p_cursor) | |
233 | + if l_cursor != nil | |
234 | + @cursor = l_cursor | |
235 | + else | |
236 | + @cursor = end_l_cursor | |
237 | + end | |
238 | + end | |
203 | 239 | |
204 | - refresh | |
240 | + refresh | |
241 | + end | |
242 | + | |
243 | + #Scroll up this window | |
244 | + def scroll_up | |
245 | + @view.hide_alert | |
246 | + | |
247 | + if @p_start_row == 0 | |
248 | + @view.show_alert("Beginning of buffer") | |
205 | 249 | return |
206 | - elsif (p_cursor_row - @p_start_row) < 0 && @p_start_row > 0 | |
207 | - # scroll up | |
250 | + end | |
251 | + | |
252 | + if @max_row != 1 | |
253 | + @p_start_row -= (@max_row / 2) | |
254 | + else | |
255 | + @p_start_row -= 1 | |
256 | + end | |
257 | + @p_start_row = 0 if @p_start_row < 0 | |
258 | + | |
259 | + p_cursor = cursor_logical_to_physical(@cursor) | |
260 | + if p_cursor.row >= @p_start_row + @max_row | |
208 | 261 | if @max_row != 1 |
209 | - @p_start_row -= (@max_row / 2) | |
262 | + p_cursor.row -= (@max_row / 2).to_i | |
210 | 263 | else |
211 | - @p_start_row -= 1 | |
264 | + p_cursor.row -= 1 | |
212 | 265 | end |
213 | - @p_start_row = 0 if @p_start_row < 0 | |
266 | + p_cursor.column = 0 | |
267 | + l_cursor = cursor_physical_to_logical(p_cursor) | |
268 | + if l_cursor != nil | |
269 | + @cursor = l_cursor | |
270 | + else | |
271 | + @cursor.row = @cursor.column = 0 | |
272 | + end | |
273 | + end | |
214 | 274 | |
215 | - refresh | |
216 | - return | |
217 | - end | |
218 | -=end | |
275 | + refresh | |
219 | 276 | end |
220 | 277 | |
221 | 278 | def ncurses_allocated_row |
@@ -1,3 +1,8 @@ | ||
1 | +2007-04-21 Takashi Nakamoto <bluedwarf@bpost.plala.or.jp> | |
2 | + | |
3 | + * New: meta commands | |
4 | + * New scroll function for Ncurses mode. | |
5 | + | |
1 | 6 | 2007-04-20 Takashi Nakamoto <bluedwarf@bpost.plala.or.jp> |
2 | 7 | |
3 | 8 | * New configuration setter. |
@@ -94,12 +94,31 @@ | ||
94 | 94 | @view.focused_window.cursor_goto_next_line |
95 | 95 | when "cursor-goto-previous-line" |
96 | 96 | @view.focused_window.cursor_goto_previous_line |
97 | + when "cursor-goto-beginning" | |
98 | + @view.focused_window.cursor_goto_beginning | |
99 | + when "cursor-goto-end" | |
100 | + @view.focused_window.cursor_goto_end | |
97 | 101 | when "scroll-down" |
98 | 102 | @view.focused_window.scroll_down |
103 | + when "scroll-up" | |
104 | + @view.focused_window.scroll_up | |
105 | + @event_manager.set_current_handler(FundamentalEventHandler.new(self)) | |
106 | + when "meta-command" | |
107 | + @event_manager.set_current_handler(MetaCommandHandler.new(self)) | |
108 | + | |
109 | + mini_buffer = @buffer_manager.get("*mini buffer*", MiniBuffer) | |
110 | + mini_buffer.clear | |
111 | + mini_buffer.append("M-") | |
112 | + @view.mini_window.buffer = mini_buffer | |
113 | + when "meta-command-quit" | |
114 | + @event_manager.set_current_handler(FundamentalEventHandler.new(self)) | |
115 | + | |
116 | + mini_buffer = @buffer_manager.get("*mini buffer*", MiniBuffer) | |
117 | + mini_buffer.clear | |
99 | 118 | when "extra-command" |
100 | 119 | @event_manager.set_current_handler(ExtraCommandHandler.new(self)) |
101 | 120 | |
102 | - mini_buffer = @buffer_manager.get("*mini buffer*", Buffer) | |
121 | + mini_buffer = @buffer_manager.get("*mini buffer*", MiniBuffer) | |
103 | 122 | mini_buffer.clear |
104 | 123 | mini_buffer.insert(0, 0, "C-x-") |
105 | 124 | @view.mini_window.buffer = mini_buffer |
@@ -106,7 +125,7 @@ | ||
106 | 125 | when "extra-command-quit" |
107 | 126 | @event_manager.set_current_handler(FundamentalEventHandler.new(self)) |
108 | 127 | |
109 | - mini_buffer = @buffer_manager.get("*mini buffer*", Buffer) | |
128 | + mini_buffer = @buffer_manager.get("*mini buffer*", MiniBuffer) | |
110 | 129 | mini_buffer.clear |
111 | 130 | |
112 | 131 | @view.show_alert("Quit") |
@@ -158,3 +177,4 @@ | ||
158 | 177 | end |
159 | 178 | end |
160 | 179 | end |
180 | + |
@@ -192,10 +192,33 @@ | ||
192 | 192 | def cursor_goto_line_tail |
193 | 193 | @view.hide_alert |
194 | 194 | |
195 | - @cursor.column = buffer.lines[@cursor.row].size | |
195 | + @cursor.column = @buffer.lines[@cursor.row].size | |
196 | 196 | refresh_cursor |
197 | 197 | end |
198 | 198 | |
199 | + #Move the cursor to the beginning of the buffer. | |
200 | + # | |
201 | + #=== Warning | |
202 | + #This method *MUST* *NOT* be overrided in derived classes. | |
203 | + def cursor_goto_beginning | |
204 | + @view.hide_alert | |
205 | + | |
206 | + @cursor.row = @cursor.column = 0 | |
207 | + refresh_cursor | |
208 | + end | |
209 | + | |
210 | + #Move the cursor to the end of the buffer. | |
211 | + # | |
212 | + #=== Warning | |
213 | + #This method *MUST* *NOT* be overrided in derived classes. | |
214 | + def cursor_goto_end | |
215 | + @view.hide_alert | |
216 | + | |
217 | + @cursor.row = @buffer.lines.size - 1 | |
218 | + @cursor.column = @buffer.lines[@cursor.row].size | |
219 | + refresh_cursor | |
220 | + end | |
221 | + | |
199 | 222 | #Move the cursor to the next line. |
200 | 223 | # |
201 | 224 | #=== Warning |
@@ -30,6 +30,7 @@ | ||
30 | 30 | @action_table["KeyPress:#{ch.chr}"] = Action.new("insert", [ch.chr]) |
31 | 31 | end |
32 | 32 | |
33 | + @action_table["KeyPress:escape"] = Action.new("meta-command") | |
33 | 34 | @action_table["KeyPress:space"] = Action.new("insert", [" "]) |
34 | 35 | @action_table["KeyPress:return"] = Action.new("insert", ["\n"]) |
35 | 36 | @action_table["KeyPress:delete"] = Action.new("delete") |
@@ -71,7 +71,15 @@ | ||
71 | 71 | #_event_name_ :: The event name to be handled. |
72 | 72 | def handle(event_name) |
73 | 73 | if @action_table.include?(event_name) |
74 | - @action_manager.action(@action_table[event_name]) | |
74 | + if @action_table[event_name].class == Edmaru::Action | |
75 | + @action_manager.action(@action_table[event_name]) | |
76 | + elsif @action_table[event_name].class == Array | |
77 | + @action_table[event_name].each{ |action| | |
78 | + @action_manager.action(action) | |
79 | + } | |
80 | + else | |
81 | + raise "Unknown type of action #{@action_table[event_name].class.to_s}." | |
82 | + end | |
75 | 83 | elsif @parent_handler != nil |
76 | 84 | @parent_handler.handle(event_name) |
77 | 85 | else |
@@ -19,4 +19,5 @@ | ||
19 | 19 | |
20 | 20 | require "event_handler/fundamental.rb" |
21 | 21 | require "event_handler/extra_command.rb" |
22 | +require "event_handler/meta_command.rb" | |
22 | 23 | require "event_handler/find_file.rb" |