Class: JLDrill::MainContext
Defined Under Namespace
Classes: MainWindowView
Instance Attribute Summary collapse
#mainView, #parent, #viewBridge
Instance Method Summary
collapse
#addView, #isEntered?, #onExit, #peekAtView, #setupViews
Constructor Details
#initialize(viewBridge) ⇒ MainContext
Returns a new instance of MainContext.
Instance Attribute Details
#addNewVocabularyContext ⇒ Object
Returns the value of attribute addNewVocabularyContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def addNewVocabularyContext
@addNewVocabularyContext
end
|
#appendFileContext ⇒ Object
Returns the value of attribute appendFileContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def appendFileContext
@appendFileContext
end
|
#deinflect ⇒ Object
Returns the value of attribute deinflect.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def deinflect
@deinflect
end
|
#displayProblemContext ⇒ Object
Returns the value of attribute displayProblemContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def displayProblemContext
@displayProblemContext
end
|
#displayQuizStatusContext ⇒ Object
Returns the value of attribute displayQuizStatusContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def displayQuizStatusContext
@displayQuizStatusContext
end
|
#editVocabularyContext ⇒ Object
Returns the value of attribute editVocabularyContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def editVocabularyContext
@editVocabularyContext
end
|
#getFilenameContext ⇒ Object
Returns the value of attribute getFilenameContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def getFilenameContext
@getFilenameContext
end
|
#inTests ⇒ Object
Returns the value of attribute inTests.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def inTests
@inTests
end
|
#kana ⇒ Object
Returns the value of attribute kana.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def kana
@kana
end
|
#kanji ⇒ Object
Returns the value of attribute kanji.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def kanji
@kanji
end
|
#loadKanjiContext ⇒ Object
Returns the value of attribute loadKanjiContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def loadKanjiContext
@loadKanjiContext
end
|
#loadQuizContext ⇒ Object
Returns the value of attribute loadQuizContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def loadQuizContext
@loadQuizContext
end
|
#loadReferenceContext ⇒ Object
Returns the value of attribute loadReferenceContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def loadReferenceContext
@loadReferenceContext
end
|
#loadTanakaContext ⇒ Object
Returns the value of attribute loadTanakaContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def loadTanakaContext
@loadTanakaContext
end
|
#loadTatoebaContext ⇒ Object
Returns the value of attribute loadTatoebaContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def loadTatoebaContext
@loadTatoebaContext
end
|
#longEventPublisher ⇒ Object
Returns the value of attribute longEventPublisher.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def longEventPublisher
@longEventPublisher
end
|
#quiz ⇒ Object
Returns the value of attribute quiz.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def quiz
@quiz
end
|
#radicals ⇒ Object
Returns the value of attribute radicals.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def radicals
@radicals
end
|
#reference ⇒ Object
Returns the value of attribute reference.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def reference
@reference
end
|
#runCommandContext ⇒ Object
Returns the value of attribute runCommandContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def runCommandContext
@runCommandContext
end
|
#setOptionsContext ⇒ Object
Returns the value of attribute setOptionsContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def setOptionsContext
@setOptionsContext
end
|
#showAboutContext ⇒ Object
Returns the value of attribute showAboutContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def showAboutContext
@showAboutContext
end
|
#showAllVocabularyContext ⇒ Object
Returns the value of attribute showAllVocabularyContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def showAllVocabularyContext
@showAllVocabularyContext
end
|
#showExamplesContext ⇒ Object
Returns the value of attribute showExamplesContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def showExamplesContext
@showExamplesContext
end
|
#showInfoContext ⇒ Object
Returns the value of attribute showInfoContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def showInfoContext
@showInfoContext
end
|
#showStatisticsContext ⇒ Object
Returns the value of attribute showStatisticsContext.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def showStatisticsContext
@showStatisticsContext
end
|
#tanaka ⇒ Object
Returns the value of attribute tanaka.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def tanaka
@tanaka
end
|
#tatoebaDB ⇒ Object
Returns the value of attribute tatoebaDB.
40
41
42
|
# File 'lib/jldrill/contexts/MainContext.rb', line 40
def tatoebaDB
@tatoebaDB
end
|
Instance Method Details
#addNewVocabulary ⇒ Object
314
315
316
|
# File 'lib/jldrill/contexts/MainContext.rb', line 314
def addNewVocabulary
@addNewVocabularyContext.enter(self) unless @addNewVocabularyContext.isEntered?
end
|
#appendFile ⇒ Object
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/jldrill/contexts/MainContext.rb', line 189
def appendFile
if !@appendFileContext.isEntered?
@appendFileContext.onExit do
if quiz.currentProblem.nil?
quiz.drill
end
end
@appendFileContext.enter(self, @quiz)
end
end
|
#correct ⇒ Object
393
394
395
396
397
398
|
# File 'lib/jldrill/contexts/MainContext.rb', line 393
def correct
if !@quiz.currentProblem.nil? && !@quiz.currentProblem.displayOnly?
@quiz.correct
@quiz.drill
end
end
|
#createNew ⇒ Object
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/jldrill/contexts/MainContext.rb', line 217
def createNew
promptForSaveAnd do
@quiz.reset
@quiz.options.subscribe(self)
optionsUpdated(@quiz.options)
@quiz.setNeedsSave(false)
@quiz.updateLoad
end
end
|
#createViews ⇒ Object
115
116
117
118
|
# File 'lib/jldrill/contexts/MainContext.rb', line 115
def createViews
@mainWindowView = @viewBridge.MainWindowView.new(self)
@mainView = @mainWindowView
end
|
#deleteItem(item) ⇒ Object
370
371
372
373
374
375
|
# File 'lib/jldrill/contexts/MainContext.rb', line 370
def deleteItem(item)
if !item.nil?
displayItem(item)
deleteVocabulary
end
end
|
#deleteVocabulary ⇒ Object
327
328
329
330
331
332
333
334
335
336
337
338
339
|
# File 'lib/jldrill/contexts/MainContext.rb', line 327
def deleteVocabulary
if !@quiz.currentProblem.nil? &&
!@quiz.currentProblem.preview?
showAnswer
prompt = PromptForDeleteContext.new(@viewBridge)
if prompt.enter(self) == prompt.yes
item = @quiz.currentProblem.item
@quiz.deleteItem(item)
drill
end
end
end
|
#destroyViews ⇒ Object
120
121
122
123
124
|
# File 'lib/jldrill/contexts/MainContext.rb', line 120
def destroyViews
@mainWindowView.destroy unless @mainWindowView.nil?
@mainWindowView = nil
@mainView = nil
end
|
#displayItem(item) ⇒ Object
Display the problem if it isn’t the current one
342
343
344
345
346
347
348
349
350
|
# File 'lib/jldrill/contexts/MainContext.rb', line 342
def displayItem(item)
if !item.nil?
if @quiz.currentProblem.nil? ||
!@quiz.currentProblem.item.eql?(item)
@quiz.displayProblem(item)
showAnswer
end
end
end
|
#drill ⇒ Object
Get a new problem in the drill without answering the current problem
389
390
391
|
# File 'lib/jldrill/contexts/MainContext.rb', line 389
def drill
@quiz.drill
end
|
#editItem(item) ⇒ Object
363
364
365
366
367
368
|
# File 'lib/jldrill/contexts/MainContext.rb', line 363
def editItem(item)
if !item.nil?
displayItem(item)
editVocabulary
end
end
|
#editVocabulary ⇒ Object
318
319
320
321
322
323
324
325
|
# File 'lib/jldrill/contexts/MainContext.rb', line 318
def editVocabulary
if !@quiz.currentProblem.nil? &&
!@quiz.currentProblem.preview?
showAnswer
@editVocabularyContext.enter(self) unless @editVocabularyContext.isEntered?
end
end
|
#enter(parent) ⇒ Object
132
133
134
135
136
137
138
139
140
|
# File 'lib/jldrill/contexts/MainContext.rb', line 132
def enter(parent)
super(parent)
@runCommandContext.enter(self)
@displayProblemContext.enter(self)
@displayQuizStatusContext.enter(self)
parseCommandLineOptions
@quiz.options.subscribe(self)
loadKanji unless @inTests
end
|
#exampleDB ⇒ Object
249
250
251
252
253
254
255
|
# File 'lib/jldrill/contexts/MainContext.rb', line 249
def exampleDB
if @tanaka.loaded?
return @tanaka
else
return @tatoebaDB
end
end
|
#exit ⇒ Object
142
143
144
145
146
147
148
149
|
# File 'lib/jldrill/contexts/MainContext.rb', line 142
def exit
@runCommandContext.exit
@displayQuizStatusContext.exit
@displayProblemContext.exit
@quiz.options.unsubscribe(self)
@parent.exit
super
end
|
#incorrect ⇒ Object
400
401
402
403
404
405
|
# File 'lib/jldrill/contexts/MainContext.rb', line 400
def incorrect
if !@quiz.currentProblem.nil? && !@quiz.currentProblem.displayOnly?
@quiz.incorrect
@quiz.drill
end
end
|
#learn ⇒ Object
407
408
409
410
411
412
|
# File 'lib/jldrill/contexts/MainContext.rb', line 407
def learn
if !@quiz.currentProblem.nil? && !@quiz.currentProblem.displayOnly?
@quiz.learn
@quiz.drill
end
end
|
#loadExamples ⇒ Object
291
292
293
|
# File 'lib/jldrill/contexts/MainContext.rb', line 291
def loadExamples
loadTatoeba
end
|
#loadKanji ⇒ Object
296
297
298
299
300
|
# File 'lib/jldrill/contexts/MainContext.rb', line 296
def loadKanji
if !@loadKanjiContext.isEntered?
@loadKanjiContext.enter(self, @kanji, @radicals, @kana)
end
end
|
#loadReference ⇒ Object
242
243
244
245
246
247
|
# File 'lib/jldrill/contexts/MainContext.rb', line 242
def loadReference
if !@loadReferenceContext.isEntered?
@loadReferenceContext.enter(self, @reference, @deinflect,
@quiz.options)
end
end
|
#loadTanaka ⇒ Object
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/jldrill/contexts/MainContext.rb', line 257
def loadTanaka
if @tanaka.loaded?
if !@showExamplesContext.isEntered?
@showExamplesContext.enter(self)
end
else
if !@loadTanakaContext.isEntered?
@loadTanakaContext.onExit do
@showExamplesContext.enter(self)
end
@loadTanakaContext.enter(self, @tanaka, @quiz.options)
end
end
end
|
#loadTatoeba ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/jldrill/contexts/MainContext.rb', line 272
def loadTatoeba
if @tatoebaDB.loaded?(@quiz.options)
if !@showExamplesContext.isEntered?
@showExamplesContext.enter(self)
end
else
if !@loadTatoebaContext.isEntered?
@loadTatoebaContext.onExit do
if !@showExamplesContext.isEntered?
@showExamplesContext.enter(self)
else
@showExamplesContext.newProblemUpdated(@quiz.currentProblem)
end
end
@loadTatoebaContext.enter(self, @tatoebaDB)
end
end
end
|
#open ⇒ Object
230
231
232
233
234
|
# File 'lib/jldrill/contexts/MainContext.rb', line 230
def open
promptForSaveAnd do
openFile
end
end
|
#openFile(filename = nil) ⇒ Object
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/jldrill/contexts/MainContext.rb', line 178
def openFile(filename = nil)
if !@loadQuizContext.isEntered?
@loadQuizContext.onExit do
@quiz.options.subscribe(self)
optionsUpdated(@quiz.options)
@quiz.drill
end
@loadQuizContext.enter(self, @quiz, filename)
end
end
|
#optionsUpdated(options) ⇒ Object
151
152
153
154
155
|
# File 'lib/jldrill/contexts/MainContext.rb', line 151
def optionsUpdated(options)
if options.autoloadDic
loadReference
end
end
|
#parseCommandLineOptions ⇒ Object
126
127
128
129
130
|
# File 'lib/jldrill/contexts/MainContext.rb', line 126
def parseCommandLineOptions
if ARGV.size == 1
openFile(ARGV[0])
end
end
|
#previewItem(item) ⇒ Object
Preview an item that doesn’t currently exist in the quiz
353
354
355
356
357
358
359
360
361
|
# File 'lib/jldrill/contexts/MainContext.rb', line 353
def previewItem(item)
if !item.nil?
if @quiz.currentProblem.nil? ||
!@quiz.currentProblem.item.eql?(item)
@quiz.previewProblem(item)
showAnswer
end
end
end
|
#promptForSaveAnd(&block) ⇒ Object
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/jldrill/contexts/MainContext.rb', line 200
def promptForSaveAnd(&block)
if @quiz.needsSave?
promptForSave = PromptForSaveContext.new(@viewBridge)
result = promptForSave.enter(self)
if result == promptForSave.yes
save
block.call
elsif result == promptForSave.no
block.call
else
end
else
block.call
end
end
|
#quit ⇒ Object
236
237
238
239
240
|
# File 'lib/jldrill/contexts/MainContext.rb', line 236
def quit
promptForSaveAnd do
exit
end
end
|
#removeDups ⇒ Object
414
415
416
417
418
|
# File 'lib/jldrill/contexts/MainContext.rb', line 414
def removeDups
if !quiz.nil?
@quiz.contents.removeDuplicates
end
end
|
#reset ⇒ Object
420
421
422
|
# File 'lib/jldrill/contexts/MainContext.rb', line 420
def reset
@quiz.resetContents
end
|
#save ⇒ Object
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/jldrill/contexts/MainContext.rb', line 157
def save
if @quiz.file.empty?
saveAs
else
if !@quiz.save
print "Error: Can't save. Try again.\n"
saveAs
end
end
end
|
#saveAs ⇒ Object
168
169
170
171
172
173
174
175
176
|
# File 'lib/jldrill/contexts/MainContext.rb', line 168
def saveAs
filename = @getFilenameContext.enter(self, GetFilenameContext::SAVE)
if !filename.nil?
@quiz.file = filename
while !@quiz.save
print "Error: Can't save. Try again.\n"
end
end
end
|
#setOptions ⇒ Object
302
303
304
|
# File 'lib/jldrill/contexts/MainContext.rb', line 302
def setOptions
@setOptionsContext.enter(self) unless @setOptionsContext.isEntered?
end
|
#setReviewMode(bool) ⇒ Object
310
311
312
|
# File 'lib/jldrill/contexts/MainContext.rb', line 310
def setReviewMode(bool)
@quiz.options.reviewMode = bool unless @quiz.nil?
end
|
#showAbout ⇒ Object
436
437
438
|
# File 'lib/jldrill/contexts/MainContext.rb', line 436
def showAbout
@showAboutContext.enter(self) unless @showAboutContext.isEntered?
end
|
#showAcknowlegements ⇒ Object
428
429
430
|
# File 'lib/jldrill/contexts/MainContext.rb', line 428
def showAcknowlegements
@showInfoContext.enter(self, Acknowlegements) unless @showInfoContext.isEntered?
end
|
#showAllVocabulary ⇒ Object
432
433
434
|
# File 'lib/jldrill/contexts/MainContext.rb', line 432
def showAllVocabulary
@showAllVocabularyContext.enter(self) unless @showAllVocabularyContext.isEntered?
end
|
#showAnswer ⇒ Object
381
382
383
384
385
386
|
# File 'lib/jldrill/contexts/MainContext.rb', line 381
def showAnswer
if !@quiz.currentProblem.nil?
@displayProblemContext.showAnswer if @displayProblemContext.isEntered?
@showExamplesContext.showAnswer if @showExamplesContext.isEntered?
end
end
|
#showQuizInfo ⇒ Object
424
425
426
|
# File 'lib/jldrill/contexts/MainContext.rb', line 424
def showQuizInfo
@showInfoContext.enter(self, @quiz.info) unless @showInfoContext.isEntered?
end
|
#showStatistics ⇒ Object
306
307
308
|
# File 'lib/jldrill/contexts/MainContext.rb', line 306
def showStatistics
@showStatisticsContext.enter(self) unless @showStatisticsContext.isEntered?
end
|
#startLongEvent ⇒ Object
440
441
442
443
|
# File 'lib/jldrill/contexts/MainContext.rb', line 440
def startLongEvent()
@mainView.showBusy(true)
@longEventPublisher.update("startLongEvent")
end
|
#stopLongEvent ⇒ Object
445
446
447
448
|
# File 'lib/jldrill/contexts/MainContext.rb', line 445
def stopLongEvent()
@mainView.showBusy(false)
@longEventPublisher.update("stopLongEvent")
end
|
#updateQuizStatus ⇒ Object
377
378
379
|
# File 'lib/jldrill/contexts/MainContext.rb', line 377
def updateQuizStatus
@displayQuizStatusContext.quizUpdated(@quiz) if @displayQuizStatusContext.isEntered?
end
|