Add default channel to bookmarks
Bookmarks can store a channel to join on connect, given either as a "/"-separated path or a channel id, plus an optional channel password. "Add bookmark" offers to remember the channel you are currently in. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -124,6 +124,10 @@ public final class BookmarksDialog extends JDialog {
|
||||
JTextField port = new JTextField(Integer.toString(b.port));
|
||||
JTextField nick = new JTextField(b.nickname == null ? "" : b.nickname);
|
||||
JPasswordField password = new JPasswordField(b.password == null ? "" : b.password);
|
||||
JTextField channel = new JTextField(b.channel == null ? "" : b.channel);
|
||||
channel.setToolTipText("Channel path, e.g. \"Lobby/Games\", or a channel id. "
|
||||
+ "Leave empty for the server's default channel.");
|
||||
JPasswordField channelPassword = new JPasswordField(b.channelPassword == null ? "" : b.channelPassword);
|
||||
IdentityChooser identity = new IdentityChooser(identities, true, b.identityId);
|
||||
|
||||
JPanel form = new JPanel(new GridLayout(0, 1, 0, 2));
|
||||
@@ -137,6 +141,10 @@ public final class BookmarksDialog extends JDialog {
|
||||
form.add(nick);
|
||||
form.add(new JLabel("Password (optional):"));
|
||||
form.add(password);
|
||||
form.add(new JLabel("Default channel (path or id, optional):"));
|
||||
form.add(channel);
|
||||
form.add(new JLabel("Channel password (optional):"));
|
||||
form.add(channelPassword);
|
||||
form.add(new JLabel("Identity:"));
|
||||
form.add(identity);
|
||||
|
||||
@@ -157,6 +165,8 @@ public final class BookmarksDialog extends JDialog {
|
||||
}
|
||||
b.nickname = nick.getText().trim();
|
||||
b.password = new String(password.getPassword());
|
||||
b.channel = channel.getText().trim();
|
||||
b.channelPassword = new String(channelPassword.getPassword());
|
||||
b.identityId = identity.getSelectedIdentityId();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.ts3client.net.TeamspeakConnection;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
@@ -23,6 +24,7 @@ import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.KeyStroke;
|
||||
@@ -30,6 +32,7 @@ import javax.swing.SwingUtilities;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.KeyEventDispatcher;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.event.KeyEvent;
|
||||
@@ -304,13 +307,17 @@ public final class MainFrame extends JFrame implements ConnectionListener, Serve
|
||||
ConnectDialog dlg = new ConnectDialog(this, settings, identities);
|
||||
dlg.setVisible(true);
|
||||
if (!dlg.isConfirmed()) return;
|
||||
startConnection(dlg.getAddress(), dlg.getPort(), dlg.getNickname(), dlg.getPassword(), dlg.getIdentityId());
|
||||
startConnection(dlg.getAddress(), dlg.getPort(), dlg.getNickname(), dlg.getPassword(), dlg.getIdentityId(),
|
||||
"", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param identityId identity to use, or empty for the default one
|
||||
* @param identityId identity to use, or empty for the default one
|
||||
* @param channel channel path to join on connect, or empty for the server's default channel
|
||||
* @param channelPassword password for that channel, if any
|
||||
*/
|
||||
private void startConnection(String address, int port, String nickname, String password, String identityId) {
|
||||
private void startConnection(String address, int port, String nickname, String password, String identityId,
|
||||
String channel, String channelPassword) {
|
||||
if (conn.isConnected()) {
|
||||
JOptionPane.showMessageDialog(this, "Already connected. Disconnect first.",
|
||||
"Connect", JOptionPane.INFORMATION_MESSAGE);
|
||||
@@ -320,7 +327,8 @@ public final class MainFrame extends JFrame implements ConnectionListener, Serve
|
||||
settings.nickname = nickname;
|
||||
settings.serverPassword = password;
|
||||
settings.save();
|
||||
chatPanel.appendSystem("Connecting to " + address + ":" + port + " …");
|
||||
chatPanel.appendSystem("Connecting to " + address + ":" + port
|
||||
+ (channel == null || channel.isBlank() ? "" : " (channel \"" + channel + "\")") + " …");
|
||||
|
||||
// Resolving may have to generate a first identity, so keep it off the EDT.
|
||||
onStatus("Loading identity…");
|
||||
@@ -336,13 +344,20 @@ public final class MainFrame extends JFrame implements ConnectionListener, Serve
|
||||
currentIdentityId = entry.getId();
|
||||
chatPanel.appendSystem("Using identity \"" + entry.getName() + "\".");
|
||||
});
|
||||
conn.connect(address, port, nickname, password, entry.getIdentity());
|
||||
conn.connect(address, port, nickname, password, entry.getIdentity(), channel, channelPassword);
|
||||
}, "identity-resolve").start();
|
||||
}
|
||||
|
||||
private void connectToBookmark(Bookmark b) {
|
||||
String nick = (b.nickname != null && !b.nickname.isBlank()) ? b.nickname : settings.nickname;
|
||||
startConnection(b.address, b.port, nick, b.password, b.identityId);
|
||||
startConnection(b.address, b.port, nick, b.password, b.identityId, b.channel, b.channelPassword);
|
||||
}
|
||||
|
||||
/** Path of the channel we are currently in, or empty when not connected. */
|
||||
private String currentChannelPath() {
|
||||
if (conn == null || !conn.isConnected()) return "";
|
||||
ClientEntry self = conn.getModel().getClient(conn.getSelfClientId());
|
||||
return self == null ? "" : conn.getModel().channelPath(self.channelId);
|
||||
}
|
||||
|
||||
private void addCurrentServerBookmark() {
|
||||
@@ -356,10 +371,22 @@ public final class MainFrame extends JFrame implements ConnectionListener, Serve
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
String label = JOptionPane.showInputDialog(this, "Bookmark label:", addr);
|
||||
if (label == null) return;
|
||||
String channelPath = currentChannelPath();
|
||||
|
||||
JTextField labelField = new JTextField(addr);
|
||||
JCheckBox joinChannel = new JCheckBox("Join \"" + channelPath + "\" on connect", !channelPath.isEmpty());
|
||||
JPanel form = new JPanel(new GridLayout(0, 1, 0, 2));
|
||||
form.add(new JLabel("Bookmark label:"));
|
||||
form.add(labelField);
|
||||
if (!channelPath.isEmpty()) form.add(joinChannel);
|
||||
if (JOptionPane.showConfirmDialog(this, form, "Add bookmark",
|
||||
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) != JOptionPane.OK_OPTION) {
|
||||
return;
|
||||
}
|
||||
String label = labelField.getText();
|
||||
Bookmark bookmark = new Bookmark(label.trim(), addr, port, settings.nickname, settings.serverPassword);
|
||||
bookmark.identityId = currentIdentityId;
|
||||
if (joinChannel.isSelected()) bookmark.channel = channelPath;
|
||||
bookmarks.add(bookmark);
|
||||
bookmarks.save();
|
||||
rebuildBookmarksMenu();
|
||||
|
||||
Reference in New Issue
Block a user