Skip to content

Commit

Permalink
Updated to v0.26-b3.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Nov 11, 2023
2 parents 66bc47a + d13a57f commit d0d1a84
Show file tree
Hide file tree
Showing 33 changed files with 1,160 additions and 353 deletions.
4 changes: 4 additions & 0 deletions src/chatty/SettingsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public void defineSettings() {
addDefaultHotkey("0.7.3", "selection.toggle", "ctrl SPACE");
addDefaultHotkey("0.7.3", "selection.toggle", "ctrl S");
addDefaultHotkeyAppWide("0.9b1", "about", "F1");
addDefaultHotkeyAppWide("0.26-b3", "scroll.pageUp", "PAGE_UP");
addDefaultHotkeyAppWide("0.26-b3", "scroll.pageDown", "PAGE_DOWN");
settings.addList("hotkeys", getDefaultHotkeySettingValue(), Setting.LIST);
settings.addBoolean("globalHotkeysEnabled", true);
settings.addBoolean("inputHistoryMultirowRequireCtrl", true);
Expand Down Expand Up @@ -574,6 +576,8 @@ public void defineSettings() {
settings.addLong("nActivityTime", 10);
settings.addString("nCommand", "");
settings.addBoolean("nHideOnStart", false);
settings.addBoolean("nInfoMsgEnabled", false);
settings.addString("nInfoMsgTarget", "Notifications");

settings.addList("notifications", getDefaultNotificationSettingValue(), Setting.LIST);
settings.addList("nColorPresets", new ArrayList<>(), Setting.LIST);
Expand Down
79 changes: 56 additions & 23 deletions src/chatty/gui/DockedDialogHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package chatty.gui;

import chatty.Helper;
import chatty.gui.components.Channel;
import chatty.gui.components.menus.ContextMenu;
import chatty.util.MiscUtil;
Expand All @@ -15,6 +16,7 @@
import java.util.List;
import java.util.function.Consumer;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

/**
* Manages docking related actions, such as docking, undocking, settings and so
Expand Down Expand Up @@ -53,6 +55,7 @@ public class DockedDialogHelper {
private boolean autoOpen;
private boolean autoOpenActivity;
private boolean fixedChannel;
private String currentChannel;

private Consumer<String> channelChangeListener;

Expand Down Expand Up @@ -265,32 +268,53 @@ public void addToContextMenu(ContextMenu menu) {
// Channel Change
//--------------------------
if (channelChangeListener != null) {
String changeChanLabel = "Channel";
String openChansLabel = "Change to";
JMenu changeChanMenu = new JMenu(changeChanLabel);
JMenu openChansMenu = new JMenu(openChansLabel);
openChansMenu.setToolTipText("All open chans, active tabs marked with *");
menu.registerSubmenu(changeChanMenu);
menu.registerSubmenu(openChansMenu);
List<Channel> open = channels.getChannelsOfType(Channel.Type.CHANNEL);
Collections.sort(open, (o1, o2) -> {
// Stream name should always be available for regular channels
return o1.getChannel().compareTo(o2.getChannel());
});
for (Channel chan : open) {
// Add menu item for each channel, mark visible with *
menu.addItem("dockChangeChannel."+chan.getChannel(),
chan.getChannel()+(chan.getDockContent().isContentVisible() ? "*" : ""),
openChansLabel);
addChannelSelectionToContextMenu(menu,
channels.getChannelsOfType(Channel.Type.CHANNEL),
fixedChannel,
false, false, currentChannel);
}
}

public static void addChannelSelectionToContextMenu(ContextMenu menu,
List<Channel> open,
boolean fixedChannelEnabled,
boolean addAllEntry,
boolean showAll,
String currentChannel) {
String optionsLabel = "Options";
String openChansLabel = "Channel";
JMenu changeChanMenu = new JMenu(optionsLabel);
JMenu openChansMenu = new JMenu(openChansLabel);
openChansMenu.setToolTipText("All open chans, active tabs marked with *");
menu.registerSubmenu(changeChanMenu);
menu.registerSubmenu(openChansMenu);

Collections.sort(open, (o1, o2) -> {
// Stream name should always be available for regular channels
return o1.getChannel().compareTo(o2.getChannel());
});
if (!open.isEmpty()) {
menu.add(openChansMenu);
if (addAllEntry) {
menu.addCheckboxItem("dockChannelsShowAll", "All", openChansLabel, showAll);
menu.addSeparator(openChansLabel);
}
if (!open.isEmpty()) {
changeChanMenu.add(openChansMenu);
menu.addSeparator(changeChanLabel);
}
for (Channel chan : open) {
// Add menu item for each channel, mark visible with *
menu.addRadioItem("dockChangeChannel." + chan.getChannel(),
chan.getChannel() + (chan.getDockContent().isContentVisible() ? "*" : ""),
"chansGroup", openChansLabel);
}
if (currentChannel != null) {
JMenuItem selectedChannel = menu.getItem("dockChangeChannel." + currentChannel);
if (selectedChannel != null) {
selectedChannel.setSelected(true);
}
menu.add(changeChanMenu);
menu.addCheckboxItem("dockToggleFixedChannel", "Fixed", changeChanLabel, fixedChannel);
menu.getItem("dockToggleFixedChannel").setToolTipText("Stay on the channel it was opened on (or the first channel joined if it was open on start)");
}
menu.add(changeChanMenu);
menu.addCheckboxItem("dockToggleFixedChannel", "Channel Fixed", optionsLabel, fixedChannelEnabled);
menu.getItem("dockToggleFixedChannel").setToolTipText("Stay on the channel it was opened on (or the first channel joined if it was open on start)");
}

private class MyContextMenu extends ContextMenu {
Expand All @@ -312,6 +336,15 @@ public void channelChanged(String channel) {
}
}

/**
* Set the current channel for the context menu.
*
* @param channel
*/
public void setCurrentChannel(String channel) {
currentChannel = Helper.toChannel(channel);
}

public static abstract class DockedDialog {

/**
Expand Down
32 changes: 30 additions & 2 deletions src/chatty/gui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private void createGui() {
channels.getComponent().setPreferredSize(new Dimension(600,300));
add(channels.getComponent(), BorderLayout.CENTER);
channels.setChangeListener(new ChannelChangeListener());
routingManager = new RoutingManager(this, channels, styleManager, contextMenuListener);
routingManager = new RoutingManager(this, channels, styleManager, contextMenuListener, client.chatLog);

dockedDialogs = new DockedDialogManager(this, channels, client.settings);

Expand Down Expand Up @@ -825,6 +825,33 @@ public void actionPerformed(ActionEvent e) {
}
});

// Scroll
Consumer<String> scrollAction = action -> {
DockContent content = channels.getActiveContent();
if (content.getComponent() instanceof Channel) {
((Channel) content.getComponent()).scroll(action);
}
else if (content.getId().startsWith("'")) {
routingManager.scroll(content.getId(), action);
}
};

hotkeyManager.registerAction("scroll.pageUp", "Scroll: Page Up", new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
scrollAction.accept("pageUp");
}
});

hotkeyManager.registerAction("scroll.pageDown", "Scroll: Page Down", new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
scrollAction.accept("pageDown");
}
});

hotkeyManager.registerAction("window.toggleCompact", "Window: Toggle Compact Mode", new AbstractAction() {

@Override
Expand Down Expand Up @@ -2573,7 +2600,6 @@ private class ChannelChangeListener implements ChangeListener {
*/
@Override
public void stateChanged(ChangeEvent e) {
state.update(true);
updateChannelInfoDialog(null);
String stream = channels.getLastActiveChannel().getStreamName();
emotesDialog.updateStream(stream, client.getEmotesetsByChannel(Helper.toChannel(stream)));
Expand All @@ -2590,6 +2616,8 @@ public void stateChanged(ChangeEvent e) {
}
}
dockedDialogs.activeContentChanged();
routingManager.setChannel(channels.getLastActiveChannel());
state.update(true);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/chatty/gui/components/AutoModDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public void showDialog() {
public void setStream(String stream) {
if (stream != null && !stream.equals(currentRoom)) {
currentRoom = stream;
helper.setCurrentChannel(stream);
if (isVisible()) {
switchDataToCurrent();
}
Expand Down
50 changes: 18 additions & 32 deletions src/chatty/gui/components/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ public Channel(final Room room, Type type, MainGui main, StyleManager styleManag
//System.out.println(west.getVerticalScrollBarPolicy());
//System.out.println(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
west.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

// PageUp/Down hotkeys / Scrolling
InputMap westScrollInputMap = west.getInputMap(WHEN_IN_FOCUSED_WINDOW);
westScrollInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "pageUp");
west.getActionMap().put("pageUp", new ScrollAction("pageUp", west.getVerticalScrollBar()));
westScrollInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "pageDown");
west.getActionMap().put("pageDown", new ScrollAction("pageDown", west.getVerticalScrollBar()));
west.getVerticalScrollBar().setUnitIncrement(40);


Expand All @@ -108,12 +101,9 @@ public Channel(final Room room, Type type, MainGui main, StyleManager styleManag
input.addActionListener(main.getActionListener());
input.setCompletionServer(new ChannelCompletion(this, main, input, users));
input.setCompletionEnabled(main.getSettings().getBoolean("completionEnabled"));
// Remove PAGEUP/DOWN so it can scroll chat (as before JTextArea)
input.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "-");
input.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "-");
installLimits(input);
TextSelectionMenu.install(input);

// Add components
add(mainPane, BorderLayout.CENTER);
add(input, BorderLayout.SOUTH);
Expand Down Expand Up @@ -354,28 +344,24 @@ public void insertText(String text, boolean withSpace) {
input.insertAtCaret(text, withSpace);
}

private static class ScrollAction extends AbstractAction {

private final String action;
private final JScrollBar scrollbar;

ScrollAction(String action, JScrollBar scrollbar) {
this.scrollbar = scrollbar;
this.action = action;
}

@Override
public void actionPerformed(ActionEvent e) {
int now = scrollbar.getValue();
int height = scrollbar.getVisibleAmount();
height = height - height / 10;
int newValue = 0;
switch (action) {
case "pageUp": newValue = now - height; break;
case "pageDown": newValue = now + height; break;
}
scrollbar.setValue(newValue);
public void scroll(String action) {
scroll(west.getVerticalScrollBar(), action);
}

public static void scroll(JScrollBar scrollbar, String action) {
int now = scrollbar.getValue();
int height = scrollbar.getVisibleAmount();
height = height - height / 10;
int newValue = 0;
switch (action) {
case "pageUp":
newValue = now - height;
break;
case "pageDown":
newValue = now + height;
break;
}
scrollbar.setValue(newValue);
}

public final void setUserlistWidth(int width, int minWidth) {
Expand Down
1 change: 1 addition & 0 deletions src/chatty/gui/components/FollowersDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ private void update() {
*/
public void showDialog(String stream) {
this.stream = stream;
helper.setCurrentChannel(stream);
setTitle(type+" of "+stream+" (100 most recent)");
if (currentInfo == null || !currentInfo.stream.equals(stream)) {
// Set to default if no info is set yet or if it is opened on a
Expand Down
1 change: 1 addition & 0 deletions src/chatty/gui/components/admin/AdminDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ private void updateTabTitle() {
*/
private void changeChannel(String channel) {
this.currentChannel = channel;
helper.setCurrentChannel(channel);
commercialPanel.changeChannel(channel);
if (tabs.getSelectedIndex() == 0) {
statusPanel.changeChannel(channel);
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/help/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<h1><a name="top">Chatty (Version: 0.26-b2)</a></h1>
<h1><a name="top">Chatty (Version: 0.26-b3)</a></h1>
<table>
<tr>
<td valign="top">
Expand Down
4 changes: 2 additions & 2 deletions src/chatty/gui/components/menus/ContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ public void addCheckboxItem(String action, String text, String parent, boolean s
}
}

protected void addRadioItem(String action, String text, String group) {
public void addRadioItem(String action, String text, String group) {
items.put(action, add(makeRadioItem(action, text, group)));
}

protected void addRadioItem(String action, String text, String group, String parent) {
public void addRadioItem(String action, String text, String group, String parent) {
if (parent != null) {
JMenuItem item = makeRadioItem(action, text, group);
getSubmenu(parent).add(item);
Expand Down
33 changes: 25 additions & 8 deletions src/chatty/gui/components/menus/RoutingTargetContextMenu.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@

package chatty.gui.components.menus;

import chatty.lang.Language;
import chatty.gui.DockedDialogHelper;
import chatty.gui.components.Channel;
import java.awt.event.ActionEvent;
import java.util.List;

/**
* Context menu for the Highlights/Ignored Messages dialog (also used for Stream
* Chat dialog currently).
* Context menu for Custom Tabs.
*
* @author tduva
*/
public class RoutingTargetContextMenu extends ContextMenu {

public RoutingTargetContextMenu() {
addItem("clearHighlights", Language.getString("highlightedDialog.cm.clear"));
// addSeparator();
// addCheckboxItem("dockToggleDocked", "Dock as tab", isDocked);
// addCheckboxItem("dockToggleAutoOpenActivity", "Open on message", autoOpen);
public RoutingTargetContextMenu(List<Channel> openChannels,
boolean fixedChannelEnabled,
boolean addAllEntry,
boolean showAll,
String currentChannel) {

if (openChannels != null) {
addItem("clearAll", "Clear all");
addItem("clearCurrent", "Clear current");
addSeparator();
DockedDialogHelper.addChannelSelectionToContextMenu(
this,
openChannels,
fixedChannelEnabled,
addAllEntry,
showAll,
currentChannel);
}
else {
addItem("clearAll", "Clear");
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/chatty/gui/components/menus/UrlContextMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public UrlContextMenu(String url, boolean deleted, ContextMenuListener listener)
addItem("playerBest", "Open in player (Best)");

channel = Helper.getChannelFromUrl(url);
if (channel != null) {
if (channel != null && Helper.isValidChannel(channel)) {
addSeparator();
addItem("join", "Join #"+channel);
Helper.TwitchPopoutUrlInfo popoutInfo = Helper.getPopoutUrlInfo(url);
Expand Down
Loading

0 comments on commit d0d1a84

Please sign in to comment.