Skip to content

Commit b65d96f

Browse files
committed
Make the new-torrent wizard remember selected files etc across panels
1 parent 7f2edb1 commit b65d96f

File tree

5 files changed

+112
-65
lines changed

5 files changed

+112
-65
lines changed

uis/src/com/biglybt/ui/swt/maketorrent/BYOPanel.java

+103-61
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public BYOPanel(NewTorrentWizard wizard,
5656
IWizardPanel<NewTorrentWizard> previous) {
5757
super(wizard, previous);
5858

59-
wizard.byo_map = null;
59+
//wizard.byo_map = null;
6060
}
6161

6262
/*
@@ -201,40 +201,55 @@ public void widgetDefaultSelected(SelectionEvent e) {
201201
}
202202
});
203203

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+
}
229244
}
245+
if (!found) {
246+
parent = createContainer(lastParent, name);
247+
}
248+
items = parent.getItems();
230249
}
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);
235252
}
236-
String name = (String) path.get(path.size() - 1);
237-
addFilename(targetFile, name, parent, false);
238253
}
239254
}
240255
}
@@ -484,52 +499,79 @@ private void moveItem(TreeItem itemToMove, TreeItem parent) {
484499
itemToMove.dispose();
485500
}
486501

487-
@Override
488-
public IWizardPanel<NewTorrentWizard> getNextPanel() {
502+
private void
503+
saveState()
504+
{
489505
if (tree.getItemCount() == 1) {
490-
// might be single file or single directory
506+
// might be single file or single directory
491507
TreeItem item = tree.getItem(0);
492508
String name = item.getText();
493509
File file = (File) item.getData();
494510
if (file != null && file.getName().equals(name) && file.exists()) {
495511
String parent = file.getParent();
496-
if ( parent != null ){
497-
((NewTorrentWizard) wizard).setDefaultOpenDir( parent );
498-
}
512+
if ( parent != null ){
513+
((NewTorrentWizard) wizard).setDefaultOpenDir( parent );
514+
}
499515

500-
if (file.isDirectory()) {
516+
if (file.isDirectory()) {
501517
wizard.directoryPath = file.getAbsolutePath();
502518
wizard.create_mode = wizard.MODE_DIRECTORY;
503519

504-
return new SavePathPanel(wizard, this);
505520
} else {
506521
wizard.singlePath = file.getAbsolutePath();
507522
wizard.create_mode = wizard.MODE_SINGLE_FILE;
508-
return new SavePathPanel(wizard, this);
509523
}
524+
525+
return;
510526
}
511527
}
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+
}
531557
}
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+
533575
return new SavePathPanel(wizard, this);
534576
}
535577

uis/src/com/biglybt/ui/swt/maketorrent/ModePanel.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,9 @@ public boolean isNextEnabled() {
490490
}
491491

492492
void activateMode(int mode) {
493+
// BYO is the only mode used, directory+single file panels are dead...
493494
wizard.setCurrentInfo(MessageText.getString(mode==NewTorrentWizard.MODE_SINGLE_FILE? "wizard.maketorrent.singlefile.help" :(mode==NewTorrentWizard.MODE_DIRECTORY? "wizard.maketorrent.directory.help" :"wizard.newtorrent.byo.help")));
494-
((NewTorrentWizard) wizard).create_mode = mode;
495+
//((NewTorrentWizard) wizard).create_mode = mode;
495496
}
496497

497498
void updateTrackerURL() {

uis/src/com/biglybt/ui/swt/maketorrent/NewTorrentWizard.java

+3
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ public void drop(DropTargetEvent event) {
378378
getNextPanelForMode(
379379
AbstractWizardPanel<NewTorrentWizard> prev )
380380
{
381+
return new BYOPanel( this, prev );
382+
/*
381383
switch( create_mode ){
382384
case MODE_DIRECTORY:
383385
return new DirectoryPanel( this, prev);
@@ -386,5 +388,6 @@ public void drop(DropTargetEvent event) {
386388
default:
387389
return new BYOPanel( this, prev );
388390
}
391+
*/
389392
}
390393
}

uis/src/com/biglybt/ui/swt/maketorrent/WebSeedsEditor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private void editTreeItem(final TreeItem item) {
360360
public void handleEvent (Event e) {
361361
String url = text.getText();
362362
if ( validURL(url)){
363-
text.setForeground( null );
363+
Utils.setSkinnedForeground(text, null);
364364
item.setForeground( null );
365365
}else{
366366
text.setForeground( Colors.colorError );
@@ -377,7 +377,7 @@ public void handleEvent (Event e) {
377377
public void handleEvent (Event e) {
378378
String url = text.getText();
379379
if ( validURL(url)){
380-
text.setForeground( null );
380+
Utils.setSkinnedForeground(text, null);
381381
item.setForeground( null );
382382
}else{
383383
text.setForeground( Colors.colorError );

uis/src/com/biglybt/ui/swt/wizard/Wizard.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,9 @@ public class Wizard {
203203
*/
204204
@Override
205205
public void handleEvent(Event arg0) {
206+
IWizardPanel<?> prevPanel = currentPanel.getPreviousPanel();
206207
clearPanel();
207-
currentPanel = currentPanel.getPreviousPanel();
208+
currentPanel = prevPanel;
208209
refresh();
209210
}
210211
});

0 commit comments

Comments
 (0)