Beispiel #1
0
 private ContextMenuResult CreateContextMenuEntry(UnitConversionResult result)
 {
     return(new ContextMenuResult
     {
         PluginName = Name,
         Title = Properties.Resources.context_menu_copy,
         Glyph = "\xE8C8",
         FontFamily = "Segoe MDL2 Assets",
         AcceleratorKey = Key.Enter,
         Action = _ =>
         {
             bool ret = false;
             var thread = new Thread(() =>
             {
                 try
                 {
                     Clipboard.SetText(result.ConvertedValue.ToString());
                     ret = true;
                 }
                 catch (ExternalException)
                 {
                     MessageBox.Show(Properties.Resources.copy_failed);
                 }
             });
             thread.SetApartmentState(ApartmentState.STA);
             thread.Start();
             thread.Join();
             return ret;
         },
     });
 }
Beispiel #2
0
 private Result GetResult(UnitConversionResult result)
 {
     return(new Result
     {
         ContextData = result,
         Title = string.Format("{0} {1}", result.ConvertedValue, result.UnitName),
         IcoPath = _icon_path,
         Score = 300,
         SubTitle = string.Format(Properties.Resources.copy_to_clipboard, result.QuantityType),
         Action = c =>
         {
             var ret = false;
             var thread = new Thread(() =>
             {
                 try
                 {
                     Clipboard.SetText(result.ConvertedValue.ToString());
                     ret = true;
                 }
                 catch (ExternalException)
                 {
                     MessageBox.Show(Properties.Resources.copy_failed);
                 }
             });
             thread.SetApartmentState(ApartmentState.STA);
             thread.Start();
             thread.Join();
             return ret;
         },
     });
 }
Beispiel #3
0
        public List <ContextMenuResult> LoadContextMenus(Result selectedResult)
        {
            if (!(selectedResult?.ContextData is UnitConversionResult))
            {
                return(new List <ContextMenuResult>());
            }

            List <ContextMenuResult> contextResults = new List <ContextMenuResult>();
            UnitConversionResult     result         = selectedResult.ContextData as UnitConversionResult;

            contextResults.Add(CreateContextMenuEntry(result));

            return(contextResults);
        }
Beispiel #4
0
        /// <summary>
        /// Given ConvertModel returns collection of possible results.
        /// </summary>
        /// <returns>The converted value as a double.</returns>
        public static IEnumerable <UnitConversionResult> Convert(ConvertModel convertModel)
        {
            var results = new List <UnitConversionResult>();

            foreach (QuantityType quantityType in _included)
            {
                double convertedValue = UnitHandler.ConvertInput(convertModel, quantityType);

                if (!double.IsNaN(convertedValue))
                {
                    UnitConversionResult result = new UnitConversionResult(Round(convertedValue), convertModel.ToUnit, quantityType);
                    results.Add(result);
                }
            }

            return(results);
        }
        private Result GetResult(UnitConversionResult result)
        {
            string hack = string.Format("{0}", result.QuantityType);

            if (hack == "Acceleration")
            {
                hack = "加速度";
            }
            else if (hack == "Angle")
            {
                hack = "角度";
            }
            else if (hack == "Area")
            {
                hack = "面积";
            }
            else if (hack == "Duration")
            {
                hack = "时间";
            }
            else if (hack == "Energy")
            {
                hack = "能量";
            }
            else if (hack == "Information")
            {
                hack = "数据";
            }
            else if (hack == "Length")
            {
                hack = "长度";
            }
            else if (hack == "Mass")
            {
                hack = "质量";
            }
            else if (hack == "Power")
            {
                hack = "功率";
            }
            else if (hack == "Pressure")
            {
                hack = "压强";
            }
            else if (hack == "Speed")
            {
                hack = "速度";
            }
            else if (hack == "Temperature")
            {
                hack = "温度";
            }
            else if (hack == "Volume")
            {
                hack = "体积";
            }
            return(new Result
            {
                ContextData = result,
                Title = string.Format("{0} {1}", result.ConvertedValue, result.UnitName),
                IcoPath = _icon_path,
                Score = 300,
                SubTitle = string.Format(Properties.Resources.copy_to_clipboard, hack),
                Action = c =>
                {
                    var ret = false;
                    var thread = new Thread(() =>
                    {
                        try
                        {
                            Clipboard.SetText(result.ConvertedValue.ToString());
                            ret = true;
                        }
                        catch (ExternalException)
                        {
                            MessageBox.Show(Properties.Resources.copy_failed);
                        }
                    });
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                    return ret;
                },
            });
        }