<commit_before>/*
 * Copyright (c) 1998-2019 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.menu;

import com.trollworks.gcs.app.GCSCmdLine;
import com.trollworks.toolkit.ui.menu.Command;
import com.trollworks.toolkit.ui.widget.WindowUtils;
import com.trollworks.toolkit.utility.I18n;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Arrays;

/** Shows the user the Library folder. */
public class ShowLibraryFolderCommand extends Command {
    /** Creates a new {@link ShowLibraryFolderCommand}. */
    public ShowLibraryFolderCommand() {
        super(I18n.Text("Show GCS Library on Disk"), "show_gcs_library");
    }

    @Override
    public void adjust() {
        // Not used. Always enabled.
    }

    @Override
    public void actionPerformed(ActionEvent event) {
        try {
            File   dir      = GCSCmdLine.getLibraryRootPath().toFile();
            File[] contents = dir.listFiles();
            if (contents.length > 0) {
                Arrays.sort(contents);
                dir = contents[0];
            }

            Desktop.getDesktop().browseFileDirectory(dir.getCanonicalFile());
        } catch (Exception exception) {
            WindowUtils.showError(null, exception.getMessage());
        }
    }
}<commit_msg>Fallback to OPEN if BROWSE_FILE_DIR isn't supported<commit_after>/*
 * Copyright (c) 1998-2019 by <NAME>. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

package com.trollworks.gcs.menu;

import com.trollworks.gcs.app.GCSCmdLine;
import com.trollworks.toolkit.ui.menu.Command;
import com.trollworks.toolkit.ui.widget.WindowUtils;
import com.trollworks.toolkit.utility.I18n;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Arrays;

/** Shows the user the Library folder. */
public class ShowLibraryFolderCommand extends Command {
    /** Creates a new {@link ShowLibraryFolderCommand}. */
    public ShowLibraryFolderCommand() {
        super(I18n.Text("Show GCS Library on Disk"), "show_gcs_library");
    }

    @Override
    public void adjust() {
        // Not used. Always enabled.
    }

    @Override
    public void actionPerformed(ActionEvent event) {
        try {
            File    dir     = GCSCmdLine.getLibraryRootPath().toFile();
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Action.BROWSE_FILE_DIR)) {
                File[] contents = dir.listFiles();
                if (contents.length > 0) {
                    Arrays.sort(contents);
                    dir = contents[0];
                }
                desktop.browseFileDirectory(dir.getCanonicalFile());
            } else {
                desktop.open(dir);
            }
        } catch (Exception exception) {
            WindowUtils.showError(null, exception.getMessage());
        }
    }
}
{'fraction_non_alphanumeric': 0.10619221070327822, 'fraction_numerical': 0.011207621182404036, 'mean_word_length': 2.61336032388664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6611535', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1010, 'n_words': 285}