PCE CDL - remember window position and size, restore defaults, make Open and Save file dialogs look pretty, don't enable save as menu item if no cdl started since it nags you if you choose it

This commit is contained in:
adelikat 2014-04-13 12:22:53 +00:00
parent aaeb2c9cdd
commit e67c329aad
3 changed files with 148 additions and 36 deletions

View File

@ -47,8 +47,10 @@
this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem();
this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CdlTextbox = new System.Windows.Forms.TextBox();
this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.RestoreDefaultSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CdlTextbox = new System.Windows.Forms.TextBox();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -93,6 +95,7 @@
this.FileSubMenu.Name = "FileSubMenu"; this.FileSubMenu.Name = "FileSubMenu";
this.FileSubMenu.Size = new System.Drawing.Size(37, 20); this.FileSubMenu.Size = new System.Drawing.Size(37, 20);
this.FileSubMenu.Text = "&File"; this.FileSubMenu.Text = "&File";
this.FileSubMenu.DropDownOpened += new System.EventHandler(this.FileSubMenu_DropDownOpened);
// //
// NewMenuItem // NewMenuItem
// //
@ -190,7 +193,9 @@
this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveWindowPositionMenuItem, this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem, this.AlwaysOnTopMenuItem,
this.FloatingWindowMenuItem}); this.FloatingWindowMenuItem,
this.toolStripSeparator3,
this.RestoreDefaultSettingsMenuItem});
this.OptionsSubMenu.Name = "OptionsSubMenu"; this.OptionsSubMenu.Name = "OptionsSubMenu";
this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20); this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20);
this.OptionsSubMenu.Text = "&Options"; this.OptionsSubMenu.Text = "&Options";
@ -199,17 +204,36 @@
// SaveWindowPositionMenuItem // SaveWindowPositionMenuItem
// //
this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem"; this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem";
this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(191, 22); this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(199, 22);
this.SaveWindowPositionMenuItem.Text = "Save Window Position"; this.SaveWindowPositionMenuItem.Text = "Save Window Position";
this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click); this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click);
// //
// AlwaysOnTopMenuItem // AlwaysOnTopMenuItem
// //
this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem"; this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem";
this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(191, 22); this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(199, 22);
this.AlwaysOnTopMenuItem.Text = "&Always On Top"; this.AlwaysOnTopMenuItem.Text = "&Always On Top";
this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click); this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
// //
// FloatingWindowMenuItem
//
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(199, 22);
this.FloatingWindowMenuItem.Text = "&Floating Window";
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(196, 6);
//
// RestoreDefaultSettingsMenuItem
//
this.RestoreDefaultSettingsMenuItem.Name = "RestoreDefaultSettingsMenuItem";
this.RestoreDefaultSettingsMenuItem.Size = new System.Drawing.Size(199, 22);
this.RestoreDefaultSettingsMenuItem.Text = "Restore Default Settings";
this.RestoreDefaultSettingsMenuItem.Click += new System.EventHandler(this.RestoreDefaultSettingsMenuItem_Click);
//
// CdlTextbox // CdlTextbox
// //
this.CdlTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.CdlTextbox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -222,13 +246,6 @@
this.CdlTextbox.Size = new System.Drawing.Size(292, 211); this.CdlTextbox.Size = new System.Drawing.Size(292, 211);
this.CdlTextbox.TabIndex = 3; this.CdlTextbox.TabIndex = 3;
// //
// FloatingWindowMenuItem
//
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(191, 22);
this.FloatingWindowMenuItem.Text = "&Floating Window";
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
//
// PCECDL // PCECDL
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -239,6 +256,7 @@
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip1; this.MainMenuStrip = this.menuStrip1;
this.MinimumSize = new System.Drawing.Size(150, 130);
this.Name = "PCECDL"; this.Name = "PCECDL";
this.Text = "Code Data Logger"; this.Text = "Code Data Logger";
this.Load += new System.EventHandler(this.PCECDL_Load); this.Load += new System.EventHandler(this.PCECDL_Load);
@ -271,6 +289,8 @@
private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem; private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem; private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem; private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem RestoreDefaultSettingsMenuItem;
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using System.IO; using System.IO;
using System.Windows.Forms; using System.Windows.Forms;
@ -14,18 +15,37 @@ namespace BizHawk.Client.EmuHawk
// TODO // TODO
// Loading doesn't work // Loading doesn't work
// Save // Save
// Save Window position and size // Drag and drop cdl files
// Restore settings // Drag and drop cdl files onto Main window?
private PCEngine _emu; private PCEngine _emu;
private CodeDataLog _cdl; private CodeDataLog _cdl;
private int _defaultWidth;
private int _defaultHeight;
public PCECDL() public PCECDL()
{ {
InitializeComponent(); InitializeComponent();
TopMost = Global.Config.PceCdlSettings.TopMost; TopMost = Global.Config.PceCdlSettings.TopMost;
Closing += (o, e) =>
{
SaveConfigSettings();
};
Restart(); Restart();
} }
private void PCECDL_Load(object sender, EventArgs e)
{
LoadConfigSettings();
if (Global.Config.RecentPceCdlFiles.AutoLoad)
{
LoadFileFromRecent(Global.Config.RecentPceCdlFiles.MostRecent);
}
}
public void UpdateValues() public void UpdateValues()
{ {
UpdateDisplay(); UpdateDisplay();
@ -112,8 +132,38 @@ namespace BizHawk.Client.EmuHawk
} }
} }
private void SaveConfigSettings()
{
Global.Config.PceCdlSettings.Wndx = Location.X;
Global.Config.PceCdlSettings.Wndy = Location.Y;
Global.Config.PceCdlSettings.Width = Right - Left;
Global.Config.PceCdlSettings.Height = Bottom - Top;
}
private void LoadConfigSettings()
{
// Size and Positioning
_defaultWidth = Size.Width;
_defaultHeight = Size.Height;
if (Global.Config.PceCdlSettings.UseWindowPosition)
{
Location = Global.Config.PceCdlSettings.WindowPosition;
}
if (Global.Config.PceCdlSettings.UseWindowSize)
{
Size = Global.Config.PceCdlSettings.WindowSize;
}
}
#region Events #region Events
private void FileSubMenu_DropDownOpened(object sender, EventArgs e)
{
SaveAsMenuItem.Enabled = _cdl != null;
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
{ {
RecentSubMenu.DropDownItems.Clear(); RecentSubMenu.DropDownItems.Clear();
@ -139,11 +189,10 @@ namespace BizHawk.Client.EmuHawk
var result = MessageBox.Show(this, "OK to load new CDL?", "Query", MessageBoxButtons.YesNo); var result = MessageBox.Show(this, "OK to load new CDL?", "Query", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
var ofd = new OpenFileDialog(); var file = ToolHelpers.GetCdlFileFromUser(string.Empty /*TODO*/);
result = ofd.ShowDialog(this); if (file != null)
if (result == DialogResult.OK)
{ {
using (var fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read)) using (var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
{ {
var newCDL = CodeDataLog.Load(fs); var newCDL = CodeDataLog.Load(fs);
if (!newCDL.CheckConsistency(_emu.Cpu.Mappings)) if (!newCDL.CheckConsistency(_emu.Cpu.Mappings))
@ -155,7 +204,7 @@ namespace BizHawk.Client.EmuHawk
_cdl = newCDL; _cdl = newCDL;
_emu.Cpu.CDL = _cdl; _emu.Cpu.CDL = _cdl;
UpdateDisplay(); UpdateDisplay();
Global.Config.RecentPceCdlFiles.Add(ofd.FileName); Global.Config.RecentPceCdlFiles.Add(file.FullName);
} }
} }
} }
@ -175,14 +224,13 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
var sfd = new SaveFileDialog(); var file = ToolHelpers.GetCdlSaveFileFromUser(string.Empty /* TODO */);
var result = sfd.ShowDialog(this); if (file != null)
if (result == DialogResult.OK)
{ {
using (var fs = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write)) using (var fs = new FileStream(file.FullName, FileMode.Create, FileAccess.Write))
{ {
_cdl.Save(fs); _cdl.Save(fs);
Global.Config.RecentPceCdlFiles.Add(sfd.FileName); Global.Config.RecentPceCdlFiles.Add(file.FullName);
} }
} }
} }
@ -196,11 +244,10 @@ namespace BizHawk.Client.EmuHawk
} }
else else
{ {
var ofd = new OpenFileDialog(); var file = ToolHelpers.GetCdlFileFromUser(string.Empty /*TODO*/);
var result = ofd.ShowDialog(this); if (file != null)
if (result == DialogResult.OK)
{ {
using (var fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read)) using (var fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read))
{ {
var newCDL = CodeDataLog.Load(fs); var newCDL = CodeDataLog.Load(fs);
_cdl.LogicalOrFrom(newCDL); _cdl.LogicalOrFrom(newCDL);
@ -274,12 +321,13 @@ namespace BizHawk.Client.EmuHawk
Global.Config.PceCdlSettings.FloatingWindow ^= true; Global.Config.PceCdlSettings.FloatingWindow ^= true;
} }
private void PCECDL_Load(object sender, EventArgs e) private void RestoreDefaultSettingsMenuItem_Click(object sender, EventArgs e)
{ {
if (Global.Config.RecentPceCdlFiles.AutoLoad) Size = new Size(_defaultWidth, _defaultHeight);
{
LoadFileFromRecent(Global.Config.RecentPceCdlFiles.MostRecent); Global.Config.PceCdlSettings.SaveWindowPosition = true;
} Global.Config.PceCdlSettings.TopMost = TopMost = false;
Global.Config.PceCdlSettings.FloatingWindow = false;
} }
private void LoggingActiveCheckbox_CheckedChanged(object sender, EventArgs e) private void LoggingActiveCheckbox_CheckedChanged(object sender, EventArgs e)

View File

@ -155,9 +155,53 @@ namespace BizHawk.Client.EmuHawk
return null; return null;
} }
var file = new FileInfo(sfd.FileName); return new FileInfo(sfd.FileName);
Global.Config.LastRomPath = file.DirectoryName; }
return file;
public static FileInfo GetCdlFileFromUser(string currentFile)
{
var ofd = new OpenFileDialog
{
Filter = "Code Data Logger Files (*.cdl)|*.cdl|All Files|*.*",
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null),
RestoreDirectory = true
};
if (!string.IsNullOrWhiteSpace(currentFile))
{
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
}
var result = ofd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
}
return new FileInfo(ofd.FileName);
}
public static FileInfo GetCdlSaveFileFromUser(string currentFile)
{
var sfd = new SaveFileDialog
{
Filter = "Code Data Logger Files (*.cdl)|*.cdl|All Files|*.*",
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null),
RestoreDirectory = true
};
if (!string.IsNullOrWhiteSpace(currentFile))
{
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
}
var result = sfd.ShowHawkDialog();
if (result != DialogResult.OK)
{
return null;
}
return new FileInfo(sfd.FileName);
} }
public static ToolStripMenuItem GenerateAutoLoadItem(RecentFiles recent) public static ToolStripMenuItem GenerateAutoLoadItem(RecentFiles recent)