<commit_before>package main.java.elegit;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.text.Text;
import main.java.elegit.exceptions.NoOwnerInfoException;
import main.java.elegit.exceptions.NoRepoSelectedException;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.util.Pair;
import org.eclipse.jgit.api.errors.GitAPIException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

/**
 *
 * An implementation of the abstract RepoHelperBuilder that builds
 * a ClonedRepoHelper by presenting dialogs to get the necessary
 * parameters.
 *
 */
public class ClonedRepoHelperBuilder extends RepoHelperBuilder {

    private static String prevRemoteURL, prevDestinationPath;

    public ClonedRepoHelperBuilder(SessionModel sessionModel) {
        super(sessionModel);
    }

    /**
     * Shows dialogs that prompt the user for information needed to
     * construct a ClonedRepoHelper.
     *
     * @return the new ClonedRepoHelper.
     * @throws Exception when constructing the new ClonedRepoHelper
     */
    @Override
    public RepoHelper getRepoHelperFromDialogs() throws GitAPIException, NoOwnerInfoException, IOException, NoRepoSelectedException{
        // Inspired by: http://code.makery.ch/blog/javafx-dialogs-official/

        // Create the custom dialog.
        Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle("Clone a Repository");
        dialog.setHeaderText("Enter a remote repository to clone into the destination path.");

        // Set the button types.
        ButtonType cloneButtonType = new ButtonType("Clone", ButtonBar.ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(cloneButtonType, ButtonType.CANCEL);

        // Create the Remote URL and destination path labels and fields.
        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(20, 150, 10, 10));

        TextField remoteURLField = new TextField();
        remoteURLField.setPromptText("Remote URL");
        if(prevRemoteURL != null) remoteURLField.setText(prevRemoteURL);

        TextField destinationPathField = new TextField();
        destinationPathField.setEditable(false); // for now, it will just show the folder you selected
        if(prevDestinationPath != null) destinationPathField.setText(prevDestinationPath);

        Button chooseDirectoryButton = new Button();
        Text folderIcon = GlyphsDude.createIcon(FontAwesomeIcon.FOLDER_OPEN);
        chooseDirectoryButton.setGraphic(folderIcon);
        chooseDirectoryButton.setOnAction(t -> {
            File cloneRepoDirectory = this.getDirectoryPathFromChooser("Choose clone destination folder", null);
            destinationPathField.setText(cloneRepoDirectory.toString());
        });

        grid.add(new Label("Remote URL:"), 0, 0);
        grid.add(remoteURLField, 1, 0);
        grid.add(new Label("Destination Path:"), 0, 1);
        grid.add(destinationPathField, 1, 1);
        grid.add(chooseDirectoryButton, 2, 1);

        dialog.getDialogPane().setContent(grid);

        // Request focus on the remote URL field by default.
        Platform.runLater(remoteURLField::requestFocus);

        // Convert the result to a destination-remote pair when the clone button is clicked.
        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == cloneButtonType) {
                prevRemoteURL = remoteURLField.getText();
                prevDestinationPath = destinationPathField.getText();
                return new Pair<>(destinationPathField.getText(), remoteURLField.getText());
            }
            return null;
        });

        Optional<Pair<String, String>> result = dialog.showAndWait();

        if (result.isPresent()) {
            Path destinationPath = Paths.get(result.get().getKey());
            RepoHelper repoHelper = new ClonedRepoHelper(destinationPath, result.get().getValue(), this.sessionModel.getDefaultOwner());

            return repoHelper;
        } else {
            // This happens when the user pressed cancel.
            throw new NoRepoSelectedException();
        }
    }
}<commit_msg>Made the clonedRepoHelperBuilder dialog more explicit. It now ensures that the destination is empty by creating a new folder<commit_after>package main.java.elegit;

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.geometry.Pos;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import main.java.elegit.exceptions.NoOwnerInfoException;
import main.java.elegit.exceptions.NoRepoSelectedException;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.util.Pair;
import org.eclipse.jgit.api.errors.GitAPIException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;

/**
 *
 * An implementation of the abstract RepoHelperBuilder that builds
 * a ClonedRepoHelper by presenting dialogs to get the necessary
 * parameters.
 *
 */
