示例#1
0
文件: TreeView.cs 项目: oqewok/gitter
            public TreeMenu(ITreeSource treeSource, TreeDirectoryListItem item)
            {
                Verify.Argument.IsNotNull(item, "item");

                Items.Add(GuiItemFactory.GetExpandAllItem <ToolStripMenuItem>(item));
                Items.Add(GuiItemFactory.GetCollapseAllItem <ToolStripMenuItem>(item));

                if (treeSource != null)
                {
                    Items.Add(new ToolStripSeparator());
                    Items.Add(GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(treeSource.Revision, item.DataContext));
                    Items.Add(new ToolStripSeparator());
                    Items.Add(GuiItemFactory.GetCheckoutPathItem <ToolStripMenuItem>(treeSource.Revision, item.DataContext));
                }
            }
示例#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),
            }));
        }
示例#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;
                }
            }
        }
示例#4
0
文件: TreeView.cs 项目: oqewok/gitter
        private void OnContextMenuRequested(object sender, ItemContextMenuRequestEventArgs e)
        {
            var vm  = ViewModel as TreeViewModel;
            var rts = vm != null ? vm.TreeSource : null;

            if (rts != null)
            {
                var item = ((ITreeItemListItem)e.Item);
                var file = item.TreeItem as TreeFile;
                if (file != null)
                {
                    var menu = new ContextMenuStrip();
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        GuiItemFactory.GetExtractAndOpenFileItem <ToolStripMenuItem>(DataSource.Data, file.RelativePath),
                        GuiItemFactory.GetExtractAndOpenFileWithItem <ToolStripMenuItem>(DataSource.Data, file.RelativePath),
                        GuiItemFactory.GetSaveAsItem <ToolStripMenuItem>(DataSource.Data, file.RelativePath),
                        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>(rts.Revision, file),
                        GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(rts.Revision, file),
                        new ToolStripSeparator(),
                        GuiItemFactory.GetCheckoutPathItem <ToolStripMenuItem>(rts.Revision, file),
                    });
                    Utility.MarkDropDownForAutoDispose(menu);
                    e.ContextMenu         = menu;
                    e.OverrideDefaultMenu = true;
                    return;
                }
                var directory = item.TreeItem as TreeDirectory;
                if (directory != null)
                {
                    var menu = new ContextMenuStrip();
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        new ToolStripMenuItem(Resources.StrOpen, null, (s, args) => e.Item.Activate()),
                        GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(rts.Revision, directory),
                        new ToolStripSeparator(),
                        GuiItemFactory.GetCheckoutPathItem <ToolStripMenuItem>(rts.Revision, directory),
                    });
                    Utility.MarkDropDownForAutoDispose(menu);
                    e.ContextMenu         = menu;
                    e.OverrideDefaultMenu = true;
                    return;
                }
                var commit = ((ITreeItemListItem)e.Item).TreeItem as TreeCommit;
                if (commit != null)
                {
                    var menu = new ContextMenuStrip();
                    menu.Items.AddRange(
                        new ToolStripItem[]
                    {
                        GuiItemFactory.GetPathHistoryItem <ToolStripMenuItem>(rts.Revision, commit),
                        new ToolStripSeparator(),
                        new ToolStripMenuItem(Resources.StrCopyToClipboard, null,
                                              new ToolStripItem[]
                        {
                            GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrName, commit.Name),
                            GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrRelativePath, commit.RelativePath),
                            GuiItemFactory.GetCopyToClipboardItem <ToolStripMenuItem>(Resources.StrFullPath, commit.FullPath),
                        }),
                        new ToolStripSeparator(),
                        GuiItemFactory.GetCheckoutPathItem <ToolStripMenuItem>(rts.Revision, commit),
                    });
                    Utility.MarkDropDownForAutoDispose(menu);
                    e.ContextMenu         = menu;
                    e.OverrideDefaultMenu = true;
                    return;
                }
            }
        }