Class: Redcar::Scm::Manager
- Inherits:
-
Object
- Object
- Redcar::Scm::Manager
- Extended by:
- HasSPI
- Defined in:
- plugins/scm/lib/scm.rb
Class Method Summary (collapse)
-
+ (Object) debug
should we print debugging messages? this can get pretty verbose.
- + (Object) keymaps
- + (Object) menus
- + (Object) modules
-
+ (Object) modules_instance
Returns a list of instances of SCM modules.
- + (Object) modules_with_init
- + (Object) modules_with_remote_init
- + (Object) open_commit_tab(repo, change = nil)
- + (Object) prepare(project, repo)
- + (Object) project_closed(project, window)
- + (Object) project_context_menus(tree, node, controller)
- + (Object) project_loaded(project)
- + (Object) project_repositories
- + (Object) refresh_trees
- + (Object) sensitivities
Methods included from HasSPI
Class Method Details
+ (Object) debug
should we print debugging messages? this can get pretty verbose
79 80 81 |
# File 'plugins/scm/lib/scm.rb', line 79 def self.debug ARGV.include?('--debug') end |
+ (Object) keymaps
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'plugins/scm/lib/scm.rb', line 40 def self.keymaps osx = Keymap.build("main", :osx) do link "Cmd+Shift+C", Scm::CommitMirror::CommitChangesCommand link "Cmd+Shift+.", :command => Scm::CommitMirror::CommitChangesCommand, :value => [:commit, [Scm::ScmChangesMirror, Scm::ScmChangesController]] end linwin = Keymap.build("main", [:linux, :windows]) do link "Ctrl+Shift+C", Scm::CommitMirror::CommitChangesCommand end [linwin, osx] end |
+ (Object) menus
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'plugins/scm/lib/scm.rb', line 53 def self. Menu::Builder.build do "Project" do group(:priority => 10) do separator "Source Control" do Scm::Manager.modules_with_remote_init.sort {|a, b| a.repository_type <=> b.repository_type}.each do |m| item m.translations[:remote_init], :command => Scm::RemoteInitCommand, :value => m end separator item "Toggle Changes Tree", :command => Scm::ToggleScmTreeCommand, :value => [:commit, [Scm::ScmChangesMirror, Scm::ScmChangesController]] item "Toggle Commits Tree", :command => Scm::ToggleScmTreeCommand, :value => [:push, [Scm::ScmCommitsMirror, Scm::ScmCommitsController]] separator item "Create Commit", :command => Scm::CommitMirror::CreateCommitCommand item "Save Commit", :command => Scm::CommitMirror::CommitChangesCommand end end end end end |
+ (Object) modules
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'plugins/scm/lib/scm.rb', line 83 def self.modules @modules ||= begin mods = [] Redcar.log.debug "SCM Loading Redcar SCM modules..." Redcar.plugin_manager.objects_implementing(:scm_module).each do |i| Redcar.log.debug "SCM Found #{i.name}." object = i.scm_module if object.supported? mods.push(object) elsif debug Redcar.log.debug "SCM but discarding because it isn't supported on the current system." end end mods end end |
+ (Object) modules_instance
Returns a list of instances of SCM modules. This list has already been filtered for invalid modules.
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'plugins/scm/lib/scm.rb', line 105 def self.modules_instance modules.map {|m| mod = m.new begin assert_interface(mod, Redcar::Scm::Model) rescue RuntimeError => e Redcar.log.debug "SCM Skipping SCM module #{m.name} because it has an invalid interface." nil else mod end }.find_all {|m| not m.nil?} end |
+ (Object) modules_with_init
119 120 121 |
# File 'plugins/scm/lib/scm.rb', line 119 def self.modules_with_init modules_instance.find_all {|m| m.supported_commands.include? :init} end |
+ (Object) modules_with_remote_init
123 124 125 |
# File 'plugins/scm/lib/scm.rb', line 123 def self.modules_with_remote_init modules_instance.find_all {|m| m.supported_commands.include? :remote_init} end |
+ (Object) open_commit_tab(repo, change = nil)
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'plugins/scm/lib/scm.rb', line 266 def self.open_commit_tab(repo, change=nil) tab = Redcar.app.focussed_window.new_tab(Redcar::EditTab) edit_view = tab.edit_view mirror = Scm::CommitMirror.new(repo, change) edit_view.document.mirror = mirror edit_view.grammar = "Diff" tab.focus mirror.add_listener(:change) do tab.close project = Project::Manager.focussed_project repo_info = project_repositories[project] repo_info['trees'].each {|t| t.refresh} end end |
+ (Object) prepare(project, repo)
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'plugins/scm/lib/scm.rb', line 143 def self.prepare(project, repo) start = Time.now begin # associate this repository with a project internally project_repositories[project] = {'repo' => repo} repo.load(project.path) project_repositories[project]['trees'] = [] rescue # cleanup info = project_repositories.delete project Redcar.log.error "*** Error loading SCM: " + $!. puts $!.backtrace end Redcar.log.debug "SCM start took #{Time.now - start}s" end |
+ (Object) project_closed(project, window)
161 162 163 164 165 166 167 |
# File 'plugins/scm/lib/scm.rb', line 161 def self.project_closed(project,window) # disassociate this project with any repositories info = project_repositories.delete project return if info.nil? info['trees'].each {|t| window.treebook.remove_tree(t)} end |
+ (Object) project_context_menus(tree, node, controller)
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 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 259 260 261 262 263 264 |
# File 'plugins/scm/lib/scm.rb', line 176 def self.(tree, node, controller) # Search for the current project project = Project::Manager.in_window(Redcar.app.focussed_window) if project.nil? Redcar.log.debug "SCM Couldn't detect the project in the current window." end repo_info = project_repositories[project] init_modules = Redcar::Scm::Manager.modules_with_init Menu::Builder.build do if not project.nil? if repo_info.nil? and init_modules.length > 0 # no repository detected group :priority => 40 do separator "Create Repository From Project" do init_modules.sort {|a, b| a.repository_type <=> b.repository_type}.each do |m| item(m.translations[:init]) do m.init!(project.path) project.refresh Redcar::Scm::Manager.prepare(project, m) Application::Dialog.("Created a new " + m.repository_type.capitalize + " repository in the root of your project.") end end end end elsif repo_info group :priority => 40 do repo = repo_info['repo'] if repo.supported_commands.find {|i| [:switch_branch, :pull, :pull_targetted].include? i} separator end if repo.supported_commands.include?(:pull) item (repo.translations[:pull]) do repo.pull! # refresh tree views project.refresh repo_info['trees'].each {|t| t.refresh} end end if repo.supported_commands.include?(:pull_targetted) repo.translations[:pull_targetted] do repo.pull_targets.sort.each do |target| action = lambda do begin repo.pull!(target) # refresh tree views project.refresh repo_info['trees'].each {|t| t.refresh} rescue Redcar::Application::Dialog.($!.) puts $!.backtrace end end item target, &action end end end if repo.supported_commands.include?(:switch_branch) repo.translations[:switch_branch] do current = repo.current_branch repo.branches.sort.each do |branch| action = lambda { begin repo.switch!(branch) # refresh tree views project.refresh repo_info['trees'].each {|t| t.refresh} rescue Redcar::Application::Dialog.($!.) puts $!.backtrace end } item branch, :type => :radio, :checked => (branch == current), &action end end end end end end end end |
+ (Object) project_loaded(project)
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'plugins/scm/lib/scm.rb', line 127 def self.project_loaded(project) Redcar.log.debug "SCM #{modules.count} SCM modules loaded." repo = modules_instance.find do |m| Redcar.log.debug "SCM Checking if #{project.path} is a #{m.repository_type} repository..." m.repository?(project.path) end # quit if we can't find something to handle this project return if repo.nil? Redcar.log.debug "SCM Yes it is!" prepare(project, repo) end |
+ (Object) project_repositories
74 75 76 |
# File 'plugins/scm/lib/scm.rb', line 74 def self.project_repositories @project_repositories ||= {} end |
+ (Object) refresh_trees
169 170 171 172 173 174 |
# File 'plugins/scm/lib/scm.rb', line 169 def self.refresh_trees project_repositories.each do |project, info| project.refresh info['trees'].each {|t| t.refresh} end end |
+ (Object) sensitivities
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'plugins/scm/lib/scm.rb', line 25 def self.sensitivities [ Sensitivity.new(:open_commit_tab, Redcar.app, false, [:tab_focussed]) do |tab| tab and tab.is_a?(EditTab) and tab.edit_view.document.mirror.is_a?(Scm::CommitMirror) end, Sensitivity.new(:open_scm, Redcar.app, false, [:window_focussed,:tree_removed,:tree_added]) do |window| project = Project::Manager.focussed_project Scm::Manager.project_repositories[project] end ] end |