From b1223ecc3a491c1604bfaea1e732702c0b15db8d Mon Sep 17 00:00:00 2001 From: Mike Pelley Date: Mon, 11 Jul 2022 16:23:52 -0400 Subject: [PATCH] Restore plugin O, but with only public functions. --- ParatextDemoPlugins.sln | 10 ++ ReferencePluginD/AnnotationSource.cs | 2 +- ReferencePluginO/ControlO.Designer.cs | 118 ++++----------------- ReferencePluginO/ControlO.cs | 147 -------------------------- 4 files changed, 32 insertions(+), 245 deletions(-) diff --git a/ParatextDemoPlugins.sln b/ParatextDemoPlugins.sln index 2441d8d..3c2198d 100644 --- a/ParatextDemoPlugins.sln +++ b/ParatextDemoPlugins.sln @@ -61,6 +61,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReferencePluginP", "Referen EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReferencePluginQ", "ReferencePluginQ\ReferencePluginQ.csproj", "{1093984F-EE65-4FE5-9E9C-54C438640644}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReferencePluginO", "ReferencePluginO\ReferencePluginO.csproj", "{D0CA0A07-A72B-4144-85E3-CFE340107E75}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -249,6 +251,14 @@ Global {1093984F-EE65-4FE5-9E9C-54C438640644}.Release|Any CPU.Build.0 = Release|Any CPU {1093984F-EE65-4FE5-9E9C-54C438640644}.Release|x64.ActiveCfg = Release|x64 {1093984F-EE65-4FE5-9E9C-54C438640644}.Release|x64.Build.0 = Release|x64 + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Debug|x64.ActiveCfg = Debug|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Debug|x64.Build.0 = Debug|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Release|Any CPU.Build.0 = Release|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Release|x64.ActiveCfg = Release|Any CPU + {D0CA0A07-A72B-4144-85E3-CFE340107E75}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ReferencePluginD/AnnotationSource.cs b/ReferencePluginD/AnnotationSource.cs index 09a77fd..520e442 100644 --- a/ReferencePluginD/AnnotationSource.cs +++ b/ReferencePluginD/AnnotationSource.cs @@ -70,7 +70,7 @@ public Annotation(IScriptureTextSelection selection, string styleName) public bool Click(MouseButton button, bool onIcon, Point location) { string icon = onIcon ? "on icon" : "off icon"; - MessageBox.Show($"Clicked with {button} button {icon} at {location}"); + MessageBox.Show($"...at {location}", $"Clicked with {button} button {icon}"); return true; } } diff --git a/ReferencePluginO/ControlO.Designer.cs b/ReferencePluginO/ControlO.Designer.cs index 82d110d..06e1275 100644 --- a/ReferencePluginO/ControlO.Designer.cs +++ b/ReferencePluginO/ControlO.Designer.cs @@ -29,110 +29,34 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.m_ProjectsListBox = new System.Windows.Forms.ListBox(); - this.label1 = new System.Windows.Forms.Label(); - this.m_FileNameTextBox = new System.Windows.Forms.TextBox(); - this.m_ContentsTextBox = new System.Windows.Forms.TextBox(); - this.m_LoadButton = new System.Windows.Forms.Button(); - this.m_SaveButton = new System.Windows.Forms.Button(); - this.m_DeleteButton = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // m_ProjectsListBox - // - this.m_ProjectsListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + this.m_ProjectsListBox = new System.Windows.Forms.ListBox(); + this.SuspendLayout(); + // + // m_ProjectsListBox + // + this.m_ProjectsListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.m_ProjectsListBox.FormattingEnabled = true; - this.m_ProjectsListBox.ItemHeight = 16; - this.m_ProjectsListBox.Location = new System.Drawing.Point(4, 69); - this.m_ProjectsListBox.Name = "m_ProjectsListBox"; - this.m_ProjectsListBox.Size = new System.Drawing.Size(398, 420); - this.m_ProjectsListBox.TabIndex = 0; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(3, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(107, 17); - this.label1.TabIndex = 1; - this.label1.Text = "Enter file name:"; - // - // m_FileNameTextBox - // - this.m_FileNameTextBox.Location = new System.Drawing.Point(116, 0); - this.m_FileNameTextBox.Name = "m_FileNameTextBox"; - this.m_FileNameTextBox.Size = new System.Drawing.Size(250, 22); - this.m_FileNameTextBox.TabIndex = 2; - // - // m_ContentsTextBox - // - this.m_ContentsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.m_ContentsTextBox.Location = new System.Drawing.Point(408, 69); - this.m_ContentsTextBox.Multiline = true; - this.m_ContentsTextBox.Name = "m_ContentsTextBox"; - this.m_ContentsTextBox.Size = new System.Drawing.Size(404, 424); - this.m_ContentsTextBox.TabIndex = 3; - // - // m_LoadButton - // - this.m_LoadButton.Location = new System.Drawing.Point(19, 28); - this.m_LoadButton.Name = "m_LoadButton"; - this.m_LoadButton.Size = new System.Drawing.Size(187, 25); - this.m_LoadButton.TabIndex = 4; - this.m_LoadButton.Text = "Load Project File"; - this.m_LoadButton.UseVisualStyleBackColor = true; - this.m_LoadButton.Click += new System.EventHandler(this.LoadButton_Click); - // - // m_SaveButton - // - this.m_SaveButton.Location = new System.Drawing.Point(318, 28); - this.m_SaveButton.Name = "m_SaveButton"; - this.m_SaveButton.Size = new System.Drawing.Size(187, 25); - this.m_SaveButton.TabIndex = 5; - this.m_SaveButton.Text = "Save Project File"; - this.m_SaveButton.UseVisualStyleBackColor = true; - this.m_SaveButton.Click += new System.EventHandler(this.SaveButton_Click); - // - // m_DeleteButton - // - this.m_DeleteButton.Location = new System.Drawing.Point(623, 28); - this.m_DeleteButton.Name = "m_DeleteButton"; - this.m_DeleteButton.Size = new System.Drawing.Size(187, 25); - this.m_DeleteButton.TabIndex = 6; - this.m_DeleteButton.Text = "Delete Project File"; - this.m_DeleteButton.UseVisualStyleBackColor = true; - this.m_DeleteButton.Click += new System.EventHandler(this.m_DeleteButton_Click); - // - // ControlO - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.m_DeleteButton); - this.Controls.Add(this.m_SaveButton); - this.Controls.Add(this.m_LoadButton); - this.Controls.Add(this.m_ContentsTextBox); - this.Controls.Add(this.m_FileNameTextBox); - this.Controls.Add(this.label1); - this.Controls.Add(this.m_ProjectsListBox); - this.Name = "ControlO"; - this.Size = new System.Drawing.Size(813, 494); - this.ResumeLayout(false); - this.PerformLayout(); + this.m_ProjectsListBox.FormattingEnabled = true; + this.m_ProjectsListBox.ItemHeight = 16; + this.m_ProjectsListBox.Location = new System.Drawing.Point(4, 5); + this.m_ProjectsListBox.Name = "m_ProjectsListBox"; + this.m_ProjectsListBox.Size = new System.Drawing.Size(806, 484); + this.m_ProjectsListBox.TabIndex = 0; + // + // ControlO + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.m_ProjectsListBox); + this.Name = "ControlO"; + this.Size = new System.Drawing.Size(813, 494); + this.ResumeLayout(false); } #endregion private System.Windows.Forms.ListBox m_ProjectsListBox; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox m_FileNameTextBox; - private System.Windows.Forms.TextBox m_ContentsTextBox; - private System.Windows.Forms.Button m_LoadButton; - private System.Windows.Forms.Button m_SaveButton; - private System.Windows.Forms.Button m_DeleteButton; } } diff --git a/ReferencePluginO/ControlO.cs b/ReferencePluginO/ControlO.cs index c24c8f7..2546a33 100644 --- a/ReferencePluginO/ControlO.cs +++ b/ReferencePluginO/ControlO.cs @@ -1,21 +1,11 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; using Paratext.PluginInterfaces; -using Paratext.PluginInterfaces.ParatextInternal; namespace ReferencePluginO { public partial class ControlO : EmbeddedPluginControl { - private IVerseRef m_Reference; private IProject m_Project; private IWindowPluginHost m_Host; @@ -27,11 +17,9 @@ public override void OnAddedToParent(IPluginChildWindow parent, IWindowPluginHos { parent.SetTitle(PluginO.pluginName); m_Project = parent.CurrentState.Project; - m_Reference = parent.CurrentState.VerseRef; m_Host = host; parent.ProjectChanged += ProjectChanged; - parent.VerseRefChanged += VerseRefChanged; } public override string GetState() @@ -49,7 +37,6 @@ public override void DoLoad(IProgressInfo progressInfo) public void ProjectChanged(IPluginChildWindow sender, IProject newProject) { m_Project = newProject; - m_Reference = sender.CurrentState.VerseRef; foreach (var item in m_ProjectsListBox.Items) { if (item.ToString().StartsWith(m_Project.ShortName)) @@ -60,11 +47,6 @@ public void ProjectChanged(IPluginChildWindow sender, IProject newProject) } } - public void VerseRefChanged(IPluginChildWindow sender, IVerseRef oldReference, IVerseRef newReference) - { - m_Reference = newReference; - } - private void GetAllProjects() { var projects = m_Host.GetAllProjects(); @@ -75,136 +57,7 @@ private void GetAllProjects() string text = $"{p.ShortName} is a {p.Type} Project"; m_ProjectsListBox.Items.Add(text); } - - } - - private void LoadButton_Click(object sender, EventArgs e) - { - if (m_Project == null) - { - m_ContentsTextBox.Text = "Need to select a project first"; - } - else - { - IProjectRootAccess root = (IProjectRootAccess)m_Project; - try - { - var reader = root.GetPluginData(m_FileNameTextBox.Text); - if (reader == null) - { - m_ContentsTextBox.Text = $"Cannot open file: {m_FileNameTextBox.Text}"; - } - else - { - m_ContentsTextBox.Text = reader.ReadToEnd(); - reader.Close(); - } - } - catch (Exception ex) - { - if (ex.InnerException == null) - { - m_ContentsTextBox.Text = $"API threw exception: {ex.Message}"; - } - else - { - m_ContentsTextBox.Text = $"API threw exception: {ex.Message}\r\n" + - $"with inner exception {ex.InnerException.Message}"; - } - } - } - } - - private void SaveButton_Click(object sender, EventArgs e) - { - if (m_Project == null) - { - m_ContentsTextBox.Text = "Need to select a project first"; - } - else - { - IWriteLock writelock = null; - string id = m_FileNameTextBox.Text; - IProjectRootAccess root = (IProjectRootAccess)m_Project; - try - { - writelock = root.RequestWriteLock(ReleaseRequested, id); - if (writelock == null) - { - m_ContentsTextBox.Text = "Cannot get write lock for this project"; - } - else - { - root.PutPluginData(writelock, id, writer => writer.Write(m_ContentsTextBox.Text)); - writelock.Dispose(); - writelock = null; - } - } - catch (Exception ex) - { - if (ex.InnerException == null) - { - m_ContentsTextBox.Text = $"API threw exception: {ex.Message}"; - } - else - { - m_ContentsTextBox.Text = $"API threw exception: {ex.Message}\r\n" + - $"with inner exception {ex.InnerException.Message}"; - } - } - if (writelock != null) - { - writelock.Dispose(); - } - } - } - private void ReleaseRequested(IWriteLock writeLock) - { - writeLock.Dispose(); } - private void m_DeleteButton_Click(object sender, EventArgs e) - { - if (m_Project == null) - { - m_ContentsTextBox.Text = "Need to select a project first"; - } - else - { - IWriteLock writelock = null; - string id = m_FileNameTextBox.Text; - IProjectRootAccess root = (IProjectRootAccess)m_Project; - try - { - writelock = root.RequestWriteLock(ReleaseRequested, id); - if (writelock == null) - { - m_ContentsTextBox.Text = "Cannot get write lock for this project"; - } - else - { - root.DeletePluginData(writelock, id); - writelock.Dispose(); - writelock = null; - } - } - catch (Exception ex) - { - if (ex.InnerException == null) - { - m_ContentsTextBox.Text = $"API threw exception: {ex.Message}"; - } - else - { - m_ContentsTextBox.Text = $"API threw exception: {ex.Message}\r\n" + - $"with inner exception {ex.InnerException.Message}"; - } - } - if (writelock != null) - { - writelock.Dispose(); - } - } - } } }