Skip to content
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

alternative keymap #121

Merged
merged 1 commit into from
Sep 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import java.io.FileReader
import java.io.IOException
import java.io.OutputStreamWriter


private const val TAG = "JsonSettings"

const val SETTINGS_ANDROID_HOME = "androidHome"
private const val SETTINGS_HISTORY = "Main.history"
private const val SETTINGS_ERGONOMIC_KEYMAP = "Main.ergonomicKeymap"
private const val SETTINGS_STAGES_FILE_DIALOG_DIR = "Plugins.stagesFileDialogDirectory"
private const val SETTINGS_STAGES_HIDE_UNKNOWN = "Plugins.stagesHideUnknown"
private const val SETTINGS_STAGES_HIERARCHICAL = "Plugins.stagesHierarchical"
Expand Down Expand Up @@ -54,14 +54,13 @@ private const val TIMEOUT_BEFORE_RECORDING = "$RECORDER_SETTINGS_ROOT.timeoutBef
private const val DEFAULT_TIMEOUT_BEFORE_RECORDING = 10

class JsonSettings(
private val filesDirName: String,
private val log: AppLogger
private val filesDirName: String, private val log: AppLogger
) : SettingsFacade {

private val gson = GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create()

private val settingsMap = mutableMapOf<String, Any>()
private val settingsFile =
File(filesDirName + File.separator + ".android-methods-profiler-settings.json")
private val settingsFile = File(filesDirName + File.separator + ".android-methods-profiler-settings.json")

init {
createHomeDirIfNeeded()
Expand Down Expand Up @@ -272,8 +271,7 @@ class JsonSettings(

override var samplingRecordModeEnabled: Boolean
get() = getBoolValueOrDefault(
RECORD_MODE_SAMPLE_SETTINGS,
true
RECORD_MODE_SAMPLE_SETTINGS, true
)
set(value) {
setBoolValue(RECORD_MODE_SAMPLE_SETTINGS, value)
Expand All @@ -293,8 +291,7 @@ class JsonSettings(

override var waitForResultTimeout: Int
get() = getIntValueOrDefault(
WAIT_FOR_RESULT_TIMEOUT_SETTINGS,
DEFAULT_WAIT_FOR_RESULT_TIMEOUT
WAIT_FOR_RESULT_TIMEOUT_SETTINGS, DEFAULT_WAIT_FOR_RESULT_TIMEOUT
)
set(value) {
setIntValue(WAIT_FOR_RESULT_TIMEOUT_SETTINGS, value)
Expand Down Expand Up @@ -326,8 +323,7 @@ class JsonSettings(

override var debugPort: Int
get() = getIntValueOrDefault(
DEBUG_PORT_SETTINGS,
DEFAULT_DEBUG_PORT
DEBUG_PORT_SETTINGS, DEFAULT_DEBUG_PORT
)
set(value) {
setIntValue(DEBUG_PORT_SETTINGS, value)
Expand All @@ -339,6 +335,12 @@ class JsonSettings(
setIntValue(TIMEOUT_BEFORE_RECORDING, value.toInt())
}

override var isErgonomicKeymapEnabled: Boolean
get() = getBoolValueOrDefault(SETTINGS_ERGONOMIC_KEYMAP, false)
set(value) {
setBoolValue(SETTINGS_ERGONOMIC_KEYMAP, value)
}

override fun filesDir() = filesDirName

override var shouldShowToolbar: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ interface SettingsFacade {
var debugPort: Int
var shouldShowToolbar: Boolean
var caseSensitive: Boolean
var isErgonomicKeymapEnabled: Boolean
}
26 changes: 22 additions & 4 deletions core/src/main/java/com/github/grishberg/profiler/ui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
import com.github.grishberg.profiler.ui.dialogs.info.FocusElementDelegate;
import com.github.grishberg.profiler.ui.dialogs.recorder.JavaMethodsRecorderDialogView;
import com.github.grishberg.profiler.ui.dialogs.recorder.JavaMethodsRecorderLogicKt;
import com.github.grishberg.profiler.ui.keymap.DefaultKeymapConfig;
import com.github.grishberg.profiler.ui.keymap.ErgonomicKeymapConfig;
import com.github.grishberg.profiler.ui.keymap.KeyBinder;
import com.github.grishberg.profiler.ui.keymap.KeymapConfig;
import com.github.grishberg.profiler.ui.theme.ThemeController;
import com.github.grishberg.tracerecorder.SystraceRecordResult;
import java.awt.*;
Expand Down Expand Up @@ -347,12 +351,16 @@ public void focusProfileElement(@NotNull ProfileData selectedElement) {
focusElementDelegate, settings, log,
coroutineScope, coroutinesDispatchers
);
KeymapConfig keymapConfig = settings.isErgonomicKeymapEnabled()
? new ErgonomicKeymapConfig()
: new DefaultKeymapConfig();
KeyBinder keyBinder = new KeyBinder(chart,
selectedClassNameLabel,
findClassText,
this,
newBookmarkDialog,
hoverInfoPanel, this
hoverInfoPanel, this,
keymapConfig
);
keyBinder.setUpKeyBindings();

Expand Down Expand Up @@ -571,7 +579,8 @@ private void deleteCurrentFile() {
if (currentOpenedFile == null) {
return;
}
boolean shouldDelete = JOptionPane.showConfirmDialog(frame,
boolean shouldDelete = JOptionPane.showConfirmDialog(
frame,
"Are you wanted to delete: \n\"" + currentOpenedFile.getName() +
"\" ?",
"Delete current file",
Expand Down Expand Up @@ -701,6 +710,15 @@ private JMenu createViewMenu() {
viewMenu.add(showHighlightingList);
showHighlightingList.addActionListener(a -> showHighlightingDialog());


JCheckBoxMenuItem ergonomicKeymap = new JCheckBoxMenuItem("Ergonomic keymap");
viewMenu.add(ergonomicKeymap);
ergonomicKeymap.setState(settings.isErgonomicKeymapEnabled());
ergonomicKeymap.addActionListener(arg0 -> {
boolean newState = ergonomicKeymap.getState();
settings.setErgonomicKeymapEnabled(newState);
});

return viewMenu;
}

Expand Down Expand Up @@ -1424,12 +1442,12 @@ private static class WorkerResult {
@Nullable final TraceContainer traceContainer;
@Nullable final Throwable throwable;

public WorkerResult(Throwable throwable) {
public WorkerResult(@Nullable Throwable throwable) {
this.traceContainer = null;
this.throwable = throwable;
}

public WorkerResult(TraceContainer traceContainer) {
public WorkerResult(@Nullable TraceContainer traceContainer) {
this.traceContainer = traceContainer;
this.throwable = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.grishberg.profiler.ui.keymap

import java.awt.event.KeyEvent

class DefaultKeymapConfig : KeymapConfig {

override val zoomOutKeyCode: Int = KeyEvent.VK_W
override val zoomInActionKeyCode: Int = KeyEvent.VK_S
override val panLeftActionKeyCode: Int = KeyEvent.VK_A
override val panRightActionKeyCode: Int = KeyEvent.VK_D
override val upActionKeyCode: Int = KeyEvent.VK_UP
override val downActionKeyCode: Int = KeyEvent.VK_DOWN
override val focusNextFoundItemActionKeyCode: Int = KeyEvent.VK_E
override val focusPrevFoundItemActionKeyCode: Int = KeyEvent.VK_Q
override val removeSelectionActionKeyCode: Int = KeyEvent.VK_ESCAPE
override val theadTimeModeActionKeyCode: Int = KeyEvent.VK_T
override val globalTimeModeActionKeyCode: Int = KeyEvent.VK_G
override val toggleBookmarkModeActionKeyCode: Int = KeyEvent.VK_B
override val goToFindActionKeyCode: Int = KeyEvent.VK_F
override val copyStackTraceActionKeyCode: Int = KeyEvent.VK_S
override val openFileDialogActionKeyCode: Int = KeyEvent.VK_O
override val newTraceActionKeyCode: Int = KeyEvent.VK_N
override val openFileDialogNewWindowActionKeyCode: Int = KeyEvent.VK_O
override val newTraceNewWindowActionKeyCode: Int = KeyEvent.VK_N
override val foundToMarkerKeyCode: Int = KeyEvent.VK_M
override val showThreadSwitcherKeyCode: Int = KeyEvent.VK_T
override val switchToMainThreadKeyCode: Int = KeyEvent.VK_0
override val findAllChildrenKeyCode: Int = KeyEvent.VK_I
override val addBookmarkActionKeyCode: Int = KeyEvent.VK_M
override val copySelectedFullClassNameActionKeyCode: Int = KeyEvent.VK_C
override val removeCurrentBookmarkActionKeyCode: Int = KeyEvent.VK_R
override val centerSelectedElementActionKeyCode: Int = KeyEvent.VK_C
override val resetZoomActionKeyCode: Int = KeyEvent.VK_Z
override val fitSelectedElementActionKeyCode: Int = KeyEvent.VK_F
override val nextBookmarkActionKeyCode: Int = KeyEvent.VK_E
override val prevBookmarkActionKeyCode: Int = KeyEvent.VK_Q
override val clearAllBookmarksActionKeyCode: Int = KeyEvent.VK_BACK_SPACE
override val generateReportsActionKeyCode: Int = KeyEvent.VK_P
override val changeFontSizeActionTrueKeyCode: Int = KeyEvent.VK_PLUS
override val changeFontSizeActionFalseKeyCode: Int = KeyEvent.VK_MINUS
override val copySelectedShortClassNameActionKeyCode: Int = KeyEvent.VK_C
override val exportTraceWithBookmarksActionKeyCode: Int = KeyEvent.VK_E
override val copySelectedShortClassNameWithoutMethodActionKeyCode: Int = KeyEvent.VK_C
override val openRangeDialogKeyCode: Int = KeyEvent.VK_R
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.github.grishberg.profiler.ui.keymap

import java.awt.event.KeyEvent

class ErgonomicKeymapConfig : KeymapConfig {

override val zoomOutKeyCode: Int = KeyEvent.VK_E
override val zoomInActionKeyCode: Int = KeyEvent.VK_D
override val panLeftActionKeyCode: Int = KeyEvent.VK_S
override val panRightActionKeyCode: Int = KeyEvent.VK_F
override val upActionKeyCode: Int = KeyEvent.VK_I
override val downActionKeyCode: Int = KeyEvent.VK_K
override val focusNextFoundItemActionKeyCode: Int = KeyEvent.VK_R
override val focusPrevFoundItemActionKeyCode: Int = KeyEvent.VK_W
override val removeSelectionActionKeyCode: Int = KeyEvent.VK_ESCAPE
override val theadTimeModeActionKeyCode: Int = KeyEvent.VK_T
override val globalTimeModeActionKeyCode: Int = KeyEvent.VK_G
override val toggleBookmarkModeActionKeyCode: Int = KeyEvent.VK_B
override val goToFindActionKeyCode: Int = KeyEvent.VK_F
override val copyStackTraceActionKeyCode: Int = KeyEvent.VK_S
override val openFileDialogActionKeyCode: Int = KeyEvent.VK_O
override val newTraceActionKeyCode: Int = KeyEvent.VK_N
override val openFileDialogNewWindowActionKeyCode: Int = KeyEvent.VK_N
override val newTraceNewWindowActionKeyCode: Int = KeyEvent.VK_M
override val foundToMarkerKeyCode: Int = KeyEvent.VK_M
override val showThreadSwitcherKeyCode: Int = KeyEvent.VK_T
override val switchToMainThreadKeyCode: Int = KeyEvent.VK_0
override val findAllChildrenKeyCode: Int = KeyEvent.VK_I
override val addBookmarkActionKeyCode: Int = KeyEvent.VK_M
override val copySelectedFullClassNameActionKeyCode: Int = KeyEvent.VK_C
override val removeCurrentBookmarkActionKeyCode: Int = KeyEvent.VK_R
override val centerSelectedElementActionKeyCode: Int = KeyEvent.VK_C
override val resetZoomActionKeyCode: Int = KeyEvent.VK_Z
override val fitSelectedElementActionKeyCode: Int = KeyEvent.VK_X
override val nextBookmarkActionKeyCode: Int = KeyEvent.VK_R
override val prevBookmarkActionKeyCode: Int = KeyEvent.VK_W
override val clearAllBookmarksActionKeyCode: Int = KeyEvent.VK_BACK_SPACE
override val generateReportsActionKeyCode: Int = KeyEvent.VK_P
override val changeFontSizeActionTrueKeyCode: Int = KeyEvent.VK_PLUS
override val changeFontSizeActionFalseKeyCode: Int = KeyEvent.VK_MINUS
override val copySelectedShortClassNameActionKeyCode: Int = KeyEvent.VK_C
override val exportTraceWithBookmarksActionKeyCode: Int = KeyEvent.VK_E
override val copySelectedShortClassNameWithoutMethodActionKeyCode: Int = KeyEvent.VK_C
override val openRangeDialogKeyCode: Int = KeyEvent.VK_R
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.github.grishberg.profiler.ui
package com.github.grishberg.profiler.ui.keymap

import com.github.grishberg.profiler.chart.CallTracePanel
import com.github.grishberg.profiler.ui.InfoPanel
import com.github.grishberg.profiler.ui.Main
import com.github.grishberg.profiler.ui.ShowDialogDelegate
import com.github.grishberg.profiler.ui.TextUtils
import com.github.grishberg.profiler.ui.dialogs.NewBookmarkDialog
import java.awt.KeyboardFocusManager
import java.awt.Toolkit
import java.awt.datatransfer.StringSelection
import java.awt.event.ActionEvent
import java.awt.event.InputEvent
import java.awt.event.KeyEvent
import javax.swing.AbstractAction
import javax.swing.JComponent
Expand All @@ -20,7 +23,8 @@ class KeyBinder(
private val dialogDelegate: ShowDialogDelegate,
private val newBookmarkDialog: NewBookmarkDialog,
private val hoverInfoPanel: InfoPanel,
private val main: Main
private val main: Main,
private val keymapConfig: KeymapConfig,
) {
val condition = JComponent.WHEN_IN_FOCUSED_WINDOW
val inputMap = profilerView.getInputMap(condition)
Expand All @@ -32,58 +36,51 @@ class KeyBinder(
val panLeftAction = PanLeftAction()
val panRightAction = PanRightAction()

addKeyMap(KeyEvent.VK_W, WAction())
addKeyMap(KeyEvent.VK_S, SAction())
addKeyMap(KeyEvent.VK_A, panLeftAction)
addKeyMap(KeyEvent.VK_LEFT, panLeftAction)
addKeyMap(KeyEvent.VK_D, panRightAction)
addKeyMap(KeyEvent.VK_RIGHT, panRightAction)
addKeyMap(KeyEvent.VK_UP, UpAction())
addKeyMap(KeyEvent.VK_DOWN, DownAction())
addKeyMap(keymapConfig.zoomOutKeyCode, ZoomOutAction())
addKeyMap(keymapConfig.zoomInActionKeyCode, ZoomInAction())
addKeyMap(keymapConfig.panLeftActionKeyCode, panLeftAction)
addKeyMap(keymapConfig.panLeftActionKeyCode, panLeftAction)
addKeyMap(keymapConfig.panRightActionKeyCode, panRightAction)
addKeyMap(keymapConfig.panRightActionKeyCode, panRightAction)
addKeyMap(keymapConfig.upActionKeyCode, UpAction())
addKeyMap(keymapConfig.downActionKeyCode, DownAction())

val focusNextAction = FocusNextAction()
addKeyMap(KeyEvent.VK_E, focusNextAction)
addKeyMap(KeyEvent.VK_ENTER, focusNextAction)
addKeyMap(KeyEvent.VK_F3, focusNextAction)
addKeyMap(KeyEvent.VK_Q, QAction())
addKeyMap(KeyEvent.VK_ESCAPE, RemoveSelectionAction())

addKeyMap(KeyEvent.VK_T, TheadTimeModeAction())
addKeyMap(KeyEvent.VK_G, GlobalTimeModeAction())
addKeyMap(KeyEvent.VK_B, ToggleBookmarkModeAction())

addKeyMapWithCtrl(KeyEvent.VK_F, GoToFindAction())
addKeyMapWithCtrl(KeyEvent.VK_S, CopyStackTraceAction())
addKeyMapWithCtrl(KeyEvent.VK_O, OpenFileDialogAction())
addKeyMapWithCtrl(KeyEvent.VK_N, NewTraceAction())
addKeyMapWithCtrlShift(KeyEvent.VK_O, OpenFileDialogNewWindowAction())
addKeyMapWithCtrlShift(KeyEvent.VK_N, NewTraceNewWindowAction())

addKeyMapWithCtrl(KeyEvent.VK_M, FoundToMarker())
addKeyMapWithCtrl(KeyEvent.VK_T, ShowThreadSwitcher())
addKeyMapWithCtrl(KeyEvent.VK_0, SwitchToMainThread())
addKeyMapWithCtrl(KeyEvent.VK_I, FindAllChildren())
addKeyMap(KeyEvent.VK_M, AddBookmarkAction())
addKeyMapWithCtrl(KeyEvent.VK_C, CopySelectedFullClassNameAction())
addKeyMapWithCtrl(KeyEvent.VK_R, RemoveCurrentBookmarkAction())
addKeyMap(KeyEvent.VK_C, CenterSelectedElementAction())
addKeyMap(KeyEvent.VK_Z, ResetZoomAction())
addKeyMap(KeyEvent.VK_F, FitSelectedElementAction())

addKeyMap(KeyEvent.VK_E, InputEvent.SHIFT_MASK, NextBookmarkAction())
addKeyMap(KeyEvent.VK_Q, InputEvent.SHIFT_MASK, PrevBookmarkAction())
addKeyMapWithCtrl(KeyEvent.VK_BACK_SPACE, ClearAllBookmarksAction())

addKeyMapWithCtrl(KeyEvent.VK_P, GenerateReportsAction())
addKeyMapWithCtrl(KeyEvent.VK_PLUS, ChangeFontSizeAction(true))
addKeyMapWithCtrl(KeyEvent.VK_EQUALS, ChangeFontSizeAction(true))
addKeyMapWithCtrl(KeyEvent.VK_MINUS, ChangeFontSizeAction(false))

addKeyMapWithCtrlShift(KeyEvent.VK_C, CopySelectedShortClassNameAction())
addKeyMapWithCtrlShift(KeyEvent.VK_E, ExportTraceWithBookmarksAction())
addKeyMapWithCtrlAlt(KeyEvent.VK_C, CopySelectedShortClassNameWithoutMethodAction())

addKeyMapWithShift(KeyEvent.VK_R, OpenRangeDialog())
addKeyMap(keymapConfig.focusNextFoundItemActionKeyCode, focusNextAction)
addKeyMap(keymapConfig.focusPrevFoundItemActionKeyCode, FocusPrevFoundItemAction())
addKeyMap(keymapConfig.removeSelectionActionKeyCode, RemoveSelectionAction())
addKeyMap(keymapConfig.theadTimeModeActionKeyCode, TheadTimeModeAction())
addKeyMap(keymapConfig.globalTimeModeActionKeyCode, GlobalTimeModeAction())
addKeyMap(keymapConfig.toggleBookmarkModeActionKeyCode, ToggleBookmarkModeAction())
addKeyMapWithCtrl(keymapConfig.goToFindActionKeyCode, GoToFindAction())
addKeyMapWithCtrl(keymapConfig.copyStackTraceActionKeyCode, CopyStackTraceAction())
addKeyMapWithCtrl(keymapConfig.openFileDialogActionKeyCode, OpenFileDialogAction())
addKeyMapWithCtrl(keymapConfig.newTraceActionKeyCode, NewTraceAction())
addKeyMapWithCtrlShift(keymapConfig.openFileDialogNewWindowActionKeyCode, OpenFileDialogNewWindowAction())
addKeyMapWithCtrlShift(keymapConfig.newTraceNewWindowActionKeyCode, NewTraceNewWindowAction())
addKeyMapWithCtrl(keymapConfig.foundToMarkerKeyCode, FoundToMarker())
addKeyMapWithCtrl(keymapConfig.showThreadSwitcherKeyCode, ShowThreadSwitcher())
addKeyMapWithCtrl(keymapConfig.switchToMainThreadKeyCode, SwitchToMainThread())
addKeyMapWithCtrl(keymapConfig.findAllChildrenKeyCode, FindAllChildren())
addKeyMap(keymapConfig.addBookmarkActionKeyCode, AddBookmarkAction())
addKeyMapWithCtrl(keymapConfig.copySelectedFullClassNameActionKeyCode, CopySelectedFullClassNameAction())
addKeyMapWithCtrl(keymapConfig.removeCurrentBookmarkActionKeyCode, RemoveCurrentBookmarkAction())
addKeyMap(keymapConfig.centerSelectedElementActionKeyCode, CenterSelectedElementAction())
addKeyMap(keymapConfig.resetZoomActionKeyCode, ResetZoomAction())
addKeyMap(keymapConfig.fitSelectedElementActionKeyCode, FitSelectedElementAction())
addKeyMap(keymapConfig.nextBookmarkActionKeyCode, NextBookmarkAction())
addKeyMap(keymapConfig.prevBookmarkActionKeyCode, PrevBookmarkAction())
addKeyMapWithCtrl(keymapConfig.clearAllBookmarksActionKeyCode, ClearAllBookmarksAction())
addKeyMapWithCtrl(keymapConfig.generateReportsActionKeyCode, GenerateReportsAction())
addKeyMapWithCtrl(keymapConfig.changeFontSizeActionTrueKeyCode, ChangeFontSizeAction(true))
addKeyMapWithCtrl(keymapConfig.changeFontSizeActionTrueKeyCode, ChangeFontSizeAction(true))
addKeyMapWithCtrl(keymapConfig.changeFontSizeActionFalseKeyCode, ChangeFontSizeAction(false))
addKeyMapWithCtrlShift(keymapConfig.copySelectedShortClassNameActionKeyCode, CopySelectedShortClassNameAction())
addKeyMapWithCtrlShift(keymapConfig.exportTraceWithBookmarksActionKeyCode, ExportTraceWithBookmarksAction())
addKeyMapWithCtrlAlt(keymapConfig.copySelectedShortClassNameWithoutMethodActionKeyCode, CopySelectedShortClassNameWithoutMethodAction())
addKeyMapWithShift(keymapConfig.openRangeDialogKeyCode, OpenRangeDialog())
}

private fun addKeyMap(keyCode: Int, action: AbstractAction) {
Expand Down Expand Up @@ -115,14 +112,14 @@ class KeyBinder(
}


private inner class WAction : SmartAction() {
private inner class ZoomOutAction : SmartAction() {
override fun actionPerformed() {
profilerView.zoomOut()
hoverInfoPanel.hidePanel()
}
}

private inner class SAction : SmartAction() {
private inner class ZoomInAction : SmartAction() {
override fun actionPerformed() {
profilerView.zoomIn()
hoverInfoPanel.hidePanel()
Expand Down Expand Up @@ -205,7 +202,7 @@ class KeyBinder(
}
}

private inner class QAction : SmartAction() {
private inner class FocusPrevFoundItemAction : SmartAction() {
override fun actionPerformed() {
profilerView.focusPrevFoundItem()
hoverInfoPanel.hidePanel()
Expand Down
Loading
Loading