diff --git a/build.gradle b/build.gradle index 166cc33..f2de20a 100644 --- a/build.gradle +++ b/build.gradle @@ -44,6 +44,6 @@ allprojects { subprojects { apply plugin: 'idea' ext { - productVersion = '22.08.08.0' + productVersion = '22.08.10.0' } } diff --git a/core/src/main/java/com/github/grishberg/profiler/chart/Finder.kt b/core/src/main/java/com/github/grishberg/profiler/chart/Finder.kt index 95b26c1..faddcad 100644 --- a/core/src/main/java/com/github/grishberg/profiler/chart/Finder.kt +++ b/core/src/main/java/com/github/grishberg/profiler/chart/Finder.kt @@ -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()) @@ -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 @@ -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 @@ -74,6 +101,7 @@ class Finder( textToFind: String, ignoreCase: Boolean, ) { + isSearchingModeEnabled = true currentSelectedThreadIndex = -1 coroutineScope.launch { val data = withContext(dispatchers.worker) { @@ -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 = threadResults.map { it.threadItem } } data class ThreadFindResult( diff --git a/core/src/main/java/com/github/grishberg/profiler/chart/threads/ThreadsViewDialog.kt b/core/src/main/java/com/github/grishberg/profiler/chart/threads/ThreadsViewDialog.kt index cdd24cb..4669b12 100644 --- a/core/src/main/java/com/github/grishberg/profiler/chart/threads/ThreadsViewDialog.kt +++ b/core/src/main/java/com/github/grishberg/profiler/chart/threads/ThreadsViewDialog.kt @@ -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 @@ -13,11 +13,7 @@ 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 @@ -25,11 +21,12 @@ 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 diff --git a/core/src/main/java/com/github/grishberg/profiler/ui/Main.java b/core/src/main/java/com/github/grishberg/profiler/ui/Main.java index 1b59969..73d9f8d 100644 --- a/core/src/main/java/com/github/grishberg/profiler/ui/Main.java +++ b/core/src/main/java/com/github/grishberg/profiler/ui/Main.java @@ -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; @@ -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; @@ -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; @@ -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, ActionListener, ShowDialogDelegate, CallTracePanel.OnRightClickListener, UpdatesChecker.UpdatesFoundAction { @@ -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 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() { @@ -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)); } } @@ -1189,6 +1158,7 @@ public void exitFromSearching(boolean removeSelection) { chart.requestFocus(); } chart.disableSearching(); + methodsFinder.disableSearching(); foundInfo.setText(DEFAULT_FOUND_INFO_MESSAGE); } diff --git a/plugin/build.gradle b/plugin/build.gradle index 8b4c0f9..75f5c97 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -71,6 +71,7 @@ patchPluginXml { sinceBuild("211") changeNotes """ Notify found results in other threads.
+ Allow switch to prev/next thread with found results.
""" }