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.SaveWindowPositionMenuItem = 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.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.RestoreDefaultSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.CdlTextbox = new System.Windows.Forms.TextBox();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -93,6 +95,7 @@
this.FileSubMenu.Name = "FileSubMenu";
this.FileSubMenu.Size = new System.Drawing.Size(37, 20);
this.FileSubMenu.Text = "&File";
this.FileSubMenu.DropDownOpened += new System.EventHandler(this.FileSubMenu_DropDownOpened);
//
// NewMenuItem
//
@ -190,7 +193,9 @@
this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveWindowPositionMenuItem,
this.AlwaysOnTopMenuItem,
this.FloatingWindowMenuItem});
this.FloatingWindowMenuItem,
this.toolStripSeparator3,
this.RestoreDefaultSettingsMenuItem});
this.OptionsSubMenu.Name = "OptionsSubMenu";
this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20);
this.OptionsSubMenu.Text = "&Options";
@ -199,17 +204,36 @@
// 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.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click);
//
// 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.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
//
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.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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -239,6 +256,7 @@
this.Controls.Add(this.menuStrip1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStrip1;
this.MinimumSize = new System.Drawing.Size(150, 130);
this.Name = "PCECDL";
this.Text = "Code Data Logger";
this.Load += new System.EventHandler(this.PCECDL_Load);
@ -271,6 +289,8 @@
private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem;
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
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.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
@ -14,18 +15,37 @@ namespace BizHawk.Client.EmuHawk
// TODO
// Loading doesn't work
// Save
// Save Window position and size
// Restore settings
// Drag and drop cdl files
// Drag and drop cdl files onto Main window?
private PCEngine _emu;
private CodeDataLog _cdl;
private int _defaultWidth;
private int _defaultHeight;
public PCECDL()
{
InitializeComponent();
TopMost = Global.Config.PceCdlSettings.TopMost;
Closing += (o, e) =>
{
SaveConfigSettings();
};
Restart();
}
private void PCECDL_Load(object sender, EventArgs e)
{
LoadConfigSettings();
if (Global.Config.RecentPceCdlFiles.AutoLoad)
{
LoadFileFromRecent(Global.Config.RecentPceCdlFiles.MostRecent);
}
}
public void UpdateValues()
{
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
private void FileSubMenu_DropDownOpened(object sender, EventArgs e)
{
SaveAsMenuItem.Enabled = _cdl != null;
}
private void RecentSubMenu_DropDownOpened(object sender, EventArgs e)
{
RecentSubMenu.DropDownItems.Clear();
@ -139,11 +189,10 @@ namespace BizHawk.Client.EmuHawk
var result = MessageBox.Show(this, "OK to load new CDL?", "Query", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
var ofd = new OpenFileDialog();
result = ofd.ShowDialog(this);
if (result == DialogResult.OK)
var file = ToolHelpers.GetCdlFileFromUser(string.Empty /*TODO*/);
if (file != null)
{
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);
if (!newCDL.CheckConsistency(_emu.Cpu.Mappings))
@ -155,7 +204,7 @@ namespace BizHawk.Client.EmuHawk
_cdl = newCDL;
_emu.Cpu.CDL = _cdl;
UpdateDisplay();
Global.Config.RecentPceCdlFiles.Add(ofd.FileName);
Global.Config.RecentPceCdlFiles.Add(file.FullName);
}
}
}
@ -175,14 +224,13 @@ namespace BizHawk.Client.EmuHawk
}
else
{
var sfd = new SaveFileDialog();
var result = sfd.ShowDialog(this);
if (result == DialogResult.OK)
var file = ToolHelpers.GetCdlSaveFileFromUser(string.Empty /* TODO */);
if (file != null)
{
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);
Global.Config.RecentPceCdlFiles.Add(sfd.FileName);
Global.Config.RecentPceCdlFiles.Add(file.FullName);
}
}
}
@ -196,11 +244,10 @@ namespace BizHawk.Client.EmuHawk
}
else
{
var ofd = new OpenFileDialog();
var result = ofd.ShowDialog(this);
if (result == DialogResult.OK)
var file = ToolHelpers.GetCdlFileFromUser(string.Empty /*TODO*/);
if (file != null)
{
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);
_cdl.LogicalOrFrom(newCDL);
@ -274,12 +321,13 @@ namespace BizHawk.Client.EmuHawk
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)
{
LoadFileFromRecent(Global.Config.RecentPceCdlFiles.MostRecent);
}
Size = new Size(_defaultWidth, _defaultHeight);
Global.Config.PceCdlSettings.SaveWindowPosition = true;
Global.Config.PceCdlSettings.TopMost = TopMost = false;
Global.Config.PceCdlSettings.FloatingWindow = false;
}
private void LoggingActiveCheckbox_CheckedChanged(object sender, EventArgs e)

View File

@ -155,9 +155,53 @@ namespace BizHawk.Client.EmuHawk
return null;
}
var file = new FileInfo(sfd.FileName);
Global.Config.LastRomPath = file.DirectoryName;
return file;
return new FileInfo(sfd.FileName);
}
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)