miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 54 additions and 0 deletions.
Added +54 -0
Added +54 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/SaveFileAsCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/SaveFileAsCommand.cs
new file mode 100644
index 0000000..a3e598e
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/SaveFileAsCommand.cs
@@ -0,0 +1,54 @@
+#region License
+
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+#endregion
+
+using System;
+using System.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The save file as command.</summary>
+    public class SaveFileAsCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="SaveFileAsCommand"/> class.</summary>
+        public SaveFileAsCommand()
+            : base("Save File &As...")
+        {
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            IEditor editor = HostWindow.Instance.ActiveMdiChild as IEditor;
+            if (editor != null)
+            {
+                string oldFilename = editor.FileName;
+                SaveFileDialog saveFileDialog = new SaveFileDialog();
+                saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
+                saveFileDialog.Filter = editor.FileFilter;
+
+                if (saveFileDialog.ShowDialog(HostWindow.Instance) == DialogResult.OK)
+                {
+                    // what if this filename covers an existing open window?
+                    string newFilename = saveFileDialog.FileName;
+                    editor.FileName = newFilename;
+                    editor.SaveFile();
+
+                    // register the new file and remove old if applicable
+                    var mostRecentFilesService = Services.Resolve<IMostRecentFilesService>();
+                    mostRecentFilesService.Register(newFilename);
+                    if (oldFilename != null && oldFilename.Equals(newFilename, StringComparison.InvariantCultureIgnoreCase))
+                    {
+                        mostRecentFilesService.Remove(oldFilename);
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file