diff --git a/plugins/settings-repository/resources/messages/IcsBundle.properties b/plugins/settings-repository/resources/messages/IcsBundle.properties index a93360103a11..d96c2cc7bc89 100644 --- a/plugins/settings-repository/resources/messages/IcsBundle.properties +++ b/plugins/settings-repository/resources/messages/IcsBundle.properties @@ -13,8 +13,8 @@ ics.settings=Settings Repository action.CommitToIcs.text=Commit to Settings Repository -init.dialog.message=Repository not exists, would you like to init it here? -init.dialog.title=Init Repository +init.dialog.message=There is no Settings Repository in the {0}, would you like to create a new one in this location? +init.dialog.title=Create Settings Repository specify.absolute.path.dialog.message=Please specify absolute path diff --git a/plugins/settings-repository/src/RepositoryService.kt b/plugins/settings-repository/src/RepositoryService.kt index 17ab3f6f2be1..debdf31c56c9 100644 --- a/plugins/settings-repository/src/RepositoryService.kt +++ b/plugins/settings-repository/src/RepositoryService.kt @@ -15,6 +15,8 @@ */ package org.jetbrains.settingsRepository +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.MessageDialogBuilder import com.intellij.openapi.ui.Messages import com.intellij.util.exists import com.intellij.util.io.URLUtil @@ -22,13 +24,12 @@ import com.intellij.util.isDirectory import org.eclipse.jgit.lib.Constants import org.eclipse.jgit.transport.URIish import org.jetbrains.settingsRepository.git.createBareRepository -import java.awt.Container import java.io.IOException import java.nio.file.Path import java.nio.file.Paths interface RepositoryService { - fun checkUrl(uriString: String, messageParent: Container? = null): Boolean { + fun checkUrl(uriString: String, suggestToCreate: Boolean, project: Project? = null): Boolean { val uri = URIish(uriString) val isFile: Boolean if (uri.scheme == URLUtil.FILE_PROTOCOL) { @@ -38,19 +39,19 @@ interface RepositoryService { isFile = uri.scheme == null && uri.host == null } - if (messageParent != null && isFile && !checkFileRepo(uriString, messageParent)) { + if (isFile && !checkFileRepo(uriString, project)) { return false } return true } - fun checkFileRepo(url: String, messageParent: Container): Boolean { + private fun checkFileRepo(url: String, project: Project?): Boolean { val suffix = "/${Constants.DOT_GIT}" val file = Paths.get(if (url.endsWith(suffix)) url.substring(0, url.length - suffix.length) else url) if (file.exists()) { if (!file.isDirectory()) { //noinspection DialogTitleCapitalization - Messages.showErrorDialog(messageParent, "Specified path is not a directory", "Specified Path is Invalid") + Messages.showErrorDialog(project, "Specified path is not a directory", "Specified Path is Invalid") return false } else if (isValidRepository(file)) { @@ -58,17 +59,21 @@ interface RepositoryService { } } else if (!file.isAbsolute) { - Messages.showErrorDialog(messageParent, icsMessage("specify.absolute.path.dialog.message"), "") + Messages.showErrorDialog(project, icsMessage("specify.absolute.path.dialog.message"), "") return false } - if (Messages.showYesNoDialog(messageParent, icsMessage("init.dialog.message"), icsMessage("init.dialog.title"), Messages.getQuestionIcon()) == Messages.YES) { + if (MessageDialogBuilder + .yesNo(icsMessage("init.dialog.title"), icsMessage("init.dialog.message", file)) + .yesText("Create") + .project(project) + .`is`()) { try { createBareRepository(file) return true } catch (e: IOException) { - Messages.showErrorDialog(messageParent, icsMessage("init.failed.message", e.message), icsMessage("init.failed.title")) + Messages.showErrorDialog(project, icsMessage("init.failed.message", e.message), icsMessage("init.failed.title")) return false } } diff --git a/plugins/settings-repository/src/settings/readOnlySourcesEditor.kt b/plugins/settings-repository/src/settings/readOnlySourcesEditor.kt index 875108a4f17d..2672ace5735a 100644 --- a/plugins/settings-repository/src/settings/readOnlySourcesEditor.kt +++ b/plugins/settings-repository/src/settings/readOnlySourcesEditor.kt @@ -66,16 +66,7 @@ internal fun createReadOnlySourcesEditor(): ConfigurableUi { urlField.addBrowseFolderListener(TextBrowseFolderListener(FileChooserDescriptorFactory.createSingleFolderDescriptor())) urlField.textField.document.addDocumentListener(object : DocumentAdapter() { override fun textChanged(event: DocumentEvent) { - val url = StringUtil.nullize(urlField.text) - val enabled: Boolean - try { - enabled = url != null && url.length > 1 && icsManager.repositoryService.checkUrl(url, null) - } - catch (e: Exception) { - enabled = false - } - - dialogBuilder.setOkActionEnabled(enabled) + dialogBuilder.setOkActionEnabled(checkUrl(urlField.text.nullize())) } }) diff --git a/plugins/settings-repository/src/settings/upstreamEditor.kt b/plugins/settings-repository/src/settings/upstreamEditor.kt index 719c7ea55f67..b789af6d1b72 100644 --- a/plugins/settings-repository/src/settings/upstreamEditor.kt +++ b/plugins/settings-repository/src/settings/upstreamEditor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,15 +29,17 @@ import java.awt.event.ActionEvent import javax.swing.AbstractAction import javax.swing.Action -fun updateSyncButtonState(url: String?, syncActions: Array) { - val enabled: Boolean +internal fun checkUrl(url: String?): Boolean { try { - enabled = url != null && url.length > 1 && icsManager.repositoryService.checkUrl(url, null); + return url != null && url.length > 1 && icsManager.repositoryService.checkUrl(url, false) } catch (e: Throwable) { - enabled = false; + return false } +} +fun updateSyncButtonState(url: String?, syncActions: Array) { + val enabled = checkUrl(url) for (syncAction in syncActions) { syncAction.isEnabled = enabled; } @@ -56,7 +58,7 @@ fun createMergeActions(project: Project?, urlTextField: TextFieldWithBrowseButto object : AbstractAction(icsMessage("action.${if (syncType == SyncType.MERGE) "Merge" else (if (syncType == SyncType.OVERWRITE_LOCAL) "ResetToTheirs" else "ResetToMy")}Settings.text")) { private fun saveRemoteRepositoryUrl(): Boolean { val url = StringUtil.nullize(urlTextField.text) - if (url != null && !icsManager.repositoryService.checkUrl(url, dialogParent)) { + if (url != null && !icsManager.repositoryService.checkUrl(url, true, project)) { return false }