2 Replies Latest reply on Oct 31, 2012 7:28 AM by _darwinjob_

    Why clipboard items are disabled?

    _darwinjob_

      Hi

      Here is a test case, simple setup which should work out of the box: AdvancedDataGrid with 3 colums and ContextMenu with clipboard menu enabled.

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                     xmlns:s="library://ns.adobe.com/flex/spark"

                     xmlns:mx="library://ns.adobe.com/flex/mx"

                     minWidth="800"

                     minHeight="600"

                     creationComplete="application1_creationCompleteHandler(event)">

          <fx:Script>

              <![CDATA[

                  import mx.collections.ArrayCollection;

                  import mx.controls.Alert;

                  import mx.events.FlexEvent;

       

                  [Bindable]

                  private var cm:ContextMenu;

       

                  [Bindable]

                  private var advancedDataGridDataProvider:ArrayCollection=new ArrayCollection();

       

                  protected function application1_creationCompleteHandler(event:FlexEvent):void

                  {

                      cm=new ContextMenu();

                      cm.hideBuiltInItems();

                      cm.clipboardMenu=true;

       

                      cm.clipboardItems.copy=true;

                      cm.clipboardItems.cut=true;

                      cm.clipboardItems.paste=true;

                      cm.clipboardItems.selectAll=true;

       

                      advancedDataGrid.addEventListener(Event.COPY, advancedDataGrid_onEvent);

                      advancedDataGrid.addEventListener(Event.CUT, advancedDataGrid_onEvent);

                      advancedDataGrid.addEventListener(Event.PASTE, advancedDataGrid_onEvent);

       

                      //Just filling with garbage

                      for (var i:int=0; i < 10000; i++)

                      {

                          var o:Object=new Object();

                          o.col1=Math.random();

                          o.col2=Math.random();

                          o.col3=Math.random();

       

                          advancedDataGridDataProvider.addItem(o);

                      }

                  }

       

                  private function advancedDataGrid_onEvent(evt:Event):void

                  {

                      Alert.show(evt.type);

                  }

              ]]>

          </fx:Script>

          <fx:Declarations>

              <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <mx:AdvancedDataGrid contextMenu="{cm}"

                               dataProvider="{advancedDataGridDataProvider}"

                               id="advancedDataGrid"

                               designViewDataType="flat"

                               selectionMode="multipleCells"

                               left="10"

                               top="10"

                               right="10"

                               bottom="10">

              <mx:columns>

                  <mx:AdvancedDataGridColumn headerText="Column 1"

                                             dataField="col1"/>

                  <mx:AdvancedDataGridColumn headerText="Column 2"

                                             dataField="col2"/>

                  <mx:AdvancedDataGridColumn headerText="Column 3"

                                             dataField="col3"/>

              </mx:columns>

          </mx:AdvancedDataGrid>

      </s:Application>

       

      If I run this, select one or more cells and then right-clcik to get the context menu all clipboard context menu items (Copy, Paste etc.) are DISABLED. Why is that? More strangely, if I precisely right-click between the rows - then the items are suddenly enabled!

        • 1. Re: Why clipboard items are disabled?
          Flex harUI Adobe Employee

          There might be another ContextMenu defined for the actual renderers so the ADG’s contextMenu doesn’t take effect.

          1 person found this helpful
          • 2. Re: Why clipboard items are disabled?
            _darwinjob_ Level 1

            Thanks for the reply.

            I have experimented with itemRenderers with no success. The problem was that I was using Canvas. After your post I realized that there is a dedicated class for that. To make in work with 4.1 it is enough to have ADG like that:

             

            <mx:AdvancedDataGrid contextMenu="{cm}"

                                     itemRenderer="ADGItemRenderer"

                                     dataProvider="{advancedDataGridDataProvider}"

                                     id="advancedDataGrid"

                                     designViewDataType="flat"

                                     selectionMode="multipleCells"

                                     left="10"

                                     top="10"

                                     right="10"

                                     bottom="10">

                    <mx:columns>

                        <mx:AdvancedDataGridColumn headerText="Column 1"

                                                   dataField="col1"/>

                        <mx:AdvancedDataGridColumn headerText="Column 2"

                                                   dataField="col2"/>

                        <mx:AdvancedDataGridColumn headerText="Column 3"

                                                   dataField="col3"/>

                    </mx:columns>

                </mx:AdvancedDataGrid>

             

            ADGItemRenderer is defined like this:

             

            <?xml version="1.0" encoding="utf-8"?>

            <s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"

                                              xmlns:s="library://ns.adobe.com/flex/spark"

                                              xmlns:mx="library://ns.adobe.com/flex/mx"

                                              focusEnabled="true">

                <s:Label id="lblData"

                         left="0"

                         text="{listData.label}"

                         verticalCenter="0"/>

            </s:MXAdvancedDataGridItemRenderer>

             

            As you can see contex menu is still in ADG but clipboard items are enabled now.

             

            The same trick does not work in 3.5 though. It does not work with AdvancedDataGridItemRenderer. I have moved ContextMenu from ADG to AdvancedDataGridItemRenderer like this:

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:AdvancedDataGridItemRenderer xmlns:mx="http://www.adobe.com/2006/mxml"

                                             xmlns:ui="flash.ui.*"

                                             copy="clipboardHandler(event)"

                                             paste="clipboardHandler(event)"

                                             cut="clipboardHandler(event)"

                                             selectAll="clipboardHandler(event)"

                                             clear="clipboardHandler(event)">

                <mx:Script>

                    <![CDATA[

                        import mx.controls.Alert;

             

                        protected function clipboardHandler(event:Event):void

                        {

                            Alert.show(event.type);

             

                        }

                    ]]>

                </mx:Script>

             

                <mx:contextMenu>

                    <ui:ContextMenu clipboardMenu="true"

                                    id="adgContextMenu">

                        <ui:clipboardItems>

                            <ui:ContextMenuClipboardItems copy="true"

                                                          cut="true"

                                                          paste="true"

                                                          selectAll="true"

                                                          clear="true"/>

                        </ui:clipboardItems>

                    </ui:ContextMenu>

                </mx:contextMenu>

            </mx:AdvancedDataGridItemRenderer>

             

            The items are still disabled. WTH?

             

            Fortunately it works with AdvancedDataGridGroupItemRenderer (which, I guess, has a slightly different purpose). If I define ADG itemRenderer just like this (keeping ContextMenu in ADG):

             

            <?xml version="1.0" encoding="utf-8"?>

            <mx:AdvancedDataGridGroupItemRenderer xmlns:mx="http://www.adobe.com/2006/mxml"/>

             

            then the clipboard items are enabled. Crazy.