Skip to content

Hide tabs without restart #12958

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.ai.components.util.EmbeddingModelGuardedComponent;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.frame.ExternalApplicationsPreferences;
import org.jabref.logic.ai.AiPreferences;
import org.jabref.logic.ai.AiService;
Expand All @@ -22,7 +23,7 @@ public class AiChatGuardedComponent extends EmbeddingModelGuardedComponent {
/// This field is used for two purposes:
/// 1. Logging
/// 2. Title of group chat window
/// Thus, if you use {@link AiChatGuardedComponent} for one entry in {@link EntryEditor}, then you may not localize
/// Thus, if you use {@link AiChatGuardedComponent} for one entry in {@link org.jabref.gui.entryeditor.EntryEditor}, then you may not localize
/// this parameter. However, for group chat window, you should.
private final StringProperty name;

Expand All @@ -42,9 +43,10 @@ public AiChatGuardedComponent(StringProperty name,
DialogService dialogService,
AiPreferences aiPreferences,
ExternalApplicationsPreferences externalApplicationsPreferences,
AdaptVisibleTabs adaptVisibleTabs,
TaskExecutor taskExecutor
) {
super(aiService, aiPreferences, externalApplicationsPreferences, dialogService);
super(aiService, aiPreferences, externalApplicationsPreferences, dialogService, adaptVisibleTabs);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor call in the superclass has been modified to include 'adaptVisibleTabs', but the JavaDoc for the constructor has not been updated to reflect this change.


this.name = name;
this.chatHistory = chatHistory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import javafx.scene.Scene;

import org.jabref.gui.DialogService;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.frame.ExternalApplicationsPreferences;
import org.jabref.gui.util.BaseWindow;
import org.jabref.logic.ai.AiPreferences;
Expand All @@ -22,6 +23,7 @@ public class AiChatWindow extends BaseWindow {
private final AiPreferences aiPreferences;
private final ExternalApplicationsPreferences externalApplicationsPreferences;
private final TaskExecutor taskExecutor;
private final AdaptVisibleTabs adaptVisibleTabs;

// This field is used for finding an existing AI chat window when user wants to chat with the same group again.
private String chatName;
Expand All @@ -30,12 +32,14 @@ public AiChatWindow(AiService aiService,
DialogService dialogService,
AiPreferences aiPreferences,
ExternalApplicationsPreferences externalApplicationsPreferences,
AdaptVisibleTabs adaptVisibleTabs,
TaskExecutor taskExecutor
) {
this.aiService = aiService;
this.dialogService = dialogService;
this.aiPreferences = aiPreferences;
this.externalApplicationsPreferences = externalApplicationsPreferences;
this.adaptVisibleTabs = adaptVisibleTabs;
this.taskExecutor = taskExecutor;
}

Expand All @@ -53,6 +57,7 @@ public void setChat(StringProperty name, ObservableList<ChatMessage> chatHistory
dialogService,
aiPreferences,
externalApplicationsPreferences,
adaptVisibleTabs,
taskExecutor
),
800,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.ai.components.aichat.AiChatGuardedComponent;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.frame.ExternalApplicationsPreferences;
import org.jabref.gui.util.DynamicallyChangeableNode;
import org.jabref.logic.ai.AiPreferences;
Expand All @@ -16,11 +17,13 @@ public abstract class AiPrivacyNoticeGuardedComponent extends DynamicallyChangea
private final AiPreferences aiPreferences;
private final ExternalApplicationsPreferences externalApplicationsPreferences;
private final DialogService dialogService;
private final AdaptVisibleTabs adaptVisibleTabs;

public AiPrivacyNoticeGuardedComponent(AiPreferences aiPreferences, ExternalApplicationsPreferences externalApplicationsPreferences, DialogService dialogService) {
public AiPrivacyNoticeGuardedComponent(AiPreferences aiPreferences, ExternalApplicationsPreferences externalApplicationsPreferences, DialogService dialogService, AdaptVisibleTabs adaptVisibleTabs) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JavaDoc for the constructor should be updated to include the new parameter 'AdaptVisibleTabs adaptVisibleTabs' as per the special instructions.

this.aiPreferences = aiPreferences;
this.externalApplicationsPreferences = externalApplicationsPreferences;
this.dialogService = dialogService;
this.adaptVisibleTabs = adaptVisibleTabs;

aiPreferences.enableAiProperty().addListener(observable -> rebuildUi());
}
Expand All @@ -34,7 +37,8 @@ public final void rebuildUi() {
aiPreferences,
this::rebuildUi,
externalApplicationsPreferences,
dialogService
dialogService,
adaptVisibleTabs
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.desktop.os.NativeDesktop;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.entryeditor.EntryEditorPreferences;
import org.jabref.gui.frame.ExternalApplicationsPreferences;
import org.jabref.gui.preferences.GuiPreferences;
import org.jabref.logic.ai.AiPreferences;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.ai.AiProvider;

import com.airhacks.afterburner.views.ViewLoader;
Expand All @@ -36,15 +36,17 @@ public class PrivacyNoticeComponent extends ScrollPane {
private final AiPreferences aiPreferences;
private final Runnable onIAgreeButtonClickCallback;
private final DialogService dialogService;
private final AdaptVisibleTabs adaptVisibleTabs;
private final ExternalApplicationsPreferences externalApplicationsPreferences;

@Inject private GuiPreferences preferences;

public PrivacyNoticeComponent(AiPreferences aiPreferences, Runnable onIAgreeButtonClickCallback, ExternalApplicationsPreferences externalApplicationsPreferences, DialogService dialogService) {
public PrivacyNoticeComponent(AiPreferences aiPreferences, Runnable onIAgreeButtonClickCallback, ExternalApplicationsPreferences externalApplicationsPreferences, DialogService dialogService, AdaptVisibleTabs adaptVisibleTabs) {
this.aiPreferences = aiPreferences;
this.onIAgreeButtonClickCallback = onIAgreeButtonClickCallback;
this.externalApplicationsPreferences = externalApplicationsPreferences;
this.dialogService = dialogService;
this.adaptVisibleTabs = adaptVisibleTabs;

ViewLoader.view(this)
.root(this)
Expand Down Expand Up @@ -112,6 +114,6 @@ private void hideAITabs() {
EntryEditorPreferences entryEditorPreferences = preferences.getEntryEditorPreferences();
entryEditorPreferences.setShouldShowAiSummaryTab(false);
entryEditorPreferences.setShouldShowAiChatTab(false);
dialogService.showWarningDialogAndWait(Localization.lang("Restart"), Localization.lang("Please restart JabRef for preferences to take effect."));
adaptVisibleTabs.adaptVisibleTabs();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.ai.components.privacynotice.AiPrivacyNoticeGuardedComponent;
import org.jabref.gui.ai.components.util.errorstate.ErrorStateComponent;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.frame.ExternalApplicationsPreferences;
import org.jabref.logic.ai.AiPreferences;
import org.jabref.logic.ai.AiService;
Expand Down Expand Up @@ -39,9 +40,10 @@ public SummaryComponent(BibDatabaseContext bibDatabaseContext,
AiPreferences aiPreferences,
ExternalApplicationsPreferences externalApplicationsPreferences,
CitationKeyPatternPreferences citationKeyPatternPreferences,
DialogService dialogService
DialogService dialogService,
AdaptVisibleTabs adaptVisibleTabs
) {
super(aiPreferences, externalApplicationsPreferences, dialogService);
super(aiPreferences, externalApplicationsPreferences, dialogService, adaptVisibleTabs);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor call now includes an additional parameter 'adaptVisibleTabs', but there is no JavaDoc update reflecting this change. JavaDoc should be updated to include this new parameter.


this.bibDatabaseContext = bibDatabaseContext;
this.entry = entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jabref.gui.DialogService;
import org.jabref.gui.ai.components.privacynotice.AiPrivacyNoticeGuardedComponent;
import org.jabref.gui.ai.components.util.errorstate.ErrorStateComponent;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.frame.ExternalApplicationsPreferences;
import org.jabref.gui.util.UiTaskExecutor;
import org.jabref.logic.ai.AiPreferences;
Expand All @@ -24,9 +25,10 @@ public abstract class EmbeddingModelGuardedComponent extends AiPrivacyNoticeGuar
public EmbeddingModelGuardedComponent(AiService aiService,
AiPreferences aiPreferences,
ExternalApplicationsPreferences externalApplicationsPreferences,
DialogService dialogService
DialogService dialogService,
AdaptVisibleTabs adaptVisibleTabs
) {
super(aiPreferences, externalApplicationsPreferences, dialogService);
super(aiPreferences, externalApplicationsPreferences, dialogService, adaptVisibleTabs);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constructor call to the superclass now includes a new parameter 'adaptVisibleTabs', but the JavaDoc for the constructor has not been updated to reflect this change.


this.aiService = aiService;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jabref.gui.entryeditor;

public interface AdaptVisibleTabs {
/**
* Adapt the visible tabs to the current entry type.
*/
void adaptVisibleTabs();
}
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/AiChatTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class AiChatTab extends EntryEditorTab {
private final EntryEditorPreferences entryEditorPreferences;
private final StateManager stateManager;
private final TaskExecutor taskExecutor;
private final AdaptVisibleTabs adaptVisibleTabs;
private final CitationKeyPatternPreferences citationKeyPatternPreferences;

private Optional<BibEntry> previousBibEntry = Optional.empty();
Expand All @@ -45,6 +46,7 @@ public AiChatTab(AiService aiService,
DialogService dialogService,
GuiPreferences preferences,
StateManager stateManager,
AdaptVisibleTabs adaptVisibleTabs,
TaskExecutor taskExecutor) {
this.aiService = aiService;
this.dialogService = dialogService;
Expand All @@ -54,6 +56,7 @@ public AiChatTab(AiService aiService,
this.entryEditorPreferences = preferences.getEntryEditorPreferences();
this.citationKeyPatternPreferences = preferences.getCitationKeyPatternPreferences();
this.stateManager = stateManager;
this.adaptVisibleTabs = adaptVisibleTabs;

this.taskExecutor = taskExecutor;

Expand Down Expand Up @@ -89,7 +92,7 @@ protected void bindToEntry(BibEntry entry) {
}

private void showPrivacyNotice(BibEntry entry) {
setContent(new PrivacyNoticeComponent(aiPreferences, () -> bindToEntry(entry), externalApplicationsPreferences, dialogService));
setContent(new PrivacyNoticeComponent(aiPreferences, () -> bindToEntry(entry), externalApplicationsPreferences, dialogService, adaptVisibleTabs));
}

private void showErrorNotPdfs() {
Expand Down Expand Up @@ -139,6 +142,7 @@ private void showChatPanel(BibDatabaseContext bibDatabaseContext, BibEntry entry
dialogService,
aiPreferences,
externalApplicationsPreferences,
adaptVisibleTabs,
taskExecutor
));
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/AiSummaryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class AiSummaryTab extends EntryEditorTab {
private final AiService aiService;
private final DialogService dialogService;
private final StateManager stateManager;
private final AdaptVisibleTabs adaptVisibleTabs;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The field 'adaptVisibleTabs' is introduced but not documented in the JavaDoc of the constructor. This violates the requirement to update JavaDoc when method arguments change.

private final AiPreferences aiPreferences;
private final ExternalApplicationsPreferences externalApplicationsPreferences;
private final CitationKeyPatternPreferences citationKeyPatternPreferences;
Expand All @@ -26,10 +27,12 @@ public class AiSummaryTab extends EntryEditorTab {
public AiSummaryTab(AiService aiService,
DialogService dialogService,
StateManager stateManager,
AdaptVisibleTabs adaptVisibleTabs,
GuiPreferences preferences) {
this.aiService = aiService;
this.dialogService = dialogService;
this.stateManager = stateManager;
this.adaptVisibleTabs = adaptVisibleTabs;

this.aiPreferences = preferences.getAiPreferences();
this.externalApplicationsPreferences = preferences.getExternalApplicationsPreferences();
Expand Down Expand Up @@ -58,7 +61,8 @@ protected void bindToEntry(BibEntry entry) {
aiPreferences,
externalApplicationsPreferences,
citationKeyPatternPreferences,
dialogService
dialogService,
adaptVisibleTabs
));
}
}
12 changes: 5 additions & 7 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
* <p>
* The editors for fields are created via {@link org.jabref.gui.fieldeditors.FieldEditors}.
*/
public class EntryEditor extends BorderPane implements PreviewControls {
public class EntryEditor extends BorderPane implements PreviewControls, AdaptVisibleTabs {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class now implements AdaptVisibleTabs, but the JavaDoc for the class does not reflect this change. The JavaDoc should be updated to include information about the new interface implementation.

private final Supplier<LibraryTab> tabSupplier;
private final ExternalFilesEntryLinker fileLinker;
private final PreviewPanel previewPanel;
Expand Down Expand Up @@ -336,8 +336,8 @@ private List<EntryEditorTab> createTabs() {
tabs.add(sourceTab);
tabs.add(new LatexCitationsTab(preferences, dialogService, stateManager, directoryMonitor));
tabs.add(new FulltextSearchResultsTab(stateManager, preferences, dialogService, taskExecutor));
tabs.add(new AiSummaryTab(aiService, dialogService, stateManager, preferences));
tabs.add(new AiChatTab(aiService, dialogService, preferences, stateManager, taskExecutor));
tabs.add(new AiSummaryTab(aiService, dialogService, stateManager, this, preferences));
tabs.add(new AiChatTab(aiService, dialogService, preferences, stateManager, this, taskExecutor));

return tabs;
}
Expand Down Expand Up @@ -374,10 +374,8 @@ private Map<String, Set<Field>> getAdditionalUserConfiguredTabs() {
return entryEditorTabList;
}

/**
* Adapt the visible tabs to the current entry type.
*/
private void adaptVisibleTabs() {
@Override
public void adaptVisibleTabs() {
// We need to find out, which tabs will be shown (and which not anymore) and remove and re-add the appropriate tabs
// to the editor. We cannot to simply remove all and re-add the complete list of visible tabs, because
// the tabs give an ugly animation the looks like all tabs are shifting in from the right. In other words:
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/jabref/gui/frame/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ public JabRefFrame(Stage mainStage,
dialogService,
SearchType.NORMAL_SEARCH);

this.entryEditor = new EntryEditor(this::getCurrentLibraryTab,
// Actions are recreated here since this avoids passing more parameters and the amount of additional memory consumption is neglegtable.
new UndoAction(this::getCurrentLibraryTab, undoManager, dialogService, stateManager),
new RedoAction(this::getCurrentLibraryTab, undoManager, dialogService, stateManager));
Injector.setModelOrService(EntryEditor.class, entryEditor);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Injector.setModelOrService call is duplicated in the patch. This could lead to unnecessary redundancy and potential maintenance issues.


this.sidePane = new SidePane(
this,
this.preferences,
Expand All @@ -177,17 +183,12 @@ public JabRefFrame(Stage mainStage,
dialogService,
aiService,
stateManager,
entryEditor,
fileUpdateMonitor,
entryTypesManager,
clipBoardManager,
undoManager);

this.entryEditor = new EntryEditor(this::getCurrentLibraryTab,
// Actions are recreated here since this avoids passing more parameters and the amount of additional memory consumption is neglegtable.
new UndoAction(this::getCurrentLibraryTab, undoManager, dialogService, stateManager),
new RedoAction(this::getCurrentLibraryTab, undoManager, dialogService, stateManager));
Injector.setModelOrService(EntryEditor.class, entryEditor);

this.pushToApplicationCommand = new PushToApplicationCommand(
stateManager,
dialogService,
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.entryeditor.AdaptVisibleTabs;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.keyboard.KeyBinding;
import org.jabref.gui.keyboard.KeyBindingRepository;
Expand Down Expand Up @@ -92,6 +93,7 @@ public class GroupTreeView extends BorderPane {
private final DialogService dialogService;
private final AiService aiService;
private final TaskExecutor taskExecutor;
private final AdaptVisibleTabs adaptVisibleTabs;
private final GuiPreferences preferences;
private final UndoManager undoManager;
private final FileUpdateMonitor fileUpdateMonitor;
Expand Down Expand Up @@ -120,13 +122,15 @@ public class GroupTreeView extends BorderPane {
*/
public GroupTreeView(TaskExecutor taskExecutor,
StateManager stateManager,
AdaptVisibleTabs adaptVisibleTabs,
GuiPreferences preferences,
DialogService dialogService,
AiService aiService,
UndoManager undoManager,
FileUpdateMonitor fileUpdateMonitor) {
this.taskExecutor = taskExecutor;
this.stateManager = stateManager;
this.adaptVisibleTabs = adaptVisibleTabs;
this.preferences = preferences;
this.dialogService = dialogService;
this.aiService = aiService;
Expand Down Expand Up @@ -189,7 +193,7 @@ private void createNodes() {

private void initialize() {
this.localDragboard = stateManager.getLocalDragboard();
viewModel = new GroupTreeViewModel(stateManager, dialogService, aiService, preferences, taskExecutor, localDragboard);
viewModel = new GroupTreeViewModel(stateManager, dialogService, aiService, preferences, adaptVisibleTabs, taskExecutor, localDragboard);

// Set-up groups tree
groupTree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
Expand Down
Loading