diff options
author | Alon Albert <aalbert@google.com> | 2022-08-09 11:05:58 -0700 |
---|---|---|
committer | Alon Albert <aalbert@google.com> | 2022-08-11 14:41:46 +0000 |
commit | ff2976e6df5c892b81c0558a5f9dc397ba5eef37 (patch) | |
tree | a897a6ae9b343d754c4fde45d89469142747e7ff /logcat | |
parent | a976dfdde563785abcc3f7a0638676085868fac0 (diff) | |
download | idea-ff2976e6df5c892b81c0558a5f9dc397ba5eef37.tar.gz |
Show a Banner if All Log Entries Are Hidden by the Filter
Screenshot: https://screenshot.googleplex.com/9EUb9XvsT2GCvpc.png
Bug: n/a
Test: Added
Change-Id: I8c17c5e0c5ae62ed6424454a06a550d5bd739951
Diffstat (limited to 'logcat')
4 files changed, 72 insertions, 3 deletions
diff --git a/logcat/resources/messages/LogcatBundle.properties b/logcat/resources/messages/LogcatBundle.properties index 2f1019410c6..f8d6bacfc1d 100644 --- a/logcat/resources/messages/LogcatBundle.properties +++ b/logcat/resources/messages/LogcatBundle.properties @@ -1,6 +1,8 @@ logcat.main.panel.pause.banner.text=Logcat is paused logcat.main.panel.no.application.ids.banner.text=Could not detect project package names. Is the project synced? logcat.main.panel.no.application.ids.banner.sync.now=Sync now +logcat.main.panel.no.logs.banner.text=All logs entries are hidden by the filter +logcat.main.panel.no.logs.banner.clear.filter=Clear filter logcat.header.options.title=Logcat Format diff --git a/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt b/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt index 6ce0dd777df..61fe7d7fe45 100644 --- a/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt +++ b/logcat/src/com/android/tools/idea/logcat/LogcatMainPanel.kt @@ -197,6 +197,7 @@ internal class LogcatMainPanel( internal val editor: EditorEx = createLogcatEditor(project) private val pausedBanner = EditorNotificationPanel() private val noApplicationIdsBanner = EditorNotificationPanel() + private val noLogsBanner = EditorNotificationPanel() private val document = editor.document private val documentAppender = DocumentAppender(project, document, logcatSettings.bufferSize) private val coroutineScope = AndroidCoroutineScope(this) @@ -287,16 +288,26 @@ internal class LogcatMainPanel( border = BANNER_BORDER isVisible = isMissingApplicationIds() } + noLogsBanner.apply { + noLogsBanner.text = LogcatBundle.message("logcat.main.panel.no.logs.banner.text") + createActionLabel(LogcatBundle.message("logcat.main.panel.no.logs.banner.clear.filter")) { + setFilter("") + } + border = BANNER_BORDER + isVisible = isLogsMissing() + } val centerPanel = JPanel(null).apply { layout = GroupLayout(this).apply { val height = pausedBanner.preferredSize.height setVerticalGroup( createSequentialGroup() + .addComponent(noLogsBanner, height, height, height) .addComponent(noApplicationIdsBanner, height, height, height) .addComponent(pausedBanner, height, height, height) .addComponent(editor.component)) setHorizontalGroup( createParallelGroup(GroupLayout.Alignment.CENTER) + .addComponent(noLogsBanner) .addComponent(noApplicationIdsBanner) .addComponent(pausedBanner) .addComponent(editor.component)) @@ -436,6 +447,7 @@ internal class LogcatMainPanel( val endMarker: RangeMarker = document.createRangeMarker(document.textLength, document.textLength) documentAppender.appendToDocument(textAccumulator) + noLogsBanner.isVisible = isLogsMissing() val startLine = if (endMarker.isValid) document.getLineNumber(endMarker.endOffset) else 0 endMarker.dispose() @@ -476,11 +488,20 @@ internal class LogcatMainPanel( } } + private fun isLogsMissing(): Boolean { + return document.immutableCharSequence.isEmpty() + && !isMissingApplicationIds() + && headerPanel.filter.isNotEmpty() + } + @UiThread override fun reloadMessages() { document.setText("") coroutineScope.launch(workerThread) { - messageProcessor.appendMessages(messageBacklog.get().messages) + val filteredMessages = messageProcessor.appendMessages(messageBacklog.get().messages) + withContext(uiThread) { + noLogsBanner.isVisible = filteredMessages.isEmpty() + } } } @@ -559,6 +580,7 @@ internal class LogcatMainPanel( messageBacklog.set(MessageBacklog(logcatSettings.bufferSize)) withContext(uiThread) { document.setText("") + noLogsBanner.isVisible = isLogsMissing() if (connectedDevice.get()?.sdk == 26) { processMessages(listOf(LogcatMessage( SYSTEM_HEADER, diff --git a/logcat/src/com/android/tools/idea/logcat/messages/MessageProcessor.kt b/logcat/src/com/android/tools/idea/logcat/messages/MessageProcessor.kt index f1835995efe..16b7d7f54dc 100644 --- a/logcat/src/com/android/tools/idea/logcat/messages/MessageProcessor.kt +++ b/logcat/src/com/android/tools/idea/logcat/messages/MessageProcessor.kt @@ -68,11 +68,12 @@ internal class MessageProcessor @TestOnly constructor( } } - internal suspend fun appendMessages(messages: List<LogcatMessage>) { + internal suspend fun appendMessages(messages: List<LogcatMessage>): List<LogcatMessage> { val filteredMessages = LogcatMasterFilter(logcatFilter).filter(messages) if (filteredMessages.isNotEmpty()) { messageChannel.send(filteredMessages) } + return filteredMessages } // TODO(b/200212377): @ExperimentalCoroutinesApi ReceiveChannel#isEmpty is required. See bug for details. diff --git a/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt b/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt index 4fd35476e88..918d1301efd 100644 --- a/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt +++ b/logcat/testSrc/com/android/tools/idea/logcat/LogcatMainPanelTest.kt @@ -253,7 +253,7 @@ class LogcatMainPanelTest { } @Test - fun appendMessages_disposedEditor() = runBlocking { + fun appendMessages_disposedEditor(): Unit = runBlocking { val logcatMainPanel = runInEdtAndGet { logcatMainPanel().also { Disposer.dispose(it) @@ -1029,6 +1029,50 @@ class LogcatMainPanelTest { } @Test + fun noLogsBanner_appearsAndDisappearsWhenAddingLogs(): Unit = runBlocking { + val logcatMainPanel = runInEdtAndGet(::logcatMainPanel) + val noLogsBanner = logcatMainPanel.findBanner("All logs entries are hidden by the filter") + logcatMainPanel.processMessages(listOf( + LogcatMessage(LogcatHeader(WARN, 1, 2, "app1", "", "tag1", Instant.ofEpochMilli(1000)), "message1"), + )) + waitForCondition { + logcatMainPanel.editor.document.text.trim() == """ + 1970-01-01 04:00:01.000 1-2 tag1 app1 W message1 + """.trimIndent() + } + runInEdtAndWait { + logcatMainPanel.setFilter("no-match") + } + waitForCondition { noLogsBanner.isVisible } + logcatMainPanel.processMessages(listOf( + LogcatMessage(LogcatHeader(WARN, 1, 2, "app1", "", "tag1", Instant.ofEpochMilli(1000)), "no-match"), + )) + waitForCondition { !noLogsBanner.isVisible } + } + + @Test + fun noLogsBanner_appearsAndDisappearsWhenChangingFilter(): Unit = runBlocking { + val logcatMainPanel = runInEdtAndGet(::logcatMainPanel) + val noLogsBanner = logcatMainPanel.findBanner("All logs entries are hidden by the filter") + logcatMainPanel.processMessages(listOf( + LogcatMessage(LogcatHeader(WARN, 1, 2, "app1", "", "tag1", Instant.ofEpochMilli(1000)), "message1"), + )) + waitForCondition { + logcatMainPanel.editor.document.text.trim() == """ + 1970-01-01 04:00:01.000 1-2 tag1 app1 W message1 + """.trimIndent() + } + runInEdtAndWait { + logcatMainPanel.setFilter("no-match") + } + waitForCondition { noLogsBanner.isVisible } + runInEdtAndWait { + logcatMainPanel.setFilter("tag:tag1") + } + waitForCondition { !noLogsBanner.isVisible } + } + + @Test fun projectAppMonitorInstalled() { val testDevice = TestDevice("device1", DeviceState.ONLINE, 11, 30, "Google", "Pixel", "") fakeAdbSession.deviceServices.setupCommandsForDevice(testDevice) |