Пример #1
0
//==============================================================================
bool CodeFileList::isValid (const juce::String& filepath)
{
    if (filepath.isNotEmpty())
        return juce::File (filepath).hasFileExtension (wildcards);

    return false;
}
void InterfaceComponent::buttonClicked (juce::Button* button)
{
    if (button == &btnBrowse)
    {
        juce::FileChooser chooser ("Select the folder which contains the code files you want to modularise");
        
        if (chooser.browseForDirectory())
        {
            const juce::File folder (chooser.getResult());

            txtSourceFileFolder.setText (folder.getFullPathName().trim(), juce::sendNotification);
            txtDestinationFolder.setText (folder.getParentDirectory().getFullPathName().trim(), juce::sendNotification);

            files = Modulariser (folder, true).getFiles();

            fileListBox.setSelectedRows (juce::SparseSet<int>());
            fileListBox.updateContent();
        }
    }
    else if (button == &btnRefresh)
    {
        refresh();
    }
    else if (button == &btnGenerate)
    {
        const juce::String srcFolder (txtSourceFileFolder.getText().trim());
        const juce::String destFolder (txtDestinationFolder.getText().trim());

        if (srcFolder.isNotEmpty()
            && destFolder.isNotEmpty()
            && juce::File::isAbsolutePath (srcFolder)
            && juce::File::isAbsolutePath (destFolder))
        {
            Modulariser modulariser (files);

            modulariser.saveTo (juce::File (destFolder),
                                srcFolder,
                                txtModuleFilename.getText().trim(),
                                txtHeaderGuard.getText().trim(),
                                txtNamespace.getText().trim());
        }
    }
}
void InterfaceComponent::refresh()
{
    const juce::String folderPath (txtSourceFileFolder.getText().trim());

    if (folderPath.isNotEmpty()
        && juce::File::isAbsolutePath (folderPath))
    {
        const juce::File folder (folderPath);

        if (folder.isDirectory())
        {
            txtDestinationFolder.setText (folder.getParentDirectory().getFullPathName().trim(), juce::sendNotification);

            const juce::StringArray fileList = Modulariser (folder, true).getFiles();

            if (fileList != files)
            {
                files = fileList;
                fileListBox.setSelectedRows (juce::SparseSet<int>());
                fileListBox.updateContent();
            }
        }
    }
}
//==============================================================================
void TrailingWhitespaceCleaner::cleanFile (const juce::File& file,
                                           const bool removeDocumentStartWhitespace,
                                           const WhitespaceRemovalOptions documentEndOptions)
{
    if (! file.hasWriteAccess())
        return;

    juce::StringArray lines;
    file.readLines (lines);

    if (lines.size() <= 0)
        return;

    while (lines.strings.getLast().trim().isEmpty())
        lines.remove (lines.size() - 1);

    lines.minimiseStorageOverheads();

    cleanRange (lines, 0, lines.size());

    if (removeDocumentStartWhitespace)
    {
        for (int i = 0; i < lines.size(); ++i)
        {
            if (lines[i].isEmpty())
            {
                lines.remove (i);
                --i;
            }
            else
            {
                break;
            }
        }
    }

    //Remove empty lines at the end of the file:
    for (int i = lines.size(); --i >= 0;)
    {
        if (lines[i].isEmpty())
            lines.remove (i);
        else
            break;
    }
#if 0
    if (documentEndOptions == KeepOneBlankLine)
    {
        const juce::String last (lines.strings[lines.size() - 1].trim());

        if (lines.size() == 0)
        {
            lines.add (juce::newLine);
        }
        else
        {
            if (last.isNotEmpty())
            {
                if (last == "\r" || last == "\n" || last == "\n\r" || last == "\r\n")
                    lines.strings.getReference (lines.size() - 1) = juce::newLine;
                else
                    lines.add (juce::newLine);
            }
            else
            {
                lines.strings.getReference (lines.size() - 1) = juce::newLine;
            }
        }
    }
#endif
    juce::ScopedPointer<juce::FileOutputStream> stream (file.createOutputStream());

    if (stream != nullptr)
        writeLinesToStream (stream, lines);
}