コード例 #1
0
        /// <summary>Describes the favorite file.</summary>
        /// <param name="favoriteFilePath">The favorite file path.</param>
        /// <param name="index">The index.</param>
        /// <returns>The favorite file.</returns>
        private static SimpleMenuItem DescribeFavoriteFile(FavoriteFilePath favoriteFilePath, int index)
        {
            var result = new SimpleMenuItem();

              if (favoriteFilePath == null)
              {
            result.Text = "<Error>";
            return result;
              }

              try
              {
            result.Text = Path.GetFileName(favoriteFilePath.Path);
              }
              catch
              {
            result.Text = favoriteFilePath.Path;
              }

              result.Style = MenuItemStyle.Enabled;
              result.ShortcutText = new RichText("(" + favoriteFilePath + ")", TextStyle.FromForeColor(Color.LightGray));

              if (index < 0 || index > 8)
              {
            return result;
              }

              result.Mnemonic = index.ToString();

              return result;
        }
コード例 #2
0
        /// <summary>Opens the favorite file.</summary>
        /// <param name="favoriteFilePath">The favorite file path.</param>
        private void OpenFavoriteFile(FavoriteFilePath favoriteFilePath)
        {
            var path = new FileSystemPath(favoriteFilePath.Path);

              if (string.IsNullOrEmpty(favoriteFilePath.ProjectName))
              {
            _DTE dte = IVsServiceProviderEx.Dte(VSShell.Instance.ServiceProvider);
            dte.ItemOperations.OpenFile(favoriteFilePath.Path, Constants.vsViewKindTextView);
            return;
              }

              if (!string.IsNullOrEmpty(favoriteFilePath.ProjectName))
              {
            var project = this.solution.GetProject(favoriteFilePath.ProjectName);

            if (project == null)
            {
              return;
            }

            var projectPath = project.Location;

            path = projectPath.Combine(path);
              }

              var location = this.solution.FindProjectItemsByLocation(path);
              if (location == null || CollectionUtil.Length(location) == 0)
              {
            return;
              }

              var projectItem = location[0];

              if (projectItem == null)
              {
            System.Windows.Forms.MessageBox.Show("File not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
              }

              if (projectItem.Kind != ProjectItemKind.PHYSICAL_FILE)
              {
            System.Windows.Forms.MessageBox.Show("File not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
              }

              var projectFile = projectItem as IProjectFile;
              if (projectFile == null)
              {
            System.Windows.Forms.MessageBox.Show("File not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
              }

              if (EditorManager.GetInstance(this.solution).OpenProjectFile(projectFile, true) == null)
              {
            System.Windows.Forms.MessageBox.Show("File not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
        }
コード例 #3
0
        /// <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();
        }
コード例 #4
0
 /// <summary>Handles the ItemClicked event of the menu control.</summary>
 /// <param name="path">The path.</param>
 private void MenuItemClicked(FavoriteFilePath path)
 {
     if (path.Path == "__add")
       {
     this.AddCurrentFile();
       }
       else if (path.Path == "__more")
       {
     Organize();
       }
       else
       {
     this.OpenFavoriteFile(path);
       }
 }
コード例 #5
0
        /// <summary>Gets the current file.</summary>
        /// <param name="solution">The solution.</param>
        /// <param name="dataContext">The data context.</param>
        /// <returns>The current file.</returns>
        private static FavoriteFilePath GetCurrentFile(ISolution solution, IDataContext dataContext)
        {
            var document = dataContext.GetData(DataConstants.DOCUMENT);
              if (document == null)
              {
            return null;
              }

              var projectFile = DocumentManager.GetInstance(solution).GetProjectFile(document);
              if (projectFile == null)
              {
            return null;
              }

              var result = new FavoriteFilePath();

              var path = projectFile.Location;

              var project = projectFile.GetProject();

              // miscellaneous files
              if (!project.IsWritable && project.LanguageType == ProjectFileType.UNKNOWN && project.Location.IsEmpty)
              {
            project = null;
              }

              if (project != null)
              {
            result.ProjectName = project.Name;
            path = projectFile.Location.ConvertToRelativePath(project.Location);
              }

              result.Path = path.ToString();

              return result;
        }