From 599ad57b5e249eff7a2ce909df7609becd27df8b Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Mon, 1 Oct 2018 19:24:47 +0300 Subject: [PATCH] git: cleanup - make class inner --- .../src/git4idea/rebase/GitRewordAction.kt | 158 +++++++++--------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt b/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt index 369aa3022f7e..418d2ab78b25 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt +++ b/plugins/git4idea/src/git4idea/rebase/GitRewordAction.kt @@ -69,90 +69,90 @@ class GitRewordAction : GitCommitEditingAction() { } override fun getFailureTitle(): String = "Couldn't Reword Commit" -} -private fun getCommitDataFromCache(data: VcsLogData, commit: VcsShortCommitDetails): VcsCommitMetadata? { - val commitIndex = data.getCommitIndex(commit.id, commit.root) - val commitData = data.commitDetailsGetter.getCommitDataIfAvailable(commitIndex) - if (commitData != null) return commitData + private fun getCommitDataFromCache(data: VcsLogData, commit: VcsShortCommitDetails): VcsCommitMetadata? { + val commitIndex = data.getCommitIndex(commit.id, commit.root) + val commitData = data.commitDetailsGetter.getCommitDataIfAvailable(commitIndex) + if (commitData != null) return commitData - val message = data.index.dataGetter?.getFullMessage(commitIndex) - if (message != null) return VcsCommitMetadataImpl(commit.id, commit.parents, commit.commitTime, commit.root, commit.subject, - commit.author, message, commit.committer, commit.authorTime) - return null -} - -private fun loadCommitData(project: Project, data: VcsLogData, commit: VcsShortCommitDetails): VcsCommitMetadata? { - var commitData: VcsCommitMetadata? = null - ProgressManager.getInstance().runProcessWithProgressSynchronously( - { - try { - commitData = VcsLogUtil.getDetails(data, commit.root, commit.id) - } - catch (e: VcsException) { - val error = "Couldn't load changes of " + commit.id.asString() - LOG.warn(error, e) - val notification = VcsNotifier.STANDARD_NOTIFICATION.createNotification( - "", error, NotificationType.ERROR, null) - VcsNotifier.getInstance(project).notify(notification) - } - }, "Loading Commit Message", true, project) - return commitData -} - -private fun rewordInBackground(project: Project, commit: VcsCommitMetadata, repository: GitRepository, newMessage: String) { - object : Task.Backgroundable(project, "Rewording") { - override fun run(indicator: ProgressIndicator) { - GitRewordOperation(repository, commit, newMessage).execute() - } - }.queue() -} - -private class RewordDialog(val project: Project, val commit: VcsCommitMetadata, val repository: GitRepository) - : DialogWrapper(project, true) { - - val originalHEAD = repository.info.currentRevision - val commitEditor = createCommitEditor() - - init { - init() - isModal = false - title = "Reword Commit" - } - - override fun createCenterPanel() = - JBUI.Panels.simplePanel(DEFAULT_HGAP, DEFAULT_VGAP) - .addToTop(JBLabel("Edit message for commit ${commit.id.toShortString()} by ${getShortPresentation(commit.author)}")) - .addToCenter(commitEditor) - - override fun getPreferredFocusedComponent() = commitEditor.editorField - - override fun getDimensionServiceKey() = "GitRewordDialog" - - private fun createCommitEditor(): CommitMessage { - val editor = CommitMessage(project, false, false, true) - editor.setText(commit.fullMessage) - editor.editorField.setCaretPosition(0) - editor.editorField.addSettingsProvider { editor -> - // display at least several rows for one-line messages - val MIN_ROWS = 3 - if ((editor as EditorImpl).visibleLineCount < MIN_ROWS) { - verticalStretch = 1.5F - } - } - return editor - } - - override fun doValidate(): ValidationInfo? { - if (repository.info.currentRevision != originalHEAD) { - return ValidationInfo("Can't reword commit: repository state was changed") - } + val message = data.index.dataGetter?.getFullMessage(commitIndex) + if (message != null) return VcsCommitMetadataImpl(commit.id, commit.parents, commit.commitTime, commit.root, commit.subject, + commit.author, message, commit.committer, commit.authorTime) return null } - override fun doOKAction() { - super.doOKAction() + private fun loadCommitData(project: Project, data: VcsLogData, commit: VcsShortCommitDetails): VcsCommitMetadata? { + var commitData: VcsCommitMetadata? = null + ProgressManager.getInstance().runProcessWithProgressSynchronously( + { + try { + commitData = VcsLogUtil.getDetails(data, commit.root, commit.id) + } + catch (e: VcsException) { + val error = "Couldn't load changes of " + commit.id.asString() + LOG.warn(error, e) + val notification = VcsNotifier.STANDARD_NOTIFICATION.createNotification( + "", error, NotificationType.ERROR, null) + VcsNotifier.getInstance(project).notify(notification) + } + }, "Loading Commit Message", true, project) + return commitData + } - rewordInBackground(project, commit, repository, commitEditor.comment) + private fun rewordInBackground(project: Project, commit: VcsCommitMetadata, repository: GitRepository, newMessage: String) { + object : Task.Backgroundable(project, "Rewording") { + override fun run(indicator: ProgressIndicator) { + GitRewordOperation(repository, commit, newMessage).execute() + } + }.queue() + } + + private inner class RewordDialog(val project: Project, val commit: VcsCommitMetadata, val repository: GitRepository) + : DialogWrapper(project, true) { + + val originalHEAD = repository.info.currentRevision + val commitEditor = createCommitEditor() + + init { + init() + isModal = false + title = "Reword Commit" + } + + override fun createCenterPanel() = + JBUI.Panels.simplePanel(DEFAULT_HGAP, DEFAULT_VGAP) + .addToTop(JBLabel("Edit message for commit ${commit.id.toShortString()} by ${getShortPresentation(commit.author)}")) + .addToCenter(commitEditor) + + override fun getPreferredFocusedComponent() = commitEditor.editorField + + override fun getDimensionServiceKey() = "GitRewordDialog" + + private fun createCommitEditor(): CommitMessage { + val editor = CommitMessage(project, false, false, true) + editor.setText(commit.fullMessage) + editor.editorField.setCaretPosition(0) + editor.editorField.addSettingsProvider { editor -> + // display at least several rows for one-line messages + val MIN_ROWS = 3 + if ((editor as EditorImpl).visibleLineCount < MIN_ROWS) { + verticalStretch = 1.5F + } + } + return editor + } + + override fun doValidate(): ValidationInfo? { + if (repository.info.currentRevision != originalHEAD) { + return ValidationInfo("Can't reword commit: repository state was changed") + } + return null + } + + override fun doOKAction() { + super.doOKAction() + + rewordInBackground(project, commit, repository, commitEditor.comment) + } } } \ No newline at end of file