Differences between revisions 5 and 14 (spanning 9 versions)
Revision 5 as of 2015-03-12 15:26:36
Size: 4448
Comment:
Revision 14 as of 2016-02-28 13:16:57
Size: 10387
Comment: Version 1.1
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
UNDER CONSTRUCTION == Overview ==
`XamlEditor` is a Xaml editor for an APL variable or for a file on disk.
Line 5: Line 6:
== Overview ==
`XamlEditor` is a Xaml editor for an
APL variable or for a file on disk. This user command is able to show the Xaml in color with folding, print it, reorganize it so it is more readable according to some settings set by the user. It is inspired by the work of Robby Ingebretsen of '''Kaxaml''' ([[http://www.Kaxaml.com||target='_blank']]). It is particularly valuable for APLers that like to keep their Xaml in the workspace. With `XamlEditor` they have a tool to maintain it without effort.
This Dyalog APL user command is able to show the Xaml in color with folding, to print it and to reorganize it so it is more readable according to some settings set by the user. It is inspired by the work of Robby Ingebretsen of '''Kaxaml''' ([[http://www.Kaxaml.com|| ]]). It is particularly valuable for APLers that like to keep their Xaml in the workspace. With `XamlEditor` they have a tool to maintain it without effort.
Line 9: Line 9:
Once installed the user command can be invoke by typing `]XamlEditor` (casing is not important, no argument). The following start-up screen will appear:<<BR>><<BR>> Once installed the user command can be invoked by typing `]XamlEditor` (casing is not important, no argument). The following start-up screen will appear:
Line 11: Line 12:
<<BR>>Here is a short description for each buttons:
Here is a short description of each button:
Line 13: Line 16:
||{{attachment:Exec32.png || width=24}}|| Execute the Xaml and Show the Result in a Separate Window ||{{attachment:SelectAll24.png || width=24}} || Select All the Xaml ||
||{{attachment:Scrubber24.png || width=24}} || Scrub the Xaml According to Settings ||{{attachment:Delete24.png || width=24}} || Delete the Selected Text ||
||{{attachment:OpenObject24.png || width=24}} || Open a Dialog Box to Select a Xaml Variable in the WS ||{{attachment:ClearClipboard24.png || width=24}} || Clear the Clipboard ||
||{{attachment:SaveObject24.png || width=24}} || Open a Dialog Box to Save the Xaml as a Variable in the WS ||{{attachment:Undo24.png || width=24}} || Undo Last Operation ||
||{{attachment:Open24.png || width=24}} || Open a Dialog Box to Select a File on Disk ||{{attachment:Redo24.png || width=24}} || Redo Previous Operation ||
||{{attachment:Save24.png || width=24}} || Open a Dialog Box to Save the Xaml to a File ||{{attachment:Print32.png || width=24}} || Print All the Xaml ||
||{{attachment:Cut24.png || width=24}} || Cut the Selected Text to The Clipboard ||{{attachment:PrintPreview32.png || width=24}} || Print Preview All the Xaml ||
||{{attachment:Copy24.png || width=24}} || Copy the Selected Text to the Clipboard ||{{attachment:Comments24.png || width=24}} || Make Selected Text a Comment ||
||{{attachment:Paste24.png || width=24}} || Paste the Text From the clipboard ||{{attachment:Settings24.png || width=24}} || Choose the Settings when Scrubbing ||
||{{attachment:Exec32.png || width=24}}|| Execute the Xaml and show the result in a separate window ||{{attachment:SelectAll24.png || width=24}} || Select all the Xaml ||
||{{attachment:Scrubber24.png || width=24}} || Rewrite the Xaml according to the settings (Scrub) ||{{attachment:Delete24.png || width=24}} || Delete the selected text ||
||{{attachment:OpenObject24.png || width=24}} || Open a dialog box to select a Xaml variable in the WS ||{{attachment:ClearClipboard24.png || width=24}} || Clear the clipboard ||
||{{attachment:SaveObject24.png || width=24}} || Open a dialog box to save the Xaml as a variable in the WS ||{{attachment:Undo24.png || width=24}} || Undo last operation ||
||{{attachment:Open24.png || width=24}} || Open a dialog box to select a file on disk ||{{attachment:Redo24.png || width=24}} || Redo previous operation ||
||{{attachment:Save24.png || width=24}} || Open a dialog box to save the Xaml to a file ||{{attachment:Print32.png || width=24}} || Print all the Xaml ||
||{{attachment:Cut24.png || width=24}} || Cut the Selected Text to The Clipboard ||{{attachment:PrintPreview32.png || width=24}} || Print preview all the Xaml ||
||{{attachment:Copy24.png || width=24}} || Copy the selected text to the clipboard ||{{attachment:Comments24.png || width=24}} || Make selected text a comment ||
||{{attachment:Paste24.png || width=24}} || Paste the text from the clipboard ||{{attachment:Settings24.png || width=24}} || Choose the settings when scrubbing ||
Line 25: Line 28:
 1. Download the file [[attachment:wpfXamlEditor.1.0.zip]]. It contains the Dyalog user command file `wpfXamlEditor.dyalog` and a dll named `ICSharpCode.AvalonEdit.dll`
 1. Copy the file `wpfXamlEditor.dyalog` to your user command directory (for advice how to organize your User Commands see [[UserCommands/WhereShouldTheyGo||target='_blank']]).
 1. Copy the file `ICSharpCode.AvalonEdit.dll` to the same directory as your `dyalog.exe` file (as shown by doing `+2 ⎕NQ'.' 'GetEnvironment' 'Dyalog'`)(you may need administrator privileges for doing that). That dll is free of charge and was written by Daniel Grunwald. It can be downloaded from [[http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor|CodeProject|target='_blank']] or from [[http://avalonedit.net/|AvalonEdit|target='_blank']] but is included in the zip file for commodity.

1. Download the file [[attachment:wpfXamlEditor.1.1.zip]]. It contains the Dyalog user command file `wpfXamlEditor.dyalog` and a dll named `ICSharpCode.AvalonEdit.dll`
 1. Copy the file `wpfXamlEditor.dyalog` to your user command directory (for advice how to organize your User Commands see [[UserCommands/WhereShouldTheyGo||]]).
 1. Copy the file `ICSharpCode.AvalonEdit.dll` to the same directory as your `dyalog.exe` file (as shown by `+2 ⎕NQ'.' 'GetEnvironment' 'Dyalog'`). You may need administrator privileges for copying the file. That dll is free of charge and was written by Daniel Grunwald. It can be downloaded from [[http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor|CodeProject|]] or from [[http://avalonedit.net/|AvalonEdit|]] but is included in the zip file for commodity.
Line 30: Line 34:
||{{attachment:Exec32.png || width=24}}|| Execute the Xaml and Show the Result in a Separate Window ||
The Xaml will be parsed and shown in a separate window. If the root element of the Xaml is not a window it will be made the content of a new window. The x:Class attribute will be removed if present. All the events will be removed before parsing the Xaml by the function `ScrubAndFix`. It does not rely on a prefix to removed the events.
<<SeeSaw(section="ScrubAndFix", toshow="(<<Show ScrubAndFix>>)", tohide="(<<Hide ScrubAndFix>>)", bg="#FEE1A5", speed="Slow")>>
{{{{#!wiki seesaw/ScrubAndFix/ScrubAndFix/hide
{{{
   ∇ rootObj←ScrubAndFix xamlString;err;reader;stringReader;writer;⎕USING
     ⍝ Function to remove the Class and Events elements of Xaml and fix the resulting Xaml.
     ⍝ This function is most usefull when experimenting with Xaml taken directly from the Web but is slower than FixXaml.
     ⍝ Inspired from the code of XAMLPAD2009.
     ⍝
     ⍝ XamlString = Vector of Characters representing a XAML string
     ⍝ rootObj = WPF Root Element Object if no error
     ⍝ = ⎕NULL (explanation of error) if error

      :Trap 0

          ⎕USING←'System.IO' 'System.Windows.Markup,WPF/PresentationFramework.dll' 'System.Xaml,System.Xaml.dll'
          stringReader←⎕NEW StringReader(⊂xamlString)
          reader←⎕NEW XamlXmlReader(stringReader XamlReader.GetWpfSchemaContext)
          writer←⎕NEW XamlObjectWriter(reader.SchemaContext)

          ⎕USING←0⍴⊂'' ⍝ Don't need it anymore

          :While reader.Read

              :If 'StartMember'≡⍕reader.NodeType
              :AndIf reader.Member.Name≡'Class'
                ⍝ Skip the x:Class attribute
                  {}reader.Read
                  {}reader.Read

              :ElseIf 'StartMember'≡⍕reader.NodeType
              :AndIf reader.Member.IsEvent
                ⍝ Skip the Event member
                  {}reader.Read
                  {}reader.Read

              :Else
                ⍝ Keep the other nodes
                  writer.WriteNode(reader)

              :End

          :EndWhile

        ⍝ The following line will return the root object
          rootObj←writer.Result

      :Else
         ⍝ Build the Error Message
          :If 90≠⎕EN
            ⍝ APL Error
              err←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13)

          :Else
            ⍝ .Net Error
              :Trap 0
                ⍝ Show the value of ⎕EXCEPTION.Message if not ⎕NULL.
                  err←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13)
              :Else
                ⍝ Sometimes ⎕EXCEPTION is (NULL) and will bug here.
                  err←'Exception (NULL): Unknown error',(⎕UCS 13)

              :EndTrap

          :End

          rootObj←⎕NULL err

      :EndTrap
    ∇
}}}
}}}}

||{{attachment:Scrubber24.png || width=24}} || Rewrite the Xaml according to the settings (Scrub) ||
Will rewrite the Xaml according to the settings. The most important setting is '''Attribute Tolerance'''; it allows you to define how many attributes there could be on one line of Xaml. Past that number all the attributes are written on a separate line.
Line 32: Line 112:
||{{attachment:Exec32.png || width=24}}|| Execute the Xaml and Show the Result in a Separate Window || ||{{attachment:OpenObject24.png || width=24}} || Open a dialog box to select a Xaml variable in the WS ||
||{{attachment:SaveObject24.png || width=24}} || Open a dialog box to save the Xaml as a variable in the WS ||

The dialog box contains a tree element where each branch is a namespace that has a character variable that responds positive to the following test: do the first and last character match '<>' after removing the white space (space,LF,NL,HT characters)? In APL:

{{{'><'≡¯2↑1⌽variableName~⎕UCS 32 10 13 9}}}

Note that variables of scripted namespaces will not be permanently changed by `XamlEditor`.
Line 35: Line 122:
<<BR>>The settings for scrubbing are saved in a xml file named `XED.Settings.xml`. The file will be created automatically the first time the user command runs. It will be located next to the `wpfXamlEditor.dyalog` file or in the `AppData` directory depending on the Windows version and security. The data of the file looks like this:<<BR>>
{{{
||{{attachment:Open24.png || width=24}} || Open a dialog box to select a file on disk ||
||{{attachment:Save24.png || width=24}} || Open a dialog box to save the Xaml to a file ||
A standard `OpenFileDialog` and `SaveFileDialog` are used to select and save the file.


||{{attachment:Print32.png || width=24}} || Print all the Xaml ||
||{{attachment:PrintPreview32.png || width=24}} || Print preview all the Xaml ||
Will take the Xaml to a `FlowDocument` where it can be previewed or printed directly.


||{{attachment:Comments24.png || width=24}} || Make selected text a comment ||

The following rules apply to this button when clicked:

 1. If nothing is selected it will insert `'<!-- -->'` at the caret.
 1. If the selection is positive to the test: `' --><!-- '≡9↑¯4⌽selectedText`, the comments are removed.
 1. Otherwise it will insert: `'<!-- ',selectedText,' -->'`


||{{attachment:Settings24.png || width=24}} || Choose the Settings when scrubbing ||

The settings for scrubbing are saved in an XML file named `XED.Settings.xml`. The file will be created automatically with default values the first time the user command runs.

It will be located in the `AppData` directory. The data of the file looks like this:

{{{#!highlight xml
Line 40: Line 151:
  <ReducePrecision>0</ReducePrecision>
  <Precision>10</Precision>
  <AttributeCounteTolerance>2</AttributeCounteTolerance>
  <ReducePrecision>1</ReducePrecision>
  <Precision>3</Precision>
  <AttributeCounteTolerance>3</AttributeCounteTolerance>
Line 44: Line 155:
  <RemoveCommonDefaultValues>1</RemoveCommonDefaultValues>   <RemoveCommonDefaultValues>0</RemoveCommonDefaultValues>
Line 46: Line 157:
  <SpaceCount>2</SpaceCount>   <SpaceCount>3</SpaceCount>
Line 49: Line 160:
<<BR>>It is used to build the Settings window (button {{attachment:Settings24.png || width=24}} of the command bar).<<BR>>
{{attachment:Settings.png || width=243}}<<BR>>
Look at the individual tooltips on the Window for more information on each settings.

It is used to populate the "Settings" window.

{{attachment:Settings.png || width=243}}
|| '''Item''' || '''Description''' ||
|| "Font" || Font used by Xaml Editor ||
|| "Font Size" || Size of the font used by Xaml Editor ||
|| "Numeric Precision" || Reduce the precision of large numbers to a maximum of this number of digits beyond the decimal point ||
|| "Attribute Tolerance" || If more than this number of attributes are defined on an element, Scrubber will move each attribute onto its own line ||
|| "Reorder Attributes By Importance" || Scrubber will reorder attributes on a given element according to a predetermined set of rules about which attributes<<BR>> are most important ||
|| "Remove Common Default Values" || Scrubber will remove common properties which are being set to their default values ||
|| "Indent Using Spaces" || If this is checked Scrubber will indent using spaces instead of tabs ||

== Version Information ==
{{{
Version 1.0 Mars 2015

Version 1.1 February 2016
        SaveSettings and GetSettings changed to always use the AppData directory
        Initial focus is now set to the editor instead of the window (via Xaml)
}}}
||Original author: ||Pierre Gilbert ||
||Responsible: ||PierreGilbert ||
||Email: || <<MailTo(apgil AT SPAMFREE videotron DOT ca)>> ||

----
CategoryDyalog - CategoryDyalogDotNet - CategoryDyalogWpfUtilities - CategoryDotNet

wpfXamlEditor

Overview

XamlEditor is a Xaml editor for an APL variable or for a file on disk.

This Dyalog APL user command is able to show the Xaml in color with folding, to print it and to reorganize it so it is more readable according to some settings set by the user. It is inspired by the work of Robby Ingebretsen of Kaxaml (http://www.Kaxaml.com). It is particularly valuable for APLers that like to keep their Xaml in the workspace. With XamlEditor they have a tool to maintain it without effort.

Usage

Once installed the user command can be invoked by typing ]XamlEditor (casing is not important, no argument). The following start-up screen will appear:

InitialView.png

Here is a short description of each button:

Button

Explanation

Button

Explanation

Exec32.png

Execute the Xaml and show the result in a separate window

SelectAll24.png

Select all the Xaml

Scrubber24.png

Rewrite the Xaml according to the settings (Scrub)

Delete24.png

Delete the selected text

OpenObject24.png

Open a dialog box to select a Xaml variable in the WS

ClearClipboard24.png

Clear the clipboard

SaveObject24.png

Open a dialog box to save the Xaml as a variable in the WS

Undo24.png

Undo last operation

Open24.png

Open a dialog box to select a file on disk

Redo24.png

Redo previous operation

Save24.png

Open a dialog box to save the Xaml to a file

Print32.png

Print all the Xaml

Cut24.png

Cut the Selected Text to The Clipboard

PrintPreview32.png

Print preview all the Xaml

Copy24.png

Copy the selected text to the clipboard

Comments24.png

Make selected text a comment

Paste24.png

Paste the text from the clipboard

Settings24.png

Choose the settings when scrubbing

Installation

  1. Download the file wpfXamlEditor.1.1.zip. It contains the Dyalog user command file wpfXamlEditor.dyalog and a dll named ICSharpCode.AvalonEdit.dll

  2. Copy the file wpfXamlEditor.dyalog to your user command directory (for advice how to organize your User Commands see UserCommands/WhereShouldTheyGo).

  3. Copy the file ICSharpCode.AvalonEdit.dll to the same directory as your dyalog.exe file (as shown by +2 ⎕NQ'.' 'GetEnvironment' 'Dyalog'). You may need administrator privileges for copying the file. That dll is free of charge and was written by Daniel Grunwald. It can be downloaded from CodeProject or from AvalonEdit but is included in the zip file for commodity.

Detailed Explanations

Exec32.png

Execute the Xaml and Show the Result in a Separate Window

The Xaml will be parsed and shown in a separate window. If the root element of the Xaml is not a window it will be made the content of a new window. The x:Class attribute will be removed if present. All the events will be removed before parsing the Xaml by the function ScrubAndFix. It does not rely on a prefix to removed the events. ( Show ScrubAndFix )

   ∇ rootObj←ScrubAndFix xamlString;err;reader;stringReader;writer;⎕USING
     ⍝ Function to remove the Class and Events elements of Xaml and fix the resulting Xaml.
     ⍝ This function is most usefull when experimenting with Xaml taken directly from the Web but is slower than FixXaml.
     ⍝ Inspired from the code of XAMLPAD2009.
     ⍝ XamlString = Vector of Characters representing a XAML string
     ⍝ rootObj    = WPF Root Element Object if no error
     ⍝            = ⎕NULL (explanation of error) if error

      :Trap 0

          ⎕USING←'System.IO' 'System.Windows.Markup,WPF/PresentationFramework.dll' 'System.Xaml,System.Xaml.dll'
          stringReader←⎕NEW StringReader(⊂xamlString)
          reader←⎕NEW XamlXmlReader(stringReader XamlReader.GetWpfSchemaContext)
          writer←⎕NEW XamlObjectWriter(reader.SchemaContext)

          ⎕USING←0⍴⊂'' ⍝ Don't need it anymore

          :While reader.Read

              :If 'StartMember'≡⍕reader.NodeType
              :AndIf reader.Member.Name≡'Class'
                ⍝ Skip the x:Class attribute
                  {}reader.Read
                  {}reader.Read

              :ElseIf 'StartMember'≡⍕reader.NodeType
              :AndIf reader.Member.IsEvent
                ⍝ Skip the Event member
                  {}reader.Read
                  {}reader.Read

              :Else
                ⍝ Keep the other nodes
                  writer.WriteNode(reader)

              :End

          :EndWhile

        ⍝ The following line will return the root object
          rootObj←writer.Result

      :Else
         ⍝ Build the Error Message
          :If 90≠⎕EN
            ⍝ APL Error
              err←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13)

          :Else
            ⍝ .Net Error
              :Trap 0
                ⍝ Show the value of ⎕EXCEPTION.Message if not ⎕NULL.
                  err←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13)
              :Else
                ⍝ Sometimes ⎕EXCEPTION is (NULL) and will bug here.
                  err←'Exception (NULL): Unknown error',(⎕UCS 13)

              :EndTrap

          :End

          rootObj←⎕NULL err

      :EndTrap

Scrubber24.png

Rewrite the Xaml according to the settings (Scrub)

Will rewrite the Xaml according to the settings. The most important setting is Attribute Tolerance; it allows you to define how many attributes there could be on one line of Xaml. Past that number all the attributes are written on a separate line.

OpenObject24.png

Open a dialog box to select a Xaml variable in the WS

SaveObject24.png

Open a dialog box to save the Xaml as a variable in the WS

The dialog box contains a tree element where each branch is a namespace that has a character variable that responds positive to the following test: do the first and last character match '<>' after removing the white space (space,LF,NL,HT characters)? In APL:

'><'≡¯2↑1⌽variableName~⎕UCS 32 10 13 9

Note that variables of scripted namespaces will not be permanently changed by XamlEditor.

Open24.png

Open a dialog box to select a file on disk

Save24.png

Open a dialog box to save the Xaml to a file

A standard OpenFileDialog and SaveFileDialog are used to select and save the file.

Print32.png

Print all the Xaml

PrintPreview32.png

Print preview all the Xaml

Will take the Xaml to a FlowDocument where it can be previewed or printed directly.

Comments24.png

Make selected text a comment

The following rules apply to this button when clicked:

  1. If nothing is selected it will insert '<!--  -->' at the caret.

  2. If the selection is positive to the test: ' --><!-- '≡9↑¯4⌽selectedText, the comments are removed.

  3. Otherwise it will insert: '<!-- ',selectedText,' -->'

Settings24.png

Choose the Settings when scrubbing

The settings for scrubbing are saved in an XML file named XED.Settings.xml. The file will be created automatically with default values the first time the user command runs.

It will be located in the AppData directory. The data of the file looks like this:

   1 <Settings>
   2   <EditorFont>APL385 Unicode</EditorFont>
   3   <EditorFontSize>14</EditorFontSize>
   4   <ReducePrecision>1</ReducePrecision>
   5   <Precision>3</Precision>
   6   <AttributeCounteTolerance>3</AttributeCounteTolerance>
   7   <ReorderAttributes>1</ReorderAttributes>
   8   <RemoveCommonDefaultValues>0</RemoveCommonDefaultValues>
   9   <ConvertTabsToSpaces>1</ConvertTabsToSpaces>
  10   <SpaceCount>3</SpaceCount>
  11 </Settings>

It is used to populate the "Settings" window.

Settings.png

Item

Description

"Font"

Font used by Xaml Editor

"Font Size"

Size of the font used by Xaml Editor

"Numeric Precision"

Reduce the precision of large numbers to a maximum of this number of digits beyond the decimal point

"Attribute Tolerance"

If more than this number of attributes are defined on an element, Scrubber will move each attribute onto its own line

"Reorder Attributes By Importance"

Scrubber will reorder attributes on a given element according to a predetermined set of rules about which attributes
are most important

"Remove Common Default Values"

Scrubber will remove common properties which are being set to their default values

"Indent Using Spaces"

If this is checked Scrubber will indent using spaces instead of tabs

Version Information

Version 1.0 Mars 2015

Version 1.1 February 2016
        SaveSettings and GetSettings changed to always use the AppData directory
        Initial focus is now set to the editor instead of the window (via Xaml)

Original author:

Pierre Gilbert

Responsible:

PierreGilbert

Email:

<apgil AT SPAMFREE videotron DOT ca>


CategoryDyalog - CategoryDyalogDotNet - CategoryDyalogWpfUtilities - CategoryDotNet

wpfXamlEditor (last edited 2016-02-28 13:16:57 by PierreGilbert)