Пример #1
0
        /// <summary>
        /// Updates a regular "Plan to X" menu : text, tag, enable/disable.
        /// </summary>
        /// <param name="plan">The plan.</param>
        /// <param name="menu">The menu.</param>
        /// <param name="skill">The skill.</param>
        /// <param name="level">The level.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">menu
        /// or
        /// plan</exception>
        public static bool UpdatesRegularPlanToMenu(this Plan plan, ToolStripItem menu, Skill skill, int level)
        {
            menu.ThrowIfNull(nameof(menu));

            plan.ThrowIfNull(nameof(plan));

            menu.Text = level == 0 ? "Remove" : $"Level {level}";

            menu.Enabled = plan.EnablePlanTo(skill, level);
            if (menu.Enabled)
            {
                IPlanOperation operation = plan.TryPlanTo(skill, level);
                menu.Tag = operation;
                if (RequiresWindow(operation))
                    menu.Text += @"...";
            }

            ToolStripMenuItem menuItem = menu as ToolStripMenuItem;
            if (menuItem != null)
                menuItem.Checked = plan.GetPlannedLevel(skill) == level;

            return menu.Enabled;
        }