FileUpdater enancements.
[Widgit.git] / UI / CommitTable.cs
blob8820c996fd10f72c627c97f308085aa9f98c102e
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 CommitTable()
20 InitializeComponent();
23 public void SetRepo(Repo repo)
25 m_currentRepo = repo;
26 m_fetchCommits.Enabled = true;
27 m_commitsView.Items.Clear();
28 m_previousCommits.Enabled = false;
29 m_nextCommits.Enabled = false;
30 m_topCommits.Clear();
31 m_lastCommitInPage = null;
34 private void OnFetchCommits(object sender, EventArgs e)
36 List<Commit> commits;
37 if (!m_currentRepo.GetLog(null, 100, out commits))
39 MessageBox.Show("Could not get commits.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
40 return;
42 m_topCommits.Clear();
43 m_topCommits.Push(commits[0]);
44 FillCommitList(commits);
47 private void FillCommitList(List<Commit> commits)
49 m_commitsView.BeginUpdate();
50 m_commitsView.Items.Clear();
51 foreach (Commit c in commits)
53 ListViewItem i = new ListViewItem(new string[] { c.ID, c.AuthorName, c.AuthorEmail, c.Date, c.Subject });
54 i.Tag = c;
55 m_commitsView.Items.Add(i);
57 if (commits.Count > 0)
59 m_lastCommitInPage = commits[commits.Count - 1];
61 m_previousCommits.Enabled = m_nextCommits.Enabled = commits.Count != 0;
62 if (m_commitsView.Items.Count != 100)
64 m_nextCommits.Enabled = false;
66 if (m_topCommits.Count < 2)
68 m_previousCommits.Enabled = false;
71 m_commitsView.EndUpdate();
74 private void OnPreviousCommits(object sender, EventArgs e)
76 List<Commit> commits;
77 Commit c = m_topCommits.Pop();
78 if (!m_currentRepo.GetLog(m_topCommits.Peek(), 100, out commits))
80 m_nextCommits.Enabled = false;
81 return;
83 if (commits.Count < 1)
85 m_previousCommits.Enabled = false;
87 else
89 FillCommitList(commits);
93 private void OnNextCommits(object sender, EventArgs e)
95 List<Commit> commits;
96 if (!m_currentRepo.GetLog(m_lastCommitInPage, 100, out commits))
98 m_nextCommits.Enabled = false;
99 return;
101 if (commits.Count < 1)
103 m_nextCommits.Enabled = false;
105 else
107 m_topCommits.Push(commits[0]);
108 FillCommitList(commits);
112 private void OnShowCommit(object sender, EventArgs e)
114 ListView.SelectedListViewItemCollection items = m_commitsView.SelectedItems;
115 if (items.Count == 1)
117 CommitViewer c = new CommitViewer((Commit)items[0].Tag);
118 c.Show();