• R/O
  • SSH

main: Commit

IE Process List のプログラム本体


Commit MetaInfo

Revisão50873de3e00227602b419b4025ed8af393678442 (tree)
Hora2011-07-02 17:41:10
AutorMagicant <magicant.starmen AT nifty.com>
CommiterMagicant <magicant.starmen AT nifty.com>

Mensagem de Log

Track tab ID

Mudança Sumário

Diff

diff -r 23446581b0c4 -r 50873de3e002 IEProcess.cs
--- a/IEProcess.cs Sat Jul 02 16:24:30 2011 +0900
+++ b/IEProcess.cs Sat Jul 02 17:41:10 2011 +0900
@@ -134,12 +134,13 @@
134134 }
135135
136136 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);
139139 foreach (KeyValuePair<int, IEProcess> item in processes) {
140140 if (item.Value.ParentId >= 0) {
141141 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>());
143144 }
144145 }
145146
@@ -147,7 +148,7 @@
147148 window != IntPtr.Zero;
148149 window = GetWindow(window, GetWindow_Cmd.GW_HWNDNEXT)) {
149150 uint pid;
150- KeyValuePair<IEProcess, IList<string>> processAndTitles;
151+ KeyValuePair<IEProcess, IDictionary<int, string>> processAndTitles;
151152 GetWindowThreadProcessId(window, out pid);
152153 if (!processesAndTitles.TryGetValue((int) pid, out processAndTitles)) {
153154 continue;
@@ -165,11 +166,11 @@
165166
166167 string titleValue = title.ToString();
167168 if (titleValue.Contains(" - ")) {
168- processAndTitles.Value.Add(titleValue);
169+ processAndTitles.Value.Add(window.ToInt32(), titleValue);
169170 }
170171 }
171172
172- foreach (KeyValuePair<IEProcess, IList<string>> processAndTitles
173+ foreach (KeyValuePair<IEProcess, IDictionary<int, string>> processAndTitles
173174 in processesAndTitles.Values) {
174175 processAndTitles.Key.UpdateTabTitles(processAndTitles.Value);
175176 }
@@ -263,7 +264,8 @@
263264 private readonly int parentId;
264265 private readonly string commandLine;
265266 private ProcessVariableProperties pvp;
266- private IList<string> tabTitles;
267+ private readonly IDictionary<int, IETab> tabs
268+ = new SortedDictionary<int, IETab>();
267269
268270 /// <summary>
269271 /// Process ID.
@@ -359,39 +361,38 @@
359361 return true;
360362 }
361363
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;
375365
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+ }
379372
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);
395396 }
396397 }
397398
diff -r 23446581b0c4 -r 50873de3e002 IEProcessList.csproj
--- a/IEProcessList.csproj Sat Jul 02 16:24:30 2011 +0900
+++ b/IEProcessList.csproj Sat Jul 02 17:41:10 2011 +0900
@@ -60,6 +60,7 @@
6060 <Compile Include="IEProcessForm.Designer.cs">
6161 <DependentUpon>IEProcessForm.cs</DependentUpon>
6262 </Compile>
63+ <Compile Include="IETab.cs" />
6364 <Compile Include="MainForm.IEProcessNode.cs">
6465 <SubType>Form</SubType>
6566 </Compile>
@@ -70,6 +71,9 @@
7071 <Compile Include="MainForm.Designer.cs">
7172 <DependentUpon>MainForm.cs</DependentUpon>
7273 </Compile>
74+ <Compile Include="MainForm.IETabNode.cs">
75+ <SubType>Form</SubType>
76+ </Compile>
7377 <Compile Include="Program.cs" />
7478 <Compile Include="Properties\AssemblyInfo.cs" />
7579 <Compile Include="Util.cs" />
diff -r 23446581b0c4 -r 50873de3e002 IETab.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IETab.cs Sat Jul 02 17:41:10 2011 +0900
@@ -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+}
diff -r 23446581b0c4 -r 50873de3e002 MainForm.IEProcessNode.cs
--- a/MainForm.IEProcessNode.cs Sat Jul 02 16:24:30 2011 +0900
+++ b/MainForm.IEProcessNode.cs Sat Jul 02 17:41:10 2011 +0900
@@ -24,7 +24,6 @@
2424
2525 iep.Updated += (_ => this.UpdateProperties());
2626 iep.TabAdded += this.AddTabNode;
27- iep.TabRemoved += this.RemoveTabNode;
2827 iep.Exited += (_ => this.Remove());
2928 }
3029
@@ -37,22 +36,13 @@
3736 iep.VariableProperties.PrivatePageCount / bytesInKilobyte);
3837 }
3938
40- private void AddTabNode(string tabTitle) {
41- this.Nodes.Add(tabTitle);
39+ private void AddTabNode(IETab tab) {
40+ this.Nodes.Add(new IETabNode(tab));
4241 if (this.Nodes.Count == 1) {
4342 this.Expand();
4443 }
4544 }
4645
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-
5646 public void ShowIEProcessForm() {
5747 if (this.IEProcessForm == null) {
5848 this.IEProcessForm = new IEProcessForm(this.IEProcess);
diff -r 23446581b0c4 -r 50873de3e002 MainForm.IETabNode.cs
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MainForm.IETabNode.cs Sat Jul 02 17:41:10 2011 +0900
@@ -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+}
Show on old repository browser