• R/O
  • SSH
  • HTTPS

edmaru: コミット


コミットメタ情報

リビジョン44 (tree)
日時2007-04-21 04:04:12
作者bluedwarf

ログメッセージ

* New: meta commands
* New scroll function for Ncurses mode.

変更サマリ

差分

--- cursor.rb (revision 43)
+++ cursor.rb (revision 44)
@@ -43,5 +43,10 @@
4343 def column
4444 @col
4545 end
46+
47+ def ==(other)
48+ return nil if other.class != self.class
49+ self.row == other.row && self.column == other.column
50+ end
4651 end
4752 end
--- ncurses/ncurses_window.rb (revision 43)
+++ ncurses/ncurses_window.rb (revision 44)
@@ -103,7 +103,29 @@
103103 end
104104
105105 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
107129 end
108130
109131 #Refresh hte cursor. Move the cursor to the correct position.
@@ -118,26 +140,11 @@
118140 p_cursor = cursor_logical_to_physical(@cursor)
119141
120142 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
130145 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
141148 end
142149
143150 @win.move(p_cursor.row - @p_start_row, p_cursor.column)
@@ -189,33 +196,83 @@
189196
190197 #Scroll down this window.
191198 def scroll_down
192-# @p_start_row += 1
193- refresh
194-=begin
199+ @view.hide_alert
195200
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
198226 if @max_row != 1
199- @p_start_row += (@max_row / 2)
227+ p_cursor.row += (@max_row / 2).to_i
200228 else
201- @p_start_row += 1
229+ p_cursor.row += 1
202230 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
203239
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")
205249 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
208261 if @max_row != 1
209- @p_start_row -= (@max_row / 2)
262+ p_cursor.row -= (@max_row / 2).to_i
210263 else
211- @p_start_row -= 1
264+ p_cursor.row -= 1
212265 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
214274
215- refresh
216- return
217- end
218-=end
275+ refresh
219276 end
220277
221278 def ncurses_allocated_row
--- ChangeLog (revision 43)
+++ ChangeLog (revision 44)
@@ -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+
16 2007-04-20 Takashi Nakamoto <bluedwarf@bpost.plala.or.jp>
27
38 * New configuration setter.
--- action_manager.rb (revision 43)
+++ action_manager.rb (revision 44)
@@ -94,12 +94,31 @@
9494 @view.focused_window.cursor_goto_next_line
9595 when "cursor-goto-previous-line"
9696 @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
97101 when "scroll-down"
98102 @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
99118 when "extra-command"
100119 @event_manager.set_current_handler(ExtraCommandHandler.new(self))
101120
102- mini_buffer = @buffer_manager.get("*mini buffer*", Buffer)
121+ mini_buffer = @buffer_manager.get("*mini buffer*", MiniBuffer)
103122 mini_buffer.clear
104123 mini_buffer.insert(0, 0, "C-x-")
105124 @view.mini_window.buffer = mini_buffer
@@ -106,7 +125,7 @@
106125 when "extra-command-quit"
107126 @event_manager.set_current_handler(FundamentalEventHandler.new(self))
108127
109- mini_buffer = @buffer_manager.get("*mini buffer*", Buffer)
128+ mini_buffer = @buffer_manager.get("*mini buffer*", MiniBuffer)
110129 mini_buffer.clear
111130
112131 @view.show_alert("Quit")
@@ -158,3 +177,4 @@
158177 end
159178 end
160179 end
180+
--- window.rb (revision 43)
+++ window.rb (revision 44)
@@ -192,10 +192,33 @@
192192 def cursor_goto_line_tail
193193 @view.hide_alert
194194
195- @cursor.column = buffer.lines[@cursor.row].size
195+ @cursor.column = @buffer.lines[@cursor.row].size
196196 refresh_cursor
197197 end
198198
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+
199222 #Move the cursor to the next line.
200223 #
201224 #=== Warning
--- event_handler/fundamental.rb (revision 43)
+++ event_handler/fundamental.rb (revision 44)
@@ -30,6 +30,7 @@
3030 @action_table["KeyPress:#{ch.chr}"] = Action.new("insert", [ch.chr])
3131 end
3232
33+ @action_table["KeyPress:escape"] = Action.new("meta-command")
3334 @action_table["KeyPress:space"] = Action.new("insert", [" "])
3435 @action_table["KeyPress:return"] = Action.new("insert", ["\n"])
3536 @action_table["KeyPress:delete"] = Action.new("delete")
--- event_handler/event_handler_base.rb (revision 43)
+++ event_handler/event_handler_base.rb (revision 44)
@@ -71,7 +71,15 @@
7171 #_event_name_ :: The event name to be handled.
7272 def handle(event_name)
7373 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
7583 elsif @parent_handler != nil
7684 @parent_handler.handle(event_name)
7785 else
--- event_handler/all_event_handlers.rb (revision 43)
+++ event_handler/all_event_handlers.rb (revision 44)
@@ -19,4 +19,5 @@
1919
2020 require "event_handler/fundamental.rb"
2121 require "event_handler/extra_command.rb"
22+require "event_handler/meta_command.rb"
2223 require "event_handler/find_file.rb"
旧リポジトリブラウザで表示