Skip to content

Commit 48a900a

Browse files
committed
Add selection dialog to choose whether to save full log or filtered log.
Implement Selection of non-adjacent rows in log table.
1 parent d22fc36 commit 48a900a

File tree

15 files changed

+167
-70
lines changed

15 files changed

+167
-70
lines changed

resources/strings/default.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@
257257
"logPath": "Log Path",
258258
"logSampleLabel": "Sample",
259259
"logTypeLabel": "Log Type",
260+
"logTypeSelectContent": "Select the log types to save",
261+
"logTypeSelectTitle": "Log Type Selection",
260262
"lowerFilterOrder": "Move to Previous Row",
261263
"maxPartsLabel": "Maximum Number of Splits",
262264
"menuAbout": "About",

resources/strings/src/main/resources/strings/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@
255255
"logPath": "Log Path",
256256
"logSampleLabel": "Sample",
257257
"logTypeLabel": "Log Type",
258+
"logTypeSelectContent": "Select the log types to save",
259+
"logTypeSelectTitle": "Log Type Selection",
258260
"lowerFilterOrder": "Move to Previous Row",
259261
"maxPartsLabel": "Maximum Number of Splits",
260262
"menuAbout": "About",

resources/strings/src/main/resources/strings/ko.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@
252252
"logPath": "로그 경로",
253253
"logSampleLabel": "샘플",
254254
"logTypeLabel": "로그 유형",
255+
"logTypeSelectContent": "저장할 로그 유형을 선택하세요",
256+
"logTypeSelectTitle": "로그 유형 선택",
255257
"lowerFilterOrder": "이전 행으로 이동",
256258
"maxPartsLabel": "최대 분할 수",
257259
"menuAbout": "소개",
@@ -338,7 +340,7 @@
338340
"tableColumnInfoHint": "이 테이블은 로그 테이블의 모든 열 정보를 정의합니다\n행 번호 n의 열은 로그 파서에 의해 파싱된 로그의 n번째 부분을 저장하므로 로그 파서와 함께 모든 열을 정의해야 하며, 열의 순서도 로그 파서의 결과와 일치해야 합니다.",
339341
"tableFilterInfo": "필터 정보",
340342
"tableLevelInfo": "로그 레벨 정보",
341-
"tableLevelInfoHint": "테이블은 모든 로�� 레벨을 정의합니다\n정의된 로그 레벨의 행 번호가 작을수록 로그 레벨이 낮습니다.",
343+
"tableLevelInfoHint": "표는 모든 로그 레벨을 정의합니다. 정의된 로그 레벨의 행 번호가 작을수록 로그 레벨이 낮습니다.",
342344
"targetPartIndexLabel": "대상 문자열 인덱스",
343345
"trimLeadingCharCountLabel": "제거할 앞부분 문자 수:",
344346
"trimLeadingCharLabel": "앞부분 문자:",

