Add setting to define the start tab

When ctbrec is started, this is the first tab shown to the user.
This commit is contained in:
0xboobface 2018-11-22 16:30:07 +01:00
parent d1e6a790ba
commit 2202dc969f
3 changed files with 40 additions and 4 deletions

View File

@ -21,6 +21,7 @@ import com.squareup.moshi.Moshi;
import com.squareup.moshi.Types;
import ctbrec.Config;
import ctbrec.StringUtil;
import ctbrec.Version;
import ctbrec.io.HttpClient;
import ctbrec.recorder.LocalRecorder;
@ -110,9 +111,6 @@ public class CamrecApplication extends Application {
rootPane.getTabs().add(siteTab);
}
}
try {
((SiteTab)rootPane.getTabs().get(0)).selected();
} catch(ClassCastException | IndexOutOfBoundsException e) {}
RecordedModelsTab modelsTab = new RecordedModelsTab("Recording", recorder, sites);
rootPane.getTabs().add(modelsTab);
@ -122,6 +120,8 @@ public class CamrecApplication extends Application {
rootPane.getTabs().add(settingsTab);
rootPane.getTabs().add(new DonateTabFx());
switchToStartTab();
primaryStage.getScene().getStylesheets().add("/ctbrec/ui/ThumbCell.css");
primaryStage.getScene().widthProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowWidth = newVal.intValue());
primaryStage.getScene().heightProperty()
@ -184,6 +184,21 @@ public class CamrecApplication extends Application {
});
}
private void switchToStartTab() {
String startTab = Config.getInstance().getSettings().startTab;
if(StringUtil.isNotBlank(startTab)) {
for (Tab tab : rootPane.getTabs()) {
if(Objects.equals(startTab, tab.getText())) {
rootPane.getSelectionModel().select(tab);
break;
}
}
}
if(rootPane.getSelectionModel().getSelectedItem() instanceof TabSelectionListener) {
((TabSelectionListener)rootPane.getSelectionModel().getSelectedItem()).selected();
}
}
private void createRecorder() {
if (config.getSettings().localRecording) {
recorder = new LocalRecorder(config);

View File

@ -15,6 +15,7 @@ import ctbrec.Config;
import ctbrec.Hmac;
import ctbrec.Settings;
import ctbrec.Settings.DirectoryStructure;
import ctbrec.StringUtil;
import ctbrec.sites.ConfigUI;
import ctbrec.sites.Site;
import javafx.beans.value.ChangeListener;
@ -75,6 +76,7 @@ public class SettingsTab extends Tab implements TabSelectionListener {
private ComboBox<Integer> maxResolution;
private ComboBox<SplitAfterOption> splitAfter;
private ComboBox<DirectoryStructure> directoryStructure;
private ComboBox<String> startTab;
private List<Site> sites;
private Label restartLabel;
private Accordion credentialsAccordion = new Accordion();
@ -373,7 +375,17 @@ public class SettingsTab extends Tab implements TabSelectionListener {
splitAfter.setOnAction((e) -> Config.getInstance().getSettings().splitRecordings = splitAfter.getSelectionModel().getSelectedItem().getValue());
GridPane.setMargin(l, new Insets(0, 0, 0, 0));
GridPane.setMargin(splitAfter, new Insets(0, 0, 0, CHECKBOX_MARGIN));
maxResolution.prefWidthProperty().bind(splitAfter.widthProperty());
l = new Label("Start Tab");
layout.add(l, 0, row);
startTab = new ComboBox<>();
layout.add(startTab, 1, row++);
startTab.setOnAction((e) -> Config.getInstance().getSettings().startTab = startTab.getSelectionModel().getSelectedItem());
GridPane.setMargin(l, new Insets(0, 0, 0, 0));
GridPane.setMargin(startTab, new Insets(0, 0, 0, CHECKBOX_MARGIN));
splitAfter.prefWidthProperty().bind(startTab.widthProperty());
maxResolution.prefWidthProperty().bind(startTab.widthProperty());
TitledPane general = new TitledPane("General", layout);
general.setCollapsible(false);
@ -589,6 +601,14 @@ public class SettingsTab extends Tab implements TabSelectionListener {
@Override
public void selected() {
startTab.getItems().clear();
for(Tab tab : getTabPane().getTabs()) {
startTab.getItems().add(tab.getText());
}
String startTabName = Config.getInstance().getSettings().startTab;
if(StringUtil.isNotBlank(startTabName)) {
startTab.getSelectionModel().select(startTabName);
}
}
@Override

View File

@ -62,6 +62,7 @@ public class Settings {
public String proxyPort;
public String proxyUser;
public String proxyPassword;
public String startTab = "Settings";
public int thumbWidth = 180;
public boolean updateThumbnails = true;
public int windowWidth = 1340;