IE Process List のプログラム本体
Revisão | 50873de3e00227602b419b4025ed8af393678442 (tree) |
---|---|
Hora | 2011-07-02 17:41:10 |
Autor | Magicant <magicant.starmen AT nifty.com> |
Commiter | Magicant <magicant.starmen AT nifty.com> |
Track tab ID
@@ -134,12 +134,13 @@ | ||
134 | 134 | } |
135 | 135 | |
136 | 136 | public static void UpdateTabTitles() { |
137 | - IDictionary<int, KeyValuePair<IEProcess, IList<string>>> processesAndTitles | |
138 | - = new Dictionary<int, KeyValuePair<IEProcess, IList<string>>>(processes.Count); | |
137 | + IDictionary<int, KeyValuePair<IEProcess, IDictionary<int, string>>> processesAndTitles | |
138 | + = new Dictionary<int, KeyValuePair<IEProcess, IDictionary<int, string>>>(processes.Count); | |
139 | 139 | foreach (KeyValuePair<int, IEProcess> item in processes) { |
140 | 140 | if (item.Value.ParentId >= 0) { |
141 | 141 | processesAndTitles[item.Key] |
142 | - = new KeyValuePair<IEProcess, IList<string>>(item.Value, new List<string>()); | |
142 | + = new KeyValuePair<IEProcess, IDictionary<int, string>>( | |
143 | + item.Value, new SortedDictionary<int, string>()); | |
143 | 144 | } |
144 | 145 | } |
145 | 146 |
@@ -147,7 +148,7 @@ | ||
147 | 148 | window != IntPtr.Zero; |
148 | 149 | window = GetWindow(window, GetWindow_Cmd.GW_HWNDNEXT)) { |
149 | 150 | uint pid; |
150 | - KeyValuePair<IEProcess, IList<string>> processAndTitles; | |
151 | + KeyValuePair<IEProcess, IDictionary<int, string>> processAndTitles; | |
151 | 152 | GetWindowThreadProcessId(window, out pid); |
152 | 153 | if (!processesAndTitles.TryGetValue((int) pid, out processAndTitles)) { |
153 | 154 | continue; |
@@ -165,11 +166,11 @@ | ||
165 | 166 | |
166 | 167 | string titleValue = title.ToString(); |
167 | 168 | if (titleValue.Contains(" - ")) { |
168 | - processAndTitles.Value.Add(titleValue); | |
169 | + processAndTitles.Value.Add(window.ToInt32(), titleValue); | |
169 | 170 | } |
170 | 171 | } |
171 | 172 | |
172 | - foreach (KeyValuePair<IEProcess, IList<string>> processAndTitles | |
173 | + foreach (KeyValuePair<IEProcess, IDictionary<int, string>> processAndTitles | |
173 | 174 | in processesAndTitles.Values) { |
174 | 175 | processAndTitles.Key.UpdateTabTitles(processAndTitles.Value); |
175 | 176 | } |
@@ -263,7 +264,8 @@ | ||
263 | 264 | private readonly int parentId; |
264 | 265 | private readonly string commandLine; |
265 | 266 | private ProcessVariableProperties pvp; |
266 | - private IList<string> tabTitles; | |
267 | + private readonly IDictionary<int, IETab> tabs | |
268 | + = new SortedDictionary<int, IETab>(); | |
267 | 269 | |
268 | 270 | /// <summary> |
269 | 271 | /// Process ID. |
@@ -359,39 +361,38 @@ | ||
359 | 361 | return true; |
360 | 362 | } |
361 | 363 | |
362 | - public event Action<string> TabAdded; | |
363 | - public event Action<string> TabRemoved; | |
364 | - | |
365 | - private void UpdateTabTitles(IList<string> titles) { | |
366 | - if (this.tabTitles == null) { | |
367 | - this.tabTitles = titles; | |
368 | - if (this.TabAdded != null) { | |
369 | - foreach (string title in titles) { | |
370 | - this.TabAdded(title); | |
371 | - } | |
372 | - } | |
373 | - } else { | |
374 | - IList<string> oldTitles = this.tabTitles; | |
364 | + public event Action<IETab> TabAdded; | |
375 | 365 | |
376 | - this.tabTitles = titles; | |
377 | - foreach (string title in titles) { | |
378 | - int index = oldTitles.IndexOf(title); | |
366 | + public void AddTab(IETab tab) { | |
367 | + this.tabs.Add(tab.Id, tab); | |
368 | + if (this.TabAdded != null) { | |
369 | + this.TabAdded(tab); | |
370 | + } | |
371 | + } | |
379 | 372 | |
380 | - if (index >= 0) { | |
381 | - oldTitles[index] = null; | |
382 | - } else { | |
383 | - if (this.TabAdded != null) { | |
384 | - this.TabAdded(title); | |
385 | - } | |
386 | - } | |
387 | - } | |
388 | - if (this.TabRemoved != null) { | |
389 | - foreach (string oldTitle in oldTitles) { | |
390 | - if (oldTitle != null) { | |
391 | - this.TabRemoved(oldTitle); | |
392 | - } | |
393 | - } | |
394 | - } | |
373 | + public void RemoveTab(IETab tab) { | |
374 | + this.tabs.Remove(tab.Id); | |
375 | + tab.OnClosed(); | |
376 | + } | |
377 | + | |
378 | + private void UpdateTabTitles(IDictionary<int, string> titles) { | |
379 | + ICollection<IETab> | |
380 | + toBeRemoved = new List<IETab>(this.tabs.Count), | |
381 | + toBeAdded = new List<IETab>(titles.Count); | |
382 | + | |
383 | + Util.CompareSortedDictionaries(this.tabs, titles, | |
384 | + (int id, IETab tab, string newTitle) => { | |
385 | + if (tab.Title != newTitle) | |
386 | + tab.Title = newTitle; | |
387 | + }, | |
388 | + (KeyValuePair<int, IETab> kv) => toBeRemoved.Add(kv.Value), | |
389 | + (KeyValuePair<int, string> kv) => toBeAdded.Add(new IETab(kv.Key, kv.Value))); | |
390 | + | |
391 | + foreach (IETab tab in toBeRemoved) { | |
392 | + this.RemoveTab(tab); | |
393 | + } | |
394 | + foreach (IETab tab in toBeAdded) { | |
395 | + this.AddTab(tab); | |
395 | 396 | } |
396 | 397 | } |
397 | 398 |
@@ -60,6 +60,7 @@ | ||
60 | 60 | <Compile Include="IEProcessForm.Designer.cs"> |
61 | 61 | <DependentUpon>IEProcessForm.cs</DependentUpon> |
62 | 62 | </Compile> |
63 | + <Compile Include="IETab.cs" /> | |
63 | 64 | <Compile Include="MainForm.IEProcessNode.cs"> |
64 | 65 | <SubType>Form</SubType> |
65 | 66 | </Compile> |
@@ -70,6 +71,9 @@ | ||
70 | 71 | <Compile Include="MainForm.Designer.cs"> |
71 | 72 | <DependentUpon>MainForm.cs</DependentUpon> |
72 | 73 | </Compile> |
74 | + <Compile Include="MainForm.IETabNode.cs"> | |
75 | + <SubType>Form</SubType> | |
76 | + </Compile> | |
73 | 77 | <Compile Include="Program.cs" /> |
74 | 78 | <Compile Include="Properties\AssemblyInfo.cs" /> |
75 | 79 | <Compile Include="Util.cs" /> |
@@ -0,0 +1,48 @@ | ||
1 | +using System; | |
2 | +using System.Collections.Generic; | |
3 | +using System.Text; | |
4 | + | |
5 | +namespace IEProcessList { | |
6 | + | |
7 | + class IETab { | |
8 | + | |
9 | + private readonly int id; | |
10 | + private string title; | |
11 | + | |
12 | + public int Id { | |
13 | + get { return this.id; } | |
14 | + } | |
15 | + | |
16 | + public string Title { | |
17 | + get { return this.title; } | |
18 | + set { | |
19 | + if (value == null) | |
20 | + throw new ArgumentNullException(); | |
21 | + this.title = value; | |
22 | + OnTitleChanged(); | |
23 | + } | |
24 | + } | |
25 | + | |
26 | + public IETab(int id, string title) { | |
27 | + this.id = id; | |
28 | + this.title = title; | |
29 | + } | |
30 | + | |
31 | + public event Action<IETab> TitleChanged; | |
32 | + | |
33 | + protected void OnTitleChanged() { | |
34 | + if (this.TitleChanged != null) | |
35 | + this.TitleChanged(this); | |
36 | + } | |
37 | + | |
38 | + public event Action<IETab> Closed; | |
39 | + | |
40 | + internal void OnClosed() { | |
41 | + if (this.Closed != null) { | |
42 | + this.Closed(this); | |
43 | + } | |
44 | + } | |
45 | + | |
46 | + } | |
47 | + | |
48 | +} |
@@ -24,7 +24,6 @@ | ||
24 | 24 | |
25 | 25 | iep.Updated += (_ => this.UpdateProperties()); |
26 | 26 | iep.TabAdded += this.AddTabNode; |
27 | - iep.TabRemoved += this.RemoveTabNode; | |
28 | 27 | iep.Exited += (_ => this.Remove()); |
29 | 28 | } |
30 | 29 |
@@ -37,22 +36,13 @@ | ||
37 | 36 | iep.VariableProperties.PrivatePageCount / bytesInKilobyte); |
38 | 37 | } |
39 | 38 | |
40 | - private void AddTabNode(string tabTitle) { | |
41 | - this.Nodes.Add(tabTitle); | |
39 | + private void AddTabNode(IETab tab) { | |
40 | + this.Nodes.Add(new IETabNode(tab)); | |
42 | 41 | if (this.Nodes.Count == 1) { |
43 | 42 | this.Expand(); |
44 | 43 | } |
45 | 44 | } |
46 | 45 | |
47 | - private void RemoveTabNode(string tabTitle) { | |
48 | - foreach (TreeNode node in this.Nodes) { | |
49 | - if (node.Text == tabTitle) { | |
50 | - node.Remove(); | |
51 | - break; | |
52 | - } | |
53 | - } | |
54 | - } | |
55 | - | |
56 | 46 | public void ShowIEProcessForm() { |
57 | 47 | if (this.IEProcessForm == null) { |
58 | 48 | this.IEProcessForm = new IEProcessForm(this.IEProcess); |
@@ -0,0 +1,33 @@ | ||
1 | +using System; | |
2 | +using System.Windows.Forms; | |
3 | + | |
4 | +namespace IEProcessList { | |
5 | + | |
6 | + partial class MainForm { | |
7 | + | |
8 | + class IETabNode : TreeNode { | |
9 | + | |
10 | + private readonly IETab tab; | |
11 | + | |
12 | + public IETab IETab { | |
13 | + get { return this.tab; } | |
14 | + } | |
15 | + | |
16 | + public IETabNode(IETab tab) { | |
17 | + this.tab = tab; | |
18 | + | |
19 | + this.UpdateProperties(); | |
20 | + | |
21 | + tab.TitleChanged += (_ => this.UpdateProperties()); | |
22 | + tab.Closed += (_ => this.Remove()); | |
23 | + } | |
24 | + | |
25 | + private void UpdateProperties() { | |
26 | + this.Text = string.Format("Tab {0} - {1}", this.IETab.Id, this.IETab.Title); | |
27 | + } | |
28 | + | |
29 | + } | |
30 | + | |
31 | + } | |
32 | + | |
33 | +} |