Bookmarks: "this channel" button instead of the channel's "Add to bookmarks"

The bookmark editors (desktop dialog, Android screen) get TeamSpeak's
button beside the default channel, with its MAKE_CURRENT_CHANNEL_DEFAULT
icon: it takes the channel we are in, enabled while we are on the server
the form's address and port lead to (Sessions.connectedTo). The Android
channel sheet drops "Add to bookmarks"; the server sheet keeps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 21:03:04 +00:00
co-authored by Claude Opus 5.5
parent 173e710960
commit 3948db69bb
7 changed files with 86 additions and 14 deletions
@@ -347,10 +347,10 @@ class SessionController(private val context: Context) {
} }
/** The channels of a server we are on at [host]:[port], to pick one to join. */ /** The channels of a server we are on at [host]:[port], to pick one to join. */
fun channelPathsAt(host: String, port: Int): List<String> = fun channelPathsAt(host: String, port: Int): List<String> = sessions.connectedTo(host, port)?.channelPaths().orEmpty()
_servers.value.firstOrNull {
it.isConnected && it.session.port() == port && it.session.address().equals(host.trim(), ignoreCase = true) /** The channel we are in on the server at [host]:[port]; null when we are not on it. */
}?.session?.channelPaths().orEmpty() fun currentChannelAt(host: String, port: Int): String? = sessions.connectedTo(host, port)?.currentChannelPath()
fun removeBookmark(bookmark: Bookmark) { fun removeBookmark(bookmark: Bookmark) {
val index = bookmarkStore.all().indexOf(bookmark) val index = bookmarkStore.all().indexOf(bookmark)
@@ -15,6 +15,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuAnchorType import androidx.compose.material3.ExposedDropdownMenuAnchorType
import androidx.compose.material3.ExposedDropdownMenuBox import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.ExposedDropdownMenuDefaults import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.Text import androidx.compose.material3.Text
@@ -117,7 +118,10 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
val paths = remember(address) { val paths = remember(address) {
SessionController.parseAddress(address).let { (host, port) -> vm.channelPathsAt(host, port) } SessionController.parseAddress(address).let { (host, port) -> vm.channelPathsAt(host, port) }
} }
ChannelField(channel, paths) { channel = it } val current = remember(address) {
SessionController.parseAddress(address).let { (host, port) -> vm.currentChannelAt(host, port) }
}
ChannelField(channel, paths, current) { channel = it }
OutlinedTextField(channelPassword, { channelPassword = it }, Modifier.fillMaxWidth(), OutlinedTextField(channelPassword, { channelPassword = it }, Modifier.fillMaxWidth(),
label = { Text("Channel password") }, singleLine = true, label = { Text("Channel password") }, singleLine = true,
visualTransformation = PasswordVisualTransformation(), visualTransformation = PasswordVisualTransformation(),
@@ -141,10 +145,13 @@ fun BookmarkScreen(vm: SessionController, edit: BookmarkEdit, onDone: () -> Unit
} }
} }
/** The channel to join, typed or picked among [paths] of the server when we are on it. */ /**
* The channel to join, typed or picked among [paths] of the server when we are on it,
* or taken from [current], the one we are in there.
*/
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
private fun ChannelField(channel: String, paths: List<String>, onChange: (String) -> Unit) { private fun ChannelField(channel: String, paths: List<String>, current: String?, onChange: (String) -> Unit) {
var open by remember { mutableStateOf(false) } var open by remember { mutableStateOf(false) }
// A channel already picked lists them all, for picking another. // A channel already picked lists them all, for picking another.
val matches = if (channel in paths) paths else paths.filter { it.contains(channel.trim(), ignoreCase = true) } val matches = if (channel in paths) paths else paths.filter { it.contains(channel.trim(), ignoreCase = true) }
@@ -154,7 +161,14 @@ private fun ChannelField(channel: String, paths: List<String>, onChange: (String
channel, { onChange(it); open = true }, singleLine = true, channel, { onChange(it); open = true }, singleLine = true,
label = { Text("Channel") }, label = { Text("Channel") },
placeholder = { Text("Default") }, placeholder = { Text("Default") },
trailingIcon = if (paths.isEmpty()) null else ({ ExposedDropdownMenuDefaults.TrailingIcon(expanded) }), trailingIcon = {
Row(verticalAlignment = Alignment.CenterVertically) {
IconButton(onClick = { current?.let(onChange) }, enabled = current != null) {
PackIcon(listOf("MAKE_CURRENT_CHANNEL_DEFAULT", "CHANNEL_SWITCH"), "This channel")
}
if (paths.isNotEmpty()) ExposedDropdownMenuDefaults.TrailingIcon(expanded)
}
},
modifier = Modifier.fillMaxWidth().menuAnchor(ExposedDropdownMenuAnchorType.PrimaryEditable), modifier = Modifier.fillMaxWidth().menuAnchor(ExposedDropdownMenuAnchorType.PrimaryEditable),
) )
ExposedDropdownMenu(expanded, { open = false }) { ExposedDropdownMenu(expanded, { open = false }) {
@@ -428,7 +428,6 @@ fun ServerScreen(
onDismiss = { channelSheet = null }, onDismiss = { channelSheet = null },
onJoin = { join(channel); channelSheet = null }, onJoin = { join(channel); channelSheet = null },
onSubscribe = { server.setSubscribed(id, it); channelSheet = null }, onSubscribe = { server.setSubscribed(id, it); channelSheet = null },
onBookmark = { channelSheet = null; bookmarkHere(id) },
onWhisper = if (state.whisperControls) ({ channelSheet = null; server.whisperToChannel(id) }) else null, onWhisper = if (state.whisperControls) ({ channelSheet = null; server.whisperToChannel(id) }) else null,
onAddToWhisperList = if (state.whisperControls) ({ onAddToWhisperList = if (state.whisperControls) ({
channelSheet = null channelSheet = null
@@ -145,7 +145,6 @@ fun ChannelSheet(
onDismiss: () -> Unit, onDismiss: () -> Unit,
onJoin: () -> Unit, onJoin: () -> Unit,
onSubscribe: (Boolean) -> Unit, onSubscribe: (Boolean) -> Unit,
onBookmark: () -> Unit,
/** Both null when whisper controls are hidden. */ /** Both null when whisper controls are hidden. */
onWhisper: (() -> Unit)?, onWhisper: (() -> Unit)?,
onAddToWhisperList: (() -> Unit)?, onAddToWhisperList: (() -> Unit)?,
@@ -171,7 +170,6 @@ fun ChannelSheet(
onWhisper?.let { Action("WHISPER", "Whisper", onClick = it) } onWhisper?.let { Action("WHISPER", "Whisper", onClick = it) }
onAddToWhisperList?.let { Action("ON_WHISPERLIST", "Add to whisper list…", onClick = it) } onAddToWhisperList?.let { Action("ON_WHISPERLIST", "Add to whisper list…", onClick = it) }
onFiles?.let { Action("FILETRANSFER", "Browse files", onClick = it) } onFiles?.let { Action("FILETRANSFER", "Browse files", onClick = it) }
Action("BOOKMARK_ADD", "Add to bookmarks", onClick = onBookmark)
onCreateSub?.let { Action("CHANNEL_CREATE_SUB", "Create sub-channel", onClick = it) } onCreateSub?.let { Action("CHANNEL_CREATE_SUB", "Create sub-channel", onClick = it) }
onEdit?.let { Action("CHANNEL_EDIT", "Edit channel", onClick = it) } onEdit?.let { Action("CHANNEL_EDIT", "Edit channel", onClick = it) }
onDelete?.let { Action("CHANNEL_DELETE", "Delete channel", onClick = it) } onDelete?.let { Action("CHANNEL_DELETE", "Delete channel", onClick = it) }
@@ -45,6 +45,15 @@ public final class Sessions {
assignMicrophoneIfFree(); assignMicrophoneIfFree();
} }
/** The session connected to the server at {@code address}:{@code port}, or null when we are not on it. */
public ServerSession connectedTo(String address, int port) {
if (address == null) return null;
for (ServerSession s : sessions) {
if (s.isConnected() && s.port() == port && address.trim().equalsIgnoreCase(s.address())) return s;
}
return null;
}
public boolean anyConnected() { public boolean anyConnected() {
for (ServerSession s : sessions) { for (ServerSession s : sessions) {
if (s.isConnected()) return true; if (s.isConnected()) return true;
@@ -6,6 +6,8 @@ import eu.lixko.ts3j.client.config.Bookmark;
import eu.lixko.ts3j.client.config.Bookmarks; import eu.lixko.ts3j.client.config.Bookmarks;
import eu.lixko.ts3j.client.config.IdentityStore; import eu.lixko.ts3j.client.config.IdentityStore;
import eu.lixko.ts3j.client.config.Settings; import eu.lixko.ts3j.client.config.Settings;
import eu.lixko.ts3j.client.session.ServerSession;
import eu.lixko.ts3j.client.session.Sessions;
import eu.lixko.ts3j.client.teamspeak.TeamSpeakImporter; import eu.lixko.ts3j.client.teamspeak.TeamSpeakImporter;
import eu.lixko.ts3j.client.teamspeak.TeamSpeakSettingsDb; import eu.lixko.ts3j.client.teamspeak.TeamSpeakSettingsDb;
@@ -26,6 +28,8 @@ import javax.swing.JScrollPane;
import javax.swing.JSplitPane; import javax.swing.JSplitPane;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.ListSelectionModel; import javax.swing.ListSelectionModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
@@ -46,6 +50,7 @@ public final class BookmarksDialog extends JDialog {
private final Bookmarks bookmarks; private final Bookmarks bookmarks;
private final IdentityStore identities; private final IdentityStore identities;
private final Settings settings; private final Settings settings;
private final Sessions sessions;
private final Consumer<Bookmark> onConnect; private final Consumer<Bookmark> onConnect;
private final Runnable onChanged; private final Runnable onChanged;
private final DefaultListModel<Bookmark> listModel = new DefaultListModel<>(); private final DefaultListModel<Bookmark> listModel = new DefaultListModel<>();
@@ -57,6 +62,7 @@ public final class BookmarksDialog extends JDialog {
private final JTextField nick = new JTextField(); private final JTextField nick = new JTextField();
private final JPasswordField password = new JPasswordField(); private final JPasswordField password = new JPasswordField();
private final JTextField channel = new JTextField(); private final JTextField channel = new JTextField();
private final JButton thisChannel = new JButton(Icons.ofAny("MAKE_CURRENT_CHANNEL_DEFAULT", "CHANNEL_SWITCH"));
private final JPasswordField channelPassword = new JPasswordField(); private final JPasswordField channelPassword = new JPasswordField();
private final JCheckBox connectOnStartup = new JCheckBox("Connect on startup"); private final JCheckBox connectOnStartup = new JCheckBox("Connect on startup");
private final JCheckBox myTeamSpeakFeatures = new JCheckBox("Enable myTeamSpeak features"); private final JCheckBox myTeamSpeakFeatures = new JCheckBox("Enable myTeamSpeak features");
@@ -68,11 +74,12 @@ public final class BookmarksDialog extends JDialog {
private Bookmark editing; private Bookmark editing;
public BookmarksDialog(Frame owner, Bookmarks bookmarks, IdentityStore identities, Settings settings, public BookmarksDialog(Frame owner, Bookmarks bookmarks, IdentityStore identities, Settings settings,
Consumer<Bookmark> onConnect, Runnable onChanged) { Sessions sessions, Consumer<Bookmark> onConnect, Runnable onChanged) {
super(owner, "Manage Bookmarks", true); super(owner, "Manage Bookmarks", true);
this.bookmarks = bookmarks; this.bookmarks = bookmarks;
this.identities = identities; this.identities = identities;
this.settings = settings; this.settings = settings;
this.sessions = sessions;
this.onConnect = onConnect; this.onConnect = onConnect;
this.onChanged = onChanged; this.onChanged = onChanged;
this.identity = new IdentityChooser(identities, true, ""); this.identity = new IdentityChooser(identities, true, "");
@@ -135,13 +142,25 @@ public final class BookmarksDialog extends JDialog {
connectOnStartup.setToolTipText("Connect to this server automatically when the client starts. " connectOnStartup.setToolTipText("Connect to this server automatically when the client starts. "
+ "Several bookmarks may be flagged; each opens its own tab."); + "Several bookmarks may be flagged; each opens its own tab.");
thisChannel.setToolTipText("This channel");
if (thisChannel.getIcon() == null) thisChannel.setText("This channel");
thisChannel.addActionListener(e -> {
ServerSession on = sessionHere();
if (on != null) channel.setText(on.currentChannelPath());
});
onEdit(address, this::updateThisChannel);
onEdit(port, this::updateThisChannel);
JPanel channelRow = new JPanel(new BorderLayout(UIScale.scale(4), 0));
channelRow.add(channel, BorderLayout.CENTER);
channelRow.add(thisChannel, BorderLayout.EAST);
int row = 0; int row = 0;
addRow(panel, row++, "Label:", label); addRow(panel, row++, "Label:", label);
addRow(panel, row++, "Address:", address); addRow(panel, row++, "Address:", address);
addRow(panel, row++, "Port:", port); addRow(panel, row++, "Port:", port);
addRow(panel, row++, "Nickname:", nick); addRow(panel, row++, "Nickname:", nick);
addRow(panel, row++, "Password:", password); addRow(panel, row++, "Password:", password);
addRow(panel, row++, "Default channel:", channel); addRow(panel, row++, "Default channel:", channelRow);
addRow(panel, row++, "Channel password:", channelPassword); addRow(panel, row++, "Channel password:", channelPassword);
addRow(panel, row++, "Identity:", identity); addRow(panel, row++, "Identity:", identity);
addRow(panel, row++, "", connectOnStartup); addRow(panel, row++, "", connectOnStartup);
@@ -214,6 +233,39 @@ public final class BookmarksDialog extends JDialog {
connectOnStartup.setSelected(b != null && b.connectOnStartup); connectOnStartup.setSelected(b != null && b.connectOnStartup);
myTeamSpeakFeatures.setSelected(b == null || b.myTeamSpeakFeatures); myTeamSpeakFeatures.setSelected(b == null || b.myTeamSpeakFeatures);
identity.setSelectedIdentityId(b == null ? "" : nullToEmpty(b.identityId)); identity.setSelectedIdentityId(b == null ? "" : nullToEmpty(b.identityId));
updateThisChannel();
}
/** The server the form's address leads to, when we are on it. */
private ServerSession sessionHere() {
try {
return sessions.connectedTo(address.getText(), Integer.parseInt(port.getText().trim()));
} catch (NumberFormatException e) {
return null;
}
}
private void updateThisChannel() {
thisChannel.setEnabled(editing != null && sessionHere() != null);
}
private static void onEdit(JTextField field, Runnable listener) {
field.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
listener.run();
}
@Override
public void removeUpdate(DocumentEvent e) {
listener.run();
}
@Override
public void changedUpdate(DocumentEvent e) {
listener.run();
}
});
} }
/** Writes the form back into the bookmark it was loaded from. */ /** Writes the form back into the bookmark it was loaded from. */
@@ -410,7 +410,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
@Override @Override
public void onManageBookmarks() { public void onManageBookmarks() {
new BookmarksDialog(MainFrame.this, bookmarks, identities, settings, new BookmarksDialog(MainFrame.this, bookmarks, identities, settings, sessions,
MainFrame.this::connectToBookmark, menuBar::rebuildBookmarks).setVisible(true); MainFrame.this::connectToBookmark, menuBar::rebuildBookmarks).setVisible(true);
} }
}); });