Repository: hsz/idea-latex Branch: master Commit: a84ec8e09acb Files: 89 Total size: 209.4 KB Directory structure: gitextract_dd7s0pn4/ ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── resources/ │ ├── META-INF/ │ │ └── plugin.xml │ ├── bnf/ │ │ └── Latex.bnf │ ├── codeStyle/ │ │ └── preview/ │ │ ├── blank_lines_settings.tex.ft │ │ ├── indent_settings.tex.ft │ │ ├── spacing_settings.tex.ft │ │ └── wrapping_and_braces_settings.tex.ft │ ├── colorSchemes/ │ │ ├── LatexDarcula.xml │ │ └── LatexDefault.xml │ ├── fileTemplates/ │ │ └── j2ee/ │ │ ├── article.tex.ft │ │ ├── book.tex.ft │ │ ├── empty.tex.ft │ │ ├── letter.tex.ft │ │ ├── presentation.tex.ft │ │ └── report.tex.ft │ ├── messages/ │ │ └── LatexBundle.properties │ └── sample.tex ├── settings.gradle └── src/ └── mobi/ └── hsz/ └── idea/ └── latex/ ├── LatexApplicationComponent.java ├── LatexBundle.java ├── LatexUpdateComponent.java ├── actions/ │ ├── CreateLatexFileAction.java │ ├── LatexTemplates.java │ ├── LatexTemplatesFactory.java │ └── editor/ │ ├── AlignCenterAction.java │ ├── AlignLeftAction.java │ ├── AlignRightAction.java │ ├── BoldAction.java │ ├── ImageAction.java │ ├── ItalicAction.java │ ├── MatrixAction.java │ ├── TableAction.java │ ├── UnderlineAction.java │ └── base/ │ ├── DialogEditorAction.java │ ├── EditorAction.java │ ├── EditorActionsFactory.java │ ├── InsertEditorAction.java │ └── WrapEditorAction.java ├── codeStyle/ │ ├── LatexCodeStyleMainPanel.java │ ├── LatexCodeStyleSettings.java │ ├── LatexCodeStyleSettingsProvider.java │ └── LatexLanguageCodeStyleSettingsProvider.java ├── editor/ │ ├── LatexEditorActionsLoaderComponent.java │ └── LatexEditorActionsWrapper.java ├── file/ │ ├── LatexFileType.java │ └── LatexFileTypeFactory.java ├── folding/ │ └── LatexFoldingBuilder.java ├── highlighter/ │ ├── LatexColorSettingsPage.java │ ├── LatexHighlighter.java │ ├── LatexHighlighterColors.java │ └── LatexHighlighterFactory.java ├── inspections/ │ └── LatexSpellcheckingStrategy.java ├── lang/ │ ├── LatexBraceMatcher.java │ ├── LatexCommenter.java │ ├── LatexLanguage.java │ └── LatexParserDefinition.java ├── lexer/ │ ├── Latex.flex │ └── LatexLexerAdapter.java ├── parser/ │ └── LatexParserUtil.java ├── psi/ │ ├── LatexArgumentElement.java │ ├── LatexElementImpl.java │ ├── LatexElementType.java │ ├── LatexFile.java │ ├── LatexTokenType.java │ └── impl/ │ ├── LatexArgumentExtImpl.java │ ├── LatexInstructionExtImpl.java │ └── LatexSectionExtImpl.java ├── reference/ │ └── LatexReferenceContributor.java ├── settings/ │ └── LatexSettings.java ├── ui/ │ ├── ImageEditorActionDialog.form │ ├── ImageEditorActionDialog.java │ ├── MatrixEditorActionDialog.form │ ├── MatrixEditorActionDialog.java │ ├── TableEditorActionDialog.form │ └── TableEditorActionDialog.java └── util/ ├── Icons.java ├── Listenable.java ├── Resources.java └── Utils.java ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ .idea/ *.iml out/ gen/ build/ build.properties junit*.properties .gradle ================================================ FILE: .travis.yml ================================================ # Configuration for CI build at https://travis-ci.org/hsz/idea-latex language: java jdk: - oraclejdk8 env: - IDEA_VERSION=2017.2 - IDEA_VERSION=2017.1.5 - IDEA_VERSION=2016.3.7 - IDEA_VERSION=2016.2.5 - IDEA_VERSION=2016.1.4 # Workaround for https://github.com/travis-ci/travis-ci/issues/5227 # Buffer overflow in Java_java_net_Inet4AddressImpl_getLocalHostName before_install: - cat /etc/hosts # optionally check the content *before* - sudo hostname "$(hostname | cut -c1-63)" - sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | sudo tee /etc/hosts - cat /etc/hosts # optionally check the content *after* before_cache: - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ after_success: - ./gradlew jacocoTestReport coveralls ================================================ FILE: CHANGELOG.md ================================================ # Change Log ## [v0.2](https://github.com/hsz/idea-latex/tree/v0.2) (2015-01-27) [Full Changelog](https://github.com/hsz/idea-latex/compare/v0.1.1...v0.2) **Implemented enhancements:** - Toolbar actions: bold, italic, underline, align left, align center, align right - Color settings page - Sections folding ## [v0.1.1](https://github.com/hsz/idea-latex/tree/v0.1.1) (2015-01-20) [Full Changelog](https://github.com/hsz/idea-latex/compare/v0.1...v0.1.1) **Fixed bugs:** - Fixed syntax highlighting (better BNF and Flex rules) **Closed issues:** - Installable release version? [\#1](https://github.com/hsz/idea-latex/issues/1) ## [v0.1](https://github.com/hsz/idea-latex/tree/v0.1) (2015-01-16) - Basic syntax highlighting \* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* License ------- Copyright (c) 2017 hsz Jakub Chrzanowski. See the [LICENSE](./LICENSE) file for license rights and limitations (MIT). ================================================ FILE: LICENSE ================================================ The MIT License (MIT) Copyright (c) 2017 hsz Jakub Chrzanowski 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. ================================================ FILE: README.md ================================================ idea-latex v0.3.0 ================= [![Gitter][badge-gitter-img]][badge-gitter] [![Build Status][badge-travis-img]][badge-travis] [![Donate][badge-paypal-img]][badge-paypal] [![Version](http://phpstorm.espend.de/badge/7660/version)][plugin-website] [![Downloads](http://phpstorm.espend.de/badge/7660/downloads)][plugin-website] [![Downloads last month](http://phpstorm.espend.de/badge/7660/last-month)][plugin-website] Introduction ------------ **LaTeX** is a plugin supporting LaTeX in your project. It supports following JetBrains IDEs: - Android Studio - AppCode - IntelliJ IDEA - PhpStorm - PyCharm - RubyMine - WebStorm - 0xDBE *Compiled with Java 1.6* Features -------- - Syntax highlighting - Editor toolbar actions with shortcuts - Code folding *Feature requests:* - *suggesting functions' names* - *obtaining installed packages* - *generating PDF files* - *preview generated PDF files* - *and more...* Installation ------------ - Using IDE built-in plugin system: - Preferences > Plugins > Browse repositories... > Search for "LaTeX" > Install Plugin - Manually: - Download the [latest release][latest-release] and install it manually using Preferences > Plugins > Install plugin from disk... Restart IDE. Usage ----- ### Available shortcuts: | Action name | Output | Shortcut | | ---------------- | ------------------------------------------------------------------------ | ------------------------------------------------ | | *Bold* |
\textbf($SELECTION$)
| Ctrl + L, **B** | | *Italic* |
\textit($SELECTION$)
| Ctrl + L, **I** | | *Underline* |
\underline($SELECTION$)
| Ctrl + L, **U** | | *Align left* |
\begin{flushleft}$SELECTION$\end{flushleft}
| Ctrl + L, **L** | | *Align center* |
\begin{center}$SELECTION$\end{center}
| Ctrl + L, **C** | | *Align right* |
\begin{flushright}$SELECTION$\end{flushright}
| Ctrl + L, **R** | Changelog --------- Version 0.2 - Toolbar actions: bold, italic, underline, align left, align center, align right - Color settings page - Sections folding Version 0.1.1 - Fixed syntax highlighting (better BNF and Flex rules) Version 0.1 - Basic syntax highlighting Developed By ------------ [**@hsz** Jakub Chrzanowski][hsz] **Contributors** - *you can be first on this list* License ------- Copyright (c) 2017 hsz Jakub Chrzanowski. See the [LICENSE](./LICENSE) file for license rights and limitations (MIT). [hsz]: http://hsz.mobi [plugin-website]: https://plugins.jetbrains.com/plugin/7660 [latest-release]: https://github.com/hsz/idea-latex/releases/latest [badge-gitter-img]: https://badges.gitter.im/hsz/idea-latex.svg [badge-gitter]: https://gitter.im/hsz/idea-latex [badge-travis-img]: https://travis-ci.org/hsz/idea-latex.svg [badge-travis]: https://travis-ci.org/hsz/idea-latex [badge-paypal-img]: https://img.shields.io/badge/donate-paypal-yellow.svg [badge-paypal]: https://www.paypal.me/hsz ================================================ FILE: build.gradle ================================================ plugins { id 'org.jetbrains.intellij' version '0.0.43' id 'de.undercouch.download' version '2.1.0' } apply plugin: 'org.jetbrains.intellij' apply plugin: 'java' apply plugin: 'idea' sourceCompatibility = javaVersion targetCompatibility = javaTargetVersion group pluginGroup version = pluginVersion tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } sourceSets { main { java.srcDirs 'src', 'gen' resources.srcDir 'resources' } } intellij { version ideaVersion type ideaType pluginName pluginName downloadSources Boolean.valueOf(sources) sameSinceUntilBuild Boolean.valueOf(isEAP) alternativeIdePath idePath updateSinceUntilBuild false publish { username publishUsername password publishPassword pluginId publishPluginId channel publishChannel } } idea { project { jdkName = javaVersion languageLevel = javaVersion } module { generatedSourceDirs += file('gen') } } // Configurations configurations { bnf jflex } repositories { mavenCentral() } test { testLogging { exceptionFormat = 'full' } } dependencies { bnf files("$buildDir/tools/GrammarKit/lib/grammar-kit.jar") bnf files("$buildDir/tools/light-psi-all.jar") jflex files("$buildDir/tools/JFlex.jar") testCompile group: 'junit', name: 'junit', version: '4.11' } import de.undercouch.gradle.tasks.download.Download // Tasks task downloadJFlexJar(type: Download) { description 'Downloads JFlex.' src 'https://github.com/JetBrains/intellij-community/raw/master/tools/lexer/jflex-1.7.0-SNAPSHOT.jar' dest "$buildDir/tools/JFlex.jar" onlyIf { !file("$buildDir/tools/JFlex.jar").exists() } } task downloadJFlexSkeleton(type: Download) { description 'Downloads JFlex skeleton.' src 'https://raw.github.com/JetBrains/intellij-community/master/tools/lexer/idea-flex.skeleton' dest "$buildDir/tools/idea-flex.skeleton" onlyIf { !file("$buildDir/tools/idea-flex.skeleton").exists() } } task generateLexer(type: JavaExec) { description 'Generates lexer sources with JFlex.' dependsOn downloadJFlexJar, downloadJFlexSkeleton main = 'jflex.Main' args = [ '-skel', "$buildDir/tools/idea-flex.skeleton", '-d', 'gen/mobi/hsz/idea/latex/lexer/', 'src/mobi/hsz/idea/latex/lexer/Latex.flex', ] classpath = configurations.jflex } task downloadGrammarKit(type: Download) { description 'Downloads GrammarKit.' src 'https://github.com/JetBrains/Grammar-Kit/releases/download/1.2.0.1/GrammarKit.zip' dest "$buildDir/tools/GrammarKit.zip" onlyIfNewer true } task downloadGrammarLightPsi(type: Download) { description 'Downloads GrammarKit Light Psi.' src 'https://github.com/JetBrains/Grammar-Kit/releases/download/1.2.0.1/light-psi-all.jar' dest "$buildDir/tools/light-psi-all.jar" onlyIfNewer true } task unzipGrammarKit(type: Copy) { description 'Extracts GrammarKit files.' dependsOn downloadGrammarKit from zipTree("$buildDir/tools/GrammarKit.zip") into "${buildDir}/tools/" include "GrammarKit/lib/*" } task generateParser(type: JavaExec) { description 'Generates parser sources with GrammarKit.' dependsOn unzipGrammarKit, downloadGrammarLightPsi main = 'org.intellij.grammar.Main' args = [ 'gen', 'resources/bnf/Latex.bnf' ] classpath = configurations.bnf + configurations.compile } task generateSources() { dependsOn generateParser, generateLexer } clean.doFirst { delete 'gen', 'out' } compileJava.dependsOn generateSources ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ #Mon Apr 11 22:05:01 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-all.zip ================================================ FILE: gradle.properties ================================================ # Available idea versions: # https://www.jetbrains.com/intellij-repository/releases # https://www.jetbrains.com/intellij-repository/snapshots ideaVersion = 2017.1.5 ideaType = IC javaVersion = 1.6 javaTargetVersion = 1.6 javaArguments = -agentpath:/home/hsz/IDE/yjp-2017.02/bin/linux-x86-64/libyjpagent.so sources = true isEAP = false runGenerators = true pluginGroup = mobi.hsz.idea pluginName = LaTeX pluginVersion = 0.3.0 publishPluginId = 7660 publishUsername = hsz publishPassword = publishChannel = org.gradle.jvmargs=-XX:MaxPermSize=512m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=utf-8 JDK6_HOME=/usr/lib/jvm/java-6-jdk/ idePath = ================================================ FILE: gradlew ================================================ #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null 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" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ================================================ FILE: gradlew.bat ================================================ @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 @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= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @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 init 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 init 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 :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :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 %CMD_LINE_ARGS% :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 ================================================ FILE: resources/META-INF/plugin.xml ================================================ mobi.hsz.idea.latex LaTeX 0.3.0 hsz LaTeX plugin for IntelliJ IDEA
GitHub | Issues | Donate ( PayPal or BTC )

