From 1b6f69bcf1488f5c6e7877644b63502590bd906a Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Thu, 20 May 2010 06:04:49 +0300 Subject: [PATCH] Keep focus on main window on savestate/loadstate Losing focus there was really annoying... --- Changelog.utf8 | 1 + org/jpc/plugins/PCControl.java | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Changelog.utf8 b/Changelog.utf8 index fb74052..8cf73d8 100644 --- a/Changelog.utf8 +++ b/Changelog.utf8 @@ -3,6 +3,7 @@ Changes since JPC-RR Release 10.7: - Don't truncate stack trace if menu invocation goes wrong. - Report inner exceptions in saved stack traces. - Set disk library in autoexec file, not from command line. +- Keep focus on main window on savestate/loadstate. Changes from JPC-RR Release 10.6 to JPC-RR Release 10.7: ======================================================== diff --git a/org/jpc/plugins/PCControl.java b/org/jpc/plugins/PCControl.java index 353e2f4..2d2bf60 100644 --- a/org/jpc/plugins/PCControl.java +++ b/org/jpc/plugins/PCControl.java @@ -98,6 +98,7 @@ public class PCControl extends JFrame implements Plugin private PCConfigDialog configDialog; private DumpControlDialog dumpDialog; private MenuManager menuManager; + private volatile boolean restoreFocus; private PC.PCFullStatus currentProject; @@ -712,21 +713,25 @@ public class PCControl extends JFrame implements Plugin public void menuSave(String i, Object[] args) { + restoreFocus = true; (new Thread(new SaveStateTask(((Boolean)args[0]).booleanValue()))).start(); } public void menuStatusDump(String i, Object[] args) { + restoreFocus = true; (new Thread(new StatusDumpTask())).start(); } public void menuLoad(String i, Object[] args) { + restoreFocus = true; (new Thread(new LoadStateTask(((Integer)args[0]).intValue()))).start(); } public void menuRAMDump(String i, Object[] args) { + restoreFocus = true; (new Thread(new RAMDumpTask(((Boolean)args[0]).booleanValue()))).start(); } @@ -750,11 +755,13 @@ public class PCControl extends JFrame implements Plugin public void menuAddDisk(String i, Object[] args) { + restoreFocus = true; (new Thread(new AddDiskTask())).start(); } public void menuChangeAuthors(String i, Object[] args) { + restoreFocus = true; (new Thread(new ChangeAuthorsTask())).start(); } @@ -913,6 +920,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "Load savestate failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; System.err.println("Total save time: " + (System.currentTimeMillis() - oTime) + "ms."); PCControl.this.vPluginManager.signalCommandCompletion(); } @@ -991,6 +1001,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "Saving savestate failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; System.err.println("Total save time: " + (System.currentTimeMillis() - oTime) + "ms."); PCControl.this.vPluginManager.signalCommandCompletion(); } @@ -1057,6 +1070,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "Status dump failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; PCControl.this.vPluginManager.signalCommandCompletion(); } @@ -1123,6 +1139,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "RAM dump failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; PCControl.this.vPluginManager.signalCommandCompletion(); } @@ -1251,6 +1270,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "PC Assembly failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; PCControl.this.vPluginManager.signalCommandCompletion(); } @@ -1301,6 +1323,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "Opening dump control dialog failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; } protected void runTask() @@ -1332,6 +1357,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "Adding disk failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; try { updateDisks(); } catch(Exception e) { @@ -1399,6 +1427,9 @@ public class PCControl extends JFrame implements Plugin errorDialog(caught, "Changing authors failed", PCControl.this, "Dismiss"); } PCControl.this.setEnabled(true); + if(restoreFocus) + PCControl.this.requestFocus(true); + restoreFocus = false; PCControl.this.vPluginManager.signalCommandCompletion(); } -- 2.11.4.GIT