Class: Ruber::World::World
- Includes:
- PluginLike
- Defined in:
- lib/ruber/world/world.rb
Defined Under Namespace
Classes: ExistingProjectFileError
Instance Attribute Summary collapse
-
#active_document ⇒ Object
readonly
Returns the value of attribute active_document.
-
#active_environment ⇒ Object
Returns the value of attribute active_environment.
-
#default_environment ⇒ Object
readonly
Returns the value of attribute default_environment.
Attributes included from PluginLike
Instance Method Summary collapse
- #active_project ⇒ Object
- #active_project=(prj) ⇒ Object
- #close_all(what, save_behaviour = :save) ⇒ Object
-
#document(file) ⇒ Document?
The document associated with the given file or URL.
- #documents ⇒ Object
- #each_document ⇒ Object
- #each_environment ⇒ Object
- #each_project ⇒ Object
- #environment(prj) ⇒ Object
- #environments ⇒ Object
-
#initialize(_, psf) ⇒ World
constructor
A new instance of World.
-
#new_document ⇒ Document
Creates a new document.
-
#new_project(file, name) ⇒ Project
Creates a new project.
-
#project(file) ⇒ Project
Retrieves the project associated with a given project file.
- #projects ⇒ Object
- #query_close ⇒ Object
- #save_settings ⇒ Object
Methods included from PluginLike
#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #plugin_name, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #session_data, #shutdown, #unload, #update_project
Constructor Details
#initialize(_, psf) ⇒ World
Returns a new instance of World.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruber/world/world.rb', line 76 def initialize _, psf super Ruber[:app] @documents = MutableDocumentList.new [] @projects = MutableProjectList.new [] @environments = {} initialize_plugin psf @active_environment = nil @active_document = nil @document_factory = DocumentFactory.new self connect @document_factory, SIGNAL('document_created(QObject*)'), self, SLOT('slot_document_created(QObject*)') @project_factory = ProjectFactory.new self connect @project_factory, SIGNAL('project_created(QObject*)'), self, SLOT('slot_project_created(QObject*)') @default_environment = Environment.new(nil, self) add_environment @default_environment, nil end |
Instance Attribute Details
#active_document ⇒ Object (readonly)
Returns the value of attribute active_document.
48 49 50 |
# File 'lib/ruber/world/world.rb', line 48 def active_document @active_document end |
#active_environment ⇒ Object
Returns the value of attribute active_environment.
46 47 48 |
# File 'lib/ruber/world/world.rb', line 46 def active_environment @active_environment end |
#default_environment ⇒ Object (readonly)
Returns the value of attribute default_environment.
44 45 46 |
# File 'lib/ruber/world/world.rb', line 44 def default_environment @default_environment end |
Instance Method Details
#active_project ⇒ Object
134 135 136 |
# File 'lib/ruber/world/world.rb', line 134 def active_project @active_environment.project if @active_environment end |
#active_project=(prj) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/ruber/world/world.rb', line 124 def active_project= prj old = @active_environment.project if @active_environment return old if old == prj old.deactivate if old self.active_environment = @environments[prj] emit active_project_changed prj emit active_project_changed_2 prj, old prj.activate if prj end |
#close_all(what, save_behaviour = :save) ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/ruber/world/world.rb', line 216 def close_all what, save_behaviour = :save close_docs = (what == :all || what == :documents) close_prjs = (what == :all || what == :projects) save = save_behaviour == :save @projects.dup.each{|prj| prj.close save} if close_prjs @documents.dup.each{|doc| doc.close save} if close_docs end |
#document(file) ⇒ Document?
The document associated with the given file or URL
If a document for the given file or URL already exists, that document will be returned, otherwise a new one will be created.
file to retrieve the document for
170 171 172 |
# File 'lib/ruber/world/world.rb', line 170 def document file @document_factory.document file, self end |
#documents ⇒ Object
174 175 176 |
# File 'lib/ruber/world/world.rb', line 174 def documents DocumentList.new @documents end |
#each_document ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/ruber/world/world.rb', line 178 def each_document if block_given? @documents.each{|doc| yield doc} self else self.to_enum :each_document end end |
#each_environment ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/ruber/world/world.rb', line 116 def each_environment if block_given? @environments.each_value{|e| yield e} self else to_enum(:each_environment) end end |
#each_project ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/ruber/world/world.rb', line 142 def each_project if block_given? @environments.each_key{|prj| yield prj if prj} self else self.to_enum(:each_project) end end |
#environment(prj) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/ruber/world/world.rb', line 92 def environment prj @environments[prj] # unless env # env = Environment.new(prj) # connect env, SIGNAL('closing(QObject*)'), self, SLOT('environment_closing(QObject*)') # connect env, SIGNAL('active_editor_changed(QWidget*)'), self, SLOT('slot_active_editor_changed(QWidget*)') # @environments[prj] = env # end end |
#environments ⇒ Object
112 113 114 |
# File 'lib/ruber/world/world.rb', line 112 def environments @environments.values end |
#new_document ⇒ Document
Creates a new document
154 155 156 157 |
# File 'lib/ruber/world/world.rb', line 154 def new_document doc = @document_factory.document nil, self doc end |
#new_project(file, name) ⇒ Project
Creates a new project
195 196 197 198 |
# File 'lib/ruber/world/world.rb', line 195 def new_project file, name raise ExistingProjectFileError, "#{file} already exists" if File.exist?(file) @project_factory.project file, name end |
#project(file) ⇒ Project
Retrieves the project associated with a given project file
If a project associated with the project file file already exists, that project is returned. Otherwise, a new project object is created.
212 213 214 |
# File 'lib/ruber/world/world.rb', line 212 def project file @project_factory.project file end |
#projects ⇒ Object
138 139 140 |
# File 'lib/ruber/world/world.rb', line 138 def projects ProjectList.new @environments.keys.compact end |
#query_close ⇒ Object
229 230 231 232 233 234 |
# File 'lib/ruber/world/world.rb', line 229 def query_close @documents.each{|doc| return false unless doc.own_project.query_close} return false unless Ruber[:main_window].save_documents @documents.to_a @projects.each{|prj| return false unless prj.query_close} true end |
#save_settings ⇒ Object
224 225 226 227 |
# File 'lib/ruber/world/world.rb', line 224 def save_settings @documents.each{|doc| doc.save_settings} @projects.each{|prj| prj.save} end |