@@ -15,9 +15,9 @@ import androidx.compose.ui.unit.dp
1515import dalvikus.composeapp.generated.resources.*
1616import me.lkl.dalvikus.tabManager
1717import me.lkl.dalvikus.tabs.TabElement
18+ import me.lkl.dalvikus.tabs.WelcomeTab
1819import org.jetbrains.compose.resources.stringResource
1920
20- @OptIn(ExperimentalMaterial3Api ::class )
2121@Composable
2222fun TabView (
2323) {
@@ -27,82 +27,101 @@ fun TabView(
2727 UnsavedChangesDialog (tabManager, showCloseDialog, pendingCloseTab)
2828 }
2929 Column {
30- if (tabManager.tabs.isNotEmpty()) {
31- SecondaryScrollableTabRow (
32- containerColor = MaterialTheme .colorScheme.surfaceContainerHigh,
33- selectedTabIndex = tabManager.selectedTabIndex,
34- modifier = Modifier .fillMaxWidth(),
35- edgePadding = 0 .dp,
36- ) {
37- tabManager.tabs.forEachIndexed { index, tab ->
38- val tooltipState = rememberTooltipState(isPersistent = false )
39- Tab (
40- selected = tabManager.selectedTabIndex == index,
41- onClick = { tabManager.selectTab(index) },
42- text = {
43- var unsaved by tab.hasUnsavedChanges
44- Row (
45- verticalAlignment = Alignment .CenterVertically ,
46- modifier = Modifier .padding(end = 8 .dp)
47- ) {
48- Icon (
49- imageVector = tab.tabIcon,
50- contentDescription = null ,
51- modifier = Modifier .size(16 .dp)
52- )
53- Spacer (modifier = Modifier .width(4 .dp))
54- TooltipBox (
55- positionProvider = TooltipDefaults .rememberTooltipPositionProvider(8 .dp),
56- tooltip = {
57- RichTooltip (
58- title = { Text (stringResource(Res .string.tooltip_tab_title)) }
59- ) {
60- Text (
61- tab.contentProvider.getSourcePath()
62- ? : stringResource(Res .string.unknown_source),
63- )
64- }
65- },
66- state = tooltipState
67- ) {
68- Text (
69- if (unsaved) " ${tab.tabName()} *" else tab.tabName(),
70- maxLines = 1 ,
71- overflow = TextOverflow .Ellipsis ,
72- style = MaterialTheme .typography.bodyLarge
73- )
30+ SecondaryScrollableTabRow (
31+ containerColor = MaterialTheme .colorScheme.surfaceContainerHigh,
32+ selectedTabIndex = tabManager.selectedTabIndex,
33+ modifier = Modifier .fillMaxWidth(),
34+ edgePadding = 0 .dp,
35+ ) {
36+ if (tabManager.tabs.isEmpty()) {
37+ Tab (
38+ selected = true ,
39+ onClick = { /* no-op */ },
40+ text = {
41+ TabViewContent (
42+ tab = WelcomeTab (),
43+ onClose = null
44+ )
45+ },
46+ )
47+ }
48+ tabManager.tabs.forEachIndexed { index, tab ->
49+ Tab (
50+ selected = tabManager.selectedTabIndex == index,
51+ onClick = { tabManager.selectTab(index) },
52+ text = {
53+ TabViewContent (
54+ tab = tab,
55+ onClose = {
56+ if (tab.hasUnsavedChanges.value) {
57+ pendingCloseTab.value = tab
58+ showCloseDialog.value = true
59+ } else {
60+ tabManager.closeTab(tab)
7461 }
62+ },
63+ )
64+ },
65+ )
66+ }
67+ }
7568
76- Spacer (modifier = Modifier .width(4 .dp))
77- if (tabManager.tabs.size > 1 ) {
78- Icon (
79- imageVector = Icons .Default .Close ,
80- contentDescription = null ,
81- modifier = Modifier
82- .size(16 .dp)
83- .clickable {
84- if (tabManager.tabs.size > 1 ) {
85- if (unsaved) {
86- pendingCloseTab.value = tab
87- showCloseDialog.value = true
88- } else {
89- tabManager.closeTab(tab)
90- }
91- }
92- }
93- )
94- }
95- }
96- }
69+ TabContentRenderer (tab = tabManager.currentTab)
70+ }
71+ }
72+
73+ @OptIn(ExperimentalMaterial3Api ::class )
74+ @Composable
75+ fun TabViewContent (tab : TabElement , onClose : (() -> Unit )? ) {
76+ var unsaved by tab.hasUnsavedChanges
77+ val tooltipState = rememberTooltipState(isPersistent = false )
78+
79+ Row (
80+ verticalAlignment = Alignment .CenterVertically
81+ ) {
82+ Icon (
83+ imageVector = tab.tabIcon,
84+ contentDescription = null ,
85+ modifier = Modifier .size(16 .dp)
86+ )
87+ Spacer (modifier = Modifier .width(4 .dp))
88+ TooltipBox (
89+ positionProvider = TooltipDefaults .rememberTooltipPositionProvider(8 .dp),
90+ tooltip = {
91+ RichTooltip (
92+ title = { Text (stringResource(Res .string.tooltip_tab_title)) }
93+ ) {
94+ Text (
95+ tab.contentProvider.getSourcePath()
96+ ? : stringResource(Res .string.unknown_source),
9797 )
9898 }
99- }
99+ },
100+ state = tooltipState
101+ ) {
102+ Text (
103+ if (unsaved) " ${tab.tabName()} *" else tab.tabName(),
104+ maxLines = 1 ,
105+ overflow = TextOverflow .Ellipsis ,
106+ style = MaterialTheme .typography.bodyLarge
107+ )
108+ }
100109
101- TabContentRenderer (tab = tabManager.currentTab)
110+ Spacer (modifier = Modifier .width(4 .dp))
111+ if (onClose != null ) {
112+ Icon (
113+ imageVector = Icons .Default .Close ,
114+ contentDescription = null ,
115+ modifier = Modifier .size(16 .dp)
116+ .clickable {
117+ onClose()
118+ }
119+ )
102120 }
103121 }
104122}
105123
124+
106125@Composable
107126fun UnsavedChangesDialog (
108127 tabManager : TabManager ,
0 commit comments