<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Entities.Extensions;
using Signum.Entities.DynamicQuery;
using Signum.Entities;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.IO;
using Microsoft.Win32;
using Signum.Entities.Reports;
using Prop = Signum.Windows.Extensions.Properties;
using Signum.Services;
using Signum.Entities.Operations;
using Signum.Utilities;
using Signum.Windows.Extensions.Properties;
using Signum.Windows;

namespace Signum.Windows.Operations
{
    public class ConstructFromMenuItem : SearchControlMenuItem
    {
        internal List<OperationInfo> OperationInfos; 

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            Header = "Construir";
            Icon = ExtensionsImageLoader.GetImageSortName("factory.png").ToSmallImage();
        }

        public override void Initialize()
        {
            Items.Clear();

            this.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_Clicked));

            foreach (OperationInfo oi in OperationInfos)
            {
                MenuItem mi = new MenuItem()
                {
                    Header = OperationClient.GetText(oi.Key),
                    Icon = OperationClient.GetImage(oi.Key),
                    Tag = oi,
                };
                Items.Add(mi);
            }
        }

        private void MenuItem_Clicked(object sender, RoutedEventArgs e)
        {
            e.Handled = true;

            if (e.OriginalSource is MenuItem) //Not to capture the mouseDown of the scrollbar buttons
            {
                MenuItem b = (MenuItem)e.OriginalSource;
                OperationInfo operationInfo = (OperationInfo)b.Tag;
                Type entityType = SearchControl.EntityType;
                object queryName = SearchControl.QueryName;

                var lites = SearchControl.SelectedItems.TryCC(a => a.Cast<Lite>().ToList());

                if (lites == null || lites.Count == 0)
                    throw new ApplicationException(Signum.Windows.Extensions.Properties.Resources.SelectSomeRowsFirst);
<commit_msg>Hide ConstructFromMany on no selection<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Signum.Entities.Extensions;
using Signum.Entities.DynamicQuery;
using Signum.Entities;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.IO;
using Microsoft.Win32;
using Signum.Entities.Reports;
using Prop = Signum.Windows.Extensions.Properties;
using Signum.Services;
using Signum.Entities.Operations;
using Signum.Utilities;
using Signum.Windows.Extensions.Properties;
using Signum.Windows;
using System.Windows.Data;

namespace Signum.Windows.Operations
{
    public class ConstructFromMenuItem : SearchControlMenuItem
    {
        static readonly IValueConverter ListToVisibility = ConverterFactory.New((Array a) => a == null || a.Length == 0 ? Visibility.Collapsed : Visibility.Visible); 

        internal List<OperationInfo> OperationInfos; 

        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            Header = Signum.Windows.Extensions.Properties.Resources.Create + "...";
            Icon = ExtensionsImageLoader.GetImageSortName("factory.png").ToSmallImage();
        }

        public override void Initialize()
        {
            Items.Clear();

            this.AddHandler(MenuItem.ClickEvent, new RoutedEventHandler(MenuItem_Clicked));

            foreach (OperationInfo oi in OperationInfos)
            {
                MenuItem mi = new MenuItem()
                {
                    Header = OperationClient.GetText(oi.Key),
                    Icon = OperationClient.GetImage(oi.Key),
                    Tag = oi,
                };
                Items.Add(mi);
            }

            this.Bind(VisibilityProperty, SearchControl, "SelectedItems", ListToVisibility);
        }

        private void MenuItem_Clicked(object sender, RoutedEventArgs e)
        {
            e.Handled = true;

            if (e.OriginalSource is MenuItem) //Not to capture the mouseDown of the scrollbar buttons
            {
                MenuItem b = (MenuItem)e.OriginalSource;
                OperationInfo operationInfo = (OperationInfo)b.Tag;
                Type entityType = SearchControl.EntityType;
                object queryName = SearchControl.QueryName;

                var lites = SearchControl.SelectedItems.TryCC(a => a.Cast<Lite>().ToList());

                if (lites == null || lites.Count == 0)
                    throw new ApplicationException(Signum.Windows.Extensions.Properties.Resources.SelectSomeRowsFirst);

{'fraction_non_alphanumeric': 0.08714462299134734, 'fraction_numerical': 0.001442109600329625, 'mean_word_length': 2.3903631284916202, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2559168', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1209, 'n_words': 276}