Publishing buttons in directory style

Build 1501 on 14/Nov/2017  This topic last edited on: 6/Sep/2016, at 13:33

It is also possible to add commands and markup in the directory style to display information and call publishing AddIn commands:

pubdirstyle

The directory style used above is at the end of this topic.

The use of HyperlinkButton allows a command to be called directly from a directory style listing:

<l:HyperlinkButton 

  Margin="2" AutoSelect="False" 

  Content="Publish GN3" 

  ObjectId="{Binding Path=[txt.id]}"

  Command="{x:Static l:Commands.ClickScript}"

  CommandParameter="PublishGN3Click"/>

The above markup calls the PublishGN3Click AddIn command:

Public Class SiteMainAddIn

  ...

  Public Sub PublishGN3Click(ByVal clickSource As IClickScriptSource)

    PublishClick("/GN3", clickSource)

  End Sub

 

  Public Sub UnpublishGN3Click(ByVal clickSource As IClickScriptSource)

    UnpublishClick("/GN3", clickSource)

  End Sub

The IClickScriptSource provides the ObjectId specified in the HyperlinkButton directly and so does not require a current selection.

The default value of AutoSelect is true which selects the associated list item when the HyperlinkButton is clicked. If AutoSelect is true, normal AddIn commands can be called.

<l:HyperlinkButton Margin="2" Content="Publish GN3"

  Command="{x:Static l:Commands.Script}"

  CommandParameter="PublishGN3"/>

The PublishedStatusIcon displays the "world" icon with the SelectorValue is not null, e.g. the element has been published. The tooltip will indicate which publishing destinations the item has been published to.

<l:PublishedStatusIcon Margin="5,0,0,0" 

  SelectorValue="{Binding Path=[txt:Referencing( pubDest.objs )]}" 

  Height="16" Width="16"/>

 

The PublishedStatusIcon is based on NullSelectableContentControl which displays alternative markup depending on whether SelectorValue is null or not.

The following code uses that control to display a publish or unpublish command in the listing depending on whether the item has been published:

<l:NullableContentControl 

  SelectorValue="{Binding Path=[txt:Referencing( pubDest.objs )]}">

  <l:NullableContentControl.NullContentTemplate>

    <DataTemplate>

      <l:HyperlinkButton Margin="2" AutoSelect="False"

        Content="Publish GN3"

        ObjectId="{Binding Path=[txt.id]}"

        Command="{x:Static l:Commands.ClickScript}"

        CommandParameter="PublishGN3Click"/>

    </DataTemplate>

  </l:NullableContentControl.NullContentTemplate>

  <l:NullableContentControl.ContentTemplate>

    <DataTemplate>

      <l:HyperlinkButton Margin="2" AutoSelect="False"

        Content="Unpublish GN3"

        ObjectId="{Binding Path=[txt.id]}"

        Command="{x:Static l:Commands.ClickScript}"

        CommandParameter="UnpublishGN3Click"/>

    </DataTemplate>

  </l:NullableContentControl.ContentTemplate>

</l:NullableContentControl>

 

When the SelectorValue evaluates to null then the markup defined in the NullContentTemplate DataTemplate is used, otherwise the ContentTemplate DataTemplate is used.

If either value is not defined then nothing is displayed.

The complete directory style is:

<DirectoryStyle Name="List" Description="" Height="1" Width="-1">

  <DataTemplate>

    <StackPanel Orientation="Vertical">

      <StackPanel Orientation="Horizontal">

        <TextBlock Width="50" Foreground="Gray" Margin="4 2 4 2" 

          Height="Auto" HorizontalAlignment="Left" Text="Folder: " />

        <TextBlock Foreground="Black" Margin="0 2 4 2" 

          Height="Auto" HorizontalAlignment="Left" 

          Text="{Binding Path=[txt.folderRef:DescName]}" />

      </StackPanel>

      <StackPanel Orientation="Horizontal">

        <TextBlock Width="50" Foreground="Gray" Margin="4 2 4 2"

          Height="Auto" HorizontalAlignment="Left"

          Text="Modified: " />

        <TextBlock Foreground="Black" 

          Margin="0 2 4 2" Height="Auto" 

          HorizontalAlignment="Left" 

          Text="{Binding Path=[txt.modifiedDate]}" />

      </StackPanel>

      <StackPanel Orientation="Horizontal" 

        Visibility="{Binding Path=IsSelected, 

           Converter={StaticResource VisibilityConverter}, 

           RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}}">

        <l:HyperlinkButton Margin="2" Content="Publish GN3"

          Command="{x:Static l:Commands.Script}"

          CommandParameter="PublishGN3"/>

        <l:HyperlinkButton Margin="2" Content="Unpublish GN3"

          Command="{x:Static l:Commands.Script}"

          CommandParameter="UnpublishGN3"/>

      </StackPanel>

    </StackPanel>

  </DataTemplate>

  <ColStyle Name="Name" Width="240" Height="0" SortName="Name">

    <CellTemplate>

      <StackPanel VerticalAlignment="Top" 

        HorizontalAlignment="Left" Orientation="Horizontal">

        <l:ObjectTypeIcon HorizontalAlignment="Center" 

          VerticalAlignment="Center" Stretch="None" 

          ObjectType="{Binding Path=ObjectType}" Size="16" />

        <TextBlock Height="Auto" HorizontalAlignment="Left" 

          Text="{Binding Path=[txt.name]}" Margin="5 0 0 0" 

          FontWeight="Bold" />

        <l:PublishedStatusIcon Margin="5,0,0,0" 

          SelectorValue="{Binding Path=[txt:Referencing( pubDest.objs )]}" 

          Height="16" Width="16"/>

        <l:NullableContentControl 

          SelectorValue="{Binding Path=[txt:Referencing( pubDest.objs )]}">

          <l:NullableContentControl.NullContentTemplate>

            <DataTemplate>

              <l:HyperlinkButton Margin="2" AutoSelect="False"

                Content="Publish GN3"

                ObjectId="{Binding Path=[txt.id]}"

                Command="{x:Static l:Commands.ClickScript}"

                CommandParameter="PublishGN3Click"/>

            </DataTemplate>

          </l:NullableContentControl.NullContentTemplate>

          <l:NullableContentControl.ContentTemplate>

            <DataTemplate>

              <l:HyperlinkButton Margin="2" AutoSelect="False"

                Content="Unpublish GN3"

                ObjectId="{Binding Path=[txt.id]}"

                Command="{x:Static l:Commands.ClickScript}"

                CommandParameter="UnpublishGN3Click"/>

            </DataTemplate>

          </l:NullableContentControl.ContentTemplate>

        </l:NullableContentControl>

      </StackPanel>

    </CellTemplate>

  </ColStyle>

</DirectoryStyle>