Skip to content

Commit

Permalink
Move cursor to path field end, #176
Browse files Browse the repository at this point in the history
  • Loading branch information
kotcrab committed Aug 3, 2016
1 parent 154e20d commit 6880e77
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ui/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- **Changed**: `FileTypeFilter` select box won't be shown when `FileChooser` `SelectionMode` is set to `DIRECTORIES`
- **Changed**: `FileChooser` now can be closed by pressing enter when file name field has focus
- **Changed**: `Dialogs#showOKDialog` can be closed using enter and escape key
- **Changed**: `FileChooser` will fallback to default directory when `setDirectory` is called with invalid file handle (either non existing path or poiting to file)
- **Changed**: [#176 (comment)](https://github.com/kotcrab/vis-editor/issues/176#issuecomment-237046516) - `FileChooser` path text field will now show end of the path when it's too long
- **Changed**: `FileChooser` will fallback to default directory when `setDirectory` is called with invalid file handle (either non existing path or pointing to file)
- Fixes possible crash when current directory is removed while it's open in file chooser
- Removed protected `handleAsyncError`, no longer needed

Expand Down
18 changes: 10 additions & 8 deletions ui/src/main/java/com/kotcrab/vis/ui/widget/file/FileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public class FileChooser extends VisWindow implements FileHistoryCallback {
private DirsSuggestionPopup dirsSuggestionPopup;
private VisLabel fileTypeLabel;
private PopupMenu viewModePopupMenu;
private FileHandle defaultStartingDirectory;

/** @param mode whether this chooser will be used to open or save files */
public FileChooser (Mode mode) {
Expand Down Expand Up @@ -289,9 +288,7 @@ private void createToolbar () {
@Override
public void activeItemChanged (MenuItem newItem, boolean changedByKeyboard) {
if (changedByKeyboard == false || newItem == null) return;

currentPath.setText(newItem.getText().toString());
currentPath.setCursorPosition(currentPath.getText().length());
setCurrentPathFieldText(newItem.getText().toString());
}
});

Expand All @@ -317,7 +314,7 @@ public boolean keyDown (InputEvent event, int keycode) {
addRecentDirectory(file);
} else {
showDialog(POPUP_DIRECTORY_DOES_NOT_EXIST.get());
currentPath.setText(currentDirectory.path());
setCurrentPathFieldText(currentDirectory.path());
}
event.stop();
}
Expand All @@ -330,7 +327,7 @@ public boolean keyDown (InputEvent event, int keycode) {
@Override
public void keyboardFocusChanged (FocusEvent event, Actor actor, boolean focused) {
if (focused == false) {
currentPath.setText(currentDirectory.path());
setCurrentPathFieldText(currentDirectory.path());
}
}
});
Expand Down Expand Up @@ -499,6 +496,11 @@ else if (actor instanceof Layout)
}
}

private void setCurrentPathFieldText (String text) {
currentPath.setText(text);
currentPath.setCursorAtTextEnd();
}

private void createFileTextBox () {
VisTable table = new VisTable(true);
VisLabel nameLabel = new VisLabel(FILE_NAME.get());
Expand Down Expand Up @@ -862,7 +864,7 @@ private void rebuildFileList () {
}
deselectAll();

currentPath.setText(currentDirectory.path());
setCurrentPathFieldText(currentDirectory.path());

if (showBusyBarTask.isScheduled() == false) {
Timer.schedule(showBusyBarTask, 0.2f); //quite period before busy bar is shown
Expand Down Expand Up @@ -1054,7 +1056,7 @@ private void updateSelectedFileFieldText () {

selectedFileTextField.setText(builder.toString());
}
selectedFileTextField.setCurosrAtTextEnd();
selectedFileTextField.setCursorAtTextEnd();
}

private void removeInvalidSelections () {
Expand Down

0 comments on commit 6880e77

Please sign in to comment.