예제 #1
0
        /// <summary>
        /// Loads bar data from either a local file, or a url.
        /// </summary>
        /// <param name="serviceProvider">The service provider/</param>
        /// <param name="barSource">The local path or remote url.</param>
        /// <param name="content">The json content, if already loaded.</param>
        /// <param name="includeDefault">true to also include the default bar data.</param>
        /// <returns>The bar data</returns>
        public static BarData?Load(IServiceProvider serviceProvider, string barSource, string?content = null, bool includeDefault = true)
        {
            BarData?defaultBar;

            if (includeDefault)
            {
                defaultBar = BarData.Load(serviceProvider, AppPaths.GetConfigFile("default-bar.json5", true), null, false);
                // Mark the items as being from the default specification
                defaultBar?.AllItems.ForEach(item => item.IsDefault = true);

                // OBSERVATION: we need a better way to determine if this is the basic bar or another bar
                var isBasicBar = (barSource == AppPaths.GetConfigFile("basic-bar.json5", true));
                //
                if (isBasicBar == true)
                {
                    // if extra bar items were specified in the config file, add them to the left side of the MorphicBar now
                    var morphicBarExtraItems = ConfigurableFeatures.MorphicBarExtraItems;
                    if (morphicBarExtraItems.Count > 0)
                    {
                        List <BarItem> extraBarItems = new List <BarItem>();
                        foreach (var extraItemData in morphicBarExtraItems)
                        {
                            BarItem extraBarItem;
                            var     extraBarItemShouldBeAdded = false;

                            switch (extraItemData.type)
                            {
                            case "application":
                            {
                                extraBarItem = new BarButton(defaultBar);
                                extraBarItem.ToolTipHeader = extraItemData.tooltipHeader;
                                extraBarItem.ToolTip       = extraItemData.tooltipText;
                                extraBarItem.Text          = extraItemData.label ?? "";
                                //
                                extraBarItem.Action = new Morphic.Client.Bar.Data.Actions.ApplicationAction();
                                ((Morphic.Client.Bar.Data.Actions.ApplicationAction)extraBarItem.Action !).ImageIsCollapsed = true;        // for horizontal bars, we don't want an image to be visible
                                ((Morphic.Client.Bar.Data.Actions.ApplicationAction)extraBarItem.Action !).ExeName          = extraItemData.appId ?? "";
                                extraBarItemShouldBeAdded = ((Morphic.Client.Bar.Data.Actions.ApplicationAction)extraBarItem.Action !).IsAvailable;
                            }
                            break;

                            case "link":
                            {
                                extraBarItem = new BarButton(defaultBar);
                                extraBarItem.ToolTipHeader = extraItemData.tooltipHeader;
                                extraBarItem.ToolTip       = extraItemData.tooltipText;
                                extraBarItem.Text          = extraItemData.label ?? "";
                                //
                                extraBarItem.Action = new Morphic.Client.Bar.Data.Actions.WebAction();
                                ((Morphic.Client.Bar.Data.Actions.WebAction)extraBarItem.Action !).UrlString = extraItemData.url ?? "";
                                extraBarItemShouldBeAdded = true;
                            }
                            break;

                            case "action":
                            {
                                extraBarItem = new BarButton(defaultBar);
                                extraBarItem.ToolTipHeader = extraItemData.tooltipHeader;
                                extraBarItem.ToolTip       = extraItemData.tooltipText;
                                extraBarItem.Text          = extraItemData.label ?? "";
                                //
                                var extraBarItemInternalAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                extraBarItemInternalAction.TelemetryEventName = "morphicBarExtraItem";
                                extraBarItem.Action = extraBarItemInternalAction;
                                ((Morphic.Client.Bar.Data.Actions.InternalAction)extraBarItem.Action !).FunctionName = extraItemData.function !;
                                extraBarItemShouldBeAdded = true;
                            }
                            break;

                            case "control":
                            {
                                extraBarItem = new BarMultiButton(defaultBar);
                                extraBarItem.ToolTipHeader = extraItemData.tooltipHeader;
                                extraBarItem.ToolTip       = extraItemData.tooltipText;
                                //
                                switch (extraItemData.feature)
                                {
                                case "usbopeneject":
                                {
                                    extraBarItem.Text = extraItemData.label ?? "{{QuickStrip_UsbOpenEject_Title}}";
                                    //
                                    var openAllUsbAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    openAllUsbAction.TelemetryEventName = "morphicBarExtraItem";
                                    openAllUsbAction.FunctionName       = "openAllUsbDrives";
                                    var openButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "{{QuickStrip_UsbOpenEject_Open_Title}}",
                                        Action            = openAllUsbAction,
                                        TelemetryCategory = "morphicBarExtraItem",
                                        Tooltip           = "{{QuickStrip_UsbOpenEject_Open_HelpTitle}}",
                                        Value             = "openallusb"
                                    };
                                    //
                                    var ejectAllUsbAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    ejectAllUsbAction.TelemetryEventName = "morphicBarExtraItem";
                                    ejectAllUsbAction.FunctionName       = "ejectAllUsbDrives";
                                    var ejectButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "{{QuickStrip_UsbOpenEject_Eject_Title}}",
                                        Action            = ejectAllUsbAction,
                                        TelemetryCategory = "morphicBarExtraItem",
                                        Tooltip           = "{{QuickStrip_UsbOpenEject_Eject_HelpTitle}}",
                                        Value             = "ejectallusb"
                                    };
                                    //
                                    ((BarMultiButton)extraBarItem).Buttons = new Dictionary <string, BarMultiButton.ButtonInfo>
                                    {
                                        { "open", openButton },
                                        { "eject", ejectButton }
                                    };
                                    //
                                    extraBarItemShouldBeAdded = true;
                                }
                                break;

                                case "volume":
                                {
                                    extraBarItem.Text = extraItemData.label ?? "{{QuickStrip_Volume_Title}}";
                                    //
                                    var volumeUpAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    volumeUpAction.TelemetryEventName = "volumeUp";
                                    volumeUpAction.FunctionName       = "volumeUp";
                                    var volumeUpButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "+",
                                        Action            = volumeUpAction,
                                        TelemetryCategory = "volumeUp",
                                        Tooltip           = "{{QuickStrip_Volume_Up_HelpTitle}}|{{QuickStrip_Volume_Up_HelpMessage}}|{{QuickStrip_Volume_Up_LimitTitle}}",
                                        Value             = "volumeUp"
                                    };
                                    //
                                    var volumeDownAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    volumeDownAction.TelemetryEventName = "volumeDown";
                                    volumeDownAction.FunctionName       = "volumeDown";
                                    var volumeDownButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "-",
                                        Action            = volumeDownAction,
                                        TelemetryCategory = "volumeDown",
                                        Tooltip           = "{{QuickStrip_Volume_Down_HelpTitle}}|{{QuickStrip_Volume_Down_HelpMessage}}|{{QuickStrip_Volume_Down_LimitTitle}}",
                                        Value             = "volumeDown"
                                    };
                                    //
                                    var volumeMuteAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    volumeMuteAction.TelemetryEventName = "volumeMute";
                                    volumeMuteAction.FunctionName       = "volumeMute";
                                    var volumeMuteButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "{{QuickStrip_Volume_Mute_Title}}",
                                        Action            = volumeMuteAction,
                                        TelemetryCategory = "volumeMute",
                                        Toggle            = true,
                                        Tooltip           = "{{QuickStrip_Volume_Mute_HelpTitle}}|{{QuickStrip_Volume_Mute_HelpMessage}}",
                                        Value             = "volumeMute"
                                    };
                                    //
                                    ((BarMultiButton)extraBarItem).Buttons = new Dictionary <string, BarMultiButton.ButtonInfo>
                                    {
                                        { "volumeUp", volumeUpButton },
                                        { "volumeDown", volumeDownButton },
                                        { "volumeMute", volumeMuteButton }
                                    };
                                    ((BarMultiButton)extraBarItem).Menu = new Dictionary <string, string>()
                                    {
                                        { "setting", "sound" },
                                        { "learn", "volmute" },
                                        { "demo", "volmute" }
                                    };
                                    ((BarMultiButton)extraBarItem).AutoSize = true;
                                    //
                                    extraBarItemShouldBeAdded = true;
                                }
                                break;

                                case "wordsimplify":
                                {
                                    extraBarItem.Text = extraItemData.label ?? "{{QuickStrip_WordSimplify_Title}}";
                                    //
                                    var basicWordRibbonAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    basicWordRibbonAction.TelemetryEventName = "morphicBarExtraItem";                 // basicWordRibbonToggle
                                    basicWordRibbonAction.FunctionName       = "basicWordRibbon";
                                    var basicWordRibbonButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "{{QuickStrip_WordSimplify_Basic_Title}}",
                                        Action            = basicWordRibbonAction,
                                        TelemetryCategory = "morphicBarExtraItem",
                                        Toggle            = true,
                                        Tooltip           = "{{QuickStrip_WordSimplify_Basic_HelpTitle}}|{{QuickStrip_WordSimplify_Basic_HelpMessage}}",
                                        Value             = "basicwordribbon"
                                    };
                                    //
                                    var essentialsWordRibbonAction = new Morphic.Client.Bar.Data.Actions.InternalAction();
                                    essentialsWordRibbonAction.TelemetryEventName = "morphicBarExtraItem";                 // essentialsWordRibbonToggle
                                    essentialsWordRibbonAction.FunctionName       = "essentialsWordRibbon";
                                    var essentialsWordRibbonButton = new BarMultiButton.ButtonInfo
                                    {
                                        Text              = "{{QuickStrip_WordSimplify_Essentials_Title}}",
                                        Action            = essentialsWordRibbonAction,
                                        TelemetryCategory = "morphicBarExtraItem",
                                        Toggle            = true,
                                        Tooltip           = "{{QuickStrip_WordSimplify_Essentials_HelpTitle}}|{{QuickStrip_WordSimplify_Essentials_HelpMessage}}",
                                        Value             = "essentialswordribbon"
                                    };
                                    //
                                    ((BarMultiButton)extraBarItem).Buttons = new Dictionary <string, BarMultiButton.ButtonInfo>
                                    {
                                        { "basic", basicWordRibbonButton },
                                        { "essentials", essentialsWordRibbonButton }
                                    };
                                    ((BarMultiButton)extraBarItem).Menu = new Dictionary <string, string>()
                                    {
                                        { "learn", "wordsimplify" },
                                        { "demo", "wordsimplify" }
                                    };
                                    ((BarMultiButton)extraBarItem).AutoSize = true;
                                    //
                                    // NOTE: we should only show this item if Word is actually installed
                                    // NOTE: if Word is not installed, Morphic.Integrations.Office may fail to load as a DLL (or otherwise throw NotImplementedException); ideally we'd
                                    //       dynamically load the DLL only if Word was installed...and would perhaps move .IsOfficeInstalled into a DLL which wasn't reliant on Office being installed.
                                    try
                                    {
                                        extraBarItemShouldBeAdded = Morphic.Integrations.Office.WordRibbon.IsOfficeInstalled();
                                    }
                                    catch (NotImplementedException)
                                    {
                                        extraBarItemShouldBeAdded = false;
                                    }
                                }
                                break;

                                default:
                                    extraBarItem.Text = extraItemData.label ?? "";
                                    // NOTE: we don't know what this button is, so do not show it
                                    extraBarItemShouldBeAdded = false;
                                    break;
                                }
                            }
                            break;

                            default:
                                // unknown type; this should be an impossible code path
                                throw new NotImplementedException();
                            }
                            //extraBarItem.ColorValue = "#00FF00";
                            //
                            if (extraBarItemShouldBeAdded == true)
                            {
                                defaultBar?.AllItems.Add(extraBarItem);
                            }
                        }

                        // add a spacer entry
                        BarButton spacerBarItem = new BarButton(defaultBar);
                        spacerBarItem.ToolTipHeader = "";
                        spacerBarItem.ToolTip       = "";
                        spacerBarItem.Text          = "";
                        spacerBarItem.ColorValue    = "#FFFFFF";
                        //
                        defaultBar?.AllItems.Add(spacerBarItem);
                    }
                }
            }
            else
            {
                defaultBar = null;
            }

            App.Current.Logger.LogInformation("Loading bar from {source}", barSource);

            BarData?bar;

            using (TextReader reader = content is null
                ? (TextReader)File.OpenText(barSource)
                : new StringReader(content))
            {
                bar = BarJson.Load(serviceProvider, reader, defaultBar);
            }

            bar.Source = barSource;
            if (File.Exists(barSource))
            {
                bar.AddWatcher(barSource);
            }

            return(bar);
        }
예제 #2
0
 public BarMultiButton(BarData bar) : base(bar)
 {
 }
예제 #3
0
 public BarItem(BarData bar)
 {
     this.Bar = bar;
 }
예제 #4
0
 public BarButton(BarData bar) : base(bar)
 {
 }