Class: Ruber::World::DocumentFactory
- Inherits:
-
Qt::Object
- Object
- Qt::Object
- Ruber::World::DocumentFactory
- Defined in:
- lib/ruber/world/document_factory.rb
Overview
in the documentation, whenever a file name is mentioned, it can be replaced
by a KDE::Url
.
Factory class to create documents
It ensures that at all times there’s only a single document associated with a given file.
Instance Method Summary (collapse)
-
- (Ruber::Document) create_document(file, parent)
private
Creates a new document.
-
- (Document?) document(file, parent = nil)
Returns a document, creating it if needed.
-
- (Object) document_closed(doc)
slot
private
Slot called whenever a document is closed.
-
- (Object) document_url_changed(doc)
slot
private
Slot called whenever a document’s URL changes.
-
- (DocumentFactory) initialize(parent = nil)
constructor
A new instance of DocumentFactory.
Signal Summary
Constructor Details
- (DocumentFactory) initialize(parent = nil)
A new instance of DocumentFactory
43 44 45 46 |
# File 'lib/ruber/world/document_factory.rb', line 43 def initialize parent = nil super @documents = {} end |
Instance Method Details
- (Ruber::Document) create_document(file, parent) (private)
Creates a new document
After creating the document, makes all the necessary signal-slot connections with it and adds it to the internal document list if needed
108 109 110 111 112 113 114 115 |
# File 'lib/ruber/world/document_factory.rb', line 108 def create_document file, parent doc = Document.new file, parent @documents[doc.url] = doc if file connect doc, SIGNAL('closing(QObject*)'), self, SLOT('document_closed(QObject*)') connect doc, SIGNAL('document_url_changed(QObject*)'), self, SLOT('document_url_changed(QObject*)') emit document_created(doc) doc end |
- (Document?) document(file, parent = nil)
Returns a document, creating it if needed
If a file name is specified, a document for that file will be returned. If a document for that file name already exists, it will be returned. Otherwise, a new document will be created.
If no file or URL is given, a new document (not associated with a file) is returned.
65 66 67 68 69 70 71 72 73 |
# File 'lib/ruber/world/document_factory.rb', line 65 def document file, parent = nil if file url = KDE::Url.new file return if url.local_file? and !File.exist?(url.path) doc = @documents[url] doc || create_document(file, parent) else create_document nil, parent end end |
- (Object) document_closed(doc) (private)
Slot called whenever a document is closed
It ensures that the document is removed from the internal document list
83 84 85 |
# File 'lib/ruber/world/document_factory.rb', line 83 def document_closed doc @documents.delete doc.url end |
Slot Signature:
document_closed(QObject*)
- (Object) document_url_changed(doc) (private)
Slot called whenever a document’s URL changes
It updates the internal list of documents
94 95 96 97 |
# File 'lib/ruber/world/document_factory.rb', line 94 def document_url_changed doc @documents.reject!{|k, v| v == doc} @documents[doc.url] = doc end |
Slot Signature:
document_url_changed(QObject*)
Signal Details
- document_created(QObject* arg1)