Skip to content

Fix/support k2 #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions CodeLocatorPlugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.6.1'
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'org.jetbrains.intellij' version '1.17.4'
id 'org.jetbrains.kotlin.jvm' version '1.9.21'
}

group 'com.bytedance.tools'
Expand Down Expand Up @@ -49,9 +49,10 @@ dependencies {
}

intellij {
updateSinceUntilBuild false
version '191.6707.61'
plugins = ["org.jetbrains.kotlin", "org.jetbrains.android"]
// updateSinceUntilBuild false
version = "2022.2"
type = "IC"
plugins = ["org.jetbrains.kotlin", "org.jetbrains.android", "com.intellij.java"]
}

boolean isFirst = true
Expand All @@ -60,6 +61,13 @@ boolean isWindows() {
return System.getProperty("os.name").toLowerCase().indexOf("windows") != -1
}

tasks{
patchPluginXml {
sinceBuild = "222"
untilBuild = "999.*"
}
}

gradle.taskGraph.beforeTask {
if (isFirst && !isWindows()) {
isFirst = false
Expand All @@ -84,6 +92,7 @@ gradle.taskGraph.beforeTask {
}

if (it instanceof Zip && !it.toString().contains("CodeLocatorModel")) {
it.duplicatesStrategy = DuplicatesStrategy.INCLUDE
it.from({
file("imgcopy.m")
})
Expand Down
2 changes: 1 addition & 1 deletion CodeLocatorPlugin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.SystemInfo
import sun.font.FontDesignMetrics
import java.awt.Dimension
import javax.swing.*

Expand Down Expand Up @@ -141,7 +140,7 @@ class FixJumpErrorDialog(
close(0)
}
try {
val stringWidth = FontDesignMetrics.getMetrics(confirmBtn.font).stringWidth(confrimText) + 10
val stringWidth = confirmBtn.getFontMetrics(confirmBtn.font).stringWidth(confrimText) + 10
confirmBtn.maximumSize = Dimension(stringWidth, 40)
cancelBtn.maximumSize = Dimension(stringWidth, 40)
} catch (t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ import com.bytedance.tools.codelocator.utils.CoordinateUtils
import com.bytedance.tools.codelocator.utils.JComponentUtils
import com.bytedance.tools.codelocator.utils.Log
import com.bytedance.tools.codelocator.utils.ResUtils
import com.bytedance.tools.codelocator.utils.onTextChange
import com.bytedance.tools.codelocator.views.JTextHintField
import com.intellij.codeInsight.hint.HintManager
import com.intellij.codeInsight.hint.HintManagerImpl
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.wm.ex.WindowManagerEx
import com.intellij.ui.LightweightHint
import com.intellij.ui.awt.RelativePoint
import org.jetbrains.kotlin.idea.util.onTextChange
import sun.font.FontDesignMetrics
import java.awt.Dimension
import java.awt.FontMetrics
import java.awt.event.ActionListener
import java.awt.event.KeyEvent
import java.awt.event.MouseAdapter
Expand Down Expand Up @@ -172,7 +168,7 @@ class SearchColorDialog(
lineWidthRemain[line] = resultPanelBox.width
result.forEachIndexed { index, result ->
val makeJLabel = makeJLabel(result)
val stringWidth = FontDesignMetrics.getMetrics(makeJLabel.font).stringWidth(result)
val stringWidth = makeJLabel.getFontMetrics(makeJLabel.font).stringWidth(result)
if (stringWidth >= resultPanelBox.width) {
val createHorizontalBox = Box.createHorizontalBox()
createHorizontalBox.add(makeJLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import com.intellij.ui.awt.RelativePoint
import com.intellij.ui.components.JBList
import com.intellij.ui.components.JBScrollPane
import com.intellij.ui.table.JBTable
import com.sun.jndi.toolkit.url.Uri
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import java.awt.Component
Expand Down Expand Up @@ -262,7 +261,6 @@ class SendSchemaDialog(
private fun convertToEncodeSchema(originSchema: String?): String {
originSchema ?: return ""
try {
val uri = Uri(originSchema)
var hasQuery = true
val indexOfSplit = originSchema.indexOf("?")
if (indexOfSplit > -1) {
Expand Down Expand Up @@ -326,7 +324,6 @@ class SendSchemaDialog(
return
}
val uriStr = textField.text
val uri = Uri(uriStr)
var hasQuery = false
val indexOfSplit = uriStr.indexOf("?")
if (indexOfSplit > -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bytedance.tools.codelocator.dialog
import com.bytedance.tools.codelocator.utils.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ex.WindowManagerEx
import sun.font.FontDesignMetrics
import java.awt.Dimension
import java.awt.Font
import java.awt.event.MouseAdapter
Expand Down Expand Up @@ -142,7 +141,7 @@ class ShowConfigDialog(
hide()
}
try {
val stringWidth = FontDesignMetrics.getMetrics(confirmButton!!.font).stringWidth(btnText)
val stringWidth = confirmButton!!.getFontMetrics(confirmButton!!.font).stringWidth(btnText)
confirmButton!!.maximumSize = Dimension(stringWidth, 38)
} catch (t: Throwable) {
Log.e("getfont width error", t)
Expand All @@ -159,7 +158,7 @@ class ShowConfigDialog(
hide()
}
try {
val stringWidth = FontDesignMetrics.getMetrics(dontShowButton.font).stringWidth(dontShowText)
val stringWidth = dontShowButton.getFontMetrics(dontShowButton.font).stringWidth(dontShowText)
dontShowButton.maximumSize = Dimension(stringWidth, 38)
} catch (t: Throwable) {
Log.e("getFont width error", t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.util.SystemInfo
import sun.font.FontDesignMetrics
import java.awt.Dimension
import javax.swing.Action
import javax.swing.BorderFactory
Expand Down Expand Up @@ -104,7 +103,7 @@ class ShowDownloadSourceDialog(val codeLocatorWindow: CodeLocatorWindow, val pro
close(0)
}
try {
val stringWidth = FontDesignMetrics.getMetrics(confirmButton.font).stringWidth(btnText)
val stringWidth = confirmButton.getFontMetrics(confirmButton.font).stringWidth(btnText)
confirmButton.maximumSize = Dimension(stringWidth, 38)
} catch (t: Throwable) {
Log.e("getfont width error", t)
Expand All @@ -117,7 +116,7 @@ class ShowDownloadSourceDialog(val codeLocatorWindow: CodeLocatorWindow, val pro
close(0)
}
try {
val stringWidth = FontDesignMetrics.getMetrics(dontShowButton.font).stringWidth(dontShowText)
val stringWidth = dontShowButton.getFontMetrics(dontShowButton.font).stringWidth(dontShowText)
dontShowButton.maximumSize = Dimension(stringWidth, 38)
} catch (t: Throwable) {
Log.e("getFont width error", t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.intellij.openapi.wm.ex.WindowManagerEx
import com.intellij.ui.awt.RelativePoint
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import sun.font.FontDesignMetrics
import java.awt.Dimension
import java.awt.Font
import java.awt.Image
Expand Down Expand Up @@ -107,7 +106,7 @@ class ShowHistoryDialog(
val buttonWidth = DIALOG_WIDTH - CoordinateUtils.DEFAULT_BORDER * 4
val jButton = JButton()
jButton.font = Font(jButton.font.name, Font.PLAIN, 12)
val fontMetrics = FontDesignMetrics.getMetrics(jButton.font)
val fontMetrics = jButton.getFontMetrics(jButton.font)

var grabTime = ""
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.bytedance.tools.codelocator.dialog
import com.bytedance.tools.codelocator.utils.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ex.WindowManagerEx
import sun.font.FontDesignMetrics
import java.awt.Dimension
import java.awt.Font
import java.io.File
Expand Down Expand Up @@ -109,7 +108,7 @@ class ShowNewsDialog(val project: Project, val msg: String, val version: String)
hide()
}
try {
val stringWidth = FontDesignMetrics.getMetrics(confirmBtn.font).stringWidth(confrimText)
val stringWidth = confirmBtn.getFontMetrics(confirmBtn.font).stringWidth(confrimText)
confirmBtn.maximumSize = Dimension(stringWidth, 38)
} catch (t: Throwable) {
Log.e("getFont width error", t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.bytedance.tools.codelocator.utils.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.wm.ex.WindowManagerEx
import sun.font.FontDesignMetrics
import java.awt.Dimension
import java.awt.Font
import java.awt.event.MouseAdapter
Expand Down Expand Up @@ -100,7 +99,7 @@ class ShowTraceDialog(
val buttonWidth = DIALOG_WIDTH - CoordinateUtils.DEFAULT_BORDER * 4
val jButton = JButton()
jButton.font = Font(jButton.font.name, Font.PLAIN, 12)
val fontMetrics = FontDesignMetrics.getMetrics(jButton.font)
val fontMetrics = jButton.getFontMetrics(jButton.font)
var keyWorkInfo = ""
if (showInfo.keyword != "null") {
keyWorkInfo = "<br>&nbsp;" + UIUtils.getMatchWidthStr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
import com.intellij.codeInsight.hint.HintManager;
import com.intellij.codeInsight.hint.HintManagerImpl;
import com.intellij.ide.ApplicationInitializedListener;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.editor.event.SelectionEvent;
import com.intellij.openapi.editor.event.SelectionListener;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.project.impl.ProjectLifecycleListener;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.TextRange;
import com.intellij.ui.LightweightHint;
import com.intellij.ui.awt.RelativePoint;
Expand All @@ -42,6 +47,8 @@ public class CodeLocatorApplicationInitializedListener implements ApplicationIni

private static int maxWidth;

private static Disposable disposable = Disposer.newDisposable();

public static void setColorInfo(List<ColorInfo> colorInfo) {
if (colorInfo == null || colorInfo.isEmpty()) {
return;
Expand All @@ -68,10 +75,10 @@ public void componentsInitialized() {
ThreadUtils.submit(() -> {
NetUtils.fetchConfig();
});

ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener() {
Disposer.register(ApplicationManager.getApplication(),disposable);
ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
@Override
public void afterProjectClosed(@NotNull Project project) {
public void projectClosed(@NotNull Project project) {
final Device currentDevice = DeviceManager.getCurrentDevice(project, true);
if (currentDevice != null && currentDevice.getDevice() != null) {
final String serialNumber = currentDevice.getDevice().getSerialNumber();
Expand Down Expand Up @@ -141,12 +148,12 @@ public void selectionChanged(@NotNull SelectionEvent e) {
point.y -= ((colorInfos.size() - 1) * CoordinateUtils.TABLE_RIGHT_MARGIN + colorInfos.size() * HINT_ITEM_HEIGHT + CoordinateUtils.TABLE_RIGHT_MARGIN);
lastSelectText = null;
HintManagerImpl.getInstanceImpl()
.showHint(colorInfosPanel,
new RelativePoint(e.getEditor().getComponent().getRootPane(), point),
HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0);
.showHint(colorInfosPanel,
new RelativePoint(e.getEditor().getComponent().getRootPane(), point),
HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_OTHER_HINT | HintManager.HIDE_BY_SCROLLING, 0);
Mob.mob(Mob.Action.CLICK, Mob.Button.COLOR_MODE);
}
});
}, disposable);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void onSyncFinish(Project project) {
}

private void subscribeNotification(@NotNull Project project, Disposable tempDisposable) {
project.getMessageBus().connect(tempDisposable).subscribe(Notifications.TOPIC, new NotificationsAdapter() {
project.getMessageBus().connect(tempDisposable).subscribe(Notifications.TOPIC, new Notifications() {
boolean hasSync = false;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private void paintChessboard(Graphics g) {
int patternSize = 2 * cellSize;

if (pattern == null) {
pattern = UIUtil.createImage(g, patternSize, patternSize, BufferedImage.TYPE_INT_ARGB);
pattern = UIUtil.createImage(this, patternSize, patternSize, BufferedImage.TYPE_INT_ARGB);
Graphics imageGraphics = pattern.getGraphics();
imageGraphics.setColor(whiteColor);
imageGraphics.fillRect(0, 0, patternSize, patternSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void updateTableColumn(int column, int width) {
width = Math.max(width, tableColumn.getPreferredWidth());
}

columnSizes.put(tableColumn, new Integer(tableColumn.getWidth()));
columnSizes.put(tableColumn, tableColumn.getWidth());

table.getTableHeader().setResizingColumn(tableColumn);
tableColumn.setWidth(width);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bytedance.tools.codelocator.utils

import com.intellij.ui.DocumentAdapter
import javax.swing.event.DocumentEvent
import javax.swing.text.JTextComponent

fun JTextComponent.onTextChange(action: (DocumentEvent) -> Unit) {
document.addDocumentListener(
object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
action(e)
}
}
)
}
4 changes: 4 additions & 0 deletions CodeLocatorPlugin/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@

<depends>org.jetbrains.android</depends>

<extensions defaultExtensionNs="org.jetbrains.kotlin">
<supportsKotlinPluginMode supportsK1="true" supportsK2="true" />
</extensions>

<extensions defaultExtensionNs="com.intellij">

<checkinHandlerFactory implementation="com.bytedance.tools.codelocator.importopt.DeleteImportinHandlerFactory"/>
Expand Down