Skip to content

Commit

Permalink
Restore plugin O, but with only public functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpelley committed Jul 11, 2022
1 parent 9ff0be8 commit b1223ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 245 deletions.
10 changes: 10 additions & 0 deletions ParatextDemoPlugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ReferencePluginD/AnnotationSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
118 changes: 21 additions & 97 deletions ReferencePluginO/ControlO.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 0 additions & 147 deletions ReferencePluginO/ControlO.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
Expand All @@ -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))
Expand All @@ -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();
Expand All @@ -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();
}
}
}
}
}

0 comments on commit b1223ec

Please sign in to comment.