Features
  • Syntax highlighting
  • Editor toolbar actions with shortcuts
  • Code folding
Feature requests:
  • suggesting functions' names
  • obtaining installed packages
  • generating PDF files
  • preview generated PDF files
  • and more...


Compiled with Java 1.6

]]>
  • Toolbar actions: bold, italic, underline, align left, align center, align right
  • Color settings page
  • Sections folding
  • Version 0.1.1
    • Fixed syntax highlighting (better BNF and Flex rules)
    Version 0.1
    • Basic syntax highlighting
    ]]>
    com.intellij.modules.lang messages.LatexBundle mobi.hsz.idea.latex.LatexApplicationComponent mobi.hsz.idea.latex.editor.LatexEditorActionsLoaderComponent mobi.hsz.idea.latex.LatexUpdateComponent
    ================================================ FILE: resources/bnf/Latex.bnf ================================================ { parserClass = "mobi.hsz.idea.latex.parser.LatexParser" parserUtilClass = "mobi.hsz.idea.latex.parser.LatexParserUtil" extends = "mobi.hsz.idea.latex.psi.LatexElementImpl" psiClassPrefix = "Latex" psiImplClassSuffix = "Impl" psiPackage = "mobi.hsz.idea.latex.psi" psiImplPackage = "mobi.hsz.idea.latex.psi.impl" elementTypeHolderClass = "mobi.hsz.idea.latex.psi.LatexTypes" elementTypeClass = "mobi.hsz.idea.latex.psi.LatexElementType" tokenTypeClass = "mobi.hsz.idea.latex.psi.LatexTokenType" tokens = [ LBRACE = "{" RBRACE = "}" LBRACKET = "[" RBRACKET = "]" LPAREN = "(" RPAREN = ")" COMMA = "," COLON = ":" ASTERISK = "*" LINE_BREAK = '\\' IDENTIFIER_BEGIN = '\begin' IDENTIFIER_END = '\end' IDENTIFIER = "regexp:\\\p{Alpha}+" ARG = "regexp:\b([^\[\]\{\}\(\),\\])+\b" COMMENT = "regexp:%.*" SPECIAL = "regexp:[\S]|\\." CRLF = "regexp:[\s\r\n]+" ] extends("instruction.*") = instruction name("instruction.*") = instruction mixin("instruction.*") = "mobi.hsz.idea.latex.psi.impl.LatexInstructionExtImpl" mixin("section") = "mobi.hsz.idea.latex.psi.impl.LatexSectionExtImpl" mixin("argument") = "mobi.hsz.idea.latex.psi.impl.LatexArgumentExtImpl" implements("argument") = "mobi.hsz.idea.latex.psi.LatexArgumentElement" } latexFile ::= item_ * private item_ ::= !<> expr * { pin = 1 } private expr ::= section | instruction | argument_group | text | SPECIAL | CRLF | LINE_BREAK section ::= instruction_begin expr * instruction_end { pin = 1 } instruction_begin ::= IDENTIFIER_BEGIN argument_brace argument_brace * { pin = 1 } instruction_end ::= IDENTIFIER_END argument_brace { pin = 1 } instruction ::= IDENTIFIER ASTERISK ? argument_group * { pin = 1 } text ::= ( ARG special_expr ? ) + private argument_group ::= argument_bracket | argument_brace | argument_paren private argument_expr ::= ( special_expr * ( ARG | section | instruction ) special_expr * ) * { pin(".*") = 2 } private special_expr ::= SPECIAL | COLON | COMMA | LINE_BREAK | CRLF meta argument_bracket ::= LBRACKET argument ? RBRACKET { pin(".*") = 1 elementType = argument } meta argument_brace ::= LBRACE argument ? RBRACE { pin(".*") = 1 elementType = argument } meta argument_paren ::= LPAREN argument ? RPAREN { pin(".*") = 1 elementType = argument } meta argument ::= <> private meta sequence ::= <

    > (<> <

    >) * { pin(".*") = 1 } ================================================ FILE: resources/codeStyle/preview/blank_lines_settings.tex.ft ================================================ blank_lines_settings file ================================================ FILE: resources/codeStyle/preview/indent_settings.tex.ft ================================================ indent_settings file ================================================ FILE: resources/codeStyle/preview/spacing_settings.tex.ft ================================================ spacing_settings file ================================================ FILE: resources/codeStyle/preview/wrapping_and_braces_settings.tex.ft ================================================ wrapping_and_braces_settings file ================================================ FILE: resources/colorSchemes/LatexDarcula.xml ================================================ ================================================ FILE: resources/colorSchemes/LatexDefault.xml ================================================ ================================================ FILE: resources/fileTemplates/j2ee/article.tex.ft ================================================ \documentclass[a4paper,11pt]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \title{} \author{} \begin{document} \maketitle \tableofcontents \begin{abstract} \end{abstract} \section{} \end{document} ================================================ FILE: resources/fileTemplates/j2ee/book.tex.ft ================================================ \documentclass[a4paper,11pt]{book} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \title{} \author{} \begin{document} \maketitle \tableofcontents \chapter{} \end{document} ================================================ FILE: resources/fileTemplates/j2ee/empty.tex.ft ================================================ ================================================ FILE: resources/fileTemplates/j2ee/letter.tex.ft ================================================ \documentclass[a4paper,11pt]{letter} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \address{Your name\\Your address\\Your phone number} \signature{Your name} \begin{document} \begin{letter}{Destination\\Address of the destination\\Phone number of the destination} \opening{Dear Sir,} % corps of the letter \closing{Yours sincerely,} %\cc{Other destination} %\ps{PS: PostScriptum} %\encl{Enclosures} \end{letter} \end{document} ================================================ FILE: resources/fileTemplates/j2ee/presentation.tex.ft ================================================ \documentclass{beamer} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \title{} \author{} \begin{document} \begin{frame} \titlepage \end{frame} \end{document} ================================================ FILE: resources/fileTemplates/j2ee/report.tex.ft ================================================ \documentclass[a4paper,11pt]{report} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{lmodern} \title{} \author{} \begin{document} \maketitle \tableofcontents \begin{abstract} \end{abstract} \chapter{} \end{document} ================================================ FILE: resources/messages/LatexBundle.properties ================================================ editor.align_left=Align left editor.align_right=Align right editor.align_center=Align center editor.bold=Bold editor.image=Insert image editor.image.dialog.browse=LaTeX - Browse Image editor.image.dialog.title=LaTeX - Insert Image editor.italic=Italic editor.matrix=Insert matrix editor.matrix.dialog.title=LaTeX - Insert Matrix editor.table=Insert table editor.table.dialog.title=LaTeX - Insert Table editor.underline=Underline colorSettings.displayName=LaTeX highlighter.instruction=Instruction highlighter.argument=Argument highlighter.bracket=Brackets highlighter.comment=Comment folding.placeholder=... form.rows=Rows\: form.columns=Columns\: form.alignment=Alignment\: form.alignment.left=left form.alignment.center=center form.alignment.right=right form.border=Border\: form.border.none=none form.border.table=table form.border.cell=cell form.bracket=Bracket\: form.bracket.none=none form.bracket.parentheses=parentheses form.bracket.brackets=brackets form.bracket.braces=braces form.bracket.single_line=single line form.bracket.double_line=double line action.create.file=LaTeX file action.create.file.description=Creates new LaTeX file action.create.file.kind.empty=empty action.create.file.kind.article=article action.create.file.kind.report=report action.create.file.kind.book=book action.create.file.kind.letter=letter action.create.file.kind.presentation=presentation file.template.group.title=LaTeX update.title=LaTeX plugin updated to v{0} notification.update.content=
    \ If you find my plugin helpful, Donate with PayPal

    \ Features:
    \ - ... (0)
    \
    \ Fixes:
    \ - ... (0)
    \
    \ If you find my plugin helpful, donate me using
    Donate with PayPal ================================================ FILE: resources/sample.tex ================================================ \documentclass[12pt]{article} \usepackage{amsmath} \title{\LaTeX} \date{} \begin{document} \maketitle \LaTeX{} is a document preparation system for the \TeX{} typesetting program. It offers programmable desktop publishing features and extensive facilities for automating most aspects of typesetting and desktop publishing, including numbering and cross-referencing, tables and figures, page layout, bibliographies, and much more. \LaTeX{} was originally written in 1984 by Leslie Lamport and has become the dominant method for using \TeX; few people write in plain \TeX{} anymore. The current version is \LaTeXe. % This is a comment, not shown in final output. % The following shows typesetting power of LaTeX: \begin{align} E_0 &= mc^2 \\ E &= \frac{mc^2}{\sqrt{1-\frac{v^2}{c^2}}} \end{align} \end{document} ================================================ FILE: settings.gradle ================================================ rootProject.name = 'idea-latex' ================================================ FILE: src/mobi/hsz/idea/latex/LatexApplicationComponent.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2017 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ApplicationComponent; import mobi.hsz.idea.latex.settings.LatexSettings; import mobi.hsz.idea.latex.util.Utils; import org.jetbrains.annotations.NotNull; /** * @author Jakub Chrzanowski * @since 0.3.0 */ public class LatexApplicationComponent implements ApplicationComponent { /** Plugin has been updated with the current run. */ private boolean updated; /** Plugin update notification has been shown. */ private boolean updateNotificationShown; /** * Get Ignore Application Component * * @return Ignore Application Component */ @NotNull public static LatexApplicationComponent getInstance() { return ApplicationManager.getApplication().getComponent(LatexApplicationComponent.class); } /** Component initialization method. */ @Override public void initComponent() { /* The settings storage object. */ LatexSettings settings = LatexSettings.getInstance(); updated = !Utils.getVersion().equals(settings.getVersion()); if (updated) { settings.setVersion(Utils.getVersion()); } } /** Component dispose method. */ @Override public void disposeComponent() { } /** * Returns component's name. * * @return component's name */ @NotNull @Override public String getComponentName() { return "LatexApplicationComponent"; } /** * Checks if plugin was updated in the current run. * * @return plugin was updated */ public boolean isUpdated() { return updated; } /** * Checks if update notification was shown. * * @return notification shown */ public boolean isUpdateNotificationShown() { return updateNotificationShown; } /** * Sets update notification shown status. * * @param shown notification */ public void setUpdateNotificationShown(boolean shown) { this.updateNotificationShown = shown; } } ================================================ FILE: src/mobi/hsz/idea/latex/LatexBundle.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex; import com.intellij.CommonBundle; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.PropertyKey; import java.util.ResourceBundle; /** * {@link java.util.ResourceBundle}/localization utils for the LaTeX plugin. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexBundle { /** Gitignore plugin ID. */ @NonNls public static final String PLUGIN_ID = "mobi.hsz.idea.latex"; /** The {@link java.util.ResourceBundle} path. */ @NonNls private static final String BUNDLE_NAME = "messages.LatexBundle"; /** The {@link java.util.ResourceBundle} instance. */ private static final ResourceBundle BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); /** Plugin name. */ @NonNls public static final String NAME = "LaTeX"; /** {@link LatexBundle} is a non-instantiable static class. */ private LatexBundle() { } /** * Loads a {@link String} from the {@link #BUNDLE} {@link java.util.ResourceBundle}. * * @param key the key of the resource * @param params the optional parameters for the specific resource * @return the {@link String} value or {@code null} if no resource found for the key */ public static String message(@PropertyKey(resourceBundle = BUNDLE_NAME) String key, Object... params) { return CommonBundle.message(BUNDLE, key, params); } /** * Loads a {@link String} from the {@link #BUNDLE} {@link java.util.ResourceBundle}. * * @param key the key of the resource * @param defaultValue the default value that will be returned if there is nothing set * @param params the optional parameters for the specific resource * @return the {@link String} value or {@code null} if no resource found for the key */ public static String messageOrDefault(@PropertyKey(resourceBundle = BUNDLE_NAME) String key, String defaultValue, Object... params) { return CommonBundle.messageOrDefault(BUNDLE, key, defaultValue, params); } } ================================================ FILE: src/mobi/hsz/idea/latex/LatexUpdateComponent.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2017 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex; import com.intellij.notification.*; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.project.Project; import mobi.hsz.idea.latex.lang.LatexLanguage; import mobi.hsz.idea.latex.util.Utils; import org.jetbrains.annotations.NotNull; /** * {@link ProjectComponent} instance to display plugin's update information. * * @author Jakub Chrzanowski * @since 0.3.0 */ public class LatexUpdateComponent extends AbstractProjectComponent { /** {@link LatexApplicationComponent} instance. */ private LatexApplicationComponent application; /** Constructor. */ protected LatexUpdateComponent(Project project) { super(project); } /** Component initialization method. */ @Override public void initComponent() { application = LatexApplicationComponent.getInstance(); } /** Component dispose method. */ @Override public void disposeComponent() { } /** * Returns component's name. * * @return component's name */ @NotNull @Override public String getComponentName() { return "LatexUpdateComponent"; } /** Method called when project is opened. */ @Override public void projectOpened() { if (application.isUpdated() && !application.isUpdateNotificationShown()) { application.setUpdateNotificationShown(true); NotificationGroup group = new NotificationGroup(LatexLanguage.GROUP, NotificationDisplayType.TOOL_WINDOW, true); Notification notification = group.createNotification( LatexBundle.message("update.title", Utils.getVersion()), LatexBundle.message("update.content"), NotificationType.INFORMATION, NotificationListener.URL_OPENING_LISTENER ); Notifications.Bus.notify(notification, myProject); } } /** Method called when project is closed. */ @Override public void projectClosed() { } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/CreateLatexFileAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions; import com.intellij.ide.actions.CreateFileFromTemplateDialog; import com.intellij.ide.actions.CreateFromTemplateAction; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.lang.LatexLanguage; import mobi.hsz.idea.latex.psi.LatexFile; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.Nullable; /** * New file action * * @author Jakub Chrzanowski * @since 0.3 */ public class CreateLatexFileAction extends CreateFromTemplateAction implements DumbAware { public CreateLatexFileAction() { super(LatexBundle.message("action.create.file"), LatexBundle.message("action.create.file.description"), Icons.FILE); } @Override protected String getDefaultTemplateProperty() { return LatexTemplates.LATEX_EMPTY; } @Nullable @Override protected LatexFile createFile(String name, String templateName, PsiDirectory dir) { String filename = name.endsWith("." + LatexLanguage.EXTENSION) ? name : name + "." + LatexLanguage.EXTENSION; return LatexTemplatesFactory.createFromTemplate(dir, name, filename, templateName, true); } @Override protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) { builder .setTitle(LatexBundle.message("action.create.file")) .addKind(LatexBundle.message("action.create.file.kind.empty"), Icons.FILE, LatexTemplates.LATEX_EMPTY) .addKind(LatexBundle.message("action.create.file.kind.article"), Icons.FILE, LatexTemplates.LATEX_ARTICLE) .addKind(LatexBundle.message("action.create.file.kind.report"), Icons.FILE, LatexTemplates.LATEX_REPORT) .addKind(LatexBundle.message("action.create.file.kind.book"), Icons.FILE, LatexTemplates.LATEX_BOOK) .addKind(LatexBundle.message("action.create.file.kind.letter"), Icons.FILE, LatexTemplates.LATEX_LETTER) .addKind(LatexBundle.message("action.create.file.kind.presentation"), Icons.FILE, LatexTemplates.LATEX_PRESENTATION); } @Override protected String getActionName(PsiDirectory directory, String newName, String templateName) { return LatexBundle.message("action.create.file"); } @Override public boolean equals(Object obj) { return obj instanceof CreateLatexFileAction; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/LatexTemplates.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions; import org.jetbrains.annotations.NonNls; /** * LaTeX files templates. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexTemplates { @NonNls public static final String LATEX_EMPTY = "empty.tex"; @NonNls public static final String LATEX_ARTICLE = "article.tex"; @NonNls public static final String LATEX_REPORT = "report.tex"; @NonNls public static final String LATEX_BOOK = "book.tex"; @NonNls public static final String LATEX_LETTER = "letter.tex"; @NonNls public static final String LATEX_PRESENTATION = "presentation.tex"; } ================================================ FILE: src/mobi/hsz/idea/latex/actions/LatexTemplatesFactory.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions; import com.intellij.codeInsight.actions.ReformatCodeProcessor; import com.intellij.ide.fileTemplates.*; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.file.LatexFileType; import mobi.hsz.idea.latex.psi.LatexFile; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; import java.util.Properties; /** * LaTeX files templates factory. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexTemplatesFactory implements FileTemplateGroupDescriptorFactory { @NonNls public static final String[] TEMPLATES = { LatexTemplates.LATEX_EMPTY, LatexTemplates.LATEX_ARTICLE, LatexTemplates.LATEX_REPORT, LatexTemplates.LATEX_BOOK, LatexTemplates.LATEX_LETTER, LatexTemplates.LATEX_PRESENTATION, }; private final ArrayList myCustomTemplates = new ArrayList(); private static class LatexTemplatesFactoryHolder { private static final LatexTemplatesFactory myInstance = new LatexTemplatesFactory(); } public static LatexTemplatesFactory getInstance() { return LatexTemplatesFactoryHolder.myInstance; } public void registerCustromTemplates(String... templates) { Collections.addAll(myCustomTemplates, templates); } @Override public FileTemplateGroupDescriptor getFileTemplatesDescriptor() { final FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor(LatexBundle.message("file.template.group.title"), Icons.FILE); final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (String template : TEMPLATES) { group.addTemplate(new FileTemplateDescriptor(template, fileTypeManager.getFileTypeByFileName(template).getIcon())); } // register custom templates for (String template : getInstance().getCustomTemplates()) { group.addTemplate(new FileTemplateDescriptor(template, fileTypeManager.getFileTypeByFileName(template).getIcon())); } return group; } public static LatexFile createFromTemplate(@NotNull final PsiDirectory directory, @NotNull final String name, @NotNull String fileName, @NotNull String templateName, boolean allowReformatting, @NonNls String... parameters) throws IncorrectOperationException { final FileTemplate template = FileTemplateManager.getInstance(directory.getProject()).getInternalTemplate(templateName); Project project = directory.getProject(); Properties properties = new Properties(FileTemplateManager.getInstance(project).getDefaultProperties()); // JavaTemplateUtil.setPackageNameAttribute(properties, directory); // properties.setProperty(NAME_TEMPLATE_PROPERTY, name); // properties.setProperty(LOW_CASE_NAME_TEMPLATE_PROPERTY, name.substring(0, 1).toLowerCase() + name.substring(1)); for (int i = 0; i < parameters.length; i += 2) { properties.setProperty(parameters[i], parameters[i + 1]); } String text; try { text = template.getText(properties); } catch (Exception e) { throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance(project).internalTemplateToSubject(templateName), e); } final PsiFileFactory factory = PsiFileFactory.getInstance(project); PsiFile file = factory.createFileFromText(fileName, LatexFileType.INSTANCE, text); file = (PsiFile) directory.add(file); if (file != null && allowReformatting && template.isReformatCode()) { new ReformatCodeProcessor(project, file, null, false).run(); } return (LatexFile) file; } public String[] getCustomTemplates() { return ArrayUtil.toStringArray(myCustomTemplates); } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/AlignCenterAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.WrapEditorAction; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - align center. * * @author Jakub Chrzanowski * @since 0.2 */ public class AlignCenterAction extends WrapEditorAction { /** Builds a new instance of {@link AlignCenterAction}. */ public AlignCenterAction() { super(Type.ALIGN_CENTER, LatexBundle.message("editor.align_center"), Icons.Editor.ALIGN_CENTER); } @NotNull @Override public String getLeftText() { return "\\begin{center}"; } @NotNull @Override public String getRightText() { return "\\end{center}"; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/AlignLeftAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.WrapEditorAction; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - align left. * * @author Jakub Chrzanowski * @since 0.2 */ public class AlignLeftAction extends WrapEditorAction { /** Builds a new instance of {@link AlignLeftAction}. */ public AlignLeftAction() { super(Type.ALIGN_LEFT, LatexBundle.message("editor.align_left"), Icons.Editor.ALIGN_LEFT); } @NotNull @Override public String getLeftText() { return "\\begin{flushleft}"; } @NotNull @Override public String getRightText() { return "\\end{flushleft}"; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/AlignRightAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.WrapEditorAction; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - align right. * * @author Jakub Chrzanowski * @since 0.2 */ public class AlignRightAction extends WrapEditorAction { /** Builds a new instance of {@link AlignRightAction}. */ public AlignRightAction() { super(Type.ALIGN_RIGHT, LatexBundle.message("editor.align_right"), Icons.Editor.ALIGN_RIGHT); } @NotNull @Override public String getLeftText() { return "\\begin{flushright}"; } @NotNull @Override public String getRightText() { return "\\end{flushright}"; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/BoldAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import com.intellij.psi.PsiElement; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.WrapEditorAction; import mobi.hsz.idea.latex.psi.LatexInstruction; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - bold text. * * @author Jakub Chrzanowski * @since 0.2 */ public class BoldAction extends WrapEditorAction { private static final String IDENTIFIER = "\\textbf"; /** Builds a new instance of {@link BoldAction}. */ public BoldAction() { super(Type.BOLD, LatexBundle.message("editor.bold"), Icons.Editor.BOLD); } @Override public boolean isMatching(@NotNull PsiElement element) { return element instanceof LatexInstruction && ((LatexInstruction) element).getIdentifier().getText().equals(IDENTIFIER); } @NotNull @Override public String getLeftText() { return IDENTIFIER + "{"; } @NotNull @Override public String getRightText() { return "}"; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/ImageAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.DialogEditorAction; import mobi.hsz.idea.latex.ui.ImageEditorActionDialog; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - insert image. * * @author Jakub Chrzanowski * @since 0.3 */ public class ImageAction extends DialogEditorAction { /** Builds a new instance of {@link ImageAction}. */ public ImageAction() { super(Type.IMAGE, LatexBundle.message("editor.image"), Icons.Editor.IMAGE); } @NotNull @Override protected ImageEditorActionDialog getDialog(@NotNull Project project) { return new ImageEditorActionDialog(project); } @NotNull @Override protected String getContent(@NotNull ImageEditorActionDialog dialog) { StringBuilder sb = new StringBuilder(); String path = dialog.getPath(); String caption = dialog.getCaption(); String label = dialog.getLabel(); sb.append("\\begin{figure}\n"); sb.append("\\centering\n"); sb.append("\\includegraphics"); sb.append(String.format("{%s}\n", path)); if (!StringUtil.isEmpty(caption)) { sb.append(String.format("\\caption{%s}\n", caption)); } if (!StringUtil.isEmpty(label)) { sb.append(String.format("\\label{%s}\n", label)); } sb.append("\\end{figure}"); return sb.toString(); } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/ItalicAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import com.intellij.psi.PsiElement; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.WrapEditorAction; import mobi.hsz.idea.latex.psi.LatexInstruction; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - italicize text. * * @author Jakub Chrzanowski * @since 0.2 */ public class ItalicAction extends WrapEditorAction { private static final String IDENTIFIER = "\\textit"; /** Builds a new instance of {@link ItalicAction}. */ public ItalicAction() { super(Type.ITALIC, LatexBundle.message("editor.italic"), Icons.Editor.ITALIC); } @Override public boolean isMatching(@NotNull PsiElement element) { return element instanceof LatexInstruction && ((LatexInstruction) element).getIdentifier().getText().equals(IDENTIFIER); } @NotNull @Override public String getLeftText() { return IDENTIFIER + "{"; } @NotNull @Override public String getRightText() { return "}"; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/MatrixAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import com.intellij.openapi.project.Project; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.DialogEditorAction; import mobi.hsz.idea.latex.ui.MatrixEditorActionDialog; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - insert matrix. * * @author Jakub Chrzanowski * @since 0.3 */ public class MatrixAction extends DialogEditorAction { /** Builds a new instance of {@link MatrixAction}. */ public MatrixAction() { super(Type.MATRIX, LatexBundle.message("editor.matrix"), Icons.Editor.MATRIX); } @NotNull @Override protected MatrixEditorActionDialog getDialog(@NotNull Project project) { return new MatrixEditorActionDialog(project); } @NotNull @Override protected String getContent(@NotNull MatrixEditorActionDialog dialog) { StringBuilder sb = new StringBuilder(); int rows = dialog.getRows(); int columns = dialog.getColumns(); char bracket = dialog.getBracket().getValue(); sb.append(String.format("$\\begin{%cmatrix}\n", bracket)); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= columns; j++) { sb.append(String.format("%d%d%s", i, j, j == columns ? "\\\\\n" : " & ")); } } sb.append(String.format("\\end{%cmatrix}", bracket)); return sb.toString(); } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/TableAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.DialogEditorAction; import mobi.hsz.idea.latex.ui.TableEditorActionDialog; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - insert table. * * @author Jakub Chrzanowski * @since 0.3 */ public class TableAction extends DialogEditorAction { /** * Builds a new instance of {@link TableAction}. */ public TableAction() { super(Type.TABLE, LatexBundle.message("editor.table"), Icons.Editor.TABLE); } @NotNull @Override protected TableEditorActionDialog getDialog(@NotNull Project project) { return new TableEditorActionDialog(project); } @NotNull @Override protected String getContent(@NotNull TableEditorActionDialog dialog) { StringBuilder sb = new StringBuilder(); int rows = dialog.getRows(); int columns = dialog.getColumns(); String alignmentValue = StringUtil.repeatSymbol(dialog.getAlignment().getValue(), columns); String tableBorder = dialog.getBorder().isNone() ? "" : "|"; String cellBorder = dialog.getBorder().isCell() ? "\\hline\n" : ""; sb.append(String.format("\\begin{tabular}{%s%s%s}\n", tableBorder, alignmentValue, tableBorder)); sb.append(cellBorder); for (int i = 1; i <= rows; i++) { for (int j = 1; j <= columns; j++) { sb.append(String.format("%d%d%s", i, j, j == columns ? "\\\\\n" : " & ")); } sb.append(cellBorder); } sb.append("\\end{tabular}"); return sb.toString(); } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/UnderlineAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor; import com.intellij.psi.PsiElement; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.actions.editor.base.WrapEditorAction; import mobi.hsz.idea.latex.psi.LatexInstruction; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; /** * Editor action - underline text. * * @author Jakub Chrzanowski * @since 0.2 */ public class UnderlineAction extends WrapEditorAction { private static final String IDENTIFIER = "\\underline"; /** Builds a new instance of {@link UnderlineAction}. */ public UnderlineAction() { super(Type.UNDERLINE, LatexBundle.message("editor.underline"), Icons.Editor.UNDERLINE); } @Override public boolean isMatching(@NotNull PsiElement element) { return element instanceof LatexInstruction && ((LatexInstruction) element).getIdentifier().getText().equals(IDENTIFIER); } @NotNull @Override public String getLeftText() { return IDENTIFIER + "{"; } @NotNull @Override public String getRightText() { return "}"; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/base/DialogEditorAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor.base; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Toggleable; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import javax.swing.*; /** * @author Jakub Chrzanowski * @since 0.3 */ public abstract class DialogEditorAction extends EditorAction implements Toggleable { /** Builds a new instance of {@link DialogEditorAction}. */ public DialogEditorAction(@NotNull Type type, @NotNull String name, @NotNull Icon icon) { super(type, name, icon); } @Override protected void actionPerformed(@NotNull AnActionEvent event, @NotNull final Project project, @NotNull VirtualFile virtualFile, @NotNull final TextEditor editor) { final T dialog = getDialog(project); if (dialog.showAndGet()) { runWriteAction(project, getDialogAction(dialog, editor)); } } @NotNull protected abstract T getDialog(@NotNull Project project); @NotNull protected abstract String getContent(@NotNull T dialog); @NotNull protected Runnable getDialogAction(@NotNull final T dialog, @NotNull final TextEditor editor) { return new Runnable() { @Override public void run() { final Document document = editor.getEditor().getDocument(); final CaretModel caretModel = editor.getEditor().getCaretModel(); final String content = getContent(dialog); int offset = caretModel.getOffset(); document.insertString(offset, content); caretModel.moveToOffset(offset + content.length()); } }; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/base/EditorAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor.base; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiManager; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.psi.LatexFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; /** * Editor action - abstract wrap selection action. * * @author Jakub Chrzanowski * @since 0.2 */ public abstract class EditorAction extends AnAction implements DumbAware { /** * Available editor's types. */ public enum Type { BOLD, ITALIC, UNDERLINE, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, IMAGE, MATRIX, TABLE, } /** * Editor action's type. */ private final Type type; /** * Editor action's name. */ private final String name; /** * Builds a new instance of {@link EditorAction}. */ EditorAction(@NotNull Type type, @NotNull String name, @NotNull Icon icon) { super(name, null, icon); this.type = type; this.name = name; } /** * Action handler. * * @param event Carries information on the invocation place */ @Override final public void actionPerformed(AnActionEvent event) { final VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE); final Project project = event.getData(CommonDataKeys.PROJECT); final TextEditor editor = getEditor(event); if (virtualFile == null || project == null || editor == null) { return; } actionPerformed(event, project, virtualFile, editor); } /** * Handles actionPerformed event of the editor action item. * * @param event action event * @param project current project * @param virtualFile current file * @param editor current editor */ protected void actionPerformed(@NotNull AnActionEvent event, @NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull TextEditor editor) { } @Override final public void update(AnActionEvent event) { final VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE); final Project project = event.getData(CommonDataKeys.PROJECT); final TextEditor editor = getEditor(event); if (virtualFile == null || project == null || editor == null) { return; } update(event, project, virtualFile, editor); } /** * Handles update event of the editor action item. * * @param event action event * @param project current project * @param virtualFile current file * @param editor current editor */ protected void update(AnActionEvent event, @NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull TextEditor editor) { } /** * Returns current active {@link TextEditor} instance or null. * * @param project current project * @return active {@link TextEditor} */ @Nullable private static TextEditor getActiveEditor(Project project) { if (project != null) { FileEditor[] fileEditors = FileEditorManager.getInstance(project).getSelectedEditors(); for (FileEditor fileEditor : fileEditors) { if (fileEditor instanceof TextEditor) { return (TextEditor) fileEditor; } } } return null; } /** * Returns {@link TextEditor} from witch action was called or null. * * @param e action event * @return active {@link TextEditor} */ @Nullable private static TextEditor getEditor(AnActionEvent e) { FileEditor fileEditor = e.getData(PlatformDataKeys.FILE_EDITOR); if (fileEditor instanceof TextEditor) { return (TextEditor) fileEditor; } else { return getActiveEditor(e.getProject()); } } /** * Returns the currently selected {@link PsiElement}. * * @param virtualFile Current file. * @param project Current project. * @param editor Current editor. * @return Currently selected {@link PsiElement}. */ @Nullable protected PsiElement getCurrentElement(@Nullable final VirtualFile virtualFile, @Nullable final Project project, @Nullable TextEditor editor) { if (virtualFile == null || project == null || editor == null) { return null; } PsiFile file = PsiManager.getInstance(project).findFile(virtualFile); if (file == null || !(file instanceof LatexFile)) { return null; } int offset = editor.getEditor().getCaretModel().getOffset(); return file.findElementAt(offset); } /** * Checks if element matches to the related one. * * @param element to check * @return action's element type */ public boolean isMatching(@NotNull PsiElement element) { return false; } /** * Checks if action related type matched to the given element in document. * * @param element to check * @return element matches to the action related type */ @Nullable protected PsiElement getMatchedElement(@Nullable PsiElement element) { while (element != null && !(element instanceof LatexFile)) { if (isMatching(element)) { return element; } element = element.getParent(); } return null; } /** * Runs write action. * * @param project current project * @param action to run */ final protected void runWriteAction(@NotNull final Project project, @NotNull final Runnable action) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { CommandProcessor.getInstance().executeCommand(project, action, getName(), LatexBundle.NAME); } }); } /** * Returns current editor action's type. */ @NotNull public Type getType() { return type; } /** * Returns current editor action's name. */ @NotNull public String getName() { return name; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/base/EditorActionsFactory.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor.base; import mobi.hsz.idea.latex.actions.editor.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Factory for creating LaTeX editor's actions. * * @author Jakub Chrzanowski * @since 0.2 */ public final class EditorActionsFactory { /** * Creates proper {@link EditorAction} instance basing on given {@link EditorAction.Type}. * * @return LaTeX editor toolbar action. */ @Nullable public static EditorAction create(@NotNull EditorAction.Type type) { switch (type) { case BOLD: return new BoldAction(); case ITALIC: return new ItalicAction(); case UNDERLINE: return new UnderlineAction(); case ALIGN_LEFT: return new AlignLeftAction(); case ALIGN_CENTER: return new AlignCenterAction(); case ALIGN_RIGHT: return new AlignRightAction(); case IMAGE: return new ImageAction(); case MATRIX: return new MatrixAction(); case TABLE: return new TableAction(); } return null; } } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/base/InsertEditorAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor.base; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Toggleable; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import javax.swing.*; /** * @author Jakub Chrzanowski * @since 0.3 */ public abstract class InsertEditorAction extends EditorAction implements Toggleable { /** Builds a new instance of {@link InsertEditorAction}. */ public InsertEditorAction(@NotNull Type type, @NotNull String name, @NotNull Icon icon) { super(type, name, icon); } @Override protected void actionPerformed(@NotNull AnActionEvent event, @NotNull final Project project, @NotNull VirtualFile virtualFile, @NotNull final TextEditor editor) { runWriteAction(project, new Runnable() { @Override public void run() { final Document document = editor.getEditor().getDocument(); final CaretModel caretModel = editor.getEditor().getCaretModel(); int offset = caretModel.getOffset(); String text = getText(); document.insertString(offset, text); caretModel.moveToOffset(offset + text.length()); } }); } /** * Returns text to insert. * * @return text to insert */ @NotNull protected abstract String getText(); } ================================================ FILE: src/mobi/hsz/idea/latex/actions/editor/base/WrapEditorAction.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.actions.editor.base; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Toggleable; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import javax.swing.*; /** * @author Jakub Chrzanowski * @since 0.3 */ public abstract class WrapEditorAction extends EditorAction implements Toggleable { /** * Builds a new instance of {@link WrapEditorAction}. */ public WrapEditorAction(@NotNull Type type, @NotNull String name, @NotNull Icon icon) { super(type, name, icon); } /** * Writes content to the current document. * * @param event action event * @param project current project * @param virtualFile current file * @param editor current editor */ @Override protected void actionPerformed(@NotNull AnActionEvent event, @NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull final TextEditor editor) { PsiElement element = getCurrentElement(virtualFile, project, editor); final PsiElement matched = getMatchedElement(element); runWriteAction(project, new Runnable() { @Override public void run() { if (matched == null) { wrap(editor); } else { unwrap(editor, matched); } } }); } /** * Updates the state of the action. * * @param event Carries information on the invocation place and data available */ @Override protected void update(AnActionEvent event, @NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull TextEditor editor) { PsiElement element = getCurrentElement(virtualFile, project, editor); PsiElement matched = getMatchedElement(element); event.getPresentation().putClientProperty(SELECTED_PROPERTY, matched != null); } /** * Wraps selection. * * @param editor Current editor. */ private void wrap(@NotNull TextEditor editor) { final Document document = editor.getEditor().getDocument(); final SelectionModel selectionModel = editor.getEditor().getSelectionModel(); final CaretModel caretModel = editor.getEditor().getCaretModel(); final int start = selectionModel.getSelectionStart(); final int end = selectionModel.getSelectionEnd(); final String text = StringUtil.notNullize(selectionModel.getSelectedText()); String newText = getLeftText() + text + getRightText(); int newStart = start + getLeftText().length(); int newEnd = StringUtil.isEmpty(text) ? newStart : end + getLeftText().length(); document.replaceString(start, end, newText); selectionModel.setSelection(newStart, newEnd); caretModel.moveToOffset(newEnd); } /** * Unwraps selection. * * @param editor Current editor. * @param matched Matched PSI element. */ private void unwrap(@NotNull final TextEditor editor, @NotNull final PsiElement matched) { final Document document = editor.getEditor().getDocument(); final SelectionModel selectionModel = editor.getEditor().getSelectionModel(); final CaretModel caretModel = editor.getEditor().getCaretModel(); final int start = matched.getTextRange().getStartOffset(); final int end = matched.getTextRange().getEndOffset(); final String text = StringUtil.notNullize(matched.getText()); String newText = StringUtil.trimEnd(StringUtil.trimStart(text, getLeftText()), getRightText()); int newStart = selectionModel.getSelectionStart() - getLeftText().length(); int newEnd = selectionModel.getSelectionEnd() - getLeftText().length(); document.replaceString(start, end, newText); selectionModel.setSelection(newStart, newEnd); caretModel.moveToOffset(newEnd); } /** * Returns left part of the wrapping text. * * @return left part */ @NotNull public abstract String getLeftText(); /** * Returns right part of the wrapping text. * * @return right part */ @NotNull public abstract String getRightText(); } ================================================ FILE: src/mobi/hsz/idea/latex/codeStyle/LatexCodeStyleMainPanel.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.codeStyle; import com.intellij.application.options.TabbedLanguageCodeStylePanel; import com.intellij.psi.codeStyle.CodeStyleSettings; import mobi.hsz.idea.latex.lang.LatexLanguage; /** * LaTeX {@link TabbedLanguageCodeStylePanel} implementation of the main panel. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexCodeStyleMainPanel extends TabbedLanguageCodeStylePanel { protected LatexCodeStyleMainPanel(CodeStyleSettings currentSettings, CodeStyleSettings settings) { super(LatexLanguage.INSTANCE, currentSettings, settings); } @Override protected void initTabs(CodeStyleSettings settings) { super.initTabs(settings); // addTab(new GrCodeStyleImportsPanelWrapper(settings)); } } ================================================ FILE: src/mobi/hsz/idea/latex/codeStyle/LatexCodeStyleSettings.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.codeStyle; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CustomCodeStyleSettings; import org.jetbrains.annotations.NotNull; /** * LaTeX {@link CustomCodeStyleSettings} implementation. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexCodeStyleSettings extends CustomCodeStyleSettings { protected LatexCodeStyleSettings(@NotNull CodeStyleSettings container) { super("LatexCodeStyleSettings", container); } } ================================================ FILE: src/mobi/hsz/idea/latex/codeStyle/LatexCodeStyleSettingsProvider.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.codeStyle; import com.intellij.application.options.CodeStyleAbstractConfigurable; import com.intellij.application.options.CodeStyleAbstractPanel; import com.intellij.openapi.options.Configurable; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; import com.intellij.psi.codeStyle.CustomCodeStyleSettings; import mobi.hsz.idea.latex.lang.LatexLanguage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * LaTeX {@link CodeStyleSettingsProvider} implementation. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexCodeStyleSettingsProvider extends CodeStyleSettingsProvider { @NotNull @Override public Configurable createSettingsPage(CodeStyleSettings settings, CodeStyleSettings originalSettings) { return new CodeStyleAbstractConfigurable(settings, originalSettings, LatexLanguage.NAME) { @Override protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { return new LatexCodeStyleMainPanel(getCurrentSettings(), settings); } @Override public String getHelpTopic() { return "reference.settingsdialog.codestyle." + LatexLanguage.NAME.toLowerCase(); } }; } @Nullable @Override public String getConfigurableDisplayName() { return LatexLanguage.NAME; } @Nullable @Override public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) { return new LatexCodeStyleSettings(settings); } } ================================================ FILE: src/mobi/hsz/idea/latex/codeStyle/LatexLanguageCodeStyleSettingsProvider.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.codeStyle; import com.intellij.application.options.IndentOptionsEditor; import com.intellij.application.options.SmartIndentOptionsEditor; import com.intellij.lang.Language; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider; import mobi.hsz.idea.latex.lang.LatexLanguage; import mobi.hsz.idea.latex.util.Resources; import org.jetbrains.annotations.NotNull; /** * LaTeX {@link LanguageCodeStyleSettingsProvider} implementation. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider { @NotNull @Override public Language getLanguage() { return LatexLanguage.INSTANCE; } @Override public CommonCodeStyleSettings getDefaultCommonSettings() { CommonCodeStyleSettings defaultSettings = new CommonCodeStyleSettings(LatexLanguage.INSTANCE); defaultSettings.initIndentOptions(); // defaultSettings.SPACE_WITHIN_BRACES = true; // defaultSettings.KEEP_SIMPLE_CLASSES_IN_ONE_LINE = true; // defaultSettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE = true; return defaultSettings; } @Override public String getCodeSample(@NotNull SettingsType settingsType) { switch (settingsType) { case INDENT_SETTINGS: case SPACING_SETTINGS: case WRAPPING_AND_BRACES_SETTINGS: case BLANK_LINES_SETTINGS: return Resources.getResourceContent("/codeStyle/preview/" + settingsType.name().toLowerCase() + ".tex.ft"); default: return "foo"; } } @Override public IndentOptionsEditor getIndentOptionsEditor() { return new SmartIndentOptionsEditor(); } } ================================================ FILE: src/mobi/hsz/idea/latex/editor/LatexEditorActionsLoaderComponent.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.editor; import com.intellij.openapi.Disposable; import com.intellij.openapi.components.AbstractProjectComponent; import com.intellij.openapi.fileEditor.*; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.vfs.VirtualFile; import mobi.hsz.idea.latex.file.LatexFileType; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; /** * Component loader for editor actions toolbar. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexEditorActionsLoaderComponent extends AbstractProjectComponent { /** Constructor. */ public LatexEditorActionsLoaderComponent(@NotNull final Project project) { super(project); } /** * Returns component name. * * @return component name */ @Override @NonNls @NotNull public String getComponentName() { return "LatexEditorActionsLoaderComponent"; } /** Initializes component. */ @Override public void initComponent() { myProject.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new LatexEditorManagerListener()); } /** Listener for LaTeX editor manager. */ private static class LatexEditorManagerListener extends FileEditorManagerAdapter { /** * Handles file opening event and attaches LaTeX editor component. * * @param source editor manager * @param file current file */ @Override public void fileOpened(@NotNull final FileEditorManager source, @NotNull final VirtualFile file) { FileType fileType = file.getFileType(); if (!(fileType instanceof LatexFileType)) { return; } for (final FileEditor fileEditor : source.getEditors(file)) { if (fileEditor instanceof TextEditor) { final LatexEditorActionsWrapper wrapper = new LatexEditorActionsWrapper(fileEditor); final JComponent c = wrapper.getComponent(); source.addTopComponent(fileEditor, c); Disposer.register(fileEditor, wrapper); Disposer.register(fileEditor, new Disposable() { @Override public void dispose() { source.removeTopComponent(fileEditor, c); } }); } } } } } ================================================ FILE: src/mobi/hsz/idea/latex/editor/LatexEditorActionsWrapper.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.editor; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.fileEditor.FileEditor; import mobi.hsz.idea.latex.actions.editor.base.EditorActionsFactory; import org.jetbrains.annotations.NotNull; import javax.swing.*; import static mobi.hsz.idea.latex.actions.editor.base.EditorAction.Type.*; /** * Wrapper that creates bottom editor component for displaying outer ignore rules. * * @author Jakub Chrzanowski * @since 0.3 */ class LatexEditorActionsWrapper implements Disposable { private final ActionToolbar actionToolbar; LatexEditorActionsWrapper(@NotNull FileEditor fileEditor) { DefaultActionGroup actions = new DefaultActionGroup(); actions.addAll( EditorActionsFactory.create(BOLD), EditorActionsFactory.create(ITALIC), EditorActionsFactory.create(UNDERLINE), Separator.getInstance(), EditorActionsFactory.create(ALIGN_LEFT), EditorActionsFactory.create(ALIGN_CENTER), EditorActionsFactory.create(ALIGN_RIGHT), Separator.getInstance(), EditorActionsFactory.create(IMAGE), EditorActionsFactory.create(TABLE), EditorActionsFactory.create(MATRIX) ); actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.EDITOR_TAB, actions, true); actionToolbar.setMinimumButtonSize(ActionToolbar.NAVBAR_MINIMUM_BUTTON_SIZE); actionToolbar.setTargetComponent(fileEditor.getComponent()); } /** * Returns outer panel. * * @return outer panel */ @NotNull JComponent getComponent() { return actionToolbar.getComponent(); } @Override public void dispose() { } } ================================================ FILE: src/mobi/hsz/idea/latex/file/LatexFileType.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.file; import com.intellij.openapi.fileTypes.LanguageFileType; import mobi.hsz.idea.latex.lang.LatexLanguage; import mobi.hsz.idea.latex.util.Icons; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; /** * Describes LaTeX file type. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexFileType extends LanguageFileType { /** Contains {@link LatexFileType} singleton. */ public static final LatexFileType INSTANCE = new LatexFileType(); /** Private constructor to prevent direct object creation. */ private LatexFileType() { super(LatexLanguage.INSTANCE); } /** * Returns the name of the file type. The name must be unique among all file types registered in the system. * * @return The file type name. */ @NotNull @Override public String getName() { return LatexLanguage.NAME + " file"; } /** * Returns the user-readable description of the file type. * * @return The file type description. */ @NotNull @Override public String getDescription() { return LatexLanguage.NAME + " file"; } /** * Returns the default extension for files of the type. * * @return The extension, not including the leading '.'. */ @NotNull @Override public String getDefaultExtension() { return LatexLanguage.EXTENSION; } /** * Returns the icon used for showing files of the type. * * @return The icon instance, or null if no icon should be shown. */ @Nullable @Override public Icon getIcon() { return Icons.FILE; } } ================================================ FILE: src/mobi/hsz/idea/latex/file/LatexFileTypeFactory.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.file; import com.intellij.openapi.fileTypes.FileTypeConsumer; import com.intellij.openapi.fileTypes.FileTypeFactory; import mobi.hsz.idea.latex.lang.LatexLanguage; import org.jetbrains.annotations.NotNull; /** * Class that assigns file types with languages. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexFileTypeFactory extends FileTypeFactory { /** * Assigns file types with languages. * * @param consumer file types consumer */ @Override public void createFileTypes(@NotNull FileTypeConsumer consumer) { consumer.consume(LatexFileType.INSTANCE, LatexLanguage.EXTENSION); } } ================================================ FILE: src/mobi/hsz/idea/latex/folding/LatexFoldingBuilder.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.folding; import com.intellij.lang.ASTNode; import com.intellij.lang.folding.FoldingBuilder; import com.intellij.lang.folding.FoldingDescriptor; import com.intellij.openapi.editor.Document; import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.psi.*; import mobi.hsz.idea.latex.psi.impl.LatexSectionExtImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; /** * LaTeX folding builder. Handles {@link LatexTypes#SECTION} folding. * * @author Jakub Chrzanowski * @since 0.2 */ public class LatexFoldingBuilder implements FoldingBuilder { /** Descriptors collection. */ private final List descriptors = new ArrayList(); /** {@link LatexVisitor} instance to walk over all sections in the {@link PsiElement}. */ private final PsiElementVisitor visitor = new LatexVisitor() { @Override public void visitSection(@NotNull LatexSection section) { LatexInstructionBegin begin = ((LatexSectionExtImpl) section).getBeginInstruction(); LatexInstructionEnd end = ((LatexSectionExtImpl) section).getEndInstruction(); if (begin == null || end == null) { return; } int startOffset = begin.getTextOffset(); int endOffset = end.getTextOffset() + end.getTextLength(); if (endOffset - startOffset > 0) { descriptors.add(new FoldingDescriptor(section, new TextRange(startOffset, endOffset))); } section.acceptChildren(visitor); } }; /** * Builds the folding regions for the specified node in the AST tree and its children. * Note that you can have several folding regions for one AST node, i.e. several {@link FoldingDescriptor} with similar AST node. * * @param node the node for which folding is requested. * @param document the document for which folding is built. Can be used to retrieve line * numbers for folding regions. * @return the array of folding descriptors. */ @NotNull public FoldingDescriptor[] buildFoldRegions(@NotNull final ASTNode node, @NotNull final Document document) { descriptors.clear(); node.getPsi().acceptChildren(visitor); return descriptors.toArray(new FoldingDescriptor[descriptors.size()]); } /** * Returns the text which is displayed in the editor for the folding region related to the * specified node when the folding region is collapsed. * * @param node the node for which the placeholder text is requested. * @return the placeholder text. */ @Nullable @Override public String getPlaceholderText(@NotNull ASTNode node) { return node.getFirstChildNode().getText() + LatexBundle.message("folding.placeholder"); } /** * Returns the default collapsed state for the folding region related to the specified node. * * @param node the node for which the collapsed state is requested. * @return true if the region is collapsed by default, false otherwise. */ @Override public boolean isCollapsedByDefault(@NotNull ASTNode node) { return false; } } ================================================ FILE: src/mobi/hsz/idea/latex/highlighter/LatexColorSettingsPage.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.highlighter; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.options.colors.AttributesDescriptor; import com.intellij.openapi.options.colors.ColorDescriptor; import com.intellij.openapi.options.colors.ColorSettingsPage; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.util.Icons; import mobi.hsz.idea.latex.util.Resources; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.Map; /** * {@link ColorSettingsPage} that allows to modify color scheme. * * @author Jakub Chrzanowski * @since 0.2 */ public class LatexColorSettingsPage implements ColorSettingsPage { /** The path to the sample LaTeX file. */ @NonNls private static final String SAMPLE_LATEX_PATH = "/sample.tex"; /** Display name for Color Settings Page. */ @NonNls private static final String DISPLAY_NAME = LatexBundle.message("colorSettings.displayName"); /** * The sample LaTeX document shown in the colors settings dialog. * * @see #loadSampleLatex() */ private static final String SAMPLE_LATEX = loadSampleLatex(); /** Attributes descriptor list. */ private static final AttributesDescriptor[] DESCRIPTORS = new AttributesDescriptor[]{ new AttributesDescriptor(LatexBundle.message("highlighter.instruction"), LatexHighlighterColors.INSTRUCTION), new AttributesDescriptor(LatexBundle.message("highlighter.argument"), LatexHighlighterColors.ARGUMENT), new AttributesDescriptor(LatexBundle.message("highlighter.bracket"), LatexHighlighterColors.BRACKET), new AttributesDescriptor(LatexBundle.message("highlighter.comment"), LatexHighlighterColors.COMMENT), }; /** * Returns the icon for the page, shown in the dialog tab. * * @return the icon for the page, or null if the page does not have a custom icon. */ @Nullable @Override public Icon getIcon() { return Icons.FILE; } /** * Returns the syntax highlighter which is used to highlight the text shown in the preview * pane of the page. * * @return the syntax highlighter instance. */ @NotNull @Override public SyntaxHighlighter getHighlighter() { return new LatexHighlighter(null, null); } /** * Returns the text shown in the preview pane. * * @return demo text */ @NotNull @Override public String getDemoText() { return SAMPLE_LATEX; } /** * Returns the mapping from special tag names surrounding the regions to be highlighted * in the preview text. * * @return null */ @Nullable @Override public Map getAdditionalHighlightingTagToDescriptorMap() { return null; } /** * Returns the list of descriptors specifying the {@link TextAttributesKey} instances * for which colors are specified in the page. For such attribute keys, the user can choose * all highlighting attributes (font type, background color, foreground color, error stripe color and * effects). * * @return the list of attribute descriptors. */ @NotNull @Override public AttributesDescriptor[] getAttributeDescriptors() { return DESCRIPTORS; } /** * Returns the list of descriptors specifying the {@link com.intellij.openapi.editor.colors.ColorKey} * instances for which colors are specified in the page. For such color keys, the user can * choose only the background or foreground color. * * @return the list of color descriptors. */ @NotNull @Override public ColorDescriptor[] getColorDescriptors() { return ColorDescriptor.EMPTY_ARRAY; } /** * Returns the title of the page, shown as text in the dialog tab. * * @return the title of the custom page. */ @NotNull @Override public String getDisplayName() { return DISPLAY_NAME; } /** * Loads sample .gitignore file * * @return the text loaded from {@link #SAMPLE_LATEX_PATH} * @see #getDemoText() * @see #SAMPLE_LATEX_PATH * @see #SAMPLE_LATEX */ private static String loadSampleLatex() { return Resources.getResourceContent(SAMPLE_LATEX_PATH); } } ================================================ FILE: src/mobi/hsz/idea/latex/highlighter/LatexHighlighter.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.highlighter; import com.intellij.lexer.Lexer; import com.intellij.openapi.editor.colors.TextAttributesKey; import com.intellij.openapi.fileTypes.SyntaxHighlighterBase; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.tree.IElementType; import com.intellij.util.containers.ContainerUtil; import mobi.hsz.idea.latex.lang.LatexParserDefinition; import mobi.hsz.idea.latex.lexer.LatexLexerAdapter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Map; /** * Syntax highlighter definition. * * @author Jakub Chrzanowski * @since 0.1 */ class LatexHighlighter extends SyntaxHighlighterBase { /** Attributes map. */ private static final Map ATTRIBUTES = ContainerUtil.newHashMap(); /** Binds parser definitions with highlighter colors. */ static { SyntaxHighlighterBase.fillMap(ATTRIBUTES, LatexParserDefinition.COMMENTS, LatexHighlighterColors.COMMENT); SyntaxHighlighterBase.fillMap(ATTRIBUTES, LatexParserDefinition.INSTRUCTIONS, LatexHighlighterColors.INSTRUCTION); SyntaxHighlighterBase.fillMap(ATTRIBUTES, LatexParserDefinition.BRACKETS, LatexHighlighterColors.BRACKET); SyntaxHighlighterBase.fillMap(ATTRIBUTES, LatexParserDefinition.ARGUMENTS, LatexHighlighterColors.ARGUMENT); } /** Current project. */ private final Project project; /** Current file. */ private final VirtualFile virtualFile; /** Builds a new instance of {@link LatexHighlighter}. */ LatexHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) { this.project = project; this.virtualFile = virtualFile; } /** * Creates lexer adapter. * * @return lexer adapter */ @NotNull @Override public Lexer getHighlightingLexer() { return new LatexLexerAdapter(project, virtualFile); } /** * Gets highlighter text {@link TextAttributesKey} list using {@link IElementType} token. * * @param tokenType element type * @return attributes list */ @NotNull @Override public TextAttributesKey[] getTokenHighlights(IElementType tokenType) { return pack(ATTRIBUTES.get(tokenType)); } } ================================================ FILE: src/mobi/hsz/idea/latex/highlighter/LatexHighlighterColors.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.highlighter; import com.intellij.openapi.editor.DefaultLanguageHighlighterColors; import com.intellij.openapi.editor.colors.TextAttributesKey; /** * Contains highlighter attributes definitions. * * @author Jakub Chrzanowski * @since 0.1 */ class LatexHighlighterColors { /** Default style for regular comment started with # */ public static final TextAttributesKey COMMENT = TextAttributesKey.createTextAttributesKey("LATEX.COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); /** Default style for Latex instruction started with \ */ static final TextAttributesKey INSTRUCTION = TextAttributesKey.createTextAttributesKey("LATEX.INSTRUCTION", DefaultLanguageHighlighterColors.FUNCTION_CALL); /** Default style for bracket: [](){} */ static final TextAttributesKey BRACKET = TextAttributesKey.createTextAttributesKey("LATEX.BRACKET", DefaultLanguageHighlighterColors.BRACKETS); /** Default style for Latex instruction's argument */ static final TextAttributesKey ARGUMENT = TextAttributesKey.createTextAttributesKey("LATEX.ARGUMENT", DefaultLanguageHighlighterColors.PARAMETER); } ================================================ FILE: src/mobi/hsz/idea/latex/highlighter/LatexHighlighterFactory.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.highlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighter; import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * {@link SyntaxHighlighterFactory} class definition. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexHighlighterFactory extends SyntaxHighlighterFactory { /** * Override this method to provide syntax highlighting (coloring) capabilities for your language implementation. * By syntax highlighting we mean highlighting of keywords, comments, braces etc. where lexing the file content is enough * to identify proper highlighting attributes. *

    * Default implementation doesn't highlight anything. * * @param project might be necessary to gather various project settings from. * @param virtualFile might be necessary to collect file specific settings * @return SyntaxHighlighter interface implementation for this particular language. */ @NotNull @Override public SyntaxHighlighter getSyntaxHighlighter(@Nullable Project project, @Nullable VirtualFile virtualFile) { return new LatexHighlighter(project, virtualFile); } } ================================================ FILE: src/mobi/hsz/idea/latex/inspections/LatexSpellcheckingStrategy.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.inspections; import com.intellij.psi.PsiElement; import com.intellij.spellchecker.tokenizer.SpellcheckingStrategy; import com.intellij.spellchecker.tokenizer.Tokenizer; import mobi.hsz.idea.latex.lang.LatexLanguage; import mobi.hsz.idea.latex.psi.LatexText; import org.jetbrains.annotations.NotNull; /** * {@link SpellcheckingStrategy} implementation for LaTeX language. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexSpellcheckingStrategy extends SpellcheckingStrategy { /** * Checks if elements is supported. * * @param element to check * @return element is {@link LatexLanguage} instance */ @Override public boolean isMyContext(@NotNull PsiElement element) { return LatexLanguage.INSTANCE.is(element.getLanguage()); } /** * Provides {@link #TEXT_TOKENIZER} for {@link LatexText} elements. * * @param element to check * @return {@link #TEXT_TOKENIZER} for {@link LatexText} or {@link #EMPTY_TOKENIZER}. */ @NotNull @Override public Tokenizer getTokenizer(PsiElement element) { if (element instanceof LatexText) { return TEXT_TOKENIZER; } return EMPTY_TOKENIZER; } } ================================================ FILE: src/mobi/hsz/idea/latex/lang/LatexBraceMatcher.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.lang; import com.intellij.lang.BracePair; import com.intellij.lang.PairedBraceMatcher; import com.intellij.psi.PsiFile; import com.intellij.psi.tree.IElementType; import mobi.hsz.idea.latex.psi.LatexTypes; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Definition of {@link PairedBraceMatcher} class. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexBraceMatcher implements PairedBraceMatcher { /** Array of definitions for brace pairs. */ private static final BracePair[] PAIRS = new BracePair[]{ new BracePair(LatexTypes.LBRACE, LatexTypes.RBRACE, false), new BracePair(LatexTypes.LBRACKET, LatexTypes.RBRACKET, false), new BracePair(LatexTypes.LPAREN, LatexTypes.RPAREN, false) }; /** * Returns the array of definitions for brace pairs that need to be matched when * editing code in the language. * * @return the array of brace pair definitions. */ @Override public BracePair[] getPairs() { return PAIRS; } /** * Returns true if paired rbrace should be inserted after lbrace of given type when lbrace is encountered before contextType token. * It is safe to always return true, then paired brace will be inserted anyway. * * @param lbraceType lbrace for which information is queried * @param contextType token type that follows lbrace * @return true / false as described */ @Override public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) { return true; } /** * Returns the start offset of the code construct which owns the opening structural brace at the specified offset. For example, * if the opening brace belongs to an 'if' statement, returns the start offset of the 'if' statement. * * @param file the file in which brace matching is performed. * @param openingBraceOffset the offset of an opening structural brace. * @return the offset of corresponding code construct, or the same offset if not defined. */ @Override public int getCodeConstructStart(PsiFile file, int openingBraceOffset) { return openingBraceOffset; } } ================================================ FILE: src/mobi/hsz/idea/latex/lang/LatexCommenter.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.lang; import com.intellij.lang.Commenter; import org.jetbrains.annotations.Nullable; /** * Defines the support for "Comment with Line Comment" and "Comment with Block Comment" * actions in a custom language. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexCommenter implements Commenter { /** * Returns the string which prefixes a line comment in the language, or null if the language * does not support line comments. * * @return the line comment text, or null. */ @Nullable @Override public String getLineCommentPrefix() { return "%"; } /** * Returns the string which marks the beginning of a block comment in the language, * or null if the language does not support block comments. * * @return the block comment start text, or null. */ @Nullable @Override public String getBlockCommentPrefix() { return null; } /** * Returns the string which marks the end of a block comment in the language, * or null if the language does not support block comments. * * @return the block comment end text, or null. */ @Nullable @Override public String getBlockCommentSuffix() { return null; } /** * Returns the string which marks the commented beginning of a block comment in the language, * or null if the language does not support block comments. * * @return the commented block comment start text, or null. */ @Nullable @Override public String getCommentedBlockCommentPrefix() { return null; } /** * Returns the string which marks the commented end of a block comment in the language, * or null if the language does not support block comments. * * @return the commented block comment end text, or null. */ @Nullable @Override public String getCommentedBlockCommentSuffix() { return null; } } ================================================ FILE: src/mobi/hsz/idea/latex/lang/LatexLanguage.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.lang; import com.intellij.lang.Language; import org.jetbrains.annotations.NonNls; /** * LaTeX {@link Language} definition. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexLanguage extends Language { /** The {@link LatexLanguage} instance. */ public static final LatexLanguage INSTANCE = new LatexLanguage(); /** The LaTeX language name. */ @NonNls public static final String NAME = "LaTeX"; /** The LaTeX file extension suffix. */ @NonNls public static final String EXTENSION = "tex"; /** LaTeX languages group name. */ @NonNls public static final String GROUP = "LATEX_GROUP"; /** {@link LatexLanguage} is a non-instantiable static class. */ private LatexLanguage() { super(NAME); } } ================================================ FILE: src/mobi/hsz/idea/latex/lang/LatexParserDefinition.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.lang; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.lang.ParserDefinition; import com.intellij.lang.PsiParser; import com.intellij.lexer.Lexer; import com.intellij.openapi.project.Project; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.TokenType; import com.intellij.psi.tree.IFileElementType; import com.intellij.psi.tree.TokenSet; import mobi.hsz.idea.latex.lexer.LatexLexerAdapter; import mobi.hsz.idea.latex.parser.LatexParser; import mobi.hsz.idea.latex.psi.LatexFile; import mobi.hsz.idea.latex.psi.LatexTypes; import org.jetbrains.annotations.NotNull; /** * Defines the implementation of a parser for a custom language. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexParserDefinition implements ParserDefinition { /** Whitespaces. */ public static final TokenSet WHITE_SPACES = TokenSet.create(TokenType.WHITE_SPACE); /** Regular comment started with # */ public static final TokenSet COMMENTS = TokenSet.create(LatexTypes.COMMENT); /** Latex instruction started with \ */ public static final TokenSet INSTRUCTIONS = TokenSet.create(LatexTypes.IDENTIFIER, LatexTypes.IDENTIFIER_BEGIN, LatexTypes.IDENTIFIER_END); /** Latex instruction's argument */ public static final TokenSet ARGUMENTS = TokenSet.create(LatexTypes.ARG); /** All brackets: braces, brackets, parenthesis */ public static final TokenSet BRACKETS = TokenSet.create( LatexTypes.LBRACE, LatexTypes.RBRACE, LatexTypes.LBRACKET, LatexTypes.RBRACKET, LatexTypes.LPAREN, LatexTypes.RPAREN ); /** Element type of the node describing a file in the specified language. */ public static final IFileElementType FILE = new IFileElementType(Language.findInstance(LatexLanguage.class)); /** * Returns the lexer for lexing files in the specified project. This lexer does not need to support incremental relexing - it is always * called for the entire file. * * @param project the project to which the lexer is connected. * @return the lexer instance. */ @NotNull @Override public Lexer createLexer(Project project) { return new LatexLexerAdapter(project); } /** * Returns the parser for parsing files in the specified project. * * @param project the project to which the parser is connected. * @return the parser instance. */ @Override public PsiParser createParser(Project project) { return new LatexParser(); } /** * Returns the element type of the node describing a file in the specified language. * * @return the file node element type. */ @Override public IFileElementType getFileNodeType() { return FILE; } /** * Returns the set of token types which are treated as whitespace by the PSI builder. * Tokens of those types are automatically skipped by PsiBuilder. Whitespace elements * on the bounds of nodes built by PsiBuilder are automatically excluded from the text * range of the nodes. *

    It is strongly advised you return TokenSet that only contains {@link com.intellij.psi.TokenType#WHITE_SPACE}, * which is suitable for all the languages unless you really need to use special whitespace token * * @return the set of whitespace token types. */ @NotNull @Override public TokenSet getWhitespaceTokens() { return WHITE_SPACES; } /** * Returns the set of token types which are treated as comments by the PSI builder. * Tokens of those types are automatically skipped by PsiBuilder. Also, To Do patterns * are searched in the text of tokens of those types. * * @return the set of comment token types. */ @NotNull @Override public TokenSet getCommentTokens() { return COMMENTS; } /** * Returns the set of token types which are treated as argument by the PSI builder. * * @return the set of argument token types. */ @NotNull public TokenSet getArgumentTokens() { return ARGUMENTS; } /** * Returns the set of token types which are treated as instructions by the PSI builder. * * @return the set of instruction token types. */ @NotNull public TokenSet getInstructionTokens() { return INSTRUCTIONS; } /** * Returns the set of token types which are treated as brackets by the PSI builder: [](){} * * @return the set of instruction token types. */ @NotNull public TokenSet getBracketTokens() { return BRACKETS; } /** * Returns the set of element types which are treated as string literals. "Search in strings" * option in refactorings is applied to the contents of such tokens. * * @return the set of string literal element types. */ @NotNull @Override public TokenSet getStringLiteralElements() { return TokenSet.EMPTY; } /** * Creates a PSI element for the specified AST node. The AST tree is a simple, semantic-free * tree of AST nodes which is built during the PsiBuilder parsing pass. The PSI tree is built * over the AST tree and includes elements of different types for different language constructs. * * @param node the node for which the PSI element should be returned. * @return the PSI element matching the element type of the AST node. */ @NotNull @Override public PsiElement createElement(ASTNode node) { return LatexTypes.Factory.createElement(node); } /** * Creates a PSI element for the specified virtual file. * * @param viewProvider virtual file. * @return the PSI file element. */ @Override public PsiFile createFile(FileViewProvider viewProvider) { return new LatexFile(viewProvider); } /** * Checks if the specified two token types need to be separated by a space according to the language grammar. * For example, in Java two keywords are always separated by a space; a keyword and an opening parenthesis may * be separated or not separated. This is used for automatic whitespace insertion during AST modification operations. * * @param left the first token to check. * @param right the second token to check. * @return the spacing requirements. */ @Override public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode left, ASTNode right) { return SpaceRequirements.MAY; } } ================================================ FILE: src/mobi/hsz/idea/latex/lexer/Latex.flex ================================================ package mobi.hsz.idea.latex.lexer; import java.io.File; import java.util.List; import com.intellij.lexer.*; import com.intellij.psi.tree.IElementType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import static mobi.hsz.idea.latex.psi.LatexTypes.*; import static com.intellij.psi.TokenType.*; %% %{ public LatexLexer() { this((java.io.Reader)null); } %} %public %class LatexLexer %implements FlexLexer %function advance %type IElementType %unicode EOL = "\r"|"\n"|"\r\n" LINE_WS = [\ \t\f] WHITE_SPACE = ({LINE_WS}|{EOL})+ IDENTIFIER = \\[:letter:]+ COMMENT = %.* ARG = [^\(\)\{\}\[\]\\,] TEXT = [^\(\)\{\}\[\]\\\%\ \t\f\r\n]|"\\\%"|("\\"{SPECIAL}) SPECIAL = "$"|"&"|"#"|"_"|"~"|"^"|"\\" %state IN_ARGUMENT %% // brackets "(" { yybegin(IN_ARGUMENT); return LPAREN; } ")" { return RPAREN; } "[" { yybegin(IN_ARGUMENT); return LBRACKET; } "]" { return RBRACKET; } "{" { yybegin(IN_ARGUMENT); return LBRACE; } "}" { return RBRACE; } { {ARG}+ { return ARG; } "," { return COMMA; } . { yypushback(1); yybegin(YYINITIAL); } } // special characters ":" { return COLON; } "*" { return ASTERISK; } "\\\\" { return LINE_BREAK; } {SPECIAL} { return SPECIAL; } "\\". { return SPECIAL; } {WHITE_SPACE}+ { return WHITE_SPACE; } "\\begin" { return IDENTIFIER_BEGIN; } "\\end" { return IDENTIFIER_END; } {IDENTIFIER} { return IDENTIFIER; } {COMMENT} { return COMMENT; } {TEXT}+ { return ARG; } ================================================ FILE: src/mobi/hsz/idea/latex/lexer/LatexLexerAdapter.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.lexer; import com.intellij.lexer.FlexAdapter; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.Nullable; /** * Definition of {@link FlexAdapter}. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexLexerAdapter extends FlexAdapter { /** Builds a new instance of {@link LatexLexerAdapter}. */ public LatexLexerAdapter(Project project) { this(project, null); } /** Builds a new instance of {@link LatexLexerAdapter}. */ public LatexLexerAdapter(Project project, @Nullable VirtualFile virtualFile) { super(new LatexLexer()); } } ================================================ FILE: src/mobi/hsz/idea/latex/parser/LatexParserUtil.java ================================================ package mobi.hsz.idea.latex.parser; import com.intellij.lang.parser.GeneratedParserUtilBase; /** * @author Jakub Chrzanowski * @since 0.3 */ public class LatexParserUtil extends GeneratedParserUtilBase { } ================================================ FILE: src/mobi/hsz/idea/latex/psi/LatexArgumentElement.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi; import com.intellij.psi.PsiElement; import org.jetbrains.annotations.Nullable; public interface LatexArgumentElement extends PsiElement { @Nullable String getValue(); } ================================================ FILE: src/mobi/hsz/idea/latex/psi/LatexElementImpl.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi; import com.intellij.extapi.psi.ASTWrapperPsiElement; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiReference; import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry; import org.jetbrains.annotations.NotNull; /** * Definition of {@link ASTWrapperPsiElement}. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexElementImpl extends ASTWrapperPsiElement { public LatexElementImpl(ASTNode node) { super(node); } /** * Gets {@link PsiReference} list for given element. * * @return {@link PsiReference} list */ @NotNull @Override public PsiReference[] getReferences() { return ReferenceProvidersRegistry.getReferencesFromProviders(this); } } ================================================ FILE: src/mobi/hsz/idea/latex/psi/LatexElementType.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi; import com.intellij.psi.tree.IElementType; import mobi.hsz.idea.latex.lang.LatexLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; /** * Latex element type. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexElementType extends IElementType { /** Build a new instance of @{link IgnoreElementType} */ public LatexElementType(@NotNull @NonNls String debugName) { super(debugName, LatexLanguage.INSTANCE); } } ================================================ FILE: src/mobi/hsz/idea/latex/psi/LatexFile.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi; import com.intellij.extapi.psi.PsiFileBase; import com.intellij.openapi.fileTypes.FileType; import com.intellij.psi.FileViewProvider; import mobi.hsz.idea.latex.file.LatexFileType; import mobi.hsz.idea.latex.lang.LatexLanguage; import org.jetbrains.annotations.NotNull; /** * Base plugin file. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexFile extends PsiFileBase { /** Current file type. */ private final LatexFileType fileType; /** Builds a new instance of {@link LatexFile}. */ public LatexFile(@NotNull FileViewProvider viewProvider) { super(viewProvider, LatexLanguage.INSTANCE); fileType = LatexFileType.INSTANCE; } /** * Returns the file type for the file. * * @return the file type instance. */ @NotNull @Override public FileType getFileType() { return fileType; } /** * Returns @{link IgnoreFileType} string interpretation. * * @return string interpretation */ @Override public String toString() { return fileType.getName(); } } ================================================ FILE: src/mobi/hsz/idea/latex/psi/LatexTokenType.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi; import com.intellij.psi.tree.IElementType; import mobi.hsz.idea.latex.LatexBundle; import mobi.hsz.idea.latex.lang.LatexLanguage; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; /** * Token type definition. * * @author Jakub Chrzanowski * @since 0.1 */ public class LatexTokenType extends IElementType { /** Token debug name. */ private final String debugName; /** Builds a new instance of @{link IgnoreTokenType}. */ LatexTokenType(@NotNull @NonNls String debugName) { super(debugName, LatexLanguage.INSTANCE); this.debugName = debugName; } /** * String interpretation of the token type. * * @return string representation */ @Override public String toString() { return LatexBundle.messageOrDefault("tokenType." + debugName, getLanguage().getDisplayName() + "TokenType." + super.toString()); } } ================================================ FILE: src/mobi/hsz/idea/latex/psi/impl/LatexArgumentExtImpl.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import mobi.hsz.idea.latex.psi.LatexArgument; import mobi.hsz.idea.latex.psi.LatexArgumentElement; import mobi.hsz.idea.latex.psi.LatexElementImpl; /** * Abstract LatexArgument implementation. * * @author Jakub Chrzanowski * @since 0.3 */ public abstract class LatexArgumentExtImpl extends LatexElementImpl implements LatexArgumentElement { LatexArgumentExtImpl(ASTNode node) { super(node); } /** * Returns the Argument element value ignoring the parentheses. * * @return Argument value. */ @Override public String getValue() { for (PsiElement child : getChildren()) { if (child instanceof LatexArgument) { return ((LatexArgument) child).getValue(); } } return getText(); } } ================================================ FILE: src/mobi/hsz/idea/latex/psi/impl/LatexInstructionExtImpl.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiTreeUtil; import mobi.hsz.idea.latex.psi.LatexArgument; import mobi.hsz.idea.latex.psi.LatexElementImpl; import mobi.hsz.idea.latex.psi.LatexInstruction; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; import static mobi.hsz.idea.latex.psi.LatexTypes.IDENTIFIER; import static mobi.hsz.idea.latex.psi.LatexTypes.IDENTIFIER_BEGIN; import static mobi.hsz.idea.latex.psi.LatexTypes.IDENTIFIER_END; /** * Abstract {@link LatexInstruction} implementation to handle {@link #getIdentifier()} in instruction subtypes. * * @author Jakub Chrzanowski * @since 0.3 */ public abstract class LatexInstructionExtImpl extends LatexElementImpl implements LatexInstruction { /** {@link TokenSet} containing all identifier types. */ private static final TokenSet IDENTIFIERS = TokenSet.create(IDENTIFIER, IDENTIFIER_BEGIN, IDENTIFIER_END); /** Default constructor. */ LatexInstructionExtImpl(ASTNode node) { super(node); } /** Returns list of identifiers and identifiers subtypes. */ @NotNull public PsiElement getIdentifier() { return findNotNullChildByType(IDENTIFIERS); } /** * Returns the {@link LatexInstruction} arguments list. * * @return {@link LatexArgument} instances list. */ @Override @NotNull public List getArgumentList() { return PsiTreeUtil.getChildrenOfTypeAsList(this, LatexArgument.class); } /** * Returns the {@link LatexInstruction} argument. * * @return {@link LatexArgument} instance. */ @Nullable public LatexArgument getArgument() { return findChildByClass(LatexArgument.class); } } ================================================ FILE: src/mobi/hsz/idea/latex/psi/impl/LatexSectionExtImpl.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.psi.util.PsiTreeUtil; import mobi.hsz.idea.latex.psi.*; import org.jetbrains.annotations.Nullable; /** * Abstract {@link LatexSection} implementation to provide shorthands for accessing {@link LatexInstructionBegin} * and {@link LatexInstructionEnd}. * * @author Jakub Chrzanowski * @since 0.3 */ public abstract class LatexSectionExtImpl extends LatexElementImpl implements LatexSection { LatexSectionExtImpl(ASTNode node) { super(node); } /** * Returns {@link LatexInstructionBegin} instance from given {@link LatexTypes#SECTION} element. * * @return begin instruction */ @Nullable public LatexInstructionBegin getBeginInstruction() { return PsiTreeUtil.getChildOfType(this, LatexInstructionBegin.class); } /** * Returns {@link LatexInstructionEnd} instance from given {@link LatexTypes#SECTION} element. * * @return end instruction */ @Nullable public LatexInstructionEnd getEndInstruction() { return PsiTreeUtil.getChildOfType(this, LatexInstructionEnd.class); } } ================================================ FILE: src/mobi/hsz/idea/latex/reference/LatexReferenceContributor.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.reference; import com.intellij.psi.*; import com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet; import com.intellij.util.ProcessingContext; import mobi.hsz.idea.latex.psi.LatexArgument; import mobi.hsz.idea.latex.psi.LatexFile; import mobi.hsz.idea.latex.psi.LatexInstruction; import mobi.hsz.idea.latex.psi.impl.LatexInstructionExtImpl; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import static com.intellij.patterns.PlatformPatterns.psiElement; import static com.intellij.patterns.PlatformPatterns.psiFile; /** * PSI elements references contributor. * * @author Jakub Chrzanowski * @since 0.3 */ public class LatexReferenceContributor extends PsiReferenceContributor { /** * Registers new references provider for PSI element. * * @param psiReferenceRegistrar reference provider */ @Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferenceRegistrar) { psiReferenceRegistrar.registerReferenceProvider(psiElement().inFile(psiFile(LatexFile.class)), new LatexReferenceProvider()); } /** Reference provider definition. */ private static class LatexReferenceProvider extends PsiReferenceProvider { private static final String[] IDENTIFIERS = {"\\input", "\\include", "\\includeonly"}; /** * Returns references for given @{link PsiElement}. * * @param psiElement current element * @param processingContext context * @return {@link PsiReference} list */ @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { if (psiElement instanceof LatexInstruction) { LatexInstructionExtImpl instruction = (LatexInstructionExtImpl) psiElement; String identifier = instruction.getIdentifier().getText(); if (Arrays.asList(IDENTIFIERS).contains(identifier)) { LatexArgument arg = instruction.getArgument(); if (arg != null && arg.getValue() != null) { return new FileReferenceSet(arg.getValue(), instruction, arg.getStartOffsetInParent() + 1, this, true).getAllReferences(); } } } return PsiReference.EMPTY_ARRAY; } } } ================================================ FILE: src/mobi/hsz/idea/latex/settings/LatexSettings.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2017 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.settings; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.util.containers.ContainerUtil; import mobi.hsz.idea.latex.util.Listenable; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; /** * Persistent global settings object for the LaTeX plugin. * * @author Jakub Chrzanowski * @since 0.3.0 */ @State( name = "LatexSettings", storages = @Storage(id = "other", file = "$APP_CONFIG$/latex.xml") ) public class LatexSettings implements PersistentStateComponent, Listenable { /** Settings keys. */ public enum KEY { ROOT("LatexSettings"), VERSION("version"); private final String key; KEY(@NotNull String key) { this.key = key; } @Override public String toString() { return this.key; } } /** Plugin version. */ private String version; /** Listeners list. */ private final List listeners = ContainerUtil.newArrayList(); /** * Get the instance of this service. * * @return the unique {@link LatexSettings} instance. */ public static LatexSettings getInstance() { return ServiceManager.getService(LatexSettings.class); } /** * Get the settings state as a DOM element. * * @return an ready to serialize DOM {@link Element}. * @see {@link #loadState(Element)} */ @Nullable @Override public Element getState() { final Element element = new Element(KEY.ROOT.toString()); element.setAttribute(KEY.VERSION.toString(), version); return element; } /** * Load the settings state from the DOM {@link Element}. * * @param element the {@link Element} to load values from. * @see {@link #getState()} */ @Override public void loadState(Element element) { String value = element.getAttributeValue(KEY.VERSION.toString()); if (value != null) version = value; } /** * Returns plugin version. * * @return version */ public String getVersion() { return version; } /** * Sets plugin version. * * @param version of the plugin */ public void setVersion(@NotNull String version) { this.notifyOnChange(KEY.VERSION, this.version, version); this.version = version; } /** * Add the given listener. The listener will be executed in the containing instance's thread. * * @param listener listener to add */ @Override public void addListener(@NotNull Listener listener) { listeners.add(listener); } /** * Remove the given listener. * * @param listener listener to remove */ @Override public void removeListener(@NotNull Listener listener) { listeners.remove(listener); } /** * Notifies listeners about the changes. * * @param key changed property key * @param oldValue new value * @param newValue new value */ private void notifyOnChange(KEY key, Object oldValue, Object newValue) { if (!newValue.equals(oldValue)) { for (Listener listener : listeners) { listener.onChange(key, newValue); } } } /** Listener interface for onChange event. */ public interface Listener { void onChange(@NotNull KEY key, Object value); } } ================================================ FILE: src/mobi/hsz/idea/latex/ui/ImageEditorActionDialog.form ================================================

    ================================================ FILE: src/mobi/hsz/idea/latex/ui/ImageEditorActionDialog.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.ui; import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import mobi.hsz.idea.latex.LatexBundle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; public class ImageEditorActionDialog extends DialogWrapper { private JPanel panel; private TextFieldWithBrowseButton path; private JTextField caption; private JTextField label; public ImageEditorActionDialog(@NotNull Project project) { super(project); path.addBrowseFolderListener(LatexBundle.message("editor.image.dialog.browse"), null, project, FileChooserDescriptorFactory.createSingleFileDescriptor()); setTitle(LatexBundle.message("editor.image.dialog.title")); init(); } @Nullable @Override protected JComponent createCenterPanel() { return panel; } @NotNull public String getPath() { return path.getText().trim(); } @NotNull public String getCaption() { return caption.getText().trim(); } @NotNull public String getLabel() { return label.getText().trim(); } } ================================================ FILE: src/mobi/hsz/idea/latex/ui/MatrixEditorActionDialog.form ================================================
    ================================================ FILE: src/mobi/hsz/idea/latex/ui/MatrixEditorActionDialog.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.ui; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import mobi.hsz.idea.latex.LatexBundle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; public class MatrixEditorActionDialog extends DialogWrapper { public enum Bracket { NONE('\0'), PARENTHESES('p'), BRACKETS('b'), BRACES('B'), SINGLE_LINE('v'), DOUBLE_LINE('V'); private final char value; Bracket(char value) { this.value = value; } public char getValue() { return value; } @Override public String toString() { return LatexBundle.message("form.bracket." + name().toLowerCase()); } } private JPanel panel; private JSpinner rows; private JSpinner columns; private JComboBox bracket; public MatrixEditorActionDialog(@NotNull Project project) { super(project); setTitle(LatexBundle.message("editor.matrix.dialog.title")); rows.setModel(new SpinnerNumberModel(2, 1, null, 1)); columns.setModel(new SpinnerNumberModel(2, 1, null, 1)); bracket.setModel(new DefaultComboBoxModel(Bracket.values())); init(); } @Nullable @Override protected JComponent createCenterPanel() { return panel; } public int getRows() { return (Integer) rows.getValue(); } public int getColumns() { return (Integer) columns.getValue(); } @NotNull public Bracket getBracket() { return (Bracket) bracket.getSelectedItem(); } } ================================================ FILE: src/mobi/hsz/idea/latex/ui/TableEditorActionDialog.form ================================================
    ================================================ FILE: src/mobi/hsz/idea/latex/ui/TableEditorActionDialog.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.ui; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.DialogWrapper; import mobi.hsz.idea.latex.LatexBundle; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; public class TableEditorActionDialog extends DialogWrapper { public enum Alignment { LEFT('l'), CENTER('c'), RIGHT('r'); private final char value; Alignment(char value) { this.value = value; } public char getValue() { return value; } @Override public String toString() { return LatexBundle.message("form.alignment." + name().toLowerCase()); } } public enum Border { NONE, TABLE, CELL; public boolean isNone() { return this.equals(NONE); } public boolean isTable() { return this.equals(TABLE); } public boolean isCell() { return this.equals(CELL); } @Override public String toString() { return LatexBundle.message("form.border." + name().toLowerCase()); } } private JPanel panel; private JSpinner rows; private JSpinner columns; private JComboBox alignment; private JComboBox border; public TableEditorActionDialog(@NotNull Project project) { super(project); setTitle(LatexBundle.message("editor.table.dialog.title")); rows.setModel(new SpinnerNumberModel(2, 1, null, 1)); columns.setModel(new SpinnerNumberModel(2, 1, null, 1)); alignment.setModel(new DefaultComboBoxModel(Alignment.values())); border.setModel(new DefaultComboBoxModel(Border.values())); init(); } @Nullable @Override protected JComponent createCenterPanel() { return panel; } public int getRows() { return (Integer) rows.getValue(); } public int getColumns() { return (Integer) columns.getValue(); } @NotNull public Alignment getAlignment() { return (Alignment) alignment.getSelectedItem(); } @NotNull public Border getBorder() { return (Border) border.getSelectedItem(); } } ================================================ FILE: src/mobi/hsz/idea/latex/util/Icons.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.util; import com.intellij.openapi.util.IconLoader; import javax.swing.*; /** * {@link Icons} class that holds icon resources. * * @author Jakub Chrzanowski * @since 0.1 */ public class Icons { public static final Icon FILE = IconLoader.getIcon("/icons/tex.png"); public static class Editor { public static final Icon ALIGN_LEFT = IconLoader.getIcon("/icons/editor/align_left.png"); public static final Icon ALIGN_CENTER = IconLoader.getIcon("/icons/editor/align_center.png"); public static final Icon ALIGN_RIGHT = IconLoader.getIcon("/icons/editor/align_right.png"); public static final Icon BOLD = IconLoader.getIcon("/icons/editor/bold.png"); public static final Icon IMAGE = IconLoader.getIcon("/icons/editor/image.png"); public static final Icon ITALIC = IconLoader.getIcon("/icons/editor/italic.png"); public static final Icon MATRIX = IconLoader.getIcon("/icons/editor/matrix.png"); public static final Icon TABLE = IconLoader.getIcon("/icons/editor/table.png"); public static final Icon UNDERLINE = IconLoader.getIcon("/icons/editor/underline.png"); } } ================================================ FILE: src/mobi/hsz/idea/latex/util/Listenable.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2017 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.util; import org.jetbrains.annotations.NotNull; /** * Abstracts a listenable object. * * @author Jakub Chrzanowski * @since 0.3.0 */ public interface Listenable { /** * Add the given listener. The listener will be executed in the containing instance's thread. * * @param listener listener to add */ void addListener(@NotNull T listener); /** * Remove the given listener. * * @param listener listener to remove */ void removeListener(@NotNull T listener); } ================================================ FILE: src/mobi/hsz/idea/latex/util/Resources.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2016 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.util; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.InputStream; import java.net.URL; import java.util.Scanner; /** * {@link Resources} util class that contains methods that work on plugin's resources. * * @author Jakub Chrzanowski * @since 0.2 */ public class Resources { /** Private constructor to prevent creating {@link Resources} instance. */ private Resources() { } /** * Returns gitignore templates directory * * @return Resources directory */ @NotNull public static File getResource(@Nullable String path) { URL resource = Resources.class.getResource(path); assert resource != null; return new File(resource.getPath()); } /** * Reads resource file and returns its content as a String * * @param path Resource path * @return Content */ @NotNull public static String getResourceContent(@Nullable String path) { return convertStreamToString(Resources.class.getResourceAsStream(path)); } /** * Converts InputStream resource to String * * @param inputStream Input stream * @return Content */ @NotNull private static String convertStreamToString(InputStream inputStream) { Scanner s = new Scanner(inputStream).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } } ================================================ FILE: src/mobi/hsz/idea/latex/util/Utils.java ================================================ /* * The MIT License (MIT) * * Copyright (c) 2017 hsz Jakub Chrzanowski * * 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. */ package mobi.hsz.idea.latex.util; import com.intellij.ide.plugins.IdeaPluginDescriptor; import com.intellij.ide.plugins.PluginManager; import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.util.text.StringUtil; import mobi.hsz.idea.latex.LatexBundle; /** * {@link Utils} class that contains various methods. * * @author Jakub Chrzanowski * @since 0.3.0 */ public class Utils { /** Private constructor to prevent creating {@link Utils} instance. */ private Utils() { } /** * Returns Gitignore plugin information. * * @return {@link IdeaPluginDescriptor} */ public static IdeaPluginDescriptor getPlugin() { return PluginManager.getPlugin(PluginId.getId(LatexBundle.PLUGIN_ID)); } /** * Returns plugin major version. * * @return major version */ public static String getMajorVersion() { return getVersion().split("\\.")[0]; } /** * Returns plugin minor version. * * @return minor version */ public static String getMinorVersion() { return StringUtil.join(getVersion().split("\\."), 0, 2, "."); } /** * Returns plugin version. * * @return version */ public static String getVersion() { return getPlugin().getVersion(); } }