Search in sources :

Example 1 with LocalFileScriptTab

use of com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab in project BowlerStudio by CommonWealthRobotics.

the class BowlerStudioController method createFileTab.

// Custom function for creation of New Tabs.
public ScriptingFileWidget createFileTab(File file) {
    if (openFiles.get(file.getAbsolutePath()) != null && widgets.get(file.getAbsolutePath()) != null) {
        BowlerStudioModularFrame.getBowlerStudioModularFrame().setSelectedTab(openFiles.get(file.getAbsolutePath()));
        return widgets.get(file.getAbsolutePath()).getScripting();
    }
    Tab fileTab = new Tab(file.getName());
    openFiles.put(file.getAbsolutePath(), fileTab);
    try {
        System.err.println("Loading local file from: " + file.getAbsolutePath());
        LocalFileScriptTab t = new LocalFileScriptTab(file);
        new Thread() {

            public void run() {
                String gitRepo = t.getScripting().getGitRepo();
                if (gitRepo != null) {
                    String message = BowlerStudioMenu.gitURLtoMessage(gitRepo);
                    if (gitRepo.length() < 5 || (message == null))
                        message = "Project " + gitRepo;
                    BowlerStudioMenuWorkspace.add(gitRepo, message);
                }
            }
        }.start();
        String key = t.getScripting().getGitRepo() + ":" + t.getScripting().getGitFile();
        ArrayList<String> files = new ArrayList<>();
        files.add(t.getScripting().getGitRepo());
        files.add(t.getScripting().getGitFile());
        try {
            if (// catch degenerates
            key.length() > 3 && files.get(0).length() > 0 && files.get(1).length() > 0)
                ConfigurationDatabase.setObject("studio-open-git", key, files);
        } catch (java.lang.NullPointerException ex) {
        // file can not be opened
        }
        fileTab.setContent(t);
        fileTab.setGraphic(AssetFactory.loadIcon("Script-Tab-" + ScriptingEngine.getShellType(file.getName()) + ".png"));
        addTab(fileTab, true);
        widgets.put(file.getAbsolutePath(), t);
        fileTab.setOnCloseRequest(event -> {
            widgets.remove(file.getAbsolutePath());
            openFiles.remove(file.getAbsolutePath());
            ConfigurationDatabase.removeObject("studio-open-git", key);
            t.getScripting().close();
            System.out.println("Closing " + file.getAbsolutePath());
        });
        FileChangeWatcher watcher = FileChangeWatcher.watch(file);
        watcher.addIFileChangeListener(new IFileChangeListener() {

            @Override
            public void onFileDelete(File fileThatIsDeleted) {
                BowlerStudioModularFrame.getBowlerStudioModularFrame().closeTab(fileTab);
            }

            @Override
            public void onFileChange(File fileThatChanged, WatchEvent event) {
            }
        });
        t.setFontSize(size);
        return t.getScripting();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) FileChangeWatcher(com.neuronrobotics.bowlerstudio.util.FileChangeWatcher) IOException(java.io.IOException) LocalFileScriptTab(com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab) LocalFileScriptTab(com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab) Tab(javafx.scene.control.Tab) IFileChangeListener(com.neuronrobotics.bowlerstudio.util.IFileChangeListener) WatchEvent(java.nio.file.WatchEvent) File(java.io.File)

Example 2 with LocalFileScriptTab

use of com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab in project BowlerStudio by CommonWealthRobotics.

the class BowlerStudioMenu method addSizesToMenu.

public void addSizesToMenu(String size, String type) {
    MenuItem sizeMenu = new MenuItem(size);
    Platform.runLater(() -> {
        getTypeMenu(type).getItems().add(sizeMenu);
    });
    sizeMenu.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            new Thread() {

                public void run() {
                    LocalFileScriptTab tab = LocalFileScriptTab.getSelectedTab();
                    if (tab != null)
                        tab.insertString("CSG vitamin_" + slugify(type) + "_" + slugify(size) + " = Vitamins.get(\"" + type + "\", \"" + size + "\")\n");
                }
            }.start();
        }
    });
}
Also used : LocalFileScriptTab(com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab) ActionEvent(javafx.event.ActionEvent)

Aggregations

LocalFileScriptTab (com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab)2 FileChangeWatcher (com.neuronrobotics.bowlerstudio.util.FileChangeWatcher)1 IFileChangeListener (com.neuronrobotics.bowlerstudio.util.IFileChangeListener)1 File (java.io.File)1 IOException (java.io.IOException)1 WatchEvent (java.nio.file.WatchEvent)1 ArrayList (java.util.ArrayList)1 ActionEvent (javafx.event.ActionEvent)1 Tab (javafx.scene.control.Tab)1