diff options
author | Alon Albert <aalbert@google.com> | 2022-07-08 13:34:01 -0700 |
---|---|---|
committer | TreeHugger Robot <treehugger-gerrit@google.com> | 2022-07-11 17:35:35 +0000 |
commit | f33996bd71525515aec2be8cfe20340864a73c31 (patch) | |
tree | f0db3902a6ea59d8fa1f7f6b19e951ac521a45b2 /logcat | |
parent | 9e359d6f41f38335ddd8274676ab81a287c1e10a (diff) | |
download | idea-f33996bd71525515aec2be8cfe20340864a73c31.tar.gz |
Add a Tooltip to the Filter Dropdown
Show a tooltip when hovering over the toggle or delete buttons.
Also show a tooltip if hovering over a filter that shows the name only (filters with duplicate names don't need a tooltip because they show their query already)
See screenshots:
https://screenshot.googleplex.com/3UspxuFJK3WFvHb.png
https://screenshot.googleplex.com/3s8D9qGadVuKVPr.png
https://screenshot.googleplex.com/5Zj4cUHcAgfiLHp.png
https://screenshot.googleplex.com/Apvu4jWS9KWzQgy.png
Fixes: na
Test: Manually
Change-Id: Ieeebcf8168983078e7a43bb1bc43775fc6a5df6a
Diffstat (limited to 'logcat')
3 files changed, 42 insertions, 8 deletions
diff --git a/logcat/resources/messages/LogcatBundle.properties b/logcat/resources/messages/LogcatBundle.properties index a77dafe7b74..62ef5cd58fc 100644 --- a/logcat/resources/messages/LogcatBundle.properties +++ b/logcat/resources/messages/LogcatBundle.properties @@ -79,7 +79,7 @@ logcat.filter.clear.tooltip=Clear filter logcat.filter.tag.favorite.tooltip=Add to favorites logcat.filter.untag.favorite.tooltip=Remove from favorites logcat.filter.history.tooltip=Show history -logcat.filter.delete.history.tooltip=Press Delete button to remove from history +logcat.filter.history.delete.tooltip=<html>Delete item \\ \\ \\ \\ \\ <span style="color:#{0}">Delete</span></html> logcat.filter.completion.hint1=Add ~ to use regex (such as, "tag~:" and "-tag~:") logcat.filter.completion.hint2=Add - to a key to exclude logs with the value (such as, "-tag:") logcat.filter.completion.hint3=Show only logs from the last day, hour etc.: "age:1d", "age:5h" diff --git a/logcat/src/com/android/tools/idea/logcat/filters/AndroidLogcatFilterHistory.kt b/logcat/src/com/android/tools/idea/logcat/filters/AndroidLogcatFilterHistory.kt index c768ff159fc..1eea21c9cd9 100644 --- a/logcat/src/com/android/tools/idea/logcat/filters/AndroidLogcatFilterHistory.kt +++ b/logcat/src/com/android/tools/idea/logcat/filters/AndroidLogcatFilterHistory.kt @@ -39,6 +39,8 @@ internal class AndroidLogcatFilterHistory( private val maxNonFavoriteItems: Int = MAX_HISTORY_SIZE, ) : PersistentStateComponent<AndroidLogcatFilterHistory> { + val items get() = favorites + nonFavorites + fun add(filter: String, isFavorite: Boolean) { remove(filter) diff --git a/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt b/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt index 52f1ac772e2..a37d8542162 100644 --- a/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt +++ b/logcat/src/com/android/tools/idea/logcat/filters/FilterTextField.kt @@ -40,7 +40,6 @@ import com.intellij.openapi.editor.event.DocumentListener import com.intellij.openapi.editor.ex.EditorEx import com.intellij.openapi.editor.markup.TextAttributes import com.intellij.openapi.project.Project -import com.intellij.openapi.ui.asSequence import com.intellij.openapi.ui.popup.JBPopupFactory import com.intellij.openapi.ui.popup.PopupChooserBuilder import com.intellij.openapi.util.Disposer @@ -54,6 +53,7 @@ import com.intellij.ui.SimpleTextAttributes import com.intellij.ui.components.JBList import com.intellij.util.ui.EmptyIcon import com.intellij.util.ui.JBUI +import com.intellij.util.ui.UIUtil import com.intellij.util.ui.components.BorderLayoutPanel import icons.StudioIcons.Logcat.Input.FAVORITE_FILLED import icons.StudioIcons.Logcat.Input.FAVORITE_FILLED_HOVER @@ -368,6 +368,7 @@ internal class FilterTextField( coroutineContext: CoroutineContext = EmptyCoroutineContext, ) : JBList<FilterHistoryItem>() { private val listModel = CollectionListModel<FilterHistoryItem>() + private val inactiveColor = String.format("%06x", UIUtil.getInactiveTextColor().rgb and 0xffffff) init { // The "count" field in FilterHistoryItem.Item takes time to calculate so initially, add all items with no count. @@ -415,6 +416,24 @@ internal class FilterTextField( addMouseMotionListener(listener) } + override fun getToolTipText(event: MouseEvent): String? { + val index = selectedIndex + val item = model.getElementAt(index) as? Item ?: return null + val cellLocation = getCellBounds(index, index).location + val favoriteIconBounds = item.getFavoriteIconBounds(cellLocation) + val deleteIconBounds = item.getDeleteIconBounds(cellLocation) + return when { + favoriteIconBounds.contains(event.point) -> getFavoriteTooltip(item) + deleteIconBounds.contains(event.point) -> LogcatBundle.message("logcat.filter.history.delete.tooltip", inactiveColor) + else -> item.tooltip + } + } + + private fun getFavoriteTooltip(item: Item) = when (item.isFavorite) { + true -> LogcatBundle.message("logcat.filter.tag.favorite.tooltip") + false -> LogcatBundle.message("logcat.filter.untag.favorite.tooltip") + } + /** * Toggle the Favorite state of an item. * @@ -517,6 +536,7 @@ internal class FilterTextField( } } + private class HistoryListCellRenderer : ListCellRenderer<FilterHistoryItem> { override fun getListCellRendererComponent( list: JList<out FilterHistoryItem>, @@ -537,10 +557,11 @@ internal class FilterTextField( var isFavorite: Boolean, val count: Int?, private val filterParser: LogcatFilterParser, - var isFavoriteHovered: Boolean = false, ) : FilterHistoryItem() { - private val filterName = filterParser.parse(filter)?.getFilterName() + var isFavoriteHovered: Boolean = false + + val tooltip: String? fun getFavoriteIconBounds(offset: Point): Rectangle = favoriteLabel.bounds + offset @@ -576,19 +597,30 @@ internal class FilterTextField( } } - override fun getComponent(isSelected: Boolean, list: JList<out FilterHistoryItem>): JComponent { - filterLabel.clear() + init { + val filterName = filterParser.parse(filter)?.getFilterName() if (filterName != null) { + val history = AndroidLogcatFilterHistory.getInstance().items // If there is more than one Item with the same filterName, show the name and the filter. - val sameName = list.model.asSequence().filterIsInstance<Item>().count { it.filterName == filterName } + val sameName = history.count { filterParser.parse(it)?.getFilterName() == filterName } filterLabel.append(filterName, NAMED_FILTER_HISTORY_ITEM_COLOR) + val filterWithoutName = filterParser.removeFilterNames(filter) if (sameName > 1) { - filterLabel.append(": ${filterParser.removeFilterNames(filter)}") + filterLabel.append(": $filterWithoutName") + tooltip = null + } + else { + tooltip = filterWithoutName } } else { + tooltip = null filterLabel.append(filter) } + + } + + override fun getComponent(isSelected: Boolean, list: JList<out FilterHistoryItem>): JComponent { // This can be mico optimized, but it's more readable like this favoriteLabel.icon = when { isFavoriteHovered && isFavorite -> FAVORITE_FILLED_POPUP_HOVER |