Offlin33er commited on
Commit
6e07290
·
verified ·
1 Parent(s): a44a51e

Pivot: command palette — primary UI of chrome-less Nova

Browse files
app/src/main/java/dev/nova/browser/CommandPalette.kt ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ package dev.nova.browser
2
+
3
+ import androidx.compose.foundation.layout.*
4
+ import androidx.compose.foundation.lazy.LazyColumn
5
+ import androidx.compose.foundation.lazy.items
6
+ import androidx.compose.material3.*
7
+ import androidx.compose.runtime.Composable
8
+ import androidx.compose.runtime.getValue
9
+ import androidx.compose.runtime.mutableStateOf
10
+ import androidx.compose.runtime.remember
11
+ import androidx.compose.runtime.setValue
12
+ import androidx.compose.ui.Alignment
13
+ import androidx.compose.ui.Modifier
14
+ import androidx.compose.ui.text.style.TextOverflow
15
+ import androidx.compose.ui.unit.dp
16
+
17
+ /**
18
+ * Nova's primary UI after the pivot: a command palette. The user types a
19
+ * command, a URL, or a search — the palette routes it. There is no URL bar
20
+ * and no toolbar; content is edge-to-edge and the palette is summoned via
21
+ * the floating ⌘ button.
22
+ */
23
+ @Composable
24
+ fun CommandPalette(
25
+ tabCount: Int,
26
+ activeTabId: Int?,
27
+ onSubmit: (String) -> Unit,
28
+ onCommand: (String) -> Unit,
29
+ onDismiss: () -> Unit,
30
+ ) {
31
+ var query by remember { mutableStateOf("") }
32
+
33
+ val commands: List<Pair<String, String>> = listOf(
34
+ "New tab" to "new_tab",
35
+ "Close current tab" to "close_tab",
36
+ "Reload page" to "reload",
37
+ "Open tab tray" to "tray",
38
+ "Add-ons manager" to "addons",
39
+ "Dev console" to "console",
40
+ "Clear console" to "clear_console",
41
+ )
42
+
43
+ val filteredCommands =
44
+ if (query.isBlank()) commands
45
+ else commands.filter { it.first.contains(query.trim(), ignoreCase = true) }
46
+
47
+ Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surface) {
48
+ Column(Modifier.fillMaxSize().padding(12.dp)) {
49
+ Row(verticalAlignment = Alignment.CenterVertically) {
50
+ Text(
51
+ "Nova ⌘",
52
+ style = MaterialTheme.typography.titleMedium,
53
+ modifier = Modifier.weight(1f),
54
+ )
55
+ Text(
56
+ "$tabCount tab(s) open",
57
+ style = MaterialTheme.typography.labelSmall,
58
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
59
+ )
60
+ TextButton(onClick = onDismiss) { Text("Done") }
61
+ }
62
+
63
+ OutlinedTextField(
64
+ value = query,
65
+ onValueChange = { query = it },
66
+ label = { Text("Command, URL, or search…") },
67
+ singleLine = true,
68
+ modifier = Modifier.fillMaxWidth(),
69
+ )
70
+
71
+ // Dynamic action rows for free-form input
72
+ val q = query.trim()
73
+ if (q.isNotBlank()) {
74
+ ListItem(
75
+ headlineContent = {
76
+ Text("Go to $q", maxLines = 1, overflow = TextOverflow.Ellipsis)
77
+ },
78
+ modifier = Modifier.fillMaxWidth(),
79
+ )
80
+ // Tap targets for the dynamic rows
81
+ Surface(
82
+ onClick = { onSubmit(q) },
83
+ tonalElevation = 2.dp,
84
+ modifier = Modifier.fillMaxWidth(),
85
+ ) { Text("↗ Navigate", style = MaterialTheme.typography.labelSmall, modifier = Modifier.padding(8.dp)) }
86
+ Surface(
87
+ onClick = { onSubmit("https://duckduckgo.com/?q=" + android.net.Uri.encode(q)) },
88
+ tonalElevation = 2.dp,
89
+ modifier = Modifier.fillMaxWidth(),
90
+ ) { Text("🔍 Search DuckDuckGo", style = MaterialTheme.typography.labelSmall, modifier = Modifier.padding(8.dp)) }
91
+ }
92
+
93
+ HorizontalDivider(Modifier.padding(vertical = 6.dp))
94
+
95
+ LazyColumn(Modifier.weight(1f)) {
96
+ items(filteredCommands.size) { idx ->
97
+ val (label, id) = filteredCommands[idx]
98
+ ListItem(
99
+ headlineContent = { Text(label) },
100
+ modifier = Modifier.fillMaxWidth(),
101
+ )
102
+ // commands are triggered from the clickable text row below
103
+ }
104
+ items(filteredCommands.size) { idx ->
105
+ val (label, id) = filteredCommands[idx]
106
+ TextButton(
107
+ onClick = { onCommand(id) },
108
+ modifier = Modifier.fillMaxWidth(),
109
+ ) { Text("→ $label", maxLines = 1, overflow = TextOverflow.Ellipsis) }
110
+ }
111
+ }
112
+
113
+ Text(
114
+ "Active tab: ${activeTabId ?: "none"} · unrestricted mode: tracking protection off, permissions auto-granted, about:config on",
115
+ style = MaterialTheme.typography.labelSmall,
116
+ color = MaterialTheme.colorScheme.onSurfaceVariant,
117
+ modifier = Modifier.padding(top = 8.dp),
118
+ )
119
+ }
120
+ }
121
+ }