Exemplo n.º 1
0
        public UnstagedItemMenu(TreeItem item)
        {
            Verify.Argument.IsValidGitObject(item, nameof(item));
            Verify.Argument.AreEqual(StagedStatus.Unstaged, item.StagedStatus & StagedStatus.Unstaged, "item",
                                     "This item is not unstaged.");

            Item = item;

            var dir = Item as TreeDirectory;

            if (Item.Status != FileStatus.Removed)
            {
                var fullPath = Item.FullPath;
                if (dir == null)
                {
                    Items.Add(GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpen, null, fullPath));
                    Items.Add(GuiItemFactory.GetOpenUrlWithItem <ToolStripMenuItem>(Resources.StrOpenWith.AddEllipsis(), null, fullPath));
                    Items.Add(GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpenContainingFolder, null, Path.GetDirectoryName(fullPath)));
                }
                else
                {
                    Items.Add(GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpenInWindowsExplorer, null, fullPath));
                }
                Items.Add(new ToolStripSeparator());
            }
            Items.Add(GuiItemFactory.GetStageItem <ToolStripMenuItem>(Item));
            if (dir != null)
            {
                if (HasRevertableItems(dir))
                {
                    Items.Add(GuiItemFactory.GetRevertPathItem <ToolStripMenuItem>(Item));
                }
            }
            else
            {
                if (Item.Status == FileStatus.Removed || Item.Status == FileStatus.Modified)
                {
                    Items.Add(GuiItemFactory.GetRevertPathItem <ToolStripMenuItem>(Item));
                }
                if (Item.Status == FileStatus.Modified || Item.Status == FileStatus.Added)
                {
                    Items.Add(GuiItemFactory.GetRemovePathItem <ToolStripMenuItem>(Item));
                }
            }
        }
Exemplo n.º 2
0
        public DiffFileMenu(IDiffSource diffSource, DiffFile diffFile)
        {
            Verify.Argument.IsNotNull(diffSource, "diffSource");
            Verify.Argument.IsNotNull(diffFile, "diffFile");

            _diffSource = diffSource;
            _diffFile   = diffFile;

            string fileName = diffFile.Status != FileStatus.Removed ? diffFile.TargetFile : diffFile.SourceFile;

            var indexDiff = diffSource as IIndexDiffSource;

            if (indexDiff != null)
            {
                var repository = indexDiff.Repository;
                if (diffFile.Status != FileStatus.Removed)
                {
                    try
                    {
                        var fullPath = Path.Combine(diffSource.Repository.WorkingDirectory, diffFile.TargetFile);
                        if (File.Exists(fullPath))
                        {
                            Items.Add(GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(
                                          Resources.StrOpen, null, fullPath));
                            Items.Add(GuiItemFactory.GetOpenUrlWithItem <ToolStripMenuItem>(
                                          Resources.StrOpenWith.AddEllipsis(), null, fullPath));
                            Items.Add(GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(
                                          Resources.StrOpenContainingFolder, null, Path.GetDirectoryName(fullPath)));
                            Items.Add(new ToolStripSeparator());
                        }
                    }
                    catch (Exception exc)
                    {
                        if (exc.IsCritical())
                        {
                            throw;
                        }
                    }
                }
                if (indexDiff.Cached)
                {
                    var item = indexDiff.Repository.Status.TryGetStaged(fileName);
                    if (item != null)
                    {
                        Items.Add(GuiItemFactory.GetUnstageItem <ToolStripMenuItem>(item));
                        Items.Add(new ToolStripSeparator());
                    }
                }
                else
                {
                    var item = indexDiff.Repository.Status.TryGetUnstaged(fileName);
                    if (item != null)
                    {
                        Items.Add(GuiItemFactory.GetStageItem <ToolStripMenuItem>(item));
                        Items.Add(new ToolStripSeparator());
                    }
                }
                if (diffFile.Status != FileStatus.Removed)
                {
                    Items.Add(GuiItemFactory.GetBlameItem <ToolStripMenuItem>(
                                  indexDiff.Repository.Head, fileName));
                }
                Items.Add(GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(
                              indexDiff.Repository.Head, fileName));
            }
            else
            {
                var revisionDiff = diffSource as IRevisionDiffSource;
                if (revisionDiff != null)
                {
                    if (diffFile.Status != FileStatus.Removed)
                    {
                        Items.Add(GuiItemFactory.GetBlameItem <ToolStripMenuItem>(
                                      revisionDiff.Revision, diffFile.TargetFile));
                        Items.Add(GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(
                                      revisionDiff.Revision, diffFile.TargetFile));
                    }
                    else
                    {
                        Items.Add(GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(
                                      revisionDiff.Revision, diffFile.SourceFile));
                    }
                }
            }
            Items.Add(new ToolStripMenuItem(Resources.StrCopyToClipboard, null,
                                            new ToolStripItem[]
            {
                GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrSourceFileName, diffFile.SourceFile),
                GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrDestinationFileName, diffFile.TargetFile),
            }));
        }
