Got viewing files and diffing files (arbitrary commits) to work.
[Widgit.git] / UI / CommitTable.cs
blob78a275ac5ee5438709a145f5b27b8028281940da
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Text;
7 using System.Windows.Forms;
8 using Git;
10 namespace Widgit
12 public partial class CommitTable : UserControl
14 protected Commit m_lastCommitInPage;
15 protected Stack<Commit> m_topCommits = new Stack<Commit>();
16 protected Repo m_currentRepo;
18 public ListView.SelectedListViewItemCollection SelectedItems { get { return m_commitsView.SelectedItems; } }
20 protected Treeish m_treeish;
21 public Treeish Treeish { get { return m_treeish; } set { m_treeish = value; } }
23 public CommitTable()
25 InitializeComponent();
28 public void SetRepo(Repo repo)
30 m_currentRepo = repo;
31 m_fetchCommits.Enabled = true;
32 m_commitsView.Items.Clear();
33 m_previousCommits.Enabled = false;
34 m_nextCommits.Enabled = false;
35 m_topCommits.Clear();
36 m_lastCommitInPage = null;
39 private void OnFetchCommits(object sender, EventArgs e)
41 RepopulateTable();
44 public void RepopulateTable()
46 List<Commit> commits;
47 if (!m_currentRepo.GetLog(m_treeish, 100, out commits))
49 MessageBox.Show("Could not get commits.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
50 return;
52 m_topCommits.Clear();
53 m_topCommits.Push(commits[0]);
54 FillCommitList(commits);
57 private void FillCommitList(List<Commit> commits)
59 m_commitsView.BeginUpdate();
60 m_commitsView.Items.Clear();
61 foreach (Commit c in commits)
63 ListViewItem i = new ListViewItem(new string[] { c.ID, c.AuthorName, c.AuthorEmail, c.Date, c.Subject });
64 i.Tag = c;
65 m_commitsView.Items.Add(i);
67 if (commits.Count > 0)
69 m_lastCommitInPage = commits[commits.Count - 1];
71 m_previousCommits.Enabled = m_nextCommits.Enabled = commits.Count != 0;
72 if (m_commitsView.Items.Count != 100)
74 m_nextCommits.Enabled = false;
76 if (m_topCommits.Count < 2)
78 m_previousCommits.Enabled = false;
81 m_commitsView.EndUpdate();
84 private void OnPreviousCommits(object sender, EventArgs e)
86 List<Commit> commits;
87 Commit c = m_topCommits.Pop();
88 if (!m_currentRepo.GetLog(m_topCommits.Peek(), 100, out commits))
90 m_nextCommits.Enabled = false;
91 return;
93 if (commits.Count < 1)
95 m_previousCommits.Enabled = false;
97 else
99 FillCommitList(commits);
103 private void OnNextCommits(object sender, EventArgs e)
105 List<Commit> commits;
106 if (!m_currentRepo.GetLog(m_lastCommitInPage, 100, out commits))
108 m_nextCommits.Enabled = false;
109 return;
111 if (commits.Count < 1)
113 m_nextCommits.Enabled = false;
115 else
117 m_topCommits.Push(commits[0]);
118 FillCommitList(commits);
122 private void OnShowCommit(object sender, EventArgs e)
124 ListView.SelectedListViewItemCollection items = m_commitsView.SelectedItems;
125 if (items.Count == 1)
127 CommitViewer c = new CommitViewer((Commit)items[0].Tag);
128 c.Show();