rubberduck-vba / RubberduckWeb

Project Website for the Rubberduck VBA Editor Add-In
19 stars 12 forks source link

Smart Indenter live demo #21

Closed retailcoder closed 7 years ago

retailcoder commented 7 years ago

Similar to the inspections page, the indenter page needs a place to paste some code and click a button to apply indenter settings.

image

The indented code should update accordingly with the specified settings, as the user tweaks them - just like in the Rubberduck indenter settings page.

retailcoder commented 7 years ago

The settings form would actually replace the screenshot.

EBrown8534 commented 7 years ago

Do we want to make the settings look as close (layout wise) to the screenshot as possible?

Do we want a serializable version of the settings that can be passed to the actual RD configuration system? (Assuming this is possible.)

retailcoder commented 7 years ago

The RD settings page ViewModel creates an indenter instance every time it refreshes the preview box:

https://github.com/rubberduck-vba/Rubberduck/blob/next/RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs#L267-L277

    public string PreviewSampleCode 
    {
        get
        {
            var indenter = new Indenter(null, GetCurrentSettings);

            var lines = RubberduckUI.IndenterSettings_PreviewCode.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            lines = indenter.Indent(lines, "TestModule").ToArray();
            return string.Join(Environment.NewLine, lines);
        }
    }

The GetCurrentSettings method returns an IIndenterSettings instance built off the current selected values:

    private IIndenterSettings GetCurrentSettings()
    {
        return new SmartIndenter.IndenterSettings
        {
            AlignCommentsWithCode = AlignCommentsWithCode,
            AlignContinuations = AlignContinuations,
            AlignDimColumn = AlignDimColumn,
            AlignDims = AlignDims,
            EndOfLineCommentColumnSpaceAlignment = EndOfLineCommentColumnSpaceAlignment,
            EndOfLineCommentStyle = EndOfLineCommentStyle,
            ForceCompilerDirectivesInColumn1 = ForceCompilerDirectivesInColumn1,
            ForceDebugStatementsInColumn1 = ForceDebugStatementsInColumn1,
            IgnoreOperatorsInContinuations = IgnoreOperatorsInContinuations,
            IndentCase = IndentCase,
            IndentCompilerDirectives = IndentCompilerDirectives,
            IndentEnumTypeAsProcedure = IndentEnumTypeAsProcedure,
            IndentEntireProcedureBody = IndentEntireProcedureBody,
            IndentFirstCommentBlock = IndentFirstCommentBlock,
            IndentFirstDeclarationBlock = IndentFirstDeclarationBlock,
            IndentSpaces = IndentSpaces
        };
    }

Simple as that!

TL;DR: you need to create a new SmartIndenter.IndenterSettings anyway for it to work.

EBrown8534 commented 7 years ago

Beautiful.

Do we already have an import/export feature on settings? If not, I'll add an issue on the other project for it. That would definitely be a nice feature.

retailcoder commented 7 years ago

Ah, I see what you mean. Unfortunately that's not implemented (yet) in RD. I mean, the settings are serialized to XML, but there's much more to it than just the indenter settings.

We're talking about a feature that lets you export the indenter settings from the website and import them to your desktop rubberduck, right?

That's definitely a nice thing to add to the RD indenter settings!

EBrown8534 commented 7 years ago

Yes. It would be trivial to serialize and send them from web -> computer file, but if there's nothing to get them to go from file -> RD, then there's no point (yet) in creating that feature on the web side. We can still create the Indenter feature, just not the "Export Settings" feature.

retailcoder commented 7 years ago

Hold that thought, then. I think it's a good idea, but it would make more sense to implement it once we ship a RD build that includes that "import indenter settings from file" button.

comintern commented 7 years ago

@retailcoder - Open an RD issue for it so I don't forget - the groundwork is there in XmlPersistanceService<T>, it just needs something to pass it a FilePath parameter.

EBrown8534 commented 7 years ago

Absolutely. I'll create the Smart Indenter on the website, but we'll hold off on the export feature until RD is ready to accept imports, then I'll look into the serialization of settings. Until then I'll make the web form layout as close to the form layout as possible, so settings are easy to copy/paste.