From de14dfdc8e00d94e63820ecc5fbac30574e277d3 Mon Sep 17 00:00:00 2001 From: Stanislav Vinokurov Date: Sun, 5 Sep 2021 20:33:23 +0300 Subject: [PATCH 1/3] #136 Feature: Suppress "Navigating away from will reset the order entry." warning. --- resources/config.ini | 22 ++++++++ src/ibcalpha/ibc/IbcTws.java | 3 +- .../ibc/NavigatingAwayDialogHandler.java | 51 +++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/ibcalpha/ibc/NavigatingAwayDialogHandler.java diff --git a/resources/config.ini b/resources/config.ini index f9017bf..626a048 100644 --- a/resources/config.ini +++ b/resources/config.ini @@ -410,6 +410,28 @@ ClosedownAt= AcceptIncomingConnectionAction=manual +# Suppress Navigating Away Warning +# -------------------------------- +# +# If you change Order Type, Quantity or other fields in Order Entry +# dialog and switch to a different ticker in a linked window, +# TWS displays dialog box with a warning: +# +# "Navigating away from will reset the order entry." +# +# TWS doesn't have built-in option to disable this warning. +# +# yes means the dialog is dismissed as though the user had +# clicked the 'Continue' button: this means that you accept +# Order Entry fields are reset to default values while +# switching to different ticker. +# +# no means the dialog remains on display and must be +# handled by the user. + +SuppressNavigatingAwayWarning=no + + # Allow Blind Trading # ------------------- # diff --git a/src/ibcalpha/ibc/IbcTws.java b/src/ibcalpha/ibc/IbcTws.java index 7ba3867..76d0895 100644 --- a/src/ibcalpha/ibc/IbcTws.java +++ b/src/ibcalpha/ibc/IbcTws.java @@ -331,7 +331,8 @@ private static List createWindowHandlers() { windowHandlers.add(new LoginFailedDialogHandler()); windowHandlers.add(new TooManyFailedLoginAttemptsDialogHandler()); windowHandlers.add(new ShutdownProgressDialogHandler()); - + windowHandlers.add(new NavigatingAwayDialogHandler()); + return windowHandlers; } diff --git a/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java b/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java new file mode 100644 index 0000000..a5e63dd --- /dev/null +++ b/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java @@ -0,0 +1,51 @@ +// This file is part of IBC. +// Copyright (C) 2004 Steven M. Kearns (skearns23@yahoo.com ) +// Copyright (C) 2004 - 2018 Richard L King (rlking@aultan.com) +// For conditions of distribution and use, see copyright notice in COPYING.txt + +// IBC is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// IBC is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with IBC. If not, see . + +package ibcalpha.ibc; + +import java.awt.Window; +import java.awt.event.WindowEvent; +import javax.swing.JDialog; + +class NavigatingAwayDialogHandler implements WindowHandler { + public boolean filterEvent(Window window, int eventId) { + switch (eventId) { + case WindowEvent.WINDOW_OPENED: + return true; + default: + return false; + } + } + + public void handleWindow(Window window, int eventID) { + if (! Settings.settings().getBoolean("SuppressNavigatingAwayWarning", false)) return; + + if (SwingUtils.clickButton(window, "Continue")) { + } else { + Utils.logError("can't close 'Navigating away' window: 'Continue' button not found"); + } + } + + public boolean recogniseWindow(Window window) { + if (! (window instanceof JDialog)) return false; + + return (SwingUtils.findLabel(window, "Navigating away from") != null) && + (SwingUtils.findLabel(window, "will reset the order entry.") != null); + } +} + From b62838d38d209aa1baffb9ad7700e1e1154bff76 Mon Sep 17 00:00:00 2001 From: Stanislav Vinokurov Date: Sun, 16 Jan 2022 16:31:50 +0300 Subject: [PATCH 2/3] Add 'You must enter a valid price.' dialog handler. --- src/ibcalpha/ibc/IbcTws.java | 1 + .../ibc/MustEnterValidPriceDialogHandler.java | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java diff --git a/src/ibcalpha/ibc/IbcTws.java b/src/ibcalpha/ibc/IbcTws.java index 3672dad..43613ce 100644 --- a/src/ibcalpha/ibc/IbcTws.java +++ b/src/ibcalpha/ibc/IbcTws.java @@ -334,6 +334,7 @@ private static List createWindowHandlers() { windowHandlers.add(new BidAskLastSizeDisplayUpdateDialogHandler()); windowHandlers.add(new LoginErrorDialogHandler()); windowHandlers.add(new NavigatingAwayDialogHandler()); + windowHandlers.add(new MustEnterValidPriceDialogHandler()); return windowHandlers; } diff --git a/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java b/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java new file mode 100644 index 0000000..79d6326 --- /dev/null +++ b/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java @@ -0,0 +1,50 @@ +// This file is part of IBC. +// Copyright (C) 2004 Steven M. Kearns (skearns23@yahoo.com ) +// Copyright (C) 2004 - 2018 Richard L King (rlking@aultan.com) +// For conditions of distribution and use, see copyright notice in COPYING.txt + +// IBC is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// IBC is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with IBC. If not, see . + +package ibcalpha.ibc; + +import java.awt.Window; +import java.awt.event.WindowEvent; +import javax.swing.JDialog; + +class MustEnterValidPriceDialogHandler implements WindowHandler { + public boolean filterEvent(Window window, int eventId) { + switch (eventId) { + case WindowEvent.WINDOW_OPENED: + return true; + default: + return false; + } + } + + public void handleWindow(Window window, int eventID) { + //if (! Settings.settings().getBoolean("SuppressYouMustEnterValidPriceWarning", false)) return; + + if (SwingUtils.clickButton(window, "OK")) { + } else { + Utils.logError("can't close 'You must enter a valid price' window: 'OK' button not found"); + } + } + + public boolean recogniseWindow(Window window) { + if (! (window instanceof JDialog)) return false; + + return (SwingUtils.findLabel(window, "You must enter a valid price.") != null); + } +} + From a2f7c0adb44c73dabb02516866a85df0a2b8f242 Mon Sep 17 00:00:00 2001 From: Stanislav Vinokurov Date: Sun, 16 Jan 2022 18:40:57 +0300 Subject: [PATCH 3/3] NavigatingAwayDialogHandler now supports TWS 1012. MustEnterValidPriceDialogHandler: now really works with TWS 1012. --- src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java | 5 +++-- src/ibcalpha/ibc/NavigatingAwayDialogHandler.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java b/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java index 79d6326..3ae49a7 100644 --- a/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java +++ b/src/ibcalpha/ibc/MustEnterValidPriceDialogHandler.java @@ -33,7 +33,7 @@ public boolean filterEvent(Window window, int eventId) { } public void handleWindow(Window window, int eventID) { - //if (! Settings.settings().getBoolean("SuppressYouMustEnterValidPriceWarning", false)) return; + if (! Settings.settings().getBoolean("SuppressYouMustEnterValidPriceWarning", false)) return; if (SwingUtils.clickButton(window, "OK")) { } else { @@ -44,7 +44,8 @@ public void handleWindow(Window window, int eventID) { public boolean recogniseWindow(Window window) { if (! (window instanceof JDialog)) return false; - return (SwingUtils.findLabel(window, "You must enter a valid price.") != null); + return (SwingUtils.findTextPane(window, "You must enter a valid price") != null); + } } diff --git a/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java b/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java index a5e63dd..3f49864 100644 --- a/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java +++ b/src/ibcalpha/ibc/NavigatingAwayDialogHandler.java @@ -21,6 +21,7 @@ import java.awt.Window; import java.awt.event.WindowEvent; import javax.swing.JDialog; +import javax.swing.JOptionPane; class NavigatingAwayDialogHandler implements WindowHandler { public boolean filterEvent(Window window, int eventId) { @@ -44,6 +45,15 @@ public void handleWindow(Window window, int eventID) { public boolean recogniseWindow(Window window) { if (! (window instanceof JDialog)) return false; + JOptionPane optionsPane = SwingUtils.findOptionPane(window); + + if (optionsPane == null) return false; + + String label = optionsPane.getMessage().toString(); + + if (label.contains("Navigating away from") && label.contains("will reset the order entry.")) + return true; + return (SwingUtils.findLabel(window, "Navigating away from") != null) && (SwingUtils.findLabel(window, "will reset the order entry.") != null); }