none
How to create a Ribbon's Gallery Control with custom BuildingBlocks? RRS feed

  • Question

  • Hi,

       I have several Building Blocks saved in:

    • MyTemplate= ActiveDocument.AttachedTemplate
    • BuildingBlockTypes = wdTypeCustom1
    • Category = "MyCategory"

       Now I want to create a Gallery Control in the Ribbon to access them.

       I thought that I had to work with the "getItemCount", "getItemImage", and "onAction" callbacks of the Gallery but I can't manage this.

    Could someone help me?

    Lauro

     

     

     

    Monday, April 18, 2011 3:20 PM

All replies

  • You don't need dynamic ribbon callbacks to display the BuildingBlocks. Try this ribbon entry

    <gallery idMso="CustomGallery1" label="Staff Biogs" />

    Tuesday, April 19, 2011 1:03 AM
  • Hello,

     

    Is your goal to dynamically display in a gallery control, previews of the building blocks found in the document? Or simply to display a text item with some information about the building block, like a name of some sort?

     

    To add/remove items from a gallery item, simply use :

    RibbonDropDownItem galleryItem = new RibbonDropDownItem();
    
    galleryItem.Tag = bb.ID;
    if (Image == null)
      {
       //if no preview of the bb is available was made
        galleryItem.Image = Resources.missingPreview;
       }
    galleryItem.Label = bb.Category;
    galleryItem.ScreenTip = "This is a screen tip";
    
    gallery.Items.Add(galleryItem);
    
    This code can be used everytime you insert a bb in the document. Also, in the "Click" event of the gallery to select the building block in the document, when it is selected in the gallery.

     

    If you want I can give you more information here. Hope this help you,

    Silviu.


    http://www.rosoftlab.net/
    Tuesday, April 19, 2011 5:08 AM
  • If I follow your suggestion what I get in the Gallery Control are all the Building Blocks with these properties:

    • BuildingBlockTypes = wdTypeCustom1
    • Categories= all
    • file = Building Blocks.dotx

    What I would like to have is:

    • BuildingBlockTypes = wdTypeCustom1
    • Categories= mycategory
    • file = my attachedTemplate.

    Thanks, Lauro

    P.S. I can do it easily in a wdContentControlBuildingBlockGallery, but not in the Ribbon.

     

    Tuesday, April 19, 2011 9:31 AM
  • Hi, thanks for your answer, but I don't understand very well it.

    I try to be clearer myself.

    I would like to insert a Gallery Control in the Ribbon (like the AutoText or Header, etc.); I would like as items of the Gallery all the Building Blocks of a certain type (wdTypeCustom1, e.g.), of a certain category ("MyCat", e.g.), stored in a certain file (ActiveDocument.AttachedTemplate, e.g.)

    To insert a Gallery like that in a ContentControlBuildingBlockGallery is very easy; I can't dothe same for a Ribbon Control Gallery.

     

    Thanks, Lauro

    Tuesday, April 19, 2011 9:42 AM
  • Hello,

    What kind of project is this? Add-In, Template, Document?

     

    If you are doing an Add-In, the Gallery Control can be added, after adding the Ribbon (found using "Add New Item" in the office project). After that, you will find the control in the Toolbox pane.

     

    Ribbon Control Gallery is a control that contains Ribbon Control Gallery Items. The items must be added by means of binding or manually (like I showed you above).

    If you can get all the Building Blocks from the attached template, and use on them something like:

     

    foreach(var bb in buildingBlocks)
    {
       if(bb.BuildingBlockType == BuildingBlockTypes.wdTypeCustom1)
         {
          // use the code from above - create GalleryItem and add it
           AddToGallery(bb);
         }
    }
    

     

     I do not know if there is a way to give the file to the gallery and it to extract the templates.

     

    Hope this is helpfull,

    Silviu.


    http://www.rosoftlab.net/
    Tuesday, April 19, 2011 9:57 AM
  • Hi,

    is a Template Project in VBA.

    Tanks, Lauro

    Tuesday, April 19, 2011 8:52 PM
  • Hi Lauro

    I don't think there's any way for you to get a Word-type gallery of the building block entries filtered the way you'd like to have it.

    It should be possible to create a Ribbon XML type of gallery listing only the building blocks you want (the approach you mention in your first message). Getting the pictures of the entries would be something of a challenge, however, if this is to be at all dynamic. Especially using VBA which has no real capabilities for cracking open the XML "Package" files.


    Cindy Meister, VSTO/Word MVP
    Sunday, April 24, 2011 6:11 AM
    Moderator
  • Getting the pictures of the entries would be something of a challenge, however, if this is to be at all dynamic. 

    Cindy Meister, VSTO/Word MVP

    Cindy,

    I would like to do the same thing from an add-in.  I'm using the VSTO ribbon designer instead of XML.  I have it working other than the preview image.  Can you elaborate on your reply or at least send me off in a useful direction?

    Thanks,

    Eddie

    Friday, May 6, 2011 9:32 PM
  • Ron de Bruin has some examples on his web site for this (see http://www.rondebruin.nl/galleries.htm) - hopefully that will start you off. It can be done, although there are some 'funnies', and some things that work in Excel but not Word 2010, if I recall. I don't know about VSTO, but I can root out some VBA code, if you want more detail on anything.
     

    Enjoy,
    Tony
    www.WordArticles.com
    Saturday, May 7, 2011 10:12 AM
  • <<Getting the pictures of the entries would be something of a challenge, however, if this is to be at all dynamic. >>

    I would like to do the same thing from an add-in.  I'm using the VSTO ribbon designer instead of XML.  I have it working other than the preview image.  Can you elaborate on your reply or at least send me off in a useful direction?


    Hi Eddie

    Well, this isn't something I've ever looked at in any depth, so all I can do is make some suggestions...

    It's possible to get a "picture" of something in Word by using either the Range.EnhMetaFileBits property or the Range.CopyAsPicture method. Both of these require actually opening the file in the Word application, which is why I mentioned "dynamic" could be tricky.

    Unfortunately, Word doesn't seem to store a graphical representation of a building block in the building block "container" file. I don't know what Word itself uses to generate previews, but whatever it is, it's not exposed in the API.


    Cindy Meister, VSTO/Word MVP
    Sunday, May 8, 2011 8:21 AM
    Moderator
  • Sorry, it seems I misunderstood what you were saying - you want to know how to get the preview image, not how to put it in the gallery.
     

    Enjoy,
    Tony
    www.WordArticles.com
    Monday, May 9, 2011 1:07 PM
  •  

    Unfortunately, Word doesn't seem to store a graphical representation of a building block in the building block "container" file. I don't know what Word itself uses to generate previews, but whatever it is, it's not exposed in the API.

     

    I was afraid of that.  I have an application that requires a gallery of building blocks that is filtered depending upon the context of the document so different building blocks would be available as the user works in different sections of the document.  Otherwise the user may insert an invalid building block.

    I guess I'll use a button on the ribbon to insert a gallery content control, populate the content control and let the user select a building block from there.

     

    Eddie


    Monday, May 9, 2011 4:24 PM