From b1acbdd98fc2b21c9a89180f73c835b726192bac Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Fri, 7 Jul 2023 12:07:14 +0300 Subject: [PATCH] Ability to open a project by double-clicking on a file in Explorer --- McBitFont/Form1.cs | 83 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/McBitFont/Form1.cs b/McBitFont/Form1.cs index 650c58c..842ba1b 100644 --- a/McBitFont/Form1.cs +++ b/McBitFont/Form1.cs @@ -89,6 +89,11 @@ namespace McBitFont { this.Text = "McBitFont " + version + " - " + prjName; fbuf = new FrameMiniature(0, dotWidth, dotHeight); + + // Chek for arguments + if (Environment.GetCommandLineArgs().Length > 1) { + loadProject(Environment.GetCommandLineArgs()[1]); + } } [DllImport("user32.dll")] @@ -654,6 +659,46 @@ namespace McBitFont { } } + private void loadProject(string filename) { + SaveBlock sav; + BinaryFormatter formatter = new BinaryFormatter(); + + using (FileStream fs = File.Open(filename, FileMode.Open)) { + sav = (SaveBlock)formatter.Deserialize(fs); + fs.Close(); + } + monospaced = sav.monospaced; + codepage = sav.codepage; + baseline = sav.baseline; + lblType.Text = monospaced ? "Monospaced" : "Variable width / Single"; + frames = sav.frames; + miniList.Items.Clear(); + ilMiniatures.Images.Clear(); + foreach (FrameMiniature ff in frames) { + var s = ff.code.ToString().PadLeft(3, '0'); + var sss = decodeSymbol(ff.code); + ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); + miniList.Items.Add(s, s + ' ' + sss, s); + } + nudX.ValueChanged -= nudX_ValueChanged; + nudY.ValueChanged -= nudY_ValueChanged; + nudX.Value = frames.First().width; + nudY.Value = frames.First().height; + dotResize((int)nudX.Value, (int)nudY.Value); + nudX.ValueChanged += nudX_ValueChanged; + nudY.ValueChanged += nudY_ValueChanged; + f = copyFrame(frames.First()); + dotPanel.Refresh(); + miniList.Refresh(); + modified = false; + prjModified = false; + + prjName = Path.GetFileNameWithoutExtension(filename); + this.Text = "McBitFont " + version + " - " + prjName; + checkForAdd(); + fbuffer = false; + } + private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (prjModified) { if (MessageBox.Show("The project is modified.\nDo you want to save it first?", "Project was modified!", MessageBoxButtons.YesNo) == DialogResult.Yes) { @@ -662,43 +707,7 @@ namespace McBitFont { } } if (dlgOpen.ShowDialog() == DialogResult.OK) { - SaveBlock sav; - BinaryFormatter formatter = new BinaryFormatter(); - - using (FileStream fs = File.Open(dlgOpen.FileName, FileMode.Open)) { - sav = (SaveBlock)formatter.Deserialize(fs); - fs.Close(); - } - monospaced = sav.monospaced; - codepage = sav.codepage; - baseline = sav.baseline; - lblType.Text = monospaced ? "Monospaced" : "Variable width / Single"; - frames = sav.frames; - miniList.Items.Clear(); - ilMiniatures.Images.Clear(); - foreach (FrameMiniature ff in frames) { - var s = ff.code.ToString().PadLeft(3, '0'); - var sss = decodeSymbol(ff.code); - ilMiniatures.Images.Add(s, (Image)getMiniPictue(ff)); - miniList.Items.Add(s, s + ' ' + sss, s); - } - nudX.ValueChanged -= nudX_ValueChanged; - nudY.ValueChanged -= nudY_ValueChanged; - nudX.Value = frames.First().width; - nudY.Value = frames.First().height; - dotResize((int)nudX.Value, (int)nudY.Value); - nudX.ValueChanged += nudX_ValueChanged; - nudY.ValueChanged += nudY_ValueChanged; - f = copyFrame(frames.First()); - dotPanel.Refresh(); - miniList.Refresh(); - modified = false; - prjModified = false; - - prjName = Path.GetFileNameWithoutExtension(dlgOpen.FileName); - this.Text = "McBitFont " + version + " - " + prjName; - checkForAdd(); - fbuffer = false; + loadProject(dlgOpen.FileName); } }