FileUpdater enancements.
[Widgit.git] / UI / StatusViewer.cs
blob914e171326f51fb49263330ba819f62518a52a46
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 protected FileUpdater m_updater;
20 public FileUpdater FileUpdater
22 set
24 if (null != m_updater)
26 m_updater.FilesUpdated -= OnFilesUpdated;
27 m_updater[m_toolbar] = null;
29 m_updater = value;
30 m_updater.FilesUpdated += OnFilesUpdated;
31 m_updater[m_toolbar] = (ISelectable)this;
35 protected int m_selectedTypes = -1 & (int)~Git.FileState.Unknown & (int)~Git.FileState.Normal;
37 public StatusViewer()
39 InitializeComponent();
40 m_toolbar.Initialize(-1 & (int)~FileState.Normal, -1 & (int)~FileState.Normal & (int)~FileState.Unknown);
41 m_toolbar.RefreshFiles += OnRefreshTree;
42 m_toolbar.StatesChanged += OnStatesChanged;
43 m_toolbar.Enabled = false;
46 public void SetRepo(Repo repo, bool bRefresh)
48 m_currentRepo = repo;
49 m_currentRepo.GetFilesMap(out m_files, bRefresh);
50 PopulateTable();
51 m_toolbar.Enabled = true;
54 protected void PopulateTable()
56 m_statusList.BeginUpdate();
57 m_statusList.Items.Clear();
58 foreach (KeyValuePair<string, Git.File> pair in m_files)
60 if (0 == (m_selectedTypes & (int)pair.Value.State))
62 continue;
64 ListViewItem item = new ListViewItem( new string[] { pair.Key }, Git.File.GetStateName(pair.Value.State));
65 item.Tag = pair.Value;
66 item.Name = pair.Key;
67 m_statusList.Items.Add(item);
69 m_statusList.EndUpdate();
72 private void OnFilesUpdated(FileUpdater sender, FilesUpdatedEvent evt)
74 List<Git.File> files = evt.FilesList;
75 foreach (Git.File f in files)
77 m_files[f.PathWithName] = f;
79 PopulateTable();
82 private void OnRefreshTree(object sender, EventArgs e)
84 if (null != m_currentRepo)
86 m_currentRepo.GetFilesMap(out m_files, true);
87 PopulateTable();
91 private void OnStatesChanged(RepoToolStrip sender, SelectedStatesChangedEvent e)
93 m_selectedTypes = e.SelectedStates;
94 PopulateTable();
97 public List<File> GetSelected()
99 List<File> files = new List<File>();
100 foreach (ListViewItem i in m_statusList.SelectedItems)
102 files.Add((File)i.Tag);
104 return files;