Search in sources :

Example 11 with FileChooserAdapter

use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project talos by rockbite.

the class SettingsDialog method addScriptPathSetting.

public void addScriptPathSetting(Table container) {
    Table inputTable = new Table();
    String sceneEditorExportScriptPath = TalosMain.Instance().Prefs().getString("sceneEditorExportScriptPath", null);
    inputTable.add(new Label("BuildScript location (JS)", getSkin())).width(180);
    exportScriptPathField = new TextField(sceneEditorExportScriptPath, getSkin());
    inputTable.add(exportScriptPathField).padLeft(13).width(130);
    TextButton browseInputBtn = new TextButton("Browse", getSkin());
    inputTable.add(browseInputBtn).padLeft(3);
    FileChooser fileChooser = new FileChooser(FileChooser.Mode.SAVE);
    fileChooser.setBackground(getSkin().getDrawable("window-noborder"));
    browseInputBtn.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            super.clicked(event, x, y);
            fileChooser.setMode(FileChooser.Mode.SAVE);
            fileChooser.setMultiSelectionEnabled(false);
            fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
            String currentProjectPath = TalosMain.Instance().ProjectController().getCurrentProjectPath();
            String sceneEditorExportScriptPath = TalosMain.Instance().Prefs().getString("sceneEditorExportScriptPath", null);
            if (sceneEditorExportScriptPath != null) {
                FileHandle path = Gdx.files.absolute(sceneEditorExportScriptPath);
                fileChooser.setDirectory(path.parent().file());
                fileChooser.setDefaultFileName(path.name());
                exportScriptPathField.setText(path.path());
            } else {
                fileChooser.setDirectory(Gdx.files.absolute(currentProjectPath).parent().file());
                fileChooser.setDefaultFileName("buildscript.js");
            }
            fileChooser.setListener(new FileChooserAdapter() {

                @Override
                public void selected(Array<FileHandle> files) {
                    FileHandle file = files.first();
                    exportScriptPathField.setText(file.path());
                }
            });
            getStage().addActor(fileChooser.fadeIn());
        }
    });
    container.add(inputTable).pad(10).expand().growX().left();
    container.row();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Array(com.badlogic.gdx.utils.Array) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 12 with FileChooserAdapter

use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project talos by rockbite.

the class UIStage method openProjectAction.

public void openProjectAction(final IProject projectType) {
    String defaultLocation = TalosMain.Instance().ProjectController().getLastDir("Open", projectType);
    if (defaultLocation.equals("")) {
        TalosMain.Instance().ProjectController().getLastDir("Save", projectType);
    }
    fileChooser.setDirectory(defaultLocation);
    fileChooser.setMode(FileChooser.Mode.OPEN);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() || pathname.getAbsolutePath().endsWith(projectType.getExtension());
        }
    });
    fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
    fileChooser.setListener(new FileChooserAdapter() {

        @Override
        public void selected(Array<FileHandle> file) {
            String path = file.first().file().getAbsolutePath();
            TalosMain.Instance().ProjectController().setProject(projectType);
            TalosMain.Instance().ProjectController().loadProject(Gdx.files.absolute(path));
        }
    });
    stage.addActor(fileChooser.fadeIn());
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter) FileFilter(java.io.FileFilter) File(java.io.File)

Example 13 with FileChooserAdapter

use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project talos by rockbite.

the class UIStage method legacyImportAction.

public void legacyImportAction() {
    fileChooser.setMode(FileChooser.Mode.OPEN);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileFilter(new FileChooser.DefaultFileFilter(fileChooser));
    fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
    fileChooser.setListener(new FileChooserAdapter() {

        @Override
        public void selected(Array<FileHandle> file) {
            TalosMain.Instance().TalosProject().importFromLegacyFormat(file.get(0));
            TalosMain.Instance().ProjectController().unbindFromFile();
        }
    });
    stage.addActor(fileChooser.fadeIn());
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter)

Example 14 with FileChooserAdapter

use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project talos by rockbite.

the class UIStage method exportAsAction.

public void exportAsAction() {
    IProject projectType = TalosMain.Instance().ProjectController().getProject();
    String defaultLocation = TalosMain.Instance().ProjectController().getLastDir("Export", projectType);
    fileChooser.setDirectory(defaultLocation);
    final String ext = projectType.getExportExtension();
    fileChooser.setMode(FileChooser.Mode.SAVE);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() || pathname.getAbsolutePath().endsWith(ext);
        }
    });
    fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
    fileChooser.setListener(new FileChooserAdapter() {

        @Override
        public void selected(Array<FileHandle> file) {
            String path = file.first().file().getAbsolutePath();
            if (!path.endsWith(ext)) {
                if (path.indexOf(".") > 0) {
                    path = path.substring(0, path.indexOf("."));
                }
                path += ext;
            }
            FileHandle handle = Gdx.files.absolute(path);
            TalosMain.Instance().ProjectController().exportProject(handle);
        }
    });
    fileChooser.setDefaultFileName(TalosMain.Instance().ProjectController().getCurrentExportNameSuggestion());
    stage.addActor(fileChooser.fadeIn());
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter) FileFilter(java.io.FileFilter) File(java.io.File) IProject(com.talosvfx.talos.editor.project.IProject)

Example 15 with FileChooserAdapter

use of com.kotcrab.vis.ui.widget.file.FileChooserAdapter in project gdx-graph by MarcinSc.

the class LibgdxGraphScreen method save.

private void save() {
    if (graphDesignTab != null) {
        if (editedFile == null) {
            FileChooser fileChooser = new FileChooser(FileChooser.Mode.SAVE);
            fileChooser.setModal(true);
            fileChooser.setSelectionMode(FileChooser.SelectionMode.FILES);
            fileChooser.setListener(new FileChooserAdapter() {

                @Override
                public void selected(Array<FileHandle> file) {
                    FileHandle selectedFile = file.get(0);
                    if (!selectedFile.name().toLowerCase().endsWith(".json")) {
                        selectedFile = selectedFile.parent().child(selectedFile.name() + ".json");
                    }
                    editedFile = selectedFile;
                    saveToFile(graphDesignTab, selectedFile);
                }
            });
            getStage().addActor(fileChooser.fadeIn());
        } else {
            saveToFile(graphDesignTab, editedFile);
        }
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) FileChooser(com.kotcrab.vis.ui.widget.file.FileChooser) FileChooserAdapter(com.kotcrab.vis.ui.widget.file.FileChooserAdapter)

Aggregations

FileChooserAdapter (com.kotcrab.vis.ui.widget.file.FileChooserAdapter)18 FileHandle (com.badlogic.gdx.files.FileHandle)16 FileChooser (com.kotcrab.vis.ui.widget.file.FileChooser)9 Array (com.badlogic.gdx.utils.Array)5 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)4 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)4 File (java.io.File)3 FileFilter (java.io.FileFilter)3 IProject (com.talosvfx.talos.editor.project.IProject)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 JsonReader (com.badlogic.gdx.utils.JsonReader)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 Menu (com.kotcrab.vis.ui.widget.Menu)1 MenuItem (com.kotcrab.vis.ui.widget.MenuItem)1 FileTypeFilter (com.kotcrab.vis.ui.widget.file.FileTypeFilter)1 ShaderNodeStage (com.talosvfx.talos.editor.addons.shader.workspace.ShaderNodeStage)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1