Class: KeepYourHead::AdaptorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/Keepyourhead/gui/WindowEditAdapters.rb

Constant Summary collapse

Adaptors =
{
	Database::Database => AdaptorDatabase.new,
	Database::File => AdaptorFile.new,
	Database::Collection => AdaptorCollection.new,
	Database::Topic => AdaptorTopic.new,
	Database::Flashcard => AdaptorFlashcard.new,
}

Instance Method Summary collapse

Instance Method Details

#children(parent) ⇒ Object



289
290
291
292
293
294
295
296
297
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 289

def children(parent)
	children = []
	c = firstChild(parent)
	while c do
		children << c
		c = nextSibling(c)
	end
	children
end

#createChild(parent) ⇒ Object



260
261
262
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 260

def createChild(parent)
	Adaptors[object.class].createChild object
end

#firstChild(object) ⇒ Object



250
251
252
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 250

def firstChild(object)
	Adaptors[object.class].firstChild object
end

#insertAfter(parent, item, other) ⇒ Object



263
264
265
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 263

def insertAfter(parent,item,other)
	Adaptors[parent.class].insertAfter parent, item, other
end

#insertLast(parent, item) ⇒ Object

for better use



276
277
278
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 276

def insertLast(parent, item)
	insertAfter(parent, item, lastChild(parent) )
end

#lastChild(parent) ⇒ Object



279
280
281
282
283
284
285
286
287
288
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 279

def lastChild(parent)
	c = firstChild(parent)

	return nil unless c

	while o = nextSibling(c)
		c = o
	end
	c
end

#moveDown(item) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 312

def moveDown(item)
	if item.class == Database::File then
		item.database.moveDown item
	else
		parent = self.parent item
		other = self.nextSibling item

		node = self.remove item
		self.insertAfter parent, node, other
	end
end

#moveUp(item) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 300

def moveUp(item)
	if item.class == Database::File then
		item.database.moveUp item
	else
		parent = self.parent item
		other = self.previousSibling item
		other = self.previousSibling other

		node = self.remove item
		self.insertAfter parent, node, other
	end
end

#name(object) ⇒ Object



243
244
245
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 243

def name(object)
	Adaptors[object.class].name object
end

#nextSibling(object) ⇒ Object



253
254
255
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 253

def nextSibling(object)
	Adaptors[object.class].nextSibling object
end

#parent(object) ⇒ Object



247
248
249
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 247

def parent(object)
	Adaptors[object.class].parent object
end

#previousSibling(object) ⇒ Object



256
257
258
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 256

def previousSibling(object)
	Adaptors[object.class].previousSibling object
end

#realization(object) ⇒ Object



270
271
272
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 270

def realization(object)
	Adaptors[object.class].realization object
end

#remove(object) ⇒ Object



266
267
268
# File 'lib/Keepyourhead/gui/WindowEditAdapters.rb', line 266

def remove(object)
	Adaptors[object.class].remove object
end