From 7451f83d6685073d10df9bae5c957fdb55dcdc53 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Fri, 23 Aug 2024 00:31:20 +0300 Subject: fix: issues with IdeaVim version 2.16.0, everything should work now --- .gitignore | 90 ++-- LICENSE | 40 +- build.gradle.kts | 93 ++-- gradle.properties | 12 +- gradle/wrapper/gradle-wrapper.properties | 10 +- gradlew | 468 ++++++++++----------- gradlew.bat | 178 ++++---- settings.gradle.kts | 16 +- .../trident/actions/TridentAppendAction.kt | 32 +- .../kyren223/trident/actions/TridentListAction.kt | 26 +- .../trident/actions/TridentListSelectAction.kt | 22 +- .../trident/actions/TridentMappingsAction.kt | 24 +- .../trident/actions/TridentSelectAction.kt | 88 ++-- .../kotlin/me/kyren223/trident/data/Settings.kt | 66 +-- .../me/kyren223/trident/data/SettingsData.kt | 350 +++++++-------- .../trident/tests/MappingsExpansionTest.kt | 82 ++-- .../kotlin/me/kyren223/trident/tests/SplitTest.kt | 120 +++--- .../me/kyren223/trident/ui/SettingsConfigurable.kt | 134 +++--- .../me/kyren223/trident/ui/TridentListMenu.kt | 204 ++++----- .../me/kyren223/trident/ui/TridentMappingsMenu.kt | 171 ++++---- .../me/kyren223/trident/utils/TridentUtils.kt | 390 ++++++++--------- src/main/kotlin/me/kyren223/trident/utils/Utils.kt | 42 +- src/main/resources/META-INF/Trident-IdeaVim.xml | 4 +- src/main/resources/META-INF/plugin.xml | 264 ++++++------ src/main/resources/META-INF/pluginIcon.svg | 52 +-- 25 files changed, 1484 insertions(+), 1494 deletions(-) diff --git a/.gitignore b/.gitignore index b478fb0..7e8e4b5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,45 +1,45 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store - -/certificate/ -/.idea/ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +/certificate/ +/.idea/ diff --git a/LICENSE b/LICENSE index 05a3ca8..d9d7d03 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2024 Kyren223 - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +MIT License + +Copyright (c) 2024 Kyren223 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index d427f07..7aa9b25 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,46 +1,47 @@ -plugins { - id("java") - id("org.jetbrains.kotlin.jvm") version "1.9.21" - id("org.jetbrains.intellij") version "1.17.3" -} -group = "me.kyren223" -version = "2.1.2" - -repositories { - mavenCentral() -} - -// Configure Gradle IntelliJ Plugin -// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html -intellij { - version.set("2024.1") - type.set("IC") // Target IDE Platform - updateSinceUntilBuild.set(false) - plugins.set(listOf("IdeaVim:2.11.0")) -} - -tasks { - // Set the JVM compatibility versions - withType { - sourceCompatibility = "17" - targetCompatibility = "17" - } - withType { - kotlinOptions.jvmTarget = "17" - } - - patchPluginXml { - // Supports versions from 2023.2 and up - sinceBuild.set("232") - } - - signPlugin { - certificateChainFile.set(file("certificate/chain.crt")) - privateKeyFile.set(file("certificate/private.pem")) - password.set(providers.environmentVariable("PRIVATE_KEY_PASSWORD")) - } - - publishPlugin { - token.set(providers.environmentVariable("PUBLISH_TOKEN")) - } -} +plugins { + id("java") + id("org.jetbrains.kotlin.jvm") version "1.9.21" + id("org.jetbrains.intellij") version "1.17.3" +} + +group = "me.kyren223" +version = "2.2.0" + +repositories { + mavenCentral() +} + +// Configure Gradle IntelliJ Plugin +// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html +intellij { + version.set("2024.1.3") + type.set("IC") // Target IDE Platform + updateSinceUntilBuild.set(false) + plugins.set(listOf("IdeaVim:2.16.0")) +} + +tasks { + // Set the JVM compatibility versions + withType { + sourceCompatibility = "17" + targetCompatibility = "17" + } + withType { + kotlinOptions.jvmTarget = "17" + } + + patchPluginXml { + // Supports versions from 2023.2 and up + sinceBuild.set("232") + } + + signPlugin { + certificateChainFile.set(file("certificate/chain.crt")) + privateKeyFile.set(file("certificate/private.pem")) + password.set(providers.environmentVariable("PRIVATE_KEY_PASSWORD")) + } + + publishPlugin { + token.set(providers.environmentVariable("PUBLISH_TOKEN")) + } +} diff --git a/gradle.properties b/gradle.properties index 24630b3..c2c3be3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib -kotlin.stdlib.default.dependency=false -# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html -org.gradle.configuration-cache=true -# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html -org.gradle.caching=true +# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib +kotlin.stdlib.default.dependency=false +# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html +org.gradle.configuration-cache=true +# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html +org.gradle.caching=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15de902..cf5dd7d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 40d1eb7..d0cd72a 100644 --- a/gradlew +++ b/gradlew @@ -1,234 +1,234 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 the original authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a able exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# Darwin, MinGW, and NonStop. -# -# (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" -APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# For Cygwin or MSYS, switch paths to Windows format before running java -if "$cygwin" || "$msys" ; then - APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) - - JAVACMD=$( cygpath --unix "$JAVACMD" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ - "$@" - -# Use "xargs" to parse quoted args. -# -# With -n1 it outputs one arg per line, with the quotes and backslashes removed. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a able exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 107acd3..ac1b06f 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,89 +1,89 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts index c096433..7756d7c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1,9 @@ -pluginManagement { - repositories { - mavenCentral() - gradlePluginPortal() - } -} - -rootProject.name = "Trident" +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + } +} + +rootProject.name = "Trident" include("IdeaVIM") \ No newline at end of file diff --git a/src/main/kotlin/me/kyren223/trident/actions/TridentAppendAction.kt b/src/main/kotlin/me/kyren223/trident/actions/TridentAppendAction.kt index 1b0d33a..571eb0f 100644 --- a/src/main/kotlin/me/kyren223/trident/actions/TridentAppendAction.kt +++ b/src/main/kotlin/me/kyren223/trident/actions/TridentAppendAction.kt @@ -1,16 +1,16 @@ -package me.kyren223.trident.actions - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.PlatformDataKeys -import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VirtualFile -import me.kyren223.trident.utils.TridentList - -class TridentAppendAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - val project: Project = e.project ?: return - val file: VirtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return - TridentList.append(project, file) - } -} +package me.kyren223.trident.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.PlatformDataKeys +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import me.kyren223.trident.utils.TridentList + +class TridentAppendAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + val project: Project = e.project ?: return + val file: VirtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return + TridentList.append(project, file) + } +} diff --git a/src/main/kotlin/me/kyren223/trident/actions/TridentListAction.kt b/src/main/kotlin/me/kyren223/trident/actions/TridentListAction.kt index 0d733f3..f37f0aa 100644 --- a/src/main/kotlin/me/kyren223/trident/actions/TridentListAction.kt +++ b/src/main/kotlin/me/kyren223/trident/actions/TridentListAction.kt @@ -1,13 +1,13 @@ -package me.kyren223.trident.actions - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import me.kyren223.trident.ui.TridentListMenu - -class TridentListAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - val project = e.project ?: return - TridentListMenu.open(project) - } - -} +package me.kyren223.trident.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import me.kyren223.trident.ui.TridentListMenu + +class TridentListAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + val project = e.project ?: return + TridentListMenu.open(project) + } + +} diff --git a/src/main/kotlin/me/kyren223/trident/actions/TridentListSelectAction.kt b/src/main/kotlin/me/kyren223/trident/actions/TridentListSelectAction.kt index 1b68a59..4161927 100644 --- a/src/main/kotlin/me/kyren223/trident/actions/TridentListSelectAction.kt +++ b/src/main/kotlin/me/kyren223/trident/actions/TridentListSelectAction.kt @@ -1,11 +1,11 @@ -package me.kyren223.trident.actions - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import me.kyren223.trident.ui.TridentListMenu - -class TridentListSelectAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - TridentListMenu.instance?.select() - } -} +package me.kyren223.trident.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import me.kyren223.trident.ui.TridentListMenu + +class TridentListSelectAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + TridentListMenu.instance?.select() + } +} diff --git a/src/main/kotlin/me/kyren223/trident/actions/TridentMappingsAction.kt b/src/main/kotlin/me/kyren223/trident/actions/TridentMappingsAction.kt index b303c9e..77e3a11 100644 --- a/src/main/kotlin/me/kyren223/trident/actions/TridentMappingsAction.kt +++ b/src/main/kotlin/me/kyren223/trident/actions/TridentMappingsAction.kt @@ -1,12 +1,12 @@ -package me.kyren223.trident.actions - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import me.kyren223.trident.ui.TridentMappingsMenu - -class TridentMappingsAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - val project = e.project ?: return - TridentMappingsMenu.open(project) - } -} +package me.kyren223.trident.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import me.kyren223.trident.ui.TridentMappingsMenu + +class TridentMappingsAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + val project = e.project ?: return + TridentMappingsMenu.open(project) + } +} diff --git a/src/main/kotlin/me/kyren223/trident/actions/TridentSelectAction.kt b/src/main/kotlin/me/kyren223/trident/actions/TridentSelectAction.kt index 60973f2..2eeada3 100644 --- a/src/main/kotlin/me/kyren223/trident/actions/TridentSelectAction.kt +++ b/src/main/kotlin/me/kyren223/trident/actions/TridentSelectAction.kt @@ -1,44 +1,44 @@ -package me.kyren223.trident.actions - -import com.intellij.openapi.actionSystem.AnAction -import com.intellij.openapi.actionSystem.AnActionEvent -import com.intellij.openapi.actionSystem.PlatformDataKeys -import com.intellij.openapi.fileEditor.FileEditorManager -import me.kyren223.trident.utils.TridentList - -class TridentSelectAction : AnAction() { - override fun actionPerformed(e: AnActionEvent) { - val project = e.project ?: return - val index = when (val actionId = e.actionManager.getId(this)) { - NEXT -> { - val file = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return - val current = TridentList.getIndexOfFile(project, file) ?: return - current + 1 - } - - PREV -> { - val file = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return - val current = TridentList.getIndexOfFile(project, file) ?: return - current - 1 - } - - else -> { - getIndex(actionId!!) - } - } - - val file = TridentList.select(project, index) ?: return - FileEditorManager.getInstance(project).openFile(file, true) - } - - private fun getIndex(actionId: String): Int { - return actionId.substring(SELECT.length).toInt() - 1 - } - - companion object { - const val NEXT = "TridentSelectNext" - const val PREV = "TridentSelectPrev" - const val SELECT = "TridentSelect" - } -} - +package me.kyren223.trident.actions + +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.PlatformDataKeys +import com.intellij.openapi.fileEditor.FileEditorManager +import me.kyren223.trident.utils.TridentList + +class TridentSelectAction : AnAction() { + override fun actionPerformed(e: AnActionEvent) { + val project = e.project ?: return + val index = when (val actionId = e.actionManager.getId(this)) { + NEXT -> { + val file = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return + val current = TridentList.getIndexOfFile(project, file) ?: return + current + 1 + } + + PREV -> { + val file = e.getData(PlatformDataKeys.VIRTUAL_FILE) ?: return + val current = TridentList.getIndexOfFile(project, file) ?: return + current - 1 + } + + else -> { + getIndex(actionId!!) + } + } + + val file = TridentList.select(project, index) ?: return + FileEditorManager.getInstance(project).openFile(file, true) + } + + private fun getIndex(actionId: String): Int { + return actionId.substring(SELECT.length).toInt() - 1 + } + + companion object { + const val NEXT = "TridentSelectNext" + const val PREV = "TridentSelectPrev" + const val SELECT = "TridentSelect" + } +} + diff --git a/src/main/kotlin/me/kyren223/trident/data/Settings.kt b/src/main/kotlin/me/kyren223/trident/data/Settings.kt index e97737c..4c9204a 100644 --- a/src/main/kotlin/me/kyren223/trident/data/Settings.kt +++ b/src/main/kotlin/me/kyren223/trident/data/Settings.kt @@ -1,33 +1,33 @@ -package me.kyren223.trident.data - -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.components.* -import com.intellij.util.xmlb.XmlSerializerUtil - -// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -@Service -@State(name = "me.kyren223.trident.data.SettingsState", storages = [Storage("SdkSettingsPlugin.xml")]) -class SettingsState : PersistentStateComponent { - var width = 800 - var height = 400 - var fontSize = 20 - var enterToSelect = true - var automaticMapping = AutomaticMapping.Disabled - var automaticReplacing = AutomaticReplacing.Smart - var recursiveMapping = false - var rememberLine = false - var indexCycling = false - - override fun getState(): SettingsState { - return this - } - - override fun loadState(state: SettingsState) { - XmlSerializerUtil.copyBean(state, this) - } - - companion object { - val instance: SettingsState - get() = ApplicationManager.getApplication().getService(SettingsState::class.java) - } -} +package me.kyren223.trident.data + +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.components.* +import com.intellij.util.xmlb.XmlSerializerUtil + +// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +@Service +@State(name = "me.kyren223.trident.data.SettingsState", storages = [Storage("SdkSettingsPlugin.xml")]) +class SettingsState : PersistentStateComponent { + var width = 800 + var height = 400 + var fontSize = 20 + var enterToSelect = true + var automaticMapping = AutomaticMapping.Disabled + var automaticReplacing = AutomaticReplacing.Smart + var recursiveMapping = false + var rememberLine = false + var indexCycling = false + + override fun getState(): SettingsState { + return this + } + + override fun loadState(state: SettingsState) { + XmlSerializerUtil.copyBean(state, this) + } + + companion object { + val instance: SettingsState + get() = ApplicationManager.getApplication().getService(SettingsState::class.java) + } +} diff --git a/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt b/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt index 26cb1d1..49ca322 100644 --- a/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt +++ b/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt @@ -1,175 +1,175 @@ -package me.kyren223.trident.data - -import com.intellij.openapi.ui.ComboBox -import com.intellij.ui.JBColor -import com.intellij.ui.JBIntSpinner -import com.intellij.ui.components.JBCheckBox -import com.intellij.ui.components.JBLabel -import com.intellij.util.ui.FormBuilder -import com.intellij.util.ui.JBFont -import javax.swing.JPanel - -class SettingsData { - - private val minValue = 1 - private val maxValue = 5000 - private val step = 10 - - val panel: JPanel - - private val width = JBIntSpinner(SettingsState.instance.width, minValue, maxValue, step) - private val height = JBIntSpinner(SettingsState.instance.height, minValue, maxValue, step) - private val fontSize = JBIntSpinner(SettingsState.instance.fontSize, minValue, maxValue, step) - - private val enterToSelect = JBCheckBox(null, SettingsState.instance.enterToSelect) - private val rememberLine = JBCheckBox(null, SettingsState.instance.rememberLine) - private val automaticMapping = ComboBox(AutomaticMapping.entries.toTypedArray()) - private val automaticReplacing = ComboBox(AutomaticReplacing.entries.toTypedArray()) - private val recursiveMapping = JBCheckBox(null, SettingsState.instance.recursiveMapping) - private val indexCycling = JBCheckBox(null, SettingsState.instance.indexCycling) - - init { - automaticMapping.selectedItem = SettingsState.instance.automaticMapping - automaticReplacing.selectedItem = SettingsState.instance.automaticReplacing - - panel = FormBuilder.createFormBuilder() - .addComponent(JBLabel("Popup settings").withFont(JBFont.h4())) - .addLabeledComponent("Popup width", width) - .addLabeledComponent("Popup height", height) - .addLabeledComponent("Popup font size", fontSize) - .addSeparator() - - .addComponent(JBLabel("Trident settings").withFont(JBFont.h4())) - .addLabeledComponent("Enter to select item", enterToSelect) - .addComponent(desc("If enabled while the TridentList is open, " + - "pressing enter will select the item in the current line and open the file (if it exists).")) - .addVerticalGap(step) - - .addLabeledComponent("Automatic mapping (when possible)", automaticMapping) - .addComponent(desc("Disabled - adds the full file path to the Trident Mappings.")) - .addComponent(desc("Filename - Adds the filename (with extension).")) - .addComponent(desc("Filename (no extension) - Adds the filename (without extension).")) - .addVerticalGap(step) - - .addLabeledComponent("Automatic replacing (when possible)", automaticReplacing) - .addComponent(desc("Disabled - Keeps the full file path.")) - .addComponent(desc("Exact - Replaces the full path if an exact match is found.")) - .addComponent(desc("Smart - Like exact but if no exact match found, " + - "it will try to make the path shorter.")) - .addVerticalGap(step) - - .addLabeledComponent("Recursive mapping", recursiveMapping) - .addComponent(desc("If enabled, when expanding a mapping for a path, " + - "each entry will be expanded recursively.")) - .addComponent(desc("This allows mapping entries to be nested (include other mappings).")) - .addVerticalGap(step) - - .addLabeledComponent("Remember last line", rememberLine) - .addComponent(desc("If enabled, the current line of the TridentList will be remembered " + - "and will be selected when the TridentList is opened.")) - .addComponent(desc("Note, this does not persist across restarts, it's run-time only.")) - - .addLabeledComponent("Index cycling", indexCycling) - .addComponent(desc("If enabled, indexes will be cyclic, " + - "For example if you have 3 files and hotkey to 4, it'll cycle to 1.")) - - .addComponentFillVertically(JPanel(), 0) - .panel - } - - private fun desc(text: String): JBLabel { - val label = JBLabel(text).withFont(JBFont.small()) - label.foreground = JBColor.GRAY - return label - } - - fun getWidth(): Int { - return width.number - } - - fun getHeight(): Int { - return height.number - } - - fun getFontSize(): Int { - return fontSize.number - } - - fun getEnterToSelect(): Boolean { - return enterToSelect.isSelected - } - - fun setWidth(width: Int) { - this.width.number = width - } - - fun setHeight(height: Int) { - this.height.number = height - } - - fun setFontSize(fontSize: Int) { - this.fontSize.number = fontSize - } - - fun setEnterToSelect(enter: Boolean) { - this.enterToSelect.isSelected = enter - } - - fun getAutomaticMapping(): AutomaticMapping { - return automaticMapping.selectedItem as AutomaticMapping - } - - fun setAutomaticMapping(automaticMapping: AutomaticMapping) { - this.automaticMapping.selectedItem = automaticMapping - } - - fun getAutomaticReplacing(): AutomaticReplacing { - return automaticReplacing.selectedItem as AutomaticReplacing - } - - fun setAutomaticReplacing(automaticReplacing: AutomaticReplacing) { - this.automaticReplacing.selectedItem = automaticReplacing - } - - fun getRememberLine(): Boolean { - return rememberLine.isSelected - } - - fun setRememberLine(rememberLine: Boolean) { - this.rememberLine.isSelected = rememberLine - } - - fun getRecursiveMapping(): Boolean { - return recursiveMapping.isSelected - } - - fun setRecursiveMapping(recursiveMapping: Boolean) { - this.recursiveMapping.isSelected = recursiveMapping - } - - fun getIndexCycling(): Boolean { - return indexCycling.isSelected - } - - fun setIndexCycling(indexCycling: Boolean) { - this.indexCycling.isSelected = indexCycling - } -} - -enum class AutomaticMapping { - Disabled, - Filename, - FilenameNoExtension, - ; - - override fun toString(): String { - if (this == FilenameNoExtension) return "Filename (without extension)" - return super.toString() - } -} - -enum class AutomaticReplacing { - Disabled, - Exact, - Smart, -} +package me.kyren223.trident.data + +import com.intellij.openapi.ui.ComboBox +import com.intellij.ui.JBColor +import com.intellij.ui.JBIntSpinner +import com.intellij.ui.components.JBCheckBox +import com.intellij.ui.components.JBLabel +import com.intellij.util.ui.FormBuilder +import com.intellij.util.ui.JBFont +import javax.swing.JPanel + +class SettingsData { + + private val minValue = 1 + private val maxValue = 5000 + private val step = 10 + + val panel: JPanel + + private val width = JBIntSpinner(SettingsState.instance.width, minValue, maxValue, step) + private val height = JBIntSpinner(SettingsState.instance.height, minValue, maxValue, step) + private val fontSize = JBIntSpinner(SettingsState.instance.fontSize, minValue, maxValue, step) + + private val enterToSelect = JBCheckBox(null, SettingsState.instance.enterToSelect) + private val rememberLine = JBCheckBox(null, SettingsState.instance.rememberLine) + private val automaticMapping = ComboBox(AutomaticMapping.entries.toTypedArray()) + private val automaticReplacing = ComboBox(AutomaticReplacing.entries.toTypedArray()) + private val recursiveMapping = JBCheckBox(null, SettingsState.instance.recursiveMapping) + private val indexCycling = JBCheckBox(null, SettingsState.instance.indexCycling) + + init { + automaticMapping.selectedItem = SettingsState.instance.automaticMapping + automaticReplacing.selectedItem = SettingsState.instance.automaticReplacing + + panel = FormBuilder.createFormBuilder() + .addComponent(JBLabel("Popup settings").withFont(JBFont.h4())) + .addLabeledComponent("Popup width", width) + .addLabeledComponent("Popup height", height) + .addLabeledComponent("Popup font size", fontSize) + .addSeparator() + + .addComponent(JBLabel("Trident settings").withFont(JBFont.h4())) + .addLabeledComponent("Enter to select item", enterToSelect) + .addComponent(desc("If enabled while the TridentList is open, " + + "pressing enter will select the item in the current line and open the file (if it exists).")) + .addVerticalGap(step) + + .addLabeledComponent("Automatic mapping (when possible)", automaticMapping) + .addComponent(desc("Disabled - adds the full file path to the Trident Mappings.")) + .addComponent(desc("Filename - Adds the filename (with extension).")) + .addComponent(desc("Filename (no extension) - Adds the filename (without extension).")) + .addVerticalGap(step) + + .addLabeledComponent("Automatic replacing (when possible)", automaticReplacing) + .addComponent(desc("Disabled - Keeps the full file path.")) + .addComponent(desc("Exact - Replaces the full path if an exact match is found.")) + .addComponent(desc("Smart - Like exact but if no exact match found, " + + "it will try to make the path shorter.")) + .addVerticalGap(step) + + .addLabeledComponent("Recursive mapping", recursiveMapping) + .addComponent(desc("If enabled, when expanding a mapping for a path, " + + "each entry will be expanded recursively.")) + .addComponent(desc("This allows mapping entries to be nested (include other mappings).")) + .addVerticalGap(step) + + .addLabeledComponent("Remember last line", rememberLine) + .addComponent(desc("If enabled, the current line of the TridentList will be remembered " + + "and will be selected when the TridentList is opened.")) + .addComponent(desc("Note, this does not persist across restarts, it's run-time only.")) + + .addLabeledComponent("Index cycling", indexCycling) + .addComponent(desc("If enabled, indexes will be cyclic, " + + "For example if you have 3 files and hotkey to 4, it'll cycle to 1.")) + + .addComponentFillVertically(JPanel(), 0) + .panel + } + + private fun desc(text: String): JBLabel { + val label = JBLabel(text).withFont(JBFont.small()) + label.foreground = JBColor.GRAY + return label + } + + fun getWidth(): Int { + return width.number + } + + fun getHeight(): Int { + return height.number + } + + fun getFontSize(): Int { + return fontSize.number + } + + fun getEnterToSelect(): Boolean { + return enterToSelect.isSelected + } + + fun setWidth(width: Int) { + this.width.number = width + } + + fun setHeight(height: Int) { + this.height.number = height + } + + fun setFontSize(fontSize: Int) { + this.fontSize.number = fontSize + } + + fun setEnterToSelect(enter: Boolean) { + this.enterToSelect.isSelected = enter + } + + fun getAutomaticMapping(): AutomaticMapping { + return automaticMapping.selectedItem as AutomaticMapping + } + + fun setAutomaticMapping(automaticMapping: AutomaticMapping) { + this.automaticMapping.selectedItem = automaticMapping + } + + fun getAutomaticReplacing(): AutomaticReplacing { + return automaticReplacing.selectedItem as AutomaticReplacing + } + + fun setAutomaticReplacing(automaticReplacing: AutomaticReplacing) { + this.automaticReplacing.selectedItem = automaticReplacing + } + + fun getRememberLine(): Boolean { + return rememberLine.isSelected + } + + fun setRememberLine(rememberLine: Boolean) { + this.rememberLine.isSelected = rememberLine + } + + fun getRecursiveMapping(): Boolean { + return recursiveMapping.isSelected + } + + fun setRecursiveMapping(recursiveMapping: Boolean) { + this.recursiveMapping.isSelected = recursiveMapping + } + + fun getIndexCycling(): Boolean { + return indexCycling.isSelected + } + + fun setIndexCycling(indexCycling: Boolean) { + this.indexCycling.isSelected = indexCycling + } +} + +enum class AutomaticMapping { + Disabled, + Filename, + FilenameNoExtension, + ; + + override fun toString(): String { + if (this == FilenameNoExtension) return "Filename (without extension)" + return super.toString() + } +} + +enum class AutomaticReplacing { + Disabled, + Exact, + Smart, +} diff --git a/src/main/kotlin/me/kyren223/trident/tests/MappingsExpansionTest.kt b/src/main/kotlin/me/kyren223/trident/tests/MappingsExpansionTest.kt index 0b66c4b..7fe33ad 100644 --- a/src/main/kotlin/me/kyren223/trident/tests/MappingsExpansionTest.kt +++ b/src/main/kotlin/me/kyren223/trident/tests/MappingsExpansionTest.kt @@ -1,42 +1,42 @@ -package me.kyren223.trident.tests - -import org.junit.Test - -class MappingsExpansionTest { - @Test - fun testExpand() { - val mappings = mapOf( - "\$A" to "A", - "\$BB" to "B", - "\$CCC" to "C", - "\$DDD" to "D", - "\$EEE" to "E", - "\$FFFFF" to "F", - "\$GG" to "G", - "\$UUU" to "U", - "\$VVVV" to "V", - "\$LLLLLL" to "L", - "\$MM" to "M", - "\$NN" to "N", - "\$OOO" to "O", - "\$PPP" to "P", - "\$QQQQ" to "Q", - "\$R" to "R", - "\$WWW" to "W", - "\$XX" to "X", - "\$HI" to "H", - "\$IJ" to "I", - "\$JetBrains" to "J", - "\$Krypton" to "K", - "\$Soft" to "S", - "\$Tnt" to "T", - "\$Ycombinator" to "Y", - "\$Zig" to "Z", - ).toList().sortedByDescending { it.first.length } - - mappings.forEach { (key, value) -> - println("$key -> $value") - } - - } +package me.kyren223.trident.tests + +import org.junit.Test + +class MappingsExpansionTest { + @Test + fun testExpand() { + val mappings = mapOf( + "\$A" to "A", + "\$BB" to "B", + "\$CCC" to "C", + "\$DDD" to "D", + "\$EEE" to "E", + "\$FFFFF" to "F", + "\$GG" to "G", + "\$UUU" to "U", + "\$VVVV" to "V", + "\$LLLLLL" to "L", + "\$MM" to "M", + "\$NN" to "N", + "\$OOO" to "O", + "\$PPP" to "P", + "\$QQQQ" to "Q", + "\$R" to "R", + "\$WWW" to "W", + "\$XX" to "X", + "\$HI" to "H", + "\$IJ" to "I", + "\$JetBrains" to "J", + "\$Krypton" to "K", + "\$Soft" to "S", + "\$Tnt" to "T", + "\$Ycombinator" to "Y", + "\$Zig" to "Z", + ).toList().sortedByDescending { it.first.length } + + mappings.forEach { (key, value) -> + println("$key -> $value") + } + + } } \ No newline at end of file diff --git a/src/main/kotlin/me/kyren223/trident/tests/SplitTest.kt b/src/main/kotlin/me/kyren223/trident/tests/SplitTest.kt index e4ea477..586fef1 100644 --- a/src/main/kotlin/me/kyren223/trident/tests/SplitTest.kt +++ b/src/main/kotlin/me/kyren223/trident/tests/SplitTest.kt @@ -1,61 +1,61 @@ -package me.kyren223.trident.tests - -import org.junit.Test - -class SplitTest { - - @Test - fun testSplit() { - val filenameAndExtension = "SplitTest.kt" - val filename = "SplitTest" - val dotfile = ".ideavimrc" - - val split = filenameAndExtension.split(".") - assert(split.size == 2) - assert(split[0] == filename) - assert(split[1] == "kt") - - val split2 = filename.split(".") - assert(split2.size == 1) - assert(split2[0] == filename) - - val split3 = dotfile.split(".") - assert(split3.size == 2) - assert(split3[0] == "") - assert(split3[1] == "ideavimrc") - - - } - - @Test - fun testSplit2() { - val path = "C:/Users/Owner/Projects/Trident/src/main/kotlin/me/kyren223/trident/tests/SplitTest.kt" - testPath(path, "SplitTest", "kt") - testPath("SplitTest.kt", "SplitTest", "kt") - testPath("SplitTest", "SplitTest", null) - testPath(".ideavimrc", null, "ideavimrc") - testPath("build.gradle.kts", "build.gradle", "kts") - - } - - private fun testPath(path: String, filename: String?, extension: String?) { - - val fullFilename = path.split("/").last() - println("fullFilename: $fullFilename") - val lastDot = fullFilename.lastIndexOf(".") - val noExtension = lastDot == -1 - - val filename2 = if (noExtension) fullFilename else { - fullFilename.substring(0, lastDot).ifEmpty { null } - } - val extension2 = if (noExtension) null else fullFilename.substring(lastDot + 1) - - println("filename: $filename") - println("extension: $extension") - println("filename2: $filename2") - println("extension2: $extension2") - - assert(filename2 == filename) - assert(extension2 == extension) - } +package me.kyren223.trident.tests + +import org.junit.Test + +class SplitTest { + + @Test + fun testSplit() { + val filenameAndExtension = "SplitTest.kt" + val filename = "SplitTest" + val dotfile = ".ideavimrc" + + val split = filenameAndExtension.split(".") + assert(split.size == 2) + assert(split[0] == filename) + assert(split[1] == "kt") + + val split2 = filename.split(".") + assert(split2.size == 1) + assert(split2[0] == filename) + + val split3 = dotfile.split(".") + assert(split3.size == 2) + assert(split3[0] == "") + assert(split3[1] == "ideavimrc") + + + } + + @Test + fun testSplit2() { + val path = "C:/Users/Owner/Projects/Trident/src/main/kotlin/me/kyren223/trident/tests/SplitTest.kt" + testPath(path, "SplitTest", "kt") + testPath("SplitTest.kt", "SplitTest", "kt") + testPath("SplitTest", "SplitTest", null) + testPath(".ideavimrc", null, "ideavimrc") + testPath("build.gradle.kts", "build.gradle", "kts") + + } + + private fun testPath(path: String, filename: String?, extension: String?) { + + val fullFilename = path.split("/").last() + println("fullFilename: $fullFilename") + val lastDot = fullFilename.lastIndexOf(".") + val noExtension = lastDot == -1 + + val filename2 = if (noExtension) fullFilename else { + fullFilename.substring(0, lastDot).ifEmpty { null } + } + val extension2 = if (noExtension) null else fullFilename.substring(lastDot + 1) + + println("filename: $filename") + println("extension: $extension") + println("filename2: $filename2") + println("extension2: $extension2") + + assert(filename2 == filename) + assert(extension2 == extension) + } } \ No newline at end of file diff --git a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt index f6979b1..085c6f2 100644 --- a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt +++ b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt @@ -1,67 +1,67 @@ -// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package me.kyren223.trident.ui - -import com.intellij.openapi.options.Configurable -import com.intellij.openapi.util.NlsContexts.ConfigurableName -import me.kyren223.trident.data.SettingsData -import me.kyren223.trident.data.SettingsState -import javax.swing.JComponent - -class SettingsConfigurable : Configurable { - - private var settings: SettingsData? = null - - override fun getDisplayName(): @ConfigurableName String { - return "Trident Settings" - } - - override fun createComponent(): JComponent { - settings = SettingsData() - return settings!!.panel - } - - override fun isModified(): Boolean { - val settings = SettingsState.instance - if (settings.width != this.settings!!.getWidth()) return true - if (settings.height != this.settings!!.getHeight()) return true - if (settings.fontSize != this.settings!!.getFontSize()) return true - if (settings.enterToSelect != this.settings!!.getEnterToSelect()) return true - if (settings.automaticMapping != this.settings!!.getAutomaticMapping()) return true - if (settings.automaticReplacing != this.settings!!.getAutomaticReplacing()) return true - if (settings.recursiveMapping != this.settings!!.getRecursiveMapping()) return true - if (settings.rememberLine != this.settings!!.getRememberLine()) return true - if (settings.indexCycling != this.settings!!.getIndexCycling()) return true - return false - } - - override fun apply() { - val settings = SettingsState.instance - settings.width = this.settings!!.getWidth() - settings.height = this.settings!!.getHeight() - settings.fontSize = this.settings!!.getFontSize() - settings.enterToSelect = this.settings!!.getEnterToSelect() - settings.automaticMapping = this.settings!!.getAutomaticMapping() - settings.automaticReplacing = this.settings!!.getAutomaticReplacing() - settings.recursiveMapping = this.settings!!.getRecursiveMapping() - settings.rememberLine = this.settings!!.getRememberLine() - settings.indexCycling = this.settings!!.getIndexCycling() - } - - override fun reset() { - val settings = SettingsState.instance - if (this.settings == null) this.settings = SettingsData() - this.settings!!.setWidth(settings.width) - this.settings!!.setHeight(settings.height) - this.settings!!.setFontSize(settings.fontSize) - this.settings!!.setEnterToSelect(settings.enterToSelect) - this.settings!!.setAutomaticMapping(settings.automaticMapping) - this.settings!!.setAutomaticReplacing(settings.automaticReplacing) - this.settings!!.setRecursiveMapping(settings.recursiveMapping) - this.settings!!.setRememberLine(settings.rememberLine) - this.settings!!.setIndexCycling(settings.indexCycling) - } - - override fun disposeUIResources() { - settings = null - } -} +// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package me.kyren223.trident.ui + +import com.intellij.openapi.options.Configurable +import com.intellij.openapi.util.NlsContexts.ConfigurableName +import me.kyren223.trident.data.SettingsData +import me.kyren223.trident.data.SettingsState +import javax.swing.JComponent + +class SettingsConfigurable : Configurable { + + private var settings: SettingsData? = null + + override fun getDisplayName(): @ConfigurableName String { + return "Trident Settings" + } + + override fun createComponent(): JComponent { + settings = SettingsData() + return settings!!.panel + } + + override fun isModified(): Boolean { + val settings = SettingsState.instance + if (settings.width != this.settings!!.getWidth()) return true + if (settings.height != this.settings!!.getHeight()) return true + if (settings.fontSize != this.settings!!.getFontSize()) return true + if (settings.enterToSelect != this.settings!!.getEnterToSelect()) return true + if (settings.automaticMapping != this.settings!!.getAutomaticMapping()) return true + if (settings.automaticReplacing != this.settings!!.getAutomaticReplacing()) return true + if (settings.recursiveMapping != this.settings!!.getRecursiveMapping()) return true + if (settings.rememberLine != this.settings!!.getRememberLine()) return true + if (settings.indexCycling != this.settings!!.getIndexCycling()) return true + return false + } + + override fun apply() { + val settings = SettingsState.instance + settings.width = this.settings!!.getWidth() + settings.height = this.settings!!.getHeight() + settings.fontSize = this.settings!!.getFontSize() + settings.enterToSelect = this.settings!!.getEnterToSelect() + settings.automaticMapping = this.settings!!.getAutomaticMapping() + settings.automaticReplacing = this.settings!!.getAutomaticReplacing() + settings.recursiveMapping = this.settings!!.getRecursiveMapping() + settings.rememberLine = this.settings!!.getRememberLine() + settings.indexCycling = this.settings!!.getIndexCycling() + } + + override fun reset() { + val settings = SettingsState.instance + if (this.settings == null) this.settings = SettingsData() + this.settings!!.setWidth(settings.width) + this.settings!!.setHeight(settings.height) + this.settings!!.setFontSize(settings.fontSize) + this.settings!!.setEnterToSelect(settings.enterToSelect) + this.settings!!.setAutomaticMapping(settings.automaticMapping) + this.settings!!.setAutomaticReplacing(settings.automaticReplacing) + this.settings!!.setRecursiveMapping(settings.recursiveMapping) + this.settings!!.setRememberLine(settings.rememberLine) + this.settings!!.setIndexCycling(settings.indexCycling) + } + + override fun disposeUIResources() { + settings = null + } +} diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt index 75e059a..45eaf76 100644 --- a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt +++ b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt @@ -1,102 +1,102 @@ -package me.kyren223.trident.ui - -import com.intellij.openapi.editor.EditorSettings -import com.intellij.openapi.editor.LogicalPosition -import com.intellij.openapi.fileEditor.FileEditorManager -import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.DialogWrapper -import com.intellij.ui.EditorTextField -import com.maddyhome.idea.vim.newapi.vim -import com.maddyhome.idea.vim.state.mode.Mode -import me.kyren223.trident.data.SettingsState -import me.kyren223.trident.utils.TridentList -import me.kyren223.trident.utils.injectEnterToSelectMapping -import me.kyren223.trident.utils.setEditorMode -import java.awt.event.FocusEvent -import java.awt.event.FocusListener -import javax.swing.JComponent - -class TridentListMenu(private val content: String) : DialogWrapper(true) { - - private lateinit var editor: EditorTextField - - init { - this.title = "Trident List" - val settings = SettingsState.instance - setSize(settings.width, settings.height) - super.init() - } - - override fun createCenterPanel(): JComponent { - editor = EditorTextField(this.content) - editor.setOneLineMode(false) - editor.addSettingsProvider { - it.setFontSize(SettingsState.instance.fontSize) - it.isInsertMode = false - val lineNumber = if (SettingsState.instance.rememberLine) line else 0 - it.caretModel.moveToLogicalPosition(LogicalPosition(lineNumber, 0)) - it.settings.isLineNumbersShown = true - it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE - } - - editor.addFocusListener(object : FocusListener { - override fun focusGained(e: FocusEvent?) { - val editor = editor.editor!!.vim - setEditorMode(editor, Mode.NORMAL()) - } - - override fun focusLost(e: FocusEvent?) { /* Do nothing */ - } - }) - - return editor - } - - - override fun getPreferredFocusedComponent(): JComponent { - return this.editor - } - - fun select() { - doOKAction() - } - - override fun doOKAction() { - save() - super.doOKAction() - } - - override fun doCancelAction() { - save() - super.doCancelAction() - } - - private fun save() { - instance = null - files = editor.text.split("\n") - line = editor.editor?.caretModel?.logicalPosition?.line ?: 0 - } - - override fun createSouthPanel(): JComponent? { - return null - } - - companion object { - var instance: TridentListMenu? = null - var files: List? = null - var line = 0 - fun open(project: Project) { - val content = TridentList.get(project).joinToString("\n") - instance = TridentListMenu(content) - injectEnterToSelectMapping() - val selected = instance!!.showAndGet() - - files?.let { TridentList.set(project, it) } - files = null - - if (!selected) return - val file = TridentList.select(project, line) ?: return - FileEditorManager.getInstance(project).openFile(file, true) - } - } -} +package me.kyren223.trident.ui + +import com.intellij.openapi.editor.EditorSettings +import com.intellij.openapi.editor.LogicalPosition +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.ui.EditorTextField +import com.maddyhome.idea.vim.newapi.vim +import com.maddyhome.idea.vim.state.mode.Mode +import me.kyren223.trident.data.SettingsState +import me.kyren223.trident.utils.TridentList +import me.kyren223.trident.utils.injectEnterToSelectMapping +import java.awt.event.FocusEvent +import java.awt.event.FocusListener +import javax.swing.JComponent + +class TridentListMenu(private val content: String) : DialogWrapper(true) { + + private lateinit var editor: EditorTextField + + init { + this.title = "Trident List" + val settings = SettingsState.instance + setSize(settings.width, settings.height) + super.init() + } + + override fun createCenterPanel(): JComponent { + editor = EditorTextField(this.content) + editor.setOneLineMode(false) + editor.addSettingsProvider { + it.setFontSize(SettingsState.instance.fontSize) + it.isInsertMode = false + val lineNumber = if (SettingsState.instance.rememberLine) line else 0 + it.caretModel.moveToLogicalPosition(LogicalPosition(lineNumber, 0)) + it.settings.isLineNumbersShown = true + it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE + } + + editor.addFocusListener(object : FocusListener { + override fun focusGained(e: FocusEvent?) { + val editor = editor.editor!!.vim + editor.mode = Mode.NORMAL() +// setEditorMode(editor, Mode.NORMAL()) + } + + override fun focusLost(e: FocusEvent?) { /* Do nothing */ + } + }) + + return editor + } + + + override fun getPreferredFocusedComponent(): JComponent { + return this.editor + } + + fun select() { + doOKAction() + } + + override fun doOKAction() { + save() + super.doOKAction() + } + + override fun doCancelAction() { + save() + super.doCancelAction() + } + + private fun save() { + instance = null + files = editor.text.split("\n") + line = editor.editor?.caretModel?.logicalPosition?.line ?: 0 + } + + override fun createSouthPanel(): JComponent? { + return null + } + + companion object { + var instance: TridentListMenu? = null + var files: List? = null + var line = 0 + fun open(project: Project) { + val content = TridentList.get(project).joinToString("\n") + instance = TridentListMenu(content) + injectEnterToSelectMapping() + val selected = instance!!.showAndGet() + + files?.let { TridentList.set(project, it) } + files = null + + if (!selected) return + val file = TridentList.select(project, line) ?: return + FileEditorManager.getInstance(project).openFile(file, true) + } + } +} diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt index 79f1df8..062c618 100644 --- a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt +++ b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt @@ -1,86 +1,85 @@ -package me.kyren223.trident.ui - -import com.intellij.openapi.editor.EditorSettings -import com.intellij.openapi.editor.LogicalPosition -import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.DialogWrapper -import com.intellij.ui.EditorTextField -import com.maddyhome.idea.vim.newapi.vim -import com.maddyhome.idea.vim.state.mode.Mode -import me.kyren223.trident.data.SettingsState -import me.kyren223.trident.utils.TridentMappings -import me.kyren223.trident.utils.setEditorMode -import java.awt.event.FocusEvent -import java.awt.event.FocusListener -import javax.swing.JComponent - -class TridentMappingsMenu(private val content: String) : DialogWrapper(true) { - private lateinit var editor: EditorTextField - - init { - val settings = SettingsState.instance.state - this.title = "Trident Mappings" - setSize(settings.width, settings.height) - super.init() - } - - override fun createCenterPanel(): JComponent { - editor = EditorTextField(this.content) - editor.setOneLineMode(false) - editor.addSettingsProvider { - it.setFontSize(SettingsState.instance.fontSize) - it.isInsertMode = false - it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0)) - it.settings.isLineNumbersShown = true - it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE - } - - editor.addFocusListener(object : FocusListener { - override fun focusGained(e: FocusEvent?) { - val editor = editor.editor!!.vim - setEditorMode(editor, Mode.NORMAL()) - } - - override fun focusLost(e: FocusEvent?) { /* Do nothing */ } - }) - - return editor - } - - override fun getPreferredFocusedComponent(): JComponent { - return this.editor - } - - override fun doOKAction() { - save() - super.doOKAction() - } - - override fun doCancelAction() { - save() - super.doCancelAction() - } - - private fun save() { - map = editor.text.split("\n") - .map { entry -> entry.split("=") } - .filter { entry -> entry.size == 2 } - .associate { it[0] to it[1] } - } - - override fun createSouthPanel(): JComponent? { - return null - } - - companion object { - var map: Map? = null - fun open(project: Project) { - val content = TridentMappings.get(project).entries - .joinToString("\n") { "${it.key}=${it.value}" } - val menu = TridentMappingsMenu(content) - menu.show() - map?.let { TridentMappings.set(project, it) } - map = null - } - } -} +package me.kyren223.trident.ui + +import com.intellij.openapi.editor.EditorSettings +import com.intellij.openapi.editor.LogicalPosition +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.DialogWrapper +import com.intellij.ui.EditorTextField +import com.maddyhome.idea.vim.newapi.vim +import com.maddyhome.idea.vim.state.mode.Mode +import me.kyren223.trident.data.SettingsState +import me.kyren223.trident.utils.TridentMappings +import java.awt.event.FocusEvent +import java.awt.event.FocusListener +import javax.swing.JComponent + +class TridentMappingsMenu(private val content: String) : DialogWrapper(true) { + private lateinit var editor: EditorTextField + + init { + val settings = SettingsState.instance.state + this.title = "Trident Mappings" + setSize(settings.width, settings.height) + super.init() + } + + override fun createCenterPanel(): JComponent { + editor = EditorTextField(this.content) + editor.setOneLineMode(false) + editor.addSettingsProvider { + it.setFontSize(SettingsState.instance.fontSize) + it.isInsertMode = false + it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0)) + it.settings.isLineNumbersShown = true + it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE + } + + editor.addFocusListener(object : FocusListener { + override fun focusGained(e: FocusEvent?) { + val editor = editor.editor!!.vim + editor.mode = Mode.NORMAL() + } + + override fun focusLost(e: FocusEvent?) { /* Do nothing */ } + }) + + return editor + } + + override fun getPreferredFocusedComponent(): JComponent { + return this.editor + } + + override fun doOKAction() { + save() + super.doOKAction() + } + + override fun doCancelAction() { + save() + super.doCancelAction() + } + + private fun save() { + map = editor.text.split("\n") + .map { entry -> entry.split("=") } + .filter { entry -> entry.size == 2 } + .associate { it[0] to it[1] } + } + + override fun createSouthPanel(): JComponent? { + return null + } + + companion object { + var map: Map? = null + fun open(project: Project) { + val content = TridentMappings.get(project).entries + .joinToString("\n") { "${it.key}=${it.value}" } + val menu = TridentMappingsMenu(content) + menu.show() + map?.let { TridentMappings.set(project, it) } + map = null + } + } +} diff --git a/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt b/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt index 96ab454..5f96bd3 100644 --- a/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt +++ b/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt @@ -1,196 +1,196 @@ -package me.kyren223.trident.utils - -import com.intellij.ide.util.PropertiesComponent -import com.intellij.openapi.project.Project -import com.intellij.openapi.project.guessProjectDir -import com.intellij.openapi.vfs.LocalFileSystem -import com.intellij.openapi.vfs.VirtualFile -import me.kyren223.trident.data.AutomaticMapping -import me.kyren223.trident.data.AutomaticReplacing -import me.kyren223.trident.data.SettingsState - -object TridentList { - private const val PROPERTIES_KEY = "TridentList" - - private fun isValidFile(project: Project, path: String): Boolean { - // Requirements: - // - File must exist on disk after expansion - val expandedPath = TridentMappings.expand(project, path) - return expandedPath.isNotBlank() && LocalFileSystem.getInstance().findFileByPath(expandedPath) != null - } - - private fun getModifiedPath(project: Project, path: String): String { - val automaticMapping = SettingsState.instance.automaticMapping - val automaticReplacing = SettingsState.instance.automaticReplacing - val mappings = TridentMappings.get(project) - - val hasReplacement = automaticReplacing != AutomaticReplacing.Disabled - && mappings.containsValue(path) - - if (hasReplacement) { - return mappings.filterValues { it == path }.keys.firstOrNull()!! - } - - if (automaticMapping == AutomaticMapping.Disabled) { - return if (automaticReplacing == AutomaticReplacing.Smart) { - return smartReplacement(path, mappings) - } else path - } - - return path.split("/") - .lastOrNull() - ?.let { - if (automaticMapping == AutomaticMapping.Filename) { - return@let it - } - val dotIndex = it.lastIndexOf(".") - val filename = if (dotIndex == -1) it else it.substring(0, dotIndex).ifBlank { null } - val extension = if (dotIndex == -1) null else it.substring(dotIndex + 1) - return@let (filename ?: extension)!! - }?.let { - val key = "\$$it" - if (TridentMappings.exists(project, key)) { - return@let null - } - TridentMappings.append(project, key, path) - return@let key - } ?: (if (automaticReplacing == AutomaticReplacing.Smart) smartReplacement(path, mappings) else path) - } - - private fun smartReplacement(path: String, mappings: Map): String { - // This is technically redundant, - // The smart path is sorted based on length, so the longest path will be the first - // And the longest path will be the first path that exactly matches - val exactPath = mappings.filter { it.value == path }.keys.firstOrNull() - exactPath?.let { return it } - - var smartPath = path - for ((key, value) in mappings - .toList() - .sortedByDescending { it.second.length } - .associate { it.first to it.second }) { - smartPath = smartPath.replace(value, key) - } - return smartPath - } - - fun append(project: Project, file: VirtualFile) { - println("TridentList.append - file: ${file.path}") - val files = get(project).toMutableList() - val path = getModifiedPath(project, file.path) - println("TridentList.append - path: $path") - files.add(path) - println("TridentList.append - add: " + files.joinToString(", ")) - set(project, files) - println("TridentList.append - set") - - println("TridentList.append - TridentList: " + get(project).joinToString(", ")) - println("TridentList.append - TridentMappings: " + TridentMappings.get(project) - .map { "${it.key}=${it.value}" } - .joinToString(", ")) - } - - fun set(project: Project, files: List) { - val properties = PropertiesComponent.getInstance(project) - val list = files.filter { isValidFile(project, it) } - properties.setList(PROPERTIES_KEY, list) - } - - fun get(project: Project): List { - val properties = PropertiesComponent.getInstance(project) - return properties.getList(PROPERTIES_KEY) ?: emptyList() - } - - private fun getFiles(project: Project): List { - return get(project) - .map { TridentMappings.expand(project, it) } - .mapNotNull { LocalFileSystem.getInstance().findFileByPath(it) } - } - - fun getIndexOfFile(project: Project, file: VirtualFile): Int? { - val files = getFiles(project) - return files.indexOfFirst { it.path == file.path }.takeUnless { it == -1 } - } - - fun select(project: Project, index: Int): VirtualFile? { - val cycle = SettingsState.instance.indexCycling - val count = getFiles(project).size - val i = if (cycle) ((index % count) + count) % count else index - val files = getFiles(project) - return files.getOrNull(i) - } -} - -object TridentMappings { - private const val PROPERTIES_KEY = "TridentMappings" - - private fun isValidEntry(key: String, value: String): Boolean { - // Requirements: - // - Key and value must not be blank - // - key must start with $ - // - key must only contain alphanumeric characters, underscores, hyphens, and dots - // - value must not contain = - return key.isNotBlank() && value.isNotBlank() && - key.matches(Regex("""^\$[a-zA-Z0-9_.\-]+$""")) && - value.matches(Regex("""^[^=]+$""")) - } - - fun append(project: Project, key: String, value: String, overwrite: Boolean = false) { - println("TridentMappings.append - key: $key, value: $value") - val map = get(project).toMutableMap() - if (map.containsKey(key) && !overwrite) return - println("TridentMappings.append - map: $map") - map[key] = value - println("TridentMappings.append - map after: $map") - set(project, map) - println("TridentMappings.append - set: ${get(project).map { "${it.key}=${it.value}" }.joinToString(", ")}") - } - - fun set(project: Project, mappings: Map) { - val properties = PropertiesComponent.getInstance(project) - - val list = mappings - .filter { isValidEntry(it.key, it.value) } - .map { "${it.key}=${it.value}" } - .toMutableList() - - properties.setList(PROPERTIES_KEY, list) - } - - fun get(project: Project): Map { - val properties = PropertiesComponent.getInstance(project) - val list = properties.getList(PROPERTIES_KEY) ?: return emptyMap() - val map = list - .map { it.split("=") } - .associate { it[0] to it[1] } - .toMutableMap() - project.guessProjectDir()?.let { - map["..."] = it.path - map["\$project"] = it.path - } - return map - } - - fun expand(project: Project, path: String): String { - val recursive = SettingsState.instance.recursiveMapping - val mappings = get(project).toList().sortedByDescending { it.first.length } - var expandedPath = path - while (true) { - var expanded = false - mappings.forEach { (key, value) -> - val expansion = expandedPath.replace(key, value) - if (expansion != expandedPath) { - expandedPath = expansion - expanded = true - } - } - if (!recursive || !expanded) break - } - - return expandedPath - } - - fun exists(project: Project, key: String): Boolean { - return get(project).containsKey(key) - } +package me.kyren223.trident.utils + +import com.intellij.ide.util.PropertiesComponent +import com.intellij.openapi.project.Project +import com.intellij.openapi.project.guessProjectDir +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.openapi.vfs.VirtualFile +import me.kyren223.trident.data.AutomaticMapping +import me.kyren223.trident.data.AutomaticReplacing +import me.kyren223.trident.data.SettingsState + +object TridentList { + private const val PROPERTIES_KEY = "TridentList" + + private fun isValidFile(project: Project, path: String): Boolean { + // Requirements: + // - File must exist on disk after expansion + val expandedPath = TridentMappings.expand(project, path) + return expandedPath.isNotBlank() && LocalFileSystem.getInstance().findFileByPath(expandedPath) != null + } + + private fun getModifiedPath(project: Project, path: String): String { + val automaticMapping = SettingsState.instance.automaticMapping + val automaticReplacing = SettingsState.instance.automaticReplacing + val mappings = TridentMappings.get(project) + + val hasReplacement = automaticReplacing != AutomaticReplacing.Disabled + && mappings.containsValue(path) + + if (hasReplacement) { + return mappings.filterValues { it == path }.keys.firstOrNull()!! + } + + if (automaticMapping == AutomaticMapping.Disabled) { + return if (automaticReplacing == AutomaticReplacing.Smart) { + return smartReplacement(path, mappings) + } else path + } + + return path.split("/") + .lastOrNull() + ?.let { + if (automaticMapping == AutomaticMapping.Filename) { + return@let it + } + val dotIndex = it.lastIndexOf(".") + val filename = if (dotIndex == -1) it else it.substring(0, dotIndex).ifBlank { null } + val extension = if (dotIndex == -1) null else it.substring(dotIndex + 1) + return@let (filename ?: extension)!! + }?.let { + val key = "\$$it" + if (TridentMappings.exists(project, key)) { + return@let null + } + TridentMappings.append(project, key, path) + return@let key + } ?: (if (automaticReplacing == AutomaticReplacing.Smart) smartReplacement(path, mappings) else path) + } + + private fun smartReplacement(path: String, mappings: Map): String { + // This is technically redundant, + // The smart path is sorted based on length, so the longest path will be the first + // And the longest path will be the first path that exactly matches + val exactPath = mappings.filter { it.value == path }.keys.firstOrNull() + exactPath?.let { return it } + + var smartPath = path + for ((key, value) in mappings + .toList() + .sortedByDescending { it.second.length } + .associate { it.first to it.second }) { + smartPath = smartPath.replace(value, key) + } + return smartPath + } + + fun append(project: Project, file: VirtualFile) { + println("TridentList.append - file: ${file.path}") + val files = get(project).toMutableList() + val path = getModifiedPath(project, file.path) + println("TridentList.append - path: $path") + files.add(path) + println("TridentList.append - add: " + files.joinToString(", ")) + set(project, files) + println("TridentList.append - set") + + println("TridentList.append - TridentList: " + get(project).joinToString(", ")) + println("TridentList.append - TridentMappings: " + TridentMappings.get(project) + .map { "${it.key}=${it.value}" } + .joinToString(", ")) + } + + fun set(project: Project, files: List) { + val properties = PropertiesComponent.getInstance(project) + val list = files.filter { isValidFile(project, it) } + properties.setList(PROPERTIES_KEY, list) + } + + fun get(project: Project): List { + val properties = PropertiesComponent.getInstance(project) + return properties.getList(PROPERTIES_KEY) ?: emptyList() + } + + private fun getFiles(project: Project): List { + return get(project) + .map { TridentMappings.expand(project, it) } + .mapNotNull { LocalFileSystem.getInstance().findFileByPath(it) } + } + + fun getIndexOfFile(project: Project, file: VirtualFile): Int? { + val files = getFiles(project) + return files.indexOfFirst { it.path == file.path }.takeUnless { it == -1 } + } + + fun select(project: Project, index: Int): VirtualFile? { + val cycle = SettingsState.instance.indexCycling + val count = getFiles(project).size + val i = if (cycle) ((index % count) + count) % count else index + val files = getFiles(project) + return files.getOrNull(i) + } +} + +object TridentMappings { + private const val PROPERTIES_KEY = "TridentMappings" + + private fun isValidEntry(key: String, value: String): Boolean { + // Requirements: + // - Key and value must not be blank + // - key must start with $ + // - key must only contain alphanumeric characters, underscores, hyphens, and dots + // - value must not contain = + return key.isNotBlank() && value.isNotBlank() && + key.matches(Regex("""^\$[a-zA-Z0-9_.\-]+$""")) && + value.matches(Regex("""^[^=]+$""")) + } + + fun append(project: Project, key: String, value: String, overwrite: Boolean = false) { + println("TridentMappings.append - key: $key, value: $value") + val map = get(project).toMutableMap() + if (map.containsKey(key) && !overwrite) return + println("TridentMappings.append - map: $map") + map[key] = value + println("TridentMappings.append - map after: $map") + set(project, map) + println("TridentMappings.append - set: ${get(project).map { "${it.key}=${it.value}" }.joinToString(", ")}") + } + + fun set(project: Project, mappings: Map) { + val properties = PropertiesComponent.getInstance(project) + + val list = mappings + .filter { isValidEntry(it.key, it.value) } + .map { "${it.key}=${it.value}" } + .toMutableList() + + properties.setList(PROPERTIES_KEY, list) + } + + fun get(project: Project): Map { + val properties = PropertiesComponent.getInstance(project) + val list = properties.getList(PROPERTIES_KEY) ?: return emptyMap() + val map = list + .map { it.split("=") } + .associate { it[0] to it[1] } + .toMutableMap() + project.guessProjectDir()?.let { + map["..."] = it.path + map["\$project"] = it.path + } + return map + } + + fun expand(project: Project, path: String): String { + val recursive = SettingsState.instance.recursiveMapping + val mappings = get(project).toList().sortedByDescending { it.first.length } + var expandedPath = path + while (true) { + var expanded = false + mappings.forEach { (key, value) -> + val expansion = expandedPath.replace(key, value) + if (expansion != expandedPath) { + expandedPath = expansion + expanded = true + } + } + if (!recursive || !expanded) break + } + + return expandedPath + } + + fun exists(project: Project, key: String): Boolean { + return get(project).containsKey(key) + } } \ No newline at end of file diff --git a/src/main/kotlin/me/kyren223/trident/utils/Utils.kt b/src/main/kotlin/me/kyren223/trident/utils/Utils.kt index e688dd8..d9b4f34 100644 --- a/src/main/kotlin/me/kyren223/trident/utils/Utils.kt +++ b/src/main/kotlin/me/kyren223/trident/utils/Utils.kt @@ -1,26 +1,16 @@ -package me.kyren223.trident.utils - -import com.maddyhome.idea.vim.api.VimEditor -import com.maddyhome.idea.vim.api.injector -import com.maddyhome.idea.vim.command.MappingMode -import com.maddyhome.idea.vim.command.OperatorArguments -import com.maddyhome.idea.vim.key.MappingOwner -import com.maddyhome.idea.vim.state.mode.Mode - -fun setEditorMode(editor: VimEditor, mode: Mode) { - val context = injector.executionContextManager.onEditor(editor, null) - val operatorArguments = OperatorArguments(false, 0, mode) - editor.exitInsertMode(context, operatorArguments) - editor.vimChangeActionSwitchMode = Mode.NORMAL() -} - -fun injectEnterToSelectMapping() { - injector.keyGroup.putKeyMapping( - MappingMode.NV, - injector.parser.parseKeys(""), - MappingOwner.Plugin.get("Trident"), - injector.parser.parseKeys(":action TridentListSelect"), - false - ) -} - +package me.kyren223.trident.utils + +import com.maddyhome.idea.vim.api.injector +import com.maddyhome.idea.vim.command.MappingMode +import com.maddyhome.idea.vim.key.MappingOwner + +fun injectEnterToSelectMapping() { + injector.keyGroup.putKeyMapping( + MappingMode.NV, + injector.parser.parseKeys(""), + MappingOwner.Plugin.get("Trident"), + injector.parser.parseKeys(":action TridentListSelect"), + false + ) +} + diff --git a/src/main/resources/META-INF/Trident-IdeaVim.xml b/src/main/resources/META-INF/Trident-IdeaVim.xml index 164f46c..b72ce85 100644 --- a/src/main/resources/META-INF/Trident-IdeaVim.xml +++ b/src/main/resources/META-INF/Trident-IdeaVim.xml @@ -1,2 +1,2 @@ - - + + diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index e52e798..60095a7 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,133 +1,133 @@ - - - - me.kyren223.trident - - - Trident - - - Kyren223 - - - Trident - Trident is a plugin for JetBrains IDEs that provides a fast and intuitive
- way to navigate between files effortlessly.
-
- The plugin is inspired by the "Harpoon" plugin made
- by ThePrimeagen for Neovim.
-
- Trident aims to bring the same experience to JetBrains IDEs.
- but with additional features and proper integration with the IDE.
-
- Want to help contribute to the project?
- Source code: GitHub Repo
- ]]>
- - - com.intellij.modules.platform - IdeaVIM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + me.kyren223.trident + + + Trident + + + Kyren223 + + + Trident + Trident is a plugin for JetBrains IDEs that provides a fast and intuitive
+ way to navigate between files effortlessly.
+
+ The plugin is inspired by the "Harpoon" plugin made
+ by ThePrimeagen for Neovim.
+
+ Trident aims to bring the same experience to JetBrains IDEs.
+ but with additional features and proper integration with the IDE.
+
+ Want to help contribute to the project?
+ Source code: GitHub Repo
+ ]]>
+ + + com.intellij.modules.platform + IdeaVIM + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/src/main/resources/META-INF/pluginIcon.svg b/src/main/resources/META-INF/pluginIcon.svg index e79cf98..1bcfd45 100644 --- a/src/main/resources/META-INF/pluginIcon.svg +++ b/src/main/resources/META-INF/pluginIcon.svg @@ -1,26 +1,26 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.3.1