mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Allow install Theme from Preferences dialog
This commit is contained in:
parent
15089f0c54
commit
6cd2e7c356
@ -40,16 +40,22 @@ import processing.app.PreferencesData;
|
||||
import processing.app.Theme;
|
||||
import processing.app.Theme.ZippedTheme;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static processing.app.I18n.format;
|
||||
import static processing.app.I18n.tr;
|
||||
|
||||
public class Preferences extends javax.swing.JDialog {
|
||||
@ -869,6 +875,22 @@ public class Preferences extends javax.swing.JDialog {
|
||||
comboTheme.setSelectedItem(theme);
|
||||
}
|
||||
}
|
||||
|
||||
// Allow install new themes.
|
||||
String installItem = "-- " + tr( "Install from Zip" + " --");
|
||||
comboTheme.addItem(installItem);
|
||||
|
||||
comboTheme.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Object item = comboTheme.getSelectedItem();
|
||||
if (item != null && item.toString().startsWith(installItem)) {
|
||||
SwingUtilities.invokeLater(() -> comboTheme.getUI().setPopupVisible(comboTheme, false));
|
||||
handleInstallTheme();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Font editorFont = PreferencesData.getFont("editor.font");
|
||||
fontSizeField.setText(String.valueOf(editorFont.getSize()));
|
||||
@ -975,4 +997,35 @@ public class Preferences extends javax.swing.JDialog {
|
||||
autoProxyFieldsSetEnabled(false);
|
||||
manualProxyFieldsSetEnabled(false);
|
||||
}
|
||||
|
||||
|
||||
public void handleInstallTheme() {
|
||||
|
||||
JFileChooser fileChooser = new JFileChooser(System.getProperty("user.home"));
|
||||
fileChooser.setDialogTitle(tr("Select a zip file containing the theme you'd like to add"));
|
||||
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
fileChooser.setFileFilter(new FileNameExtensionFilter(tr("ZIP files"), "zip"));
|
||||
|
||||
Dimension preferredSize = fileChooser.getPreferredSize();
|
||||
fileChooser.setPreferredSize(new Dimension(preferredSize.width + 200, preferredSize.height + 200));
|
||||
|
||||
int returnVal = fileChooser.showOpenDialog(this);
|
||||
|
||||
if (returnVal != JFileChooser.APPROVE_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
File sourceFile = fileChooser.getSelectedFile();
|
||||
|
||||
if (!sourceFile.isDirectory()) {
|
||||
try {
|
||||
|
||||
Theme.install(sourceFile);
|
||||
|
||||
} catch (IOException e) {
|
||||
base.getActiveEditor().statusError(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -66,6 +68,9 @@ import org.apache.batik.transcoder.TranscoderOutput;
|
||||
import org.apache.batik.transcoder.image.PNGTranscoder;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import processing.app.Theme.ZippedTheme;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesHelper;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
@ -724,4 +729,31 @@ public class Theme {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Intalll theme in skecthboot
|
||||
* @param zipTheme
|
||||
*/
|
||||
static public void install(File zipTheme) throws IOException{
|
||||
|
||||
// Validate...
|
||||
ZippedTheme theme = ZippedTheme.load(NAMESPACE_USER, zipTheme);
|
||||
|
||||
if(theme == null) {
|
||||
throw new IOException(format(tr("Error loading theme: {0}"), zipTheme.getAbsolutePath()));
|
||||
}
|
||||
|
||||
// Create themes folder.
|
||||
File themesFolder = new File(PreferencesData.get("sketchbook.path"), "theme");
|
||||
if (!themesFolder.exists()) {
|
||||
themesFolder.mkdir();
|
||||
}
|
||||
|
||||
// Copy
|
||||
File dest = new File(themesFolder, zipTheme.getName());
|
||||
Files.copy(zipTheme.toPath(), dest.toPath(),StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
System.out.println("COPY done: " + dest.getAbsolutePath());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user