ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Docking/PIDSelector.cs
Revision: 152
Committed: Mon May 28 02:01:34 2012 UTC (11 years, 4 months ago) by william
File size: 8691 byte(s)
Log Message:
+ add support to save dock layout

File Contents

# User Rev Content
1 william 88 using System;
2     using System.Collections.Generic;
3     using System.ComponentModel;
4     using System.Data;
5     using System.Drawing;
6     using System.Text;
7     using System.Windows.Forms;
8     using System.Diagnostics;
9     using RomCheater.PluginFramework.Interfaces;
10     using RomCheater.PluginFramework.Core;
11 william 109 using System.IO;
12     using RomCheater.Logging;
13 william 148 using WeifenLuo.WinFormsUI.Docking;
14 william 88
15 william 149 namespace RomCheater.Docking
16 william 88 {
17 william 148 public partial class PIDSelector : DockContent
18 william 88 {
19 william 152 //private IConfigPlugin plugin = null;
20 william 88 //bool isInError = false;
21 william 151 public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; OnSelectedProcessChanged = null; }
22 william 152 public PIDSelector(IConfigPlugin plugin) : this() { this.ConfigPlugin = plugin; }
23 william 88 // unsued construtor (it's not implmented, may not be)
24     [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]
25     public PIDSelector(int pid) : this() { this.SelectedPid = pid; }
26     [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]
27     public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; }
28    
29     private int _SelectedPid;
30     public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }
31    
32 william 152 public IConfigPlugin ConfigPlugin { get; set; }
33 william 88
34 william 151 public EventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged { get; set; }
35    
36    
37    
38 william 88 public new void Show() { this.Show(null); }
39 william 150 //public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
40     public new void Show(DockPanel panel) { this.PreInitShow(panel); }
41     //public new DialogResult ShowDialog() { return this.ShowDialog(null); }
42     //public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }
43     //private void PreInitShow(IWin32Window owner)
44     //{
45     // if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.",plugin.ToString())); }
46     // else { if (owner == null) { base.Show(); } else { base.Show(owner); } }
47     //}
48     private void PreInitShow(DockPanel panel)
49 william 88 {
50 william 150 //if (panel == null) return;
51 william 152 if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.", ConfigPlugin.ToString())); }
52 william 150 else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
53 william 88 }
54 william 150 //private DialogResult PreInitDialog(IWin32Window owner)
55     //{
56     // if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.", plugin.ToString())); return DialogResult.Cancel; }
57     // else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }
58     //}
59 william 88 private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; }
60     private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; }
61     private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; }
62     private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; }
63     private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; }
64    
65     private void btnOK_Click(object sender, EventArgs e)
66     {
67     if (!(lstProcessList.SelectedItems.Count > 0)) return;
68     this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);
69 william 151 //this.Close();
70     if (this.OnSelectedProcessChanged != null)
71     {
72     this.OnSelectedProcessChanged(this, new ProcessChangedEventArgs(this.SelectedPid));
73     }
74 william 88 }
75    
76 william 151 //private void btnCancel_Click(object sender, EventArgs e)
77     //{
78     // this.SelectedPid = -1;
79     // //this.Close();
80     //}
81 william 88
82     private void btnRefresh_Click(object sender, EventArgs e)
83     {
84     this.RefreshList();
85     }
86    
87     private bool RefreshList()
88     {
89     lstProcessList.Items.Clear();
90 william 152 this.ConfigPlugin.Reload();
91 william 88 // create a selection of PCSX2 processes
92 william 152 List<ProcContainer> proc_list = ConfigPlugin.ValidProcessesForPlugin;
93 william 88
94     if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one.");
95     return false; }
96    
97     List<ListViewItem> items = new List<ListViewItem>();
98     ImageList small_image_list = new ImageList();
99     ImageList large_image_list = new ImageList();
100 william 109
101 william 110 int small_width = 32;
102     int large_width = 48;
103 william 109
104     small_image_list.ImageSize = new Size(small_width, small_width);
105     large_image_list.ImageSize = new Size(large_width, large_width);
106     foreach (ProcContainer p in proc_list)
107     {
108     Bitmap small_image = null;
109     Bitmap large_image = null;
110     string image_key = string.Empty;
111     this.AddProcessItem(p, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image);
112     if (image_key != string.Empty)
113     {
114     if (small_image != null) { small_image_list.Images.Add(image_key, small_image); }
115     if (large_image != null) { large_image_list.Images.Add(image_key, large_image); }
116     ListViewItem item = new ListViewItem();
117     // process name
118     item.Text = p.Name;
119     // pid
120     item.SubItems.Add(p.ProcessInfo.Id.ToString());
121     // FullPath
122     item.SubItems.Add(p.FileName);
123     // image key
124     item.ImageKey = p.FileName;
125     if (!items.Contains(item)) items.Add(item);
126     }
127     else
128     {
129     logger.Error.Write("image_key is an empty string!");
130     if (small_image != null) { logger.Error.Write(" [however small_image is not null]"); }
131     if (large_image != null) { logger.Error.Write(" [however large_image is not null]\n"); }
132     }
133     }
134 william 88 lstProcessList.SmallImageList = small_image_list;
135     lstProcessList.LargeImageList = large_image_list;
136     this.lstProcessList.Items.AddRange(items.ToArray());
137     return true;
138     }
139    
140 william 109 private void AddProcessItem(ProcContainer p, Size small, Size large, out string image_key, out Bitmap small_image, out Bitmap large_image)
141 william 88 {
142 william 109 image_key = "";
143     small_image = null;
144     large_image = null;
145     ////small_image_list = new ImageList();
146     ////large_image_list = new ImageList();
147     //ListViewItem item = new ListViewItem();
148     //// process
149     //item.Text = p.Name;
150     //if (p.ProcessIcon != null)
151     //{
152     // //small_image_list.Images.Add(
153     // //large_image_list.Images.Add(p.FileName, p.ProcessIcon);
154     // item.ImageKey = p.FileName;
155     //}
156     //// pid
157     //item.SubItems.Add(p.ProcessInfo.Id.ToString());
158     //// FullPath
159     //item.SubItems.Add(p.FileName);
160     //if (!items.Contains(item)) items.Add(item);
161     if (p != null)
162 william 88 {
163 william 109 if (p.ProcessIcon != null)
164     {
165     image_key = p.FileName;
166     small_image = new Bitmap(p.ProcessIcon, small);
167     large_image = new Bitmap(p.ProcessIcon, large);
168     }
169 william 88 }
170 william 109
171 william 88 }
172 william 152
173     private void PIDSelector_Load(object sender, EventArgs e)
174     {
175     if (ConfigPlugin == null || this.DesignMode) return;
176     btnRefresh.PerformClick();
177     }
178 william 88 }
179 william 151
180     #region eventargs
181     public class ProcessChangedEventArgs : EventArgs
182     {
183     public ProcessChangedEventArgs() : this(-1) { }
184     public ProcessChangedEventArgs(int pid) { this.ProcessID = pid; }
185     public int ProcessID { get; private set; }
186     }
187     #endregion
188 william 88 }
189