Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ private class TabSize(
override val tooltipTag: String = TooltipTag.PREFS_EDITOR,
) : SingleChoicePreference() {

@IgnoredOnParcel
override val dialogCancellable = true

@IgnoredOnParcel
private val tabSizes = intArrayOf(2, 4, 6, 8)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ class UiMode(
override val icon: Int? = R.drawable.ic_ui_mode
) : SingleChoicePreference() {

@IgnoredOnParcel
override val dialogCancellable = true

@IgnoredOnParcel
override val tooltipTag: String = PREFS_GENERAL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.preference.Preference
import com.itsaky.androidide.idetooltips.TooltipTag
import com.itsaky.androidide.preferences.internal.XmlPreferences
import com.itsaky.androidide.resources.R.string
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import org.eclipse.lemminx.dom.builder.EmptyElements

Expand Down Expand Up @@ -212,9 +211,6 @@ private class EmptyElementsBehavior(
override val tooltipTag: String = TooltipTag.PREFS_EDITOR_XML,
) : SingleChoicePreference() {

@IgnoredOnParcel
override val dialogCancellable = true

override fun getEntries(preference: Preference): Array<PreferenceChoices.Entry> {
val entries = EmptyElements.entries
val currentBehavior = EmptyElements.valueOf(XmlPreferences.emptyElementsBehavior)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ abstract class ChoiceBasedDialogPreference : DialogPreference(), PreferenceChoic
}

override fun onChoicesCancelled(preference: Preference) {}

final override fun onDialogCancelled(preference: Preference) {
onChoicesCancelled(preference)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ abstract class DialogPreference : SimplePreference() {
get() = this.title

open val dialogMessage: Int? = null
open val dialogCancellable: Boolean = false
open val dialogCancellable: Boolean = true
open val tooltipTag: String = ""

override fun onPreferenceClick(preference: Preference): Boolean {
val dialog = DialogUtils.newMaterialDialogBuilder(preference.context)
dialog.setTitle(this.dialogTitle)
dialogMessage?.let { dialog.setMessage(it) }
dialog.setCancelable(this.dialogCancellable)
dialog.setOnCancelListener { onDialogCancelled(preference) }
onConfigureDialog(preference, dialog)
val alertDialog = dialog.create()
alertDialog.show()
Expand All @@ -57,4 +58,12 @@ abstract class DialogPreference : SimplePreference() {
protected open fun onConfigureDialog(preference: Preference,
dialog: MaterialAlertDialogBuilder) {
}

/**
* Called when the dialog is cancelled by the user (e.g. the system back button), as opposed to
* being dismissed by an action button. The default behaviour discards any unconfirmed changes,
* matching the dialog's cancel button.
*/
protected open fun onDialogCancelled(preference: Preference) {
}
}
Loading