| 1 |
# modeline.rb: the module definition of Edmaru::ModeLine |
| 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 "modeline_element.rb" |
| 21 |
|
| 22 |
module Edmaru |
| 23 |
|
| 24 |
module ModeLine |
| 25 |
|
| 26 |
#Construct the modeline instance. |
| 27 |
# |
| 28 |
#=== Arguments |
| 29 |
#_view_ :: The parent window. |
| 30 |
#_config_ :: An instance of Edmaru::ConfigurationManager. |
| 31 |
# |
| 32 |
#=== Warning |
| 33 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 34 |
# |
| 35 |
#=== Return |
| 36 |
#An initialized instance of ModeLine. |
| 37 |
def initialize(window, config) |
| 38 |
@window = window |
| 39 |
@elements = Hash.new |
| 40 |
@elements_order = Array.new |
| 41 |
@config = config |
| 42 |
|
| 43 |
init_ui |
| 44 |
end |
| 45 |
|
| 46 |
#The system specific initialization for ModeLine. |
| 47 |
# |
| 48 |
#=== Warning |
| 49 |
#This method *SHOULD* be overrided in derived classes. |
| 50 |
def init_ui |
| 51 |
end |
| 52 |
|
| 53 |
#Add the specified _element_, an instance of ModeLineElement, to |
| 54 |
#this ModeLine. |
| 55 |
# |
| 56 |
#=== Argument |
| 57 |
#_element_ :: an instance of ModeLineElement to be added. |
| 58 |
# |
| 59 |
#=== Warning |
| 60 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 61 |
# |
| 62 |
#=== Return |
| 63 |
#_true_ if the addition is succeeded. |
| 64 |
#_false_ if the _element_'s name has already reserved. |
| 65 |
def add_element(element) |
| 66 |
if @elements.include?(element.name) |
| 67 |
return false |
| 68 |
end |
| 69 |
|
| 70 |
@elements[element.name] = element |
| 71 |
@elements_order.push(element.name) |
| 72 |
end |
| 73 |
|
| 74 |
#Show the specified element. |
| 75 |
# |
| 76 |
#=== Argument |
| 77 |
#_name_ :: the name of the element. |
| 78 |
# |
| 79 |
#=== Warning |
| 80 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 81 |
def show_element(name) |
| 82 |
if !@elements.include?(name) || @elements[name].visible? |
| 83 |
return |
| 84 |
end |
| 85 |
|
| 86 |
@elements[name].visible = true |
| 87 |
refresh |
| 88 |
end |
| 89 |
|
| 90 |
#Hide the specified element. |
| 91 |
# |
| 92 |
#=== Argument |
| 93 |
#_name_ :: the name of the element. |
| 94 |
# |
| 95 |
#=== Warning |
| 96 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 97 |
def hide_element(name) |
| 98 |
if !@elements.include?(name) || !@elements[name].visible? |
| 99 |
return |
| 100 |
end |
| 101 |
|
| 102 |
@elements[name].visible = false |
| 103 |
refresh |
| 104 |
end |
| 105 |
|
| 106 |
#Set the text of the specified element. |
| 107 |
# |
| 108 |
#=== Warning |
| 109 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 110 |
# |
| 111 |
#=== Argument |
| 112 |
#_name_ :: the name of this element |
| 113 |
#_text_ :: a new text to be set as the text of the specified element. |
| 114 |
def set_element_text(name, text) |
| 115 |
if !@elements.include?(name) || @elements[name].text == text |
| 116 |
return |
| 117 |
end |
| 118 |
|
| 119 |
@elements[name].text = text |
| 120 |
refresh |
| 121 |
end |
| 122 |
|
| 123 |
|
| 124 |
#Get the specified element. |
| 125 |
# |
| 126 |
#=== Warning |
| 127 |
#This method *MUST* *NOT* be overrided in derived classes. |
| 128 |
# |
| 129 |
#=== Argument |
| 130 |
#_name_ :: the name of the element. |
| 131 |
# |
| 132 |
#=== Return |
| 133 |
#An instance of ModeLineElement whose name is the specified name |
| 134 |
#or _nil_ if the specified name is not registered. |
| 135 |
def get_element(name) |
| 136 |
if !@elements.include?(name) |
| 137 |
return nil |
| 138 |
end |
| 139 |
|
| 140 |
@elements[name] |
| 141 |
end |
| 142 |
|
| 143 |
#Redraws this modeline. |
| 144 |
# |
| 145 |
#=== Warning |
| 146 |
#This method *SHOULD* be overrided in derived classes. |
| 147 |
def refresh |
| 148 |
end |
| 149 |
|
| 150 |
#Terminate this modeline instance. |
| 151 |
# |
| 152 |
#=== Warning |
| 153 |
#This method *SHOULD* be overrided in derived classes. |
| 154 |
def terminate |
| 155 |
end |
| 156 |
end |
| 157 |
end |