@@ -56,7 +56,7 @@ public BYOPanel(NewTorrentWizard wizard,
56
56
IWizardPanel <NewTorrentWizard > previous ) {
57
57
super (wizard , previous );
58
58
59
- wizard .byo_map = null ;
59
+ // wizard.byo_map = null;
60
60
}
61
61
62
62
/*
@@ -201,40 +201,55 @@ public void widgetDefaultSelected(SelectionEvent e) {
201
201
}
202
202
});
203
203
204
-
205
- if (wizard .byo_map != null ) {
206
- List list = (List ) wizard .byo_map .get ("file_map" );
207
- if (list != null ) {
208
- for (Iterator iterator = list .iterator (); iterator .hasNext ();) {
209
- Map map = (Map ) iterator .next ();
210
- String target = MapUtils .getMapString (map , "target" , null );
211
- List path = MapUtils .getMapList (map , "logical_path" , null );
212
- if (target != null && path != null ) {
213
- File targetFile = new File (target );
214
- if (path .size () == 1 ) {
215
- addFilename (targetFile , (String ) path .get (0 ), null , true );
216
- } else {
217
- TreeItem [] items = tree .getItems ();
218
- TreeItem parent = null ;
219
- for (int i = 0 ; i < path .size () - 1 ; i ++) {
220
- TreeItem lastParent = parent ;
221
- String name = (String ) path .get (i );
222
-
223
- boolean found = false ;
224
- for (TreeItem item : items ) {
225
- if (item .getText ().equals (name )) {
226
- parent = item ;
227
- found = true ;
228
- break ;
204
+ // restore state if there is any
205
+
206
+ if ( wizard .create_mode == wizard .MODE_DIRECTORY || wizard .create_mode == wizard .MODE_SINGLE_FILE ){
207
+
208
+ String path = wizard .create_mode == wizard .MODE_DIRECTORY ?wizard .directoryPath :wizard .singlePath ;
209
+
210
+ if ( path != null ){
211
+
212
+ File file = new File ( path );
213
+
214
+ if ( file .exists ()){
215
+ addFilename ( file );
216
+ }
217
+ }
218
+ }else {
219
+ if (wizard .byo_map != null ) {
220
+ List list = (List ) wizard .byo_map .get ("file_map" );
221
+ if (list != null ) {
222
+ for (Iterator iterator = list .iterator (); iterator .hasNext ();) {
223
+ Map map = (Map ) iterator .next ();
224
+ String target = MapUtils .getMapString (map , "target" , null );
225
+ List path = MapUtils .getMapList (map , "logical_path" , null );
226
+ if (target != null && path != null ) {
227
+ File targetFile = new File (target );
228
+ if (path .size () == 1 ) {
229
+ addFilename (targetFile , (String ) path .get (0 ), null , true );
230
+ } else {
231
+ TreeItem [] items = tree .getItems ();
232
+ TreeItem parent = null ;
233
+ for (int i = 0 ; i < path .size () - 1 ; i ++) {
234
+ TreeItem lastParent = parent ;
235
+ String name = (String ) path .get (i );
236
+
237
+ boolean found = false ;
238
+ for (TreeItem item : items ) {
239
+ if (item .getText ().equals (name )) {
240
+ parent = item ;
241
+ found = true ;
242
+ break ;
243
+ }
229
244
}
245
+ if (!found ) {
246
+ parent = createContainer (lastParent , name );
247
+ }
248
+ items = parent .getItems ();
230
249
}
231
- if (!found ) {
232
- parent = createContainer (lastParent , name );
233
- }
234
- items = parent .getItems ();
250
+ String name = (String ) path .get (path .size () - 1 );
251
+ addFilename (targetFile , name , parent , false );
235
252
}
236
- String name = (String ) path .get (path .size () - 1 );
237
- addFilename (targetFile , name , parent , false );
238
253
}
239
254
}
240
255
}
@@ -484,52 +499,79 @@ private void moveItem(TreeItem itemToMove, TreeItem parent) {
484
499
itemToMove .dispose ();
485
500
}
486
501
487
- @ Override
488
- public IWizardPanel <NewTorrentWizard > getNextPanel () {
502
+ private void
503
+ saveState ()
504
+ {
489
505
if (tree .getItemCount () == 1 ) {
490
- // might be single file or single directory
506
+ // might be single file or single directory
491
507
TreeItem item = tree .getItem (0 );
492
508
String name = item .getText ();
493
509
File file = (File ) item .getData ();
494
510
if (file != null && file .getName ().equals (name ) && file .exists ()) {
495
511
String parent = file .getParent ();
496
- if ( parent != null ){
497
- ((NewTorrentWizard ) wizard ).setDefaultOpenDir ( parent );
498
- }
512
+ if ( parent != null ){
513
+ ((NewTorrentWizard ) wizard ).setDefaultOpenDir ( parent );
514
+ }
499
515
500
- if (file .isDirectory ()) {
516
+ if (file .isDirectory ()) {
501
517
wizard .directoryPath = file .getAbsolutePath ();
502
518
wizard .create_mode = wizard .MODE_DIRECTORY ;
503
519
504
- return new SavePathPanel (wizard , this );
505
520
} else {
506
521
wizard .singlePath = file .getAbsolutePath ();
507
522
wizard .create_mode = wizard .MODE_SINGLE_FILE ;
508
- return new SavePathPanel (wizard , this );
509
523
}
524
+
525
+ return ;
510
526
}
511
527
}
512
- Map map = new HashMap ();
513
-
514
- List <Map > list = new ArrayList <>();
515
-
516
- map .put ("file_map" , list );
517
-
518
- buildList (list , tree .getItems ());
519
-
520
- wizard .byo_map = map ;
521
-
522
- try {
523
- wizard .byo_desc_file = AETemporaryFileHandler .createTempFile ();
524
-
525
- FileUtil .writeBytesAsFile (wizard .byo_desc_file .getAbsolutePath (),
526
- BEncoder .encode (map ));
527
-
528
- } catch (Throwable e ) {
529
-
530
- Debug .out (e );
528
+
529
+ wizard .create_mode = wizard .MODE_BYO ;
530
+
531
+ if ( tree .getItemCount () == 0 ){
532
+
533
+ wizard .byo_map = null ;
534
+
535
+ }else {
536
+
537
+ Map map = new HashMap ();
538
+
539
+ List <Map > list = new ArrayList <>();
540
+
541
+ map .put ("file_map" , list );
542
+
543
+ buildList (list , tree .getItems ());
544
+
545
+ wizard .byo_map = map ;
546
+
547
+ try {
548
+ wizard .byo_desc_file = AETemporaryFileHandler .createTempFile ();
549
+
550
+ FileUtil .writeBytesAsFile (wizard .byo_desc_file .getAbsolutePath (),
551
+ BEncoder .encode (map ));
552
+
553
+ } catch (Throwable e ) {
554
+
555
+ Debug .out (e );
556
+ }
531
557
}
532
-
558
+ }
559
+
560
+ @ Override
561
+ public IWizardPanel <NewTorrentWizard >
562
+ getPreviousPanel ()
563
+ {
564
+ saveState ();
565
+
566
+ return ( super .getPreviousPanel ());
567
+ }
568
+
569
+ @ Override
570
+ public IWizardPanel <NewTorrentWizard >
571
+ getNextPanel ()
572
+ {
573
+ saveState ();
574
+
533
575
return new SavePathPanel (wizard , this );
534
576
}
535
577
0 commit comments