GP-2059 improve GhidraFileChooser interactivity

Refactor how file system root locations are handled to avoid potential slowdowns and swing thread blocking.
This commit is contained in:
dev747368 2022-06-02 14:57:58 -04:00
parent b6501c8283
commit c99f770b23
8 changed files with 287 additions and 273 deletions

View file

@ -1,30 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ghidra.util.filechooser;
/**
* A listener for notifying when the contents
* of the file chooser model have changed.
*
*/
public interface GhidraFileChooserListener {
/**
* Invoked when the contents of the file
* chooser model have changed.
*/
public void modelChanged();
}

View file

@ -15,11 +15,15 @@
*/
package ghidra.util.filechooser;
import java.util.List;
import java.io.File;
import java.io.FileFilter;
import javax.swing.Icon;
import utility.function.Callback;
/**
* Interface for the GhidraFileChooser data model.
* This allows the GhidraFileChooser to operate
@ -28,13 +32,15 @@ import javax.swing.Icon;
*/
public interface GhidraFileChooserModel {
/**
* Set the model listener.
* @param l the new model listener
* Set the model update callback.
*
* @param callback the new model update callback handler
*/
public void setListener(GhidraFileChooserListener l);
public void setModelUpdateCallback(Callback callback);
/**
* Returns the home directory.
*
* @return the home directory
*/
public File getHomeDirectory();
@ -43,12 +49,13 @@ public interface GhidraFileChooserModel {
* Returns the user's desktop directory, as defined by their operating system and/or their windowing environment, or
* null if there is no desktop directory.<p>
* Example: "/home/the_user/Desktop" or "c:/Users/the_user/Desktop"
*
* @return desktop directory
*/
public File getDesktopDirectory();
/**
* Returns the root drives/directories.
* Returns a list of the root drives/directories.
* <p>
* On windows, "C:\", "D:\", etc.
* <p>
@ -57,18 +64,20 @@ public interface GhidraFileChooserModel {
* @param forceUpdate if true, request a fresh listing, if false allow a cached result
* @return the root drives
*/
public File[] getRoots(boolean forceUpdate);
public List<File> getRoots(boolean forceUpdate);
/**
* Returns an array of the files that
* exist in the specified directory.
*
* @param directory the directory
* @return an array of files
* @return list of files
*/
public File[] getListing(File directory, FileFilter filter);
public List<File> getListing(File directory, FileFilter filter);
/**
* Returns an icon for the specified file.
*
* @param file the file
* @return an icon for the specified file
*/