forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add export current theme JabRef#5790
* Add method for saving theme to file * Add modal for selection witch theme to export as CSS
- Loading branch information
Showing
6 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/org/jabref/gui/preferences/ExportThemeDialog.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.*?> | ||
<?import javafx.scene.layout.*?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<DialogPane xmlns="http://javafx.com/javafx" | ||
xmlns:fx="http://javafx.com/fxml" | ||
fx:controller="org.jabref.gui.preferences.ExportThemeDialog" | ||
prefHeight="300.0" prefWidth="500.0"> | ||
|
||
<content> | ||
<BorderPane> | ||
<center> | ||
<TableView fx:id="table"> | ||
<columns> | ||
<TableColumn fx:id="columnName" text="%Theme name"/> | ||
<TableColumn fx:id="columnPath" text="%Path to theme"/> | ||
</columns> | ||
<padding> | ||
<Insets bottom="30.0"/> | ||
</padding> | ||
</TableView> | ||
</center> | ||
</BorderPane> | ||
</content> | ||
<ButtonType fx:constant="CLOSE"/> | ||
</DialogPane> |
121 changes: 121 additions & 0 deletions
121
src/main/java/org/jabref/gui/preferences/ExportThemeDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package org.jabref.gui.preferences; | ||
|
||
import com.airhacks.afterburner.views.ViewLoader; | ||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TablePosition; | ||
import javafx.scene.control.TableRow; | ||
import javafx.scene.control.TableView; | ||
import javafx.scene.control.cell.PropertyValueFactory; | ||
import javafx.scene.input.KeyCode; | ||
import org.jabref.JabRefException; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.gui.util.FileDialogConfiguration; | ||
import org.jabref.gui.util.ThemeLoader; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.util.StandardFileType; | ||
import org.jabref.preferences.JabRefPreferences; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ExportThemeDialog extends BaseDialog<Void> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ExportThemeDialog.class); | ||
|
||
@FXML private TableView<Theme> table; | ||
@FXML private TableColumn<Theme, String> columnName; | ||
@FXML private TableColumn<Theme, String> columnPath; | ||
|
||
private JabRefPreferences preferences; | ||
private DialogService dialogService; | ||
|
||
public ExportThemeDialog(DialogService dialogService, JabRefPreferences preferences) { | ||
this.dialogService = dialogService; | ||
this.preferences = preferences; | ||
|
||
ViewLoader | ||
.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
this.setTitle(Localization.lang("Export Theme")); | ||
} | ||
|
||
@FXML | ||
private void initialize() { | ||
columnName.setCellValueFactory(new PropertyValueFactory<>("name")); | ||
columnPath.setCellValueFactory(new PropertyValueFactory<>("path")); | ||
|
||
ObservableList<Theme> data = | ||
FXCollections.observableArrayList(new Theme("Light theme", ThemeLoader.MAIN_CSS), new Theme("Dark theme", ThemeLoader.DARK_CSS)); | ||
|
||
if (!(ThemeLoader.CUSTOM_CSS.isBlank() || ThemeLoader.CUSTOM_CSS.isEmpty())) { | ||
data.add(new Theme("Custom theme", ThemeLoader.CUSTOM_CSS)); | ||
} | ||
|
||
table.setItems(data); | ||
|
||
table.setOnKeyPressed(event -> { | ||
TablePosition tablePosition; | ||
if (event.getCode().equals(KeyCode.ENTER)) { | ||
tablePosition = table.getFocusModel().getFocusedCell(); | ||
final int row = tablePosition.getRow(); | ||
ObservableList<Theme> list = table.getItems(); | ||
Theme theme = list.get(row); | ||
exportCSSFile(theme.getPath()); | ||
} | ||
}); | ||
|
||
table.setRowFactory(tv -> { | ||
TableRow<Theme> row = new TableRow<>(); | ||
row.setOnMouseClicked(event -> handleSelectedRowEvent(row)); | ||
return row; | ||
}); | ||
} | ||
|
||
private void handleSelectedRowEvent(TableRow<Theme> row) { | ||
if (!row.isEmpty()) { | ||
exportCSSFile(row.getItem().getPath()); | ||
} | ||
} | ||
|
||
private void exportCSSFile(String theme) { | ||
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() | ||
.addExtensionFilter(StandardFileType.CSS) | ||
.withDefaultExtension(StandardFileType.CSS) | ||
.withInitialDirectory(preferences.setLastPreferencesExportPath()) | ||
.build(); | ||
|
||
dialogService.showFileSaveDialog(fileDialogConfiguration) | ||
.ifPresent(exportFile -> { | ||
try { | ||
preferences.exportTheme(exportFile.getFileName(), theme); | ||
} catch (JabRefException ex) { | ||
LOGGER.warn(ex.getMessage(), ex); | ||
dialogService.showErrorDialogAndWait(Localization.lang("Export theme"), ex); | ||
} | ||
}); | ||
} | ||
|
||
public static class Theme { | ||
private SimpleStringProperty name; | ||
private SimpleStringProperty path; | ||
|
||
public Theme(String name, String path) { | ||
this.name = new SimpleStringProperty(name); | ||
this.path = new SimpleStringProperty(path); | ||
} | ||
|
||
public String getName() { | ||
return name.get(); | ||
} | ||
|
||
public String getPath() { | ||
return path.get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters