/[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 149 by william, Sun May 27 23:34:33 2012 UTC revision 196 by william, Thu May 31 05:52:41 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; }          public PIDSelector() { InitializeComponent(); this.ProcessPID = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
23          public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = 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    
30          private int _SelectedPid;          #region IAcceptsProcessPID
31          public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }          public int ProcessPID { get; set; }
32            #endregion
33            #region IAcceptsPlugin<IConfigPlugin> members
34            public IConfigPlugin AcceptedPlugin { get; set; }
35            #endregion
36            #region IAcceptsChangedProcess members
37            public BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged { get; set; }
38            #endregion
39            
40    
41    
42          public new void Show() { this.Show(null); }          public new void Show() { this.Show(null); }
43          public new void Show(IWin32Window owner) { this.PreInitShow(owner); }          //public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
44          public new DialogResult ShowDialog() { return this.ShowDialog(null); }          public new void Show(DockPanel panel) { this.PreInitShow(panel); }
45          public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }          //public new DialogResult ShowDialog() { return this.ShowDialog(null); }
46          private void PreInitShow(IWin32Window owner)          //public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }
47          {          //private void PreInitShow(IWin32Window owner)
48              if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.",plugin.ToString())); }          //{
49              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())); }
50          }          //    else { if (owner == null) { base.Show(); } else { base.Show(owner); } }
51          private DialogResult PreInitDialog(IWin32Window owner)          //}
52          {          private void PreInitShow(DockPanel panel)
53              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; }          {
54              else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }              //if (panel == null) return;
55          }              if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", AcceptedPlugin.ToString())); }
56                else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
57            }
58            //private DialogResult PreInitDialog(IWin32Window owner)
59            //{
60            //    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; }
61            //    else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }
62            //}
63          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; }
64          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; }
65          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; }
66          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; }
67          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; }
68    
69          private void btnOK_Click(object sender, EventArgs e)          private void PerformListViewItemSelect(ListViewItem li)
70          {          {
71              if (!(lstProcessList.SelectedItems.Count > 0)) return;              this.ProcessPID = Convert.ToInt32(li.SubItems[1].Text);
72              this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);              //this.Close();
73              this.Close();              if (this.OnSelectedProcessChanged != null)
74                {
75                    this.OnSelectedProcessChanged(new ProcessChangedEventArgs(this.ProcessPID));
76                }
77                Process SelectedProcess = Process.GetProcessById(this.ProcessPID);
78                logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName);
79          }          }
80            private void btnOK_Click(object sender, EventArgs e)
         private void btnCancel_Click(object sender, EventArgs e)  
81          {          {
82              this.SelectedPid = -1;              
             this.Close();  
83          }          }
84    
85            //private void btnCancel_Click(object sender, EventArgs e)
86            //{
87            //    this.SelectedPid = -1;
88            //    //this.Close();
89            //}
90    
91          private void btnRefresh_Click(object sender, EventArgs e)          private void btnRefresh_Click(object sender, EventArgs e)
92          {          {
93              this.RefreshList();              this.RefreshList();
# Line 71  namespace RomCheater.Docking Line 96  namespace RomCheater.Docking
96          private bool RefreshList()          private bool RefreshList()
97          {          {
98              lstProcessList.Items.Clear();              lstProcessList.Items.Clear();
99              this.plugin.Reload();              this.AcceptedPlugin.Reload();
100              // create a selection of PCSX2 processes              // create a selection of PCSX2 processes
101              List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin;              List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
102    
103              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.");
104                  return false; }                  return false; }
# Line 110  namespace RomCheater.Docking Line 135  namespace RomCheater.Docking
135                  }                  }
136                  else                  else
137                  {                  {
138                      logger.Error.Write("image_key is an empty string!");                      //logger.Error.WriteLine("image_key is an empty string!");
139                      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]"); }
140                      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"); }
141                  }                  }
142              }              }
143              lstProcessList.SmallImageList = small_image_list;              lstProcessList.SmallImageList = small_image_list;
144              lstProcessList.LargeImageList = large_image_list;              lstProcessList.LargeImageList = large_image_list;
145              this.lstProcessList.Items.AddRange(items.ToArray());              this.lstProcessList.Items.AddRange(items.ToArray());
146    
147                if (lstProcessList.Items.Count > 0)
148                {
149                    lstProcessList.Items[0].Selected = true;
150                }
151    
152              return true;              return true;
153          }          }
154    
# Line 153  namespace RomCheater.Docking Line 184  namespace RomCheater.Docking
184              }              }
185    
186          }          }
187    
188            private void PIDSelector_Load(object sender, EventArgs e)
189            {
190                if (AcceptedPlugin == null || this.DesignMode) return;
191                btnRefresh.PerformClick();
192            }
193    
194    
195            private void lstProcessList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
196            {
197                if (!e.IsSelected) return;
198                PerformListViewItemSelect(e.Item);
199            }
200    
201            private void lstProcessList_ItemActivate(object sender, EventArgs e)
202            {
203                ListViewItem Item = lstProcessList.SelectedItems[0];
204                PerformListViewItemSelect(Item);
205            }
206    
207    
208      }      }
209  }  }
210    

Legend:
Removed from v.149  
changed lines
  Added in v.196

  ViewVC Help
Powered by ViewVC 1.1.22