/[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/Docking/PIDSelector.cs	2012/05/27 23:59:22	150
+++ trunk/RomCheater/Docking/PIDSelector.cs	2012/05/28 02:20:29	153
@@ -14,12 +14,12 @@
 
 namespace RomCheater.Docking
 {
-    public partial class PIDSelector : DockContent
+    public partial class PIDSelector : DockContent, IAcceptsPlugin<IConfigPlugin>
     {
-        private IConfigPlugin plugin = null;
+        //private IConfigPlugin plugin = null;
         //bool isInError = false;
-        public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; }
-        public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = plugin; }
+        public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
+        public PIDSelector(IConfigPlugin plugin) : this() { this.AcceptedPlugin = plugin; }
         // unsued construtor (it's not implmented, may not be)
         [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]
         public PIDSelector(int pid) : this() { this.SelectedPid = pid; }
@@ -29,6 +29,11 @@
         private int _SelectedPid;
         public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }
 
+        public IConfigPlugin AcceptedPlugin { get; set; }
+
+        public EventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged { get; set; }
+        
+
 
         public new void Show() { this.Show(null); }
         //public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
@@ -43,7 +48,7 @@
         private void PreInitShow(DockPanel panel)
         {
             //if (panel == null) return;
-            if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", plugin.ToString())); }
+            if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", AcceptedPlugin.ToString())); }
             else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
         }
         //private DialogResult PreInitDialog(IWin32Window owner)
@@ -61,14 +66,18 @@
         {
             if (!(lstProcessList.SelectedItems.Count > 0)) return;
             this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);
-            this.Close();
+            //this.Close();
+            if (this.OnSelectedProcessChanged != null)
+            {
+                this.OnSelectedProcessChanged(this, new ProcessChangedEventArgs(this.SelectedPid));
+            }
         }
 
-        private void btnCancel_Click(object sender, EventArgs e)
-        {
-            this.SelectedPid = -1;
-            this.Close();
-        }
+        //private void btnCancel_Click(object sender, EventArgs e)
+        //{
+        //    this.SelectedPid = -1;
+        //    //this.Close();
+        //}
 
         private void btnRefresh_Click(object sender, EventArgs e)
         {
@@ -78,9 +87,9 @@
         private bool RefreshList()
         {
             lstProcessList.Items.Clear();
-            this.plugin.Reload();
+            this.AcceptedPlugin.Reload();
             // create a selection of PCSX2 processes
-            List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin;
+            List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
 
             if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one."); 
                 return false; }
@@ -160,6 +169,21 @@
             }
 
         }
+
+        private void PIDSelector_Load(object sender, EventArgs e)
+        {
+            if (AcceptedPlugin == null || this.DesignMode) return;
+            btnRefresh.PerformClick();
+        }
+    }
+
+    #region eventargs
+    public class ProcessChangedEventArgs : EventArgs
+    {
+        public ProcessChangedEventArgs() : this(-1) { }
+        public ProcessChangedEventArgs(int pid) { this.ProcessID = pid; }
+        public int ProcessID { get; private set; }
     }
+    #endregion
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22