2222import org .jetbrains .annotations .Nullable ;
2323import org .yanhuang .plugins .intellij .exportjar .ExportPacker ;
2424import org .yanhuang .plugins .intellij .exportjar .HistoryData ;
25+ import org .yanhuang .plugins .intellij .exportjar .HistoryData .ExportOptions ;
26+ import org .yanhuang .plugins .intellij .exportjar .HistoryData .SavedJarInfo ;
2527import org .yanhuang .plugins .intellij .exportjar .utils .CommonUtils ;
2628import org .yanhuang .plugins .intellij .exportjar .utils .Constants ;
2729import org .yanhuang .plugins .intellij .exportjar .utils .MessagesUtils ;
3941import java .nio .file .Paths ;
4042import java .util .List ;
4143import java .util .*;
44+ import java .util .stream .Collectors ;
4245
4346import static com .intellij .openapi .ui .Messages .getWarningIcon ;
4447import static com .intellij .openapi .ui .Messages .showErrorDialog ;
4750
4851/**
4952 * export jar settings dialog (link to SettingDialog.form)
53+ * <li><b>In UIDesigner: export options JCheckBox's name is same as HistoryData.ExportOptions</b></li>
5054 */
5155public class SettingDialog extends JDialog {
5256 private final Project project ;
@@ -58,12 +62,14 @@ public class SettingDialog extends JDialog {
5862 private JCheckBox exportJavaFileCheckBox ;
5963 private JCheckBox exportClassFileCheckBox ;
6064 private JCheckBox exportTestFileCheckBox ;
65+ private JCheckBox exportAddDirectoryCheckBox ;
6166 private JComboBox <String > outPutJarFileComboBox ;
6267 private JButton selectJarFileButton ;
6368 private JPanel settingPanel ;
6469 private JPanel fileListPanel ;
6570 private JButton debugButton ;
6671 private JPanel actionPanel ;
72+ private JPanel optionsPanel ;
6773 private HistoryData historyData ;
6874 private FileListDialog fileListDialog ;
6975 private BorderLayoutPanel fileListLabel ;
@@ -91,6 +97,7 @@ public void windowClosing(WindowEvent e) {
9197
9298 readSaveHistory ();
9399 initComboBox ();
100+ initOptionCheckBox ();
94101 createFileListTree ();
95102
96103// uiDebug();
@@ -109,15 +116,34 @@ private void initComboBox() {
109116 String [] historyFiles ;
110117 if (historyData != null ) {
111118 historyFiles =
112- Arrays .stream (Optional .ofNullable (historyData .getSavedJarInfo ()).orElse (new HistoryData . SavedJarInfo [0 ]))
113- .map (HistoryData . SavedJarInfo ::getPath ).toArray (String []::new );
119+ Arrays .stream (Optional .ofNullable (historyData .getSavedJarInfo ()).orElse (new SavedJarInfo [0 ]))
120+ .map (SavedJarInfo ::getPath ).toArray (String []::new );
114121 } else {
115122 historyFiles = new String [0 ];
116123 }
117124 ComboBoxModel <String > model = new DefaultComboBoxModel <>(historyFiles );
118125 outPutJarFileComboBox .setModel (model );
119126 }
120127
128+ private void initOptionCheckBox (){
129+ final Component [] components = optionsPanel .getComponents ();
130+ final Set <String > optionSet = Optional .ofNullable (historyData .getLastExportOptions ()).stream ().flatMap (Arrays ::stream )
131+ .map (ExportOptions ::name )
132+ .map (String ::toLowerCase )
133+ .collect (Collectors .toSet ());
134+ if (optionSet .size () == 0 ) {
135+ return ;
136+ }
137+ //set select state according to last saved
138+ for (Component c : components ) {
139+ if (c instanceof JCheckBox && optionSet .contains (c .getName ().toLowerCase ())) {
140+ ((JCheckBox ) c ).setSelected (true );
141+ } else if (c instanceof JCheckBox ) {
142+ ((JCheckBox ) c ).setSelected (false );
143+ }
144+ }
145+ }
146+
121147 private void createFileListTree () {
122148 //remove old component
123149 if (this .fileListLabel != null ) {
@@ -174,7 +200,8 @@ private void writeSaveHistory(Path exportJarName) {
174200 if (historyData == null ) {
175201 this .historyData = new HistoryData ();
176202 }
177- HistoryData .SavedJarInfo savedJar = new HistoryData .SavedJarInfo ();
203+ this .historyData .setLastExportOptions (pickExportOptions ());
204+ SavedJarInfo savedJar = new SavedJarInfo ();
178205 savedJar .setCreation (System .currentTimeMillis ());
179206 savedJar .setPath (exportJarName .toString ());
180207 historyData .addSavedJarInfo (savedJar );
@@ -189,6 +216,22 @@ private void writeSaveHistory(Path exportJarName) {
189216 }
190217 }
191218
219+ private ExportOptions [] pickExportOptions (){
220+ final Component [] components = optionsPanel .getComponents ();
221+ return Arrays .stream (components ).filter (c -> c instanceof JCheckBox )
222+ .filter (c ->((JCheckBox ) c ).isSelected ())
223+ .map (Component ::getName )
224+ .map (String ::toLowerCase )
225+ .filter (n -> {
226+ try {
227+ ExportOptions .valueOf (n );
228+ return true ;
229+ } catch (Exception e ) {
230+ return false ;
231+ }
232+ }).map (ExportOptions ::valueOf ).toArray (ExportOptions []::new );
233+ }
234+
192235 private void onSelectJarFileButton (ActionEvent event ) {
193236 FileChooserDescriptor descriptor = FileChooserDescriptorFactory .createSingleFileDescriptor ();
194237 Consumer <VirtualFile > chooserConsumer = new FileChooserConsumerImplForComboBox (this .outPutJarFileComboBox );
@@ -260,9 +303,7 @@ public void doExport(VirtualFile[] exportFiles) {
260303 }
261304 this .dispose ();
262305 writeSaveHistory (exportJarFullPath );
263- final CompileStatusNotification packager = new ExportPacker (project , exportFiles , exportJarFullPath ,
264- exportJavaFileCheckBox .isSelected (), exportClassFileCheckBox .isSelected (),
265- exportTestFileCheckBox .isSelected ());
306+ final CompileStatusNotification packager = new ExportPacker (project , exportFiles , exportJarFullPath , pickExportOptions ());
266307 app .invokeAndWait (() -> CompilerManager .getInstance (project ).make (project , null == modules ? new Module [0 ] : modules , packager ));
267308 }
268309 } else {
0 commit comments