Class: JLDrill::ModifyVocabularyContext

Inherits:
Context::Context show all
Defined in:
lib/jldrill/contexts/ModifyVocabularyContext.rb

Defined Under Namespace

Classes: VocabularyView

Instance Attribute Summary

Attributes inherited from Context::Context

#mainView, #parent, #viewBridge

Instance Method Summary collapse

Methods inherited from Context::Context

#addView, #isEntered?, #onExit, #peekAtView, #setupViews

Constructor Details

#initialize(viewBridge) ⇒ ModifyVocabularyContext

Returns a new instance of ModifyVocabularyContext.



10
11
12
13
14
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 10

def initialize(viewBridge)
    super(viewBridge)
    @originalProblem = nil
    @actionName = ""
end

Instance Method Details

#closeObject

The close method is mostly just so that I have something that the tests can catch without screwing up the shutdown of the context.



119
120
121
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 119

def close
    self.exit
end

#createViewsObject



73
74
75
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 73

def createViews
    		@mainView = @viewBridge.VocabularyView.new(self, @actionName)
end

#destroyViewsObject



77
78
79
80
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 77

def destroyViews
    @mainView.destroy if !@mainView.nil?
    @mainView = nil
end

#dictionaryLoaded?Boolean

Returns:

  • (Boolean)


137
138
139
140
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 137

def dictionaryLoaded?
    !@parent.nil? && !@parent.reference.nil? &&
        @parent.reference.loaded?
end

#edictLoadUpdated(reference) ⇒ Object



163
164
165
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 163

def edictLoadUpdated(reference)
    @mainView.updateSearch unless @mainView.nil?
end

#enter(parent) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 82

def enter(parent)
    super(parent)
          if !@parent.nil?
              if !@parent.quiz.nil?
                  @parent.quiz.publisher.subscribe(self, "newProblem")
                  @parent.quiz.publisher.subscribe(self, "problemModified")
              end
              if !@parent.reference.nil?
                  @parent.reference.publisher.subscribe(self, "edictLoad")
              end
              @parent.longEventPublisher.subscribe(self, "startLongEvent")
              @parent.longEventPublisher.subscribe(self, "stopLongEvent")
              update(@parent.quiz.currentProblem)
          end
end

#exitObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 98

def exit
          if !@parent.nil?
              if !@parent.quiz.nil?
                  if !@originalProblem.nil?
                      @parent.quiz.setCurrentProblem(@originalProblem)
                  end
                  @parent.quiz.publisher.unsubscribe(self, "newProblem")
                  @parent.quiz.publisher.unsubscribe(self, "problemModified")
              end
              if !@parent.reference.nil?
                  @parent.reference.publisher.unsubscribe(self, "edictLoad")
              end
              @parent.longEventPublisher.unsubscribe(self, "startLongEvent")
              @parent.longEventPublisher.unsubscribe(self, "stopLongEvent")
          end
    super
end

#loadDictionaryObject



142
143
144
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 142

def loadDictionary
    @parent.loadReference unless @parent.nil?
end

#newProblemUpdated(problem) ⇒ Object



123
124
125
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 123

def newProblemUpdated(problem)
    update(problem)
end

#preview(item) ⇒ Object



175
176
177
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 175

def preview(item)
    @parent.previewItem(item)
end

#problemModifiedUpdated(problem) ⇒ Object



127
128
129
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 127

def problemModifiedUpdated(problem)
    update(problem)
end

#search(kanji, reading) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 146

def search(kanji, reading)
          retVal = []

    if dictionaryLoaded? 
              if !reading.nil? && !reading.empty?
                  retVal = @parent.reference.findReadingsStartingWith(reading).sort do |x,y|
                      x.reading <=> y.reading
                  end
              elsif !kanji.nil? && !kanji.empty?
                  retVal = @parent.reference.findKanjiStartingWith(kanji).sort do |x,y|
                      x.kanji <=> y.kanji
                  end
              end
    end
          return retVal
end

#startLongEventUpdated(source) ⇒ Object



167
168
169
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 167

def startLongEventUpdated(source)
    @mainView.showBusy(true)
end

#stopLongEventUpdated(source) ⇒ Object



171
172
173
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 171

def stopLongEventUpdated(source)
    @mainView.showBusy(false)
end

#update(problem) ⇒ Object



131
132
133
134
135
# File 'lib/jldrill/contexts/ModifyVocabularyContext.rb', line 131

def update(problem)
    if !problem.nil? && !problem.preview?
        @originalProblem = problem
    end
end