MichaelJakubec / gtkjfilechooser

Automatically exported from code.google.com/p/gtkjfilechooser
1 stars 0 forks source link

setCurrentDirectory is not working #85

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a new JFileChooser.
2. Set the current directory.
3. Show open dialog.

What is the expected output? What do you see instead?
Expected:  Should be current directory.
Reality: It always starts with the "~HOME" directory.

Can you attach an Exception stacktrace or a screenshot?
N/A

What version of the gtkjfilechooser are you using?
1.4.9

What linux/unix distro are you using and which version of gtk (use "uname
-a" and "pkg-config --modversion gtk+-2.0" to get both information)?

uname: Linux Cobus-PC 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 
2012 x86_64 x86_64 x86_64 GNU/Linux

I am using Ubuntu 12.04

Please provide any additional information below.
Using Java Runtime 1.6

Original issue reported on code.google.com by stroebel...@gmail.com on 14 Nov 2012 at 11:58

GoogleCodeExporter commented 9 years ago
After some browsing of the code, the source of this bug seems to be 
in GTKFileChooserUI:
------------------
    private void doDirectoryChanged(File olddir, File newdir, Object source) {
        if (getFileChooser().getCurrentDirectory().equals(newdir)) {
            // to avoid repeated invocations on the same directory.
            return;
        }
        [...]
-------------------
See line 1256 in com/google/code/gtkjfilechooser/ui/GtkFileChooserUI.java 

The value of newdir should be compared to the value of olddir, but instead it 
is compared to the value of the currentDirectory field of the file chooser. 

The property change that triggers invocation of doDirectoryChanged is fired 
from JFileChooser.setCurrentDirectory, which has already set the file chooser's 
currentDirectory field to newdir, so the .equals method call always returns 
true and doDirectoryChanged returns without doing anything. 

The method should be modified like this:
---------------------
    private void doDirectoryChanged(File olddir, File newdir, Object source) {
        if (olddir != null ? olddir.equals(newdir) : newdir == null) {
            // to avoid repeated invocations on the same directory.
            return;
        }
        [...]
---------------------

Original comment by mchaber...@biometricgroup.com on 23 Jan 2013 at 9:29