Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /window.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (hide annotations) (download)
Thu Apr 12 19:31:19 2007 UTC (16 years, 11 months ago) by bluedwarf
File size: 7941 byte(s)
All buffer manipulation codes are moved to Edmaru::Buffer.

1 bluedwarf 12 # window.rb: the module definition of Edmaru::Window.
2 bluedwarf 10 #
3     # Copyright (C) 2007 Takashi Nakamoto
4     #
5     # This program is free software; you can redistribute it and/or modify
6     # it under the terms of the GNU General Public License version 2 as
7     # published by the Free Software Foundation.
8     #
9     # This program is distributed in the hope that it will be useful, but
10     # WITHOUT ANY WARRANTY; without even the implied warranty of
11     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     # General Public License for more details.
13     #
14     # You should have received a copy of the GNU General Public License
15     # along with this program; if not, write to the Free Software
16     # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17     # 02110-1301 USA.
18     #
19 bluedwarf 4
20 bluedwarf 9 require "cursor.rb"
21 bluedwarf 5 require "modeline.rb"
22    
23 bluedwarf 4 module Edmaru
24 bluedwarf 5
25 bluedwarf 6 #Abstract class to implement system specific window.
26 bluedwarf 5 module Window
27    
28 bluedwarf 6 #Construct a window instance.
29 bluedwarf 5 #
30 bluedwarf 6 #=== Arguments
31     #_view_ :: The parent view.
32 bluedwarf 20 #_config_ :: An instance of Edmaru::ConfigurationManager.
33 bluedwarf 6 #
34     #=== Warning
35     #This method *MUST* *NOT* be overrided in derived classes.
36     #
37     #=== Return
38     #An initialized instance of Window.
39 bluedwarf 20 def initialize(view, config)
40 bluedwarf 24 @buffer = nil
41 bluedwarf 6 @view = view
42 bluedwarf 20 @config = config
43 bluedwarf 31 @cursor = Cursor.new(0, 0) # logical cursor
44 bluedwarf 17 @modeline = Edmaru::SYSTEM_MODELINE.new(self)
45 bluedwarf 30 @start_line = 0
46 bluedwarf 9
47 bluedwarf 15 init_ui
48 bluedwarf 4 end
49    
50 bluedwarf 6 #The system specific initialization for this window.
51     #
52     #=== Warning
53     #This method *SHOULD* be overrided in derived classes.
54 bluedwarf 15 def init_ui
55 bluedwarf 5 end
56    
57 bluedwarf 9 #Discard the current buffer and set the specified new buffer.
58     #
59 bluedwarf 18 #=== Warning
60     #This method *MUST* *NOT* be overrided in derived classes.
61     #
62 bluedwarf 9 #=== Argument
63     #_new_buffer_ :: The buffer to be shown in this window.
64     def buffer=(new_buffer)
65     if @buffer != nil
66     @buffer.unlink(self)
67     end
68 bluedwarf 4
69 bluedwarf 9 #Linked buffer to this window.
70     @buffer = new_buffer
71     @buffer.link(self)
72     refresh
73 bluedwarf 4 end
74    
75 bluedwarf 9 def buffer
76     @buffer
77 bluedwarf 4 end
78    
79 bluedwarf 15 def modeline
80     @modeline
81     end
82    
83 bluedwarf 28 #Remove all characters from this buffer.
84     #
85     #=== Warning
86     #This method *MUST* *NOT* be overrided in derived classes.
87     #
88     def clear
89     @cursor.row = @cursor.column = 0
90     @buffer.clear
91     end
92    
93 bluedwarf 18 #Insert the specified string to the buffer shown in this window.
94     #
95     #=== Warning
96     #This method *MUST* *NOT* be overrided in derived classes.
97     #
98     #=== Argument
99     #_str_ :: String to be inserted.
100     #_move_cursor_ :: _true_ to cause the cursor move to the end of the
101     #inserted string.
102     def insert_at_cursor(str, move_cursor = true)
103     #Insert to the buffer.
104     @buffer.insert(@cursor.row, @cursor.column, str)
105    
106     #Move the cursor to the end of inserted string.
107 bluedwarf 30 cursor_forward(str.size) if move_cursor
108 bluedwarf 18 end
109    
110     #Move the cursor forward.
111     #
112     #=== Argument
113     #_n_ :: the number of times to forward the cursor.
114     #
115     #=== Warning
116     #This method *MUST* *NOT* be overrided in derived classes.
117     def cursor_forward(n = 1)
118     n.times{
119     if @cursor.column >= @buffer.lines[@cursor.row].size &&
120     @cursor.row == (@buffer.lines.size - 1)
121     #ToDo: Alert that the cursor is at the end of this buffer.
122     @view.beep
123     elsif @cursor.column >= @buffer.lines[@cursor.row].size
124     #Go to the begin of the next line
125     @cursor.row += 1
126     @cursor.column = 0
127     else
128     @cursor.column += 1
129     end
130     }
131    
132     refresh_cursor
133     end
134    
135     #Move the cursor backward.
136     #
137     #=== Argument
138     #_n_ :: the number of times to backward the cursor.
139     #
140     #=== Warning
141     #This method *MUST* *NOT* be overrided in derived classes.
142     def cursor_backward(n = 1)
143     n.times{
144     if @cursor.column == 0 && @cursor.row == 0
145     #ToDo: Alert that the cursor is at the begin of this buffer.
146     @view.beep
147     elsif @cursor.column == 0
148     @cursor.row -= 1
149     @cursor.column = @buffer.lines[@cursor.row].size
150     else
151     @cursor.column -= 1
152     end
153     }
154    
155     refresh_cursor
156     end
157    
158     #Move the cursor to the begin of the current line.
159     #
160     #=== Warning
161     #This method *MUST* *NOT* be overrided in derived classes.
162     def cursor_goto_line_head
163     @cursor.column = 0
164     refresh_cursor
165     end
166    
167     #Move the cursor to the end of the current line.
168     #
169     #=== Warning
170     #This method *MUST* *NOT* be overrided in derived classes.
171     def cursor_goto_line_tail
172     @cursor.column = buffer.lines[@cursor.row].size
173     refresh_cursor
174     end
175    
176 bluedwarf 19 #Move the cursor to the next line.
177     #
178     #=== Warning
179     #This method *MUST* *NOT* be overrided in derived classes.
180     def cursor_goto_next_line
181     if @cursor.row == (@buffer.lines.size - 1)
182 bluedwarf 33 @view.mini_window.show_alert("The last line")
183 bluedwarf 19 @view.beep
184     else
185     @cursor.row += 1
186     if @buffer.lines[@cursor.row].size < @cursor.column
187     @cursor.column = @buffer.lines[@cursor.row].size
188     end
189 bluedwarf 21
190     refresh_cursor
191 bluedwarf 19 end
192     end
193    
194     #Move the cursor to the previous line.
195     #
196     #=== Warning
197     #This method *MUST* *NOT* be overrided in derived classes.
198     def cursor_goto_previous_line
199     if @cursor.row == 0
200 bluedwarf 33 @view.mini_window.show_alert("The first line")
201 bluedwarf 19 @view.beep
202     else
203     @cursor.row -= 1
204     if @buffer.lines[@cursor.row].size < @cursor.column
205     @cursor.column = @buffer.lines[@cursor.row].size
206     end
207 bluedwarf 21
208     refresh_cursor
209 bluedwarf 19 end
210 bluedwarf 21 end
211 bluedwarf 19
212 bluedwarf 21 #Remove a character just in front of the cursor and move the cursor
213     #backward.
214     #
215     #=== Warning
216     #This method *MUST* *NOT* be overrided in derived classes.
217     def backspace
218     if @cursor.column == 0 && @cursor.row == 0
219     #ToDo: Alert that the cursor is at the begin of the current buffer.
220 bluedwarf 33 @view.mini_window.show_alert("Beginning of buffer")
221 bluedwarf 21 @view.beep
222 bluedwarf 33 elsif @cursor.column == 0 # && @cursor.row != 0
223 bluedwarf 21 #Concatenate the current lien into the previous line.
224     @cursor.row -= 1
225 bluedwarf 33 @cursor.column = @buffer.lines[@cursor.row].size
226     delete_at_cursor
227 bluedwarf 21 else
228     @cursor.column -= 1
229 bluedwarf 33 delete_at_cursor
230 bluedwarf 21 end
231 bluedwarf 19 end
232    
233 bluedwarf 21 #Remove a character beneath the cursor.
234     #
235     #=== Warning
236     #This method *MUST* *NOT* be overrided in derived classes.
237 bluedwarf 33 def delete_at_cursor
238     begin
239     @buffer.delete_at(@cursor.row, @cursor.column)
240     rescue EndOfBufferException => e
241     @view.mini_window.show_alert(e.to_s)
242 bluedwarf 21 @view.beep
243     end
244     end
245    
246 bluedwarf 26 #Remove the string in the current line behind the cursor and push it to
247     #the kill ring.
248     #
249     #=== Warning
250     #This method *MUST* *NOT* be overrided in derived classes.
251     def kill_line
252 bluedwarf 33 begin
253     @view.push_to_kill_ring(@buffer.delete_line(@cursor.row, @cursor.column))
254     rescue EndOfBufferException => e
255     @view.mini_window.show_alert(e.to_s)
256 bluedwarf 26 @view.beep
257     end
258     end
259    
260     #Get a certain string from kill ring and insert it at the cursor position.
261     #
262     #=== Warning
263     #This method *MUST* *NOT* be overrided in derived classes.
264     def yank
265     insert_at_cursor(@view.yank_from_kill_ring)
266     end
267    
268 bluedwarf 18 #Redraw the cursor.
269     #
270     #=== Warning
271     #This method *SHOULD* be overrided in derived clases.
272     def refresh_cursor
273     end
274    
275 bluedwarf 9 #Redraw this window.
276     #
277     #=== Warning
278     #This method *SHOULD* be overrided in derived clases.
279 bluedwarf 4 def refresh
280     end
281    
282 bluedwarf 6 #Terminate this view instance.
283     #
284     #=== Warning
285 bluedwarf 7 #This method *MUST* *NOT* be overrided in derived classes.
286 bluedwarf 4 def terminate
287 bluedwarf 7 @modeline.terminate
288    
289     terminate_ui
290 bluedwarf 4 end
291 bluedwarf 7
292     #Free system specific resources.
293     #
294     #=== Warning
295     #This method *SHOULD* be overrided in derived classes.
296     def terminate_ui
297     end
298 bluedwarf 4 end
299     end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26