Renamed DiffEntryType to DiffType
This commit is contained in:
parent
a542e38ae2
commit
6dd55bcc84
@ -6,8 +6,8 @@ import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
|||||||
import com.jetpackduba.gitnuro.git.workspace.StatusType
|
import com.jetpackduba.gitnuro.git.workspace.StatusType
|
||||||
import org.eclipse.jgit.diff.DiffEntry
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
|
|
||||||
sealed interface DiffEntryType {
|
sealed interface DiffType {
|
||||||
class CommitDiff(val diffEntry: DiffEntry) : DiffEntryType {
|
class CommitDiff(val diffEntry: DiffEntry) : DiffType {
|
||||||
override val filePath: String
|
override val filePath: String
|
||||||
get() = diffEntry.filePath
|
get() = diffEntry.filePath
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ sealed interface DiffEntryType {
|
|||||||
get() = diffEntry.toStatusType()
|
get() = diffEntry.toStatusType()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class UncommittedDiff(val statusEntry: StatusEntry) : DiffEntryType {
|
sealed class UncommittedDiff(val statusEntry: StatusEntry) : DiffType {
|
||||||
override val filePath: String
|
override val filePath: String
|
||||||
get() = statusEntry.filePath
|
get() = statusEntry.filePath
|
||||||
|
|
@ -1,17 +1,15 @@
|
|||||||
package com.jetpackduba.gitnuro.git.diff
|
package com.jetpackduba.gitnuro.git.diff
|
||||||
|
|
||||||
import com.jetpackduba.gitnuro.extensions.filePath
|
import com.jetpackduba.gitnuro.extensions.filePath
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.EntryContent
|
import com.jetpackduba.gitnuro.git.EntryContent
|
||||||
import com.jetpackduba.gitnuro.git.submodules.GetSubmodulesUseCase
|
import com.jetpackduba.gitnuro.git.submodules.GetSubmodulesUseCase
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.diff.DiffEntry
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
import org.eclipse.jgit.diff.DiffFormatter
|
|
||||||
import org.eclipse.jgit.dircache.DirCacheIterator
|
import org.eclipse.jgit.dircache.DirCacheIterator
|
||||||
import org.eclipse.jgit.treewalk.FileTreeIterator
|
import org.eclipse.jgit.treewalk.FileTreeIterator
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
import java.io.InvalidObjectException
|
import java.io.InvalidObjectException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -19,41 +17,18 @@ class FormatDiffUseCase @Inject constructor(
|
|||||||
private val formatHunksUseCase: FormatHunksUseCase,
|
private val formatHunksUseCase: FormatHunksUseCase,
|
||||||
private val getDiffContentUseCase: GetDiffContentUseCase,
|
private val getDiffContentUseCase: GetDiffContentUseCase,
|
||||||
private val canGenerateTextDiffUseCase: CanGenerateTextDiffUseCase,
|
private val canGenerateTextDiffUseCase: CanGenerateTextDiffUseCase,
|
||||||
private val getDiffEntryForUncommittedDiffUseCase: GetDiffEntryForUncommittedDiffUseCase,
|
private val getDiffEntryFromDiffTypeUseCase: GetDiffEntryFromDiffTypeUseCase,
|
||||||
private val getSubmodulesUseCase: GetSubmodulesUseCase,
|
private val getSubmodulesUseCase: GetSubmodulesUseCase,
|
||||||
) {
|
) {
|
||||||
suspend operator fun invoke(
|
suspend operator fun invoke(
|
||||||
git: Git,
|
git: Git,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
isDisplayFullFile: Boolean
|
isDisplayFullFile: Boolean
|
||||||
): DiffResult = withContext(Dispatchers.IO) {
|
): DiffResult = withContext(Dispatchers.IO) {
|
||||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
|
||||||
val repository = git.repository
|
val repository = git.repository
|
||||||
val diffEntry: DiffEntry
|
|
||||||
val submodules = getSubmodulesUseCase(git)
|
val submodules = getSubmodulesUseCase(git)
|
||||||
|
|
||||||
DiffFormatter(byteArrayOutputStream).use { formatter ->
|
val diffEntry = getDiffEntryFromDiffTypeUseCase(git, diffType)
|
||||||
formatter.setRepository(repository)
|
|
||||||
|
|
||||||
val oldTree = DirCacheIterator(repository.readDirCache())
|
|
||||||
val newTree = FileTreeIterator(repository)
|
|
||||||
|
|
||||||
if (diffEntryType is DiffEntryType.UnstagedDiff)
|
|
||||||
formatter.scan(oldTree, newTree)
|
|
||||||
|
|
||||||
diffEntry = when (diffEntryType) {
|
|
||||||
is DiffEntryType.CommitDiff -> {
|
|
||||||
diffEntryType.diffEntry
|
|
||||||
}
|
|
||||||
|
|
||||||
is DiffEntryType.UncommittedDiff -> {
|
|
||||||
getDiffEntryForUncommittedDiffUseCase(git, diffEntryType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
formatter.format(diffEntry)
|
|
||||||
formatter.flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
var diffResult: DiffResult
|
var diffResult: DiffResult
|
||||||
val submoduleStatus = submodules[diffEntry.filePath]
|
val submoduleStatus = submodules[diffEntry.filePath]
|
||||||
@ -64,7 +39,7 @@ class FormatDiffUseCase @Inject constructor(
|
|||||||
val oldTree: DirCacheIterator?
|
val oldTree: DirCacheIterator?
|
||||||
val newTree: FileTreeIterator?
|
val newTree: FileTreeIterator?
|
||||||
|
|
||||||
if (diffEntryType is DiffEntryType.UnstagedDiff) {
|
if (diffType is DiffType.UnstagedDiff) {
|
||||||
oldTree = DirCacheIterator(repository.readDirCache())
|
oldTree = DirCacheIterator(repository.readDirCache())
|
||||||
newTree = FileTreeIterator(repository)
|
newTree = FileTreeIterator(repository)
|
||||||
} else {
|
} else {
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
package com.jetpackduba.gitnuro.git.diff
|
||||||
|
|
||||||
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
|
import org.eclipse.jgit.diff.DiffFormatter
|
||||||
|
import org.eclipse.jgit.dircache.DirCacheIterator
|
||||||
|
import org.eclipse.jgit.treewalk.FileTreeIterator
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetDiffEntryFromDiffTypeUseCase @Inject constructor(
|
||||||
|
private val getDiffEntryFromStatusEntryUseCase: GetDiffEntryFromStatusEntryUseCase,
|
||||||
|
) {
|
||||||
|
suspend operator fun invoke(git: Git, diffType: DiffType): DiffEntry {
|
||||||
|
val repository = git.repository
|
||||||
|
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||||
|
|
||||||
|
return DiffFormatter(byteArrayOutputStream).use { formatter ->
|
||||||
|
formatter.setRepository(repository)
|
||||||
|
|
||||||
|
val oldTree = DirCacheIterator(repository.readDirCache())
|
||||||
|
val newTree = FileTreeIterator(repository)
|
||||||
|
|
||||||
|
if (diffType is DiffType.UnstagedDiff)
|
||||||
|
formatter.scan(oldTree, newTree)
|
||||||
|
|
||||||
|
val diffEntry = when (diffType) {
|
||||||
|
is DiffType.CommitDiff -> {
|
||||||
|
diffType.diffEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
is DiffType.UncommittedDiff -> {
|
||||||
|
getDiffEntryFromStatusEntryUseCase(git, diffType is DiffType.StagedDiff, diffType.statusEntry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter.format(diffEntry)
|
||||||
|
formatter.flush()
|
||||||
|
|
||||||
|
diffEntry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,9 +2,9 @@ package com.jetpackduba.gitnuro.git.diff
|
|||||||
|
|
||||||
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
||||||
import com.jetpackduba.gitnuro.extensions.isMerging
|
import com.jetpackduba.gitnuro.extensions.isMerging
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
|
||||||
import com.jetpackduba.gitnuro.git.branches.GetCurrentBranchUseCase
|
import com.jetpackduba.gitnuro.git.branches.GetCurrentBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.git.repository.GetRepositoryStateUseCase
|
import com.jetpackduba.gitnuro.git.repository.GetRepositoryStateUseCase
|
||||||
|
import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
@ -12,25 +12,24 @@ import org.eclipse.jgit.treewalk.EmptyTreeIterator
|
|||||||
import org.eclipse.jgit.treewalk.filter.PathFilter
|
import org.eclipse.jgit.treewalk.filter.PathFilter
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class GetDiffEntryForUncommittedDiffUseCase @Inject constructor(
|
class GetDiffEntryFromStatusEntryUseCase @Inject constructor(
|
||||||
private val getRepositoryStateUseCase: GetRepositoryStateUseCase,
|
private val getRepositoryStateUseCase: GetRepositoryStateUseCase,
|
||||||
private val getCurrentBranchUseCase: GetCurrentBranchUseCase,
|
private val getCurrentBranchUseCase: GetCurrentBranchUseCase,
|
||||||
) {
|
) {
|
||||||
suspend operator fun invoke(
|
suspend operator fun invoke(
|
||||||
git: Git,
|
git: Git,
|
||||||
diffEntryType: DiffEntryType.UncommittedDiff,
|
isCached: Boolean,
|
||||||
|
statusEntry: StatusEntry,
|
||||||
) = withContext(Dispatchers.IO) {
|
) = withContext(Dispatchers.IO) {
|
||||||
val statusEntry = diffEntryType.statusEntry
|
|
||||||
val cached = diffEntryType is DiffEntryType.StagedDiff
|
|
||||||
val firstDiffEntry = git.diff()
|
val firstDiffEntry = git.diff()
|
||||||
.setPathFilter(PathFilter.create(statusEntry.filePath))
|
.setPathFilter(PathFilter.create(statusEntry.filePath))
|
||||||
.setCached(cached).apply {
|
.setCached(isCached).apply {
|
||||||
val repositoryState = getRepositoryStateUseCase(git)
|
val repositoryState = getRepositoryStateUseCase(git)
|
||||||
if (
|
if (
|
||||||
getCurrentBranchUseCase(git) == null &&
|
getCurrentBranchUseCase(git) == null &&
|
||||||
!repositoryState.isMerging &&
|
!repositoryState.isMerging &&
|
||||||
!repositoryState.isRebasing &&
|
!repositoryState.isRebasing &&
|
||||||
cached
|
isCached
|
||||||
) {
|
) {
|
||||||
setOldTree(EmptyTreeIterator()) // Required if the repository is empty
|
setOldTree(EmptyTreeIterator()) // Required if the repository is empty
|
||||||
}
|
}
|
@ -23,9 +23,7 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.jetpackduba.gitnuro.AppIcons
|
import com.jetpackduba.gitnuro.AppIcons
|
||||||
import com.jetpackduba.gitnuro.extensions.*
|
import com.jetpackduba.gitnuro.extensions.*
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.theme.backgroundSelected
|
|
||||||
import com.jetpackduba.gitnuro.theme.linesHeight
|
|
||||||
import com.jetpackduba.gitnuro.theme.onBackgroundSecondary
|
import com.jetpackduba.gitnuro.theme.onBackgroundSecondary
|
||||||
import com.jetpackduba.gitnuro.theme.tertiarySurface
|
import com.jetpackduba.gitnuro.theme.tertiarySurface
|
||||||
import com.jetpackduba.gitnuro.ui.components.*
|
import com.jetpackduba.gitnuro.ui.components.*
|
||||||
@ -45,7 +43,7 @@ fun CommitChanges(
|
|||||||
commitChangesViewModel: CommitChangesViewModel,
|
commitChangesViewModel: CommitChangesViewModel,
|
||||||
selectedItem: SelectedItem.CommitBasedItem,
|
selectedItem: SelectedItem.CommitBasedItem,
|
||||||
onDiffSelected: (DiffEntry) -> Unit,
|
onDiffSelected: (DiffEntry) -> Unit,
|
||||||
diffSelected: DiffEntryType?,
|
diffSelected: DiffType?,
|
||||||
onBlame: (String) -> Unit,
|
onBlame: (String) -> Unit,
|
||||||
onHistory: (String) -> Unit,
|
onHistory: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -97,7 +95,7 @@ fun CommitChanges(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun CommitChangesView(
|
private fun CommitChangesView(
|
||||||
commitChangesStatus: CommitChangesStateUi.Loaded,
|
commitChangesStatus: CommitChangesStateUi.Loaded,
|
||||||
diffSelected: DiffEntryType?,
|
diffSelected: DiffType?,
|
||||||
changesListScroll: LazyListState,
|
changesListScroll: LazyListState,
|
||||||
textScroll: ScrollState,
|
textScroll: ScrollState,
|
||||||
showSearch: Boolean,
|
showSearch: Boolean,
|
||||||
@ -380,7 +378,7 @@ fun Author(
|
|||||||
@Composable
|
@Composable
|
||||||
fun ListCommitLogChanges(
|
fun ListCommitLogChanges(
|
||||||
diffEntries: List<DiffEntry>,
|
diffEntries: List<DiffEntry>,
|
||||||
diffSelected: DiffEntryType?,
|
diffSelected: DiffType?,
|
||||||
changesListScroll: LazyListState,
|
changesListScroll: LazyListState,
|
||||||
onDiffSelected: (DiffEntry) -> Unit,
|
onDiffSelected: (DiffEntry) -> Unit,
|
||||||
onGenerateContextMenu: (DiffEntry) -> List<ContextMenuElement>,
|
onGenerateContextMenu: (DiffEntry) -> List<ContextMenuElement>,
|
||||||
@ -396,7 +394,7 @@ fun ListCommitLogChanges(
|
|||||||
iconColor = diffEntry.iconColor,
|
iconColor = diffEntry.iconColor,
|
||||||
parentDirectoryPath = diffEntry.parentDirectoryPath,
|
parentDirectoryPath = diffEntry.parentDirectoryPath,
|
||||||
fileName = diffEntry.fileName,
|
fileName = diffEntry.fileName,
|
||||||
isSelected = diffSelected is DiffEntryType.CommitDiff && diffSelected.diffEntry == diffEntry,
|
isSelected = diffSelected is DiffType.CommitDiff && diffSelected.diffEntry == diffEntry,
|
||||||
onClick = { onDiffSelected(diffEntry) },
|
onClick = { onDiffSelected(diffEntry) },
|
||||||
onDoubleClick = {},
|
onDoubleClick = {},
|
||||||
onGenerateContextMenu = { onGenerateContextMenu(diffEntry) },
|
onGenerateContextMenu = { onGenerateContextMenu(diffEntry) },
|
||||||
@ -409,7 +407,7 @@ fun ListCommitLogChanges(
|
|||||||
@Composable
|
@Composable
|
||||||
fun TreeCommitLogChanges(
|
fun TreeCommitLogChanges(
|
||||||
treeItems: List<TreeItem<DiffEntry>>,
|
treeItems: List<TreeItem<DiffEntry>>,
|
||||||
diffSelected: DiffEntryType?,
|
diffSelected: DiffType?,
|
||||||
changesListScroll: LazyListState,
|
changesListScroll: LazyListState,
|
||||||
onDiffSelected: (DiffEntry) -> Unit,
|
onDiffSelected: (DiffEntry) -> Unit,
|
||||||
onDirectoryClicked: (TreeItem.Dir) -> Unit,
|
onDirectoryClicked: (TreeItem.Dir) -> Unit,
|
||||||
@ -424,7 +422,7 @@ fun TreeCommitLogChanges(
|
|||||||
CommitTreeItemEntry(
|
CommitTreeItemEntry(
|
||||||
entry = entry,
|
entry = entry,
|
||||||
isSelected = entry is TreeItem.File &&
|
isSelected = entry is TreeItem.File &&
|
||||||
diffSelected is DiffEntryType.CommitDiff &&
|
diffSelected is DiffType.CommitDiff &&
|
||||||
diffSelected.diffEntry == entry.data,
|
diffSelected.diffEntry == entry.data,
|
||||||
onFileClick = { onDiffSelected(it) },
|
onFileClick = { onDiffSelected(it) },
|
||||||
onDirectoryClick = { onDirectoryClicked(it) },
|
onDirectoryClick = { onDirectoryClicked(it) },
|
||||||
|
@ -170,7 +170,7 @@ fun HistoryContentLoaded(
|
|||||||
when (val diffResult = viewDiffResult.diffResult) {
|
when (val diffResult = viewDiffResult.diffResult) {
|
||||||
is DiffResult.Text -> {
|
is DiffResult.Text -> {
|
||||||
HunkUnifiedTextDiff(
|
HunkUnifiedTextDiff(
|
||||||
diffEntryType = viewDiffResult.diffEntryType,
|
diffType = viewDiffResult.diffType,
|
||||||
scrollState = scrollState,
|
scrollState = scrollState,
|
||||||
diffResult = diffResult,
|
diffResult = diffResult,
|
||||||
onUnstageHunk = { _, _ -> },
|
onUnstageHunk = { _, _ -> },
|
||||||
@ -183,7 +183,7 @@ fun HistoryContentLoaded(
|
|||||||
|
|
||||||
is DiffResult.TextSplit -> {
|
is DiffResult.TextSplit -> {
|
||||||
HunkSplitTextDiff(
|
HunkSplitTextDiff(
|
||||||
diffEntryType = viewDiffResult.diffEntryType,
|
diffType = viewDiffResult.diffType,
|
||||||
scrollState = scrollState,
|
scrollState = scrollState,
|
||||||
diffResult = diffResult,
|
diffResult = diffResult,
|
||||||
onUnstageHunk = { _, _ -> },
|
onUnstageHunk = { _, _ -> },
|
||||||
|
@ -17,7 +17,7 @@ import androidx.compose.ui.platform.LocalDensity
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.jetpackduba.gitnuro.AppConstants
|
import com.jetpackduba.gitnuro.AppConstants
|
||||||
import com.jetpackduba.gitnuro.extensions.handMouseClickable
|
import com.jetpackduba.gitnuro.extensions.handMouseClickable
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.rebase.RebaseInteractiveState
|
import com.jetpackduba.gitnuro.git.rebase.RebaseInteractiveState
|
||||||
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||||
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
import com.jetpackduba.gitnuro.keybindings.matchesBinding
|
||||||
@ -226,7 +226,7 @@ private fun BottomInfoBar(
|
|||||||
@Composable
|
@Composable
|
||||||
fun RepoContent(
|
fun RepoContent(
|
||||||
tabViewModel: TabViewModel,
|
tabViewModel: TabViewModel,
|
||||||
diffSelected: DiffEntryType?,
|
diffSelected: DiffType?,
|
||||||
selectedItem: SelectedItem,
|
selectedItem: SelectedItem,
|
||||||
repositoryState: RepositoryState,
|
repositoryState: RepositoryState,
|
||||||
blameState: BlameState,
|
blameState: BlameState,
|
||||||
@ -257,7 +257,7 @@ fun RepoContent(
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainContentView(
|
fun MainContentView(
|
||||||
tabViewModel: TabViewModel,
|
tabViewModel: TabViewModel,
|
||||||
diffSelected: DiffEntryType?,
|
diffSelected: DiffType?,
|
||||||
selectedItem: SelectedItem,
|
selectedItem: SelectedItem,
|
||||||
repositoryState: RepositoryState,
|
repositoryState: RepositoryState,
|
||||||
blameState: BlameState,
|
blameState: BlameState,
|
||||||
@ -348,9 +348,9 @@ fun MainContentView(
|
|||||||
|
|
||||||
tabViewModel.newDiffSelected = if (diffEntry != null) {
|
tabViewModel.newDiffSelected = if (diffEntry != null) {
|
||||||
if (repositoryState == RepositoryState.SAFE)
|
if (repositoryState == RepositoryState.SAFE)
|
||||||
DiffEntryType.SafeStagedDiff(diffEntry)
|
DiffType.SafeStagedDiff(diffEntry)
|
||||||
else
|
else
|
||||||
DiffEntryType.UnsafeStagedDiff(diffEntry)
|
DiffType.UnsafeStagedDiff(diffEntry)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@ -359,9 +359,9 @@ fun MainContentView(
|
|||||||
tabViewModel.minimizeBlame()
|
tabViewModel.minimizeBlame()
|
||||||
|
|
||||||
if (repositoryState == RepositoryState.SAFE)
|
if (repositoryState == RepositoryState.SAFE)
|
||||||
tabViewModel.newDiffSelected = DiffEntryType.SafeUnstagedDiff(diffEntry)
|
tabViewModel.newDiffSelected = DiffType.SafeUnstagedDiff(diffEntry)
|
||||||
else
|
else
|
||||||
tabViewModel.newDiffSelected = DiffEntryType.UnsafeUnstagedDiff(diffEntry)
|
tabViewModel.newDiffSelected = DiffType.UnsafeUnstagedDiff(diffEntry)
|
||||||
},
|
},
|
||||||
onBlameFile = { tabViewModel.blameFile(it) },
|
onBlameFile = { tabViewModel.blameFile(it) },
|
||||||
onHistoryFile = { tabViewModel.fileHistory(it) }
|
onHistoryFile = { tabViewModel.fileHistory(it) }
|
||||||
@ -375,7 +375,7 @@ fun MainContentView(
|
|||||||
diffSelected = diffSelected,
|
diffSelected = diffSelected,
|
||||||
onDiffSelected = { diffEntry ->
|
onDiffSelected = { diffEntry ->
|
||||||
tabViewModel.minimizeBlame()
|
tabViewModel.minimizeBlame()
|
||||||
tabViewModel.newDiffSelected = DiffEntryType.CommitDiff(diffEntry)
|
tabViewModel.newDiffSelected = DiffType.CommitDiff(diffEntry)
|
||||||
},
|
},
|
||||||
onBlame = { tabViewModel.blameFile(it) },
|
onBlame = { tabViewModel.blameFile(it) },
|
||||||
onHistory = { tabViewModel.fileHistory(it) },
|
onHistory = { tabViewModel.fileHistory(it) },
|
||||||
|
@ -31,7 +31,7 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.jetpackduba.gitnuro.AppIcons
|
import com.jetpackduba.gitnuro.AppIcons
|
||||||
import com.jetpackduba.gitnuro.extensions.*
|
import com.jetpackduba.gitnuro.extensions.*
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.rebase.RebaseInteractiveState
|
import com.jetpackduba.gitnuro.git.rebase.RebaseInteractiveState
|
||||||
import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
import com.jetpackduba.gitnuro.git.workspace.StatusEntry
|
||||||
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
import com.jetpackduba.gitnuro.keybindings.KeybindingOption
|
||||||
@ -54,7 +54,7 @@ import org.eclipse.jgit.lib.RepositoryState
|
|||||||
@Composable
|
@Composable
|
||||||
fun UncommittedChanges(
|
fun UncommittedChanges(
|
||||||
statusViewModel: StatusViewModel,
|
statusViewModel: StatusViewModel,
|
||||||
selectedEntryType: DiffEntryType?,
|
selectedEntryType: DiffType?,
|
||||||
repositoryState: RepositoryState,
|
repositoryState: RepositoryState,
|
||||||
onStagedDiffEntrySelected: (StatusEntry?) -> Unit,
|
onStagedDiffEntrySelected: (StatusEntry?) -> Unit,
|
||||||
onUnstagedDiffEntrySelected: (StatusEntry) -> Unit,
|
onUnstagedDiffEntrySelected: (StatusEntry) -> Unit,
|
||||||
@ -321,7 +321,7 @@ fun ColumnScope.StagedView(
|
|||||||
showSearchUnstaged: Boolean,
|
showSearchUnstaged: Boolean,
|
||||||
searchFilterUnstaged: TextFieldValue,
|
searchFilterUnstaged: TextFieldValue,
|
||||||
stagedListState: LazyListState,
|
stagedListState: LazyListState,
|
||||||
selectedEntryType: DiffEntryType?,
|
selectedEntryType: DiffType?,
|
||||||
onSearchFilterToggled: (Boolean) -> Unit,
|
onSearchFilterToggled: (Boolean) -> Unit,
|
||||||
onDiffEntryOptionSelected: (StatusEntry) -> Unit,
|
onDiffEntryOptionSelected: (StatusEntry) -> Unit,
|
||||||
onDiffEntrySelected: (StatusEntry) -> Unit,
|
onDiffEntrySelected: (StatusEntry) -> Unit,
|
||||||
@ -369,7 +369,7 @@ fun ColumnScope.StagedView(
|
|||||||
onTreeDirectoryAction = onTreeDirectoryAction,
|
onTreeDirectoryAction = onTreeDirectoryAction,
|
||||||
onTreeEntries = { it.staged },
|
onTreeEntries = { it.staged },
|
||||||
onListEntries = { it.staged },
|
onListEntries = { it.staged },
|
||||||
onGetSelectedEntry = { if (selectedEntryType is DiffEntryType.StagedDiff) selectedEntryType else null }
|
onGetSelectedEntry = { if (selectedEntryType is DiffType.StagedDiff) selectedEntryType else null },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ fun ColumnScope.UnstagedView(
|
|||||||
showSearchUnstaged: Boolean,
|
showSearchUnstaged: Boolean,
|
||||||
searchFilterUnstaged: TextFieldValue,
|
searchFilterUnstaged: TextFieldValue,
|
||||||
unstagedListState: LazyListState,
|
unstagedListState: LazyListState,
|
||||||
selectedEntryType: DiffEntryType?,
|
selectedEntryType: DiffType?,
|
||||||
onSearchFilterToggled: (Boolean) -> Unit,
|
onSearchFilterToggled: (Boolean) -> Unit,
|
||||||
onDiffEntryOptionSelected: (StatusEntry) -> Unit,
|
onDiffEntryOptionSelected: (StatusEntry) -> Unit,
|
||||||
onDiffEntrySelected: (StatusEntry) -> Unit,
|
onDiffEntrySelected: (StatusEntry) -> Unit,
|
||||||
@ -427,7 +427,7 @@ fun ColumnScope.UnstagedView(
|
|||||||
onTreeDirectoryAction = onTreeDirectoryAction,
|
onTreeDirectoryAction = onTreeDirectoryAction,
|
||||||
onTreeEntries = { it.unstaged },
|
onTreeEntries = { it.unstaged },
|
||||||
onListEntries = { it.unstaged },
|
onListEntries = { it.unstaged },
|
||||||
onGetSelectedEntry = { if (selectedEntryType is DiffEntryType.UnstagedDiff) selectedEntryType else null }
|
onGetSelectedEntry = { if (selectedEntryType is DiffType.UnstagedDiff) selectedEntryType else null },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,7 +444,7 @@ fun ColumnScope.NeutralView(
|
|||||||
showSearchUnstaged: Boolean,
|
showSearchUnstaged: Boolean,
|
||||||
searchFilterUnstaged: TextFieldValue,
|
searchFilterUnstaged: TextFieldValue,
|
||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
selectedEntryType: DiffEntryType?,
|
selectedEntryType: DiffType?,
|
||||||
onTreeEntries: (StageStateUi.TreeLoaded) -> List<TreeItem<StatusEntry>>,
|
onTreeEntries: (StageStateUi.TreeLoaded) -> List<TreeItem<StatusEntry>>,
|
||||||
onListEntries: (StageStateUi.ListLoaded) -> List<StatusEntry>,
|
onListEntries: (StageStateUi.ListLoaded) -> List<StatusEntry>,
|
||||||
onSearchFilterToggled: (Boolean) -> Unit,
|
onSearchFilterToggled: (Boolean) -> Unit,
|
||||||
@ -459,7 +459,7 @@ fun ColumnScope.NeutralView(
|
|||||||
onAlternateShowAsTree: () -> Unit,
|
onAlternateShowAsTree: () -> Unit,
|
||||||
onTreeDirectoryClicked: (String) -> Unit,
|
onTreeDirectoryClicked: (String) -> Unit,
|
||||||
onTreeDirectoryAction: (String) -> Unit,
|
onTreeDirectoryAction: (String) -> Unit,
|
||||||
onGetSelectedEntry: () -> DiffEntryType?,
|
onGetSelectedEntry: () -> DiffType?,
|
||||||
) {
|
) {
|
||||||
val modifier = Modifier
|
val modifier = Modifier
|
||||||
.weight(5f)
|
.weight(5f)
|
||||||
@ -495,7 +495,7 @@ fun ColumnScope.NeutralView(
|
|||||||
onAllAction = onAllAction,
|
onAllAction = onAllAction,
|
||||||
onTreeDirectoryClicked = { onTreeDirectoryClicked(it.fullPath) },
|
onTreeDirectoryClicked = { onTreeDirectoryClicked(it.fullPath) },
|
||||||
allActionTitle = allActionTitle,
|
allActionTitle = allActionTitle,
|
||||||
selectedEntryType = if (selectedEntryType is DiffEntryType.UnstagedDiff) selectedEntryType else null,
|
selectedEntryType = if (selectedEntryType is DiffType.UnstagedDiff) selectedEntryType else null,
|
||||||
onAlternateShowAsTree = onAlternateShowAsTree,
|
onAlternateShowAsTree = onAlternateShowAsTree,
|
||||||
onGenerateDirectoryContextMenu = { dir ->
|
onGenerateDirectoryContextMenu = { dir ->
|
||||||
statusDirEntriesContextMenuItems(
|
statusDirEntriesContextMenuItems(
|
||||||
@ -798,7 +798,7 @@ private fun EntriesList(
|
|||||||
onAllAction: () -> Unit,
|
onAllAction: () -> Unit,
|
||||||
onAlternateShowAsTree: () -> Unit,
|
onAlternateShowAsTree: () -> Unit,
|
||||||
allActionTitle: String,
|
allActionTitle: String,
|
||||||
selectedEntryType: DiffEntryType?,
|
selectedEntryType: DiffType?,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
@ -827,7 +827,7 @@ private fun EntriesList(
|
|||||||
) {
|
) {
|
||||||
items(statusEntries, key = { it.filePath }) { statusEntry ->
|
items(statusEntries, key = { it.filePath }) { statusEntry ->
|
||||||
val isEntrySelected = selectedEntryType != null &&
|
val isEntrySelected = selectedEntryType != null &&
|
||||||
selectedEntryType is DiffEntryType.UncommittedDiff && // Added for smartcast
|
selectedEntryType is DiffType.UncommittedDiff && // Added for smartcast
|
||||||
selectedEntryType.statusEntry == statusEntry
|
selectedEntryType.statusEntry == statusEntry
|
||||||
UncommittedFileEntry(
|
UncommittedFileEntry(
|
||||||
statusEntry = statusEntry,
|
statusEntry = statusEntry,
|
||||||
@ -870,7 +870,7 @@ private fun TreeEntriesList(
|
|||||||
onAlternateShowAsTree: () -> Unit,
|
onAlternateShowAsTree: () -> Unit,
|
||||||
onTreeDirectoryClicked: (TreeItem.Dir) -> Unit,
|
onTreeDirectoryClicked: (TreeItem.Dir) -> Unit,
|
||||||
allActionTitle: String,
|
allActionTitle: String,
|
||||||
selectedEntryType: DiffEntryType?,
|
selectedEntryType: DiffType?,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
@ -899,7 +899,7 @@ private fun TreeEntriesList(
|
|||||||
items(statusEntries, key = { it.fullPath }) { treeEntry ->
|
items(statusEntries, key = { it.fullPath }) { treeEntry ->
|
||||||
val isEntrySelected = treeEntry is TreeItem.File<StatusEntry> &&
|
val isEntrySelected = treeEntry is TreeItem.File<StatusEntry> &&
|
||||||
selectedEntryType != null &&
|
selectedEntryType != null &&
|
||||||
selectedEntryType is DiffEntryType.UncommittedDiff && // Added for smartcast
|
selectedEntryType is DiffType.UncommittedDiff && // Added for smartcast
|
||||||
selectedEntryType.statusEntry == treeEntry.data
|
selectedEntryType.statusEntry == treeEntry.data
|
||||||
|
|
||||||
UncommittedTreeItemEntry(
|
UncommittedTreeItemEntry(
|
||||||
|
@ -38,7 +38,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.jetpackduba.gitnuro.AppIcons
|
import com.jetpackduba.gitnuro.AppIcons
|
||||||
import com.jetpackduba.gitnuro.extensions.*
|
import com.jetpackduba.gitnuro.extensions.*
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.EntryContent
|
import com.jetpackduba.gitnuro.git.EntryContent
|
||||||
import com.jetpackduba.gitnuro.git.animatedImages
|
import com.jetpackduba.gitnuro.git.animatedImages
|
||||||
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
||||||
@ -87,7 +87,7 @@ fun Diff(
|
|||||||
onCloseDiffView: () -> Unit,
|
onCloseDiffView: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val diffResultState = diffViewModel.diffResult.collectAsState()
|
val diffResultState = diffViewModel.diffResult.collectAsState()
|
||||||
val diffType by diffViewModel.diffTypeFlow.collectAsState()
|
val textDiffType by diffViewModel.diffTypeFlow.collectAsState()
|
||||||
val isDisplayFullFile by diffViewModel.isDisplayFullFile.collectAsState()
|
val isDisplayFullFile by diffViewModel.isDisplayFullFile.collectAsState()
|
||||||
val viewDiffResult = diffResultState.value ?: return
|
val viewDiffResult = diffResultState.value ?: return
|
||||||
val focusRequester = remember { FocusRequester() }
|
val focusRequester = remember { FocusRequester() }
|
||||||
@ -112,15 +112,15 @@ fun Diff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is ViewDiffResult.Loaded -> {
|
is ViewDiffResult.Loaded -> {
|
||||||
val diffEntryType = viewDiffResult.diffEntryType
|
val diffType = viewDiffResult.diffType
|
||||||
val diffEntry = viewDiffResult.diffResult.diffEntry
|
val diffEntry = viewDiffResult.diffResult.diffEntry
|
||||||
val diffResult = viewDiffResult.diffResult
|
val diffResult = viewDiffResult.diffResult
|
||||||
|
|
||||||
DiffHeader(
|
DiffHeader(
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
diffEntry = diffEntry,
|
diffEntry = diffEntry,
|
||||||
onCloseDiffView = onCloseDiffView,
|
onCloseDiffView = onCloseDiffView,
|
||||||
diffType = diffType,
|
textDiffType = textDiffType,
|
||||||
isTextDiff = diffResult is DiffResult.TextDiff,
|
isTextDiff = diffResult is DiffResult.TextDiff,
|
||||||
isDisplayFullFile = isDisplayFullFile,
|
isDisplayFullFile = isDisplayFullFile,
|
||||||
onStageFile = { diffViewModel.stageFile(it) },
|
onStageFile = { diffViewModel.stageFile(it) },
|
||||||
@ -133,7 +133,7 @@ fun Diff(
|
|||||||
|
|
||||||
when (diffResult) {
|
when (diffResult) {
|
||||||
is DiffResult.TextSplit -> HunkSplitTextDiff(
|
is DiffResult.TextSplit -> HunkSplitTextDiff(
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
scrollState = scrollState,
|
scrollState = scrollState,
|
||||||
diffResult = diffResult,
|
diffResult = diffResult,
|
||||||
onUnstageHunk = { entry, hunk ->
|
onUnstageHunk = { entry, hunk ->
|
||||||
@ -146,9 +146,9 @@ fun Diff(
|
|||||||
diffViewModel.resetHunk(entry, hunk)
|
diffViewModel.resetHunk(entry, hunk)
|
||||||
},
|
},
|
||||||
onUnStageLine = { entry, hunk, line ->
|
onUnStageLine = { entry, hunk, line ->
|
||||||
if (diffEntryType is DiffEntryType.UnstagedDiff)
|
if (diffType is DiffType.UnstagedDiff)
|
||||||
diffViewModel.stageHunkLine(entry, hunk, line)
|
diffViewModel.stageHunkLine(entry, hunk, line)
|
||||||
else if (diffEntryType is DiffEntryType.StagedDiff)
|
else if (diffType is DiffType.StagedDiff)
|
||||||
diffViewModel.unstageHunkLine(entry, hunk, line)
|
diffViewModel.unstageHunkLine(entry, hunk, line)
|
||||||
},
|
},
|
||||||
onDiscardLine = { entry, hunk, line ->
|
onDiscardLine = { entry, hunk, line ->
|
||||||
@ -157,7 +157,7 @@ fun Diff(
|
|||||||
)
|
)
|
||||||
|
|
||||||
is DiffResult.Text -> HunkUnifiedTextDiff(
|
is DiffResult.Text -> HunkUnifiedTextDiff(
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
scrollState = scrollState,
|
scrollState = scrollState,
|
||||||
diffResult = diffResult,
|
diffResult = diffResult,
|
||||||
onUnstageHunk = { entry, hunk ->
|
onUnstageHunk = { entry, hunk ->
|
||||||
@ -170,9 +170,9 @@ fun Diff(
|
|||||||
diffViewModel.resetHunk(entry, hunk)
|
diffViewModel.resetHunk(entry, hunk)
|
||||||
},
|
},
|
||||||
onUnStageLine = { entry, hunk, line ->
|
onUnStageLine = { entry, hunk, line ->
|
||||||
if (diffEntryType is DiffEntryType.UnstagedDiff)
|
if (diffType is DiffType.UnstagedDiff)
|
||||||
diffViewModel.stageHunkLine(entry, hunk, line)
|
diffViewModel.stageHunkLine(entry, hunk, line)
|
||||||
else if (diffEntryType is DiffEntryType.StagedDiff)
|
else if (diffType is DiffType.StagedDiff)
|
||||||
diffViewModel.unstageHunkLine(entry, hunk, line)
|
diffViewModel.unstageHunkLine(entry, hunk, line)
|
||||||
},
|
},
|
||||||
onDiscardLine = { entry, hunk, line ->
|
onDiscardLine = { entry, hunk, line ->
|
||||||
@ -427,7 +427,7 @@ fun BinaryDiff() {
|
|||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HunkUnifiedTextDiff(
|
fun HunkUnifiedTextDiff(
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
scrollState: LazyListState,
|
scrollState: LazyListState,
|
||||||
diffResult: DiffResult.Text,
|
diffResult: DiffResult.Text,
|
||||||
onUnstageHunk: (DiffEntry, Hunk) -> Unit,
|
onUnstageHunk: (DiffEntry, Hunk) -> Unit,
|
||||||
@ -455,7 +455,7 @@ fun HunkUnifiedTextDiff(
|
|||||||
DisableSelection {
|
DisableSelection {
|
||||||
HunkHeader(
|
HunkHeader(
|
||||||
header = hunk.header,
|
header = hunk.header,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onUnstageHunk = { onUnstageHunk(diffResult.diffEntry, hunk) },
|
onUnstageHunk = { onUnstageHunk(diffResult.diffEntry, hunk) },
|
||||||
onStageHunk = { onStageHunk(diffResult.diffEntry, hunk) },
|
onStageHunk = { onStageHunk(diffResult.diffEntry, hunk) },
|
||||||
onResetHunk = { onResetHunk(diffResult.diffEntry, hunk) },
|
onResetHunk = { onResetHunk(diffResult.diffEntry, hunk) },
|
||||||
@ -471,14 +471,14 @@ fun HunkUnifiedTextDiff(
|
|||||||
items(hunk.lines) { line ->
|
items(hunk.lines) { line ->
|
||||||
DiffContextMenu(
|
DiffContextMenu(
|
||||||
selectedText = selectedText,
|
selectedText = selectedText,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onDiscardLine = { onDiscardLine(diffResult.diffEntry, hunk, line) },
|
onDiscardLine = { onDiscardLine(diffResult.diffEntry, hunk, line) },
|
||||||
line = line,
|
line = line,
|
||||||
) {
|
) {
|
||||||
DiffLine(
|
DiffLine(
|
||||||
highestLineNumberLength,
|
highestLineNumberLength,
|
||||||
line,
|
line,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onActionTriggered = {
|
onActionTriggered = {
|
||||||
onUnStageLine(
|
onUnStageLine(
|
||||||
diffResult.diffEntry,
|
diffResult.diffEntry,
|
||||||
@ -498,7 +498,7 @@ fun HunkUnifiedTextDiff(
|
|||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HunkSplitTextDiff(
|
fun HunkSplitTextDiff(
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
scrollState: LazyListState,
|
scrollState: LazyListState,
|
||||||
diffResult: DiffResult.TextSplit,
|
diffResult: DiffResult.TextSplit,
|
||||||
onUnstageHunk: (DiffEntry, Hunk) -> Unit,
|
onUnstageHunk: (DiffEntry, Hunk) -> Unit,
|
||||||
@ -532,7 +532,7 @@ fun HunkSplitTextDiff(
|
|||||||
DisableSelection {
|
DisableSelection {
|
||||||
HunkHeader(
|
HunkHeader(
|
||||||
header = splitHunk.sourceHunk.header,
|
header = splitHunk.sourceHunk.header,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onUnstageHunk = { onUnstageHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
onUnstageHunk = { onUnstageHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
||||||
onStageHunk = { onStageHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
onStageHunk = { onStageHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
||||||
onResetHunk = { onResetHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
onResetHunk = { onResetHunk(diffResult.diffEntry, splitHunk.sourceHunk) },
|
||||||
@ -551,7 +551,7 @@ fun HunkSplitTextDiff(
|
|||||||
oldLine = linesPair.first,
|
oldLine = linesPair.first,
|
||||||
newLine = linesPair.second,
|
newLine = linesPair.second,
|
||||||
selectableSide = selectableSide,
|
selectableSide = selectableSide,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
selectedText = selectedText,
|
selectedText = selectedText,
|
||||||
onActionTriggered = { line ->
|
onActionTriggered = { line ->
|
||||||
onUnStageLine(diffResult.diffEntry, splitHunk.sourceHunk, line)
|
onUnStageLine(diffResult.diffEntry, splitHunk.sourceHunk, line)
|
||||||
@ -586,7 +586,7 @@ fun SplitDiffLine(
|
|||||||
oldLine: Line?,
|
oldLine: Line?,
|
||||||
newLine: Line?,
|
newLine: Line?,
|
||||||
selectableSide: SelectableSide,
|
selectableSide: SelectableSide,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
selectedText: AnnotatedString,
|
selectedText: AnnotatedString,
|
||||||
onChangeSelectableSide: (SelectableSide) -> Unit,
|
onChangeSelectableSide: (SelectableSide) -> Unit,
|
||||||
onActionTriggered: (Line) -> Unit,
|
onActionTriggered: (Line) -> Unit,
|
||||||
@ -606,7 +606,7 @@ fun SplitDiffLine(
|
|||||||
currentSelectableSide = selectableSide,
|
currentSelectableSide = selectableSide,
|
||||||
lineSelectableSide = SelectableSide.OLD,
|
lineSelectableSide = SelectableSide.OLD,
|
||||||
onChangeSelectableSide = onChangeSelectableSide,
|
onChangeSelectableSide = onChangeSelectableSide,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onActionTriggered = { if (oldLine != null) onActionTriggered(oldLine) },
|
onActionTriggered = { if (oldLine != null) onActionTriggered(oldLine) },
|
||||||
selectedText = selectedText,
|
selectedText = selectedText,
|
||||||
onDiscardLine = onDiscardLine,
|
onDiscardLine = onDiscardLine,
|
||||||
@ -628,7 +628,7 @@ fun SplitDiffLine(
|
|||||||
currentSelectableSide = selectableSide,
|
currentSelectableSide = selectableSide,
|
||||||
lineSelectableSide = SelectableSide.NEW,
|
lineSelectableSide = SelectableSide.NEW,
|
||||||
onChangeSelectableSide = onChangeSelectableSide,
|
onChangeSelectableSide = onChangeSelectableSide,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onActionTriggered = { if (newLine != null) onActionTriggered(newLine) },
|
onActionTriggered = { if (newLine != null) onActionTriggered(newLine) },
|
||||||
selectedText = selectedText,
|
selectedText = selectedText,
|
||||||
onDiscardLine = onDiscardLine,
|
onDiscardLine = onDiscardLine,
|
||||||
@ -646,7 +646,7 @@ fun SplitDiffLineSide(
|
|||||||
displayLineNumber: Int,
|
displayLineNumber: Int,
|
||||||
currentSelectableSide: SelectableSide,
|
currentSelectableSide: SelectableSide,
|
||||||
lineSelectableSide: SelectableSide,
|
lineSelectableSide: SelectableSide,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
selectedText: AnnotatedString,
|
selectedText: AnnotatedString,
|
||||||
onChangeSelectableSide: (SelectableSide) -> Unit,
|
onChangeSelectableSide: (SelectableSide) -> Unit,
|
||||||
onActionTriggered: () -> Unit,
|
onActionTriggered: () -> Unit,
|
||||||
@ -692,14 +692,14 @@ fun SplitDiffLineSide(
|
|||||||
DiffContextMenu(
|
DiffContextMenu(
|
||||||
selectedText,
|
selectedText,
|
||||||
line,
|
line,
|
||||||
diffEntryType,
|
diffType,
|
||||||
onDiscardLine = { onDiscardLine(line) },
|
onDiscardLine = { onDiscardLine(line) },
|
||||||
) {
|
) {
|
||||||
SplitDiffLine(
|
SplitDiffLine(
|
||||||
highestLineNumberLength = highestLineNumberLength,
|
highestLineNumberLength = highestLineNumberLength,
|
||||||
line = line,
|
line = line,
|
||||||
lineNumber = displayLineNumber,
|
lineNumber = displayLineNumber,
|
||||||
diffEntryType = diffEntryType,
|
diffType = diffType,
|
||||||
onActionTriggered = onActionTriggered,
|
onActionTriggered = onActionTriggered,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -712,7 +712,7 @@ fun SplitDiffLineSide(
|
|||||||
fun DiffContextMenu(
|
fun DiffContextMenu(
|
||||||
selectedText: AnnotatedString,
|
selectedText: AnnotatedString,
|
||||||
line: Line,
|
line: Line,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
onDiscardLine: () -> Unit,
|
onDiscardLine: () -> Unit,
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
@ -721,8 +721,8 @@ fun DiffContextMenu(
|
|||||||
items = {
|
items = {
|
||||||
if (
|
if (
|
||||||
line.lineType != LineType.CONTEXT &&
|
line.lineType != LineType.CONTEXT &&
|
||||||
diffEntryType is DiffEntryType.UnstagedDiff &&
|
diffType is DiffType.UnstagedDiff &&
|
||||||
diffEntryType.statusType == StatusType.MODIFIED
|
diffType.statusType == StatusType.MODIFIED
|
||||||
) {
|
) {
|
||||||
listOf(
|
listOf(
|
||||||
ContextMenuElement.ContextTextEntry(
|
ContextMenuElement.ContextTextEntry(
|
||||||
@ -750,7 +750,7 @@ enum class SelectableSide {
|
|||||||
@Composable
|
@Composable
|
||||||
fun HunkHeader(
|
fun HunkHeader(
|
||||||
header: String,
|
header: String,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
onUnstageHunk: () -> Unit,
|
onUnstageHunk: () -> Unit,
|
||||||
onStageHunk: () -> Unit,
|
onStageHunk: () -> Unit,
|
||||||
onResetHunk: () -> Unit,
|
onResetHunk: () -> Unit,
|
||||||
@ -772,12 +772,12 @@ fun HunkHeader(
|
|||||||
|
|
||||||
// Hunks options are only visible when repository is a normal state (not during merge/rebase)
|
// Hunks options are only visible when repository is a normal state (not during merge/rebase)
|
||||||
if (
|
if (
|
||||||
(diffEntryType is DiffEntryType.SafeStagedDiff || diffEntryType is DiffEntryType.SafeUnstagedDiff) &&
|
(diffType is DiffType.SafeStagedDiff || diffType is DiffType.SafeUnstagedDiff) &&
|
||||||
diffEntryType.statusType == StatusType.MODIFIED
|
diffType.statusType == StatusType.MODIFIED
|
||||||
) {
|
) {
|
||||||
val buttonText: String
|
val buttonText: String
|
||||||
val color: Color
|
val color: Color
|
||||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
if (diffType is DiffType.StagedDiff) {
|
||||||
buttonText = "Unstage hunk"
|
buttonText = "Unstage hunk"
|
||||||
color = MaterialTheme.colors.error
|
color = MaterialTheme.colors.error
|
||||||
} else {
|
} else {
|
||||||
@ -785,7 +785,7 @@ fun HunkHeader(
|
|||||||
color = MaterialTheme.colors.primary
|
color = MaterialTheme.colors.primary
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diffEntryType is DiffEntryType.UnstagedDiff) {
|
if (diffType is DiffType.UnstagedDiff) {
|
||||||
SecondaryButton(
|
SecondaryButton(
|
||||||
text = "Discard hunk",
|
text = "Discard hunk",
|
||||||
backgroundButton = MaterialTheme.colors.error,
|
backgroundButton = MaterialTheme.colors.error,
|
||||||
@ -800,7 +800,7 @@ fun HunkHeader(
|
|||||||
backgroundButton = color,
|
backgroundButton = color,
|
||||||
modifier = Modifier.padding(horizontal = 16.dp),
|
modifier = Modifier.padding(horizontal = 16.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
if (diffType is DiffType.StagedDiff) {
|
||||||
onUnstageHunk()
|
onUnstageHunk()
|
||||||
} else {
|
} else {
|
||||||
onStageHunk()
|
onStageHunk()
|
||||||
@ -813,9 +813,9 @@ fun HunkHeader(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun DiffHeader(
|
private fun DiffHeader(
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
diffEntry: DiffEntry,
|
diffEntry: DiffEntry,
|
||||||
diffType: TextDiffType,
|
textDiffType: TextDiffType,
|
||||||
isDisplayFullFile: Boolean,
|
isDisplayFullFile: Boolean,
|
||||||
isTextDiff: Boolean,
|
isTextDiff: Boolean,
|
||||||
onCloseDiffView: () -> Unit,
|
onCloseDiffView: () -> Unit,
|
||||||
@ -879,18 +879,18 @@ private fun DiffHeader(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
if (diffEntryType.statusType != StatusType.ADDED && diffEntryType.statusType != StatusType.REMOVED && isTextDiff) {
|
if (diffType.statusType != StatusType.ADDED && diffType.statusType != StatusType.REMOVED && isTextDiff) {
|
||||||
DiffTypeButtons(
|
DiffTypeButtons(
|
||||||
diffType = diffType,
|
diffType = textDiffType,
|
||||||
isDisplayFullFile = isDisplayFullFile,
|
isDisplayFullFile = isDisplayFullFile,
|
||||||
onChangeDiffType = onChangeDiffType,
|
onChangeDiffType = onChangeDiffType,
|
||||||
onDisplayFullFile = onDisplayFullFile,
|
onDisplayFullFile = onDisplayFullFile,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (diffEntryType is DiffEntryType.UncommittedDiff) {
|
if (diffType is DiffType.UncommittedDiff) {
|
||||||
UncommittedDiffFileHeaderButtons(
|
UncommittedDiffFileHeaderButtons(
|
||||||
diffEntryType,
|
diffType,
|
||||||
onUnstageFile = onUnstageFile,
|
onUnstageFile = onUnstageFile,
|
||||||
onStageFile = onStageFile
|
onStageFile = onStageFile
|
||||||
)
|
)
|
||||||
@ -995,14 +995,14 @@ fun DiffTypeButtons(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UncommittedDiffFileHeaderButtons(
|
fun UncommittedDiffFileHeaderButtons(
|
||||||
diffEntryType: DiffEntryType.UncommittedDiff,
|
diffType: DiffType.UncommittedDiff,
|
||||||
onUnstageFile: (StatusEntry) -> Unit,
|
onUnstageFile: (StatusEntry) -> Unit,
|
||||||
onStageFile: (StatusEntry) -> Unit
|
onStageFile: (StatusEntry) -> Unit
|
||||||
) {
|
) {
|
||||||
val buttonText: String
|
val buttonText: String
|
||||||
val color: Color
|
val color: Color
|
||||||
|
|
||||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
if (diffType is DiffType.StagedDiff) {
|
||||||
buttonText = "Unstage file"
|
buttonText = "Unstage file"
|
||||||
color = MaterialTheme.colors.error
|
color = MaterialTheme.colors.error
|
||||||
} else {
|
} else {
|
||||||
@ -1014,10 +1014,10 @@ fun UncommittedDiffFileHeaderButtons(
|
|||||||
text = buttonText,
|
text = buttonText,
|
||||||
backgroundButton = color,
|
backgroundButton = color,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
if (diffType is DiffType.StagedDiff) {
|
||||||
onUnstageFile(diffEntryType.statusEntry)
|
onUnstageFile(diffType.statusEntry)
|
||||||
} else {
|
} else {
|
||||||
onStageFile(diffEntryType.statusEntry)
|
onStageFile(diffType.statusEntry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -1064,7 +1064,7 @@ private fun PathOnlyDiffHeader(
|
|||||||
fun DiffLine(
|
fun DiffLine(
|
||||||
highestLineNumberLength: Int,
|
highestLineNumberLength: Int,
|
||||||
line: Line,
|
line: Line,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
onActionTriggered: () -> Unit,
|
onActionTriggered: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val backgroundColor = when (line.lineType) {
|
val backgroundColor = when (line.lineType) {
|
||||||
@ -1100,7 +1100,7 @@ fun DiffLine(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffLineText(line, diffEntryType, onActionTriggered = onActionTriggered)
|
DiffLineText(line, diffType, onActionTriggered = onActionTriggered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1109,7 +1109,7 @@ fun SplitDiffLine(
|
|||||||
highestLineNumberLength: Int,
|
highestLineNumberLength: Int,
|
||||||
line: Line,
|
line: Line,
|
||||||
lineNumber: Int,
|
lineNumber: Int,
|
||||||
diffEntryType: DiffEntryType,
|
diffType: DiffType,
|
||||||
onActionTriggered: () -> Unit,
|
onActionTriggered: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val backgroundColor = when (line.lineType) {
|
val backgroundColor = when (line.lineType) {
|
||||||
@ -1129,27 +1129,27 @@ fun SplitDiffLine(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffLineText(line, diffEntryType, onActionTriggered = onActionTriggered)
|
DiffLineText(line, diffType, onActionTriggered = onActionTriggered)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DiffLineText(line: Line, diffEntryType: DiffEntryType, onActionTriggered: () -> Unit) {
|
fun DiffLineText(line: Line, diffType: DiffType, onActionTriggered: () -> Unit) {
|
||||||
val text = line.text
|
val text = line.text
|
||||||
val hoverInteraction = remember { MutableInteractionSource() }
|
val hoverInteraction = remember { MutableInteractionSource() }
|
||||||
val isHovered by hoverInteraction.collectIsHoveredAsState()
|
val isHovered by hoverInteraction.collectIsHoveredAsState()
|
||||||
|
|
||||||
Box(modifier = Modifier.hoverable(hoverInteraction)) {
|
Box(modifier = Modifier.hoverable(hoverInteraction)) {
|
||||||
if (isHovered && diffEntryType is DiffEntryType.UncommittedDiff && line.lineType != LineType.CONTEXT) {
|
if (isHovered && diffType is DiffType.UncommittedDiff && line.lineType != LineType.CONTEXT) {
|
||||||
val color: Color = if (diffEntryType is DiffEntryType.StagedDiff) {
|
val color: Color = if (diffType is DiffType.StagedDiff) {
|
||||||
MaterialTheme.colors.error
|
MaterialTheme.colors.error
|
||||||
} else {
|
} else {
|
||||||
MaterialTheme.colors.primary
|
MaterialTheme.colors.primary
|
||||||
}
|
}
|
||||||
|
|
||||||
val iconName = remember(diffEntryType) {
|
val iconName = remember(diffType) {
|
||||||
if (diffEntryType is DiffEntryType.StagedDiff) {
|
if (diffType is DiffType.StagedDiff) {
|
||||||
AppIcons.REMOVE
|
AppIcons.REMOVE
|
||||||
} else {
|
} else {
|
||||||
AppIcons.ADD
|
AppIcons.ADD
|
||||||
|
@ -3,7 +3,7 @@ package com.jetpackduba.gitnuro.viewmodels
|
|||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
||||||
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
import com.jetpackduba.gitnuro.extensions.delayedStateChange
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.RefreshType
|
import com.jetpackduba.gitnuro.git.RefreshType
|
||||||
import com.jetpackduba.gitnuro.git.TabState
|
import com.jetpackduba.gitnuro.git.TabState
|
||||||
import com.jetpackduba.gitnuro.git.diff.*
|
import com.jetpackduba.gitnuro.git.diff.*
|
||||||
@ -45,7 +45,7 @@ class DiffViewModel @Inject constructor(
|
|||||||
val diffTypeFlow = settings.textDiffTypeFlow
|
val diffTypeFlow = settings.textDiffTypeFlow
|
||||||
val isDisplayFullFile = settings.diffDisplayFullFileFlow
|
val isDisplayFullFile = settings.diffDisplayFullFileFlow
|
||||||
|
|
||||||
private var diffEntryType: DiffEntryType? = null
|
private var diffType: DiffType? = null
|
||||||
private var diffJob: Job? = null
|
private var diffJob: Job? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@ -53,7 +53,7 @@ class DiffViewModel @Inject constructor(
|
|||||||
diffTypeFlow
|
diffTypeFlow
|
||||||
.drop(1) // Ignore the first time the flow triggers, we only care about updates
|
.drop(1) // Ignore the first time the flow triggers, we only care about updates
|
||||||
.collect {
|
.collect {
|
||||||
val diffEntryType = this@DiffViewModel.diffEntryType
|
val diffEntryType = this@DiffViewModel.diffType
|
||||||
if (diffEntryType != null) {
|
if (diffEntryType != null) {
|
||||||
updateDiff(diffEntryType)
|
updateDiff(diffEntryType)
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ class DiffViewModel @Inject constructor(
|
|||||||
isDisplayFullFile
|
isDisplayFullFile
|
||||||
.drop(1) // Ignore the first time the flow triggers, we only care about updates
|
.drop(1) // Ignore the first time the flow triggers, we only care about updates
|
||||||
.collect {
|
.collect {
|
||||||
val diffEntryType = this@DiffViewModel.diffEntryType
|
val diffEntryType = this@DiffViewModel.diffType
|
||||||
if (diffEntryType != null) {
|
if (diffEntryType != null) {
|
||||||
updateDiff(diffEntryType)
|
updateDiff(diffEntryType)
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ class DiffViewModel @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
val diffResultValue = diffResult.value
|
val diffResultValue = diffResult.value
|
||||||
if (diffResultValue is ViewDiffResult.Loaded) {
|
if (diffResultValue is ViewDiffResult.Loaded) {
|
||||||
updateDiff(diffResultValue.diffEntryType)
|
updateDiff(diffResultValue.diffType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,24 +91,24 @@ class DiffViewModel @Inject constructor(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun updateDiff(diffEntryType: DiffEntryType) {
|
fun updateDiff(diffType: DiffType) {
|
||||||
diffJob = tabState.runOperation(refreshType = RefreshType.NONE) { git ->
|
diffJob = tabState.runOperation(refreshType = RefreshType.NONE) { git ->
|
||||||
this.diffEntryType = diffEntryType
|
this.diffType = diffType
|
||||||
|
|
||||||
var oldDiffEntryType: DiffEntryType? = null
|
var oldDiffType: DiffType? = null
|
||||||
val oldDiffResult = _diffResult.value
|
val oldDiffResult = _diffResult.value
|
||||||
|
|
||||||
if (oldDiffResult is ViewDiffResult.Loaded) {
|
if (oldDiffResult is ViewDiffResult.Loaded) {
|
||||||
oldDiffEntryType = oldDiffResult.diffEntryType
|
oldDiffType = oldDiffResult.diffType
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it's a different file or different state (index or workdir), reset the scroll state
|
// If it's a different file or different state (index or workdir), reset the scroll state
|
||||||
if (
|
if (
|
||||||
oldDiffEntryType?.filePath != diffEntryType.filePath ||
|
oldDiffType?.filePath != diffType.filePath ||
|
||||||
oldDiffEntryType is DiffEntryType.UncommittedDiff &&
|
oldDiffType is DiffType.UncommittedDiff &&
|
||||||
diffEntryType is DiffEntryType.UncommittedDiff &&
|
diffType is DiffType.UncommittedDiff &&
|
||||||
oldDiffEntryType.statusEntry.filePath == diffEntryType.statusEntry.filePath &&
|
oldDiffType.statusEntry.filePath == diffType.statusEntry.filePath &&
|
||||||
oldDiffEntryType::class != diffEntryType::class
|
oldDiffType::class != diffType::class
|
||||||
) {
|
) {
|
||||||
lazyListState.value = LazyListState(
|
lazyListState.value = LazyListState(
|
||||||
0,
|
0,
|
||||||
@ -121,9 +121,9 @@ class DiffViewModel @Inject constructor(
|
|||||||
try {
|
try {
|
||||||
delayedStateChange(
|
delayedStateChange(
|
||||||
delayMs = if (isFirstLoad) 0 else DIFF_MIN_TIME_IN_MS_TO_SHOW_LOAD,
|
delayMs = if (isFirstLoad) 0 else DIFF_MIN_TIME_IN_MS_TO_SHOW_LOAD,
|
||||||
onDelayTriggered = { _diffResult.value = ViewDiffResult.Loading(diffEntryType.filePath) }
|
onDelayTriggered = { _diffResult.value = ViewDiffResult.Loading(diffType.filePath) }
|
||||||
) {
|
) {
|
||||||
val diffFormat = formatDiffUseCase(git, diffEntryType, isDisplayFullFile.value)
|
val diffFormat = formatDiffUseCase(git, diffType, isDisplayFullFile.value)
|
||||||
val diffEntry = diffFormat.diffEntry
|
val diffEntry = diffFormat.diffEntry
|
||||||
if (
|
if (
|
||||||
diffTypeFlow.value == TextDiffType.SPLIT &&
|
diffTypeFlow.value == TextDiffType.SPLIT &&
|
||||||
@ -133,11 +133,11 @@ class DiffViewModel @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
val splitHunkList = generateSplitHunkFromDiffResultUseCase(diffFormat)
|
val splitHunkList = generateSplitHunkFromDiffResultUseCase(diffFormat)
|
||||||
_diffResult.value = ViewDiffResult.Loaded(
|
_diffResult.value = ViewDiffResult.Loaded(
|
||||||
diffEntryType,
|
diffType,
|
||||||
DiffResult.TextSplit(diffEntry, splitHunkList)
|
DiffResult.TextSplit(diffEntry, splitHunkList)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
_diffResult.value = ViewDiffResult.Loaded(diffEntryType, diffFormat)
|
_diffResult.value = ViewDiffResult.Loaded(diffType, diffFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
@ -4,7 +4,7 @@ import androidx.compose.foundation.lazy.LazyListState
|
|||||||
import com.jetpackduba.gitnuro.TaskType
|
import com.jetpackduba.gitnuro.TaskType
|
||||||
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
import com.jetpackduba.gitnuro.exceptions.MissingDiffEntryException
|
||||||
import com.jetpackduba.gitnuro.extensions.filePath
|
import com.jetpackduba.gitnuro.extensions.filePath
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.RefreshType
|
import com.jetpackduba.gitnuro.git.RefreshType
|
||||||
import com.jetpackduba.gitnuro.git.TabState
|
import com.jetpackduba.gitnuro.git.TabState
|
||||||
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
||||||
@ -61,14 +61,14 @@ class HistoryViewModel @Inject constructor(
|
|||||||
if (diffResult is DiffResult.Text && newDiffType == TextDiffType.SPLIT) { // Current is unified and new is split
|
if (diffResult is DiffResult.Text && newDiffType == TextDiffType.SPLIT) { // Current is unified and new is split
|
||||||
val hunksList = generateSplitHunkFromDiffResultUseCase(diffResult)
|
val hunksList = generateSplitHunkFromDiffResultUseCase(diffResult)
|
||||||
_viewDiffResult.value = ViewDiffResult.Loaded(
|
_viewDiffResult.value = ViewDiffResult.Loaded(
|
||||||
diffEntryType = viewDiffResult.diffEntryType,
|
diffType = viewDiffResult.diffType,
|
||||||
diffResult = DiffResult.TextSplit(diffResult.diffEntry, hunksList)
|
diffResult = DiffResult.TextSplit(diffResult.diffEntry, hunksList)
|
||||||
)
|
)
|
||||||
} else if (diffResult is DiffResult.TextSplit && newDiffType == TextDiffType.UNIFIED) { // Current is split and new is unified
|
} else if (diffResult is DiffResult.TextSplit && newDiffType == TextDiffType.UNIFIED) { // Current is split and new is unified
|
||||||
val hunksList = diffResult.hunks.map { it.sourceHunk }
|
val hunksList = diffResult.hunks.map { it.sourceHunk }
|
||||||
|
|
||||||
_viewDiffResult.value = ViewDiffResult.Loaded(
|
_viewDiffResult.value = ViewDiffResult.Loaded(
|
||||||
diffEntryType = viewDiffResult.diffEntryType,
|
diffType = viewDiffResult.diffType,
|
||||||
diffResult = DiffResult.Text(diffResult.diffEntry, hunksList)
|
diffResult = DiffResult.Text(diffResult.diffEntry, hunksList)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -109,11 +109,11 @@ class HistoryViewModel @Inject constructor(
|
|||||||
return@runOperation
|
return@runOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
val diffEntryType = DiffEntryType.CommitDiff(diffEntry)
|
val diffType = DiffType.CommitDiff(diffEntry)
|
||||||
|
|
||||||
val diffResult = formatDiffUseCase(
|
val diffResult = formatDiffUseCase(
|
||||||
git,
|
git,
|
||||||
diffEntryType,
|
diffType,
|
||||||
false
|
false
|
||||||
) // TODO This hardcoded false should be changed when the UI is implemented
|
) // TODO This hardcoded false should be changed when the UI is implemented
|
||||||
val textDiffType = settings.textDiffType
|
val textDiffType = settings.textDiffType
|
||||||
@ -123,7 +123,7 @@ class HistoryViewModel @Inject constructor(
|
|||||||
} else
|
} else
|
||||||
diffResult
|
diffResult
|
||||||
|
|
||||||
_viewDiffResult.value = ViewDiffResult.Loaded(diffEntryType, formattedDiffResult)
|
_viewDiffResult.value = ViewDiffResult.Loaded(diffType, formattedDiffResult)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
if (ex is MissingDiffEntryException) {
|
if (ex is MissingDiffEntryException) {
|
||||||
tabState.refreshData(refreshType = RefreshType.UNCOMMITTED_CHANGES)
|
tabState.refreshData(refreshType = RefreshType.UNCOMMITTED_CHANGES)
|
||||||
|
@ -89,10 +89,10 @@ class TabViewModel @Inject constructor(
|
|||||||
|
|
||||||
val credentialsState: StateFlow<CredentialsState> = credentialsStateManager.credentialsState
|
val credentialsState: StateFlow<CredentialsState> = credentialsStateManager.credentialsState
|
||||||
|
|
||||||
private val _diffSelected = MutableStateFlow<DiffEntryType?>(null)
|
private val _diffSelected = MutableStateFlow<DiffType?>(null)
|
||||||
val diffSelected: StateFlow<DiffEntryType?> = _diffSelected
|
val diffSelected: StateFlow<DiffType?> = _diffSelected
|
||||||
|
|
||||||
var newDiffSelected: DiffEntryType?
|
var newDiffSelected: DiffType?
|
||||||
get() = diffSelected.value
|
get() = diffSelected.value
|
||||||
set(value) {
|
set(value) {
|
||||||
_diffSelected.value = value
|
_diffSelected.value = value
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.jetpackduba.gitnuro.viewmodels
|
package com.jetpackduba.gitnuro.viewmodels
|
||||||
|
|
||||||
import com.jetpackduba.gitnuro.git.DiffEntryType
|
import com.jetpackduba.gitnuro.git.DiffType
|
||||||
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
import com.jetpackduba.gitnuro.git.diff.DiffResult
|
||||||
|
|
||||||
sealed interface ViewDiffResult {
|
sealed interface ViewDiffResult {
|
||||||
@ -10,5 +10,5 @@ sealed interface ViewDiffResult {
|
|||||||
|
|
||||||
object DiffNotFound : ViewDiffResult
|
object DiffNotFound : ViewDiffResult
|
||||||
|
|
||||||
data class Loaded(val diffEntryType: DiffEntryType, val diffResult: DiffResult) : ViewDiffResult
|
data class Loaded(val diffType: DiffType, val diffResult: DiffResult) : ViewDiffResult
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user