diff --git a/examples/codeviewer/build.gradle.kts b/examples/codeviewer/build.gradle.kts index 0c00883af5..8d0c1f3d7c 100644 --- a/examples/codeviewer/build.gradle.kts +++ b/examples/codeviewer/build.gradle.kts @@ -14,5 +14,6 @@ allprojects { google() mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + mavenLocal() } } diff --git a/experimental/examples/codeviewer/.gitignore b/experimental/examples/codeviewer/.gitignore index ba8435b9c5..e949f25f51 100644 --- a/experimental/examples/codeviewer/.gitignore +++ b/experimental/examples/codeviewer/.gitignore @@ -2,14 +2,14 @@ .gradle /local.properties /.idea -/.idea/caches -/.idea/libraries -/.idea/modules.xml -/.idea/workspace.xml -/.idea/navEditor.xml -/.idea/assetWizardSettings.xml .DS_Store build/ /captures .externalNativeBuild -.cxx \ No newline at end of file +.cxx +iosApp/Podfile.lock +iosApp/Pods/* +iosApp/Codeviewer.xcworkspace/* +iosApp/Codeviewer.xcodeproj/* +!iosApp/Codeviewer.xcodeproj/project.pbxproj +shared/shared.podspec diff --git a/experimental/examples/codeviewer/.run/desktop.run.xml b/experimental/examples/codeviewer/.run/desktop.run.xml deleted file mode 100644 index d9335c1be5..0000000000 --- a/experimental/examples/codeviewer/.run/desktop.run.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - true - - - \ No newline at end of file diff --git a/experimental/examples/codeviewer/.run/desktopApp.run.xml b/experimental/examples/codeviewer/.run/desktopApp.run.xml new file mode 100644 index 0000000000..2d56d7f072 --- /dev/null +++ b/experimental/examples/codeviewer/.run/desktopApp.run.xml @@ -0,0 +1,28 @@ + + + + + + + + true + true + false + + + \ No newline at end of file diff --git a/experimental/examples/codeviewer/.run/iosApp.run.xml b/experimental/examples/codeviewer/.run/iosApp.run.xml new file mode 100644 index 0000000000..cb9a3578f1 --- /dev/null +++ b/experimental/examples/codeviewer/.run/iosApp.run.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/experimental/examples/codeviewer/.run/iosApp_.run.xml b/experimental/examples/codeviewer/.run/iosApp_.run.xml new file mode 100644 index 0000000000..b8737d8dd8 --- /dev/null +++ b/experimental/examples/codeviewer/.run/iosApp_.run.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/experimental/examples/codeviewer/README.md b/experimental/examples/codeviewer/README.md index 172adda0ce..6a5b097c67 100644 --- a/experimental/examples/codeviewer/README.md +++ b/experimental/examples/codeviewer/README.md @@ -1,10 +1,22 @@ -MPP Code Viewer example for desktop/android written in Multiplatform Compose library. +# Code Viewer +MPP Code Viewer example for desktop/android/iOS written in Multiplatform Compose library. -### Running desktop application +## How to run -* To run, launch command: `./gradlew :desktop:run` -* Or choose **desktop** configuration in IDE and run it. - ![desktop-run-configuration.png](screenshots/desktop-run-configuration.png) +Choose a run configuration for an appropriate target in IDE and run it. + +![run-configurations.png](run-configurations.png) + +To run on iOS device, please correct `iosApp/Configuration/TeamId.xcconfig` with your Apple Team ID. +Alternatively, you may setup signing within XCode opening `iosApp/Codeviewer.xcworkspace` and then +using "Signing & Capabilities" tab of `Codeviewer` target. + +Then choose **iosApp** configuration in IDE and run it +(may also be referred as `Codeviewer` in the Run Configurations or `iosApp_` for Android studio). + +## Run on desktop via Gradle + +`./gradlew desktopApp:run` ### Building native desktop distribution ``` @@ -12,9 +24,4 @@ MPP Code Viewer example for desktop/android written in Multiplatform Compose lib # outputs are written to desktop/build/compose/binaries ``` -### Installing Android application on device/emulator -``` -./gradlew installDebug -``` - ![Desktop](screenshots/codeviewer.png) \ No newline at end of file diff --git a/experimental/examples/codeviewer/android/build.gradle.kts b/experimental/examples/codeviewer/android/build.gradle.kts deleted file mode 100644 index 13073d45fb..0000000000 --- a/experimental/examples/codeviewer/android/build.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - id("com.android.application") - kotlin("android") - id("org.jetbrains.compose") -} - -android { - compileSdk = 32 - - defaultConfig { - minSdk = 26 - targetSdk = 32 - versionCode = 1 - versionName = "1.0" - } - - compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } -} - -dependencies { - implementation(project(":common")) - implementation("androidx.activity:activity-compose:1.5.0") -} \ No newline at end of file diff --git a/experimental/examples/codeviewer/androidApp/build.gradle.kts b/experimental/examples/codeviewer/androidApp/build.gradle.kts new file mode 100644 index 0000000000..b65e1126a2 --- /dev/null +++ b/experimental/examples/codeviewer/androidApp/build.gradle.kts @@ -0,0 +1,33 @@ +plugins { + kotlin("multiplatform") + id("com.android.application") + id("org.jetbrains.compose") +} + +kotlin { + android() + sourceSets { + val androidMain by getting { + dependencies { + implementation(project(":shared")) + implementation("androidx.appcompat:appcompat:1.5.1") + implementation("androidx.activity:activity-compose:1.6.1") + } + } + } +} + +android { + compileSdk = 33 + defaultConfig { + applicationId = "org.jetbrains.Codeviewer" + minSdk = 24 + targetSdk = 33 + versionCode = 1 + versionName = "1.0" + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} diff --git a/experimental/examples/codeviewer/android/src/main/AndroidManifest.xml b/experimental/examples/codeviewer/androidApp/src/main/AndroidManifest.xml similarity index 100% rename from experimental/examples/codeviewer/android/src/main/AndroidManifest.xml rename to experimental/examples/codeviewer/androidApp/src/main/AndroidManifest.xml diff --git a/experimental/examples/codeviewer/android/src/main/assets/data/EditorView.kt b/experimental/examples/codeviewer/androidApp/src/main/assets/data/EditorView.kt similarity index 100% rename from experimental/examples/codeviewer/android/src/main/assets/data/EditorView.kt rename to experimental/examples/codeviewer/androidApp/src/main/assets/data/EditorView.kt diff --git a/experimental/examples/codeviewer/android/src/main/java/org/jetbrains/codeviewer/MainActivity.kt b/experimental/examples/codeviewer/androidApp/src/main/java/org/jetbrains/codeviewer/MainActivity.kt similarity index 95% rename from experimental/examples/codeviewer/android/src/main/java/org/jetbrains/codeviewer/MainActivity.kt rename to experimental/examples/codeviewer/androidApp/src/main/java/org/jetbrains/codeviewer/MainActivity.kt index 872c04c87a..850c63ef7d 100644 --- a/experimental/examples/codeviewer/android/src/main/java/org/jetbrains/codeviewer/MainActivity.kt +++ b/experimental/examples/codeviewer/androidApp/src/main/java/org/jetbrains/codeviewer/MainActivity.kt @@ -4,7 +4,7 @@ import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity import org.jetbrains.codeviewer.platform._HomeFolder -import org.jetbrains.codeviewer.ui.MainView +import MainView import java.io.File import java.io.FileOutputStream diff --git a/experimental/examples/codeviewer/android/src/main/res/drawable/ic_launcher_foreground.xml b/experimental/examples/codeviewer/androidApp/src/main/res/drawable/ic_launcher_foreground.xml similarity index 100% rename from experimental/examples/codeviewer/android/src/main/res/drawable/ic_launcher_foreground.xml rename to experimental/examples/codeviewer/androidApp/src/main/res/drawable/ic_launcher_foreground.xml diff --git a/experimental/examples/codeviewer/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/experimental/examples/codeviewer/androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from experimental/examples/codeviewer/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to experimental/examples/codeviewer/androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/experimental/examples/codeviewer/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/experimental/examples/codeviewer/androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from experimental/examples/codeviewer/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to experimental/examples/codeviewer/androidApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/experimental/examples/codeviewer/android/src/main/res/values/ic_launcher_background.xml b/experimental/examples/codeviewer/androidApp/src/main/res/values/ic_launcher_background.xml similarity index 100% rename from experimental/examples/codeviewer/android/src/main/res/values/ic_launcher_background.xml rename to experimental/examples/codeviewer/androidApp/src/main/res/values/ic_launcher_background.xml diff --git a/experimental/examples/codeviewer/android/src/main/res/values/strings.xml b/experimental/examples/codeviewer/androidApp/src/main/res/values/strings.xml similarity index 100% rename from experimental/examples/codeviewer/android/src/main/res/values/strings.xml rename to experimental/examples/codeviewer/androidApp/src/main/res/values/strings.xml diff --git a/experimental/examples/codeviewer/build.gradle.kts b/experimental/examples/codeviewer/build.gradle.kts index 0c00883af5..8d0c1f3d7c 100644 --- a/experimental/examples/codeviewer/build.gradle.kts +++ b/experimental/examples/codeviewer/build.gradle.kts @@ -14,5 +14,6 @@ allprojects { google() mavenCentral() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") + mavenLocal() } } diff --git a/experimental/examples/codeviewer/common/build.gradle.kts b/experimental/examples/codeviewer/common/build.gradle.kts deleted file mode 100644 index 1b8e451301..0000000000 --- a/experimental/examples/codeviewer/common/build.gradle.kts +++ /dev/null @@ -1,50 +0,0 @@ -plugins { - id("com.android.library") - kotlin("multiplatform") - id("org.jetbrains.compose") -} - -kotlin { - android() - jvm("desktop") - - sourceSets { - named("commonMain") { - dependencies { - api(compose.runtime) - api(compose.foundation) - api(compose.material) - api(compose.materialIconsExtended) - } - } - named("androidMain") { - kotlin.srcDirs("src/jvmMain/kotlin") - dependencies { - api("androidx.appcompat:appcompat:1.5.1") - api("androidx.core:core-ktx:1.8.0") - } - } - named("desktopMain") { - kotlin.srcDirs("src/jvmMain/kotlin") - dependencies { - api(compose.desktop.common) - } - } - } -} - -android { - compileSdk = 32 - - defaultConfig { - minSdk = 26 - targetSdk = 32 - } - - sourceSets { - named("main") { - manifest.srcFile("src/androidMain/AndroidManifest.xml") - res.srcDirs("src/androidMain/res", "src/commonMain/resources") - } - } -} diff --git a/experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt deleted file mode 100644 index 7726dbb3e7..0000000000 --- a/experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.jetbrains.codeviewer.platform - -import androidx.compose.ui.ExperimentalComposeUiApi -import androidx.compose.ui.Modifier -import androidx.compose.ui.input.pointer.PointerIcon -import androidx.compose.ui.input.pointer.pointerHoverIcon -import java.awt.Cursor - -actual fun Modifier.cursorForHorizontalResize(): Modifier = - this.pointerHoverIcon(PointerIcon(Cursor(Cursor.E_RESIZE_CURSOR))) diff --git a/experimental/examples/codeviewer/desktop/build.gradle.kts b/experimental/examples/codeviewer/desktopApp/build.gradle.kts similarity index 82% rename from experimental/examples/codeviewer/desktop/build.gradle.kts rename to experimental/examples/codeviewer/desktopApp/build.gradle.kts index e7263fd745..240574ab9e 100644 --- a/experimental/examples/codeviewer/desktop/build.gradle.kts +++ b/experimental/examples/codeviewer/desktopApp/build.gradle.kts @@ -1,17 +1,17 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat plugins { - kotlin("multiplatform") // kotlin("jvm") doesn't work well in IDEA/AndroidStudio (https://github.com/JetBrains/compose-jb/issues/22) + kotlin("multiplatform") id("org.jetbrains.compose") } kotlin { jvm {} sourceSets { - named("jvmMain") { + val jvmMain by getting { dependencies { implementation(compose.desktop.currentOs) - implementation(project(":common")) + implementation(project(":shared")) } } } diff --git a/experimental/examples/codeviewer/desktop/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt b/experimental/examples/codeviewer/desktopApp/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt similarity index 92% rename from experimental/examples/codeviewer/desktop/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt rename to experimental/examples/codeviewer/desktopApp/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt index b3e70a808f..cfe2817302 100644 --- a/experimental/examples/codeviewer/desktop/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt +++ b/experimental/examples/codeviewer/desktopApp/src/jvmMain/kotlin/org/jetbrains/codeviewer/main.kt @@ -6,7 +6,7 @@ import androidx.compose.ui.res.useResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.WindowState import androidx.compose.ui.window.singleWindowApplication -import org.jetbrains.codeviewer.ui.MainView +import MainView fun main() = singleWindowApplication( title = "Code Viewer", diff --git a/experimental/examples/codeviewer/desktop/src/jvmMain/resources/ic_launcher.png b/experimental/examples/codeviewer/desktopApp/src/jvmMain/resources/ic_launcher.png similarity index 100% rename from experimental/examples/codeviewer/desktop/src/jvmMain/resources/ic_launcher.png rename to experimental/examples/codeviewer/desktopApp/src/jvmMain/resources/ic_launcher.png diff --git a/experimental/examples/codeviewer/gradle.properties b/experimental/examples/codeviewer/gradle.properties index c18fa7d46c..ea83c74d6a 100644 --- a/experimental/examples/codeviewer/gradle.properties +++ b/experimental/examples/codeviewer/gradle.properties @@ -1,24 +1,17 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app"s APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn -android.useAndroidX=true -# Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true -# Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official +xcodeproj=./iosApp +kotlin.native.cocoapods.generate.wrapper=true +android.useAndroidX=true +org.gradle.jvmargs=-Xmx3g +org.jetbrains.compose.experimental.jscanvas.enabled=true +org.jetbrains.compose.experimental.macos.enabled=true +org.jetbrains.compose.experimental.uikit.enabled=true +kotlin.native.cacheKind=none +kotlin.native.useEmbeddableCompilerJar=true +kotlin.native.enableDependencyPropagation=false +kotlin.mpp.enableGranularSourceSetsMetadata=true +# Enable kotlin/native experimental memory model +kotlin.native.binary.memoryModel=experimental kotlin.version=1.7.20 agp.version=7.1.3 -compose.version=1.2.1 +compose.version=1.3.0-beta04-dev885 diff --git a/experimental/examples/codeviewer/gradle/wrapper/gradle-wrapper.jar b/experimental/examples/codeviewer/gradle/wrapper/gradle-wrapper.jar index 62d4c05355..249e5832f0 100644 Binary files a/experimental/examples/codeviewer/gradle/wrapper/gradle-wrapper.jar and b/experimental/examples/codeviewer/gradle/wrapper/gradle-wrapper.jar differ diff --git a/experimental/examples/codeviewer/gradlew b/experimental/examples/codeviewer/gradlew index 2fe81a7d95..a69d9cb6c2 100755 --- a/experimental/examples/codeviewer/gradlew +++ b/experimental/examples/codeviewer/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -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 +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + 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 @@ -105,79 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "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 +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# 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 +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; 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 +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - 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\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - 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 -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/experimental/examples/codeviewer/gradlew.bat b/experimental/examples/codeviewer/gradlew.bat index 9618d8d960..f127cfd49d 100644 --- a/experimental/examples/codeviewer/gradlew.bat +++ b/experimental/examples/codeviewer/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,13 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,38 +64,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_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=%* - :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% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 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 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/experimental/examples/codeviewer/iosApp/Codeviewer.xcodeproj/project.pbxproj b/experimental/examples/codeviewer/iosApp/Codeviewer.xcodeproj/project.pbxproj new file mode 100644 index 0000000000..df3eca3e08 --- /dev/null +++ b/experimental/examples/codeviewer/iosApp/Codeviewer.xcodeproj/project.pbxproj @@ -0,0 +1,398 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 2152FB042600AC8F00CF470E /* iosApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iosApp.swift */; }; + C1FC908188C4E8695729CB06 /* Pods_Codeviewer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DE96E47030356CE6AD9794A /* Pods_Codeviewer.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 1EB65E27D2C0F884D0A1A133 /* Pods-Codeviewer.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Codeviewer.debug.xcconfig"; path = "Target Support Files/Pods-Codeviewer/Pods-Codeviewer.debug.xcconfig"; sourceTree = ""; }; + 2152FB032600AC8F00CF470E /* iosApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iosApp.swift; sourceTree = ""; }; + 3D7A606AB0AD7636269BD9D0 /* Pods-Codeviewer.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Codeviewer.release.xcconfig"; path = "Target Support Files/Pods-Codeviewer/Pods-Codeviewer.release.xcconfig"; sourceTree = ""; }; + 7555FF7B242A565900829871 /* Codeviewer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Codeviewer.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 8DE96E47030356CE6AD9794A /* Pods_Codeviewer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Codeviewer.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + AB3632DC29227652001CCB65 /* TeamId.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = TeamId.xcconfig; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 9964867F0862B4D9FB6ABFC7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + C1FC908188C4E8695729CB06 /* Pods_Codeviewer.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 7555FF72242A565900829871 = { + isa = PBXGroup; + children = ( + AB1DB47929225F7C00F7AF9C /* Configuration */, + 7555FF7D242A565900829871 /* iosApp */, + 7555FF7C242A565900829871 /* Products */, + E1DAFBE8E1CFC0878361EF0E /* Pods */, + B62309C7396AD7BF607A63B2 /* Frameworks */, + ); + sourceTree = ""; + }; + 7555FF7C242A565900829871 /* Products */ = { + isa = PBXGroup; + children = ( + 7555FF7B242A565900829871 /* Codeviewer.app */, + ); + name = Products; + sourceTree = ""; + }; + 7555FF7D242A565900829871 /* iosApp */ = { + isa = PBXGroup; + children = ( + 7555FF8C242A565B00829871 /* Info.plist */, + 2152FB032600AC8F00CF470E /* iosApp.swift */, + ); + path = iosApp; + sourceTree = ""; + }; + AB1DB47929225F7C00F7AF9C /* Configuration */ = { + isa = PBXGroup; + children = ( + AB3632DC29227652001CCB65 /* TeamId.xcconfig */, + ); + path = Configuration; + sourceTree = ""; + }; + B62309C7396AD7BF607A63B2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 8DE96E47030356CE6AD9794A /* Pods_Codeviewer.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + E1DAFBE8E1CFC0878361EF0E /* Pods */ = { + isa = PBXGroup; + children = ( + 1EB65E27D2C0F884D0A1A133 /* Pods-Codeviewer.debug.xcconfig */, + 3D7A606AB0AD7636269BD9D0 /* Pods-Codeviewer.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 7555FF7A242A565900829871 /* Codeviewer */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "Codeviewer" */; + buildPhases = ( + E8D673591E7196AEA2EA10E2 /* [CP] Check Pods Manifest.lock */, + 7555FF77242A565900829871 /* Sources */, + 7555FF79242A565900829871 /* Resources */, + 9964867F0862B4D9FB6ABFC7 /* Frameworks */, + 36D9E9FD1C89A17F9A69F669 /* [CP] Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Codeviewer; + productName = iosApp; + productReference = 7555FF7B242A565900829871 /* Codeviewer.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 7555FF73242A565900829871 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1130; + LastUpgradeCheck = 1130; + ORGANIZATIONNAME = org.jetbrains; + TargetAttributes = { + 7555FF7A242A565900829871 = { + CreatedOnToolsVersion = 11.3.1; + }; + }; + }; + buildConfigurationList = 7555FF76242A565900829871 /* Build configuration list for PBXProject "Codeviewer" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 7555FF72242A565900829871; + productRefGroup = 7555FF7C242A565900829871 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 7555FF7A242A565900829871 /* Codeviewer */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 7555FF79242A565900829871 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 36D9E9FD1C89A17F9A69F669 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Codeviewer/Pods-Codeviewer-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Codeviewer/Pods-Codeviewer-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Codeviewer/Pods-Codeviewer-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + E8D673591E7196AEA2EA10E2 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Codeviewer-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 7555FF77242A565900829871 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2152FB042600AC8F00CF470E /* iosApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 7555FFA3242A565B00829871 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = AB3632DC29227652001CCB65 /* TeamId.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.1; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 7555FFA4242A565B00829871 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = AB3632DC29227652001CCB65 /* TeamId.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.1; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 7555FFA6242A565B00829871 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 1EB65E27D2C0F884D0A1A133 /* Pods-Codeviewer.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_ASSET_PATHS = ""; + DEVELOPMENT_TEAM = "${TEAM_ID}"; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = iosApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 14.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "org.jetbrains.Codeviewer${TEAM_ID}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 7555FFA7242A565B00829871 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3D7A606AB0AD7636269BD9D0 /* Pods-Codeviewer.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_ASSET_PATHS = ""; + DEVELOPMENT_TEAM = "${TEAM_ID}"; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = iosApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 14.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "org.jetbrains.Codeviewer${TEAM_ID}"; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 7555FF76242A565900829871 /* Build configuration list for PBXProject "Codeviewer" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7555FFA3242A565B00829871 /* Debug */, + 7555FFA4242A565B00829871 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "Codeviewer" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7555FFA6242A565B00829871 /* Debug */, + 7555FFA7242A565B00829871 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 7555FF73242A565900829871 /* Project object */; +} diff --git a/experimental/examples/codeviewer/iosApp/Configuration/TeamId.xcconfig b/experimental/examples/codeviewer/iosApp/Configuration/TeamId.xcconfig new file mode 100644 index 0000000000..bf06eb27e9 --- /dev/null +++ b/experimental/examples/codeviewer/iosApp/Configuration/TeamId.xcconfig @@ -0,0 +1 @@ +TEAM_ID= diff --git a/experimental/examples/codeviewer/iosApp/Podfile b/experimental/examples/codeviewer/iosApp/Podfile new file mode 100644 index 0000000000..d2bd79b172 --- /dev/null +++ b/experimental/examples/codeviewer/iosApp/Podfile @@ -0,0 +1,5 @@ +target 'Codeviewer' do + use_frameworks! + platform :ios, '14.1' + pod 'shared', :path => '../shared' +end \ No newline at end of file diff --git a/experimental/examples/codeviewer/iosApp/iosApp/Info.plist b/experimental/examples/codeviewer/iosApp/iosApp/Info.plist new file mode 100644 index 0000000000..9a269f5eaa --- /dev/null +++ b/experimental/examples/codeviewer/iosApp/iosApp/Info.plist @@ -0,0 +1,48 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + + UILaunchScreen + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/experimental/examples/codeviewer/iosApp/iosApp/iosApp.swift b/experimental/examples/codeviewer/iosApp/iosApp/iosApp.swift new file mode 100644 index 0000000000..b42016a6fc --- /dev/null +++ b/experimental/examples/codeviewer/iosApp/iosApp/iosApp.swift @@ -0,0 +1,15 @@ +import UIKit +import shared + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + var window: UIWindow? + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + window = UIWindow(frame: UIScreen.main.bounds) + let mainViewController = Main_iosKt.MainViewController() + window?.rootViewController = mainViewController + window?.makeKeyAndVisible() + return true + } +} diff --git a/experimental/examples/codeviewer/run-configurations.png b/experimental/examples/codeviewer/run-configurations.png new file mode 100644 index 0000000000..0840602f9b Binary files /dev/null and b/experimental/examples/codeviewer/run-configurations.png differ diff --git a/experimental/examples/codeviewer/screenshots/desktop-run-configuration.png b/experimental/examples/codeviewer/screenshots/desktop-run-configuration.png deleted file mode 100644 index 3688407c6f..0000000000 Binary files a/experimental/examples/codeviewer/screenshots/desktop-run-configuration.png and /dev/null differ diff --git a/experimental/examples/codeviewer/settings.gradle.kts b/experimental/examples/codeviewer/settings.gradle.kts index c2ab465cc8..a1d0b79e3e 100644 --- a/experimental/examples/codeviewer/settings.gradle.kts +++ b/experimental/examples/codeviewer/settings.gradle.kts @@ -3,6 +3,7 @@ pluginManagement { gradlePluginPortal() maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") google() + mavenLocal() } plugins { @@ -20,4 +21,8 @@ pluginManagement { } } -include(":common", ":android", ":desktop") +rootProject.name = "codeviewer" + +include(":androidApp") +include(":shared") +include(":desktopApp") diff --git a/experimental/examples/codeviewer/shared/build.gradle.kts b/experimental/examples/codeviewer/shared/build.gradle.kts new file mode 100644 index 0000000000..f37617b2fe --- /dev/null +++ b/experimental/examples/codeviewer/shared/build.gradle.kts @@ -0,0 +1,78 @@ +plugins { + kotlin("multiplatform") + kotlin("native.cocoapods") + id("com.android.library") + id("org.jetbrains.compose") +} + +version = "1.0-SNAPSHOT" + +kotlin { + android() + + jvm("desktop") + + ios() + iosSimulatorArm64() + + cocoapods { + summary = "Shared code for the sample" + homepage = "https://github.com/JetBrains/compose-jb" + ios.deploymentTarget = "14.1" + podfile = project.file("../iosApp/Podfile") + framework { + baseName = "shared" + } + extraSpecAttributes["resources"] = "['src/commonMain/resources/**', 'src/iosMain/resources/**']" + } + + val composeVersion = extra["compose.version"] as String + + sourceSets { + val commonMain by getting { + dependencies { + implementation(compose.runtime) + implementation(compose.foundation) + implementation(compose.material) + implementation(compose.materialIconsExtended) + implementation("org.jetbrains.compose.components:components-resources:$composeVersion") + } + } + val androidMain by getting { + kotlin.srcDirs("src/jvmMain/kotlin") + dependencies { + implementation("androidx.appcompat:appcompat:1.5.1") + implementation("androidx.core:core-ktx:1.8.0") + } + } + val iosMain by getting + val iosTest by getting + val iosSimulatorArm64Main by getting { + dependsOn(iosMain) + } + val iosSimulatorArm64Test by getting { + dependsOn(iosTest) + } + + val desktopMain by getting { + kotlin.srcDirs("src/jvmMain/kotlin") + dependencies { + implementation(compose.desktop.common) + } + } + } +} + +android { + compileSdk = 33 + sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") + sourceSets["main"].res.srcDirs("src/androidMain/res", "src/commonMain/resources") + defaultConfig { + minSdk = 24 + targetSdk = 33 + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} diff --git a/experimental/examples/codeviewer/common/src/androidMain/AndroidManifest.xml b/experimental/examples/codeviewer/shared/src/androidMain/AndroidManifest.xml similarity index 100% rename from experimental/examples/codeviewer/common/src/androidMain/AndroidManifest.xml rename to experimental/examples/codeviewer/shared/src/androidMain/AndroidManifest.xml diff --git a/experimental/examples/codeviewer/shared/src/androidMain/kotlin/main.android.kt b/experimental/examples/codeviewer/shared/src/androidMain/kotlin/main.android.kt new file mode 100644 index 0000000000..faa491aedf --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/androidMain/kotlin/main.android.kt @@ -0,0 +1,5 @@ +import androidx.compose.runtime.Composable +import org.jetbrains.codeviewer.ui.MainView + +@Composable +fun MainView() = MainView() \ No newline at end of file diff --git a/experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/File.kt b/experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/File.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/File.kt rename to experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/File.kt diff --git a/experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt rename to experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt diff --git a/experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt rename to experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt diff --git a/experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt b/experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt rename to experimental/examples/codeviewer/shared/src/androidMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/File.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/File.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/File.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/File.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt similarity index 71% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt index d22698e61b..757e9f9511 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt @@ -6,4 +6,4 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.text.font.FontWeight @Composable -expect fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font \ No newline at end of file +internal expect fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font \ No newline at end of file diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt similarity index 83% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt index fd1f50c0d7..bb7f3dd5e9 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt @@ -7,13 +7,13 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.Dp @Composable -expect fun VerticalScrollbar( +internal expect fun VerticalScrollbar( modifier: Modifier, scrollState: ScrollState ) @Composable -expect fun VerticalScrollbar( +internal expect fun VerticalScrollbar( modifier: Modifier, scrollState: LazyListState ) \ No newline at end of file diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewer.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewer.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewer.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewer.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt similarity index 98% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt index cfc8ef796d..aa54964e03 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/CodeViewerView.kt @@ -26,7 +26,7 @@ import org.jetbrains.codeviewer.util.SplitterState import org.jetbrains.codeviewer.util.VerticalSplittable @Composable -fun CodeViewerView(model: CodeViewer) { +internal fun CodeViewerView(model: CodeViewer) { val panelState = remember { PanelState() } val animatedSize = if (panelState.splitter.isResizing) { diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt similarity index 97% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt index 7648efd5c0..b9959a68ef 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/MainView.kt @@ -12,7 +12,7 @@ import org.jetbrains.codeviewer.ui.editor.Editors import org.jetbrains.codeviewer.ui.filetree.FileTree @Composable -fun MainView() { +internal fun MainView() { val codeViewer = remember { val editors = Editors() diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt similarity index 96% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt index 70461d77e5..97e50febf7 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Fonts.kt @@ -8,7 +8,7 @@ import org.jetbrains.codeviewer.platform.font object Fonts { @Composable - fun jetbrainsMono() = FontFamily( + internal fun jetbrainsMono() = FontFamily( font( "JetBrains Mono", "jetbrainsmono_regular", diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Settings.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Settings.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Settings.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Settings.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Theme.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Theme.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Theme.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/common/Theme.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editor.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt similarity index 94% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt index 6e62993275..67d8f69f5b 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorEmptyView.kt @@ -16,7 +16,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @Composable -fun EditorEmptyView() = Box(Modifier.fillMaxSize()) { +internal fun EditorEmptyView() = Box(Modifier.fillMaxSize()) { Column(Modifier.align(Alignment.Center)) { Icon( Icons.Default.Code, diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt similarity index 93% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt index 845c48a547..973e8b742c 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorTabsView.kt @@ -24,14 +24,14 @@ import androidx.compose.ui.unit.sp import org.jetbrains.codeviewer.ui.common.AppTheme @Composable -fun EditorTabsView(model: Editors) = Row(Modifier.horizontalScroll(rememberScrollState())) { +internal fun EditorTabsView(model: Editors) = Row(Modifier.horizontalScroll(rememberScrollState())) { for (editor in model.editors) { EditorTabView(editor) } } @Composable -fun EditorTabView(model: Editor) = Surface( +internal fun EditorTabView(model: Editor) = Surface( color = if (model.isActive) { AppTheme.colors.backgroundDark } else { diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt similarity index 98% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt index af895553ee..d2b951f4bf 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/EditorView.kt @@ -32,7 +32,7 @@ import org.jetbrains.codeviewer.util.withoutWidthConstraints import kotlin.text.Regex.Companion.fromLiteral @Composable -fun EditorView(model: Editor, settings: Settings) = key(model) { +internal fun EditorView(model: Editor, settings: Settings) = key(model) { with (LocalDensity.current) { SelectionContainer { Surface( diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editors.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editors.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editors.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/editor/Editors.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTree.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTree.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTree.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTree.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt similarity index 97% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt index 9bc690a7a5..e441d781fb 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/filetree/FileTreeView.kt @@ -31,7 +31,7 @@ import org.jetbrains.codeviewer.platform.VerticalScrollbar import org.jetbrains.codeviewer.util.withoutWidthConstraints @Composable -fun FileTreeViewTabView() = Surface { +internal fun FileTreeViewTabView() = Surface { Row( Modifier.padding(8.dp), verticalAlignment = Alignment.CenterVertically @@ -46,7 +46,7 @@ fun FileTreeViewTabView() = Surface { } @Composable -fun FileTreeView(model: FileTree) = Surface( +internal fun FileTreeView(model: FileTree) = Surface( modifier = Modifier.fillMaxSize() ) { with(LocalDensity.current) { diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt similarity index 96% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt index d2e29c8d81..158368c895 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/ui/statusbar/StatusBar.kt @@ -16,7 +16,7 @@ private val MinFontSize = 6.sp private val MaxFontSize = 40.sp @Composable -fun StatusBar(settings: Settings) = Box( +internal fun StatusBar(settings: Settings) = Box( Modifier .height(32.dp) .fillMaxWidth() diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/LayoutModifiers.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/LayoutModifiers.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/LayoutModifiers.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/LayoutModifiers.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/Loadable.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/Loadable.kt similarity index 78% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/Loadable.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/Loadable.kt index 58d8945726..0c9a8928ef 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/Loadable.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/Loadable.kt @@ -5,14 +5,14 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope @Composable -fun loadable(load: () -> T): MutableState { +internal fun loadable(load: () -> T): MutableState { return loadableScoped { load() } } private val loadingKey = Any() @Composable -fun loadableScoped(load: CoroutineScope.() -> T): MutableState { +internal fun loadableScoped(load: CoroutineScope.() -> T): MutableState { val state: MutableState = remember { mutableStateOf(null) } LaunchedEffect(loadingKey) { try { diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/SingleSelection.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/SingleSelection.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/SingleSelection.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/SingleSelection.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/TextLines.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/TextLines.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/TextLines.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/TextLines.kt diff --git a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/VerticalSplittable.kt b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/VerticalSplittable.kt similarity index 98% rename from experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/VerticalSplittable.kt rename to experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/VerticalSplittable.kt index d9b2e0f896..e3f415bcd0 100644 --- a/experimental/examples/codeviewer/common/src/commonMain/kotlin/org/jetbrains/codeviewer/util/VerticalSplittable.kt +++ b/experimental/examples/codeviewer/shared/src/commonMain/kotlin/org/jetbrains/codeviewer/util/VerticalSplittable.kt @@ -22,7 +22,7 @@ import org.jetbrains.codeviewer.platform.cursorForHorizontalResize import org.jetbrains.codeviewer.ui.common.AppTheme @Composable -fun VerticalSplittable( +internal fun VerticalSplittable( modifier: Modifier, splitterState: SplitterState, onResize: (delta: Dp) -> Unit, @@ -57,7 +57,7 @@ class SplitterState { } @Composable -fun VerticalSplitter( +internal fun VerticalSplitter( splitterState: SplitterState, onResize: (delta: Dp) -> Unit, color: Color = AppTheme.colors.backgroundDark diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_bold.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_bold.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_bold.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_bold.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_bold_italic.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_bold_italic.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_bold_italic.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_bold_italic.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_extrabold.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_extrabold.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_extrabold.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_extrabold.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_extrabold_italic.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_extrabold_italic.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_extrabold_italic.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_extrabold_italic.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_italic.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_italic.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_italic.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_italic.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_medium.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_medium.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_medium.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_medium.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_medium_italic.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_medium_italic.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_medium_italic.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_medium_italic.ttf diff --git a/experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_regular.ttf b/experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_regular.ttf similarity index 100% rename from experimental/examples/codeviewer/common/src/commonMain/resources/font/jetbrainsmono_regular.ttf rename to experimental/examples/codeviewer/shared/src/commonMain/resources/font/jetbrainsmono_regular.ttf diff --git a/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/main.desktop.kt b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/main.desktop.kt new file mode 100644 index 0000000000..faa491aedf --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/main.desktop.kt @@ -0,0 +1,5 @@ +import androidx.compose.runtime.Composable +import org.jetbrains.codeviewer.ui.MainView + +@Composable +fun MainView() = MainView() \ No newline at end of file diff --git a/experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/File.kt b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/File.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/File.kt rename to experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/File.kt diff --git a/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt new file mode 100644 index 0000000000..839576bb41 --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt @@ -0,0 +1,5 @@ +package org.jetbrains.codeviewer.platform + +import androidx.compose.ui.Modifier + +actual fun Modifier.cursorForHorizontalResize() = this diff --git a/experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt rename to experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt diff --git a/experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt b/experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt rename to experimental/examples/codeviewer/shared/src/desktopMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt diff --git a/experimental/examples/widgets-gallery/shared/src/iosMain/kotlin/main.ios.kt b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/main.ios.kt similarity index 89% rename from experimental/examples/widgets-gallery/shared/src/iosMain/kotlin/main.ios.kt rename to experimental/examples/codeviewer/shared/src/iosMain/kotlin/main.ios.kt index c64bf93623..1e3e239735 100644 --- a/experimental/examples/widgets-gallery/shared/src/iosMain/kotlin/main.ios.kt +++ b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/main.ios.kt @@ -9,11 +9,11 @@ import androidx.compose.foundation.layout.height import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Application -import org.jetbrains.compose.demo.widgets.ui.MainView import platform.UIKit.UIViewController +import org.jetbrains.codeviewer.ui.MainView fun MainViewController() : UIViewController = - Application("Widgets Gallery") { + Application("Codeviewer") { Column { // To skip upper part of screen. Box( diff --git a/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/File.kt b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/File.kt new file mode 100644 index 0000000000..889ee767cb --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/File.kt @@ -0,0 +1,41 @@ +@file:Suppress("NewApi") + +package org.jetbrains.codeviewer.platform + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.runBlocking +import org.jetbrains.codeviewer.util.EmptyTextLines +import org.jetbrains.codeviewer.util.TextLines +import org.jetbrains.compose.resources.ExperimentalResourceApi +import org.jetbrains.compose.resources.resource + +class VirtualFile(override val name: String, override val isDirectory: Boolean, val textLines: TextLines, override val children: List = listOf()): File { + override val hasChildren: Boolean + get() = children.size > 0 + + override fun readLines(scope: CoroutineScope): TextLines = textLines +} + +fun ByteArray.toTextLines(): TextLines = object : TextLines { + val contents = decodeToString().split("\n") + + override val size: Int + get() = contents.size + + override fun get(index: Int): String = contents[index] +} + + +@OptIn(ExperimentalResourceApi::class) +actual val HomeFolder: File get() = VirtualFile("files", + isDirectory = true, + textLines = EmptyTextLines, + children = listOf( + VirtualFile("EditorView.kt", + isDirectory = false, + textLines = runBlocking { + resource("EditorView.kt").readBytes() + }.toTextLines() + ) + ) +) diff --git a/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt new file mode 100644 index 0000000000..3a8174f63c --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Mouse.kt @@ -0,0 +1,5 @@ +package org.jetbrains.codeviewer.platform + +import androidx.compose.ui.Modifier + +actual fun Modifier.cursorForHorizontalResize(): Modifier = this diff --git a/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt new file mode 100644 index 0000000000..6c63ae93af --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Resources.kt @@ -0,0 +1,23 @@ +package org.jetbrains.codeviewer.platform + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.text.font.Font +import androidx.compose.ui.text.font.FontStyle +import androidx.compose.ui.text.font.FontWeight +import kotlinx.coroutines.runBlocking +import org.jetbrains.compose.resources.ExperimentalResourceApi +import org.jetbrains.compose.resources.resource + +private val cache: MutableMap = mutableMapOf() + +@OptIn(ExperimentalResourceApi::class) +@Composable +internal actual fun font(name: String, res: String, weight: FontWeight, style: FontStyle): Font { + return cache.getOrPut(res) { + val byteArray = runBlocking { + resource("font/$res.ttf").readBytes() + } + androidx.compose.ui.text.platform.Font(res, byteArray, weight, style) + } +} \ No newline at end of file diff --git a/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt new file mode 100644 index 0000000000..7ffe0d5b00 --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/iosMain/kotlin/org/jetbrains/codeviewer/platform/Scrollbar.kt @@ -0,0 +1,18 @@ +package org.jetbrains.codeviewer.platform + +import androidx.compose.foundation.ScrollState +import androidx.compose.foundation.lazy.LazyListState +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +internal actual fun VerticalScrollbar( + modifier: Modifier, + scrollState: ScrollState +) = Unit + +@Composable +internal actual fun VerticalScrollbar( + modifier: Modifier, + scrollState: LazyListState +) = Unit \ No newline at end of file diff --git a/experimental/examples/codeviewer/shared/src/iosMain/resources/EditorView.kt b/experimental/examples/codeviewer/shared/src/iosMain/resources/EditorView.kt new file mode 100644 index 0000000000..90037570b1 --- /dev/null +++ b/experimental/examples/codeviewer/shared/src/iosMain/resources/EditorView.kt @@ -0,0 +1,183 @@ +/** + * This file is an example (we can open it in iOS application) + */ + +package org.jetbrains.codeviewer.ui.editor + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.text.selection.DisableSelection +import androidx.compose.material.AmbientContentColor +import androidx.compose.material.CircularProgressIndicator +import androidx.compose.material.Surface +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.key +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha +import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.* +import androidx.compose.ui.unit.dp +import org.jetbrains.codeviewer.platform.SelectionContainer +import org.jetbrains.codeviewer.ui.common.AppTheme +import org.jetbrains.codeviewer.ui.common.Fonts +import org.jetbrains.codeviewer.ui.common.Settings +import org.jetbrains.codeviewer.util.loadableScoped +import org.jetbrains.codeviewer.util.withoutWidthConstraints +import kotlin.text.Regex.Companion.fromLiteral + +@Composable +fun EditorView(model: Editor, settings: Settings) = key(model) { + with (LocalDensity.current) { + SelectionContainer { + Surface( + Modifier.fillMaxSize(), + color = AppTheme.colors.backgroundDark, + ) { + val lines by loadableScoped(model.lines) + + if (lines != null) { + Box { + Lines(lines!!, settings) + Box( + Modifier + .offset( + x = settings.fontSize.toDp() * 0.5f * settings.maxLineSymbols + ) + .width(1.dp) + .fillMaxHeight() + .background(AppTheme.colors.backgroundLight) + ) + } + } else { + CircularProgressIndicator( + modifier = Modifier + .size(36.dp) + .padding(4.dp) + ) + } + } + } + } +} + +@Composable +private fun Lines(lines: Editor.Lines, settings: Settings) = with(DensityAmbient.current) { + val maxNumber = remember(lines.lineNumberDigitCount) { + (1..lines.lineNumberDigitCount).joinToString(separator = "") { "9" } + } + + Box(Modifier.fillMaxSize()) { + val scrollState = rememberLazyListState() + val lineHeight = settings.fontSize.toDp() * 1.6f + + LazyColumnFor( + lines.size, + modifier = Modifier.fillMaxSize(), + state = scrollState, + itemContent = { index -> + val line: Editor.Line? by loadable { lines.get(index) } + Box(Modifier.height(lineHeight)) { + if (line != null) { + Line(Modifier.align(Alignment.CenterStart), maxNumber, line!!, settings) + } + } + } + ) + + VerticalScrollbar( + Modifier.align(Alignment.CenterEnd), + scrollState, + lines.size, + lineHeight + ) + } +} + +// Поддержка русского языка +// دعم اللغة العربية +// 中文支持 +@Composable +private fun Line(modifier: Modifier, maxNumber: String, line: Editor.Line, settings: Settings) { + Row(modifier = modifier) { + DisableSelection { + Box { + LineNumber(maxNumber, Modifier.alpha(0f), settings) + LineNumber(line.number.toString(), Modifier.align(Alignment.CenterEnd), settings) + } + } + LineContent( + line.content, + modifier = Modifier + .weight(1f) + .withoutWidthConstraints() + .padding(start = 28.dp, end = 12.dp), + settings = settings + ) + } +} + +@Composable +private fun LineNumber(number: String, modifier: Modifier, settings: Settings) = Text( + text = number, + fontSize = settings.fontSize, + fontFamily = Fonts.jetbrainsMono(), + color = AmbientContentColor.current.copy(alpha = 0.30f), + modifier = modifier.padding(start = 12.dp) +) + +@Composable +private fun LineContent(content: Editor.Content, modifier: Modifier, settings: Settings) = Text( + text = if (content.isCode) { + codeString(content.value.value) + } else { + AnnotatedString(content.value.value) + }, + fontSize = settings.fontSize, + fontFamily = Fonts.jetbrainsMono(), + modifier = modifier, + softWrap = false +) + +private fun codeString(str: String) = buildAnnotatedString { + withStyle(AppTheme.code.simple) { + append(str.replace("\t", " ")) + addStyle(AppTheme.code.punctuation, ":") + addStyle(AppTheme.code.punctuation, "=") + addStyle(AppTheme.code.punctuation, "\"") + addStyle(AppTheme.code.punctuation, "[") + addStyle(AppTheme.code.punctuation, "]") + addStyle(AppTheme.code.punctuation, "{") + addStyle(AppTheme.code.punctuation, "}") + addStyle(AppTheme.code.punctuation, "(") + addStyle(AppTheme.code.punctuation, ")") + addStyle(AppTheme.code.punctuation, ",") + addStyle(AppTheme.code.keyword, "fun ") + addStyle(AppTheme.code.keyword, "val ") + addStyle(AppTheme.code.keyword, "var ") + addStyle(AppTheme.code.keyword, "private ") + addStyle(AppTheme.code.keyword, "internal ") + addStyle(AppTheme.code.keyword, "for ") + addStyle(AppTheme.code.keyword, "expect ") + addStyle(AppTheme.code.keyword, "actual ") + addStyle(AppTheme.code.keyword, "import ") + addStyle(AppTheme.code.keyword, "package ") + addStyle(AppTheme.code.value, "true") + addStyle(AppTheme.code.value, "false") + addStyle(AppTheme.code.value, Regex("[0-9]*")) + addStyle(AppTheme.code.annotation, Regex("^@[a-zA-Z_]*")) + addStyle(AppTheme.code.comment, Regex("^\\s*//.*")) + } +} + +private fun AnnotatedString.Builder.addStyle(style: SpanStyle, regexp: String) { + addStyle(style, fromLiteral(regexp)) +} + +private fun AnnotatedString.Builder.addStyle(style: SpanStyle, regexp: Regex) { + for (result in regexp.findAll(toString())) { + addStyle(style, result.range.first, result.range.last + 1) + } +} \ No newline at end of file diff --git a/experimental/examples/codeviewer/common/src/jvmMain/kotlin/org/jetbrains/codeviewer/platform/JvmFile.kt b/experimental/examples/codeviewer/shared/src/jvmMain/kotlin/org/jetbrains/codeviewer/platform/JvmFile.kt similarity index 100% rename from experimental/examples/codeviewer/common/src/jvmMain/kotlin/org/jetbrains/codeviewer/platform/JvmFile.kt rename to experimental/examples/codeviewer/shared/src/jvmMain/kotlin/org/jetbrains/codeviewer/platform/JvmFile.kt