Skip to content

refactor: ui improves #845

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

Merged
merged 19 commits into from
Sep 28, 2022
Merged
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
2 changes: 1 addition & 1 deletion detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml

build:
maxIssues: 27 #todo: zero out
maxIssues: 26 #todo: zero out

formatting:
Indentation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ interface SourceMark : JBPopupListener, MouseMotionListener, VisibleAreaListener

fun dispose(removeFromMarker: Boolean = true, assertRemoval: Boolean = true) {
if (this is InlayMark) {
configuration.inlayRef?.get()?.dispose()
configuration.inlayRef = null
ApplicationManager.getApplication().invokeAndWait {
configuration.inlayRef?.get()?.dispose()
configuration.inlayRef = null
}
}
closePopup()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ private void initComponents() {
textField1 = new AutocompleteField(
inlayMark.getProject(),
message("location") + ": " + location + "#" + inlayMark.getLineNumber(),
availableCommands, lookup, inlayMark.getArtifactQualifiedName(), true, true, SELECT_COLOR_RED, true);
availableCommands, lookup, inlayMark.getArtifactQualifiedName(), true);
textField1.setReplaceCommandOnTab(true);
textField1.setAutocompleteAndFinishOnEnter(true);
textField1.setMaxSuggestSize(3);
textField1.setCellRenderer(new ControlBarCellRenderer(inlayMark, textField1));
label2 = new JLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.*;
import org.jetbrains.annotations.NotNull;
import spp.jetbrains.PluginUI;

import javax.swing.*;
import java.awt.*;
Expand All @@ -36,7 +37,7 @@ public LiveControlBarRow() {
}

public void setCommandName(String commandName, String input) {
String selectHex = "#" + Integer.toHexString(SELECT_COLOR_RED.getRGB()).substring(2);
String selectHex = "#" + Integer.toHexString(PluginUI.getCommandHighlightForeground().getRGB()).substring(2);
String defaultHex = getCommandTypeColor();

int minIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public Icon getUnselectedIcon() {

@Override
public void onInstrumentRemovedEvent(@NotNull LiveInstrumentRemoved event) {
LiveStatusManager.getInstance(inlayMark.getProject()).removeActiveLiveInstrument(event.getLiveInstrument());
this.liveBreakpoint = null;
}

Expand Down Expand Up @@ -531,7 +532,7 @@ private void initComponents() {
configLabel = new JLabel();
configDropdownLabel = new JLabel();
mainPanel = new JPanel();
breakpointConditionField = new AutocompleteField(inlayMark.getProject(), placeHolderText, scopeVars, lookup, inlayMark.getArtifactQualifiedName(), false, false, COMPLETE_COLOR_PURPLE, false);
breakpointConditionField = new AutocompleteField(inlayMark.getProject(), placeHolderText, scopeVars, lookup, inlayMark.getArtifactQualifiedName(), false);
label1 = new JLabel();
hitLimitSpinner = new JBIntSpinner(1, 1, 10_000);
timeLabel = new JLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ public Icon getUnselectedIcon() {
}
}).collect(Collectors.toList());
lookup = text -> scopeVars.stream()
.filter(v -> {
//ignore exact matches
String var = substringAfterLast(" ", text.toLowerCase());
var = substringAfterLast("$", var);
return !var.equalsIgnoreCase(v);
})
.filter(v -> VariableParser.isVariable(text, v))
.map(it -> new AutocompleteFieldRow() {
public String getText() {
Expand Down Expand Up @@ -697,6 +703,12 @@ private void dispose() {
inlayMark.dispose(true);
}

public static String substringAfterLast(String delimiter, String value) {
int index = value.lastIndexOf(delimiter);
if (index == -1) return value;
else return value.substring(index + delimiter.length());
}

private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
setBackground(getBackgroundColor());
Expand All @@ -705,7 +717,7 @@ private void initComponents() {
configDropdownLabel = new JLabel();
timeLabel = new JLabel();
separator1 = new JSeparator();
liveLogTextField = new AutocompleteField(inlayMark.getProject(), placeHolderText, scopeVars, lookup, inlayMark.getArtifactQualifiedName(), false, false, COMPLETE_COLOR_PURPLE, false);
liveLogTextField = new AutocompleteField(inlayMark.getProject(), placeHolderText, scopeVars, lookup, inlayMark.getArtifactQualifiedName(), false);
liveLogTextField.setVarPattern(varPattern);
closeLabel = new JLabel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ private void initComponents() {
configLabel = new JLabel();
configDropdownLabel = new JLabel();
mainPanel = new JPanel();
meterIdField = new AutocompleteField(inlayMark.getProject(), meterName, Collections.emptyList(), null, inlayMark.getArtifactQualifiedName(), false, false, COMPLETE_COLOR_PURPLE, false);
meterConditionField = new AutocompleteField(inlayMark.getProject(), placeHolderText, scopeVars, lookup, inlayMark.getArtifactQualifiedName(), false, false, COMPLETE_COLOR_PURPLE, false);
meterIdField = new AutocompleteField(inlayMark.getProject(), meterName, Collections.emptyList(), null, inlayMark.getArtifactQualifiedName(), false);
meterConditionField = new AutocompleteField(inlayMark.getProject(), placeHolderText, scopeVars, lookup, inlayMark.getArtifactQualifiedName(), false);
label1 = new JLabel();
meterTypeComboBox = new JComboBox<>();
timeLabel = new JLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private void initComponents() {
configLabel = new JLabel();
configDropdownLabel = new JLabel();
mainPanel = new JPanel();
spanOperationNameField = new AutocompleteField(inlayMark.getProject(), placeHolderText, Collections.emptyList(), null, inlayMark.getArtifactQualifiedName(), false, false, COMPLETE_COLOR_PURPLE, false);
spanOperationNameField = new AutocompleteField(inlayMark.getProject(), placeHolderText, Collections.emptyList(), null, inlayMark.getArtifactQualifiedName(), false);
timeLabel = new JLabel();
separator1 = new JSeparator();
closeLabel = new JLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import spp.jetbrains.marker.source.mark.api.component.jcef.config.BrowserLoading
import spp.jetbrains.marker.source.mark.api.component.jcef.config.SourceMarkJcefComponentConfiguration
import spp.jetbrains.marker.source.mark.api.event.SourceMarkEventCode
import spp.jetbrains.marker.source.mark.guide.GuideMark
import spp.jetbrains.sourcemarker.mark.SourceMarkKeys
import spp.jetbrains.sourcemarker.settings.SourceMarkerConfig
import spp.jetbrains.sourcemarker.settings.getServicePortNormalized
import spp.jetbrains.sourcemarker.settings.isSsl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class LiveInstrumentManager(

//register listener
FrameHelper.sendFrame(
BridgeEventType.REGISTER.name.toLowerCase(),
BridgeEventType.REGISTER.name.lowercase(),
toLiveInstrumentSubscriberAddress(developer), null,
JsonObject().apply { pluginConfig.serviceToken?.let { put("auth-token", it) } },
null, null, TCPServiceDiscoveryBackend.getSocket(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LiveViewManager(
}

FrameHelper.sendFrame(
BridgeEventType.REGISTER.name.toLowerCase(),
BridgeEventType.REGISTER.name.lowercase(),
toLiveViewSubscriberAddress(developer), null,
JsonObject().apply { pluginConfig.serviceToken?.let { put("auth-token", it) } },
null, null, TCPServiceDiscoveryBackend.getSocket(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TCPServiceDiscoveryBackend : ServiceDiscoveryBackend {
}
val headers = JsonObject().apply { pluginConfig.serviceToken?.let { put("auth-token", it) } }
FrameHelper.sendFrame(
BridgeEventType.SEND.name.toLowerCase(),
BridgeEventType.SEND.name.lowercase(),
PlatformAddress.MARKER_CONNECTED,
replyAddress, headers, true, JsonObject.mapFrom(pc), socket!!
)
Expand All @@ -191,7 +191,7 @@ class TCPServiceDiscoveryBackend : ServiceDiscoveryBackend {
val headers = JsonObject()
resp.headers().entries().forEach { headers.put(it.key, it.value) }
FrameHelper.sendFrame(
BridgeEventType.SEND.name.toLowerCase(),
BridgeEventType.SEND.name.lowercase(),
address, replyAddress, headers, true, resp.body(), socket!!
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ object VariableParser {

@JvmStatic
fun isVariable(text: String, v: String): Boolean {
val variable = text.toLowerCase().substringAfterLast(SPACE)
val variable = text.lowercase().substringAfterLast(SPACE)
return ((variable.startsWith(DOLLAR) && variable.substring(1) != v
&& v.toLowerCase().contains(variable.substring(1)))
&& v.lowercase().contains(variable.substring(1)))
|| (variable.startsWith("\${") && variable.substring(2) != v
&& v.toLowerCase().contains(variable.substring(2))))
&& v.lowercase().contains(variable.substring(2))))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SourceStatusServiceImpl(val project: Project) : SourceStatusService {
if (waitBefore) delay(repeatMillis)
try {
SourceMarkerPlugin.getInstance(project).init()
} catch (ex: AlreadyDisposedException) {
} catch (ignore: AlreadyDisposedException) {
log.info("${project.name} is disposed, stopping reconnection loop")
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.intellij.ui.components.JBList
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import spp.jetbrains.PluginUI
import spp.jetbrains.PluginUI.COMPLETE_COLOR_PURPLE
import spp.jetbrains.PluginUI.SMALLEST_FONT
import spp.jetbrains.icons.PluginIcons
import spp.jetbrains.sourcemarker.element.AutocompleteDropdown
Expand Down Expand Up @@ -51,12 +50,13 @@ class AutocompleteField<T : AutocompleteFieldRow>(
private val allLookup: List<T>,
private val lookup: Function<String, List<T>>? = null,
internal val artifactQualifiedName: ArtifactQualifiedName,
private val replaceCommandOnTab: Boolean = false,
private val autocompleteOnEnter: Boolean = true,
private val varColor: Color = COMPLETE_COLOR_PURPLE,
addAutocompleteDropdownInfo: Boolean = false
) : JTextPane(), FocusListener, DocumentListener, KeyListener, MouseMotionListener, MouseListener {

var autocompleteOnTab: Boolean = true
var replaceCommandOnTab: Boolean = false
var autocompleteAndFinishOnEnter: Boolean = false
var varColor: Color = PluginUI.commandHighlightForeground
private val results: MutableList<AutocompleteFieldRow>
private val autocompleteDropdown: AutocompleteDropdown?
private val popup: JWindow
Expand Down Expand Up @@ -285,19 +285,24 @@ class AutocompleteField<T : AutocompleteFieldRow>(
}
scrollListToSelected()
} else if (e.keyCode == KeyEvent.VK_TAB) {
if (text.isBlank() || list.selectedValue == null || !replaceCommandOnTab) return
if (text.isBlank() || list.selectedValue == null || (!replaceCommandOnTab && !autocompleteOnTab)) return
val autocompleteRow = list.selectedValue
if (autocompleteRow is LiveCommandFieldRow && autocompleteRow.liveCommand.params.isNotEmpty()) {
if (getText().lowercase().startsWith(autocompleteRow.liveCommand.getTriggerName().lowercase() + " ")) {
return //do nothing
if (replaceCommandOnTab) {
if (autocompleteRow is LiveCommandFieldRow && autocompleteRow.liveCommand.params.isNotEmpty()) {
if (getText().lowercase().startsWith(autocompleteRow.liveCommand.getTriggerName().lowercase() + " ")) {
return //do nothing
}
setText(autocompleteRow.getText() + " ")
} else {
setText(autocompleteRow.getText())
}
setText(autocompleteRow.getText() + " ")
} else {
setText(autocompleteRow.getText())
val userInput = text.substringAfterLast(" ")
setText(text.substring(0, text.length - userInput.length) + autocompleteRow.getText())
}
caretPosition = getText().length
} else if (e.keyCode == KeyEvent.VK_ENTER) {
if (!autocompleteOnEnter) {
if (!autocompleteAndFinishOnEnter) {
ready = true
actualText = text
hideAutocompletePopup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ControlBarCellRenderer(
"*methodName*",
getShortFunctionSignature(autocompleteField.artifactQualifiedName.identifier)
)
} catch (ex: Exception) {
} catch (ignore: Exception) {
formattedDescription.replace("*methodName*", "anonymous")
}
}
Expand Down