Got viewing files and diffing files (arbitrary commits) to work.
[Widgit.git] / UI / StatusViewer.cs
blob7c9f6a3b72e0fe039f6d5af89516082a442498aa
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 StatusViewer : UserControl, ISelectable
14 Repo m_currentRepo;
15 Dictionary<string, Git.File> m_files;
16 ImageList m_imageList;
17 public ImageList ImageList { get { return m_imageList; } set { m_imageList = value; m_statusList.SmallImageList = m_imageList; } }
19 public ListView.SelectedListViewItemCollection SelectedItems { get { return m_statusList.SelectedItems; } }
21 public bool Multiselect { get { return m_statusList.MultiSelect; } set { m_statusList.MultiSelect = value; } }
23 protected FileUpdater m_updater;
24 public FileUpdater FileUpdater
26 set
28 if (null != m_updater)
30 m_updater.FilesUpdated -= OnFilesUpdated;
31 m_updater[m_toolbar] = null;
32 m_updater[m_opMenu] = null;
34 m_updater = value;
35 m_updater.FilesUpdated += OnFilesUpdated;
36 m_updater[m_toolbar] = (ISelectable)this;
37 m_updater[m_opMenu] = (ISelectable)this;
41 protected int m_selectedTypes = -1 & (int)~Git.FileState.Unknown & (int)~Git.FileState.Normal;
43 public StatusViewer()
45 InitializeComponent();
46 m_toolbar.Initialize(-1 & (int)~FileState.Normal, -1 & (int)~FileState.Normal & (int)~FileState.Unknown);
47 m_toolbar.RefreshFiles += OnRefreshTree;
48 m_toolbar.StatesChanged += OnStatesChanged;
49 m_toolbar.Enabled = false;
52 public void SetRepo(Repo repo, bool bRefresh)
54 m_currentRepo = repo;
55 m_currentRepo.GetFilesMap(out m_files, bRefresh);
56 PopulateTable();
57 m_toolbar.Enabled = true;
60 protected void PopulateTable()
62 m_statusList.BeginUpdate();
63 m_statusList.Items.Clear();
64 foreach (KeyValuePair<string, Git.File> pair in m_files)
66 if (0 == (m_selectedTypes & (int)pair.Value.State))
68 continue;
70 ListViewItem item = new ListViewItem( new string[] { pair.Key }, Git.File.GetStateName(pair.Value.State));
71 item.Tag = pair.Value;
72 item.Name = pair.Key;
73 m_statusList.Items.Add(item);
75 m_statusList.EndUpdate();
78 private void OnFilesUpdated(FileUpdater sender, FilesUpdatedEvent evt)
80 List<Git.File> files = evt.FilesList;
81 foreach (Git.File f in files)
83 m_files[f.PathWithName] = f;
85 PopulateTable();
88 private void OnRefreshTree(object sender, EventArgs e)
90 if (null != m_currentRepo)
92 m_currentRepo.GetFilesMap(out m_files, true);
93 PopulateTable();
97 private void OnStatesChanged(RepoToolStrip sender, SelectedStatesChangedEvent e)
99 m_selectedTypes = e.SelectedStates;
100 PopulateTable();
103 public List<File> GetSelected()
105 List<File> files = new List<File>();
106 foreach (ListViewItem i in m_statusList.SelectedItems)
108 files.Add((File)i.Tag);
110 return files;
113 private void OnRowClicked(object sender, MouseEventArgs e)
115 if (e.Button == MouseButtons.Right)
117 ListViewItem i = m_statusList.GetItemAt(e.X, e.Y);
118 m_statusList.SelectedItems.Clear();
119 i.Selected = true;
120 m_opMenu.Show(m_statusList, e.X, e.Y);