Exemplo n.º 3
0
        private void OnItemContextMenuRequested(object sender, ItemContextMenuRequestEventArgs e)
        {
            var item = e.Item as ITreeItemListItem;

            if (item != null)
            {
                var file = item.TreeItem as TreeFile;
                if (file != null)
                {
                    var menu = new ContextMenuStrip();
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpen, null, file.FullPath),
                        GuiItemFactory.GetOpenUrlWithItem <ToolStripMenuItem>(Resources.StrOpenWith.AddEllipsis(), null, file.FullPath),
                        GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpenContainingFolder, null, Path.GetDirectoryName(file.FullPath)),
                        new ToolStripSeparator(),
                        new ToolStripMenuItem(Resources.StrCopyToClipboard, null,
                                              new ToolStripItem[]
                        {
                            GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrFileName, file.Name),
                            GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrRelativePath, file.RelativePath),
                            GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrFullPath, file.FullPath),
                        }),
                        new ToolStripSeparator(),
                        GuiItemFactory.GetBlameItem <ToolStripMenuItem>(Repository.Head, file.RelativePath),
                        GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(Repository.Head, file.RelativePath),
                    });
                    Utility.MarkDropDownForAutoDispose(menu);
                    e.ContextMenu = menu;
                    return;
                }
                var directory = item.TreeItem as TreeDirectory;
                if (directory != null)
                {
                    var menu = new ContextMenuStrip();
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpenInWindowsExplorer, null, directory.FullPath),
                        GuiItemFactory.GetOpenCmdAtItem <ToolStripMenuItem>(Resources.StrOpenCommandLine, null, directory.FullPath),
                    });
                    if (e.Item.Items.Count != 0)
                    {
                        menu.Items.AddRange(
                            new ToolStripItem[]
                        {
                            new ToolStripSeparator(),
                            GuiItemFactory.GetExpandAllItem <ToolStripMenuItem>(e.Item),
                            GuiItemFactory.GetCollapseAllItem <ToolStripMenuItem>(e.Item),
                        });
                    }
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        new ToolStripSeparator(),
                        GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(Repository.Head, directory.RelativePath + "/"),
                    });
                    Utility.MarkDropDownForAutoDispose(menu);
                    e.ContextMenu = menu;
                    return;
                }
                var commit = item.TreeItem as TreeCommit;
                if (commit != null)
                {
                    var menu = new ContextMenuStrip();
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        GuiItemFactory.GetOpenAppItem <ToolStripMenuItem>(
                            Resources.StrOpenWithGitter, null, Application.ExecutablePath, commit.FullPath.SurroundWithDoubleQuotes()),
                        GuiItemFactory.GetOpenUrlItem <ToolStripMenuItem>(Resources.StrOpenInWindowsExplorer, null, commit.FullPath),
                        GuiItemFactory.GetOpenCmdAtItem <ToolStripMenuItem>(Resources.StrOpenCommandLine, null, commit.FullPath),
                        new ToolStripSeparator(),
                        GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(Repository.Head, commit.RelativePath),
                    });
                    Utility.MarkDropDownForAutoDispose(menu);
                    e.ContextMenu = menu;
                    return;
                }
            }
        }