/[RomCheater]/trunk/RomCheater/Docking/PIDSelector.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/PIDSelector.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/RomCheater/PIDSelector.cs revision 109 by william, Thu May 10 12:12:26 2012 UTC trunk/RomCheater/Docking/PIDSelector.cs revision 156 by william, Mon May 28 04:14:03 2012 UTC
# Line 10  using RomCheater.PluginFramework.Interfa Line 10  using RomCheater.PluginFramework.Interfa
10  using RomCheater.PluginFramework.Core;  using RomCheater.PluginFramework.Core;
11  using System.IO;  using System.IO;
12  using RomCheater.Logging;  using RomCheater.Logging;
13    using WeifenLuo.WinFormsUI.Docking;
14    
15  namespace RomCheater  namespace RomCheater.Docking
16  {  {
17      public partial class PIDSelector : Form      public partial class PIDSelector : DockContent, IAcceptsPlugin<IConfigPlugin>
18      {      {
19          private IConfigPlugin plugin = null;          //private IConfigPlugin plugin = null;
20          //bool isInError = false;          //bool isInError = false;
21          public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; }          public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
22          public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = plugin; }          public PIDSelector(IConfigPlugin plugin) : this() { this.AcceptedPlugin = plugin; }
23          // unsued construtor (it's not implmented, may not be)          // unsued construtor (it's not implmented, may not be)
24          [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]          [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]
25          public PIDSelector(int pid) : this() { this.SelectedPid = pid; }          public PIDSelector(int pid) : this() { this.SelectedPid = pid; }
# Line 28  namespace RomCheater Line 29  namespace RomCheater
29          private int _SelectedPid;          private int _SelectedPid;
30          public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }          public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }
31    
32            public IConfigPlugin AcceptedPlugin { get; set; }
33    
34            public EventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged { get; set; }
35            
36    
37    
38          public new void Show() { this.Show(null); }          public new void Show() { this.Show(null); }
39          public new void Show(IWin32Window owner) { this.PreInitShow(owner); }          //public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
40          public new DialogResult ShowDialog() { return this.ShowDialog(null); }          public new void Show(DockPanel panel) { this.PreInitShow(panel); }
41          public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }          //public new DialogResult ShowDialog() { return this.ShowDialog(null); }
42          private void PreInitShow(IWin32Window owner)          //public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }
43          {          //private void PreInitShow(IWin32Window owner)
44              if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.",plugin.ToString())); }          //{
45              else { if (owner == null) { base.Show(); } else { base.Show(owner); } }          //    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          private DialogResult PreInitDialog(IWin32Window owner)          //}
48          {          private void PreInitShow(DockPanel panel)
49              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; }          {
50              else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }              //if (panel == null) return;
51          }              if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", AcceptedPlugin.ToString())); }
52                else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
53            }
54            //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          private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; }          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; }          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; }          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; }          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; }          private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; }
64    
65          private void btnOK_Click(object sender, EventArgs e)          private void PerformListViewItemSelect(ListViewItem li)
66          {          {
67              if (!(lstProcessList.SelectedItems.Count > 0)) return;              this.SelectedPid = Convert.ToInt32(li.SubItems[1].Text);
68              this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);              //this.Close();
69              this.Close();              if (this.OnSelectedProcessChanged != null)
70                {
71                    this.OnSelectedProcessChanged(this, new ProcessChangedEventArgs(this.SelectedPid));
72                }
73                Process SelectedProcess = Process.GetProcessById(this.SelectedPid);
74                logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName);
75          }          }
76            private void btnOK_Click(object sender, EventArgs e)
         private void btnCancel_Click(object sender, EventArgs e)  
77          {          {
78              this.SelectedPid = -1;              
             this.Close();  
79          }          }
80    
81            //private void btnCancel_Click(object sender, EventArgs e)
82            //{
83            //    this.SelectedPid = -1;
84            //    //this.Close();
85            //}
86    
87          private void btnRefresh_Click(object sender, EventArgs e)          private void btnRefresh_Click(object sender, EventArgs e)
88          {          {
89              this.RefreshList();              this.RefreshList();
# Line 70  namespace RomCheater Line 92  namespace RomCheater
92          private bool RefreshList()          private bool RefreshList()
93          {          {
94              lstProcessList.Items.Clear();              lstProcessList.Items.Clear();
95              this.plugin.Reload();              this.AcceptedPlugin.Reload();
96              // create a selection of PCSX2 processes              // create a selection of PCSX2 processes
97              List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin;              List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
98    
99              if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one.");              if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one.");
100                  return false; }                  return false; }
# Line 81  namespace RomCheater Line 103  namespace RomCheater
103              ImageList small_image_list = new ImageList();              ImageList small_image_list = new ImageList();
104              ImageList large_image_list = new ImageList();              ImageList large_image_list = new ImageList();
105    
106              int small_width = 16;              int small_width = 32;
107              int large_width = 32;              int large_width = 48;
108    
109              small_image_list.ImageSize = new Size(small_width, small_width);              small_image_list.ImageSize = new Size(small_width, small_width);
110              large_image_list.ImageSize = new Size(large_width, large_width);              large_image_list.ImageSize = new Size(large_width, large_width);
# Line 109  namespace RomCheater Line 131  namespace RomCheater
131                  }                  }
132                  else                  else
133                  {                  {
134                      logger.Error.Write("image_key is an empty string!");                      //logger.Error.WriteLine("image_key is an empty string!");
135                      if (small_image != null) { logger.Error.Write(" [however small_image is not null]"); }                      //if (small_image != null) { logger.Error.WriteLine(" [however small_image is not null]"); }
136                      if (large_image != null) { logger.Error.Write(" [however large_image is not null]\n"); }                      //if (large_image != null) { logger.Error.WriteLine(" [however large_image is not null]\n"); }
137                  }                  }
138              }              }
139              lstProcessList.SmallImageList = small_image_list;              lstProcessList.SmallImageList = small_image_list;
140              lstProcessList.LargeImageList = large_image_list;              lstProcessList.LargeImageList = large_image_list;
141              this.lstProcessList.Items.AddRange(items.ToArray());              this.lstProcessList.Items.AddRange(items.ToArray());
142    
143                if (lstProcessList.Items.Count > 0)
144                {
145                    lstProcessList.Items[0].Selected = true;
146                }
147    
148              return true;              return true;
149          }          }
150    
# Line 152  namespace RomCheater Line 180  namespace RomCheater
180              }              }
181    
182          }          }
183    
184            private void PIDSelector_Load(object sender, EventArgs e)
185            {
186                if (AcceptedPlugin == null || this.DesignMode) return;
187                btnRefresh.PerformClick();
188            }
189    
190    
191            private void lstProcessList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
192            {
193                if (!e.IsSelected) return;
194                PerformListViewItemSelect(e.Item);
195            }
196    
197            private void lstProcessList_ItemActivate(object sender, EventArgs e)
198            {
199                ListViewItem Item = lstProcessList.SelectedItems[0];
200                PerformListViewItemSelect(Item);
201            }
202    
203    
204        }
205    
206        #region eventargs
207        public class ProcessChangedEventArgs : EventArgs
208        {
209            public ProcessChangedEventArgs() : this(-1) { }
210            public ProcessChangedEventArgs(int pid) { this.ProcessID = pid; }
211            public int ProcessID { get; private set; }
212      }      }
213        #endregion
214  }  }
215    

Legend:
Removed from v.109  
changed lines
  Added in v.156

  ViewVC Help
Powered by ViewVC 1.1.22