From f9a269ed995c4151678aef787573fe44657ed6dd Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 13 Oct 2015 19:11:55 -0600 Subject: [PATCH] Prompt about checking out head revision in TextEditor, not GitRepository This allows us not to inject confirm or ApplicationDelegate into Project, GitRepositoryProvider, and GitRepository. --- src/atom-environment.coffee | 2 +- src/git-repository-provider.coffee | 4 ++-- src/git-repository.coffee | 19 ++----------------- src/project.coffee | 4 ++-- src/text-editor.coffee | 22 +++++++++++++++++----- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index dbb144678..a53541940 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -168,7 +168,7 @@ class AtomEnvironment extends Model @clipboard = new Clipboard() Project = require './project' - @project = new Project({notificationManager: @notifications, packageManager: @packages, @confirm, @config}) + @project = new Project({notificationManager: @notifications, packageManager: @packages, @config}) CommandInstaller = require './command-installer' @commandInstaller = new CommandInstaller(@getVersion(), @applicationDelegate) diff --git a/src/git-repository-provider.coffee b/src/git-repository-provider.coffee index 1f2d2b776..593324d0c 100644 --- a/src/git-repository-provider.coffee +++ b/src/git-repository-provider.coffee @@ -48,7 +48,7 @@ isValidGitDirectorySync = (directory) -> module.exports = class GitRepositoryProvider - constructor: (@project, @config, @confirm) -> + constructor: (@project, @config) -> # Keys are real paths that end in `.git`. # Values are the corresponding GitRepository objects. @pathToRepository = {} @@ -75,7 +75,7 @@ class GitRepositoryProvider gitDirPath = gitDir.getPath() repo = @pathToRepository[gitDirPath] unless repo - repo = GitRepository.open(gitDirPath, {@project, @config, @confirm}) + repo = GitRepository.open(gitDirPath, {@project, @config}) return null unless repo repo.onDidDestroy(=> delete @pathToRepository[gitDirPath]) @pathToRepository[gitDirPath] = repo diff --git a/src/git-repository.coffee b/src/git-repository.coffee index e1ea58e44..1663f9ad4 100644 --- a/src/git-repository.coffee +++ b/src/git-repository.coffee @@ -80,7 +80,7 @@ class GitRepository for submodulePath, submoduleRepo of @repo.submodules submoduleRepo.upstream = {ahead: 0, behind: 0} - {@project, @config, @confirm, refreshOnWindowFocus} = options + {@project, @config, refreshOnWindowFocus} = options refreshOnWindowFocus ?= true if refreshOnWindowFocus @@ -443,25 +443,10 @@ class GitRepository # Subscribes to editor view event. checkoutHeadForEditor: (editor) -> - filePath = editor.getPath() - return unless filePath - - fileName = basename(filePath) - - checkoutHead = => + if filePath = editor.getPath() editor.buffer.reload() if editor.buffer.isModified() @checkoutHead(filePath) - if @config.get('editor.confirmCheckoutHeadRevision') - @confirm - message: 'Confirm Checkout HEAD Revision' - detailedMessage: "Are you sure you want to discard all changes to \"#{fileName}\" since the last Git commit?" - buttons: - OK: checkoutHead - Cancel: null - else - checkoutHead() - # Returns the corresponding {Repository} getRepo: (path) -> if @repo? diff --git a/src/project.coffee b/src/project.coffee index 645a54896..935e3a213 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -21,7 +21,7 @@ class Project extends Model Section: Construction and Destruction ### - constructor: ({@confirm, @notificationManager, packageManager, config}) -> + constructor: ({@notificationManager, packageManager, config}) -> @emitter = new Emitter @buffers = [] @paths = [] @@ -30,7 +30,7 @@ class Project extends Model @directoryProviders = [] @defaultDirectoryProvider = new DefaultDirectoryProvider() @repositoryPromisesByPath = new Map() - @repositoryProviders = [new GitRepositoryProvider(this, config, confirm)] + @repositoryProviders = [new GitRepositoryProvider(this, config)] @consumeServices(packageManager) destroyed: -> diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 875b437aa..5f5610dec 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -82,6 +82,7 @@ class TextEditor extends Model state.grammarRegistry = atomEnvironment.grammars state.project = atomEnvironment.project state.assert = atomEnvironment.assert.bind(atomEnvironment) + state.applicationDelegate = atomEnvironment.applicationDelegate new this(state) constructor: (params={}) -> @@ -91,7 +92,7 @@ class TextEditor extends Model @softTabs, @scrollRow, @scrollColumn, initialLine, initialColumn, tabLength, softWrapped, @displayBuffer, buffer, suppressCursorCreation, @mini, @placeholderText, lineNumberGutterVisible, largeFileMode, @config, @notificationManager, @packageManager, - @clipboard, @viewRegistry, @grammarRegistry, @project, @assert + @clipboard, @viewRegistry, @grammarRegistry, @project, @assert, @applicationDelegate } = params throw new Error("Must pass a config parameter when constructing TextEditors") unless @config? @@ -480,7 +481,7 @@ class TextEditor extends Model newEditor = new TextEditor({ @buffer, displayBuffer, @tabLength, softTabs, suppressCursorCreation: true, @config, @notificationManager, @packageManager, @clipboard, @viewRegistry, - @grammarRegistry, @project, @assert + @grammarRegistry, @project, @assert, @applicationDelegate }) for marker in @findMarkers(editorId: @id) marker.copy(editorId: newEditor.id, preserveFolds: true) @@ -642,9 +643,20 @@ class TextEditor extends Model checkoutHeadRevision: -> if filePath = this.getPath() - @project.repositoryForDirectory(new Directory(path.dirname(filePath))) - .then (repository) => - repository?.checkoutHeadForEditor(this) + checkoutHead = => + @project.repositoryForDirectory(new Directory(path.dirname(filePath))) + .then (repository) => + repository?.checkoutHeadForEditor(this) + + if @config.get('editor.confirmCheckoutHeadRevision') + @applicationDelegate.confirm + message: 'Confirm Checkout HEAD Revision' + detailedMessage: "Are you sure you want to discard all changes to \"#{path.basename(filePath)}\" since the last Git commit?" + buttons: + OK: checkoutHead + Cancel: null + else + checkoutHead() else Promise.resolve(false)