Added functionality to the Import Word Content feature (Insert Ribbon in Debug Mode)

This commit is contained in:
Rich
2019-05-06 18:24:02 +00:00
parent c973925790
commit a0461e9a7a
3 changed files with 374 additions and 58 deletions

View File

@@ -25,20 +25,20 @@ namespace Volian.Controls.Library
{
_initializing = true;
InitializeComponent();
// C2019-021 Allow the Number field to be edited.
txbWordFile.Text = Properties.Settings.Default.ImportWordFilePath;
disableButtons();
_initializing = false;
btnOpen.Enabled = (txbWordFile.Text.Length > 0);
}
private void disableButtons()
{
btnOpen.Enabled = false;
btnNext.Enabled = false;
btnPage.Enabled = false;
btnPrev.Enabled = false;
}
}
private void ofd_FileOk(object sender, CancelEventArgs e)
{
_initializing = true;
@@ -86,65 +86,65 @@ namespace Volian.Controls.Library
Properties.Settings.Default.ImportWordFilePath = txbWordFile.Text;
Properties.Settings.Default.Save();
}
private void btnPage_Click(object sender, EventArgs e)
{
_WordApp.Selection.MoveDown(LBWdUnits.wdScreen, 1, 0);
}
private void btnPrev_Click(object sender, EventArgs e)
{
_WordApp.Selection.MoveUp(LBWdUnits.wdParagraph, 1, 0);
_WordApp.Selection.MoveUp(LBWdUnits.wdParagraph, 1, 1);
try
{
int idx = -1;
if (_WordApp.Selection.Text.EndsWith("\t(\r") || _WordApp.Selection.Text.EndsWith("\t___\r"))
idx = _WordApp.Selection.Text.LastIndexOf("\t");
if (idx > 0)
txbWrdText.Text = _WordApp.Selection.Text.Substring(0, idx);
// C2019-021 Use generic function CopyWordText
CopyWordText();
if (txbWrdText.Text.TrimEnd("\r\n\f".ToCharArray()) == "")
btnPrev_Click(sender, e);
else
txbWrdText.Text = _WordApp.Selection.Text;
txbWrdText.Text = txbWrdText.Text.Replace('\xA0', ' '); // replace hard space with regular space
txbWrdText.Text = txbWrdText.Text.Replace('\x0B', ' '); // replace hard return with regular space
txvStyle.Text = _WordApp.Selection.Style.NameLocal;
txbLevel.Text = _WordApp.Selection.Style.ListLevelNumber.ToString();
Clipboard.SetText(txbWrdText.Text);
Clipboard.SetText(txbWrdText.Text);
}
catch
{ }
}
private void btnNext_Click(object sender, EventArgs e)
{
_WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 1, 0);
_WordApp.Selection.MoveDown(LBWdUnits.wdParagraph, 1, 1);
try
{
int idx = -1;
if (_WordApp.Selection.Text.EndsWith("\t(\r") || _WordApp.Selection.Text.EndsWith("\t___\r"))
idx = _WordApp.Selection.Text.LastIndexOf("\t");
if (idx > 0)
txbWrdText.Text = _WordApp.Selection.Text.Substring(0, idx);
// C2019-021 Use Generic CopyWordText
CopyWordText();
// C2019-021If the word text only contains whitespace skip to next
if (txbWrdText.Text.TrimEnd("\f\r\n".ToCharArray()) == "")
btnNext_Click(sender, e);
else
txbWrdText.Text = _WordApp.Selection.Text;
txbWrdText.Text = txbWrdText.Text.Replace('\xA0', ' '); // replace hard space with regular space
txbWrdText.Text = txbWrdText.Text.Replace('\x0B', ' '); // replace hard return with regular space
txbWrdText.Text = txbWrdText.Text.Replace("\t", " "); // replace tabs with 5 regular spaces
txvStyle.Text = _WordApp.Selection.Style.NameLocal;
txbLevel.Text = _WordApp.Selection.Style.ListLevelNumber.ToString();
Clipboard.SetText(txbWrdText.Text);
Clipboard.SetText(txbWrdText.Text);
}
catch
{ }
}
// C2019-021 Generic CopyWordText (Copy Text, Style and Number to fields on form)
private void CopyWordText()
{
txvStyle.Text = _WordApp.Selection.Style.NameLocal;
txbLevel.Text = _WordApp.Selection.Style.ListLevelNumber.ToString();
tbxNumber.Text = _WordApp.Selection.Range.ListFormat.ListString;
int idx = -1;
if (_WordApp.Selection.Text.EndsWith("\t(\r") || _WordApp.Selection.Text.EndsWith("\t___\r"))
idx = _WordApp.Selection.Text.LastIndexOf("\t");
if (idx > 0)
txbWrdText.Text = _WordApp.Selection.Text.Substring(0, idx);
else
txbWrdText.Text = _WordApp.Selection.Text;
txbWrdText.Text = txbWrdText.Text.Replace('\xA0', ' '); // replace hard space with regular space
txbWrdText.Text = txbWrdText.Text.Replace('\x0B', ' '); // replace hard return with regular space
// C2019-021 Don't replace tabs
//txbWrdText.Text = txbWrdText.Text.Replace("\t", " "); // replace tabs with 5 regular spaces
}
private void txbWordFile_TextChanged(object sender, EventArgs e)
{
btnOpen.Enabled = !_initializing;
}
private void frmImportWordContents_FormClosing(object sender, FormClosingEventArgs e)
{
try
@@ -157,34 +157,172 @@ namespace Volian.Controls.Library
// incase user manually closed word
}
}
private void btnNextIns_Click(object sender, EventArgs e)
//C2019-021 Remove old method.
//private void btnNextIns_Click(object sender, EventArgs e)
//{
// if (MyStepRTB != null)
// {
// if (MyStepRTB.MyItemInfo.IsSection)
// {
// MyStepRTB.RtbSendKeys("^{DOWN}"); // <Ctrl><down arrow> - next edit window
// MyStepRTB.RtbSendKeys("^+b"); // insert previous
// }
// else
// MyStepRTB.RtbSendKeys("^+i"); // insert next (same type and level)
// MyStepRTB.RtbSendKeys("^v"); // clipboard paste
// Application.DoEvents();
// }
// this.Focus(); // set focus back to this form
//}
//private void btnNextRpl_Click(object sender, EventArgs e)
//{
// if (MyStepRTB != null)
// {
// MyStepRTB.RtbSendKeys("^{DOWN}"); // <Ctrl><down arrow> - next edit window
// MyStepRTB.RtbSendKeys("^a"); // select all
// MyStepRTB.RtbSendKeys("^v"); // clipboard paste
// Application.DoEvents();
// }
// this.Focus(); // set focus back to this form
//}
// C2019-021 New function to replace the PROMS text with the word text and move to the next paragraph in word.
private void btnReplaceNext_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
if (MyStepRTB.MyItemInfo.IsSection)
if (MyStepRTB.MyItemInfo.IsSection && tbxNumber.Text != "")
{
MyStepRTB.RtbSendKeys("^{DOWN}"); // <Ctrl><down arrow> - next edit window
MyStepRTB.RtbSendKeys("^+b"); // insert previous
using (VEPROMS.CSLA.Library.Item ii = MyStepRTB.MyItemInfo.Get())
{
ii.MyContent.Text = txbWrdText.Text.Trim("\r\n\f".ToCharArray());
ii.MyContent.Number = tbxNumber.Text;
ii.MyContent.Save();
}
EditItem ei = MyStepRTB.Parent as EditItem;
ei.RefreshTab();
}
else
MyStepRTB.RtbSendKeys("^+i"); // insert next (same type and level)
MyStepRTB.RtbSendKeys("^v"); // clipboard paste
Application.DoEvents();
{
MyStepRTB.Text = txbWrdText.Text.Trim("\r\n".ToCharArray());
MyStepRTB.Select(MyStepRTB.TextLength, 0);
}
btnNext_Click(sender, e);
}
this.Focus(); // set focus back to this form
}
private void btnNextRpl_Click(object sender, EventArgs e)
// C2019-021 New function to insert the Word text into PROMS and move to the next paragraph in Word
private void btnInsertNext_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
MyStepRTB.RtbSendKeys("^{DOWN}"); // <Ctrl><down arrow> - next edit window
MyStepRTB.RtbSendKeys("^a"); // select all
MyStepRTB.RtbSendKeys("^v"); // clipboard paste
Application.DoEvents();
MyStepRTB.SelectedText = txbWrdText.Text.Trim("\r\n\f".ToCharArray());
MyStepRTB.Select(MyStepRTB.TextLength, 0);
btnNext_Click(sender, e);
}
}
// C2019-021 New Function to create a after node in PROMS
private void btnAfter_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
EditItem ei = MyStepRTB.Parent as EditItem;
if (ei != null)
{
ei.AddSiblingAfter();
}
}
}
// C2019-021 Add a New Section in PROMS (Default Type = 10000)
private void btnSect_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
EditItem ei = MyStepRTB.Parent as EditItem;
if (ei.MyItemInfo.IsProcedure)
{
ei.AddChild(VEPROMS.CSLA.Library.E_FromType.Section, 10000);// TODO: Need Type for Procedure Steps
return;
}
while (ei != null && !ei.MyItemInfo.IsSection)
if(ei.MyParentEditItem != null)
ei = ei.MyParentEditItem;
else
ei=ei.MyPreviousEditItem;
if (ei != null)
{
ei.AddSiblingAfter();
}
}
}
// C201-021 New Function Add a new High level step
private void btnHigh_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
EditItem ei = MyStepRTB.Parent as EditItem;
if (ei.MyItemInfo.IsSection)
{
ei.AddChild(VEPROMS.CSLA.Library.E_FromType.Step, 20002);
return;
}
while (ei != null && !ei.MyItemInfo.IsHigh)
if (ei.MyParentEditItem != null)
ei = ei.MyParentEditItem;
else
ei = ei.MyPreviousEditItem;
if (ei != null)
{
ei.AddSiblingAfter();
}
}
}
// C2019-021 New Function Add a new sequential substep
private void btnSEQ_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
EditItem ei = MyStepRTB.Parent as EditItem;
ei.AddChild(VEPROMS.CSLA.Library.E_FromType.Step, 20001);
}
}
// C2019-021 New Function Add a new parent step after
private void btnParentAfter_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
EditItem ei = MyStepRTB.Parent as EditItem;
while (ei.MyPreviousEditItem != null)
ei = ei.MyPreviousEditItem;
if (ei != null && ei.MyParentEditItem != null)
{
ei.MyParentEditItem.AddSiblingAfter();
}
}
}
// C2019-021 New Function Split the text in the current proms window into two
// The text before the selection is kept in the current PROMS window
// The selected text is deleted
// the text after the selection is cut to the clipboard
private void btnSplit_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
MyStepRTB.SelectedText = "";
MyStepRTB.Select(MyStepRTB.SelectionStart, MyStepRTB.TextLength - MyStepRTB.SelectionStart);
Clipboard.SetText(MyStepRTB.SelectedText);
MyStepRTB.SelectedText = "";
}
}
// C2019-021 New Function - Performs a paste in the current window
private void btnPaste_Click(object sender, EventArgs e)
{
if (MyStepRTB != null)
{
MyStepRTB.SelectedText = Clipboard.GetText();
}
this.Focus(); // set focus back to this form
}
}
}