Commit db2dd159 authored by Konstantin Bulenkov's avatar Konstantin Bulenkov
Browse files

add PMM Utils to internal actions (ability to set custom size to any window)

parent af941306
Showing with 106 additions and 0 deletions
+106 -0
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal.inspector;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import java.awt.*;
/**
* @author Konstantin Bulenkov
*/
public class ApplyWindowSizeAction extends DumbAwareAction {
public ApplyWindowSizeAction() {
setEnabledInModalContext(true);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Component owner = IdeFocusManager.findInstance().getFocusOwner();
if (owner != null) {
Window window = UIUtil.getParentOfType(Window.class, owner);
if (window != null) {
PropertiesComponent props = PropertiesComponent.getInstance();
int w = props.getInt(ConfigureCustomSizeAction.widthId(), 640);
int h = props.getInt(ConfigureCustomSizeAction.heightId(), 300);
window.setMinimumSize(new Dimension(w, h));
window.setSize(w, h);
}
}
}
}
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.internal.inspector
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.ValidationInfo
import com.intellij.ui.layout.*
import javax.swing.JComponent
import javax.swing.JTextField
/**
* @author Konstantin Bulenkov
*/
class ConfigureCustomSizeAction: DumbAwareAction() {
override fun actionPerformed(e: AnActionEvent) {
ConfigureCustomSizeDialog(e.project).show()
}
companion object {
private fun id() = ConfigureCustomSizeAction::class.java
@JvmStatic
fun widthId() = "${id()}.width"
@JvmStatic
fun heightId() = "${id()}.height"
}
class ConfigureCustomSizeDialog(project: Project?): DialogWrapper(project) {
val width: JTextField
val height: JTextField
init {
title = "Default Size"
width = JTextField(loadWidth(), 20)
height = JTextField(loadHeight(), 20)
init()
}
private fun loadWidth() = PropertiesComponent.getInstance().getValue(widthId(), "640")
private fun loadHeight() = PropertiesComponent.getInstance().getValue(heightId(), "300")
override fun createCenterPanel(): JComponent? {
return panel {
row("Width:") {width()}
row("Height:") {height()}
}
}
override fun doOKAction() {
PropertiesComponent.getInstance().setValue(widthId(), width.text)
PropertiesComponent.getInstance().setValue(heightId(), height.text)
super.doOKAction()
}
override fun doValidate(): ValidationInfo? {
val errorMessage = "Should be integer in range 1..1000"
val w = width.text.toIntOrNull()
val h = height.text.toIntOrNull()
if (w == null || w < 1 || w > 1000) return ValidationInfo(errorMessage, width)
if (h == null || h < 1 || h > 1000) return ValidationInfo(errorMessage, height)
return null
}
}
}
\ No newline at end of file
......@@ -855,6 +855,11 @@
<action internal="true" id="RecordStateCollectors" class="com.intellij.internal.statistic.actions.RecordStateStatisticsEventLogAction" text="Record State Collectors to Event Log"/>
</group>
<group id="Internal.PMM" popup="true" text="PMM Utils">
<action id="ApplyFixedWindowSize" internal="true" class="com.intellij.internal.inspector.ApplyWindowSizeAction" text="Apply Specific Size"/>
<action id="ConfigureDefaultSize" internal="true" class="com.intellij.internal.inspector.ConfigureCustomSizeAction" text="Configure Default Size..."/>
</group>
<action internal="true" id="ShowEditorHighlighterTokens" class="com.intellij.openapi.editor.actions.ShowEditorHighlighterTokensAction"
text="Show Editor Highlighter Tokens"/>
<add-to-group group-id="ToolsMenu" anchor="last"/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment