Skip to content

Commit 2242761

Browse files
committed
Extracted strings from all context menus
1 parent 5398b69 commit 2242761

File tree

14 files changed

+236
-196
lines changed

14 files changed

+236
-196
lines changed

src/main/composeResources/values/strings.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,65 @@
8787
<string name="status_entries_context_menu_file_history">File history</string>
8888
<string name="status_entries_context_menu_blame_file">Blame file</string>
8989
<string name="status_entries_context_menu_discard_file_changes">Discard file changes</string>
90+
91+
<!-- Branch context menu -->
92+
<string name="branch_context_menu_checkout_branch">Checkout branch</string>
93+
<string name="branch_context_menu_merge_branch">Merge branch</string>
94+
<string name="branch_context_menu_rebase_branch">Rebase branch</string>
95+
<string name="branch_context_menu_push_current_to_target">Push "%1$s" to "%2$s"</string>
96+
<string name="branch_context_menu_pull_target_to_current">Pull "%1$s" to "%2$s"</string>
97+
<string name="branch_context_menu_change_default_upstream_branch">Change default upstream branch</string>
98+
<string name="branch_context_menu_delete_remote_branch">Delete remote branch</string>
99+
<string name="branch_context_menu_delete_branch">Delete branch</string>
100+
<string name="branch_context_menu_copy_branch_name">Copy branch name</string>
101+
102+
<!-- Committed changes context menu -->
103+
<string name="committed_changes_context_menu_blame_file">Blame file</string>
104+
<string name="committed_changes_context_menu_file_history">File history</string>
105+
106+
<!-- Log context menu -->
107+
<string name="log_context_menu_checkout_commit">Checkout commit</string>
108+
<string name="log_context_menu_create_branch">Create branch</string>
109+
<string name="log_context_menu_create_tag">Create tag</string>
110+
<string name="log_context_menu_rebase_interactive">Rebase interactive</string>
111+
<string name="log_context_menu_revert_commit">Revert commit</string>
112+
<string name="log_context_menu_cherry_pick_commit">Cherry-pick commit</string>
113+
<string name="log_context_menu_reset_current_branch_to_commit">Reset current branch to this commit</string>
114+
115+
<!-- Pull context menu -->
116+
<string name="pull_context_menu_pull_with_merge">Pull with merge</string>
117+
<string name="pull_context_menu_pull_with_rebase">Pull with rebase</string>
118+
<string name="pull_context_menu_fetch_all">Fetch all</string>
119+
120+
<!-- Push context menu -->
121+
<string name="push_context_menu_push_including_tags">Push including tags</string>
122+
<string name="push_context_menu_force_push">Force push</string>
123+
124+
<!-- Remote context menu -->
125+
<string name="remote_context_menu_edit">Edit</string>
126+
<string name="remote_context_menu_delete">Delete</string>
127+
128+
<!-- Stash menu context menu -->
129+
<string name="stash_context_menu_stash_with_message">Stash with message</string>
130+
131+
<!-- Stashes context menu -->
132+
<string name="stashes_context_menu_apply_stash">Apply stash</string>
133+
<string name="stashes_context_menu_pop_stash">Pop stash</string>
134+
<string name="stashes_context_menu_drop_stash">Drop stash</string>
135+
136+
<!-- Status dir entries context menu -->
137+
<string name="status_dir_entries_context_menu_unstage_changes">Unstage changes in the directory</string>
138+
<string name="status_dir_entries_context_menu_stage_changes">Stage changes in the directory</string>
139+
<string name="status_dir_entries_context_menu_discard_changes">Discard changes</string>
140+
141+
<!-- Submodules context menu -->
142+
<string name="submodules_context_menu_initialize_submodule">Initialize submodule</string>
143+
<string name="submodules_context_menu_open_submodule_in_tab">Open submodule in new tab</string>
144+
<string name="submodules_context_menu_sync_submodule">Sync submodule</string>
145+
<string name="submodules_context_menu_update_submodule">Update submodule</string>
146+
<string name="submodules_context_menu_delete_submodule">Delete submodule</string>
147+
148+
<!-- Tag context menu -->
149+
<string name="tag_context_menu_checkout_tag_commit">Checkout tag's commit</string>
150+
<string name="tag_context_menu_delete_tag">Delete tag</string>
90151
</resources>

src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/BranchContextMenu.kt

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package com.jetpackduba.gitnuro.ui.context_menu
33
import com.jetpackduba.gitnuro.extensions.isHead
44
import com.jetpackduba.gitnuro.extensions.simpleLogName
55
import com.jetpackduba.gitnuro.extensions.simpleName
6-
import com.jetpackduba.gitnuro.generated.resources.Res
7-
import com.jetpackduba.gitnuro.generated.resources.copy
8-
import com.jetpackduba.gitnuro.generated.resources.delete
9-
import com.jetpackduba.gitnuro.generated.resources.start
6+
import com.jetpackduba.gitnuro.generated.resources.*
107
import com.jetpackduba.gitnuro.models.Notification
118
import com.jetpackduba.gitnuro.models.positiveNotification
129
import org.eclipse.jgit.lib.Ref
1310
import org.jetbrains.compose.resources.painterResource
11+
import org.jetbrains.compose.resources.stringResource
1412
import org.jetbrains.skiko.ClipboardManager
1513

1614
fun branchContextMenuItems(
@@ -31,90 +29,84 @@ fun branchContextMenuItems(
3129

3230
return mutableListOf<ContextMenuElement>().apply {
3331
if (!isCurrentBranch) {
34-
add(
35-
ContextMenuElement.ContextTextEntry(
36-
label = "Checkout branch",
37-
icon = { painterResource(Res.drawable.start) },
38-
onClick = onCheckoutBranch
39-
)
32+
addContextMenu(
33+
composableLabel = { stringResource(Res.string.branch_context_menu_checkout_branch) },
34+
icon = { painterResource(Res.drawable.start) },
35+
onClick = onCheckoutBranch
4036
)
4137
if (currentBranch != null && !currentBranch.isHead) {
42-
add(
43-
ContextMenuElement.ContextTextEntry(
44-
label = "Merge branch",
45-
onClick = onMergeBranch
46-
)
38+
addContextMenu(
39+
composableLabel = { stringResource(Res.string.branch_context_menu_merge_branch) },
40+
onClick = onMergeBranch
4741
)
48-
add(
49-
ContextMenuElement.ContextTextEntry(
50-
label = "Rebase branch",
51-
onClick = onRebaseBranch
52-
)
42+
addContextMenu(
43+
composableLabel = { stringResource(Res.string.branch_context_menu_rebase_branch) },
44+
onClick = onRebaseBranch
5345
)
5446

5547
add(ContextMenuElement.ContextSeparator)
5648
}
5749
}
5850
if (!isLocal && currentBranch != null && !currentBranch.isHead) {
59-
add(
60-
ContextMenuElement.ContextTextEntry(
61-
label = "Push ${currentBranch.simpleLogName} to ${branch.simpleLogName}",
62-
onClick = onPushToRemoteBranch
63-
)
51+
addContextMenu(
52+
composableLabel = {
53+
stringResource(
54+
Res.string.branch_context_menu_push_current_to_target,
55+
currentBranch.simpleLogName,
56+
branch.simpleLogName,
57+
)
58+
},
59+
onClick = onPushToRemoteBranch
6460
)
65-
add(
66-
ContextMenuElement.ContextTextEntry(
67-
label = "Pull ${branch.simpleLogName} to ${currentBranch.simpleLogName}",
68-
onClick = onPullFromRemoteBranch
69-
)
61+
addContextMenu(
62+
composableLabel = {
63+
stringResource(
64+
Res.string.branch_context_menu_pull_target_to_current,
65+
branch.simpleLogName,
66+
currentBranch.simpleLogName,
67+
)
68+
},
69+
onClick = onPullFromRemoteBranch,
7070
)
7171

7272
add(ContextMenuElement.ContextSeparator)
7373
}
7474

7575
if (isLocal) {
76-
add(
77-
ContextMenuElement.ContextTextEntry(
78-
label = "Change default upstream branch",
79-
onClick = onChangeDefaultUpstreamBranch
80-
),
76+
addContextMenu(
77+
composableLabel = { stringResource(Res.string.branch_context_menu_change_default_upstream_branch) },
78+
onClick = onChangeDefaultUpstreamBranch
8179
)
8280

8381
add(ContextMenuElement.ContextSeparator)
8482
}
8583

8684
if (!isLocal) {
87-
add(
88-
ContextMenuElement.ContextTextEntry(
89-
label = "Delete remote branch",
90-
icon = { painterResource(Res.drawable.delete) },
91-
onClick = onDeleteRemoteBranch
92-
),
85+
addContextMenu(
86+
composableLabel = { stringResource(Res.string.branch_context_menu_delete_remote_branch) },
87+
icon = { painterResource(Res.drawable.delete) },
88+
onClick = onDeleteRemoteBranch,
9389
)
9490

9591
add(ContextMenuElement.ContextSeparator)
9692
}
9793

9894
if (isLocal && !isCurrentBranch) {
99-
add(
100-
ContextMenuElement.ContextTextEntry(
101-
label = "Delete branch",
102-
icon = { painterResource(Res.drawable.delete) },
103-
onClick = onDeleteBranch
104-
)
95+
addContextMenu(
96+
composableLabel = { stringResource(Res.string.branch_context_menu_delete_branch) },
97+
icon = { painterResource(Res.drawable.delete) },
98+
onClick = onDeleteBranch,
10599
)
106100

107101
add(ContextMenuElement.ContextSeparator)
108102
}
109103

110-
add(
111-
ContextMenuElement.ContextTextEntry(
112-
label = "Copy branch name",
113-
icon = { painterResource(Res.drawable.copy) },
114-
onClick = {
115-
onCopyBranchNameToClipboard()
116-
}
117-
)
104+
addContextMenu(
105+
composableLabel = { stringResource(Res.string.branch_context_menu_copy_branch_name) },
106+
icon = { painterResource(Res.drawable.copy) },
107+
onClick = {
108+
onCopyBranchNameToClipboard()
109+
}
118110
)
119111
}
120112
}

src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/CommitedChangesEntriesContextMenu.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.jetpackduba.gitnuro.ui.context_menu
22

3-
import androidx.compose.foundation.ExperimentalFoundationApi
4-
import com.jetpackduba.gitnuro.generated.resources.Res
5-
import com.jetpackduba.gitnuro.generated.resources.blame
6-
import com.jetpackduba.gitnuro.generated.resources.history
3+
import com.jetpackduba.gitnuro.generated.resources.*
74
import org.eclipse.jgit.diff.DiffEntry
85
import org.jetbrains.compose.resources.painterResource
6+
import org.jetbrains.compose.resources.stringResource
97

10-
@OptIn(ExperimentalFoundationApi::class)
118
fun committedChangesEntriesContextMenuItems(
129
diffEntry: DiffEntry,
1310
onBlame: () -> Unit,
@@ -17,19 +14,15 @@ fun committedChangesEntriesContextMenuItems(
1714
if (diffEntry.changeType != DiffEntry.ChangeType.ADD ||
1815
diffEntry.changeType != DiffEntry.ChangeType.DELETE
1916
) {
20-
add(
21-
ContextMenuElement.ContextTextEntry(
22-
label = "Blame file",
23-
icon = { painterResource(Res.drawable.blame) },
24-
onClick = onBlame,
25-
)
17+
addContextMenu(
18+
composableLabel = { stringResource(Res.string.committed_changes_context_menu_blame_file) },
19+
icon = { painterResource(Res.drawable.blame) },
20+
onClick = onBlame,
2621
)
27-
add(
28-
ContextMenuElement.ContextTextEntry(
29-
label = "File history",
30-
icon = { painterResource(Res.drawable.history) },
31-
onClick = onHistory,
32-
)
22+
addContextMenu(
23+
composableLabel = { stringResource(Res.string.committed_changes_context_menu_file_history) },
24+
icon = { painterResource(Res.drawable.history) },
25+
onClick = onHistory,
3326
)
3427
}
3528
}

src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/ContextMenu.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,18 @@ class AppContextMenuRepresentation : ContextMenuRepresentation {
461461
}
462462
}
463463
}
464+
}
465+
466+
fun MutableList<ContextMenuElement>.addContextMenu(
467+
composableLabel: @Composable (() -> String),
468+
icon: @Composable (() -> Painter)? = null,
469+
onClick: () -> Unit = {},
470+
) {
471+
this.add(
472+
ContextMenuElement.ContextTextEntry(
473+
composableLabel = composableLabel,
474+
icon = icon,
475+
onClick = onClick,
476+
)
477+
)
464478
}

src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/LogContextMenu.kt

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
44
import androidx.compose.ui.graphics.painter.Painter
55
import com.jetpackduba.gitnuro.generated.resources.*
66
import org.jetbrains.compose.resources.painterResource
7+
import org.jetbrains.compose.resources.stringResource
78

89
fun logContextMenu(
910
onCheckoutCommit: () -> Unit,
@@ -16,17 +17,17 @@ fun logContextMenu(
1617
isLastCommit: Boolean,
1718
) = mutableListOf<ContextMenuElement>().apply {
1819
addContextMenu(
19-
label = "Checkout commit",
20+
composableLabel = { stringResource(Res.string.log_context_menu_checkout_commit) },
2021
icon = { painterResource(Res.drawable.start) },
2122
onClick = onCheckoutCommit
2223
)
2324
addContextMenu(
24-
label = "Create branch",
25+
composableLabel = { stringResource(Res.string.log_context_menu_create_branch) },
2526
icon = { painterResource(Res.drawable.branch) },
2627
onClick = onCreateNewBranch
2728
)
2829
addContextMenu(
29-
label = "Create tag",
30+
composableLabel = { stringResource(Res.string.log_context_menu_create_tag) },
3031
icon = { painterResource(Res.drawable.tag) },
3132
onClick = onCreateNewTag
3233
)
@@ -35,37 +36,23 @@ fun logContextMenu(
3536

3637
if (!isLastCommit) {
3738
addContextMenu(
38-
label = "Rebase interactive",
39+
composableLabel = { stringResource(Res.string.log_context_menu_rebase_interactive) },
3940
onClick = onRebaseInteractive
4041
)
4142
}
4243

4344
addContextMenu(
44-
label = "Revert commit",
45+
composableLabel = { stringResource(Res.string.log_context_menu_revert_commit) },
4546
icon = { painterResource(Res.drawable.revert) },
4647
onClick = onRevertCommit
4748
)
4849
addContextMenu(
49-
label = "Cherry-pick commit",
50+
composableLabel = { stringResource(Res.string.log_context_menu_cherry_pick_commit) },
5051
onClick = onCherryPickCommit
5152
)
5253
addContextMenu(
53-
label = "Reset current branch to this commit",
54+
composableLabel = { stringResource(Res.string.log_context_menu_reset_current_branch_to_commit) },
5455
icon = { painterResource(Res.drawable.undo) },
5556
onClick = onResetBranch
5657
)
5758
}
58-
59-
fun MutableList<ContextMenuElement>.addContextMenu(
60-
label: String,
61-
icon: @Composable (() -> Painter)? = null,
62-
onClick: () -> Unit = {},
63-
) {
64-
this.add(
65-
ContextMenuElement.ContextTextEntry(
66-
label = label,
67-
icon = icon,
68-
onClick = onClick,
69-
)
70-
)
71-
}

src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/PullContextMenu.kt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
package com.jetpackduba.gitnuro.ui.context_menu
22

3+
import com.jetpackduba.gitnuro.generated.resources.Res
4+
import com.jetpackduba.gitnuro.generated.resources.pull_context_menu_fetch_all
5+
import com.jetpackduba.gitnuro.generated.resources.pull_context_menu_pull_with_merge
6+
import com.jetpackduba.gitnuro.generated.resources.pull_context_menu_pull_with_rebase
7+
import org.jetbrains.compose.resources.stringResource
8+
39
fun pullContextMenuItems(
410
onPullWith: () -> Unit,
511
onFetchAll: () -> Unit,
612
isPullWithRebaseDefault: Boolean,
713
): List<ContextMenuElement> {
8-
val pullWithText = if (isPullWithRebaseDefault) {
9-
"Pull with merge"
10-
} else {
11-
"Pull with rebase"
12-
}
13-
1414
return mutableListOf(
1515
ContextMenuElement.ContextTextEntry(
16-
label = pullWithText,
16+
composableLabel = {
17+
if (isPullWithRebaseDefault) {
18+
stringResource(Res.string.pull_context_menu_pull_with_merge)
19+
} else {
20+
stringResource(Res.string.pull_context_menu_pull_with_rebase)
21+
}
22+
},
1723
onClick = onPullWith,
1824
),
1925
ContextMenuElement.ContextTextEntry(
20-
label = "Fetch all",
26+
composableLabel = { stringResource(Res.string.pull_context_menu_fetch_all) },
2127
onClick = onFetchAll,
2228
),
2329
)

0 commit comments

Comments
 (0)