package com.imyeyu.fx.ui.components.alert;

import com.imyeyu.fx.icon.TimiFXIcon;
import com.imyeyu.fx.icon.TimiIcon;
import com.imyeyu.fx.ui.TimiFXUI;
import javafx.beans.binding.Bindings;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;

import java.io.File;

/**
 * 目录选择
 *
 * @author 夜雨
 * @since 2022-05-20 10:55
 */
public class AlertFilePathSelector extends AbstractAlertFile {

	/**
	 * 构造器
	 *
	 * @param mode 选择模式
	 */
	public AlertFilePathSelector(SelectionMode mode) {
		super(mode);

		// 确认
		confirm.disableProperty().bind(Bindings.createBooleanBinding(() -> {
			TreeItem<File> item = tree.getSelectionModel().getSelectedItem();
			return item == null || item.getValue().isFile();
		}, tree.getSelectionModel().selectedItemProperty()));

		getIcons().setAll(TimiFXIcon.rerender(TimiIcon.FOLDER));
		setTitle(TimiFXUI.MULTILINGUAL.text("file.tips.select_directory"));

		addItemFilter(File::isDirectory);
	}
}