feat: add preference to toggle line number pinning in editor

This commit is contained in:
Akash Yadav
2023-11-01 17:37:53 +05:30
parent 6cb604e5e9
commit 5986e6ac76
5 changed files with 32 additions and 0 deletions
@@ -33,6 +33,7 @@ import com.itsaky.androidide.preferences.internal.FLAG_PASSWORD
import com.itsaky.androidide.preferences.internal.FONT_LIGATURES
import com.itsaky.androidide.preferences.internal.FONT_SIZE
import com.itsaky.androidide.preferences.internal.HIDE_FILE_TREE_BUTTON
import com.itsaky.androidide.preferences.internal.PIN_LINE_NUMBERS
import com.itsaky.androidide.preferences.internal.PRINTABLE_CHARS
import com.itsaky.androidide.preferences.internal.STICKY_SCROLL_ENABLED
import com.itsaky.androidide.preferences.internal.TAB_SIZE
@@ -54,6 +55,7 @@ import com.itsaky.androidide.preferences.internal.drawTrailingWs
import com.itsaky.androidide.preferences.internal.fontLigatures
import com.itsaky.androidide.preferences.internal.fontSize
import com.itsaky.androidide.preferences.internal.hideFileTreeButton
import com.itsaky.androidide.preferences.internal.pinLineNumbers
import com.itsaky.androidide.preferences.internal.stickyScrollEnabled
import com.itsaky.androidide.preferences.internal.tabSize
import com.itsaky.androidide.preferences.internal.useCustomFont
@@ -106,6 +108,7 @@ private class CommonConfigurations(
addPreference(DeleteEmptyLines())
addPreference(DeleteTabs())
addPreference(StickyScrollEnabled())
addPreference(PinLineNumbersEnabled())
addPreference(CompletionsMatchLower())
}
}
@@ -349,3 +352,11 @@ private class StickyScrollEnabled(
override val summary: Int? = R.string.idepref_editor_stickyScroll_summary,
override val icon: Int? = drawable.ic_sticky_scroll
) : SwitchPreference(setValue = ::stickyScrollEnabled::set, getValue = ::stickyScrollEnabled::get)
@Parcelize
private class PinLineNumbersEnabled(
override val key: String = PIN_LINE_NUMBERS,
override val title: Int = R.string.idepref_editor_pinLineNumbers_title,
override val summary: Int? = R.string.idepref_editor_pinLineNumbers_summary,
override val icon: Int? = drawable.ic_pin
) : SwitchPreference(setValue = ::pinLineNumbers::set, getValue = ::pinLineNumbers::get)
@@ -51,6 +51,7 @@ import com.itsaky.androidide.preferences.internal.FLAG_WS_LEADING
import com.itsaky.androidide.preferences.internal.FLAG_WS_TRAILING
import com.itsaky.androidide.preferences.internal.FONT_LIGATURES
import com.itsaky.androidide.preferences.internal.FONT_SIZE
import com.itsaky.androidide.preferences.internal.PIN_LINE_NUMBERS
import com.itsaky.androidide.preferences.internal.STICKY_SCROLL_ENABLED
import com.itsaky.androidide.preferences.internal.USE_CUSTOM_FONT
import com.itsaky.androidide.preferences.internal.USE_ICU
@@ -65,6 +66,7 @@ import com.itsaky.androidide.preferences.internal.drawLineBreak
import com.itsaky.androidide.preferences.internal.drawTrailingWs
import com.itsaky.androidide.preferences.internal.fontLigatures
import com.itsaky.androidide.preferences.internal.fontSize
import com.itsaky.androidide.preferences.internal.pinLineNumbers
import com.itsaky.androidide.preferences.internal.stickyScrollEnabled
import com.itsaky.androidide.preferences.internal.useCustomFont
import com.itsaky.androidide.preferences.internal.useIcu
@@ -363,6 +365,7 @@ class CodeEditorView(
onDeleteEmptyLinesPrefChanged()
onDeleteTabsPrefChanged()
onStickyScrollEnabeldPrefChanged()
onPinLineNumbersPrefChanged()
}
private fun onMagnifierPrefChanged() {
@@ -433,6 +436,10 @@ class CodeEditorView(
binding.editor.props.stickyScroll = stickyScrollEnabled
}
private fun onPinLineNumbersPrefChanged() {
binding.editor.setPinLineNumber(pinLineNumbers)
}
/**
* For internal use only!
*
@@ -479,6 +486,7 @@ class CodeEditorView(
DELETE_EMPTY_LINES -> onDeleteEmptyLinesPrefChanged()
DELETE_TABS_ON_BACKSPACE -> onDeleteTabsPrefChanged()
STICKY_SCROLL_ENABLED -> onStickyScrollEnabeldPrefChanged()
PIN_LINE_NUMBERS -> onPinLineNumbersPrefChanged()
}
}
@@ -42,6 +42,7 @@ const val USE_CUSTOM_FONT = "idepref_editor_useCustomFont"
const val DELETE_EMPTY_LINES = "idepref_editor_deleteEmptyLines"
const val DELETE_TABS_ON_BACKSPACE = "idepref_editor_deleteTab"
const val STICKY_SCROLL_ENABLED = "idepref_editor_stickyScrollEnabled"
const val PIN_LINE_NUMBERS = "idepref_editor_pinLineNumbers"
const val COLOR_SCHEME = "idepref_editor_colorScheme"
const val DEFAULT_COLOR_SCHEME = "default"
@@ -178,3 +179,7 @@ var stickyScrollEnabled : Boolean
set(value) {
prefManager.putBoolean(STICKY_SCROLL_ENABLED, value)
}
var pinLineNumbers: Boolean
get() = prefManager.getBoolean(PIN_LINE_NUMBERS, true)
set(value) = prefManager.putBoolean(PIN_LINE_NUMBERS, value)
@@ -0,0 +1,6 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white"
android:fillType="evenOdd" android:pathData="M16,9V4l1,0c0.55,0 1,-0.45 1,-1v0c0,-0.55 -0.45,-1 -1,-1H7C6.45,2 6,2.45 6,3v0c0,0.55 0.45,1 1,1l1,0v5c0,1.66 -1.34,3 -3,3h0v2h5.97v7l1,1l1,-1v-7H19v-2h0C17.34,12 16,10.66 16,9z"/>
</vector>
@@ -614,4 +614,6 @@
<string name="msg_64bit_on_32bit_device">You are using 64-bit variant of AndroidIDE on a 32-bit-only device. This configuration is not supported. Please install the 32-bit variant of AndroidIDE.</string>
<string name="title_32bit_on_64bit_device">Configuration Warning</string>
<string name="msg_32bit_on_64bit_device">You are using 32-bit variant of AndroidIDE on a 64-bit device. This configuration may work, but it\'ll result in reduced performance and possible security vulnerabilities. Please avoid using this configuration whenever possible.</string>
<string name="idepref_editor_pinLineNumbers_title">Pin line numbers</string>
<string name="idepref_editor_pinLineNumbers_summary">Whether the editor should pin line number panel when scrolled horizontally.</string>
</resources>