Skip to content

Commit

Permalink
Fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
Guo Yunhe committed Sep 13, 2015
1 parent 35c85f1 commit 6f717a4
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/me/guoyunhe/fontweak/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class MainWindow extends javax.swing.JFrame {
private DefaultTableModel aliasTableModel;
private SchemeManager schemeManager;
private DefaultComboBoxModel schemeComboBoxModel;
private String currentScheme = null;
private boolean schemeLoaded = false; // Saved in config.properties
private String selectedScheme = null; // Scheme ComboBox value

/**
* Creates new form MainWindow
Expand Down Expand Up @@ -711,17 +712,25 @@ private void deleteAliasButtonActionPerformed(java.awt.event.ActionEvent evt) {/
}//GEN-LAST:event_deleteAliasButtonActionPerformed

private void schemeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schemeComboBoxActionPerformed
if (currentScheme != null && currentScheme.isEmpty()) {
String scheme = (String) schemeComboBox.getSelectedItem();
if (!currentScheme.equals(scheme)) {
File schemeFile = schemeManager.getSchemeFile(scheme);
if (schemeFile.exists()) {
fontconfig.readConfig(schemeFile);
} else {
fontconfig.readConfig();
}
loadConfig();
if (!schemeLoaded) {
return;
}
String scheme = (String) schemeComboBox.getSelectedItem();
// If selected scheme changed, save previous scheme, and load next scheme
if (!scheme.equals(selectedScheme)) {
// Save previous scheme
this.saveConfig();
File selectedSchemeFile = schemeManager.getSchemeFile(selectedScheme);
fontconfig.writeConfig(selectedSchemeFile);
// Load next scheme
selectedScheme = scheme;
selectedSchemeFile = schemeManager.getSchemeFile(selectedScheme);
if (selectedSchemeFile.exists()) {
fontconfig.readConfig(selectedSchemeFile);
} else {
fontconfig.readConfig();
}
loadConfig();
}
}//GEN-LAST:event_schemeComboBoxActionPerformed

Expand Down Expand Up @@ -961,17 +970,18 @@ private void loadSchemes() {
}
schemeComboBoxModel = new DefaultComboBoxModel(schemeList);
schemeComboBox.setModel(schemeComboBoxModel);
// Set current scheme
currentScheme = schemeManager.getCurrentSchemeName();
if (currentScheme != null) {
schemeComboBox.setSelectedItem(currentScheme);
// Set selected scheme
selectedScheme = schemeManager.getCurrentSchemeName();
if (selectedScheme != null) {
schemeComboBox.setSelectedItem(selectedScheme);
} else {
schemeComboBox.setSelectedIndex(0);
currentScheme = (String) schemeComboBox.getSelectedItem();
schemeManager.setCurrentSchemeName(currentScheme);
selectedScheme = (String) schemeComboBox.getSelectedItem();
schemeManager.setCurrentSchemeName(selectedScheme);
}
// Sync from fontconfig to current scheme file
fontconfig.writeConfig(schemeManager.getSchemeFile(currentScheme));
fontconfig.writeConfig(schemeManager.getSchemeFile(selectedScheme));
schemeLoaded = true;
}

/**
Expand Down

0 comments on commit 6f717a4

Please sign in to comment.