Updated the help window to not preserve the previous location on a new

request for the same page
This commit is contained in:
dragonmacher 2025-03-10 19:01:48 -04:00
parent 73d29e3488
commit ef7c79f0c0
4 changed files with 23 additions and 14 deletions

View file

@ -573,7 +573,7 @@ public class DisassembledViewPlugin extends ProgramPlugin implements DomainObjec
/** /**
* Returns true if there is a {@link CodeUnit} for the address * Returns true if there is a {@link CodeUnit} for the address
* wrapped by this info. If not, then we do not have a valid addreess. * wrapped by this info. If not, then we do not have a valid address.
* *
* @return true if there is a {@link CodeUnit} for the address * @return true if there is a {@link CodeUnit} for the address
* wrapped by this info. * wrapped by this info.

View file

@ -142,7 +142,7 @@ public class DockingHelpBroker extends GHelpBroker {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
reloadHelpPage(getCurrentURL()); reloadHelpPage(getCurrentURL(), true);
} }
}; };
toolbar.add(new JButton(refreshAction)); toolbar.add(new JButton(refreshAction));
@ -150,8 +150,8 @@ public class DockingHelpBroker extends GHelpBroker {
} }
@Override // opened access @Override // opened access
protected void reloadHelpPage(URL url) { protected void reloadHelpPage(URL url, boolean preserveLocation) {
super.reloadHelpPage(url); super.reloadHelpPage(url, preserveLocation);
} }
//================================================================================================= //=================================================================================================

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -462,7 +462,7 @@ public class HelpManager implements HelpService {
// an invokeLater() will work as long as the model loading is // an invokeLater() will work as long as the model loading is
// relatively quick. // relatively quick.
// //
SystemUtilities.runSwingLater(() -> displayHelp(help, owner)); Swing.runLater(() -> displayHelp(help, owner));
return; return;
} }
@ -596,7 +596,10 @@ public class HelpManager implements HelpService {
return; return;
} }
((DockingHelpBroker) mainHB).reloadHelpPage(validateUrl(helpURL)); // Let the URL dictate where the page scrolls to. If we do not do this, then there is an
// odd effect of having the page load and then jump to a previous location.
boolean preserveLocation = false;
((DockingHelpBroker) mainHB).reloadHelpPage(validateUrl(helpURL), preserveLocation);
} }
private URL getURLForID(ID ID) { private URL getURLForID(ID ID) {

View file

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -85,14 +85,14 @@ public class GHelpBroker extends DefaultHelpBroker {
} }
/* Perform some shenanigans to force Java Help to reload the given URL */ /* Perform some shenanigans to force Java Help to reload the given URL */
protected void reloadHelpPage(URL url) { protected void reloadHelpPage(URL url, boolean preserveLocation) {
clearContentViewer(); clearContentViewer();
showNavigationAid(url); showNavigationAid(url);
try { try {
// Page loading is asynchronous. Listen for the page to be loaded and then restore the // Page loading is asynchronous. Listen for the page to be loaded and then restore the
// users current view state. // users current view state.
htmlEditorPane.addPropertyChangeListener(new PageLocationUpdater()); htmlEditorPane.addPropertyChangeListener(new PageLocationUpdater(preserveLocation));
htmlEditorPane.setPage(url); htmlEditorPane.setPage(url);
} }
catch (IOException e) { catch (IOException e) {
@ -102,7 +102,7 @@ public class GHelpBroker extends DefaultHelpBroker {
} }
private void reloadHelpPage() { private void reloadHelpPage() {
reloadHelpPage(getCurrentURL()); reloadHelpPage(getCurrentURL(), true);
} }
public void reload() { public void reload() {
@ -378,8 +378,10 @@ public class GHelpBroker extends DefaultHelpBroker {
private URL url; private URL url;
private int caretPosition; private int caretPosition;
private Rectangle viewPosition; private Rectangle viewPosition;
private boolean preserveLocation;
PageLocationUpdater() { PageLocationUpdater(boolean preserveLocation) {
this.preserveLocation = preserveLocation;
url = getCurrentURL(); url = getCurrentURL();
caretPosition = htmlEditorPane.getCaretPosition(); caretPosition = htmlEditorPane.getCaretPosition();
viewPosition = htmlEditorPane.getVisibleRect(); viewPosition = htmlEditorPane.getVisibleRect();
@ -399,6 +401,10 @@ public class GHelpBroker extends DefaultHelpBroker {
return; // new page loaded; ignore return; // new page loaded; ignore
} }
if (!preserveLocation) {
return;
}
htmlEditorPane.setCaretPosition(caretPosition); htmlEditorPane.setCaretPosition(caretPosition);
// not sure why this needs to be done later, but setting the caret seems to trigger a // not sure why this needs to be done later, but setting the caret seems to trigger a
// view updated, so try to run after that // view updated, so try to run after that