[MonoDevelop] Some changes to ambiences

Michael Hutchinson m.j.hutchinson at gmail.com
Thu Nov 27 13:42:07 EST 2008


On Thu, Nov 27, 2008 at 1:26 AM, Mike Krüger <mkrueger at novell.com> wrote:
> Hi
>
> I've extended the ambiences a bit. They're now more flexible, can fly,
> cook coffe etc.
>
> It's now possible to specify an OutputSettings object that can do
> further formatting. This class also is responsible for generating
> markup. The default one generates pango markup, but it would be easy to
> print any other markup using OutputSettings.
> (The ambiences have done that itself in the past)
>
> Therefore I changed the GetString to:
>
> public abstract string GetString (IDomVisitable domVisitable,
> object settings);
>
> Why setting is an object ? Because on the caller side nothing changes.

Why not strongly typed overloads? These would work just as well, and
are more usable -- plus you have compile-time type safety.

> It's still valid to call:
>
> ----------------------------------------------------------------------
> ambience.GetString (someMethod, OutputFlags.ClassBrowserEntries);
> ----------------------------------------------------------------------
>
> This was my biggest concern: Keeping the ambiences easy to use and not
> breaking any consuming code.
>
> For output settings you can do something like:
>
> -------------------------------------------------
> OutputSettings settings = new OutputSettings
> (OutputFlags.ClassBrowserEntries);
>
> // change something in the settings
>
> ambience.GetString (someMethod, settings);
> -------------------------------------------------
>
> The OutputSettings object contains some delegates that handle the
> strings that are emitted by the underlying ambience. It has:
>
> --------------------------------------------------
>  public delegate string MarkupText (string text);

You could use Func<string,string>  for this.

>  public MarkupText EmitModifiers;
>  public MarkupText EmitKeyword;
>
>  public MarkupText Highlight;
>  public MarkupText Markup;
>
> --------------------------------------------------
>
> EmitModifiers/Keywords is separated because it's possible to turn them
> off seperately in the output flags. Highlight is used to highlight
> names. Markup is used on any other text (like ":" or "<").
>
> For changing the output string for special dom objects the PostProcess
> can be used:
> --------------------------------------------------
> public ProcessString PostProcess;
> public delegate void ProcessString (IDomVisitable domVisitable, ref
> string outString);
> --------------------------------------------------

Why void/ref? Why not just return a string?

>
> This is useful for creating links for returntypes.
>
> Example:
> --------------------------------------------------
> settings.PostProcess =
> delegate (IDomVisitable domVisitable,
>          ref string outString) {
>  if (domVisitable is IReturnType)
>   outString = "<span foreground=\"blue\"><u>" +
>               outString +
>               "</u></span>";
> };
> --------------------------------------------------
> This example underlines return types and prints them blue.
>
> Regards
> Mike



-- 
Michael Hutchinson
http://mjhutchinson.com


More information about the Monodevelop-list mailing list