public class ClonedRepoHelperBuilder extends RepoHelperBuilder {

    private static String prevRemoteURL, prevDestinationPath;

    public ClonedRepoHelperBuilder(SessionModel sessionModel) {
        super(sessionModel);
    }

    /**
     * Builds (with a grid) and shows dialogs that prompt the user for
     * information needed to construct a ClonedRepoHelper.
     *
     * @return the new ClonedRepoHelper.
     * @throws Exception when constructing the new ClonedRepoHelper
     */
    @Override
    public RepoHelper getRepoHelperFromDialogs() throws GitAPIException, NoOwnerInfoException, IOException, NoRepoSelectedException{
        // Inspired by: http://code.makery.ch/blog/javafx-dialogs-official/

        // Create the custom dialog.
        Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle("Clone");
        dialog.setHeaderText("Clone a remote repository");

        Text instructionsText = new Text("Select an enclosing folder for the repository folder\n" +
                                         "to be created in.");

        // Set the button types.
        ButtonType cloneButtonType = new ButtonType("Clone", ButtonBar.ButtonData.OK_DONE);
        dialog.getDialogPane().getButtonTypes().addAll(cloneButtonType, ButtonType.CANCEL);

        // Create the Remote URL and destination path labels and fields.
        GridPane grid = new GridPane();
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(10, 10, 10, 10));

        TextField remoteURLField = new TextField();
        remoteURLField.setPromptText("Remote URL");
        if(prevRemoteURL != null) remoteURLField.setText(prevRemoteURL);

        TextField enclosingFolderField = new TextField();
        enclosingFolderField.setEditable(false); // for now, it will just show the folder you selected
        if(prevDestinationPath != null) enclosingFolderField.setText(prevDestinationPath);

        Text enclosingDirectoryPathText = new Text();

        Button chooseDirectoryButton = new Button();
        Text folderIcon = GlyphsDude.createIcon(FontAwesomeIcon.FOLDER_OPEN);
        chooseDirectoryButton.setGraphic(folderIcon);
        chooseDirectoryButton.setOnAction(t -> {
            File cloneRepoDirectory = this.getDirectoryPathFromChooser("Choose clone destination folder", null);
            enclosingFolderField.setText(cloneRepoDirectory.toString());
            enclosingDirectoryPathText.setText(cloneRepoDirectory.toString() + File.separator);
        });

        TextField repoNameField = new TextField();
        repoNameField.setPromptText("Repository name...");

        grid.add(instructionsText, 0, 0, 2, 1);

        grid.add(new Label("Remote URL:"), 0, 1);
        grid.add(remoteURLField, 1, 1);
        grid.add(new Label("Enclosing folder:"), 0, 2);
        grid.add(enclosingFolderField, 1, 2);
        grid.add(chooseDirectoryButton, 2, 2);

        grid.add(new Label("Repository name:"), 0, 3);
        grid.add(repoNameField, 1, 3);

        dialog.getDialogPane().setContent(grid);

        // Request focus on the remote URL field by default.
        Platform.runLater(remoteURLField::requestFocus);

        // Convert the result to a destination-remote pair when the clone button is clicked.
        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == cloneButtonType) {
                // Store these values for callback after a login (if user isn't logged in):
                prevRemoteURL = remoteURLField.getText();
                prevDestinationPath = enclosingFolderField.getText();

                return new Pair<>(enclosingFolderField.getText() + File.separator + repoNameField.getText(), remoteURLField.getText());
            }
            return null;
        });

        Optional<Pair<String, String>> result = dialog.showAndWait();

        if (result.isPresent()) {
            Path destinationPath = Paths.get(result.get().getKey());
            RepoHelper repoHelper = new ClonedRepoHelper(destinationPath, result.get().getValue(), this.sessionModel.getDefaultOwner());

            return repoHelper;
        } else {
            // This happens when the user pressed cancel.
            throw new NoRepoSelectedException();
        }
    }
}
{'fraction_non_alphanumeric': 0.09733595936560589, 'fraction_numerical': 0.005493935938633772, 'mean_word_length': 3.1425504508372692, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2552955', 'n_tokens_mistral': 2624, 'n_tokens_neox': 2533, 'n_words': 644}