Skip to content

Commit

Permalink
Merge pull request #85 from Grigory-Rylov/show_thread_selection_dialo…
Browse files Browse the repository at this point in the history
…g_after_find_nethods

Show thread selection dialog after find nethods
  • Loading branch information
Grigory-Rylov committed Aug 10, 2022
2 parents 6e7c137 + 4cd6ad0 commit 92fad8b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 70 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ allprojects {
subprojects {
apply plugin: 'idea'
ext {
productVersion = '22.08.08.0'
productVersion = '22.08.10.0'
}
}
33 changes: 33 additions & 0 deletions core/src/main/java/com/github/grishberg/profiler/chart/Finder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Finder(

var listener: FindResultListener? = null

var isSearchingModeEnabled = false
private set

private var currentSelectedThreadIndex: Int = -1

private var currentFindResult: FindResult = FindResult(emptyList())
Expand All @@ -28,6 +31,24 @@ class Finder(

fun getCurrentThreadResult(): ThreadFindResult = currentFindResult.threadResults[currentSelectedThreadIndex]

fun getResultForThread(threadItem: ThreadItem): ThreadFindResult? {
for (i in currentFindResult.threadResults.indices) {
if (currentFindResult.threadResults[i].threadItem == threadItem) {
return currentFindResult.threadResults[i]
}
}
return null
}

fun setCurrentThreadResultForThread(threadItem: ThreadItem) {
for (i in currentFindResult.threadResults.indices) {
if (currentFindResult.threadResults[i].threadItem == threadItem) {
currentSelectedThreadIndex = i
return
}
}
}

fun getNextThread(): ThreadItem {
val index = getNextThreadIndex()
return currentFindResult.threadResults[index].threadItem
Expand All @@ -42,6 +63,12 @@ class Finder(
currentSelectedThreadIndex = getNextThreadIndex()
}

fun disableSearching() {
isSearchingModeEnabled = false
currentSelectedThreadIndex = -1
currentFindResult = FindResult(emptyList())
}

private fun getNextThreadIndex(): Int {
if (currentSelectedThreadIndex == -1) {
return -1
Expand Down Expand Up @@ -74,6 +101,7 @@ class Finder(
textToFind: String,
ignoreCase: Boolean,
) {
isSearchingModeEnabled = true
currentSelectedThreadIndex = -1
coroutineScope.launch {
val data = withContext(dispatchers.worker) {
Expand Down Expand Up @@ -153,6 +181,11 @@ class Finder(
fun getResultForThread(threadId: Int): ThreadFindResult? {
return threadResults.find { it.threadId == threadId }
}

fun getThreadResult(threadItem: ThreadItem): ThreadFindResult =
threadResults.find { it.threadItem == threadItem }!!

fun getThreadList(): List<ThreadItem> = threadResults.map { it.threadItem }
}

data class ThreadFindResult(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.github.grishberg.profiler.chart.threads

import com.github.grishberg.profiler.core.ThreadItem
import com.github.grishberg.profiler.chart.preview.PREVIEW_IMAGE_HEIGHT
import com.github.grishberg.profiler.chart.preview.PREVIEW_IMAGE_WIDTH
import com.github.grishberg.profiler.chart.preview.PreviewImageRepository
import com.github.grishberg.profiler.common.AppLogger
import com.github.grishberg.profiler.core.ThreadItem
import com.github.grishberg.profiler.ui.dialogs.CloseByEscapeDialog
import java.awt.Color
import java.awt.Dimension
Expand All @@ -13,23 +13,20 @@ import java.awt.event.ActionEvent
import java.awt.event.KeyEvent
import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import javax.swing.AbstractAction
import javax.swing.JScrollPane
import javax.swing.JTable
import javax.swing.KeyStroke
import javax.swing.ListSelectionModel
import javax.swing.*
import kotlin.math.max


private const val THREAD_NAME_WIDTH = 180
private const val SELECT_ACTION = "Select"

class ThreadsViewDialog(
private val frame: Frame,
private val controller: ThreadsSelectionController,
private val previewImageRepository: PreviewImageRepository,
title: String,
frame: Frame,
controller: ThreadsSelectionController,
previewImageRepository: PreviewImageRepository,
private val logger: AppLogger
) : CloseByEscapeDialog(frame, "Select thread", true), ThreadsSelectionView {
) : CloseByEscapeDialog(frame, title, true), ThreadsSelectionView {

private val model = ThreadListModel(previewImageRepository)
var selectedThreadItem: ThreadItem? = null
Expand Down
88 changes: 29 additions & 59 deletions core/src/main/java/com/github/grishberg/profiler/ui/Main.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package com.github.grishberg.profiler.ui;

import com.github.grishberg.profiler.analyzer.FlatMethodsReportGenerator;
import com.github.grishberg.profiler.chart.BookmarkPopupMenu;
import com.github.grishberg.profiler.chart.Bookmarks;
import com.github.grishberg.profiler.chart.BookmarksRectangle;
import com.github.grishberg.profiler.chart.CallTracePanel;
import com.github.grishberg.profiler.chart.CallTracePreviewPanel;
import com.github.grishberg.profiler.chart.Finder;
import com.github.grishberg.profiler.chart.FoundNavigationListener;
import com.github.grishberg.profiler.chart.MethodsPopupMenu;
import com.github.grishberg.profiler.chart.*;
import com.github.grishberg.profiler.chart.flame.FlameChartController;
import com.github.grishberg.profiler.chart.flame.FlameChartDialog;
import com.github.grishberg.profiler.chart.highlighting.MethodsColorImpl;
Expand All @@ -20,13 +13,7 @@
import com.github.grishberg.profiler.chart.stages.systrace.SystraceStagesFacade;
import com.github.grishberg.profiler.chart.threads.ThreadsSelectionController;
import com.github.grishberg.profiler.chart.threads.ThreadsViewDialog;
import com.github.grishberg.profiler.common.AppLogger;
import com.github.grishberg.profiler.common.CoroutinesDispatchersImpl;
import com.github.grishberg.profiler.common.FileSystem;
import com.github.grishberg.profiler.common.MainScope;
import com.github.grishberg.profiler.common.MenuAcceleratorHelperKt;
import com.github.grishberg.profiler.common.TraceContainer;
import com.github.grishberg.profiler.common.UrlOpener;
import com.github.grishberg.profiler.common.*;
import com.github.grishberg.profiler.common.settings.SettingsFacade;
import com.github.grishberg.profiler.common.updates.ReleaseVersion;
import com.github.grishberg.profiler.common.updates.UpdatesChecker;
Expand All @@ -38,12 +25,7 @@
import com.github.grishberg.profiler.core.ProfileData;
import com.github.grishberg.profiler.core.ThreadItem;
import com.github.grishberg.profiler.plugins.PluginsFacade;
import com.github.grishberg.profiler.ui.dialogs.KeymapDialog;
import com.github.grishberg.profiler.ui.dialogs.LoadingDialog;
import com.github.grishberg.profiler.ui.dialogs.NewBookmarkDialog;
import com.github.grishberg.profiler.ui.dialogs.ReportsGeneratorDialog;
import com.github.grishberg.profiler.ui.dialogs.ScaleRangeDialog;
import com.github.grishberg.profiler.ui.dialogs.SetAndroidHomeDialog;
import com.github.grishberg.profiler.ui.dialogs.*;
import com.github.grishberg.profiler.ui.dialogs.highlighting.HighlightDialog;
import com.github.grishberg.profiler.ui.dialogs.info.DependenciesDialogLogic;
import com.github.grishberg.profiler.ui.dialogs.info.FocusElementDelegate;
Expand All @@ -54,40 +36,20 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.SwingWorker;
import javax.swing.UIManager;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;
import java.io.File;
import java.util.List;

public class Main implements ZoomAndPanDelegate.MouseEventsListener,
FoundNavigationListener<ProfileData>, ActionListener, ShowDialogDelegate, CallTracePanel.OnRightClickListener, UpdatesChecker.UpdatesFoundAction {
Expand Down Expand Up @@ -709,16 +671,27 @@ public void showThreadsDialog() {
return;
}

ThreadsSelectionController controller = new ThreadsSelectionController();
ThreadsViewDialog dialog = new ThreadsViewDialog(frame, controller, previewImageRepository, log);
dialog.showThreads(resultContainer.getResult().getThreads());
dialog.setLocationRelativeTo(chart);
dialog.setVisible(true);
ThreadItem selected = dialog.getSelectedThreadItem();
ThreadItem selected = showThreadsDialog(resultContainer.getResult().getThreads(), "Select thread");
if (selected == null) {
return;
}
switchThread(selected);
if (methodsFinder.isSearchingModeEnabled()) {
Finder.ThreadFindResult resultForThread = methodsFinder.getResultForThread(selected);
if (resultForThread != null) {
methodsFinder.setCurrentThreadResultForThread(selected);
chart.renderFoundItems(resultForThread);
}
}
}

private ThreadItem showThreadsDialog(List<ThreadItem> threads, String title) {
ThreadsSelectionController controller = new ThreadsSelectionController();
ThreadsViewDialog dialog = new ThreadsViewDialog(title, frame, controller, previewImageRepository, log);
dialog.showThreads(threads);
dialog.setLocationRelativeTo(chart);
dialog.setVisible(true);
return dialog.getSelectedThreadItem();
}

public void switchMainThread() {
Expand Down Expand Up @@ -908,15 +881,11 @@ public void onFindDone(@NotNull Finder.FindResult findResult) {
}

private void onResultsFoundInOtherThreads(Finder.FindResult findResult) {
boolean shouldSwitchThread = JOptionPane.showConfirmDialog(frame, "Found results in another threads: \n" +
findResult.generateFoundThreadNames() +
"\n\nShould switch to first one?",
"Found in another thread", JOptionPane.YES_NO_OPTION) == 0;

if (shouldSwitchThread) { //The ISSUE is here
Finder.ThreadFindResult firstThreadResult = findResult.getThreadResults().get(0);
switchThread(firstThreadResult.getThreadItem());
chart.renderFoundItems(firstThreadResult);
ThreadItem selectedThread = showThreadsDialog(findResult.getThreadList(), "Found results in another threads");

if (selectedThread != null) {
switchThread(selectedThread);
chart.renderFoundItems(findResult.getThreadResult(selectedThread));
}
}

Expand Down Expand Up @@ -1189,6 +1158,7 @@ public void exitFromSearching(boolean removeSelection) {
chart.requestFocus();
}
chart.disableSearching();
methodsFinder.disableSearching();
foundInfo.setText(DEFAULT_FOUND_INFO_MESSAGE);
}

Expand Down
1 change: 1 addition & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ patchPluginXml {
sinceBuild("211")
changeNotes """
Notify found results in other threads.<br>
Allow switch to prev/next thread with found results.<br>
"""
}

Expand Down

0 comments on commit 92fad8b

Please sign in to comment.