Skip to content

Commit 14b849a

Browse files
committed
Blender setup: allow to select installation directory
1 parent 97478d1 commit 14b849a

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

mastodon-plugin/src/main/java/org/mastodon/blender/setup/BlenderSetupController.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ private void setState( State state )
7979
@Override
8080
public void setBlenderPath( Path blenderPath )
8181
{
82-
this.blenderPath = blenderPath;
83-
frame.setBlenderPath( blenderPath );
82+
this.blenderPath = deriveBinaryFromDirectory( blenderPath );
83+
frame.setBlenderPath( this.blenderPath );
8484
if ( this.blenderPath == null)
8585
setState( State.PATH_NOT_SET );
8686
else if ( Files.isDirectory( this.blenderPath ) )
@@ -95,6 +95,21 @@ else if ( !BlenderSetupUtils.isMastodonAddonInstalled( this.blenderPath ))
9595
setState( State.ADDON_INSTALLED );
9696
}
9797

98+
private Path deriveBinaryFromDirectory( Path blenderPath )
99+
{
100+
if ( blenderPath == null )
101+
return null;
102+
if ( Files.isDirectory( blenderPath ) ) {
103+
Path blenderExe = blenderPath.resolve( "blender.exe" );
104+
if ( Files.exists( blenderExe ) && Files.isExecutable( blenderExe ) )
105+
return blenderExe;
106+
Path blenderBinary = blenderPath.resolve( "blender" );
107+
if ( Files.exists( blenderBinary ) && Files.isExecutable( blenderBinary ) )
108+
return blenderBinary;
109+
}
110+
return blenderPath;
111+
}
112+
98113
@Override
99114
public void installAddonClicked()
100115
{

mastodon-plugin/src/main/java/org/mastodon/blender/setup/BlenderSetupView.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.swing.JDialog;
3535
import javax.swing.JLabel;
3636
import javax.swing.JTextArea;
37+
import javax.swing.filechooser.FileFilter;
3738
import net.miginfocom.swing.MigLayout;
3839
import org.mastodon.ui.util.FileChooser;
3940

@@ -80,9 +81,6 @@ public class BlenderSetupView extends JDialog
8081

8182
setLayout( new MigLayout("insets dialog, fill", "[][grow]") );
8283

83-
// TODO: Allow to select directory.
84-
// TODO: Make setup not modal
85-
8684
final String introText = "<html><body>"
8785
+ "Mastodon can use Blender to visualise cell trackings in 3D. "
8886
+ "In order to achieve this, it is required to install "
@@ -178,7 +176,32 @@ private JComponent setFonStyle( JComponent component, int style )
178176
private void onSelectPathClicked()
179177
{
180178
String selectedFile = blenderPath == null ? null : blenderPath.toString();
181-
File file = FileChooser.chooseFile( this, selectedFile, FileChooser.DialogType.LOAD );
179+
FileFilter filenameFilter = new FileFilter()
180+
{
181+
@Override
182+
public boolean accept( File f )
183+
{
184+
if ( f.isDirectory() )
185+
return true;
186+
String name = f.getName();
187+
return name.equals( "blender" )
188+
|| name.equals( "blender-softwaregl" )
189+
|| name.equals( "blender.exe" )
190+
|| name.equals( "Blender" );
191+
}
192+
193+
@Override
194+
public String getDescription()
195+
{
196+
return "Blender Binary (blender.exe etc.)";
197+
}
198+
};
199+
File file = FileChooser.chooseFile( this,
200+
selectedFile,
201+
filenameFilter,
202+
"Select Blender Installation",
203+
FileChooser.DialogType.LOAD,
204+
FileChooser.SelectionMode.FILES_AND_DIRECTORIES );
182205
if(file == null)
183206
return;
184207
listener.setBlenderPath( file.toPath() );

0 commit comments

Comments
 (0)