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
@@ -6,6 +6,8 @@ import eu.lixko.ts3j.client.config.Bookmark;
import eu.lixko.ts3j.client.config.Bookmarks;
import eu.lixko.ts3j.client.config.IdentityStore;
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.TeamSpeakSettingsDb;
@@ -26,6 +28,8 @@ import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
@@ -46,6 +50,7 @@ public final class BookmarksDialog extends JDialog {
private final Bookmarks bookmarks;
private final IdentityStore identities;
private final Settings settings;
private final Sessions sessions;
private final Consumer<Bookmark> onConnect;
private final Runnable onChanged;
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 JPasswordField password = new JPasswordField();
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 JCheckBox connectOnStartup = new JCheckBox("Connect on startup");
private final JCheckBox myTeamSpeakFeatures = new JCheckBox("Enable myTeamSpeak features");
@@ -68,11 +74,12 @@ public final class BookmarksDialog extends JDialog {
private Bookmark editing;
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);
this.bookmarks = bookmarks;
this.identities = identities;
this.settings = settings;
this.sessions = sessions;
this.onConnect = onConnect;
this.onChanged = onChanged;
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. "
+ "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;
addRow(panel, row++, "Label:", label);
addRow(panel, row++, "Address:", address);
addRow(panel, row++, "Port:", port);
addRow(panel, row++, "Nickname:", nick);
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++, "Identity:", identity);
addRow(panel, row++, "", connectOnStartup);
@@ -214,6 +233,39 @@ public final class BookmarksDialog extends JDialog {
connectOnStartup.setSelected(b != null && b.connectOnStartup);
myTeamSpeakFeatures.setSelected(b == null || b.myTeamSpeakFeatures);
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. */
@@ -410,7 +410,7 @@ public final class MainFrame extends JFrame implements ServerTabPane.Listener {
@Override
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);
}
});