Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /window.rb

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (hide annotations) (download)
Sun Apr 8 11:00:15 2007 UTC (16 years, 11 months ago) by bluedwarf
File size: 4967 byte(s)
Added some actions.

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     #
33     #=== Warning
34     #This method *MUST* *NOT* be overrided in derived classes.
35     #
36     #=== Return
37     #An initialized instance of Window.
38 bluedwarf 15 def initialize(view)
39 bluedwarf 6 @view = view
40 bluedwarf 9 @cursor = Cursor.new(0, 0)
41 bluedwarf 17 @modeline = Edmaru::SYSTEM_MODELINE.new(self)
42 bluedwarf 9
43 bluedwarf 15 init_ui
44 bluedwarf 4 end
45    
46 bluedwarf 6 #The system specific initialization for this window.
47     #
48     #=== Warning
49     #This method *SHOULD* be overrided in derived classes.
50 bluedwarf 15 def init_ui
51 bluedwarf 5 end
52    
53 bluedwarf 9 #Discard the current buffer and set the specified new buffer.
54     #
55 bluedwarf 18 #=== Warning
56     #This method *MUST* *NOT* be overrided in derived classes.
57     #
58 bluedwarf 9 #=== Argument
59     #_new_buffer_ :: The buffer to be shown in this window.
60     def buffer=(new_buffer)
61     if @buffer != nil
62     @buffer.unlink(self)
63     end
64 bluedwarf 4
65 bluedwarf 9 #Linked buffer to this window.
66     @buffer = new_buffer
67     @buffer.link(self)
68     refresh
69 bluedwarf 4 end
70    
71 bluedwarf 9 def buffer
72     @buffer
73 bluedwarf 4 end
74    
75 bluedwarf 15 def modeline
76     @modeline
77     end
78    
79 bluedwarf 18 #Insert the specified string to the buffer shown in this window.
80     #
81     #=== Warning
82     #This method *MUST* *NOT* be overrided in derived classes.
83     #
84     #=== Argument
85     #_str_ :: String to be inserted.
86     #_move_cursor_ :: _true_ to cause the cursor move to the end of the
87     #inserted string.
88     def insert_at_cursor(str, move_cursor = true)
89     #Insert to the buffer.
90     @buffer.insert(@cursor.row, @cursor.column, str)
91    
92     #Move the cursor to the end of inserted string.
93     if move_cursor
94     str.size.times{ |n|
95     cursor_forward
96     }
97     end
98    
99     refresh
100     end
101    
102     #Move the cursor forward.
103     #
104     #=== Argument
105     #_n_ :: the number of times to forward the cursor.
106     #
107     #=== Warning
108     #This method *MUST* *NOT* be overrided in derived classes.
109     def cursor_forward(n = 1)
110     n.times{
111     if @cursor.column >= @buffer.lines[@cursor.row].size &&
112     @cursor.row == (@buffer.lines.size - 1)
113     #ToDo: Alert that the cursor is at the end of this buffer.
114     @view.beep
115     elsif @cursor.column >= @buffer.lines[@cursor.row].size
116     #Go to the begin of the next line
117     @cursor.row += 1
118     @cursor.column = 0
119     else
120     @cursor.column += 1
121     end
122     }
123    
124     refresh_cursor
125     end
126    
127     #Move the cursor backward.
128     #
129     #=== Argument
130     #_n_ :: the number of times to backward the cursor.
131     #
132     #=== Warning
133     #This method *MUST* *NOT* be overrided in derived classes.
134     def cursor_backward(n = 1)
135     n.times{
136     if @cursor.column == 0 && @cursor.row == 0
137     #ToDo: Alert that the cursor is at the begin of this buffer.
138     @view.beep
139     elsif @cursor.column == 0
140     @cursor.row -= 1
141     @cursor.column = @buffer.lines[@cursor.row].size
142     else
143     @cursor.column -= 1
144     end
145     }
146    
147     refresh_cursor
148     end
149    
150     #Move the cursor to the begin of the current line.
151     #
152     #=== Warning
153     #This method *MUST* *NOT* be overrided in derived classes.
154     def cursor_goto_line_head
155     @cursor.column = 0
156     refresh_cursor
157     end
158    
159     #Move the cursor to the end of the current line.
160     #
161     #=== Warning
162     #This method *MUST* *NOT* be overrided in derived classes.
163     def cursor_goto_line_tail
164     @cursor.column = buffer.lines[@cursor.row].size
165     refresh_cursor
166     end
167    
168     #Redraw the cursor.
169     #
170     #=== Warning
171     #This method *SHOULD* be overrided in derived clases.
172     def refresh_cursor
173     end
174    
175 bluedwarf 9 #Redraw this window.
176     #
177     #=== Warning
178     #This method *SHOULD* be overrided in derived clases.
179 bluedwarf 4 def refresh
180     end
181    
182 bluedwarf 6 #Terminate this view instance.
183     #
184     #=== Warning
185 bluedwarf 7 #This method *MUST* *NOT* be overrided in derived classes.
186 bluedwarf 4 def terminate
187 bluedwarf 7 @modeline.terminate
188    
189     terminate_ui
190 bluedwarf 4 end
191 bluedwarf 7
192     #Free system specific resources.
193     #
194     #=== Warning
195     #This method *SHOULD* be overrided in derived classes.
196     def terminate_ui
197     end
198 bluedwarf 4 end
199     end

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