*/
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
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) {
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)) {
}
}
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
}
}