Exemple #1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            AppContext  = new GitApplicationContext();
            SyncContext = new WindowsFormsSynchronizationContext();

            string pathOrCommitish = args.Length > 0 ? args[0] : null;
            string fullPath        = pathOrCommitish == null ? Environment.CurrentDirectory : Path.GetFullPath(pathOrCommitish);

            if (Directory.Exists(fullPath) && !fullPath.EndsWith("\\"))
            {
                fullPath += "\\";
            }

            // Repository.Discover doesn't work with paths that don't exist.
            // Traverse up the tree to find an existing directory.
            string discoverPath = fullPath;

            while (!Directory.Exists(discoverPath))
            {
                discoverPath = Directory.GetParent(discoverPath).FullName;
            }

            string repoRoot = Repository.Discover(discoverPath);

            if (repoRoot == null)
            {
                return;
            }

            using (var repo = new Repository(repoRoot))
            {
                Form form;
                var  commit = TryLookupCommit(repo, fullPath, pathOrCommitish);
                if (commit != null)
                {
                    fullPath = Environment.CurrentDirectory;
                    if (!fullPath.EndsWith("\\"))
                    {
                        fullPath += "\\";
                    }

                    var gitLog = new GitLog(repo, fullPath, Constants.MaxCommits);
                    form = new GitCommitForm(gitLog, commit);
                }
                else
                {
                    form = new GitLogForm(repo, fullPath);
                }

                AppContext.NewForm(form);

                Application.Run(AppContext);
            }
        }
Exemple #2
0
        public GitCommitListViewOwner(GitLog gitLog, Commit commit)
        {
            this.gitLog = gitLog ?? throw new ArgumentNullException(nameof(gitLog));
            this.commit = commit ?? throw new ArgumentNullException(nameof(commit));

            this.baseFileRelPaths    = new List <string>();
            this.nonBaseFileRelPaths = new List <string>();
            this.headerRows          = new List <string>();
            this.baseFileRows        = new List <string>();
            this.nonBaseFileRows     = new List <string>();
        }
Exemple #3
0
        public GitCommitForm(GitLog gitLog, Commit commit)
        {
            InitializeComponent();

            var commitOwner    = new GitCommitListViewOwner(gitLog, commit);
            var commitListView = new GitCommitListView(commitOwner);

            SuspendLayout();

            this.Text  += $" {commit.Sha}";
            this.Width  = 1200;
            this.Height = 600;

            this.listView      = commitListView;
            this.listView.Dock = DockStyle.Fill;

            this.Controls.Add(this.listView);

            ResumeLayout(false);
            PerformLayout();
        }
