Ejemplo n.º 1
0
		protected void OnAttributeLevelMenuClick(object sender, EventArgs args)
		{
			var menuItem = (sender as ToolStripMenuItem);

			if (menuItem == null)
			{
				Debug.Assert(false);
				return;
			}

			var selText = GetTextRange();

			if (selText == null)
			{
				Debug.Assert(false);
				return;
			}

			int level = -1;

			if (!Int32.TryParse(menuItem.Name, out level))
				level = -1;

			string basePlaceholder;
			int unused;

			if (HtmlReportUtils.ParsePlaceholder(selText, out basePlaceholder, out unused, true)) // atomic
			{
				var element = selText.parentElement();

				if (!HtmlReportUtils.IsPlaceholder(element))
				{
					Debug.Assert(false);
					return;
				}

				element.innerText = HtmlReportUtils.FormatPlaceholder(basePlaceholder, level);
			}
			else if (HtmlReportUtils.ParsePlaceholder(selText, out basePlaceholder, out unused)) // plain text
			{
				selText.text = HtmlReportUtils.FormatPlaceholder(basePlaceholder, level);
			}

			OnSelectionChange();
		}
Ejemplo n.º 2
0
		protected void OnAttributeMenuClick(object sender, EventArgs args)
		{
			var menuItem = (sender as ToolStripMenuItem);

			if (menuItem == null)
			{
				Debug.Assert(false);
				return;
			}

			var selText = GetTextRange();

			if (selText == null)
			{
				Debug.Assert(false);
				return;
			}

			string unused;
			int level;

			if (HtmlReportUtils.ParsePlaceholder(selText, out unused, out level, true)) // atomic
			{
				var element = selText.parentElement();

				if (!HtmlReportUtils.IsPlaceholder(element))
				{
					Debug.Assert(false);
					return;
				}

				element.innerText = HtmlReportUtils.FormatPlaceholder(menuItem.Name, level);
			}
			else if (HtmlReportUtils.ParsePlaceholder(selText, out unused, out level)) // plain text
			{
				selText.text = HtmlReportUtils.FormatPlaceholder(menuItem.Name, level);
			}
			else if (String.IsNullOrEmpty(selText.text)) // insertion point
			{
				// This is the trickiest bit because if we are
				// butted up against an atomic placeholder our
				// text can end up merged with that so we have to
				// do a bit of detective work and shift the selection
				// to a safer location

				// Look to the left
				var tempSel = selText.duplicate();

				tempSel.moveStart("character", -1);
				bool placeHolderToLeft = ((tempSel.text != null) && tempSel.text.Equals(")"));

				// Look to the right
				tempSel = selText.duplicate();

				tempSel.moveEnd("character", 1);
				bool placeHolderToRight = ((tempSel.text != null) && tempSel.text.Equals("$"));

				if (placeHolderToLeft)
				{
					selText.move("character", 1);
				}
				else if (placeHolderToRight)
				{
					selText.move("character", -1);
				}

				// if we have placeholders on both sides then we have to tell 
				// the user to insert a space first and then try again
				if (placeHolderToLeft && placeHolderToRight)
				{
					MessageBox.Show(m_Trans.Translate("Please insert at least one space between the existing placeholders and then try again."), m_Trans.Translate("Report Builder"), MessageBoxButtons.OK, MessageBoxIcon.Information);
					Focus();

					return;
				}

				selText.pasteHTML(HtmlReportUtils.FormatAtomicPlaceholderHtml(menuItem.Name, -1));
			}
			else // some other text selected
			{
				selText.pasteHTML(HtmlReportUtils.FormatAtomicPlaceholderHtml(menuItem.Name, -1));
			}

			OnSelectionChange();
		}