Skip to content

Commit

Permalink
Merge branch 'Bubb13-fix-advanced-search' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Oct 12, 2023
2 parents 49fe279 + 4037ee7 commit 8ee849b
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 42 deletions.
6 changes: 5 additions & 1 deletion src/org/infinity/NearInfinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,11 @@ public boolean removeViewable() {
}

public void showResourceEntry(ResourceEntry resourceEntry) {
tree.select(resourceEntry);
showResourceEntry(resourceEntry, null);
}

public void showResourceEntry(ResourceEntry resourceEntry, Operation doneOperation) {
tree.select(resourceEntry, doneOperation);
}

public void quit() {
Expand Down
7 changes: 4 additions & 3 deletions src/org/infinity/check/BCSIDSChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ public void actionPerformed(ActionEvent event) {
int row = table.getSelectedRow();
if (row != -1) {
ResourceEntry resourceEntry = (ResourceEntry) table.getValueAt(row, 0);
NearInfinity.getInstance().showResourceEntry(resourceEntry);
BcsResource bcsfile = (BcsResource) NearInfinity.getInstance().getViewable();
bcsfile.highlightText(((Integer) table.getValueAt(row, 2)), null);
NearInfinity.getInstance().showResourceEntry(resourceEntry, () -> {
final BcsResource bcsfile = (BcsResource) NearInfinity.getInstance().getViewable();
bcsfile.highlightText(((Integer) table.getValueAt(row, 2)), null);
});
}
} else if (event.getSource() == bopennew) {
int row = table.getSelectedRow();
Expand Down
6 changes: 3 additions & 3 deletions src/org/infinity/check/CreInvChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void actionPerformed(ActionEvent event) {
int row = table.getSelectedRow();
if (row != -1) {
ResourceEntry resourceEntry = (ResourceEntry) table.getValueAt(row, 0);
NearInfinity.getInstance().showResourceEntry(resourceEntry);
((AbstractStruct) NearInfinity.getInstance().getViewable()).getViewer()
.selectEntry(((Item) table.getValueAt(row, 2)).getName());
NearInfinity.getInstance().showResourceEntry(resourceEntry,
() -> ((AbstractStruct)NearInfinity.getInstance().getViewable()).getViewer()
.selectEntry(((Item)table.getValueAt(row, 2)).getName()));
}
} else if (event.getSource() == bopennew) {
int row = table.getSelectedRow();
Expand Down
7 changes: 4 additions & 3 deletions src/org/infinity/check/DialogChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public void actionPerformed(ActionEvent event) {
int row = table.getSelectedRow();
if (row != -1) {
ResourceEntry resourceEntry = (ResourceEntry) table.getValueAt(row, 0);
NearInfinity.getInstance().showResourceEntry(resourceEntry);
((AbstractStruct) NearInfinity.getInstance().getViewable()).getViewer()
.selectEntry((String) table.getValueAt(row, 1));
final SortableTable tableCapture = table;
NearInfinity.getInstance().showResourceEntry(resourceEntry,
() -> ((AbstractStruct)NearInfinity.getInstance().getViewable()).getViewer()
.selectEntry((String)tableCapture.getValueAt(row, 1)));
}
} else if (event.getSource() == bopennew) {
int row = table.getSelectedRow();
Expand Down
7 changes: 4 additions & 3 deletions src/org/infinity/check/ScriptChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public void actionPerformed(ActionEvent event) {
int row = table.getSelectedRow();
if (row != -1) {
ResourceEntry resourceEntry = (ResourceEntry) table.getValueAt(row, 0);
NearInfinity.getInstance().showResourceEntry(resourceEntry);
((BcsResource) NearInfinity.getInstance().getViewable()).highlightText(((Integer) table.getValueAt(row, 2)),
null);
final SortableTable tableCapture = table;
NearInfinity.getInstance().showResourceEntry(resourceEntry,
() -> ((BcsResource)NearInfinity.getInstance().getViewable())
.highlightText(((Integer)tableCapture.getValueAt(row, 2)), null));
}
} else if (event.getSource() == bopennew) {
int row = table.getSelectedRow();
Expand Down
40 changes: 28 additions & 12 deletions src/org/infinity/gui/ResourceTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.infinity.resource.key.ResourceTreeFolder;
import org.infinity.resource.key.ResourceTreeModel;
import org.infinity.util.IconCache;
import org.infinity.util.Operation;
import org.infinity.util.io.FileEx;
import org.infinity.util.io.FileManager;
import org.infinity.util.io.StreamUtils;
Expand Down Expand Up @@ -192,24 +193,39 @@ public void select(ResourceEntry entry) {
}

public void select(ResourceEntry entry, boolean forced) {
select(entry, forced, null);
}

public void select(ResourceEntry entry, Operation doneOperation) {
select(entry, false, doneOperation);
}

public void select(ResourceEntry entry, boolean forced, Operation doneOperation) {
new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
if (entry == null) {
tree.clearSelection();
} else if (forced || entry != shownResource) {
TreePath tp = ResourceFactory.getResourceTreeModel().getPathToNode(entry);
try {
expandListener.treeWillExpand(new TreeExpansionEvent(tree, tp));
tree.scrollPathToVisible(tp);
tree.addSelectionPath(tp);
tree.repaint();
} finally {
expandListener.treeExpanded(new TreeExpansionEvent(tree, tp));
}
if (entry == null) {
tree.clearSelection();
} else if (forced || entry != shownResource) {
TreePath tp = ResourceFactory.getResourceTreeModel().getPathToNode(entry);
try {
expandListener.treeWillExpand(new TreeExpansionEvent(tree, tp));
tree.scrollPathToVisible(tp);
tree.addSelectionPath(tp);
tree.repaint();
} finally {
expandListener.treeExpanded(new TreeExpansionEvent(tree, tp));
}
}
return null;
}

@Override
protected void done() {
if (doneOperation != null) {
doneOperation.perform();
}
}
}.execute();
}

Expand Down
13 changes: 7 additions & 6 deletions src/org/infinity/search/ReferenceHitFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ public void actionPerformed(ActionEvent event) {
((ViewFrame) parent).toFront();
}
} else {
NearInfinity.getInstance().showResourceEntry(entry);
Viewable viewable = NearInfinity.getInstance().getViewable();
showEntryInViewer(row, viewable);
if (viewable instanceof DlgResource) {
NearInfinity.getInstance().toFront();
}
NearInfinity.getInstance().showResourceEntry(entry, () -> {
Viewable viewable = NearInfinity.getInstance().getViewable();
showEntryInViewer(row, viewable);
if (viewable instanceof DlgResource) {
NearInfinity.getInstance().toFront();
}
});
}
}
} else if (event.getSource() == bopennew) {
Expand Down
11 changes: 6 additions & 5 deletions src/org/infinity/search/TextHitFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ public void actionPerformed(ActionEvent event) {
((TextResource) res).highlightText(((Integer) table.getValueAt(row, 2)), query);
}
} else {
NearInfinity.getInstance().showResourceEntry(entry);
Viewable viewable = NearInfinity.getInstance().getViewable();
if (viewable instanceof TextResource) {
((TextResource) viewable).highlightText(((Integer) table.getValueAt(row, 2)), query);
}
NearInfinity.getInstance().showResourceEntry(entry, () -> {
Viewable viewable = NearInfinity.getInstance().getViewable();
if (viewable instanceof TextResource) {
((TextResource) viewable).highlightText(((Integer) table.getValueAt(row, 2)), query);
}
});
}
}
} else if (event.getSource() == bopennew) {
Expand Down
13 changes: 7 additions & 6 deletions src/org/infinity/search/advanced/AdvancedSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,13 @@ public void actionPerformed(ActionEvent event) {
if (row != -1) {
ResourceEntry entry = (ResourceEntry) listResults.getValueAt(row, 0);
if (entry != null) {
NearInfinity.getInstance().showResourceEntry(entry);
Viewable viewable = NearInfinity.getInstance().getViewable();
showEntryInViewer(row, viewable);
if (viewable instanceof DlgResource) {
NearInfinity.getInstance().toFront();
}
NearInfinity.getInstance().showResourceEntry(entry, () -> {
Viewable viewable = NearInfinity.getInstance().getViewable();
showEntryInViewer(row, viewable);
if (viewable instanceof DlgResource) {
NearInfinity.getInstance().toFront();
}
});
}
}
} else if (event.getSource() == bOpenNew) {
Expand Down

0 comments on commit 8ee849b

Please sign in to comment.