Beispiel #1
0
 private static void Display(string caption, List<SimpleMenuItem> menuItems)
 {
     var menu = new JetPopupMenu();
     menu.Caption.Value = WindowlessControl.Create(caption);
     menu.SetItems(menuItems.ToArray());
     menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);
     menu.Show();
 }
        /// <summary>Shows the popup menu.</summary>
        /// <param name="element">The element.</param>
        /// <param name="rule">The rule.</param>
        /// <param name="name">The name.</param>
        private void ShowPopupMenu(IElement element, Rule rule, string name)
        {
            var menu = new JetPopupMenu();

              var assertions = new List<SimpleMenuItem>(rule.ValueAssertions.Count);

              foreach (var valueAssertion in rule.ValueAssertions)
              {
            var item = new SimpleMenuItem
            {
              Text = string.Format(valueAssertion, name),
              Style = MenuItemStyle.Enabled
            };

            item.Clicked += delegate { this.InsertAssertion(item.Text, element); };

            assertions.Add(item);
              }

              menu.Caption.Value = WindowlessControl.Create("Assert Assignment");
              menu.SetItems(assertions.ToArray());
              menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);

              menu.Show();
        }
        /// <summary>
        /// Handles the OnClicked event of the CreateLiveTemplates control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        private void CreateLiveTemplates_OnClicked(object sender, EventArgs e)
        {
            var simpleMenuItem = sender as SimpleMenuItem;
              if (simpleMenuItem == null)
              {
            return;
              }

              var liveTemplates = simpleMenuItem.Tag as List<LiveTemplateItem>;
              if (liveTemplates == null)
              {
            return;
              }

              var items = new List<SimpleMenuItem>();

              foreach (var template in liveTemplates)
              {
            var item = new SimpleMenuItem
            {
              Style = MenuItemStyle.Enabled,
              Text = template.MenuText ?? string.Empty,
              Tag = template
            };

            item.Clicked += LiveTemplateManager.AddLiveTemplate;

            items.Add(item);
              }

              var menu = new JetPopupMenu();

              var popupWindowContext = this.dataContext.GetData(DataConstants.POPUP_WINDOW_CONTEXT);
              if (popupWindowContext != null)
              {
            menu.Layouter = popupWindowContext.CreateLayouter();
              }

              menu.Caption.Value = WindowlessControl.Create("Create live template");
              menu.SetItems(items.ToArray());
              menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);

              menu.Show();
        }
        /// <summary>
        /// Shows the popup menu.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="items">
        /// The items.
        /// </param>
        private static void ShowPopupMenu(IDataContext context, List<SimpleMenuItem> items)
        {
            var menu = new JetPopupMenu();

              var popupWindowContext = context.GetData(DataConstants.POPUP_WINDOW_CONTEXT);
              if (popupWindowContext != null)
              {
            menu.Layouter = popupWindowContext.CreateLayouter();
              }

              menu.Caption.Value = WindowlessControl.Create("Smart Generate [Agent Johnson]");
              menu.SetItems(items.ToArray());
              menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);

              var right = ImageLoader.GetImage("AgentJohnson.Resources.LeftArrow.png", Assembly.GetExecutingAssembly());
              var left = ImageLoader.GetImage("AgentJohnson.Resources.RightArrow.png", Assembly.GetExecutingAssembly());

              menu.ToolbarButtons.Add(
            new ToolbarItemInfo(
              new PresentableItem(right),
              "Previous in scope",
              Keys.Left,
              false,
              delegate()
              {
            Shell.Instance.Invocator.ReentrancyGuard.ExecuteOrQueue(
              "SmartGenerate2",
              delegate
            {
              scopeIndex++;
              var action = ActionManager.Instance.TryGetAction("SmartGenerate2") as IExecutableAction;
              if (action != null)
              {
                ActionManager.Instance.ExecuteActionIfAvailable(action);
              }
            });
              }));

              menu.ToolbarButtons.Add(
            new ToolbarItemInfo(
              new PresentableItem(left),
              "Next in scope",
              Keys.None,
              false,
              delegate()
              {
            Shell.Instance.Invocator.ReentrancyGuard.ExecuteOrQueue(
              "SmartGenerate2",
              delegate
              {
                scopeIndex--;
                var action = ActionManager.Instance.TryGetAction("SmartGenerate2") as IExecutableAction;
                if (action != null)
                {
                  ActionManager.Instance.ExecuteActionIfAvailable(action);
                }
              });
              }));

              menu.Show();
        }
        /// <summary>Executes this instance.</summary>
        public void Execute()
        {
            var classNames = IntroduceStringConstantSettings.Instance.ClassNames;
              if (classNames.Count == 0)
              {
            this.IntroduceLocalStringConstant();
            return;
              }

              var menu = new JetPopupMenu();

              var classes = new List<SimpleMenuItem>(classNames.Count + 1);
              foreach (var className in classNames)
              {
            var item = new SimpleMenuItem
            {
              Text = className,
              Style = MenuItemStyle.Enabled
            };

            item.Clicked += delegate { this.MenuItemClicked(item.Text); };

            classes.Add(item);
              }

              var classDeclaration = this.GetClassDeclaration();
              if (classDeclaration != null)
              {
            var item = new SimpleMenuItem
            {
              Text = "<Local>" + GetQualifiedClassDeclarationName(classDeclaration),
              Style = MenuItemStyle.Enabled
            };

            item.Clicked += delegate { this.MenuItemClicked(item.Text); };

            classes.Add(item);
              }

              menu.Caption.Value = WindowlessControl.Create("Introduce String Constant");
              menu.SetItems(classes.ToArray());
              menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);

              menu.Show();
        }
        /// <summary>Executes action. Called after Update, that set <c>ActionPresentation</c>.Enabled to true.</summary>
        /// <param name="solution">The solution.</param>
        /// <param name="context">The context.</param>
        private void Execute(ISolution solution, IDataContext context)
        {
            this.solution = solution;
              this.currentFile = GetCurrentFile(this.solution, context);

              var items = new List<SimpleMenuItem>();

              var files = FavoriteFilesSettings.Instance.FavoriteFiles;

              var index = 0;

              foreach (var favoriteFilePath in files)
              {
            var path = favoriteFilePath;

            if (string.IsNullOrEmpty(favoriteFilePath.ProjectName))
            {
              var item = DescribeFavoriteFile(favoriteFilePath, index);

              item.Clicked += delegate { this.MenuItemClicked(path); };

              items.Add(item);

              index++;

              continue;
            }

            var project = solution.GetProject(favoriteFilePath.ProjectName);

            if (project != null)
            {
              var item = DescribeFavoriteFile(favoriteFilePath, index);

              item.Clicked += delegate { this.MenuItemClicked(path); };

              items.Add(item);

              index++;

              continue;
            }
              }

              if (items.Count > 0)
              {
            items.Add(SimpleMenuItem.CreateSeparator());
              }

              items.Add(this.DescribeAddMenuItem());
              items.Add(this.DescribeOrganizeMenuItem());

              var menu = new JetPopupMenu();

              menu.Caption.Value = WindowlessControl.Create("Favorite Files");
              menu.SetItems(items.ToArray());
              menu.KeyboardAcceleration.SetValue(KeyboardAccelerationFlags.Mnemonics);

              menu.Show();
        }