Ejemplo n.º 1
0
        public void OnBeforeContextMenu(TModel model, Context context)
        {
            for (int i = modelAdapter.GetItemCount(model) - 1; i >= 0; i--)
            {
                int command = modelAdapter.GetCommandAt(model, i);

                if (!(AllowedCommands.Contains(command) || command is >= CommandCustomFirst and <= CommandCustomLast))
                {
                    modelAdapter.RemoveAt(model, i);
                }
            }

            for (int i = modelAdapter.GetItemCount(model) - 2; i >= 0; i--)
            {
                if (modelAdapter.IsSeparatorAt(model, i) && modelAdapter.IsSeparatorAt(model, i + 1))
                {
                    modelAdapter.RemoveAt(model, i);
                }
            }

            if (modelAdapter.GetItemCount(model) > 0 && modelAdapter.IsSeparatorAt(model, 0))
            {
                modelAdapter.RemoveAt(model, 0);
            }

            var builder = new ContextMenuBuilder(modelAdapter, actionRegistry, model);

            builder.AddSeparator();
            handler?.Show(builder, context);
            builder.RemoveSeparatorIfLast(model);
        }
Ejemplo n.º 2
0
            public void AddSeparator()
            {
                int count = modelAdapter.GetItemCount(model);

                if (count > 0 && !modelAdapter.IsSeparatorAt(model, count - 1))                   // do not add separators if there is nothing to separate
                {
                    modelAdapter.AddSeparator(model);
                }
            }