/[EmuXPortal]/trunk/EmuXPortal/Form1.cs
ViewVC logotype

Diff of /trunk/EmuXPortal/Form1.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/EmuXPortal/Form1.cs	2013/10/08 18:39:46	160
+++ trunk/EmuXPortal/Form1.cs	2014/08/04 03:27:49	168
@@ -46,7 +46,177 @@
             c.BorderStyle = BorderStyle.FixedSingle;
             CurrentPlatformControl = c;
         }
+        void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
+        {
+            GameControl c = sender as GameControl;
+
+            int changeAmount = 0;
+            int currentPosition = 0;
+
+            if (e.KeyCode == Keys.F && e.Modifiers.HasFlag(Keys.Control))
+            {
+                IRomConfig config = c.Tag as IRomConfig;
+                if (config == null)
+                {
+                    log.WriteLine("Unable to add/remove from/to favorites (config is null): {0} [{1}]", config.RomTitle, config.RomFile);
+                }
+                else
+                {
+                    var isFavorite = RomFavorite.IsFavorite(config);
+                    if (isFavorite)
+                    {
+                        // add to favorites
+                        log.WriteLine("Removing from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        if (!RomFavorite.RemoveFavorite(config))
+                        {
+                            log.WriteLine("Failed to remove from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        }
+                        else
+                        {
+                            log.WriteLine("Removed from favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        }
+                    }
+                    else
+                    {
+                        // add to favorites
+                        log.WriteLine("Adding to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        if (!RomFavorite.AddFavorite(config))
+                        {
+                            log.WriteLine("Failed to add to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        }
+                        else
+                        {
+                            log.WriteLine("Added to favorites: {0} [{1}]", config.RomTitle, config.RomFile);
+                        }
+                    }
+                    log.WriteLine("Updateing favorites");
+                    if (!RomFavorite.UpdateFavorites())
+                    {
+                        log.WriteLine("Failed to update favorites");
+                    }
+                    else
+                    {
+                        log.WriteLine("Updated favorites");
+                    }
+                }
+                return; // stop processing other keys
 
+            }
+            if (e.KeyCode == Keys.Home)
+            {
+                rom_flow.Controls[0].Select();
+                rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
+            }
+            if (e.KeyCode == Keys.End)
+            {
+                rom_flow.Controls[rom_flow.Controls.Count - 1].Select();
+                rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]);
+            }
+            if (e.KeyCode == Keys.PageUp)
+            {
+                changeAmount = rom_flow.VerticalScroll.LargeChange;
+                currentPosition = rom_flow.VerticalScroll.Value;
+                if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum)
+                {
+                    try
+                    {
+                        rom_flow.VerticalScroll.Value += changeAmount;
+                    }
+                    catch
+                    {
+                        rom_flow.Controls[0].Select();
+                        rom_flow.ScrollControlIntoView(platform_flow.Controls[0]);
+                        rom_flow.PerformLayout();
+                        return;
+                    }
+                }
+                else
+                {
+                    rom_flow.Controls[0].Select();
+                    rom_flow.ScrollControlIntoView(platform_flow.Controls[0]);
+                }
+                GameControl s = game_ctrl_get_last_visible();
+                s.Select();
+                rom_flow.ScrollControlIntoView(s);
+                rom_flow.PerformLayout();
+            }
+            if (e.KeyCode == Keys.PageDown)
+            {
+                changeAmount = rom_flow.VerticalScroll.LargeChange;
+                currentPosition = rom_flow.VerticalScroll.Value;
+                if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum)
+                {
+                    rom_flow.VerticalScroll.Value += changeAmount;
+                }
+                else
+                {
+                    rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
+                }
+                GameControl s = game_ctrl_get_last_visible();
+                s.Select();
+                rom_flow.ScrollControlIntoView(s);
+                rom_flow.PerformLayout();
+            }
+
+            if (e.KeyCode == Keys.Enter)
+            {
+                IRomConfig config = c.Tag as IRomConfig;
+
+                Process p = new Process();
+
+                p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe;
+                p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(log, config) : config.Config.GameExeArgs;
+                p.Start();
+
+                // minimize EmuXPortal
+                this.WindowState = FormWindowState.Minimized;
+                // wait for exit of game
+                p.WaitForExit();
+                // maximize EmuXPortal
+                this.WindowState = FormWindowState.Maximized;
+            }
+            if (e.KeyCode == Keys.Back)
+            {
+                rom_flow.Visible = false;
+                platform_flow.Visible = true;
+            }
+
+            if ((e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) ||
+                (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
+            {
+                char t = (char)e.KeyCode;
+                GameControl ctrl = (rom_flow.GetNextControl(CurrentPlatformControl, true) as GameControl);
+                if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); }
+                bool found = false;
+                GameControl pc = CurrentGameControl;
+                bool wrapped = false;
+                bool not_found = true;
+                while (!found)
+                {
+                    if (wrapped)
+                    {
+                        foreach (Control ctl in rom_flow.Controls)
+                        {
+                            GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
+                        }
+                        if (not_found) { found = true; }
+                    }
+                    ctrl = (rom_flow.GetNextControl(pc, true) as GameControl);
+                    if (ctrl == null)
+                    {
+                        ctrl = rom_flow.Controls[0] as GameControl;
+                        wrapped = true;
+                    }
+                    if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower()))
+                    {
+                        rom_flow.ScrollControlIntoView(ctrl);
+                        ctrl.Select();
+                        found = true;
+                    }
+                    pc = ctrl;
+                }
+            }
+        }
         void platform_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
         {
             PlatformControl c = sender as PlatformControl;
@@ -211,127 +381,7 @@
             }
             return s;
         }
-        void game_ctrl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
-        {
-            GameControl c = sender as GameControl;
-
-            int changeAmount = 0;
-            int currentPosition = 0;
-            if (e.KeyCode == Keys.Home)
-            {
-                rom_flow.Controls[0].Select();
-                rom_flow.ScrollControlIntoView(rom_flow.Controls[0]);
-            }
-            if (e.KeyCode == Keys.End)
-            {
-                rom_flow.Controls[rom_flow.Controls.Count - 1].Select();
-                rom_flow.ScrollControlIntoView(rom_flow.Controls[rom_flow.Controls.Count - 1]);
-            }
-            if (e.KeyCode == Keys.PageUp)
-            {
-                changeAmount = rom_flow.VerticalScroll.LargeChange;
-                currentPosition = rom_flow.VerticalScroll.Value;
-                if ((currentPosition - changeAmount) > rom_flow.VerticalScroll.Minimum)
-                {
-                    try
-                    {
-                        rom_flow.VerticalScroll.Value += changeAmount;
-                    }
-                    catch
-                    {
-                        rom_flow.Controls[0].Select();
-                        rom_flow.ScrollControlIntoView(platform_flow.Controls[0]);
-                        rom_flow.PerformLayout();
-                        return;
-                    }
-                }
-                else
-                {
-                    rom_flow.Controls[0].Select();
-                    rom_flow.ScrollControlIntoView(platform_flow.Controls[0]);
-                }
-                GameControl s = game_ctrl_get_last_visible();
-                s.Select();
-                rom_flow.ScrollControlIntoView(s);
-                rom_flow.PerformLayout();
-            }
-            if (e.KeyCode == Keys.PageDown)
-            {
-                changeAmount = rom_flow.VerticalScroll.LargeChange;
-                currentPosition = rom_flow.VerticalScroll.Value;
-                if ((currentPosition - changeAmount) < rom_flow.VerticalScroll.Maximum)
-                {
-                    rom_flow.VerticalScroll.Value += changeAmount;
-                }
-                else
-                {
-                    rom_flow.VerticalScroll.Value = rom_flow.VerticalScroll.Maximum;
-                }
-                GameControl s = game_ctrl_get_last_visible();
-                s.Select();
-                rom_flow.ScrollControlIntoView(s);
-                rom_flow.PerformLayout();
-            }
-
-            if (e.KeyCode == Keys.Enter)
-            {
-                IRomConfig config = c.Tag as IRomConfig;
-
-                Process p = new Process();
-
-                p.StartInfo.FileName = config.Config.GameExe == "" ? config.Config.EmuPath : config.Config.GameExe;
-                p.StartInfo.Arguments = config.Config.GameExeArgs == "" ? EmuConfigLoader.GetEMUOptions(log, config) : config.Config.GameExeArgs;
-                p.Start();
-
-                // minimize EmuXPortal
-                this.WindowState = FormWindowState.Minimized;
-                // wait for exit of game
-                p.WaitForExit();
-                // maximize EmuXPortal
-                this.WindowState = FormWindowState.Maximized;
-            }
-            if (e.KeyCode == Keys.Back)
-            {
-                rom_flow.Visible = false;
-                platform_flow.Visible = true;
-            }
-
-            if ( (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z) || 
-                (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9))
-            {
-                char t = (char)e.KeyCode;
-                GameControl ctrl = (rom_flow.GetNextControl(CurrentPlatformControl, true) as GameControl);
-                if (ctrl == null) { ctrl = (rom_flow.GetNextControl(rom_flow.Controls[0], true) as GameControl); }
-                bool found = false;
-                GameControl pc = CurrentGameControl;
-                bool wrapped = false;
-                bool not_found = true;
-                while (!found)
-                {
-                    if (wrapped)
-                    {
-                        foreach (Control ctl in rom_flow.Controls)
-                        {
-                            GameControl p_ctl = ctl as GameControl; if (p_ctl.GameName.ToLower().StartsWith(t.ToString().ToLower())) { not_found = false; }
-                        }
-                        if (not_found) { found = true; }
-                    }
-                    ctrl = (rom_flow.GetNextControl(pc, true) as GameControl);
-                    if (ctrl == null)
-                    {
-                        ctrl = rom_flow.Controls[0] as GameControl;
-                        wrapped = true;
-                    }
-                    if (ctrl.GameName.ToLower().StartsWith(t.ToString().ToLower()))
-                    {
-                        rom_flow.ScrollControlIntoView(ctrl);
-                        ctrl.Select();
-                        found = true;
-                    }
-                    pc = ctrl;
-                }           
-            }
-        }
+      
 
         #region Background Workers
 

 

  ViewVC Help
Powered by ViewVC 1.1.22