Ejemplo n.º 1
0
        public static bool Populate(DropDownList dropDownList, string stateCode,
                                    string countyCode, string firstEntry, string firstEntryValue,
                                    string selectedValue = null, bool includeCode = false)
        {
            dropDownList.Items.Clear();

            // handle the optional first (default) entry
            if (firstEntry != null)
            {
                if (firstEntryValue == null)
                {
                    firstEntryValue = firstEntry;
                }
                dropDownList.AddItem(firstEntry, firstEntryValue, firstEntryValue == selectedValue);
            }

            if (IsNullOrWhiteSpace(stateCode) || IsNullOrWhiteSpace(countyCode))
            {
                return(false);
            }
            var locals = GetNamesDictionary(stateCode, countyCode);

            if (locals.Count == 0)
            {
                return(false);
            }
            var comparer = new AlphanumericComparer();

            foreach (var local in locals.OrderBy(kvp => kvp.Value, comparer))
            {
                dropDownList.AddItem(local.Value + (includeCode ? $" ({local.Key})" : Empty),
                                     local.Key, local.Key == selectedValue);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public static bool Populate(DropDownList dropDownList, string stateCode,
                                    string countyCode, string firstEntry, string firstEntryValue,
                                    string selectedValue = null)
        {
            dropDownList.Items.Clear();

            // handle the optional first (default) entry
            if (firstEntry != null)
            {
                if (firstEntryValue == null)
                {
                    firstEntryValue = firstEntry;
                }
                dropDownList.AddItem(firstEntry, firstEntryValue,
                                     firstEntryValue == selectedValue);
            }

            if (string.IsNullOrWhiteSpace(stateCode) ||
                string.IsNullOrWhiteSpace(countyCode))
            {
                return(false);
            }
            var locals = GetNamesDictionary(stateCode, countyCode);

            if (locals.Count == 0)
            {
                return(false);
            }
            foreach (var local in locals.OrderBy(kvp => kvp.Value))
            {
                dropDownList.AddItem(local.Value, local.Key, local.Key == selectedValue);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public static void Populate(DropDownList dropDownList, string firstEntry,
                                    string firstEntryValue, string selectedValue = null, bool clear = true)
        {
            if (clear)
            {
                dropDownList.Items.Clear();
            }

            // handle the optional first (default) entry
            if (firstEntry != null)
            {
                if (firstEntryValue == null)
                {
                    firstEntryValue = firstEntry;
                }
                dropDownList.AddItem(firstEntry, firstEntryValue,
                                     firstEntryValue == selectedValue);
            }

            // Add all real states (plus DC)
            foreach (var si in StateList.Where(si => si.IsState))
            {
                dropDownList.AddItem(si.Name, si.StateCode, si.StateCode == selectedValue);
            }
        }
Ejemplo n.º 4
0
        public override PortalControl GetEditControl(object defaultValue)
        {
            if (SettingsObject == null)
            {
                return(null);
            }

            Setting settings = (Setting)SettingsObject;

            DropDownList list         = new DropDownList();
            SearchOption searchOption = settings.IncludeSubDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            list.AddItem("Select", string.Empty);
            foreach (string file in Directory.GetFiles(Context.HttpContext.Server.MapPath(settings.Directory), settings.SearchPattern ?? "*.*", searchOption))
            {
                list.AddItem(Path.GetFileName(file), file);
            }

            if (defaultValue != null)
            {
                ListItem item = list.Items.FindByValue(defaultValue.ToString());
                if (item != null)
                {
                    item.Selected = true;
                }
            }

            return(list);
        }
Ejemplo n.º 5
0
        private FlowLayoutWidget GetModeControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Margin  = new BorderDouble(top: 4);

            TextWidget settingsLabel = new TextWidget("Interface Mode".Localize());

            settingsLabel.AutoExpandBoundsToText = true;
            settingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            settingsLabel.VAnchor   = VAnchor.ParentTop;

            FlowLayoutWidget optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            optionsContainer.Margin = new BorderDouble(bottom: 6);

            DropDownList interfaceModeDropList = new DropDownList("Standard", maxHeight: 200);

            interfaceModeDropList.HAnchor = HAnchor.ParentLeftRight;

            optionsContainer.AddChild(interfaceModeDropList);
            optionsContainer.Width = 200;

            MenuItem standardModeDropDownItem = interfaceModeDropList.AddItem("Standard".Localize(), "True");
            MenuItem advancedModeDropDownItem = interfaceModeDropList.AddItem("Advanced".Localize(), "False");

            interfaceModeDropList.SelectedValue     = UserSettings.Instance.Fields.IsSimpleMode.ToString();
            interfaceModeDropList.SelectionChanged += new EventHandler(InterfaceModeDropList_SelectionChanged);

            buttonRow.AddChild(settingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(optionsContainer);
            return(buttonRow);
        }
Ejemplo n.º 6
0
        public static void Populate(DropDownList dropDownList, string stateCode, string firstEntry, string firstEntryValue, string selectedValue = null)
        {
            dropDownList.Items.Clear();

            // handle the optional first (default) entry
            if (firstEntry != null)
            {
                if (firstEntryValue == null)
                {
                    firstEntryValue = firstEntry;
                }
                dropDownList.AddItem(firstEntry, firstEntryValue,
                                     firstEntryValue == selectedValue);
            }

            if (IsNullOrWhiteSpace(stateCode))
            {
                return;
            }
            var counties = GetCountiesByState(stateCode);

            if (counties.Count == 0)
            {
                return;
            }
            foreach (var countyCode in counties)
            {
                dropDownList.AddItem(GetCountyName(stateCode, countyCode), countyCode,
                                     countyCode == selectedValue);
            }
        }
Ejemplo n.º 7
0
        private FlowLayoutWidget GetUpdateControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Margin  = new BorderDouble(top: 4);

            configureUpdateFeedButton         = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
            configureUpdateFeedButton.Margin  = new BorderDouble(left: 6);
            configureUpdateFeedButton.VAnchor = VAnchor.ParentCenter;

            TextWidget settingsLabel = new TextWidget("Update Notification Feed".Localize());

            settingsLabel.AutoExpandBoundsToText = true;
            settingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            settingsLabel.VAnchor   = VAnchor.ParentTop;

            FlowLayoutWidget optionsContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);

            optionsContainer.Margin = new BorderDouble(bottom: 6);

            releaseOptionsDropList         = new DropDownList("Development", maxHeight: 200);
            releaseOptionsDropList.HAnchor = HAnchor.ParentLeftRight;

            optionsContainer.AddChild(releaseOptionsDropList);
            optionsContainer.Width = 200;

            MenuItem releaseOptionsDropDownItem = releaseOptionsDropList.AddItem("Stable".Localize(), "release");

            releaseOptionsDropDownItem.Selected += new EventHandler(FixTabDot);

            MenuItem preReleaseDropDownItem = releaseOptionsDropList.AddItem("Beta".Localize(), "pre-release");

            preReleaseDropDownItem.Selected += new EventHandler(FixTabDot);

            MenuItem developmentDropDownItem = releaseOptionsDropList.AddItem("Alpha".Localize(), "development");

            developmentDropDownItem.Selected += new EventHandler(FixTabDot);

            List <string> acceptableUpdateFeedTypeValues = new List <string>()
            {
                "release", "pre-release", "development"
            };
            string currentUpdateFeedType = UserSettings.Instance.get(UserSettingsKey.UpdateFeedType);

            if (acceptableUpdateFeedTypeValues.IndexOf(currentUpdateFeedType) == -1)
            {
                UserSettings.Instance.set(UserSettingsKey.UpdateFeedType, "release");
            }

            releaseOptionsDropList.SelectedValue     = UserSettings.Instance.get(UserSettingsKey.UpdateFeedType);
            releaseOptionsDropList.SelectionChanged += new EventHandler(ReleaseOptionsDropList_SelectionChanged);

            buttonRow.AddChild(settingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(optionsContainer);
            return(buttonRow);
        }
Ejemplo n.º 8
0
        public void AddReleaseOptions(FlowLayoutWidget controlsTopToBottom)
        {
            AltGroupBox releaseOptionsGroupBox = new AltGroupBox(LocalizedString.Get("Update Feed"));

            releaseOptionsGroupBox.Margin      = new BorderDouble(0);
            releaseOptionsGroupBox.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            releaseOptionsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            releaseOptionsGroupBox.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            releaseOptionsGroupBox.VAnchor     = Agg.UI.VAnchor.ParentTop;
            releaseOptionsGroupBox.Height      = 68;

            FlowLayoutWidget controlsContainer = new FlowLayoutWidget();

            controlsContainer.HAnchor |= HAnchor.ParentCenter;

            var releaseOptionsDropList = new DropDownList("Development");

            releaseOptionsDropList.Margin = new BorderDouble(0, 3);

            MenuItem releaseOptionsDropDownItem = releaseOptionsDropList.AddItem("Release", "release");

            releaseOptionsDropDownItem.Selected += new EventHandler(FixTabDot);

            MenuItem preReleaseDropDownItem = releaseOptionsDropList.AddItem("Pre-Release", "pre-release");

            preReleaseDropDownItem.Selected += new EventHandler(FixTabDot);

            MenuItem developmentDropDownItem = releaseOptionsDropList.AddItem("Development", "development");

            developmentDropDownItem.Selected += new EventHandler(FixTabDot);

            releaseOptionsDropList.MinimumSize = new Vector2(releaseOptionsDropList.LocalBounds.Width, releaseOptionsDropList.LocalBounds.Height);

            List <string> acceptableUpdateFeedTypeValues = new List <string>()
            {
                "release", "pre-release", "development"
            };
            string currentUpdateFeedType = UserSettings.Instance.get("UpdateFeedType");

            if (acceptableUpdateFeedTypeValues.IndexOf(currentUpdateFeedType) == -1)
            {
                UserSettings.Instance.set("UpdateFeedType", "release");
            }

            releaseOptionsDropList.SelectedValue = UserSettings.Instance.get("UpdateFeedType");

            releaseOptionsDropList.SelectionChanged += new EventHandler(ReleaseOptionsDropList_SelectionChanged);

            controlsContainer.AddChild(releaseOptionsDropList);
            releaseOptionsGroupBox.AddChild(controlsContainer);
            controlsTopToBottom.AddChild(releaseOptionsGroupBox);
        }
Ejemplo n.º 9
0
 public static void PopulateMajorParties(DropDownList dropDownList,
                                         string stateCode, bool includeSpecial = true, string selectedValue = null)
 {
     dropDownList.Items.Clear();
     dropDownList.AddItem("--- Select a party ---", " ");
     foreach (var kvp in GetMajorParties(stateCode, includeSpecial))
     {
         dropDownList.AddItem(kvp.Value, kvp.Key, kvp.Key == selectedValue);
     }
     if (stateCode == "US")
     {
         dropDownList.AddItem("All (use for final presidential comparison)", "A",
                              "A" == selectedValue);
     }
 }
Ejemplo n.º 10
0
        public override void Initialize(int tabIndex)
        {
            var theme = ApplicationController.Instance.Theme;

            dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
            {
                BorderColor = theme.GetBorderColor(75)
            };

            dropDownList.AddItem(
                "Back".Localize(),
                JsonConvert.SerializeObject(
                    new DirectionVector()
            {
                Normal = Vector3.UnitY
            }));

            dropDownList.AddItem(
                "Up".Localize(),
                JsonConvert.SerializeObject(
                    new DirectionVector()
            {
                Normal = Vector3.UnitZ
            }));

            dropDownList.AddItem(
                "Right".Localize(),
                JsonConvert.SerializeObject(
                    new DirectionVector()
            {
                Normal = Vector3.UnitX
            }));

            dropDownList.SelectedLabel = "Right";

            dropDownList.SelectionChanged += (s, e) =>
            {
                if (this.Value != dropDownList.SelectedValue)
                {
                    this.SetValue(
                        dropDownList.SelectedValue,
                        userInitiated: true);
                }
                ;
            };

            this.Content = dropDownList;
        }
Ejemplo n.º 11
0
 public void AddDropDownList()
 {
     if (!string.IsNullOrWhiteSpace(input.text))
     {
         dropDownList.AddItem(input.text);
     }
 }
Ejemplo n.º 12
0
        public override void Initialize(int tabIndex)
        {
            // Enum keyed on name to friendly name
            var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
            {
                return(new
                {
                    Key = enumName,
                    Value = enumName.Replace('_', ' ')
                });
            });

            dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
            {
                BorderColor = theme.GetBorderColor(75)
            };

            var sortableAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType <SortableAttribute>().FirstOrDefault();
            var orderedItems      = sortableAttribute != null?enumItems.OrderBy(n => n.Value) : enumItems;

            foreach (var orderItem in orderedItems)
            {
                MenuItem newItem = dropDownList.AddItem(orderItem.Value, orderItem.Key);

                var localOrderedItem = orderItem;
                newItem.Selected += (sender, e) =>
                {
                    this.SetValue(localOrderedItem.Key, true);
                };
            }

            dropDownList.SelectedLabel = property.Value.ToString().Replace('_', ' ');

            this.Content = dropDownList;
        }
Ejemplo n.º 13
0
        public override void Initialize(int tabIndex)
        {
            var theme = ApplicationController.Instance.Theme;

            dropdownList = new DropDownList("None".Localize(), theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize)
            {
                ToolTipText = this.HelpText,
                TabIndex    = tabIndex,
                Margin      = new BorderDouble(),
                BorderColor = theme.GetBorderColor(75)
            };

            foreach (string listItem in this.ListItems)
            {
                MenuItem newItem = dropdownList.AddItem(listItem);
                if (newItem.Text == this.Value)
                {
                    dropdownList.SelectedLabel = this.Value;
                }

                newItem.Selected += (sender, e) =>
                {
                    if (sender is MenuItem menuItem)
                    {
                        this.SetValue(
                            menuItem.Text,
                            userInitiated: true);
                    }
                };
            }

            this.Content = dropdownList;
        }
Ejemplo n.º 14
0
        public override void Initialize(int tabIndex)
        {
            dropdownList = new MHDropDownList("None".Localize(), theme, maxHeight: 200)
            {
                ToolTipText = this.HelpText,
                TabIndex    = tabIndex,
                Margin      = new BorderDouble(),
            };

            foreach (string listItem in this.ListItems)
            {
                MenuItem newItem = dropdownList.AddItem(listItem);
                if (newItem.Text == this.Value)
                {
                    dropdownList.SelectedLabel = this.Value;
                }

                newItem.Selected += (sender, e) =>
                {
                    if (sender is MenuItem menuItem)
                    {
                        this.SetValue(
                            menuItem.Text,
                            userInitiated: true);
                    }
                };
            }

            this.Content = dropdownList;
        }
Ejemplo n.º 15
0
        private void RebuildMenuItems()
        {
            dropdownList.MenuItems.Clear();

            foreach (var sliceEngine in PrinterSettings.SliceEngines)
            {
                // Add each serial port to the dropdown list
                MenuItem newItem = dropdownList.AddItem(sliceEngine.Key);

                // When the given menu item is selected, save its value back into settings
                newItem.Selected += (sender, e) =>
                {
                    if (sender is MenuItem menuItem)
                    {
                        if (PrinterSettings.SliceEngines.TryGetValue(menuItem.Text, out IObjectSlicer slicer))
                        {
                            printer.Settings.Slicer = slicer;
                        }

                        this.SetValue(
                            menuItem.Text,
                            userInitiated: true);
                    }
                };
            }

            // Set control text
            dropdownList.SelectedLabel = this.Value;
        }
Ejemplo n.º 16
0
        public override void Initialize(int tabIndex)
        {
            EventHandler unregisterEvents = null;

            var theme = ApplicationController.Instance.Theme;

            base.Initialize(tabIndex);
            bool canChangeComPort = !printer.Connection.IsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
            //This setting defaults to Manual
            var selectedMachine = printer.Settings.GetValue(SettingsKey.selector_ip_address);

            dropdownList = new DropDownList(selectedMachine, theme.Colors.PrimaryTextColor, maxHeight: 200, pointSize: theme.DefaultFontSize)
            {
                ToolTipText = HelpText,
                Margin      = new BorderDouble(),
                TabIndex    = tabIndex,

                Enabled     = canChangeComPort,
                TextColor   = canChangeComPort ? theme.Colors.PrimaryTextColor : new Color(theme.Colors.PrimaryTextColor, 150),
                BorderColor = theme.GetBorderColor(75)
            };

            //Create default option
            MenuItem defaultOption = dropdownList.AddItem("Manual", "127.0.0.1:23");

            defaultOption.Selected += (sender, e) =>
            {
                printer.Settings.SetValue(SettingsKey.selector_ip_address, defaultOption.Text);
            };
            UiThread.RunOnIdle(RebuildMenuItems);

            // Prevent droplist interaction when connected
            printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
            {
                canChangeComPort         = !printer.Connection.IsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
                dropdownList.Enabled     = canChangeComPort;
                dropdownList.TextColor   = canChangeComPort ? theme.Colors.PrimaryTextColor : new Color(theme.Colors.PrimaryTextColor, 150);
                dropdownList.BorderColor = canChangeComPort ? theme.Colors.SecondaryTextColor : new Color(theme.Colors.SecondaryTextColor, 150);
            }, ref unregisterEvents);

            // Release event listener on close
            dropdownList.Closed += (s, e) =>
            {
                unregisterEvents?.Invoke(null, null);
            };

            var widget = new FlowLayoutWidget();

            widget.AddChild(dropdownList);
            refreshButton = new IconButton(AggContext.StaticData.LoadIcon("fa-refresh_14.png", theme.InvertIcons), ApplicationController.Instance.Theme)
            {
                Margin = new BorderDouble(left: 5)
            };

            refreshButton.Click += (s, e) => RebuildMenuItems();
            widget.AddChild(refreshButton);

            this.Content = widget;
        }
Ejemplo n.º 17
0
        //public static bool IsDisplayablePartyCode(string partyCode)
        //{
        //  return partyCode != "X";
        //}

        public static void PopulateNationalParties(DropDownList dropDownList,
                                                   bool includeSpecial = true, string selectedValue = null, bool excludeAll = false,
                                                   string firstItem    = "--- Select a party ---")
        {
            dropDownList.Items.Clear();
            if (!string.IsNullOrWhiteSpace(firstItem))
            {
                dropDownList.AddItem(firstItem, " ");
            }
            foreach (var kvp in GetNationalParties(includeSpecial))
            {
                if (!excludeAll || (kvp.Key != NationalPartyAll))
                {
                    dropDownList.AddItem(kvp.Value, kvp.Key, kvp.Key == selectedValue);
                }
            }
        }
Ejemplo n.º 18
0
 public static void PopulateFromList(DropDownList dropDownList,
                                     IEnumerable <SimpleListItem> list, string valueToSelect = null)
 {
     dropDownList.Items.Clear();
     foreach (var item in list)
     {
         dropDownList.AddItem(item.Text, item.Value, item.Value == valueToSelect);
     }
 }
Ejemplo n.º 19
0
        public static void PopulateElectionTypes(DropDownList dropDownList,
                                                 string stateCode, string selectedValue = null)
        {
            dropDownList.Items.Clear();

            foreach (var kvp in GetElectionTypes(stateCode))
            {
                dropDownList.AddItem(kvp.Value, kvp.Key, kvp.Key == selectedValue);
            }
        }
Ejemplo n.º 20
0
        public override void Initialize(int tabIndex)
        {
            dropDownList = new MHDropDownList("Name".Localize(), theme);

            dropDownList.AddItem(
                "Back".Localize(),
                JsonConvert.SerializeObject(
                    new DirectionVector()
            {
                Normal = Vector3.UnitY
            }));

            dropDownList.AddItem(
                "Up".Localize(),
                JsonConvert.SerializeObject(
                    new DirectionVector()
            {
                Normal = Vector3.UnitZ
            }));

            dropDownList.AddItem(
                "Right".Localize(),
                JsonConvert.SerializeObject(
                    new DirectionVector()
            {
                Normal = Vector3.UnitX
            }));

            dropDownList.SelectedLabel = "Right";

            dropDownList.SelectionChanged += (s, e) =>
            {
                if (this.Value != dropDownList.SelectedValue)
                {
                    this.SetValue(
                        dropDownList.SelectedValue,
                        userInitiated: true);
                }
                ;
            };

            this.Content = dropDownList;
        }
Ejemplo n.º 21
0
        public void AddItemTest()
        {
            Vector2      position = new Vector2();                    // TODO: Initialize to an appropriate value
            SpriteFont   font     = null;                             // TODO: Initialize to an appropriate value
            DropDownList target   = new DropDownList(position, font); // TODO: Initialize to an appropriate value
            DropDownItem item     = null;                             // TODO: Initialize to an appropriate value

            target.AddItem(item);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
Ejemplo n.º 22
0
        private async void RebuildMenuItems()
        {
            refreshButton.Enabled = false;
            IReadOnlyList <Zeroconf.IZeroconfHost> possibleHosts = await ProbeForNetworkedTelenetConnections();

            dropdownList.MenuItems.Clear();

            MenuItem defaultOption = dropdownList.AddItem("Manual", "127.0.0.1:23");

            defaultOption.Selected += (sender, e) =>
            {
                printer.Settings.SetValue(SettingsKey.selector_ip_address, defaultOption.Text);
            };

            foreach (Zeroconf.IZeroconfHost host in possibleHosts)
            {
                // Add each found telnet host to the dropdown list
                IService service;
                bool     exists  = host.Services.TryGetValue("_telnet._tcp.local.", out service);
                int      port    = exists ? service.Port : 23;
                MenuItem newItem = dropdownList.AddItem(host.DisplayName, $"{host.IPAddress}:{port}");                 // The port may be unnecessary
                // When the given menu item is selected, save its value back into settings
                newItem.Selected += (sender, e) =>
                {
                    if (sender is MenuItem menuItem)
                    {
                        // this.SetValue(
                        // menuItem.Text,
                        // userInitiated: true);
                        string[] ipAndPort = menuItem.Value.Split(':');
                        printer.Settings.SetValue(SettingsKey.ip_address, ipAndPort[0]);
                        printer.Settings.SetValue(SettingsKey.ip_port, ipAndPort[1]);
                        printer.Settings.SetValue(SettingsKey.selector_ip_address, menuItem.Text);
                    }
                };
            }

            refreshButton.Enabled = true;
        }
Ejemplo n.º 23
0
        public override void Initialize(int tabIndex)
        {
            base.Initialize(tabIndex);
            bool canChangeComPort = !printer.Connection.IsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
            //This setting defaults to Manual
            var selectedMachine = printer.Settings.GetValue(SettingsKey.selector_ip_address);

            dropdownList = new MHDropDownList(selectedMachine, theme, maxHeight: 200 * GuiWidget.DeviceScale)
            {
                ToolTipText = HelpText,
                Margin      = new BorderDouble(),
                TabIndex    = tabIndex,

                Enabled   = canChangeComPort,
                TextColor = canChangeComPort ? theme.TextColor : new Color(theme.TextColor, 150),
            };

            // Create default option
            MenuItem defaultOption = dropdownList.AddItem("Manual", "127.0.0.1:23");

            defaultOption.Selected += (sender, e) =>
            {
                printer.Settings.SetValue(SettingsKey.selector_ip_address, defaultOption.Text);
            };

            // Prevent droplist interaction when connected
            void CommunicationStateChanged(object s, EventArgs e)
            {
                canChangeComPort       = !printer.Connection.IsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
                dropdownList.TextColor = theme.TextColor;
                dropdownList.Enabled   = canChangeComPort;
            }

            printer.Connection.CommunicationStateChanged += CommunicationStateChanged;
            dropdownList.Closed += (s, e) => printer.Connection.CommunicationStateChanged -= CommunicationStateChanged;

            var widget = new FlowLayoutWidget();

            widget.AddChild(dropdownList);
            refreshButton = new IconButton(StaticData.Instance.LoadIcon("fa-refresh_14.png", 14, 14).SetToColor(theme.TextColor), theme)
            {
                Margin = new BorderDouble(left: 5)
            };

            refreshButton.Click += (s, e) => RebuildMenuItems();
            widget.AddChild(refreshButton);

            this.Content = widget;

            UiThread.RunOnIdle(RebuildMenuItems);
        }
Ejemplo n.º 24
0
        public SliceSettingsDetailControl(List <PrinterSettingsLayer> layerCascade)
        {
            primarySettingsView         = layerCascade == null;
            settingsDetailSelector      = new DropDownList("Basic", maxHeight: 200);
            settingsDetailSelector.Name = "User Level Dropdown";
            settingsDetailSelector.AddItem("Basic".Localize(), "Simple");
            settingsDetailSelector.AddItem("Standard".Localize(), "Intermediate");
            settingsDetailSelector.AddItem("Advanced".Localize(), "Advanced");

            if (primarySettingsView)
            {
                // set to the user requested value when in default view
                if (UserSettings.Instance.get(SliceSettingsLevelEntry) != null &&
                    SliceSettingsOrganizer.Instance.UserLevels.ContainsKey(UserSettings.Instance.get(SliceSettingsLevelEntry)))
                {
                    settingsDetailSelector.SelectedValue = UserSettings.Instance.get(SliceSettingsLevelEntry);
                }
            }
            else             // in settings editor view
            {
                // set to advanced
                settingsDetailSelector.SelectedValue = "Advanced";
            }

            settingsDetailSelector.SelectionChanged += (s, e) => RebuildSlicerSettings(null, null);
            settingsDetailSelector.VAnchor           = VAnchor.ParentCenter;
            settingsDetailSelector.Margin            = new BorderDouble(5, 3);
            settingsDetailSelector.BorderColor       = new RGBA_Bytes(ActiveTheme.Instance.SecondaryTextColor, 100);

            if (primarySettingsView)
            {
                // only add these in the default view
                this.AddChild(settingsDetailSelector);
                this.AddChild(GetSliceOptionsMenuDropList());
            }

            VAnchor = VAnchor.ParentCenter;
        }
        public SliceSettingsDetailControl()
        {
            showHelpBox         = new CheckBox(0, 0, "Show Help".Localize(), textSize: 10);
            showHelpBox.Checked = UserSettings.Instance.get(SliceSettingsShowHelpEntry) == "true";
            // add in the ability to turn on and off help text
            showHelpBox.TextColor            = ActiveTheme.Instance.PrimaryTextColor;
            showHelpBox.Margin               = new BorderDouble(right: 3);
            showHelpBox.VAnchor              = VAnchor.ParentCenter;
            showHelpBox.Cursor               = Cursors.Hand;
            showHelpBox.CheckedStateChanged += (s, e) =>
            {
                UserSettings.Instance.set(SliceSettingsShowHelpEntry, showHelpBox.Checked.ToString().ToLower());
                ShowHelpChanged?.Invoke(this, null);
            };

            this.AddChild(showHelpBox);

            settingsDetailSelector      = new DropDownList("Basic", maxHeight: 200);
            settingsDetailSelector.Name = "User Level Dropdown";
            settingsDetailSelector.AddItem("Basic".Localize(), "Simple");
            settingsDetailSelector.AddItem("Standard".Localize(), "Intermediate");
            settingsDetailSelector.AddItem("Advanced".Localize(), "Advanced");
            if (UserSettings.Instance.get(SliceSettingsLevelEntry) != null &&
                SliceSettingsOrganizer.Instance.UserLevels.ContainsKey(UserSettings.Instance.get(SliceSettingsLevelEntry)))
            {
                settingsDetailSelector.SelectedValue = UserSettings.Instance.get(SliceSettingsLevelEntry);
            }

            settingsDetailSelector.SelectionChanged += (s, e) => RebuildSlicerSettings(null, null);;
            settingsDetailSelector.VAnchor           = VAnchor.ParentCenter;
            settingsDetailSelector.Margin            = new BorderDouble(5, 3);
            settingsDetailSelector.BorderColor       = new RGBA_Bytes(ActiveTheme.Instance.SecondaryTextColor, 100);

            this.AddChild(settingsDetailSelector);
            this.AddChild(GetSliceOptionsMenuDropList());
        }
Ejemplo n.º 26
0
        public override void Initialize(int tabIndex)
        {
            // Enum keyed on name to friendly name
            var enumItems = Enum.GetNames(property.PropertyType).Select(enumName =>
            {
                var renamedName = enumName;

                var renameAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType <EnumRenameAttribute>().FirstOrDefault();
                if (renameAttribute != null)
                {
                    if (renameAttribute.NameMaping.TryGetValue(renamedName, out string value))
                    {
                        renamedName = value;
                    }
                }

                return(new
                {
                    Key = enumName,
                    Value = renamedName.Replace('_', ' ')
                });
            });

            dropDownList = new MHDropDownList("Name".Localize(), theme)
            {
                Name = property.DisplayName + " DropDownList"
            };

            var sortableAttribute = property.PropertyInfo.GetCustomAttributes(true).OfType <SortableAttribute>().FirstOrDefault();
            var orderedItems      = sortableAttribute != null?enumItems.OrderBy(n => n.Value) : enumItems;

            foreach (var orderItem in orderedItems)
            {
                Enum.TryParse <NamedTypeFace>(orderItem.Key, out NamedTypeFace namedTypeFace);
                var      typeFace = ApplicationController.GetTypeFace(namedTypeFace);
                MenuItem newItem  = dropDownList.AddItem(orderItem.Value, orderItem.Key, typeFace);

                var localOrderedItem = orderItem;
                newItem.Selected += (sender, e) =>
                {
                    this.SetValue(localOrderedItem.Key, true);
                };
            }

            dropDownList.SelectedLabel = property.Value.ToString().Replace('_', ' ');

            this.Content = dropDownList;
        }
Ejemplo n.º 27
0
        public GridOptionsPanel(InteractionLayer interactionLayer) : base(FlowDirection.TopToBottom)
        {
            var theme = ApplicationController.Instance.Theme;

            this.HAnchor = HAnchor.MaxFitOrStretch;

            this.AddChild(new TextWidget("Snap Grid".Localize())
            {
                Margin    = new BorderDouble(35, 2, 8, 8),
                TextColor = Color.Gray,
                HAnchor   = HAnchor.Left
            });

            var snapSettings = new Dictionary <double, string>()
            {
                { 0, "Off" },
                { .1, "0.1" },
                { .25, "0.25" },
                { .5, "0.5" },
                { 1, "1" },
                { 2, "2" },
                { 5, "5" },
            };

            var dropDownList = new DropDownList("Custom", theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
            {
                TextColor   = Color.Black,
                Margin      = new BorderDouble(35, 15, 35, 5),
                HAnchor     = HAnchor.Left,
                BorderColor = theme.GetBorderColor(75)
            };

            foreach (var snapSetting in snapSettings)
            {
                MenuItem newItem = dropDownList.AddItem(snapSetting.Value);
                if (interactionLayer.SnapGridDistance == snapSetting.Key)
                {
                    dropDownList.SelectedLabel = snapSetting.Value;
                }

                newItem.Selected += (sender, e) =>
                {
                    interactionLayer.SnapGridDistance = snapSetting.Key;
                };
            }
            this.AddChild(dropDownList);
        }
        public override void Initialize(int tabIndex)
        {
            // Enum keyed on name to friendly name
            List <(string key, string value)> names = null;
            string selectedID = "";

            var value = property.PropertyInfo.GetGetMethod().Invoke(property.Source, null);

            if (property.Source is Object3D item)
            {
                names = item.Children
                        .Where(c => c.GetType() != typeof(OperationSourceObject3D))
                        .Select(child => (child.ID, child.Name)).ToList();
                if (value is SelectedChildren selectedChildren &&
                    selectedChildren.Count == 1)
                {
                    selectedID = selectedChildren.First();
                }
            }

            dropDownList = new MHDropDownList("Name".Localize(), theme);

            var orderedItems = names.OrderBy(n => n.value);

            foreach (var orderItem in orderedItems)
            {
                MenuItem newItem = dropDownList.AddItem(orderItem.value, orderItem.key);

                var localOrderedItem = orderItem;
                newItem.Selected += (sender, e) =>
                {
                    this.SetValue(localOrderedItem.key, true);
                };
            }

            if (!string.IsNullOrWhiteSpace(selectedID))
            {
                dropDownList.SelectedValue = selectedID;
            }
            else if (dropDownList.MenuItems.Count > 0)
            {
                dropDownList.SelectedIndex = 0;
            }

            this.Content = dropDownList;
        }
Ejemplo n.º 29
0
                protected PlayerItem(Screen screen, PlayerInsignia insignia, int initialTeamID, PlayerTypeCategory playerTypeCategory)
                {
                    this.Insignia = insignia;

                    elementToTypeMap = new Dictionary <UIElement, PlayerType>();
                    elementToTeamMap = new Dictionary <UIElement, int>();

                    var child =
                        screen.Game.UI.LoadLayout(screen.Game.PackageManager.GetXmlFile("UI/PlayerItemLayout.xml", true));

                    AddChild(child);

                    BorderImage playerShield = (BorderImage)child.GetChild("PlayerShield", true);

                    playerTypeList = (DropDownList)child.GetChild("PlayerTypeList", true);
                    teamList       = (DropDownList)child.GetChild("TeamList", true);

                    playerShield.Texture   = insignia.ShieldTexture;
                    playerShield.ImageRect = insignia.ShieldRectangle;

                    foreach (var player in screen.Level.GamePack.GetPlayersWithTypeCategory(playerTypeCategory))
                    {
                        var item = InitTypeItem(player, screen.Game, screen.MenuUIManager);
                        playerTypeList.AddItem(item);
                        elementToTypeMap.Add(item, player);
                    }

                    if (playerTypeCategory != PlayerTypeCategory.Neutral)
                    {
                        for (int teamID = 1; teamID <= screen.Level.MaxNumberOfPlayers; teamID++)
                        {
                            UIElement item = InitTeamItem(teamID, screen.Game, screen.MenuUIManager);
                            teamList.AddItem(item);
                            elementToTeamMap.Add(item, teamID);

                            if (teamID == initialTeamID)
                            {
                                teamList.Selection = teamList.NumItems - 1;
                            }
                        }
                    }
                    else
                    {
                        teamList.Visible = false;
                    }
                }
        public override void Initialize(int tabIndex)
        {
            // Enum keyed on name to friendly name
            List <(string key, string value)> names = null;
            var selectedName = "";

            if (property.source is AlignObject3D item)
            {
                names = item.Children.Select(child => (child.ID, child.Name)).ToList();
                if (item.AnchorObjectSelector.Count == 1)
                {
                    var selectedKey = item.AnchorObjectSelector[0];
                    foreach (var name in names)
                    {
                        if (name.key == selectedKey)
                        {
                            selectedName = name.value;
                        }
                    }
                }
            }

            dropDownList = new DropDownList("Name".Localize(), theme.Colors.PrimaryTextColor, Direction.Down, pointSize: theme.DefaultFontSize)
            {
                BorderColor = theme.GetBorderColor(75)
            };

            var orderedItems = names.OrderBy(n => n.value);

            foreach (var orderItem in orderedItems)
            {
                MenuItem newItem = dropDownList.AddItem(orderItem.value, orderItem.key);

                var localOrderedItem = orderItem;
                newItem.Selected += (sender, e) =>
                {
                    this.SetValue(localOrderedItem.key, true);
                };
            }

            dropDownList.SelectedLabel = selectedName;

            this.Content = dropDownList;
        }