Class: KeepYourHead::WindowEdit
- Inherits:
-
Object
- Object
- KeepYourHead::WindowEdit
- Defined in:
- lib/Keepyourhead/gui/WindowEdit.rb,
lib/Keepyourhead/gui/WindowEditActions.rb
Defined Under Namespace
Classes: LazyUpdate
Constant Summary collapse
- Widgets =
[ "treeview_flashcards", "image_front", "image_back", "entryNameFlashcard", "entryTypeFlashcard", "entryNameTopic", "entryNameCollection", "entryOriginAuthor", "entryOriginType", "entryOriginDate", "textviewLatexHeader", "textviewLatexPrepend", "textviewLatexAppend", "notebookContent", "hboxFront", "hscaleFront", "hboxBack", "hscaleBack", "labelFileCount", "labelFileDistribution", "labelCollectionCount", "labelCollectionDistribution", ]
- MapNameToClass =
{ "flashcard" => Database::Flashcard, "topic" => Database::Topic, "collection" => Database::Collection, }
- AcceptStrict =
{ Database::Database => [Database::File], Database::File => [Database::Collection], Database::Collection => [Database::Topic, Database::Flashcard], Database::Topic => [Database::Topic, Database::Flashcard], Database::Flashcard => [] }
- Actions =
[ [ "New", proc { true } ], [ "Open", proc { true } ], [ "Save", proc { |obj| obj.selected && [Database::File, Database::Collection, Database::Topic,Database::Flashcard].include?(obj.selected.class) && obj.selected.file.changed } ], [ "SaveAs", proc { |obj| obj.selected && [Database::File, Database::Collection, Database::Topic,Database::Flashcard].include?(obj.selected.class) } ], [ "SaveAll", proc { |obj| true } ], [ "Close", proc { |obj| obj.selected && [Database::File, Database::Collection, Database::Topic,Database::Flashcard].include?(obj.selected.class) } ], [ "Paste", proc { |obj| text = Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).wait_for_text dom = REXML::Document.new text node = dom.root node && canInsertInterpreted( obj.selected, node.name ) } ], [ "Copy", proc { |obj| obj.selected && [Database::Collection, Database::Topic,Database::Flashcard].include?(obj.selected.class) } ], [ "Cut", proc { |obj| obj.selected && [Database::Collection, Database::Topic,Database::Flashcard].include?(obj.selected.class) } ], [ "AddTopic", proc { |obj| obj.selected && canInsertInterpreted( obj.selected, Database::Topic) }], [ "AddFlashcard", proc { |obj| obj.selected && canInsertInterpreted( obj.selected, Database::Flashcard) }], [ "AddCollection", proc { |obj| obj.selected && canInsertInterpreted( obj.selected, Database::Collection) }], [ "Delete", proc { |obj| obj.selected && [Database::Collection, Database::Topic, Database::Flashcard].include?(obj.selected.class) }], [ "Left", proc { |obj| if obj.selected then parent = MyAdaptor.parent(obj.selected) if parent then parent2 = MyAdaptor.parent(parent) if parent2 then return canInsertStrict( parent2, obj.selected.class) end end end false }], [ "Right", proc { |obj| if obj.selected then parent = MyAdaptor.nextSibling(obj.selected) if parent then return canInsertStrict( parent, obj.selected.class) end end false }], [ "Up", proc { |obj| if obj.selected && [Database::File, Database::Collection, Database::Topic, Database::Flashcard].include?(obj.selected.class) then other = MyAdaptor.previousSibling obj.selected if other then return true end end false }], [ "Down", proc { |obj| if obj.selected && [Database::File, Database::Collection, Database::Topic, Database::Flashcard].include?(obj.selected.class) then other = MyAdaptor.nextSibling obj.selected if other then return true end end false }], [ "Train", proc { |obj| true }], [ "About", proc { |obj| true }], [ "RemoveStatistics", proc { |obj| obj.selected && [Database::File, Database::Collection, Database::Topic, Database::Flashcard].include?(obj.selected.class) }], [ "Quit", proc { |obj| true }], ]
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#selected ⇒ Object
readonly
Returns the value of attribute selected.
-
#widget ⇒ Object
readonly
Returns the value of attribute widget.
Class Method Summary collapse
- .canInsertInterpreted(parent, other) ⇒ Object
- .canInsertStrict(parent, other) ⇒ Object
- .insertInterpretedAfter(parent, node, after) ⇒ Object
- .insertStrictAfter(parent, node, after) ⇒ Object
Instance Method Summary collapse
- #actionAfter ⇒ Object
- #actionBefore ⇒ Object
-
#addTreeModelItemAfter(model, item, parentIter = nil, previousIter = nil) ⇒ Object
insert a whole subtree.
- #build_tree_model ⇒ Object
- #callAction(name, *args) ⇒ Object
- #filePrepareToClose(file) ⇒ Object
- #fileSave(file) ⇒ Object
- #fileSaveAs(file) ⇒ Object
- #helper(obj, baseMethod) ⇒ Object
- #helperRead(obj, baseMethod) ⇒ Object
- #helperWrite(obj, baseMethod) ⇒ Object
- #initActions ⇒ Object
-
#initialize(database) ⇒ WindowEdit
constructor
A new instance of WindowEdit.
- #on_treeview_flashcards_cursor_changed ⇒ Object
- #on_window_edit_delete_event ⇒ Object
- #on_window_edit_destroy ⇒ Object
- #onActionAbout ⇒ Object
- #onActionAddCollection ⇒ Object
- #onActionAddFlashcard ⇒ Object
- #onActionAddTopic ⇒ Object
- #onActionClose ⇒ Object
- #onActionCopy ⇒ Object
- #onActionCut ⇒ Object
- #onActionDelete ⇒ Object
- #onActionDown ⇒ Object
- #onActionLeft ⇒ Object
- #onActionNew ⇒ Object
- #onActionOpen ⇒ Object
- #onActionPaste ⇒ Object
- #onActionQuit ⇒ Object
- #onActionRemoveStatistics ⇒ Object
- #onActionRight ⇒ Object
- #onActionSave ⇒ Object
- #onActionSaveAll ⇒ Object
- #onActionSaveAs ⇒ Object
- #onActionTrain ⇒ Object
- #onActionUp ⇒ Object
- #onContentChange ⇒ Object
- #onEditBack ⇒ Object
- #onEditFront ⇒ Object
- #onEditLatexAppend ⇒ Object
- #onEditLatexHeader ⇒ Object
- #onEditLatexPrepend ⇒ Object
-
#onItemChange(item) ⇒ Object
Interface for implementing Database::Visitor class Database::Visitor.
- #onItemInsert(item) ⇒ Object
- #onItemRemove(item) ⇒ Object
- #onReload ⇒ Object
- #updateImages ⇒ Object
- #updateView ⇒ Object
- #visibleFields ⇒ Object
Constructor Details
#initialize(database) ⇒ WindowEdit
Returns a new instance of WindowEdit.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 129 def initialize(database) @disableUpdateView = nil @glade = GladeXML.new(Resources::system("glade/WindowEdit.glade")) { |handler| method(handler) } @pixbufs = { Database::File => "gtk-file", Database::Collection => "gnome-stock-book-green", Database::Topic => "gtk-directory", Database::Flashcard => "gnome-stock-attach", } @pixbufs.keys.each { |k| iconFactory = Gtk::IconFactory.lookup_default @pixbufs[k] @pixbufs[k] = iconFactory.render_icon Gtk::Style.new, Gtk::Widget::TEXT_DIR_NONE, Gtk::STATE_NORMAL, Gtk::IconSize::MENU, nil, nil } # a bit complicated because Gnome Stock items are not directly supported @window = @glade.("window_edit") @widget = @window Widgets.each { |name| = @glade.(name) assert eval("@#{name} = widget") } @lazyUpdate = LazyUpdate.new( self ) renderer = Gtk::CellRendererText.new renderer.xalign = 0.0 # col_offset = @treeview_flashcards.insert_column(-1, "Name", # renderer, # 'text' => 0) column = Gtk::TreeViewColumn.new( "Name" ) renderer = Gtk::CellRendererPixbuf.new column.pack_start renderer, false # column.add_attribute renderer, "stock-id", 2 column.add_attribute renderer, "pixbuf", 2 renderer = Gtk::CellRendererText.new column.pack_start renderer, true column.add_attribute renderer, "text", 0 @treeview_flashcards.insert_column( column, -1 ) @flashcardViewControllerFront = FlashcardViewController.new @image_front, @hscaleFront, @hboxFront @flashcardViewControllerBack = FlashcardViewController.new @image_back, @hscaleBack, @hboxBack initActions self.database = database @window.show updateView end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
21 22 23 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 21 def database @database end |
#selected ⇒ Object (readonly)
Returns the value of attribute selected.
22 23 24 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 22 def selected @selected end |
#widget ⇒ Object (readonly)
Returns the value of attribute widget.
23 24 25 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 23 def @widget end |
Class Method Details
.canInsertInterpreted(parent, other) ⇒ Object
80 81 82 83 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 80 def self.canInsertInterpreted( parent, other ) return false unless parent and other canInsertStrict( parent, other ) or ( MyAdaptor.parent(parent) and canInsertInterpreted( MyAdaptor.parent(parent), other ) ) end |
.canInsertStrict(parent, other) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 60 def self.canInsertStrict(parent, other) return false unless parent and other type = case other when String MapNameToClass[other.downcase] when REXML::Element MapNameToClass[other.name.downcase] when Class other else throw ExceptionNotImplemented.new end assert AcceptStrict[parent.class] AcceptStrict[parent.class].include? type end |
.insertInterpretedAfter(parent, node, after) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 92 def self.insertInterpretedAfter( parent, node, after ) assert node assert node.kind_of?(REXML::Element) assert canInsertInterpreted( parent, node.name) if canInsertStrict( parent, node ) then insertStrictAfter( parent, node, after ) else assert MyAdaptor.parent(parent) insertInterpretedAfter( MyAdaptor.parent(parent), node, parent ) end end |
.insertStrictAfter(parent, node, after) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 85 def self.insertStrictAfter( parent, node, after ) assert node assert node.kind_of?(REXML::Element) assert canInsertStrict( parent, node.name ) MyAdaptor.insertAfter( parent, node, after ) end |
Instance Method Details
#actionAfter ⇒ Object
210 211 212 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 210 def actionAfter updateView end |
#actionBefore ⇒ Object
208 209 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 208 def actionBefore end |
#addTreeModelItemAfter(model, item, parentIter = nil, previousIter = nil) ⇒ Object
insert a whole subtree
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 83 def addTreeModelItemAfter( model, item, parentIter = nil, previousIter = nil ) iter = model.insert_after(parentIter,previousIter) iter.set_value( 0, MyAdaptor.name(item) ) iter.set_value( 1, item ) iter.set_value( 2, @pixbufs[item.class] ) @mapIterItem[iter] = item @mapItemIter[item] = iter lastChild = nil MyAdaptor.children(item).each{ |childItem| lastChild = addTreeModelItemAfter(model, childItem, iter, lastChild) } iter end |
#build_tree_model ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 100 def build_tree_model model = Gtk::TreeStore.new(String, Object, Gdk::Pixbuf) @mapIterItem = {} @mapItemIter = {} lastChild = nil MyAdaptor.children(self.database).each{ |childItem| lastChild = addTreeModelItemAfter(model, childItem, nil, lastChild) } if self.database @treeview_flashcards.model = model @treeview_flashcards. end |
#callAction(name, *args) ⇒ Object
42 43 44 45 46 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 42 def callAction(name, *args) assert @actions[name.to_s] and @actions[name.to_s].executeable? @actions[name.to_s].activate( *args ) end |
#filePrepareToClose(file) ⇒ Object
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 288 def filePrepareToClose( file ) if file.changed then dialog = Gtk::MessageDialog.new( @window, Gtk::Dialog::MODAL, Gtk::MessageDialog::WARNING, Gtk::MessageDialog::BUTTONS_NONE, "Save changes ?" ) dialog.( "Ja", Gtk::Dialog::RESPONSE_YES ) dialog.( "Nein", Gtk::Dialog::RESPONSE_NO ) dialog.( "Abbrechen", Gtk::Dialog::RESPONSE_CANCEL ) response = dialog.run dialog.destroy case response when Gtk::Dialog::RESPONSE_YES fileSave file not file.changed when Gtk::Dialog::RESPONSE_NO true when Gtk::Dialog::RESPONSE_CANCEL, Gtk::Dialog::RESPONSE_DELETE_EVENT false else false end else true end end |
#fileSave(file) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 281 def fileSave(file) if file.filename then file.save else fileSaveAs file end end |
#fileSaveAs(file) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 249 def fileSaveAs(file) dialog = Gtk::FileChooserDialog.new("Save File", @window, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]) # dialog.current_folder = ::File.expand_path "~" filter = Gtk::FileFilter.new filter.name = "Flashcards (*.xfc)" filter.add_pattern "*.xfc" dialog.add_filter( filter ) filter = Gtk::FileFilter.new filter.name = "all" filter.add_pattern "*" dialog.add_filter( filter ) dialog.current_name = "unnamed.xfc" response = dialog.run filename = dialog.filename dialog.destroy if response == Gtk::Dialog::RESPONSE_ACCEPT file.saveAs filename true else false end end |
#helper(obj, baseMethod) ⇒ Object
213 214 215 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 213 def helper( obj, baseMethod ) [ obj.method( baseMethod ), obj.method( (baseMethod.to_s+"=").to_sym) ] end |
#helperRead(obj, baseMethod) ⇒ Object
207 208 209 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 207 def helperRead( obj, baseMethod ) [ obj.method( baseMethod ), nil ] end |
#helperWrite(obj, baseMethod) ⇒ Object
210 211 212 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 210 def helperWrite( obj, baseMethod ) [ nil, obj.method( (baseMethod.to_s+"=").to_sym) ] end |
#initActions ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 21 def initActions @actions = {} Actions.each { |name, procExecuteable| action = Action.new self, name action.procExecuteable = procExecuteable name2 = name.gsub( /[A-Z]/ ) { |s| "_" + s.downcase }[1..-1] = @glade.("menuitem_#{name2}") toolButton = @glade.("toolbutton_#{name2}") # print "not found menuItem for #{name2}" unless menuItem # print "not found toolButton for #{name2}" unless toolButton action.addActivator if action.addActivator toolButton if toolButton @actions[name] = action } end |
#on_treeview_flashcards_cursor_changed ⇒ Object
398 399 400 401 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 398 def on_treeview_flashcards_cursor_changed # onContentChange updateView end |
#on_window_edit_delete_event ⇒ Object
189 190 191 192 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 189 def on_window_edit_delete_event callAction("Quit") @window.destroy if self.database != nil end |
#on_window_edit_destroy ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 194 def on_window_edit_destroy self.database = nil @treeview_flashcards, @image_front, @image_back = nil, nil, nil @actions.values.each { |a| a..each { |w| a.removeActivator w } } $application.quit end |
#onActionAbout ⇒ Object
411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 411 def onActionAbout # aboutDialog = Gtk::AboutDialog.new Gtk::AboutDialog.show @window, { # :artists => nil, :authors => [Project::AUTHOR_WITH_EMAIL], :comments => Project::SUMMARY, :copyright => Project::COPYRIGHT, :license => Project::LICENSE, :name => Project::NAME, :version => Project::VERSION, :website => Project::HOMEPAGE, "program-name" => Project::NAME, } end |
#onActionAddCollection ⇒ Object
358 359 360 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 358 def onActionAddCollection self.class.insertInterpretedAfter self.selected, Database::Collection.createNode(self.selected.file), MyAdaptor.lastChild(self.selected) end |
#onActionAddFlashcard ⇒ Object
355 356 357 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 355 def onActionAddFlashcard self.class.insertInterpretedAfter self.selected, Database::Flashcard.createNode(self.selected.file), MyAdaptor.lastChild(self.selected) end |
#onActionAddTopic ⇒ Object
352 353 354 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 352 def onActionAddTopic self.class.insertInterpretedAfter self.selected, Database::Topic.createNode(self.selected.file), MyAdaptor.lastChild(self.selected) end |
#onActionClose ⇒ Object
325 326 327 328 329 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 325 def onActionClose if filePrepareToClose( self.selected.file ) then database.fileClose self.selected.file end end |
#onActionCopy ⇒ Object
346 347 348 349 350 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 346 def onActionCopy text = "" REXML::Formatters::Default.new.write @selected.node, text Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).text = text end |
#onActionCut ⇒ Object
339 340 341 342 343 344 345 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 339 def onActionCut text = "" REXML::Formatters::Default.new.write @selected.node, text Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).text = text MyAdaptor.remove self.selected end |
#onActionDelete ⇒ Object
361 362 363 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 361 def onActionDelete MyAdaptor.remove self.selected end |
#onActionDown ⇒ Object
388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 388 def onActionDown if @selected.class == Database::File then database.moveDown @selected else parent = MyAdaptor.parent @selected other = MyAdaptor.nextSibling @selected node = MyAdaptor.remove @selected MyAdaptor.insertAfter parent, node, other end end |
#onActionLeft ⇒ Object
364 365 366 367 368 369 370 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 364 def onActionLeft parent = MyAdaptor.parent(self.selected) parent2 = MyAdaptor.parent(parent) other = MyAdaptor.previousSibling( parent ) node = MyAdaptor.remove( self.selected ) self.class.insertStrictAfter( parent2, node, other) end |
#onActionNew ⇒ Object
214 215 216 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 214 def onActionNew self.database.fileNew end |
#onActionOpen ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 217 def onActionOpen dialog = Gtk::FileChooserDialog.new("Open File", @window, Gtk::FileChooser::ACTION_OPEN, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT]) # dialog.current_folder = ::File.expand_path "~" filter = Gtk::FileFilter.new filter.name = "Flashcards (*.xfc)" filter.add_pattern "*.xfc" dialog.add_filter( filter ) filter = Gtk::FileFilter.new filter.name = "all" filter.add_pattern "*" dialog.add_filter( filter ) if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT filename = ::File. dialog.filename self.database.fileOpen( filename ) end dialog.destroy end |
#onActionPaste ⇒ Object
331 332 333 334 335 336 337 338 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 331 def onActionPaste Gtk::Clipboard.get(Gdk::Selection::CLIPBOARD).request_text{ |clipboard, text| dom = REXML::Document.new text node = dom.root self.class.insertInterpretedAfter self.selected, node, MyAdaptor.lastChild(self.selected) } end |
#onActionQuit ⇒ Object
428 429 430 431 432 433 434 435 436 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 428 def onActionQuit ret = true database.files.inject(true) { |ret, file| ret &&= filePrepareToClose( file ) } @window.destroy if ret end |
#onActionRemoveStatistics ⇒ Object
425 426 427 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 425 def onActionRemoveStatistics @selected.removeStatistics end |
#onActionRight ⇒ Object
371 372 373 374 375 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 371 def onActionRight parent = MyAdaptor.nextSibling(self.selected) node = MyAdaptor.remove( self.selected ) self.class.insertStrictAfter( parent, node, nil) end |
#onActionSave ⇒ Object
319 320 321 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 319 def onActionSave fileSave self.selected.file end |
#onActionSaveAll ⇒ Object
243 244 245 246 247 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 243 def onActionSaveAll database.files.each { |file| fileSave file if file.changed } end |
#onActionSaveAs ⇒ Object
322 323 324 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 322 def onActionSaveAs fileSaveAs self.selected.file end |
#onActionTrain ⇒ Object
399 400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 399 def onActionTrain dialog = DialogQuestionStart.new if dialog.run then max_questions, max_minutes = dialog.max_questions, dialog.max_minutes dialog.destroy training = FlashcardTraining.new(database, max_questions, max_minutes * 60) WindowQuestion.new(self, training) else dialog.destroy end end |
#onActionUp ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/Keepyourhead/gui/WindowEditActions.rb', line 376 def onActionUp if @selected.class == Database::File then database.moveUp @selected else parent = MyAdaptor.parent @selected other = MyAdaptor.previousSibling @selected other = MyAdaptor.previousSibling other node = MyAdaptor.remove @selected MyAdaptor.insertAfter parent, node, other end end |
#onContentChange ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 382 def onContentChange return if @disableOnContentChange @disableOnContentChange = true visibleFields.each{ |readView, writeView, readData, writeData| if writeData and readView then if not readData or readView.call != readData.call then writeData.call readView.call end end } updateView @disableOnContentChange = false end |
#onEditBack ⇒ Object
446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 446 def onEditBack if @selected && @selected.class == Database::Flashcard then dialog = DialogEditFlashcardLatex.new @selected, Database::BACK dialog.text = @selected.back if dialog.run then @selected.back = dialog.text end dialog.destroy end end |
#onEditFront ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 434 def onEditFront if @selected && @selected.class == Database::Flashcard then dialog = DialogEditFlashcardLatex.new @selected, Database::FRONT dialog.text = @selected.front if dialog.run then @selected.front = dialog.text end dialog.destroy end end |
#onEditLatexAppend ⇒ Object
423 424 425 426 427 428 429 430 431 432 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 423 def onEditLatexAppend if @selected && @selected.class == Database::Collection then dialog = DialogEditText.new( "Anhang" ) dialog.text = @selected.latexAppend if dialog.run then @selected.latexAppend = dialog.text end dialog.destroy end end |
#onEditLatexHeader ⇒ Object
403 404 405 406 407 408 409 410 411 412 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 403 def onEditLatexHeader if @selected && @selected.class == Database::Collection then dialog = DialogEditText.new( "Header" ) dialog.text = @selected.latexHeader if dialog.run then @selected.latexHeader = dialog.text end dialog.destroy end end |
#onEditLatexPrepend ⇒ Object
413 414 415 416 417 418 419 420 421 422 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 413 def onEditLatexPrepend if @selected && @selected.class == Database::Collection then dialog = DialogEditText.new( "Vorspann" ) dialog.text = @selected.latexPrepend if dialog.run then @selected.latexPrepend = dialog.text end dialog.destroy end end |
#onItemChange(item) ⇒ Object
Interface for implementing Database::Visitor class Database::Visitor
27 28 29 30 31 32 33 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 27 def onItemChange(item) iter = @mapItemIter[item] if iter then # can be called before item is added with onItemAdd iter.set_value( 0, MyAdaptor.name(item) ) updateView end end |
#onItemInsert(item) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 48 def onItemInsert(item) previous = MyAdaptor.previousSibling(item) parent = MyAdaptor.parent(item) previousIter = previous ? @mapItemIter[previous] : nil parentIter = @mapItemIter[parent] addTreeModelItemAfter( @treeview_flashcards.model, item, parentIter, previousIter) iter = @mapItemIter[item] if parentIter then @treeview_flashcards.(parentIter.path, true) else @treeview_flashcards.(iter.path, true) end if @selectedRealization == MyAdaptor.realization( item ) then @treeview_flashcards.selection.select_iter iter end end |
#onItemRemove(item) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 34 def onItemRemove(item) @selectedRealization = MyAdaptor.realization( item ) @selected = nil if @selected == item iter = @mapItemIter[item] assert iter @mapItemIter[item] = nil @mapIterItem[iter] = nil model = @treeview_flashcards.model model.remove iter end |
#onReload ⇒ Object
68 69 70 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 68 def onReload build_tree_model end |
#updateImages ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 260 def updateImages( ) @lastFilenames ||= {} [Database::FRONT, Database::BACK].each{ |type| $cache.hasCacheItem( self.selected, type ) { |cacheItem| filenames = Images.fromCacheItem( type, cacheItem ) case type when Database::FRONT @flashcardViewControllerFront.filenames = filenames when Database::BACK @flashcardViewControllerBack.filenames = filenames end } } end |
#updateView ⇒ Object
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 336 def updateView return unless @treeview_flashcards return if @disableUpdateView @disableUpdateView = true @disableOnContentChange = true # unterdrücke change events während view update @lastSelected = selected iter = @treeview_flashcards && @treeview_flashcards.selection && @treeview_flashcards.selection.selected @selected = iter && iter[1] visibleFields.each{ |readView, writeView, readData, writeData| if writeView and readData then if not readView or readView.call != readData.call then writeView.call readData.call end end } if @selected then case @selected when Database::File @notebookContent.page = 1 when Database::Collection @notebookContent.page = 2 when Database::Topic @notebookContent.page = 3 when Database::Flashcard @notebookContent.page = 4 updateImages @lazyUpdate.restart else throw ExceptionNotSupported.new end else @notebookContent.page = 0 end @actions.values.each { |a| a.updateEnable } @disableOnContentChange = false @disableUpdateView = false end |
#visibleFields ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/Keepyourhead/gui/WindowEdit.rb', line 217 def visibleFields fields = [] if @selected then fields += case @selected when Database::File [ [ helperWrite(@labelFileCount,:text), proc{ "#{@selected.count} ( #{@selected.countActive} / #{@selected.countPassive} )" }, nil ].flatten, [ helperWrite(@labelFileDistribution,:text), proc{ "#{d = @selected.distribution; d[d.length+3] = 0; d = d.map{ |v| v || 0 }; d.join(" | ")}" }, nil ].flatten, ] when Database::Collection [ [ helperWrite(@labelCollectionCount,:text), proc{ "#{@selected.count} ( #{@selected.countActive} / #{@selected.countPassive} )" }, nil ].flatten, [ helperWrite(@labelCollectionDistribution,:text), proc{ "#{d = @selected.distribution; d[d.length+3] = 0; d = d.map{ |v| v || 0 }; d.join(" | ")}" }, nil ].flatten, [ helper(@entryNameCollection,:text), helper(@selected,:name) ].flatten, [ helper(@entryOriginAuthor,:text), helper(@selected,:originAuthor) ].flatten, [ helper(@entryOriginType,:text), helper(@selected,:originType) ].flatten, [ helper(@entryOriginDate,:text), helper(@selected,:originDate) ].flatten, [ helper(@textviewLatexHeader.buffer,:text), helper(@selected,:latexHeader) ].flatten, [ helper(@textviewLatexPrepend.buffer,:text), helper(@selected,:latexPrepend) ].flatten, [ helper(@textviewLatexAppend.buffer,:text), helper(@selected,:latexAppend) ].flatten, ] when Database::Topic [ [ helper(@entryNameTopic,:text), helper(@selected,:name) ].flatten, ] when Database::Flashcard [ [ helper(@entryNameFlashcard,:text), helper(@selected,:name) ].flatten, [ helper(@entryTypeFlashcard,:text), helper(@selected,:type) ].flatten, ] else throw ExceptionNotImplemented.new end end fields end |