/[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/28 02:01:34	152
+++ trunk/RomCheater/Docking/PIDSelector.cs	2012/06/05 10:52:57	296
@@ -11,27 +11,36 @@
 using System.IO;
 using RomCheater.Logging;
 using WeifenLuo.WinFormsUI.Docking;
+using RomCheater.PluginFramework.Events;
 
 namespace RomCheater.Docking
 {
-    public partial class PIDSelector : DockContent
+    public partial class PIDSelector : DockContent, IAcceptsPlugin<IConfigPlugin>, IAcceptsChangedProcess, IAcceptsProcessPID
     {
         //private IConfigPlugin plugin = null;
         //bool isInError = false;
-        public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; OnSelectedProcessChanged = null; }
-        public PIDSelector(IConfigPlugin plugin) : this() { this.ConfigPlugin = plugin; }
+        public PIDSelector() { InitializeComponent(); this.ProcessPID = -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; }
+        public PIDSelector(int pid) : this() { this.ProcessPID = pid; }
         [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]
-        public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; }
+        public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.ProcessPID = pid; }
 
-        private int _SelectedPid;
-        public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }
 
-        public IConfigPlugin ConfigPlugin { get; set; }
+        private void OnProcessChanged(ProcessChangedEventArgs e)
+        {
+        }
 
-        public EventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged { get; set; }
+        #region IAcceptsProcessPID
+        public int ProcessPID { get; set; }
+        #endregion
+        #region IAcceptsPlugin<IConfigPlugin> members
+        public IConfigPlugin AcceptedPlugin { get; set; }
+        #endregion
+        #region IAcceptsChangedProcess members
+        public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged;
+        #endregion
         
 
 
@@ -48,7 +57,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.", 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())); }
             else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
         }
         //private DialogResult PreInitDialog(IWin32Window owner)
@@ -62,15 +71,18 @@
         private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; }
         private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; }
 
+        private void PerformListViewItemSelect(ListViewItem li)
+        {            
+            this.ProcessPID = Convert.ToInt32(li.SubItems[1].Text);
+            Process SelectedProcess = Process.GetProcessById(this.ProcessPID);
+            logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName);
+            //this.Close();
+            if (OnSelectedProcessChanged != null)
+                OnSelectedProcessChanged(new ProcessChangedEventArgs(this.ProcessPID));           
+        }
         private void btnOK_Click(object sender, EventArgs e)
         {
-            if (!(lstProcessList.SelectedItems.Count > 0)) return;
-            this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);
-            //this.Close();
-            if (this.OnSelectedProcessChanged != null)
-            {
-                this.OnSelectedProcessChanged(this, new ProcessChangedEventArgs(this.SelectedPid));
-            }
+            
         }
 
         //private void btnCancel_Click(object sender, EventArgs e)
@@ -87,9 +99,9 @@
         private bool RefreshList()
         {
             lstProcessList.Items.Clear();
-            this.ConfigPlugin.Reload();
+            this.AcceptedPlugin.Reload();
             // create a selection of PCSX2 processes
-            List<ProcContainer> proc_list = ConfigPlugin.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; }
@@ -126,14 +138,20 @@
                 }
                 else
                 {
-                    logger.Error.Write("image_key is an empty string!");
-                    if (small_image != null) { logger.Error.Write(" [however small_image is not null]"); }
-                    if (large_image != null) { logger.Error.Write(" [however large_image is not null]\n"); }
+                    //logger.Error.WriteLine("image_key is an empty string!");
+                    //if (small_image != null) { logger.Error.WriteLine(" [however small_image is not null]"); }
+                    //if (large_image != null) { logger.Error.WriteLine(" [however large_image is not null]\n"); }
                 }
             }
             lstProcessList.SmallImageList = small_image_list;
             lstProcessList.LargeImageList = large_image_list;
             this.lstProcessList.Items.AddRange(items.ToArray());
+
+            if (lstProcessList.Items.Count > 0)
+            {
+                lstProcessList.Items[0].Selected = true;
+            }
+
             return true;
         }
 
@@ -172,18 +190,24 @@
 
         private void PIDSelector_Load(object sender, EventArgs e)
         {
-            if (ConfigPlugin == null || this.DesignMode) return;
+            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; }
+
+        private void lstProcessList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
+        {
+            if (!e.IsSelected) return;
+            PerformListViewItemSelect(e.Item);
+        }
+
+        private void lstProcessList_ItemActivate(object sender, EventArgs e)
+        {
+            ListViewItem Item = lstProcessList.SelectedItems[0];
+            PerformListViewItemSelect(Item);
+        }
+
+
     }
-    #endregion
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22