/[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:34:33	149
+++ trunk/RomCheater/Docking/PIDSelector.cs	2012/06/07 16:33:41	323
@@ -11,57 +11,80 @@
 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;
+        //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.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; }
-
-        private int _SelectedPid;
-        public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }
+        public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.ProcessPID = pid; }
+        
+        #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
+        
 
 
         public new void Show() { this.Show(null); }
-        public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
-        public new DialogResult ShowDialog() { return this.ShowDialog(null); }
-        public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }
-        private void PreInitShow(IWin32Window owner)
-        {
-            if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.",plugin.ToString())); }
-            else { if (owner == null) { base.Show(); } else { base.Show(owner); } }
-        }
-        private DialogResult PreInitDialog(IWin32Window owner)
-        {
-            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; }
-            else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }
-        }
+        //public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
+        public new void Show(DockPanel panel) { this.PreInitShow(panel); }
+        //public new DialogResult ShowDialog() { return this.ShowDialog(null); }
+        //public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }
+        //private void PreInitShow(IWin32Window owner)
+        //{
+        //    if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.",plugin.ToString())); }
+        //    else { if (owner == null) { base.Show(); } else { base.Show(owner); } }
+        //}
+        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.", AcceptedPlugin.ToString())); }
+            else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
+        }
+        //private DialogResult PreInitDialog(IWin32Window owner)
+        //{
+        //    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; }
+        //    else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }
+        //}
         private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; }
         private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; }
         private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; }
         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, 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();
+            
         }
 
-        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)
         {
@@ -71,9 +94,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; }
@@ -110,14 +133,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;
         }
 
@@ -153,6 +182,27 @@
             }
 
         }
+
+        private void PIDSelector_Load(object sender, EventArgs e)
+        {
+            if (AcceptedPlugin == null || this.DesignMode) return;
+            btnRefresh.PerformClick();
+        }
+
+
+        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);
+        }
+
+
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22