resources/strings/src/main/resources/strings/zh_cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@
251251
"logPath": "日志路径",
252252
"logSampleLabel": "样本",
253253
"logTypeLabel": "日志类型",
254+
"logTypeSelectContent": "选择需要保存的日志类型",
255+
"logTypeSelectTitle": "日志类型选择",
254256
"lowerFilterOrder": "移动到上一行",
255257
"maxPartsLabel": "最大分割数",
256258
"menuAbout": "关于",

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/datasource/DeviceLogProducer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import me.gegenbauer.catspy.log.metadata.LogcatLogSupport
1919
import me.gegenbauer.catspy.log.ui.LogConfiguration
2020
import me.gegenbauer.catspy.platform.GlobalProperties
2121
import me.gegenbauer.catspy.platform.LOG_DIR
22-
import me.gegenbauer.catspy.platform.currentPlatform
2322
import me.gegenbauer.catspy.platform.filesDir
2423
import me.gegenbauer.catspy.task.CommandExecutorImpl
2524
import me.gegenbauer.catspy.task.CommandProcessBuilder

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/datasource/LogFilterable.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import me.gegenbauer.catspy.log.filter.LogFilter
55
interface LogFilterable {
66
val logFilter: LogFilter
77

8-
var fullTableSelectedRows: List<Int>
8+
val fullTableSelectedRows: MutableSet<Int>
99

10-
var filteredTableSelectedRows: List<Int>
10+
val filteredTableSelectedRows: MutableSet<Int>
1111

1212
fun updateFilter(filter: LogFilter)
1313
}

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/datasource/LogViewModel.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import me.gegenbauer.catspy.view.panel.StatusPanel
4040
import me.gegenbauer.catspy.view.panel.Task
4141
import me.gegenbauer.catspy.view.panel.TaskHandle
4242
import java.io.File
43+
import java.util.HashSet
4344
import java.util.Objects
4445
import java.util.concurrent.atomic.AtomicBoolean
4546
import java.util.concurrent.atomic.AtomicReference
@@ -60,9 +61,9 @@ class LogViewModel(
6061
override val logFilter: LogFilter
6162
get() = logConf.getCurrentFilter()
6263

63-
override var fullTableSelectedRows: List<Int> = emptyList()
64+
override val fullTableSelectedRows: MutableSet<Int> = HashSet()
6465

65-
override var filteredTableSelectedRows: List<Int> = emptyList()
66+
override val filteredTableSelectedRows: MutableSet<Int> = HashSet()
6667

6768
override val tempLogFile: File
6869
get() = produceLogTask.logProducer.tempFile
@@ -138,9 +139,10 @@ class LogViewModel(
138139
/**
139140
* save full log to file
140141
*/
141-
suspend fun saveLog(targetFile: File): Result<File?> {
142+
suspend fun saveLog(targetFile: File, isFilteredLog: Boolean): Result<File?> {
142143
return withContext(Dispatchers.GIO) {
143-
val logs = fullLogRepo.readLogItems { it.toList() }
144+
val repo = if (isFilteredLog) filteredLogRepo else fullLogRepo
145+
val logs = repo.readLogItems { it.toList() }
144146
Log.d(TAG, "[saveLog] targetLogFile=${targetFile.absolutePath}, logSize=${logs.size}")
145147
val taskName = STRINGS.ui.exportFileTaskTitle.get(targetFile.absolutePath)
146148
val task = Task(taskName, object : TaskHandle {

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/ui/tab/BaseLogMainPanel.kt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import me.gegenbauer.catspy.utils.event.EventManager
4646
import me.gegenbauer.catspy.utils.ui.Key
4747
import me.gegenbauer.catspy.utils.ui.findFrameFromParent
4848
import me.gegenbauer.catspy.utils.ui.registerStroke
49+
import me.gegenbauer.catspy.utils.ui.showMultiOptionsDialog
4950
import me.gegenbauer.catspy.view.button.IconBarButton
5051
import me.gegenbauer.catspy.view.dialog.FileSaveHandler
5152
import me.gegenbauer.catspy.view.panel.StatusBar
@@ -165,8 +166,6 @@ abstract class BaseLogMainPanel : BaseTabPanel() {
165166
logToolBar.isVisible = logConf.isPreviewMode.not()
166167
logConf.getFavoriteFilterPanel().isVisible = logConf.isPreviewMode.not()
167168

168-
saveBtn.isVisible = false
169-
170169
topPanel.border = BorderFactory.createEmptyBorder(4, 6, 4, 0)
171170
topPanel.layout = VerticalFlexibleWidthLayout(4)
172171
topPanel.add(logToolBar)
@@ -534,13 +533,34 @@ abstract class BaseLogMainPanel : BaseTabPanel() {
534533
}
535534

536535
private fun saveLog() {
536+
val logType = showLogTypeSelectDialog()
537+
if (logType <= 0) {
538+
return
539+
}
540+
val isFilteredLog = logType == LOG_TYPE_FILTERED
537541
FileSaveHandler.Builder(this)
538-
.onFileSpecified(logViewModel::saveLog)
542+
.onFileSpecified { logViewModel.saveLog(it, isFilteredLog) }
539543
.setDefaultName(logStatus.path.fileName)
540544
.build()
541545
.show()
542546
}
543547

548+
private fun showLogTypeSelectDialog(): Int {
549+
val actions = listOf(
550+
STRINGS.ui.fullLog to { LOG_TYPE_FULL },
551+
STRINGS.ui.filteredLog to { LOG_TYPE_FILTERED }
552+
)
553+
val res = showMultiOptionsDialog(
554+
findFrameFromParent(),
555+
STRINGS.ui.logTypeSelectTitle,
556+
STRINGS.ui.logTypeSelectContent,
557+
actions,
558+
1,
559+
JOptionPane.QUESTION_MESSAGE
560+
)
561+
return res
562+
}
563+
544564
private fun showLogPanelInWindow() {
545565
splitLogPane.detachFullLogPanel()
546566
val logTableDialog = LogTableDialog(splitLogPane.fullLogPanel) {
@@ -657,4 +677,11 @@ abstract class BaseLogMainPanel : BaseTabPanel() {
657677
ui.logMainBinding.pauseAll.updateValue(false)
658678
}
659679
}
680+
681+
companion object {
682+
private const val tag = "BaseLogMainPanel"
683+
private const val LOG_TYPE_NONE = 0
684+
private const val LOG_TYPE_FULL = 1
685+
private const val LOG_TYPE_FILTERED = 2
686+
}
660687
}

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/ui/tab/DeviceLogMainPanel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class DeviceLogMainPanel : BaseLogMainPanel(), LogMetadataChangeListener {
8080

8181
splitLogWithStatefulPanel.hideEmptyContent()
8282
deviceCombo.isVisible = true
83-
saveBtn.isVisible = true
8483
logConf.getLogBufferSelectPanel().isVisible = logConf.isPreviewMode.not()
8584
}
8685

ui/log/src/main/kotlin/me/gegenbauer/catspy/log/ui/table/FilteredLogPanel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ class FilteredLogPanel(
9090
if (selectedLogNum != baseSelectedLogNum) {
9191
val targetRow = basePanel.tableModel.getRowIndexInAllPages(selectedLogNum)
9292
basePanel.goToRowIndex(targetRow)
93+
val targetSelectRow = basePanel.tableModel.getRowIndexInCurrentPage(selectedLogNum)
94+
basePanel.tableModel.selectedLogRows.clear()
95+
basePanel.tableModel.selectedLogRows.add(targetSelectRow)
96+
basePanel.table.repaint()
9397

9498
if (table.isLastRowSelected()) {
9599
setGoToLast(true)

0 commit comments

Comments
 (0)