1 //Widgit is free software; you can redistribute it and/or modify
2 //it under the terms of the GNU General Public License as published by
3 //the Free Software Foundation; either version 2 of the License, or
4 //(at your option) any later version.
6 //Widgit is distributed in the hope that it will be useful,
7 //but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 //GNU General Public License for more details.
11 //You should have received a copy of the GNU General Public License
12 //along with Widgit; if not, write to the Free Software
13 //Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USAusing System;
16 using System
.Collections
.Generic
;
17 using System
.ComponentModel
;
21 using System
.Windows
.Forms
;
26 public partial class CommitTable
: UserControl
28 protected Commit m_lastCommitInPage
;
29 protected Stack
<Commit
> m_topCommits
= new Stack
<Commit
>();
30 protected Repo m_currentRepo
;
31 protected CommitFilter m_filter
;
33 public ListView
.SelectedListViewItemCollection SelectedItems { get { return m_commitsView.SelectedItems; }
}
35 protected Treeish m_treeish
;
36 public Treeish Treeish { get { return m_treeish; }
set { m_treeish = value; }
}
38 public List
<string> Paths
40 get { return m_filter.Paths; }
45 m_filter
.Paths
= value;
52 InitializeComponent();
55 public void SetRepo(Repo repo
)
58 m_filter
= new CommitFilter(repo
);
59 m_fetchCommits
.Enabled
= true;
60 m_filterCommits
.Enabled
= true;
61 m_commitsView
.Items
.Clear();
62 m_previousCommits
.Enabled
= false;
63 m_nextCommits
.Enabled
= false;
65 m_lastCommitInPage
= null;
68 private void OnFetchCommits(object sender
, EventArgs e
)
73 public void RepopulateTable()
76 m_filter
.Treeish
= m_treeish
;
77 if (!m_currentRepo
.GetLog(m_filter
, out commits
))
79 MessageBox
.Show("Could not get commits.", "Error", MessageBoxButtons
.OK
, MessageBoxIcon
.Error
);
83 if (m_topCommits
.Count
> 0)
85 m_topCommits
.Push(commits
[0]);
87 FillCommitList(commits
);
90 private void FillCommitList(List
<Commit
> commits
)
92 m_commitsView
.BeginUpdate();
93 m_commitsView
.Items
.Clear();
94 foreach (Commit c
in commits
)
96 ListViewItem i
= new ListViewItem(new string[] { c.ID, c.AuthorName, c.AuthorEmail, c.Date, c.Subject }
);
98 m_commitsView
.Items
.Add(i
);
100 if (commits
.Count
> 0)
102 m_lastCommitInPage
= commits
[commits
.Count
- 1];
104 m_previousCommits
.Enabled
= m_nextCommits
.Enabled
= commits
.Count
!= 0;
105 if (m_commitsView
.Items
.Count
!= 100)
107 m_nextCommits
.Enabled
= false;
109 if (m_topCommits
.Count
< 2)
111 m_previousCommits
.Enabled
= false;
114 m_commitsView
.EndUpdate();
117 private void OnPreviousCommits(object sender
, EventArgs e
)
119 List
<Commit
> commits
;
121 m_filter
.Treeish
= m_topCommits
.Peek();
122 if (!m_currentRepo
.GetLog(m_filter
, out commits
))
124 m_nextCommits
.Enabled
= false;
127 if (commits
.Count
< 1)
129 m_previousCommits
.Enabled
= false;
133 FillCommitList(commits
);
137 private void OnNextCommits(object sender
, EventArgs e
)
139 List
<Commit
> commits
;
140 m_filter
.Treeish
= m_lastCommitInPage
;
141 if (!m_currentRepo
.GetLog(m_filter
, out commits
))
143 m_nextCommits
.Enabled
= false;
146 if (commits
.Count
< 1)
148 m_nextCommits
.Enabled
= false;
152 m_topCommits
.Push(commits
[0]);
153 FillCommitList(commits
);
157 private void OnShowCommit(object sender
, EventArgs e
)
159 ListView
.SelectedListViewItemCollection items
= m_commitsView
.SelectedItems
;
160 if (items
.Count
== 1)
162 CommitViewer c
= new CommitViewer((Commit
)items
[0].Tag
);
167 private void OnShowFilter(object sender
, EventArgs e
)
169 if (DialogResult
.OK
== m_filter
.ShowDialog())