Skip to content

Commit 83b7d8e

Browse files
committed
stack progress dialogs more sensibly
1 parent cbf2629 commit 83b7d8e

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

uis/src/com/biglybt/ui/swt/progress/ProgressWindow.java

+77-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.util.ArrayList;
2626
import java.util.List;
27+
import java.util.concurrent.atomic.AtomicInteger;
2728
import java.util.function.Supplier;
2829

2930
import org.eclipse.swt.SWT;
@@ -49,6 +50,7 @@
4950
import com.biglybt.ui.swt.UIExitUtilsSWT.canCloseListener;
5051
import com.biglybt.ui.swt.mainwindow.Colors;
5152
import com.biglybt.ui.swt.shells.MessageBoxShell;
53+
import com.biglybt.ui.swt.shells.opentorrent.OpenTorrentOptionsWindow;
5254
import com.biglybt.core.CoreOperation;
5355
import com.biglybt.core.CoreOperationListener;
5456
import com.biglybt.core.CoreOperationTask;
@@ -61,6 +63,10 @@
6163
{
6264
private static canCloseListener canCloseListener;
6365

66+
private static final AtomicInteger window_id_next = new AtomicInteger();
67+
68+
private static List<ProgressWindow> active_windows = new ArrayList();
69+
6470
public static void
6571
register(
6672
Core core )
@@ -290,6 +296,8 @@
290296

291297
private static final ThreadPool core_op_pool = new ThreadPool( "ProgressWindow:coreops", 32, true );
292298

299+
private final int window_id = window_id_next.incrementAndGet();
300+
293301
private volatile Shell shell;
294302
private volatile boolean task_complete;
295303

@@ -524,6 +532,12 @@
524532
}
525533
}
526534

535+
private Shell
536+
getShell()
537+
{
538+
return( shell );
539+
}
540+
527541
protected void
528542
showDialog(
529543
Shell _shell,
@@ -920,7 +934,69 @@ public void widgetDisposed(DisposeEvent arg0){
920934
}
921935
}
922936

923-
shell.open();
937+
ProgressWindow moveBelow = null;
938+
939+
for ( ProgressWindow window: active_windows ){
940+
941+
if ( moveBelow == null ||
942+
moveBelow.window_id < window.window_id ){
943+
944+
moveBelow = window;
945+
}
946+
}
947+
948+
active_windows.add( this );
949+
950+
shell.addListener( SWT.Dispose, (ev)->{ active_windows.remove( this ); });
951+
952+
if ( moveBelow == null ){
953+
954+
shell.open();
955+
956+
}else{
957+
958+
shell.moveBelow(moveBelow.getShell());
959+
960+
shell.setVisible(true);
961+
}
962+
963+
// don't want them appearing on top of each other
964+
965+
int num_active_windows = active_windows.size();
966+
967+
if ( num_active_windows > 1 ){
968+
969+
int max_x = Integer.MIN_VALUE;
970+
int max_y = Integer.MIN_VALUE;
971+
972+
for ( ProgressWindow window: active_windows ){
973+
974+
Rectangle rect = window.getShell().getBounds();
975+
976+
max_x = Math.max( max_x, rect.x );
977+
max_y = Math.max( max_y, rect.y );
978+
}
979+
980+
if ( max_x > Integer.MIN_VALUE ){
981+
982+
Rectangle rect = shell.getBounds();
983+
984+
rect.x = max_x + 16;
985+
rect.y = max_y + 16;
986+
987+
try{
988+
Utils.setShellMetricsConfigEnabled( shell, false );
989+
990+
shell.setBounds( rect );
991+
992+
}finally{
993+
994+
Utils.setShellMetricsConfigEnabled( shell, true );
995+
}
996+
}
997+
}
998+
999+
Utils.verifyShellRect( shell, true );
9241000
}
9251001

9261002
public void

0 commit comments

Comments
 (0)