Code cleanup and fix typos
This commit is contained in:
parent
e91bfcf146
commit
c2e69d00f3
@ -74,7 +74,6 @@ class TabState @Inject constructor(
|
|||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun safeProcessing(
|
fun safeProcessing(
|
||||||
showError: Boolean = true,
|
|
||||||
refreshType: RefreshType,
|
refreshType: RefreshType,
|
||||||
// TODO Eventually the title and subtitles should be mandatory but for now the default it's empty to slowly
|
// TODO Eventually the title and subtitles should be mandatory but for now the default it's empty to slowly
|
||||||
// migrate the code that uses this function
|
// migrate the code that uses this function
|
||||||
@ -144,7 +143,7 @@ class TabState @Inject constructor(
|
|||||||
|
|
||||||
val containsCancellation = exceptionContainsCancellation(ex)
|
val containsCancellation = exceptionContainsCancellation(ex)
|
||||||
|
|
||||||
if (showError && !containsCancellation)
|
if (!containsCancellation)
|
||||||
errorsManager.addError(newErrorNow(ex, null, ex.message.orEmpty()))
|
errorsManager.addError(newErrorNow(ex, null, ex.message.orEmpty()))
|
||||||
|
|
||||||
printError(TAG, ex.message.orEmpty(), ex)
|
printError(TAG, ex.message.orEmpty(), ex)
|
||||||
@ -174,7 +173,6 @@ class TabState @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun safeProcessingWithoutGit(
|
fun safeProcessingWithoutGit(
|
||||||
showError: Boolean = true,
|
|
||||||
// TODO Eventually the title and subtitles should be mandatory but for now the default it's empty to slowly
|
// TODO Eventually the title and subtitles should be mandatory but for now the default it's empty to slowly
|
||||||
// migrate the code that uses this function
|
// migrate the code that uses this function
|
||||||
title: String = "",
|
title: String = "",
|
||||||
@ -193,7 +191,7 @@ class TabState @Inject constructor(
|
|||||||
|
|
||||||
val containsCancellation = exceptionContainsCancellation(ex)
|
val containsCancellation = exceptionContainsCancellation(ex)
|
||||||
|
|
||||||
if (showError && !containsCancellation)
|
if (!containsCancellation)
|
||||||
errorsManager.addError(newErrorNow(ex, null, ex.localizedMessage))
|
errorsManager.addError(newErrorNow(ex, null, ex.localizedMessage))
|
||||||
|
|
||||||
printError(TAG, ex.message.orEmpty(), ex)
|
printError(TAG, ex.message.orEmpty(), ex)
|
||||||
@ -318,8 +316,8 @@ enum class RefreshType {
|
|||||||
ONLY_LOG,
|
ONLY_LOG,
|
||||||
STASHES,
|
STASHES,
|
||||||
SUBMODULES,
|
SUBMODULES,
|
||||||
UNCOMMITED_CHANGES,
|
UNCOMMITTED_CHANGES,
|
||||||
UNCOMMITED_CHANGES_AND_LOG,
|
UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
REMOTES,
|
REMOTES,
|
||||||
REBASE_INTERACTIVE_STATE,
|
REBASE_INTERACTIVE_STATE,
|
||||||
}
|
}
|
||||||
|
@ -477,8 +477,8 @@ fun MessagesList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting a key makes the graph preserve the scroll position when a new line has been added on top (uncommited changes)
|
// Setting a key makes the graph preserve the scroll position when a new line has been added on top (uncommitted changes)
|
||||||
// Therefore, after popping a stash, the uncommited changes wouldn't be visible and requires the user scrolling.
|
// Therefore, after popping a stash, the uncommitted changes wouldn't be visible and requires the user scrolling.
|
||||||
items(items = commitList) { graphNode ->
|
items(items = commitList) { graphNode ->
|
||||||
CommitLine(
|
CommitLine(
|
||||||
graphWidth = graphWidth,
|
graphWidth = graphWidth,
|
||||||
|
@ -74,8 +74,8 @@ class DiffViewModel @Inject constructor(
|
|||||||
|
|
||||||
tabScope.launch {
|
tabScope.launch {
|
||||||
tabState.refreshFlowFiltered(
|
tabState.refreshFlowFiltered(
|
||||||
RefreshType.UNCOMMITED_CHANGES,
|
RefreshType.UNCOMMITTED_CHANGES,
|
||||||
RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) {
|
) {
|
||||||
val diffResultValue = diffResult.value
|
val diffResultValue = diffResult.value
|
||||||
if (diffResultValue is ViewDiffResult.Loaded) {
|
if (diffResultValue is ViewDiffResult.Loaded) {
|
||||||
@ -143,7 +143,7 @@ class DiffViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
if (ex is MissingDiffEntryException) {
|
if (ex is MissingDiffEntryException) {
|
||||||
tabState.refreshData(refreshType = RefreshType.UNCOMMITED_CHANGES)
|
tabState.refreshData(refreshType = RefreshType.UNCOMMITTED_CHANGES)
|
||||||
_diffResult.value = ViewDiffResult.DiffNotFound
|
_diffResult.value = ViewDiffResult.DiffNotFound
|
||||||
} else
|
} else
|
||||||
ex.printStackTrace()
|
ex.printStackTrace()
|
||||||
@ -152,33 +152,33 @@ class DiffViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stageHunk(diffEntry: DiffEntry, hunk: Hunk) = tabState.runOperation(
|
fun stageHunk(diffEntry: DiffEntry, hunk: Hunk) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
) { git ->
|
) { git ->
|
||||||
stageHunkUseCase(git, diffEntry, hunk)
|
stageHunkUseCase(git, diffEntry, hunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resetHunk(diffEntry: DiffEntry, hunk: Hunk) = tabState.runOperation(
|
fun resetHunk(diffEntry: DiffEntry, hunk: Hunk) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
resetHunkUseCase(git, diffEntry, hunk)
|
resetHunkUseCase(git, diffEntry, hunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unstageHunk(diffEntry: DiffEntry, hunk: Hunk) = tabState.runOperation(
|
fun unstageHunk(diffEntry: DiffEntry, hunk: Hunk) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
) { git ->
|
) { git ->
|
||||||
unstageHunkUseCase(git, diffEntry, hunk)
|
unstageHunkUseCase(git, diffEntry, hunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stageFile(statusEntry: StatusEntry) = tabState.runOperation(
|
fun stageFile(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
stageEntryUseCase(git, statusEntry)
|
stageEntryUseCase(git, statusEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unstageFile(statusEntry: StatusEntry) = tabState.runOperation(
|
fun unstageFile(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
unstageEntryUseCase(git, statusEntry)
|
unstageEntryUseCase(git, statusEntry)
|
||||||
@ -197,14 +197,14 @@ class DiffViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stageHunkLine(entry: DiffEntry, hunk: Hunk, line: Line) = tabState.runOperation(
|
fun stageHunkLine(entry: DiffEntry, hunk: Hunk, line: Line) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
stageHunkLineUseCase(git, entry, hunk, line)
|
stageHunkLineUseCase(git, entry, hunk, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unstageHunkLine(entry: DiffEntry, hunk: Hunk, line: Line) = tabState.runOperation(
|
fun unstageHunkLine(entry: DiffEntry, hunk: Hunk, line: Line) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
unstageHunkLineUseCase(git, entry, hunk, line)
|
unstageHunkLineUseCase(git, entry, hunk, line)
|
||||||
@ -215,7 +215,7 @@ class DiffViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun discardHunkLine(entry: DiffEntry, hunk: Hunk, line: Line) = tabState.runOperation(
|
fun discardHunkLine(entry: DiffEntry, hunk: Hunk, line: Line) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
discardUnstagedHunkLineUseCase(git, entry, hunk, line)
|
discardUnstagedHunkLineUseCase(git, entry, hunk, line)
|
||||||
|
@ -119,7 +119,7 @@ class HistoryViewModel @Inject constructor(
|
|||||||
_viewDiffResult.value = ViewDiffResult.Loaded(diffEntryType, formattedDiffResult)
|
_viewDiffResult.value = ViewDiffResult.Loaded(diffEntryType, formattedDiffResult)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
if (ex is MissingDiffEntryException) {
|
if (ex is MissingDiffEntryException) {
|
||||||
tabState.refreshData(refreshType = RefreshType.UNCOMMITED_CHANGES)
|
tabState.refreshData(refreshType = RefreshType.UNCOMMITTED_CHANGES)
|
||||||
_viewDiffResult.value = ViewDiffResult.DiffNotFound
|
_viewDiffResult.value = ViewDiffResult.DiffNotFound
|
||||||
} else
|
} else
|
||||||
ex.printStackTrace()
|
ex.printStackTrace()
|
||||||
|
@ -17,9 +17,6 @@ import com.jetpackduba.gitnuro.git.rebase.StartRebaseInteractiveUseCase
|
|||||||
import com.jetpackduba.gitnuro.git.remote_operations.DeleteRemoteBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.DeleteRemoteBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.PullFromSpecificBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.PullFromSpecificBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.PushToSpecificBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.PushToSpecificBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.git.stash.ApplyStashUseCase
|
|
||||||
import com.jetpackduba.gitnuro.git.stash.DeleteStashUseCase
|
|
||||||
import com.jetpackduba.gitnuro.git.stash.PopStashUseCase
|
|
||||||
import com.jetpackduba.gitnuro.git.tags.CreateTagOnCommitUseCase
|
import com.jetpackduba.gitnuro.git.tags.CreateTagOnCommitUseCase
|
||||||
import com.jetpackduba.gitnuro.git.tags.DeleteTagUseCase
|
import com.jetpackduba.gitnuro.git.tags.DeleteTagUseCase
|
||||||
import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommitedChangesUseCase
|
import com.jetpackduba.gitnuro.git.workspace.CheckHasUncommitedChangesUseCase
|
||||||
@ -53,7 +50,7 @@ private const val LOG_MIN_TIME_IN_MS_TO_SHOW_LOAD = 500L
|
|||||||
class LogViewModel @Inject constructor(
|
class LogViewModel @Inject constructor(
|
||||||
private val getLogUseCase: GetLogUseCase,
|
private val getLogUseCase: GetLogUseCase,
|
||||||
private val getStatusSummaryUseCase: GetStatusSummaryUseCase,
|
private val getStatusSummaryUseCase: GetStatusSummaryUseCase,
|
||||||
private val checkHasUncommitedChangesUseCase: CheckHasUncommitedChangesUseCase,
|
private val checkHasUncommittedChangesUseCase: CheckHasUncommitedChangesUseCase,
|
||||||
private val getCurrentBranchUseCase: GetCurrentBranchUseCase,
|
private val getCurrentBranchUseCase: GetCurrentBranchUseCase,
|
||||||
private val checkoutRefUseCase: CheckoutRefUseCase,
|
private val checkoutRefUseCase: CheckoutRefUseCase,
|
||||||
private val createBranchOnCommitUseCase: CreateBranchOnCommitUseCase,
|
private val createBranchOnCommitUseCase: CreateBranchOnCommitUseCase,
|
||||||
@ -70,13 +67,10 @@ class LogViewModel @Inject constructor(
|
|||||||
private val deleteTagUseCase: DeleteTagUseCase,
|
private val deleteTagUseCase: DeleteTagUseCase,
|
||||||
private val rebaseBranchUseCase: RebaseBranchUseCase,
|
private val rebaseBranchUseCase: RebaseBranchUseCase,
|
||||||
private val startRebaseInteractiveUseCase: StartRebaseInteractiveUseCase,
|
private val startRebaseInteractiveUseCase: StartRebaseInteractiveUseCase,
|
||||||
private val applyStashUseCase: ApplyStashUseCase,
|
|
||||||
private val popStashUseCase: PopStashUseCase,
|
|
||||||
private val deleteStashUseCase: DeleteStashUseCase,
|
|
||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
private val appSettings: AppSettings,
|
private val appSettings: AppSettings,
|
||||||
private val tabScope: CoroutineScope,
|
private val tabScope: CoroutineScope,
|
||||||
sharedStashViewModel: SharedStashViewModel,
|
private val sharedStashViewModel: SharedStashViewModel,
|
||||||
) : ViewModel, ISharedStashViewModel by sharedStashViewModel {
|
) : ViewModel, ISharedStashViewModel by sharedStashViewModel {
|
||||||
private val _logStatus = MutableStateFlow<LogStatus>(LogStatus.Loading)
|
private val _logStatus = MutableStateFlow<LogStatus>(LogStatus.Loading)
|
||||||
|
|
||||||
@ -125,10 +119,10 @@ class LogViewModel @Inject constructor(
|
|||||||
tabState.refreshFlowFiltered(
|
tabState.refreshFlowFiltered(
|
||||||
RefreshType.ALL_DATA,
|
RefreshType.ALL_DATA,
|
||||||
RefreshType.ONLY_LOG,
|
RefreshType.ONLY_LOG,
|
||||||
RefreshType.UNCOMMITED_CHANGES,
|
RefreshType.UNCOMMITTED_CHANGES,
|
||||||
RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) { refreshType ->
|
) { refreshType ->
|
||||||
if (refreshType == RefreshType.UNCOMMITED_CHANGES) {
|
if (refreshType == RefreshType.UNCOMMITTED_CHANGES) {
|
||||||
uncommitedChangesLoadLog(tabState.git)
|
uncommitedChangesLoadLog(tabState.git)
|
||||||
} else
|
} else
|
||||||
refresh(tabState.git)
|
refresh(tabState.git)
|
||||||
@ -205,9 +199,9 @@ class LogViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun revertCommit(revCommit: RevCommit) = tabState.safeProcessing(
|
fun revertCommit(revCommit: RevCommit) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
refreshEvenIfCrashes = true,
|
|
||||||
title = "Commit revert",
|
title = "Commit revert",
|
||||||
subtitle = "Reverting commit ${revCommit.name}",
|
subtitle = "Reverting commit ${revCommit.name}",
|
||||||
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
revertCommitUseCase(git, revCommit)
|
revertCommitUseCase(git, revCommit)
|
||||||
}
|
}
|
||||||
@ -229,7 +223,7 @@ class LogViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun cherrypickCommit(revCommit: RevCommit) = tabState.safeProcessing(
|
fun cherrypickCommit(revCommit: RevCommit) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
title = "Cherry-pick",
|
title = "Cherry-pick",
|
||||||
subtitle = "Cherry-picking commit ${revCommit.shortName}",
|
subtitle = "Cherry-picking commit ${revCommit.shortName}",
|
||||||
) { git ->
|
) { git ->
|
||||||
@ -238,9 +232,9 @@ class LogViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing(
|
fun createBranchOnCommit(branch: String, revCommit: RevCommit) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
refreshEvenIfCrashesInteractive = { it is CheckoutConflictException },
|
|
||||||
title = "New branch",
|
title = "New branch",
|
||||||
subtitle = "Creating new branch \"$branch\" on commit ${revCommit.shortName}",
|
subtitle = "Creating new branch \"$branch\" on commit ${revCommit.shortName}",
|
||||||
|
refreshEvenIfCrashesInteractive = { it is CheckoutConflictException },
|
||||||
) { git ->
|
) { git ->
|
||||||
createBranchOnCommitUseCase(git, branch, revCommit)
|
createBranchOnCommitUseCase(git, branch, revCommit)
|
||||||
}
|
}
|
||||||
@ -279,7 +273,7 @@ class LogViewModel @Inject constructor(
|
|||||||
|
|
||||||
private suspend fun uncommitedChangesLoadLog(git: Git) {
|
private suspend fun uncommitedChangesLoadLog(git: Git) {
|
||||||
val currentBranch = getCurrentBranchUseCase(git)
|
val currentBranch = getCurrentBranchUseCase(git)
|
||||||
val hasUncommitedChanges = checkHasUncommitedChangesUseCase(git)
|
val hasUncommitedChanges = checkHasUncommittedChangesUseCase(git)
|
||||||
|
|
||||||
val statsSummary = if (hasUncommitedChanges) {
|
val statsSummary = if (hasUncommitedChanges) {
|
||||||
getStatusSummaryUseCase(
|
getStatusSummaryUseCase(
|
||||||
|
@ -28,41 +28,41 @@ class MenuViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun pull(pullType: PullType) = tabState.safeProcessing(
|
fun pull(pullType: PullType) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
refreshEvenIfCrashes = true,
|
|
||||||
title = "Pulling",
|
title = "Pulling",
|
||||||
subtitle = "Pulling changes from the remote branch to the current branch"
|
subtitle = "Pulling changes from the remote branch to the current branch",
|
||||||
|
refreshEvenIfCrashes = true
|
||||||
) { git ->
|
) { git ->
|
||||||
pullBranchUseCase(git, pullType)
|
pullBranchUseCase(git, pullType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fetchAll() = tabState.safeProcessing(
|
fun fetchAll() = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
refreshEvenIfCrashes = true,
|
|
||||||
title = "Fetching",
|
title = "Fetching",
|
||||||
subtitle = "Updating references from the remote repositories...",
|
subtitle = "Updating references from the remote repositories...",
|
||||||
isCancellable = false
|
isCancellable = false,
|
||||||
|
refreshEvenIfCrashes = true
|
||||||
) { git ->
|
) { git ->
|
||||||
fetchAllBranchesUseCase(git)
|
fetchAllBranchesUseCase(git)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun push(force: Boolean = false, pushTags: Boolean = false) = tabState.safeProcessing(
|
fun push(force: Boolean = false, pushTags: Boolean = false) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.ALL_DATA,
|
refreshType = RefreshType.ALL_DATA,
|
||||||
refreshEvenIfCrashes = true,
|
|
||||||
title = "Push",
|
title = "Push",
|
||||||
subtitle = "Pushing current branch to the remote repository",
|
subtitle = "Pushing current branch to the remote repository",
|
||||||
isCancellable = false,
|
isCancellable = false,
|
||||||
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
pushBranchUseCase(git, force, pushTags)
|
pushBranchUseCase(git, force, pushTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stash() = tabState.safeProcessing(
|
fun stash() = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) { git ->
|
) { git ->
|
||||||
stashChangesUseCase(git, null)
|
stashChangesUseCase(git, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun popStash() = tabState.safeProcessing(
|
fun popStash() = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
refreshEvenIfCrashes = true,
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
popLastStashUseCase(git)
|
popLastStashUseCase(git)
|
||||||
|
@ -25,14 +25,14 @@ class SharedStashViewModel @Inject constructor(
|
|||||||
private val tabState: TabState,
|
private val tabState: TabState,
|
||||||
) : ISharedStashViewModel {
|
) : ISharedStashViewModel {
|
||||||
override fun applyStash(stashInfo: RevCommit) = tabState.safeProcessing(
|
override fun applyStash(stashInfo: RevCommit) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
refreshEvenIfCrashes = true,
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
applyStashUseCase(git, stashInfo)
|
applyStashUseCase(git, stashInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun popStash(stash: RevCommit) = tabState.safeProcessing(
|
override fun popStash(stash: RevCommit) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
refreshEvenIfCrashes = true,
|
refreshEvenIfCrashes = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
popStashUseCase(git, stash)
|
popStashUseCase(git, stash)
|
||||||
|
@ -153,8 +153,8 @@ class StatusViewModel @Inject constructor(
|
|||||||
tabScope.launch {
|
tabScope.launch {
|
||||||
tabState.refreshFlowFiltered(
|
tabState.refreshFlowFiltered(
|
||||||
RefreshType.ALL_DATA,
|
RefreshType.ALL_DATA,
|
||||||
RefreshType.UNCOMMITED_CHANGES,
|
RefreshType.UNCOMMITTED_CHANGES,
|
||||||
RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) {
|
) {
|
||||||
refresh(tabState.git)
|
refresh(tabState.git)
|
||||||
}
|
}
|
||||||
@ -177,14 +177,14 @@ class StatusViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stage(statusEntry: StatusEntry) = tabState.runOperation(
|
fun stage(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
stageEntryUseCase(git, statusEntry)
|
stageEntryUseCase(git, statusEntry)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unstage(statusEntry: StatusEntry) = tabState.runOperation(
|
fun unstage(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
showError = true,
|
showError = true,
|
||||||
) { git ->
|
) { git ->
|
||||||
unstageEntryUseCase(git, statusEntry)
|
unstageEntryUseCase(git, statusEntry)
|
||||||
@ -192,25 +192,25 @@ class StatusViewModel @Inject constructor(
|
|||||||
|
|
||||||
|
|
||||||
fun unstageAll() = tabState.safeProcessing(
|
fun unstageAll() = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
) { git ->
|
) { git ->
|
||||||
unstageAllUseCase(git)
|
unstageAllUseCase(git)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stageAll() = tabState.safeProcessing(
|
fun stageAll() = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
) { git ->
|
) { git ->
|
||||||
stageAllUseCase(git)
|
stageAllUseCase(git)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resetStaged(statusEntry: StatusEntry) = tabState.runOperation(
|
fun resetStaged(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) { git ->
|
) { git ->
|
||||||
resetEntryUseCase(git, statusEntry, staged = true)
|
resetEntryUseCase(git, statusEntry, staged = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resetUnstaged(statusEntry: StatusEntry) = tabState.runOperation(
|
fun resetUnstaged(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) { git ->
|
) { git ->
|
||||||
resetEntryUseCase(git, statusEntry, staged = false)
|
resetEntryUseCase(git, statusEntry, staged = false)
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ class StatusViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteFile(statusEntry: StatusEntry) = tabState.runOperation(
|
fun deleteFile(statusEntry: StatusEntry) = tabState.runOperation(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES,
|
||||||
) { git ->
|
) { git ->
|
||||||
val path = statusEntry.filePath
|
val path = statusEntry.filePath
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ class TabViewModel @Inject constructor(
|
|||||||
refreshType = RefreshType.NONE,
|
refreshType = RefreshType.NONE,
|
||||||
) {
|
) {
|
||||||
updateDiffEntry()
|
updateDiffEntry()
|
||||||
tabState.refreshData(RefreshType.UNCOMMITED_CHANGES_AND_LOG)
|
tabState.refreshData(RefreshType.UNCOMMITTED_CHANGES_AND_LOG)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun refreshRepositoryInfo() {
|
private suspend fun refreshRepositoryInfo() {
|
||||||
@ -327,9 +327,7 @@ class TabViewModel @Inject constructor(
|
|||||||
return openFilePickerUseCase(PickerType.DIRECTORIES, latestDirectoryOpened)
|
return openFilePickerUseCase(PickerType.DIRECTORIES, latestDirectoryOpened)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun initLocalRepository(dir: String) = tabState.safeProcessingWithoutGit(
|
fun initLocalRepository(dir: String) = tabState.safeProcessingWithoutGit {
|
||||||
showError = true,
|
|
||||||
) {
|
|
||||||
val repoDir = File(dir)
|
val repoDir = File(dir)
|
||||||
initLocalRepositoryUseCase(repoDir)
|
initLocalRepositoryUseCase(repoDir)
|
||||||
openRepository(repoDir)
|
openRepository(repoDir)
|
||||||
@ -409,7 +407,7 @@ class TabViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stashWithMessage(message: String) = tabState.safeProcessing(
|
fun stashWithMessage(message: String) = tabState.safeProcessing(
|
||||||
refreshType = RefreshType.UNCOMMITED_CHANGES_AND_LOG,
|
refreshType = RefreshType.UNCOMMITTED_CHANGES_AND_LOG,
|
||||||
) { git ->
|
) { git ->
|
||||||
stageUntrackedFileUseCase(git)
|
stageUntrackedFileUseCase(git)
|
||||||
stashChangesUseCase(git, message)
|
stashChangesUseCase(git, message)
|
||||||
|
@ -9,7 +9,6 @@ import com.jetpackduba.gitnuro.git.rebase.RebaseBranchUseCase
|
|||||||
import com.jetpackduba.gitnuro.git.remote_operations.PullFromSpecificBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.PullFromSpecificBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.git.remote_operations.PushToSpecificBranchUseCase
|
import com.jetpackduba.gitnuro.git.remote_operations.PushToSpecificBranchUseCase
|
||||||
import com.jetpackduba.gitnuro.preferences.AppSettings
|
import com.jetpackduba.gitnuro.preferences.AppSettings
|
||||||
import com.jetpackduba.gitnuro.ui.SelectedItem
|
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
@ -125,7 +125,6 @@ class RemotesViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
fun deleteRemote(remoteName: String, isNew: Boolean) = tabState.safeProcessing(
|
fun deleteRemote(remoteName: String, isNew: Boolean) = tabState.safeProcessing(
|
||||||
refreshType = if (isNew) RefreshType.REMOTES else RefreshType.ALL_DATA,
|
refreshType = if (isNew) RefreshType.REMOTES else RefreshType.ALL_DATA,
|
||||||
showError = true,
|
|
||||||
) { git ->
|
) { git ->
|
||||||
deleteRemoteUseCase(git, remoteName)
|
deleteRemoteUseCase(git, remoteName)
|
||||||
|
|
||||||
|
@ -3,11 +3,7 @@ package com.jetpackduba.gitnuro.viewmodels.sidepanel
|
|||||||
import com.jetpackduba.gitnuro.extensions.lowercaseContains
|
import com.jetpackduba.gitnuro.extensions.lowercaseContains
|
||||||
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.stash.ApplyStashUseCase
|
|
||||||
import com.jetpackduba.gitnuro.git.stash.DeleteStashUseCase
|
|
||||||
import com.jetpackduba.gitnuro.git.stash.GetStashListUseCase
|
import com.jetpackduba.gitnuro.git.stash.GetStashListUseCase
|
||||||
import com.jetpackduba.gitnuro.git.stash.PopStashUseCase
|
|
||||||
import com.jetpackduba.gitnuro.ui.SelectedItem
|
|
||||||
import com.jetpackduba.gitnuro.viewmodels.ISharedStashViewModel
|
import com.jetpackduba.gitnuro.viewmodels.ISharedStashViewModel
|
||||||
import com.jetpackduba.gitnuro.viewmodels.SharedStashViewModel
|
import com.jetpackduba.gitnuro.viewmodels.SharedStashViewModel
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
@ -27,6 +23,7 @@ class StashesViewModel @AssistedInject constructor(
|
|||||||
private val filter: StateFlow<String>,
|
private val filter: StateFlow<String>,
|
||||||
sharedStashViewModel: SharedStashViewModel,
|
sharedStashViewModel: SharedStashViewModel,
|
||||||
) : SidePanelChildViewModel(true), ISharedStashViewModel by sharedStashViewModel {
|
) : SidePanelChildViewModel(true), ISharedStashViewModel by sharedStashViewModel {
|
||||||
|
|
||||||
private val stashes = MutableStateFlow<List<RevCommit>>(emptyList())
|
private val stashes = MutableStateFlow<List<RevCommit>>(emptyList())
|
||||||
|
|
||||||
val stashesState: StateFlow<StashesState> = combine(stashes, isExpanded, filter) { stashes, isExpanded, filter ->
|
val stashesState: StateFlow<StashesState> = combine(stashes, isExpanded, filter) { stashes, isExpanded, filter ->
|
||||||
@ -45,14 +42,14 @@ class StashesViewModel @AssistedInject constructor(
|
|||||||
tabState.refreshFlowFiltered(
|
tabState.refreshFlowFiltered(
|
||||||
RefreshType.ALL_DATA,
|
RefreshType.ALL_DATA,
|
||||||
RefreshType.STASHES,
|
RefreshType.STASHES,
|
||||||
RefreshType.UNCOMMITED_CHANGES_AND_LOG
|
RefreshType.UNCOMMITTED_CHANGES_AND_LOG
|
||||||
) {
|
) {
|
||||||
refresh(tabState.git)
|
refresh(tabState.git)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun loadStashes(git: Git) {
|
private suspend fun loadStashes(git: Git) {
|
||||||
val stashList = getStashListUseCase(git)
|
val stashList = getStashListUseCase(git)
|
||||||
stashes.value = stashList
|
stashes.value = stashList
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class SubmodulesViewModel @AssistedInject constructor(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
tabScope.launch {
|
tabScope.launch {
|
||||||
tabState.refreshFlowFiltered(RefreshType.ALL_DATA, RefreshType.UNCOMMITED_CHANGES, RefreshType.SUBMODULES) {
|
tabState.refreshFlowFiltered(RefreshType.ALL_DATA, RefreshType.UNCOMMITTED_CHANGES, RefreshType.SUBMODULES) {
|
||||||
refresh(tabState.git)
|
refresh(tabState.git)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,7 +54,6 @@ class SubmodulesViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun initializeSubmodule(path: String) = tabState.safeProcessing(
|
fun initializeSubmodule(path: String) = tabState.safeProcessing(
|
||||||
showError = true,
|
|
||||||
refreshType = RefreshType.SUBMODULES,
|
refreshType = RefreshType.SUBMODULES,
|
||||||
) { git ->
|
) { git ->
|
||||||
initializeSubmoduleUseCase(git, path)
|
initializeSubmoduleUseCase(git, path)
|
||||||
|
Loading…
Reference in New Issue
Block a user