/// <summary> /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Command" <see /// cref="ListView"/>.</summary> /// <param name="sender"> /// The <see cref="Object"/> where the event handler is attached.</param> /// <param name="args"> /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param> /// <remarks> /// <b>OnCommandSelected</b> updates the text box to reflect the selected command.</remarks> private void OnCommandSelected(object sender, SelectionChangedEventArgs args) { // clear command text box CommandInfo.Text = ""; // retrieve selected command, if any CommandListItem item = CommandList.SelectedItem as CommandListItem; if (item == null) { return; } // show command text CommandInfo.Text = item.Command.ToString(); CommandInfo.AppendText(Environment.NewLine); // show message events but suppress dialogs foreach (Instruction instruction in item.Command.Program) { MessageInstruction message = instruction as MessageInstruction; if (message != null) { SessionExecutor.ShowMessageEvent(message, CommandInfo, false); } } }
/// <summary> /// Handles the command event represented by the specified <see cref="Instruction"/>. /// </summary> /// <param name="instruction"> /// The <see cref="Instruction"/> that represents the command event to handle.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="instruction"/> is a null reference.</exception> /// <exception cref="PropertyValueException"> /// The current session <see cref="Session.State"/> is <see cref="SessionState.Invalid"/>. /// </exception> /// <remarks><para> /// <b>ShowCommandEvent</b> takes the following actions, depending on the exact type of the /// specified <paramref name="instruction"/>: /// </para><list type="table"><listheader> /// <term>Type</term><description>Action</description> /// </listheader><item> /// <term><see cref="SelectEntityInstruction"/></term> /// <description>Call <see cref="SelectEntityEvent"/>.</description> /// </item><item> /// <term><see cref="ImageInstruction"/></term> /// <description>Call <see cref="ShowImageEvent"/>.</description> /// </item><item> /// <term><see cref="MessageInstruction"/></term> /// <description>Call <see cref="ShowMessageEvent"/>.</description> /// </item><item> /// <term>Other</term><description>Do nothing.</description> /// </item></list></remarks> public static void ShowCommandEvent(Instruction instruction) { if (instruction == null) { ThrowHelper.ThrowArgumentNullException("instruction"); } if (Session.State == SessionState.Invalid) { ThrowHelper.ThrowPropertyValueExceptionWithFormat("Session.State", Session.State, Tektosyne.Strings.PropertyIsValue, SessionState.Invalid); } MessageInstruction message = instruction as MessageInstruction; if (message != null) { AsyncAction.Invoke(() => ShowMessageEvent(message, MainWindow.Instance.EventMessage, true)); return; } SelectEntityInstruction selectEntity = instruction as SelectEntityInstruction; if (selectEntity != null) { SelectEntityEvent(selectEntity); return; } ImageInstruction image = instruction as ImageInstruction; if (image != null) { ShowImageEvent(image); return; } }
private static string GetMessage(MessageInstruction messageInstruction) { return(messageInstruction.Message); }
/// <summary> /// Handles the message event represented by the specified <see cref="Instruction"/>. /// </summary> /// <param name="instruction"> /// The <see cref="MessageInstruction"/> that represents the message event to handle. /// </param> /// <param name="textBox"> /// The <see cref="TextBoxBase"/> control to which to append the message.</param> /// <param name="showDialog"> /// <c>true</c> to display a dialog if requested by the specified <paramref /// name="instruction"/>; otherwise, <c>false</c>.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="instruction"/> or <paramref name="textBox"/> is a null reference. /// </exception> /// <remarks><para> /// <b>ShowMessageEvent</b> creates a text message from the data of the specified <paramref /// name="instruction"/> and appends it to the specified <paramref name="textBox"/> control. /// </para><para> /// If <paramref name="instruction"/> is of type <see cref="ShowMessageDialogInstruction"/> /// and <paramref name="showDialog"/> is <c>true</c>, <b>ShowMessageEvent</b> also shows the /// message text in a <see cref="Dialog.ShowEvent"/> dialog.</para></remarks> public static void ShowMessageEvent(MessageInstruction instruction, TextBoxBase textBox, bool showDialog) { if (instruction == null) { ThrowHelper.ThrowArgumentNullException("instruction"); } if (textBox == null) { ThrowHelper.ThrowArgumentNullException("textBox"); } // show message in a modal dialog? bool dialog = (instruction is ShowMessageDialogInstruction); // get mandatory summary text string summary = StringUtility.Validate( instruction.Text, Global.Strings.LabelEventUnknown); // get details text (mandatory for dialog) string details = instruction.Details; if (dialog) { details = StringUtility.Validate(details, Global.Strings.InfoEventUnknown); } // get optional faction and entity names FactionClass faction = instruction.Faction; string[] names = instruction.Names.ToArray(); // create caption from faction and summary StringBuilder caption = new StringBuilder(); if (faction != null) { caption.Append(faction.Name); caption.Append(": "); } caption.Append(summary); // create message from details and names StringBuilder message = new StringBuilder(); if (details != null) { message.Append(details); } // append specified names to message if (names != null) { foreach (string name in names) { if (message.Length > 0) { message.Append(Environment.NewLine); } message.Append('\t'); message.Append(name); } } // append message to event view text textBox.AppendText("– "); // en dash textBox.AppendText(caption.ToString()); textBox.AppendText(Environment.NewLine); if (message.Length > 0) { textBox.AppendText(message.ToString()); textBox.AppendText(Environment.NewLine); } // show message as dialog if desired if (dialog && showDialog) { // temporarily restore normal cursor if in wait mode var cursor = Mouse.OverrideCursor; Mouse.OverrideCursor = null; Dialog.ShowEvent.Show(MainWindow.Instance, message.ToString(), caption.ToString()); Mouse.OverrideCursor = cursor; } }