forked from lxm_plugin_idea/ADB-Wi-Fi
show confirmation dialog before removing device from previously connected list
This commit is contained in:
@@ -8,7 +8,10 @@ formatting:
|
||||
active: false
|
||||
complexity:
|
||||
TooManyFunctions:
|
||||
thresholdInClasses: 20
|
||||
ignoreDeprecated: true
|
||||
ignorePrivate: true
|
||||
ignoreOverridden: true
|
||||
LongMethod:
|
||||
active: true
|
||||
threshold: 100
|
||||
|
||||
@@ -4,6 +4,7 @@ interface PropertiesService {
|
||||
var isLogVisible: Boolean
|
||||
|
||||
var isPreviouslyConnectedDevicesExpanded: Boolean
|
||||
var doNotShowRemoveDeviceConfirmation: Boolean
|
||||
|
||||
var useAdbFromPath: Boolean
|
||||
var adbLocation: String
|
||||
|
||||
@@ -23,6 +23,12 @@ class PropertiesServiceImpl : PropertiesService {
|
||||
properties.setValue(IS_PREVIOUSLY_CONNECTED_DEVICES_EXPANDED, value, true)
|
||||
}
|
||||
|
||||
override var doNotShowRemoveDeviceConfirmation: Boolean
|
||||
get() = properties.getBoolean(DO_NOT_SHOW_REMOVE_DEVICE_CONFIRMATION, false)
|
||||
set(value) {
|
||||
properties.setValue(DO_NOT_SHOW_REMOVE_DEVICE_CONFIRMATION, value, false)
|
||||
}
|
||||
|
||||
override var useAdbFromPath: Boolean
|
||||
get() = properties.getBoolean(ADB_FROM_SYSTEM_PATH, false)
|
||||
set(value) {
|
||||
@@ -109,6 +115,9 @@ class PropertiesServiceImpl : PropertiesService {
|
||||
private const val IS_PREVIOUSLY_CONNECTED_DEVICES_EXPANDED =
|
||||
"dev.polek.adbwifi.IS_PREVIOUSLY_CONNECTED_DEVICES_EXPANDED"
|
||||
|
||||
private const val DO_NOT_SHOW_REMOVE_DEVICE_CONFIRMATION =
|
||||
"dev.polek.adbwifi.DO_NOT_SHOW_REMOVE_DEVICE_CONFIRMATION"
|
||||
|
||||
private const val ADB_FROM_SYSTEM_PATH = "dev.polek.adbwifi.ADB_FROM_SYSTEM_PATH"
|
||||
private const val ADB_LOCATION_PROPERTY = "dev.polek.adbwifi.ADB_LOCATION_PROPERTY"
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ class ToolWindowPresenter : BasePresenter<ToolWindowView>() {
|
||||
unsubscribeFromDeviceList()
|
||||
unsubscribeFromLogEvents()
|
||||
unsubscribeFromAdbLocationChanges()
|
||||
unsubscribeFromAdbLocationChanges()
|
||||
unsubscribeFromScrcpyEnabledState()
|
||||
super.detach()
|
||||
}
|
||||
|
||||
@@ -104,6 +104,20 @@ class ToolWindowPresenter : BasePresenter<ToolWindowView>() {
|
||||
}
|
||||
|
||||
fun onRemoveDeviceButtonClicked(device: DeviceViewModel) {
|
||||
if (propertiesService.doNotShowRemoveDeviceConfirmation) {
|
||||
removeDevice(device)
|
||||
} else {
|
||||
view?.showRemoveDeviceConfirmation(device)
|
||||
}
|
||||
}
|
||||
|
||||
fun onRemoveDeviceConfirmed(device: DeviceViewModel, doNotAskAgain: Boolean) {
|
||||
propertiesService.doNotShowRemoveDeviceConfirmation = doNotAskAgain
|
||||
|
||||
removeDevice(device)
|
||||
}
|
||||
|
||||
private fun removeDevice(device: DeviceViewModel) {
|
||||
pinDeviceService.removePreviouslyConnectedDevice(device.device)
|
||||
pinnedDevices = pinDeviceService.pinnedDevices.toViewModel()
|
||||
updateDeviceLists()
|
||||
|
||||
@@ -10,6 +10,8 @@ import com.intellij.openapi.actionSystem.DefaultActionGroup
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.options.ShowSettingsUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.DialogWrapper
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.IconLoader
|
||||
import com.intellij.openapi.wm.ToolWindow
|
||||
import com.intellij.openapi.wm.ex.ToolWindowManagerListener
|
||||
@@ -239,6 +241,29 @@ class AdbWiFiToolWindow(
|
||||
notification.notify(project)
|
||||
}
|
||||
|
||||
override fun showRemoveDeviceConfirmation(device: DeviceViewModel) {
|
||||
val doNotAskAgain = object : DialogWrapper.DoNotAskOption.Adapter() {
|
||||
override fun rememberChoice(isSelected: Boolean, exitCode: Int) {
|
||||
if (exitCode == Messages.OK) {
|
||||
presenter.onRemoveDeviceConfirmed(device, doNotAskAgain = isSelected)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDoNotShowMessage(): String {
|
||||
return PluginBundle.message("doNotAskAgain")
|
||||
}
|
||||
}
|
||||
Messages.showOkCancelDialog(
|
||||
project,
|
||||
PluginBundle.message("removeDeviceConfirmation"),
|
||||
device.titleText,
|
||||
PluginBundle.message("removeButton"),
|
||||
PluginBundle.message("cancelButton"),
|
||||
null,
|
||||
doNotAskAgain
|
||||
)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val DEFAULT_PANEL_PROPORTION = 0.6f
|
||||
private val NOTIFICATION_GROUP = NotificationGroup(
|
||||
|
||||
@@ -22,4 +22,6 @@ interface ToolWindowView {
|
||||
fun closeLog()
|
||||
|
||||
fun setLogEntries(entries: List<LogEntry>)
|
||||
|
||||
fun showRemoveDeviceConfirmation(device: DeviceViewModel)
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ deviceListEmptyMessage=Connect a device via USB cable
|
||||
goToSettingsButton=Go to Settings
|
||||
previouslyConnectedTitle=Previously connected devices
|
||||
removeDeviceTooltip=Remove from list
|
||||
removeButton=Remove
|
||||
cancelButton=Cancel
|
||||
removeDeviceConfirmation=Remove device?
|
||||
doNotAskAgain="Don't ask again
|
||||
scrcpyHelpTitle=scrcpy
|
||||
scrcpyEnabled=Enable 'scrcpy' integration
|
||||
scrcpyHelpDescription=This application provides display and control of Android devices connected on USB (or over TCP/IP)
|
||||
|
||||
@@ -5,6 +5,7 @@ import dev.polek.adbwifi.services.PropertiesService
|
||||
class MockPropertiesService(
|
||||
override var isLogVisible: Boolean = false,
|
||||
override var isPreviouslyConnectedDevicesExpanded: Boolean = true,
|
||||
override var doNotShowRemoveDeviceConfirmation: Boolean = false,
|
||||
override var useAdbFromPath: Boolean = false,
|
||||
override var adbLocation: String = "/bin",
|
||||
override var defaultAdbLocation: String = "/bin",
|
||||
|
||||
Reference in New Issue
Block a user