Skip to content

Commit

Permalink
use isCloseable condition for remember chat tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-Spector committed Jun 19, 2024
1 parent fd080d2 commit d232b96
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/faforever/client/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
@RequiredArgsConstructor
public class ChatController extends NodeController<AnchorPane> {

public static String ADD_CHANNEL_TAB_ID = "_add_channel_tab_";

private final ChatService chatService;
private final UiService uiService;
private final FxApplicationThreadExecutor fxApplicationThreadExecutor;
Expand All @@ -44,7 +42,6 @@ public class ChatController extends NodeController<AnchorPane> {

public AnchorPane chatRoot;
public TabPane tabPane;
public Tab addChannelTab;
public Pane connectingProgressPane;
public VBox noOpenTabsContainer;
public TextField channelNameTextField;
Expand All @@ -55,14 +52,17 @@ public class ChatController extends NodeController<AnchorPane> {
@Override
protected void onInitialize() {
super.onInitialize();
addChannelTab.setId(ADD_CHANNEL_TAB_ID);
openedTabs = tabPane.getTabs();

chatService.addChannelsListener(new WeakMapChangeListener<>(channelChangeListener));
chatService.getChannels().forEach(this::onChannelJoined);

chatService.connectionStateProperty().when(showing).subscribe(this::onConnectionStateChange);
tabPane.getSelectionModel().selectedItemProperty().subscribe(tab -> chatNavigation.setLastOpenedTabId(tab.getId()));
tabPane.getSelectionModel().selectedItemProperty().subscribe(tab -> {
if (tab.isClosable()) {
chatNavigation.setLastOpenedTabId(tab.getId());
}
});
}

private void onChannelLeft(ChatChannel chatChannel) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/faforever/client/chat/ChatNavigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public String getLastOpenedTabId() {
}

public void setLastOpenedTabId(String tabId) {
if (ChatController.ADD_CHANNEL_TAB_ID.equals(tabId)) {
return;
}

currentTabs.forEach(tab -> tab.setSelected(tab.getId().equals(tabId)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/theme/chat/chat.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<children>
<TabPane fx:id="tabPane" tabClosingPolicy="ALL_TABS" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" visible="false">
<Tab fx:id="addChannelTab" text="+" closable="false">
<Tab text="+" closable="false">
<VBox fx:id="noOpenTabsContainer" alignment="CENTER" fillWidth="false">
<children>
<Label styleClass="h2" text="%chat.joinAChannel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void setChannelsListener() {
@Test
public void testOnlyOneAddChannelTabAfterInitialized() {
assertEquals(1, openedTabs.size());
assertEquals(ChatController.ADD_CHANNEL_TAB_ID, openedTabs.getFirst().getId());
assertFalse(openedTabs.getFirst().isClosable());
}

@Test
Expand Down

0 comments on commit d232b96

Please sign in to comment.