From 042a98f478603fcb8ad4e38883913a37efe4ed9e Mon Sep 17 00:00:00 2001 From: Michael Delpach Date: Fri, 3 Jul 2020 08:39:35 +0800 Subject: [PATCH] Save as and close --- .../Forms/DirectoryIndexerForm.Designer.cs | 22 +- .../Forms/DirectoryIndexerForm.cs | 28 ++ .../Forms/DirectoryIndexerForm.resx | 270 ++++++++++++------ 3 files changed, 230 insertions(+), 90 deletions(-) diff --git a/ShareX.IndexerLib/Forms/DirectoryIndexerForm.Designer.cs b/ShareX.IndexerLib/Forms/DirectoryIndexerForm.Designer.cs index 1b73a0dd3..55801e24d 100644 --- a/ShareX.IndexerLib/Forms/DirectoryIndexerForm.Designer.cs +++ b/ShareX.IndexerLib/Forms/DirectoryIndexerForm.Designer.cs @@ -29,7 +29,6 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DirectoryIndexerForm)); - this.wbPreview = new System.Windows.Forms.WebBrowser(); this.txtFolderPath = new System.Windows.Forms.TextBox(); this.btnBrowseFolder = new System.Windows.Forms.Button(); this.btnIndexFolder = new System.Windows.Forms.Button(); @@ -39,16 +38,13 @@ private void InitializeComponent() this.txtPreview = new System.Windows.Forms.TextBox(); this.tpSettings = new System.Windows.Forms.TabPage(); this.pgSettings = new System.Windows.Forms.PropertyGrid(); + this.btnSaveAs = new System.Windows.Forms.Button(); + this.wbPreview = new System.Windows.Forms.WebBrowser(); this.tcMain.SuspendLayout(); this.tpPreview.SuspendLayout(); this.tpSettings.SuspendLayout(); this.SuspendLayout(); // - // wbPreview - // - resources.ApplyResources(this.wbPreview, "wbPreview"); - this.wbPreview.Name = "wbPreview"; - // // txtFolderPath // resources.ApplyResources(this.txtFolderPath, "txtFolderPath"); @@ -112,11 +108,24 @@ private void InitializeComponent() this.pgSettings.PropertySort = System.Windows.Forms.PropertySort.Categorized; this.pgSettings.ToolbarVisible = false; // + // btnSaveAs + // + resources.ApplyResources(this.btnSaveAs, "btnSaveAs"); + this.btnSaveAs.Name = "btnSaveAs"; + this.btnSaveAs.UseVisualStyleBackColor = true; + this.btnSaveAs.Click += new System.EventHandler(this.btnSaveAs_Click); + // + // wbPreview + // + resources.ApplyResources(this.wbPreview, "wbPreview"); + this.wbPreview.Name = "wbPreview"; + // // DirectoryIndexerForm // resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.Window; + this.Controls.Add(this.btnSaveAs); this.Controls.Add(this.tcMain); this.Controls.Add(this.btnUpload); this.Controls.Add(this.btnIndexFolder); @@ -145,5 +154,6 @@ private void InitializeComponent() private System.Windows.Forms.PropertyGrid pgSettings; private System.Windows.Forms.TabPage tpPreview; private System.Windows.Forms.TextBox txtPreview; + private System.Windows.Forms.Button btnSaveAs; } } \ No newline at end of file diff --git a/ShareX.IndexerLib/Forms/DirectoryIndexerForm.cs b/ShareX.IndexerLib/Forms/DirectoryIndexerForm.cs index 372efdd51..31200aa52 100644 --- a/ShareX.IndexerLib/Forms/DirectoryIndexerForm.cs +++ b/ShareX.IndexerLib/Forms/DirectoryIndexerForm.cs @@ -26,6 +26,7 @@ You should have received a copy of the GNU General Public License using ShareX.HelpersLib; using System; using System.IO; +using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -84,6 +85,7 @@ private async Task IndexFolder() { btnIndexFolder.Enabled = false; btnUpload.Enabled = false; + btnSaveAs.Enabled = false; await Task.Run(() => { @@ -113,6 +115,7 @@ await Task.Run(() => } btnIndexFolder.Enabled = true; + btnSaveAs.Enabled = true; } } } @@ -133,5 +136,30 @@ protected void OnUploadRequested(string source) UploadRequested(source); } } + + private void btnSaveAs_Click(object sender, EventArgs e) + { + if (!string.IsNullOrEmpty(Source)) + { + using (SaveFileDialog sfd = new SaveFileDialog()) + { + string indexType = Settings.Output.ToString().ToLower(); + sfd.FileName = "Index for " + Path.GetFileNameWithoutExtension(txtFolderPath.Text); + sfd.DefaultExt = indexType; + sfd.Filter = string.Format("*.{0}|*.{0}|All files (*.*)|*.*", indexType); + + if (!string.IsNullOrEmpty(HelpersOptions.LastSaveDirectory) && Directory.Exists(HelpersOptions.LastSaveDirectory)) + { + sfd.InitialDirectory = HelpersOptions.LastSaveDirectory; + } + + if (sfd.ShowDialog() == DialogResult.OK) + { + File.WriteAllText(sfd.FileName, Source, Encoding.UTF8); + Close(); + } + } + } + } } } \ No newline at end of file diff --git a/ShareX.IndexerLib/Forms/DirectoryIndexerForm.resx b/ShareX.IndexerLib/Forms/DirectoryIndexerForm.resx index 9196f6792..535b1e1c8 100644 --- a/ShareX.IndexerLib/Forms/DirectoryIndexerForm.resx +++ b/ShareX.IndexerLib/Forms/DirectoryIndexerForm.resx @@ -118,44 +118,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Fill - - - - 0, 0 - - - 20, 20 - - - 860, 564 - - - - 0 - - - wbPreview - - - System.Windows.Forms.WebBrowser, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tpPreview - - - 1 - Top, Left, Right + 192, 8 682, 20 + 2 @@ -169,7 +142,10 @@ $this - 4 + 5 + + + NoControl 8, 7 @@ -193,16 +169,19 @@ $this - 3 + 4 False + + NoControl + 8, 32 - 344, 23 + 294, 23 3 @@ -220,16 +199,19 @@ $this - 2 + 3 False + + NoControl + - 360, 32 + 308, 32 - 344, 23 + 276, 23 0 @@ -247,11 +229,104 @@ $this - 1 + 2 Top, Bottom, Left, Right + + tpPreview + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 0 + + + tpSettings + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 1 + + + 8, 64 + + + 868, 590 + + + 4 + + + tcMain + + + System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + txtPreview + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpPreview + + + 0 + + + wbPreview + + + System.Windows.Forms.WebBrowser, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpPreview + + + 1 + + + 4, 22 + + + 860, 564 + + + 1 + + + Preview + + + tpPreview + + + System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tcMain + + + 0 + Fill @@ -282,42 +357,6 @@ 0 - - 4, 22 - - - 860, 564 - - - 1 - - - Preview - - - tpPreview - - - System.Windows.Forms.TabPage, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - tcMain - - - 0 - - - Fill - - - 0, 0 - - - 860, 564 - - - 0 - pgSettings @@ -354,27 +393,87 @@ 1 - - 8, 64 + + Fill - - 868, 590 + + 0, 0 - - 4 + + 860, 564 - - tcMain + + 0 - - System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + pgSettings - + + System.Windows.Forms.PropertyGrid, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpSettings + + + 0 + + + False + + + NoControl + + + 590, 32 + + + 284, 23 + + + 5 + + + Save as and close this window... + + + btnSaveAs + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + $this - + 0 + + Fill + + + 0, 0 + + + 20, 20 + + + 860, 564 + + + 0 + + + wbPreview + + + System.Windows.Forms.WebBrowser, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tpPreview + + + 1 + True @@ -384,6 +483,9 @@ 884, 661 + + NoControl + CenterScreen