Class: Ruber::DocumentProject

Inherits:
AbstractProject show all
Defined in:
lib/ruber/document_project.rb

Defined Under Namespace

Classes: Backend

Instance Attribute Summary (collapse)

Attributes inherited from AbstractProject

project_file, project_name

Attributes included from SettingsContainer

dialog_title

Instance Method Summary (collapse)

Methods inherited from AbstractProject

#[]=, #add_extension, #close, #each_extension, #extension, #extensions, #finalize, #has_extension?, #method_missing, #query_close, #remove_extension, #save

Methods included from SettingsContainer

#[], #[]=, #add_setting, #add_widget, #collect_options, #default, #delete_dialog, #dialog, #has_setting?, #relative_path?, #remove_setting, #remove_widget, #setup_container

Constructor Details

- (DocumentProject) initialize(doc)

TODO:

in classes derived from Qt::Object, korundum executes the code in initialize,

Creates a new DocumentProject. doc is the document the project refers to. Note that, until doc becomes associated with a file, attempting to save the project will fail with an ArgumentError.

If the path of the file associated with the document changes (usually because of a “Save As” action), the file associated with the backend is changed automatically

up until the call to super twice. This means that two Backend items will be created. See if something can be done to avoid it. I don’t know whether this has any bad consequence or not.



137
138
139
140
141
142
143
# File 'lib/ruber/document_project.rb', line 137

def initialize doc
  @document = doc
  path = backend_file
  back = Backend.new path
  !File.exist?(back.file) ? super(doc, back, path) : super(doc, back)
  connect doc, SIGNAL('document_url_changed(QObject*)'), self, SLOT(:change_file)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ruber::AbstractProject

Instance Attribute Details

- (Object) document (readonly)

The document associated with the project



122
123
124
# File 'lib/ruber/document_project.rb', line 122

def document
  @document
end

Instance Method Details

- (Object) backend_file (private)



220
221
222
223
224
225
# File 'lib/ruber/document_project.rb', line 220

def backend_file
  if @document.has_file?
    @document.url.to_encoded(Qt::Url::RemoveUserInfo|Qt::Url::RemovePort|Qt::Url::RemoveFragment).to_s
  else ''
  end
end

- (Object) change_file (private)

Updates the backend so that the associated file reflects the file associated with the document.



216
217
218
# File 'lib/ruber/document_project.rb', line 216

def change_file
  @backend.document_path = backend_file
end

Slot Signature:

change_file()

- (Object) files

Override of AbstractProject#files which returns an array with the path of the associated document, if it corresponds to a file, and an empty array otherwise



200
201
202
203
204
205
206
207
208
# File 'lib/ruber/document_project.rb', line 200

def files
  url =  @document.url
  if url.local_file?
    path = url.path
  else 
    path = url.to_encoded(Qt::Url::RemoveUserInfo|Qt::Url::RemovePort|Qt::Url::RemoveFragment).to_s
  end
  path.empty? ? [] : [path] 
end

- (Boolean) match_rule?(obj)

Override of AbstractProject#match_rule? which also takes into account the mimetype and the file extension of the document and compares them with those in the rule. The comparison is made using Document#file_type_match?. This method returns true only if the Document#file_type_match? returns true and the rule’s scope includes :document

Returns:

  • (Boolean)


159
160
161
162
163
164
165
166
167
168
169
# File 'lib/ruber/document_project.rb', line 159

def match_rule? obj
  doc_place  = if !@document.path.empty?
    @document.url.local_file? ? :local : :remote
  else :local
  end
  if !super then false
  elsif !obj.place.include? doc_place then false
  elsif !@document.file_type_match? obj.mimetype, obj.file_extension then false
  else true
  end
end

- (Object) project_directory Also known as: project_dir

Override of AbstractProject#project_directory which returns the current directory if the document isn’t associated with a file.



172
173
174
175
# File 'lib/ruber/document_project.rb', line 172

def project_directory
  path = @document.path
  path.empty? ? Dir.pwd : File.dirname(path) 
end

- (Object) scope

Override of AbstractProject#scope which returns :document



148
149
150
# File 'lib/ruber/document_project.rb', line 148

def scope
  :document
end

- (Object) write

Override of AbstractProject#write which prevents a Errno::ENOENT exception to be raised by the backend if the document isn’t associated with a file. If the document is associated with a file, however, the exception will be raised as usual.

The reason for this kind of behaviour is that the backend is expected to raise the exception when the document isn’t associated with a file: it simply means that it doesn’t know where to write the data. If the document is associated with a file, however, this shouldn’t happen and the exception is then propagated because it truly means something is wrong.



189
190
191
192
193
194
# File 'lib/ruber/document_project.rb', line 189

def write
  begin super
  rescue Errno::ENOENT
    raise unless @document.path.empty?
  end
end