miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 9 changed files with 602 additions and 0 deletions.
Added +75 -0
Added +42 -0
Added +49 -0
Added +178 -0
Added +54 -0
Added +58 -0
Added +80 -0
Added +32 -0
Added +34 -0
Added +75 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/DuplicateLineCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/DuplicateLineCommand.cs
new file mode 100644
index 0000000..a71f955
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/DuplicateLineCommand.cs
@@ -0,0 +1,75 @@
+#region License
+// Copyright 2005-2009 Paul Kohler (http://pksoftware.net/MiniSqlQuery/). All rights reserved.
+// This source code is made available under the terms of the Microsoft Public License (Ms-PL)
+// http://minisqlquery.codeplex.com/license
+#endregion
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.Commands
+{
+	/// <summary>
+	/// Whatever line the cursor is on this command will duplicate that line (its a resharper this that I use alot!)
+	/// </summary>
+	public class DuplicateLineCommand
+		: CommandBase
+	{
+		public DuplicateLineCommand()
+			: base("Duplicate Line")
+		{
+			ShortcutKeys = Keys.Control | Keys.D;
+			//todo SmallImage = ImageResource.?;
+		}
+
+		/// <summary>
+		/// Gets a value indicating whether this <see cref="ICommand"/> is enabled.
+		/// The window needs to implement the <see cref="IFindReplaceProvider"/> and 
+		/// support replacing text (<see cref="IFindReplaceProvider.CanReplaceText"/>).
+		/// </summary>
+		/// <value>
+		/// 	<c>true</c> if enabled; otherwise, <c>false</c>.
+		/// </value>
+		public override bool Enabled
+		{
+			get
+			{
+				IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+				if (findReplaceProvider == null || !findReplaceProvider.CanReplaceText)
+				{
+					return false;
+				}
+				return true;
+			}
+		}
+
+		/// <summary>
+		/// Finds the current line position and duplicates that line.
+		/// </summary>
+		public override void Execute()
+		{
+			IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+
+			if (findReplaceProvider == null || !findReplaceProvider.CanReplaceText)
+			{
+				return;
+			}
+
+			// todo!
+
+			int offset = findReplaceProvider.CursorOffset;
+			int originalLineStartOffset = 0;
+			int lineLength = 0;
+
+			string line = "?";
+			// find current text "line", back to start or \n and find next \n or eof
+
+			line = line + Environment.NewLine + line;
+
+			findReplaceProvider.ReplaceString(line, 0, 0);
+		}
+	}
+}
\ No newline at end of file
Added +42 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/NewFileCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/NewFileCommand.cs
new file mode 100644
index 0000000..3fb143f
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/NewFileCommand.cs
@@ -0,0 +1,42 @@
+#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.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+using WeifenLuo.WinFormsUI.Docking;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The new file command.</summary>
+    public class NewFileCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="NewFileCommand"/> class.</summary>
+        public NewFileCommand()
+            : base("New &File")
+        {
+            ShortcutKeys = Keys.Control | Keys.Alt | Keys.N;
+            SmallImage = ImageResource.page;
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            NewFileForm newFileForm = Services.Resolve<NewFileForm>();
+
+            DialogResult result = newFileForm.ShowDialog();
+
+            if (result == DialogResult.OK)
+            {
+                var editor = Services.Resolve<IEditor>(newFileForm.FileEditorDescriptor.EditorKeyName);
+                editor.FileName = null;
+                HostWindow.DisplayDockedForm(editor as DockContent);
+            }
+        }
+    }
+}
\ No newline at end of file
Added +49 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/OpenFileCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/OpenFileCommand.cs
new file mode 100644
index 0000000..efe27ea
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/OpenFileCommand.cs
@@ -0,0 +1,49 @@
+#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;
+using WeifenLuo.WinFormsUI.Docking;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The open file command.</summary>
+    public class OpenFileCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="OpenFileCommand"/> class.</summary>
+        public OpenFileCommand()
+            : base("&Open File")
+        {
+            ShortcutKeys = Keys.Control | Keys.O;
+            SmallImage = ImageResource.folder_page;
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            OpenFileDialog openFileDialog = new OpenFileDialog();
+            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
+            openFileDialog.Filter = Settings.DefaultFileFilter;
+            openFileDialog.CheckFileExists = true;
+            if (openFileDialog.ShowDialog(HostWindow.Instance) == DialogResult.OK)
+            {
+                // todo: check for file exist file in open windows;
+                IFileEditorResolver resolver = Services.Resolve<IFileEditorResolver>();
+                var fileName = openFileDialog.FileName;
+                IEditor editor = resolver.ResolveEditorInstance(fileName);
+                editor.FileName = fileName;
+                editor.LoadFile();
+                HostWindow.DisplayDockedForm(editor as DockContent);
+
+                Services.Resolve<IMostRecentFilesService>().Register(fileName);
+            }
+        }
+    }
+}
\ No newline at end of file
Added +178 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/OpenRecentFileCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/OpenRecentFileCommand.cs
new file mode 100644
index 0000000..85d5372
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/OpenRecentFileCommand.cs
@@ -0,0 +1,178 @@
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+using WeifenLuo.WinFormsUI.Docking;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>
+    /// 	Opens a recent file in a list by the <see cref = "Index" />.
+    /// 	Makes use of <see cref = "IMostRecentFilesService" /> to calculate the filename.
+    /// </summary>
+    public class OpenRecentFileCommand
+        : CommandBase
+    {
+        private readonly int _index;
+        private IMostRecentFilesService _mostRecentFilesService;
+
+        /// <summary>
+        /// 	Initializes a new instance of the <see cref = "OpenRecentFileCommand" /> class.
+        /// </summary>
+        protected OpenRecentFileCommand(int index)
+            : base("MRU")
+        {
+            _index = index;
+        }
+
+        public OpenRecentFileCommand(IMostRecentFilesService mostRecentFilesService, int index)
+            : base("MRU")
+        {
+            _mostRecentFilesService = mostRecentFilesService;
+            _index = index;
+        }
+
+        public override bool Enabled
+        {
+            get
+            {
+                if (MostRecentFilesService.Filenames != null)
+                {
+                    return MostRecentFilesService.Filenames.Count >= Index;
+                }
+                return false;
+            }
+        }
+
+        public int Index
+        {
+            get { return _index; }
+        }
+
+        public IMostRecentFilesService MostRecentFilesService
+        {
+            get
+            {
+                if (_mostRecentFilesService == null)
+                {
+                    _mostRecentFilesService = Services.Resolve<IMostRecentFilesService>();
+                    _mostRecentFilesService.MostRecentFilesChanged += MostRecentFilesServiceFilesChanged;
+                }
+                return _mostRecentFilesService;
+            }
+        }
+
+        void MostRecentFilesServiceFilesChanged(object sender, MostRecentFilesChangedEventArgs e)
+        {
+            UpdateName();
+        }
+
+        public void UpdateName()
+        {
+            if (Enabled)
+            {
+                Name = string.Format("&{0} - {1}", Index, GetFilenameByIndex());
+            }
+        }
+
+        public override void Execute()
+        {
+            if (!Enabled)
+            {
+                return;
+            }
+
+            var fileEditorResolver = Services.Resolve<IFileEditorResolver>();
+            _mostRecentFilesService = Services.Resolve<IMostRecentFilesService>();
+            string fileName = GetFilenameByIndex();
+
+            var editor = fileEditorResolver.ResolveEditorInstance(fileName);
+            editor.FileName = fileName;
+            editor.LoadFile();
+            HostWindow.DisplayDockedForm(editor as DockContent);
+        }
+
+        private string GetFilenameByIndex()
+        {
+            return MostRecentFilesService.Filenames[Index - 1];
+        }
+    }
+
+    public class OpenRecentFile1Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile1Command()
+            : base(1)
+        {
+        }
+    }
+
+    public class OpenRecentFile2Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile2Command()
+            : base(2)
+        {
+        }
+    }
+
+    public class OpenRecentFile3Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile3Command()
+            : base(3)
+        {
+        }
+    }
+
+    public class OpenRecentFile4Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile4Command()
+            : base(4)
+        {
+        }
+    }
+
+    public class OpenRecentFile5Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile5Command()
+            : base(5)
+        {
+        }
+    }
+
+    public class OpenRecentFile6Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile6Command()
+            : base(6)
+        {
+        }
+    }
+
+    public class OpenRecentFile7Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile7Command()
+            : base(7)
+        {
+        }
+    }
+
+    public class OpenRecentFile8Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile8Command()
+            : base(8)
+        {
+        }
+    }
+
+    public class OpenRecentFile9Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile9Command()
+            : base(9)
+        {
+        }
+    }
+
+    public class OpenRecentFile10Command : OpenRecentFileCommand
+    {
+        public OpenRecentFile10Command()
+            : base(10)
+        {
+        }
+    }
+}
\ No newline at end of file
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
Added +58 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/SaveFileCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/SaveFileCommand.cs
new file mode 100644
index 0000000..bd41f52
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/SaveFileCommand.cs
@@ -0,0 +1,58 @@
+#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.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The save file command.</summary>
+    public class SaveFileCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="SaveFileCommand"/> class.</summary>
+        public SaveFileCommand()
+            : base("&Save File")
+        {
+            ShortcutKeys = Keys.Control | Keys.S;
+            SmallImage = ImageResource.disk;
+        }
+
+        /// <summary>Gets a value indicating whether Enabled.</summary>
+        public override bool Enabled
+        {
+            get
+            {
+                IEditor editor = HostWindow.Instance.ActiveMdiChild as IEditor;
+                if (editor != null)
+                {
+                    return editor.IsDirty;
+                }
+
+                return false;
+            }
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            IEditor editor = HostWindow.Instance.ActiveMdiChild as IEditor;
+            if (editor != null)
+            {
+                if (editor.FileName == null)
+                {
+                    CommandManager.GetCommandInstance<SaveFileAsCommand>().Execute();
+                }
+                else
+                {
+                    editor.SaveFile();
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
Added +80 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/SaveResultsAsDataSetCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/SaveResultsAsDataSetCommand.cs
new file mode 100644
index 0000000..cea455c
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/SaveResultsAsDataSetCommand.cs
@@ -0,0 +1,80 @@
+#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.Data;
+using System.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+using MiniSqlQuery.Core.Forms;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The save results as data set command.</summary>
+    public class SaveResultsAsDataSetCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="SaveResultsAsDataSetCommand"/> class.</summary>
+        public SaveResultsAsDataSetCommand()
+            : base("Save Results as DataSet XML...")
+        {
+            SmallImage = ImageResource.table_save;
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            IQueryBatchProvider batchProvider = HostWindow.ActiveChildForm as IQueryBatchProvider;
+
+            if (batchProvider == null)
+            {
+                HostWindow.DisplaySimpleMessageBox(null, "No results to save as a 'DataSet'.", "Save Results as DataSet XML Error");
+            }
+            else
+            {
+                DataSet ds = null;
+
+                if (batchProvider.Batch != null)
+                {
+                    if (batchProvider.Batch.Queries.Count > 1)
+                    {
+                        BatchQuerySelectForm querySelectForm = Services.Resolve<BatchQuerySelectForm>();
+                        querySelectForm.Fill(batchProvider.Batch);
+                        querySelectForm.ShowDialog();
+                        if (querySelectForm.DialogResult == DialogResult.OK)
+                        {
+                            ds = querySelectForm.SelectedQuery.Result;
+                        }
+                    }
+                    else if (batchProvider.Batch.Queries.Count == 1)
+                    {
+                        ds = batchProvider.Batch.Queries[0].Result;
+                    }
+                }
+
+                if (ds == null)
+                {
+                    return;
+                }
+
+                using (SaveFileDialog saveFileDialog = new SaveFileDialog())
+                {
+                    saveFileDialog.Title = "Save Results as DataSet XML";
+                    saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
+                    saveFileDialog.Filter = Properties.Settings.Default.XmlFileDialogFilter;
+
+                    if (saveFileDialog.ShowDialog(HostWindow.Instance) == DialogResult.OK)
+                    {
+                        ds.WriteXml(saveFileDialog.FileName, XmlWriteMode.WriteSchema);
+                        string msg = string.Format("Saved results to file: '{0}'", saveFileDialog.FileName);
+                        HostWindow.SetStatus(HostWindow.ActiveChildForm, msg);
+                    }
+                }
+            }
+        }
+    }
+}
Added +32 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/ShowAboutCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/ShowAboutCommand.cs
new file mode 100644
index 0000000..1b960eb
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/ShowAboutCommand.cs
@@ -0,0 +1,32 @@
+#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.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The show about command.</summary>
+    public class ShowAboutCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="ShowAboutCommand"/> class.</summary>
+        public ShowAboutCommand()
+            : base("&About...")
+        {
+            SmallImage = ImageResource.ApplicationIcon;
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            Form frm = Services.Resolve<AboutForm>();
+            frm.Show(HostWindow.Instance);
+        }
+    }
+}
\ No newline at end of file
Added +34 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/ShowOptionsFormCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/ShowOptionsFormCommand.cs
new file mode 100644
index 0000000..5b1ce09
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/ShowOptionsFormCommand.cs
@@ -0,0 +1,34 @@
+#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 MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.Commands
+{
+    /// <summary>The show options form command.</summary>
+    public class ShowOptionsFormCommand
+        : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="ShowOptionsFormCommand"/> class.</summary>
+        public ShowOptionsFormCommand()
+            : base("Options")
+        {
+            // ShortcutKeys = ?;
+            SmallImage = ImageResource.cog;
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            using (OptionsForm optionsForm = Services.Resolve<OptionsForm>())
+            {
+                optionsForm.ShowDialog(HostWindow.Instance);
+            }
+        }
+    }
+}
\ No newline at end of file