Skip to content

Commit

Permalink
Merge pull request #186 from raeleus/Stop-input-with-file-picker
Browse files Browse the repository at this point in the history
Stop receiving input when the file picker is open
  • Loading branch information
tommyettinger authored Jul 15, 2024
2 parents 5bf195b + 5235d08 commit c02a10b
Showing 1 changed file with 62 additions and 47 deletions.
109 changes: 62 additions & 47 deletions src/main/java/gdx/liftoff/ui/panels/PathsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Cursor.SystemCursor;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
Expand Down Expand Up @@ -39,33 +40,40 @@ public void populate(boolean fullscreen) {
TextButton projectFieldButton = addField(UserData.projectPath);
addTooltip(projectFieldButton, label, Align.top, 0, prop.getProperty("destinationTip"));
onChange(projectFieldButton, () -> {
FileHandle initialFolder = Gdx.files.absolute(Gdx.files.getExternalStoragePath());
if (UserData.projectPath != null && !UserData.projectPath.isEmpty())
initialFolder = Gdx.files.absolute(UserData.projectPath);

Main.pickDirectory(initialFolder, new FileChooserAdapter() {
@Override
public void canceled() {

}

@Override
public void selected(Array<FileHandle> files) {
if (files.size > 0) {
String path = files.first().path();
projectFieldButton.setText(path);
UserData.projectPath = path;
pref.putString("projectPath", path);
pref.flush();
updateError();
if (FullscreenDialog.fullscreenDialog != null)
FullscreenDialog.fullscreenDialog.updateGenerateButtons();
if (root.settingsTable != null) root.settingsTable.updateGenerateButton();
root.quickSettingsTable.populate();
updateDeleteProjectPathButton();
Gdx.input.setInputProcessor(null);
Gdx.graphics.setSystemCursor(SystemCursor.Arrow);

Thread filePickerThread = new Thread(() -> {
FileHandle initialFolder = Gdx.files.absolute(Gdx.files.getExternalStoragePath());
if (UserData.projectPath != null && !UserData.projectPath.isEmpty())
initialFolder = Gdx.files.absolute(UserData.projectPath);

Main.pickDirectory(initialFolder, new FileChooserAdapter() {
@Override
public void canceled() {
Gdx.app.postRunnable(() -> Gdx.input.setInputProcessor(stage));
}
}

@Override
public void selected(Array<FileHandle> files) {
if (files.size > 0) {
String path = files.first().path();
projectFieldButton.setText(path);
UserData.projectPath = path;
pref.putString("projectPath", path);
pref.flush();
updateError();
if (FullscreenDialog.fullscreenDialog != null)
FullscreenDialog.fullscreenDialog.updateGenerateButtons();
if (root.settingsTable != null) root.settingsTable.updateGenerateButton();
root.quickSettingsTable.populate();
updateDeleteProjectPathButton();
}
Gdx.app.postRunnable(() -> Gdx.input.setInputProcessor(stage));
}
});
});
filePickerThread.start();
});

//select folder button
Expand Down Expand Up @@ -95,31 +103,38 @@ public void selected(Array<FileHandle> files) {
TextButton androidFieldButton = addField(UserData.androidPath);
addTooltip(androidFieldButton, label, Align.top, 0, prop.getProperty("sdkTip"));
onChange(androidFieldButton, () -> {
FileHandle initialFolder = Gdx.files.absolute(Gdx.files.getExternalStoragePath());
if (UserData.androidPath != null && !UserData.androidPath.isEmpty())
initialFolder = Gdx.files.absolute(UserData.androidPath);

Main.pickDirectory(initialFolder, new FileChooserAdapter() {
@Override
public void canceled() {

}
Gdx.input.setInputProcessor(null);
Gdx.graphics.setSystemCursor(SystemCursor.Arrow);

Thread filePickerThread = new Thread(() -> {
FileHandle initialFolder = Gdx.files.absolute(Gdx.files.getExternalStoragePath());
if (UserData.androidPath != null && !UserData.androidPath.isEmpty())
initialFolder = Gdx.files.absolute(UserData.androidPath);

Main.pickDirectory(initialFolder, new FileChooserAdapter() {
@Override
public void canceled() {
Gdx.app.postRunnable(() -> Gdx.input.setInputProcessor(stage));
}

@Override
public void selected(Array<FileHandle> files) {
if (files.size > 0) {
String path = files.first().path();
androidFieldButton.setText(path);
UserData.androidPath = path;
pref.putString("AndroidSdk", path);
pref.flush();
updateError();
if (FullscreenDialog.fullscreenDialog != null)
FullscreenDialog.fullscreenDialog.updateGenerateButtons();
if (root.settingsTable != null) root.settingsTable.updateGenerateButton();
@Override
public void selected(Array<FileHandle> files) {
if (files.size > 0) {
String path = files.first().path();
androidFieldButton.setText(path);
UserData.androidPath = path;
pref.putString("AndroidSdk", path);
pref.flush();
updateError();
if (FullscreenDialog.fullscreenDialog != null)
FullscreenDialog.fullscreenDialog.updateGenerateButtons();
if (root.settingsTable != null) root.settingsTable.updateGenerateButton();
}
Gdx.app.postRunnable(() -> Gdx.input.setInputProcessor(stage));
}
}
});
});
filePickerThread.start();
});

button = new Button(skin, "folder");
Expand Down

0 comments on commit c02a10b

Please sign in to comment.