/[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

revision 152 by william, Mon May 28 02:01:34 2012 UTC revision 287 by william, Tue Jun 5 08:52:07 2012 UTC
# Line 11  using RomCheater.PluginFramework.Core; Line 11  using RomCheater.PluginFramework.Core;
11  using System.IO;  using System.IO;
12  using RomCheater.Logging;  using RomCheater.Logging;
13  using WeifenLuo.WinFormsUI.Docking;  using WeifenLuo.WinFormsUI.Docking;
14    using RomCheater.PluginFramework.Events;
15    
16  namespace RomCheater.Docking  namespace RomCheater.Docking
17  {  {
18      public partial class PIDSelector : DockContent      public partial class PIDSelector : DockContent, IAcceptsPlugin<IConfigPlugin>, IAcceptsChangedProcess, IAcceptsProcessPID
19      {      {
20          //private IConfigPlugin plugin = null;          //private IConfigPlugin plugin = null;
21          //bool isInError = false;          //bool isInError = false;
22          public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; OnSelectedProcessChanged = null; }          public PIDSelector() { InitializeComponent(); this.ProcessPID = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
23          public PIDSelector(IConfigPlugin plugin) : this() { this.ConfigPlugin = plugin; }          public PIDSelector(IConfigPlugin plugin) : this() { this.AcceptedPlugin = plugin; }
24          // unsued construtor (it's not implmented, may not be)          // unsued construtor (it's not implmented, may not be)
25          [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]          [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]
26          public PIDSelector(int pid) : this() { this.SelectedPid = pid; }          public PIDSelector(int pid) : this() { this.ProcessPID = pid; }
27          [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]          [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]
28          public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; }          public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.ProcessPID = pid; }
29    
         private int _SelectedPid;  
         public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }  
30    
31          public IConfigPlugin ConfigPlugin { get; set; }          private void OnProcessChanged(ProcessChangedEventArgs e)
32            {
33            }
34    
35          public EventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged { get; set; }          #region IAcceptsProcessPID
36            public int ProcessPID { get; set; }
37            #endregion
38            #region IAcceptsPlugin<IConfigPlugin> members
39            public IConfigPlugin AcceptedPlugin { get; set; }
40            #endregion
41            #region IAcceptsChangedProcess members
42            public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged;
43            #endregion
44                    
45    
46    
# Line 48  namespace RomCheater.Docking Line 57  namespace RomCheater.Docking
57          private void PreInitShow(DockPanel panel)          private void PreInitShow(DockPanel panel)
58          {          {
59              //if (panel == null) return;              //if (panel == null) return;
60              if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", ConfigPlugin.ToString())); }              if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", AcceptedPlugin.ToString())); }
61              else { if (panel == null) { base.Show(); } else { base.Show(panel); } }              else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
62          }          }
63          //private DialogResult PreInitDialog(IWin32Window owner)          //private DialogResult PreInitDialog(IWin32Window owner)
# Line 62  namespace RomCheater.Docking Line 71  namespace RomCheater.Docking
71          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; }
72          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; }
73    
74          private void btnOK_Click(object sender, EventArgs e)          private void PerformListViewItemSelect(ListViewItem li)
75          {          {
76              if (!(lstProcessList.SelectedItems.Count > 0)) return;              this.ProcessPID = Convert.ToInt32(li.SubItems[1].Text);
             this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);  
77              //this.Close();              //this.Close();
78              if (this.OnSelectedProcessChanged != null)              if (OnSelectedProcessChanged != null)
79              {                  OnSelectedProcessChanged(new ProcessChangedEventArgs(this.ProcessPID));
80                  this.OnSelectedProcessChanged(this, new ProcessChangedEventArgs(this.SelectedPid));              Process SelectedProcess = Process.GetProcessById(this.ProcessPID);
81              }              logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName);
82            }
83            private void btnOK_Click(object sender, EventArgs e)
84            {
85                
86          }          }
87    
88          //private void btnCancel_Click(object sender, EventArgs e)          //private void btnCancel_Click(object sender, EventArgs e)
# Line 87  namespace RomCheater.Docking Line 99  namespace RomCheater.Docking
99          private bool RefreshList()          private bool RefreshList()
100          {          {
101              lstProcessList.Items.Clear();              lstProcessList.Items.Clear();
102              this.ConfigPlugin.Reload();              this.AcceptedPlugin.Reload();
103              // create a selection of PCSX2 processes              // create a selection of PCSX2 processes
104              List<ProcContainer> proc_list = ConfigPlugin.ValidProcessesForPlugin;              List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
105    
106              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.");
107                  return false; }                  return false; }
# Line 126  namespace RomCheater.Docking Line 138  namespace RomCheater.Docking
138                  }                  }
139                  else                  else
140                  {                  {
141                      logger.Error.Write("image_key is an empty string!");                      //logger.Error.WriteLine("image_key is an empty string!");
142                      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]"); }
143                      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"); }
144                  }                  }
145              }              }
146              lstProcessList.SmallImageList = small_image_list;              lstProcessList.SmallImageList = small_image_list;
147              lstProcessList.LargeImageList = large_image_list;              lstProcessList.LargeImageList = large_image_list;
148              this.lstProcessList.Items.AddRange(items.ToArray());              this.lstProcessList.Items.AddRange(items.ToArray());
149    
150                if (lstProcessList.Items.Count > 0)
151                {
152                    lstProcessList.Items[0].Selected = true;
153                }
154    
155              return true;              return true;
156          }          }
157    
# Line 172  namespace RomCheater.Docking Line 190  namespace RomCheater.Docking
190    
191          private void PIDSelector_Load(object sender, EventArgs e)          private void PIDSelector_Load(object sender, EventArgs e)
192          {          {
193              if (ConfigPlugin == null || this.DesignMode) return;              if (AcceptedPlugin == null || this.DesignMode) return;
194              btnRefresh.PerformClick();              btnRefresh.PerformClick();
195          }          }
     }  
196    
197      #region eventargs  
198      public class ProcessChangedEventArgs : EventArgs          private void lstProcessList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
199      {          {
200          public ProcessChangedEventArgs() : this(-1) { }              if (!e.IsSelected) return;
201          public ProcessChangedEventArgs(int pid) { this.ProcessID = pid; }              PerformListViewItemSelect(e.Item);
202          public int ProcessID { get; private set; }          }
203    
204            private void lstProcessList_ItemActivate(object sender, EventArgs e)
205            {
206                ListViewItem Item = lstProcessList.SelectedItems[0];
207                PerformListViewItemSelect(Item);
208            }
209    
210    
211      }      }
     #endregion  
212  }  }
213    

Legend:
Removed from v.152  
changed lines
  Added in v.287

  ViewVC Help
Powered by ViewVC 1.1.22