Exemple #4
0
        public GitLogForm(Repository repo, string path)
        {
            InitializeComponent();

            var gitLog      = new GitLog(repo, path, Constants.MaxCommits);
            var logOwner    = new GitLogListViewOwner(gitLog);
            var logListView = new GitLogListView(logOwner);

            this.listView         = logListView;
            this.statusStrip      = new StatusStrip();
            this.commitCountLabel = new ToolStripStatusLabel();
            this.searchBox        = new ToolStripTextBox();
            this.authorLabel      = new ToolStripStatusLabel();
            this.fromDateLabel    = new ToolStripStatusLabel();
            this.toDateLabel      = new ToolStripStatusLabel();
            this.fillerLabel      = new ToolStripStatusLabel();
            this.branchComboBox   = new ToolStripComboBox();

            this.statusStrip.SuspendLayout();
            SuspendLayout();

            this.Text      += $" {path}";
            this.Width      = 1200;
            this.Height     = 600;
            this.KeyPreview = true;
            this.KeyDown   += GitLogForm_KeyDown;

            this.listView.Dock               = DockStyle.Fill;
            this.listView.ListSizeChanged   += ListView_ListSizeChanged;
            this.listView.FilteringByAuthor += ListView_FilteringByAuthor;
            this.listView.FilteringFromDate += ListView_FilteringFromDate;
            this.listView.FilteringToDate   += ListView_FilteringToDate;

            this.statusStrip.Items.Add(this.commitCountLabel);
            this.statusStrip.Items.Add(this.searchBox);
            this.statusStrip.Items.Add(this.authorLabel);
            this.statusStrip.Items.Add(this.fromDateLabel);
            this.statusStrip.Items.Add(this.toDateLabel);
            this.statusStrip.Items.Add(this.fillerLabel);
            this.statusStrip.Items.Add(this.branchComboBox);
            this.statusStrip.TabStop          = true;
            this.statusStrip.ShowItemToolTips = true;

            this.commitCountLabel.AutoSize    = false;
            this.commitCountLabel.Size        = new Size(150, 20);
            this.commitCountLabel.TextAlign   = ContentAlignment.MiddleLeft;
            this.commitCountLabel.BorderSides = ToolStripStatusLabelBorderSides.Right;
            this.commitCountLabel.BorderStyle = Border3DStyle.Etched;

            this.authorLabel.Size        = new Size(180, 16);
            this.authorLabel.ToolTipText = Constants.AuthorLabelToolTipText;
            this.authorLabel.AutoToolTip = true;
            this.authorLabel.Click      += AuthorLabel_Click;

            this.fromDateLabel.Size        = new Size(150, 16);
            this.fromDateLabel.ToolTipText = Constants.FromDateLabelToolTipText;
            this.fromDateLabel.AutoToolTip = true;
            this.fromDateLabel.Click      += FromDateLabel_Click;

            this.toDateLabel.Size        = new Size(150, 16);
            this.toDateLabel.ToolTipText = Constants.ToDateLabelToolTipText;
            this.toDateLabel.AutoToolTip = true;
            this.toDateLabel.Click      += ToDateLabel_Click;

            this.fillerLabel.Spring = true;

            this.branchComboBox.Size          = new Size(240, 16);
            this.branchComboBox.AutoSize      = true;
            this.branchComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            this.branchComboBox.FlatStyle     = FlatStyle.Standard;
            this.branchComboBox.Padding       = new Padding(0, 0, 20, 0);
            this.branchComboBox.Items.AddRange(gitLog.GetLocalBranchNames(out this.selectedBranchIndex));
            this.branchComboBox.SelectedIndex         = this.selectedBranchIndex;
            this.branchComboBox.SelectedIndexChanged += BranchComboBox_SelectedIndexChanged;

            this.searchBox.AutoSize           = false;
            this.searchBox.Font               = new Font(Constants.ListViewFontName, 8);
            this.searchBox.Size               = new Size(180, 16);
            this.searchBox.Padding            = new Padding(10, 0, 0, 0);
            this.searchBox.AutoCompleteMode   = AutoCompleteMode.Append;
            this.searchBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
            this.searchBox.MaxLength          = Constants.SearchBoxMaxLength;
            this.searchBox.TextBox.SetCueText(Constants.SearchBoxCueText);
            this.searchBox.TextChanged            += SearchBox_TextChanged;
            this.searchBox.KeyDown                += SearchBox_KeyDown;
            this.searchBox.TextBox.PreviewKeyDown += TextBox_PreviewKeyDown;

            this.searchBoxTimer          = new Timer();
            this.searchBoxTimer.Tick    += SearchBoxTimer_Tick;
            this.searchBoxTimer.Interval = Constants.SearchBoxTimerInterval;

            this.Controls.Add(this.listView);
            this.Controls.Add(this.statusStrip);

            this.statusStrip.ResumeLayout(false);
            this.statusStrip.PerformLayout();
            ResumeLayout(false);
            PerformLayout();
        }
Exemple #5
0
 public GitLogListViewOwner(GitLog gitLog)
 {
     this.gitLog  = gitLog ?? throw new ArgumentNullException(nameof(gitLog));
     this.commits = new List <Commit>();
 }