| 1 |
# view.rb: the module definition of Edmaru::View. |
| 2 |
# |
| 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 |
|
| 20 |
require "event_manager.rb" |
| 21 |
require "window.rb" |
| 22 |
|
| 23 |
module Edmaru |
| 24 |
|
| 25 |
#Abstract class to implement system specific view. |
| 26 |
module View |
| 27 |
|
| 28 |
#Construct a view instance. |
| 29 |
# |
| 30 |
#=== Warning |
| 31 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 32 |
# |
| 33 |
#=== Argument |
| 34 |
#_config_ :: An instance of Edmaru::ConfigurationManager. |
| 35 |
#_event_manager_ :: An instance of Edmaru::EventManager to handle all events raised from this view. |
| 36 |
#_buffer_manager_ :: An instance of Edmaru::BufferManager. |
| 37 |
# |
| 38 |
#=== Return |
| 39 |
#An initialized instance of View. |
| 40 |
def initialize(config, event_manager, buffer_manager) |
| 41 |
@config = config |
| 42 |
@event_manager = event_manager |
| 43 |
@buffer_manager = buffer_manager |
| 44 |
@kill_ring = "" |
| 45 |
|
| 46 |
init_ui |
| 47 |
|
| 48 |
@windows = Array.new |
| 49 |
@windows.push(Edmaru::SYSTEM_WINDOW.new(self, @config)) |
| 50 |
@focused_window = @windows[0] |
| 51 |
@mini_window = Edmaru::SYSTEM_MINI_WINDOW.new(self, @config) |
| 52 |
|
| 53 |
init_windows |
| 54 |
|
| 55 |
element = ModeLineElement.new("buffer-name", -1, 1, 1, "") |
| 56 |
@windows[0].modeline.add_element(element) |
| 57 |
@windows[0].modeline.show_element("buffer-name") |
| 58 |
|
| 59 |
element = ModeLineElement.new("cursor-position", -1, 1, 1, "(*,*)") |
| 60 |
@windows[0].modeline.add_element(element) |
| 61 |
@windows[0].modeline.show_element("cursor-position") |
| 62 |
end |
| 63 |
|
| 64 |
#The system specific initialization for this view. |
| 65 |
# |
| 66 |
#=== Warning |
| 67 |
#This method *SHOULD* be overrided in derived classes. |
| 68 |
def init_ui |
| 69 |
end |
| 70 |
|
| 71 |
#The system specific initialization for windows that belongs to this view. |
| 72 |
# |
| 73 |
#=== Warning |
| 74 |
#This method *SHOULD* be overrided in derived classes. |
| 75 |
def init_windows |
| 76 |
end |
| 77 |
|
| 78 |
#The event manager linked to this view. |
| 79 |
# |
| 80 |
#=== Warning |
| 81 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 82 |
def event_manager |
| 83 |
@event_manager |
| 84 |
end |
| 85 |
|
| 86 |
#The mini window displayed in the bottom of the screen. |
| 87 |
# |
| 88 |
#=== Warning |
| 89 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 90 |
def mini_window |
| 91 |
@mini_window |
| 92 |
end |
| 93 |
|
| 94 |
#The main wnidow |
| 95 |
# |
| 96 |
#=== Warning |
| 97 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 98 |
def main_window |
| 99 |
@windows[0] |
| 100 |
end |
| 101 |
|
| 102 |
#The focused window. |
| 103 |
# |
| 104 |
#=== Warning |
| 105 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 106 |
def focused_window |
| 107 |
@focused_window |
| 108 |
end |
| 109 |
|
| 110 |
|
| 111 |
#Cause the specfieid window have focus. |
| 112 |
# |
| 113 |
#=== Warning |
| 114 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 115 |
def focused_window=(window) |
| 116 |
prev_focused_window = @focused_window |
| 117 |
@focused_window = window |
| 118 |
|
| 119 |
#ToDo: Determine this code must be deleted as far as possible |
| 120 |
#because a cursor in prev_focused_window doesn't need to be |
| 121 |
#refreshed. |
| 122 |
# prev_focused_window.refresh_cursor |
| 123 |
@focused_window.refresh_cursor |
| 124 |
end |
| 125 |
|
| 126 |
#Push the specified string to the kill ring. |
| 127 |
# |
| 128 |
#ToDo: This implementation is incomplete. Kill ring doesn't store multiple |
| 129 |
# strings. |
| 130 |
def push_to_kill_ring(str) |
| 131 |
@kill_ring = str |
| 132 |
end |
| 133 |
|
| 134 |
#Get a string from kill ring. |
| 135 |
# |
| 136 |
#ToDo: This implementation is incomplete. Kill ring doesn't store multiple |
| 137 |
# strings. |
| 138 |
def yank_from_kill_ring |
| 139 |
@kill_ring |
| 140 |
end |
| 141 |
|
| 142 |
#Main loop to catch all events. |
| 143 |
# |
| 144 |
#=== Warning |
| 145 |
#This method *SHOULD* be overrided in derived classes. |
| 146 |
def main_loop |
| 147 |
end |
| 148 |
|
| 149 |
#Exit the running main loop. |
| 150 |
# |
| 151 |
#=== Warning |
| 152 |
#This method *SHOULD* be overrided in derived classes. |
| 153 |
# |
| 154 |
#=== Note |
| 155 |
#Some UI systems (such as Ncurses) don't exit the main loop as |
| 156 |
#soon as this method is called. |
| 157 |
def exit_main_loop |
| 158 |
end |
| 159 |
|
| 160 |
#Beep once. |
| 161 |
# |
| 162 |
#=== Warning |
| 163 |
#This method *SHOULD* be overrided in derived classes. |
| 164 |
def beep |
| 165 |
false |
| 166 |
end |
| 167 |
|
| 168 |
#Terminate this view instance. |
| 169 |
# |
| 170 |
#=== Warning |
| 171 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 172 |
def terminate |
| 173 |
@windows.each{ |window| |
| 174 |
window.terminate |
| 175 |
} |
| 176 |
@mini_window.terminate |
| 177 |
|
| 178 |
terminate_ui |
| 179 |
end |
| 180 |
|
| 181 |
#Free system specifiec resources. |
| 182 |
# |
| 183 |
#=== Warning |
| 184 |
#This method *SHOULD* be overrided in derived classes. |
| 185 |
def terminate_ui |
| 186 |
end |
| 187 |
end |
| 188 |
end |