public void TriggerAction(Action action) { // called by frmMain when it detects one of the palette control actions and this colour panel is focused if (!this.Enabled || !m_Applicable) { return; } switch ((action as PaletteButtonAction)?.Index ?? 0) { // will be 0 for any other actions, and drop into default case 1: HandleClick(MOREBUTTON); break; case 2: HandleClick(TRANSPARENTBUTTON); break; default: Utilities.LogSubError("Unexpected code in ColourPanel::TriggerAction"); return; } if (this.Focused) { Globals.Root.PerformAction(Verb.Find(Codes.RestoreFocus)); } // for keyboard users need to return to main area, as selecting a colour does }
private void AddShapeForParameters(Datum obj) { // Adds the given shape to m_Parameters if (!(obj is ButtonShape)) { return; } Action action = ((ButtonShape)obj).Action; if (action is ValueSelectableAction) { // Need to check if we have a list for this parameter yet... if (!m_Parameters.ContainsKey(action.Change)) { m_Parameters.Add(action.Change, new List <ButtonShape>()); } m_Parameters[action.Change].Add((ButtonShape)obj); } else if (action.Change == Parameters.Action_Key || action.Change == Parameters.Action_Character || action.Change == Parameters.Action_Text) { m_KeyShapes.Add((ButtonShape)obj); } else // if (action.Change == Parameters.Action_Verb) { m_OtherApplicable.Add((ButtonShape)obj); } }
private void FillStyleActions(TreeNode top, Parameters parameter, bool withCustom = false) { TreeNode folder = top.Nodes.Add(ParameterSupport.GetParameterTypeName(parameter)); // the first entry selects the palette, but limited for one or two parameters where they share a palette if (Mode != Modes.Button) // buttons on palettes don't switch to other palettes { switch (parameter) { case Parameters.LineWidth: break; default: AddAction(folder, new PaletteAction(parameter), Strings.Item("Config_SwitchToPalette"), "CursorClick"); break; } } foreach (int value in ParameterSupport.GetStandardParameterValues(parameter)) { AddAction(folder, Action.Create(parameter, value), ParameterSupport.GetParameterValueName(parameter, value)); } if (withCustom) { AddAction(folder, new ParameterAction(parameter, 0, true), Strings.Item("Custom_Style_Value")); } }
private void SetKeyFromText() { if (txtText.Text.Length == 0) { return; } if (m_Action.Change == Parameters.Action_Character) { if (txtText.Text.IsTranslatable()) { // Need to store the entire translatable text m_Action = new CharAction(txtText.Text); } else { m_Action = new CharAction(txtText.Text[0]); } } else if (m_Action.Change == Parameters.Action_Text) { m_Action = new TextAction(txtText.Text); } else { Keys key = txtText.Text[0].ToKeyData(); if (((int)key & 255) == 255) // seems to mean that there was no valid key { m_Action = new CharAction(txtText.Text[0]); } else { m_Action = new KeyAction(key); } } }
private void AddAction(TreeNode folder, Action action, string title = "?", string imageName = "?") { if (action == null) { return; // can happen for verb enums that aren't used } // we don't usually use objaction.Description, because sometimes that is a bit longer (describing context which is obvious in the Treeview) // strImage is the key of the image to use; pass "" to omit the image. If "?" it is created from the action if (title == "?") { title = action.DescriptionWithoutAccelerator(); } TreeNode node = folder.Nodes.Add(title); if (imageName == "?") { Image bitmap = action.CreateSampleImage(); if (bitmap != null) { ActionImageList.Images.Add(action.ToString(), bitmap); imageName = action.ToString(); } else { imageName = "Empty"; } } node.ImageKey = imageName; node.SelectedImageKey = imageName; node.Tag = action; }
private static string GenerateKeyLine(Keys key) { // generate one line for the above table. This includes all the variations of shift and control // the Alt key must be put on a separate line System.Text.StringBuilder output = new System.Text.StringBuilder(); bool defined = false; // true if any keys were defined output.Append("<tr><td>").Append(GUIUtilities.KeyDescription(key).Replace("<", "")).Append("</td>"); foreach (Keys modifier in new[] { Keys.None, Keys.Shift, Keys.Control, Keys.Shift | Keys.Control }) { Functions.Action action = Globals.Root.CurrentConfig.KeyAction(key | modifier); output.Append("<td>"); if (!action.IsEmpty) { output.Append(action.DescriptionWithoutAccelerator()); defined = true; } output.Append("</td>"); } if (!defined) { return(""); } output.AppendLine("</tr>"); return(output.ToString()); }
private void RoundButton_MouseEnter(object sender, EventArgs e) { // mostly implemented in base class if (m_Parameter != Parameters.None) { Globals.SetHover(Action.Create(m_Parameter, m_ParameterValue)); } }
private void TV_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { // occurs before select Action action; if (e.Node.Tag != null) { action = (Action)e.Node.Tag; // TV.SelectedNode.Tag } else { action = Action.Empty; } if ((action as ParameterAction)?.CustomRequiresParameter ?? false) { // must select value string value = "Cancel"; // If a valid selection is made the TextValue is put here Action selected = SelectedAction; switch (action.Change) { case Parameters.LineWidth: float width = frmLineWidth.Ask(selected.Change == Parameters.LineWidth ? (selected as ParameterAction).Value / 100f : float.NaN); if (!float.IsNaN(width)) { value = (width * 100).ToString(); } break; case Parameters.LineColour: case Parameters.FillColour: Color col = Color.Empty; if (selected.Change == Parameters.FillColour || selected.Change == Parameters.LineColour) { col = Color.FromArgb((selected as ParameterAction).Value); } col = frmMoreColours.DisplayPickColour(FindForm(), col, useSettings: false); if (!col.IsEmpty) { value = col.ToArgb().ToString(); } break; default: Utilities.LogSubError("Unexpected Change in ctrActionSelect.TV_AfterSelect"); break; } if (value == "Cancel") { TV.SelectedNode = null; } else { m_CustomValue = new ParameterAction(action.Change, int.Parse(value)); SelectionChanged?.Invoke(this, EventArgs.Empty); } } }
public void ctrActionColour_UserChangedColour(object sender, EventArgs e) { m_Filling = true; m_Action = new ParameterAction(m_Action.Change, ctrActionColour.CurrentColour.ToArgb()); ctrActions.SelectedAction = Action.Empty; string temp; ButtonShape.GetDisplayFromAction(m_Action, out temp, out m_NewImage, m_Transaction); txtText.Text = temp; ImageChanged(); m_Filling = false; }
internal static void SetHover(Action action) { Shape.Prompt prompt = action.GetPrompt(); if (prompt != null) { m_HoverPrompts = new List <Shape.Prompt>(); m_HoverPrompts.Add(prompt); } else { m_HoverPrompts = null; } SetPrompts(); }
public void ctrActions_AfterSelect(object sender, EventArgs e) { if (m_Filling) { return; } m_Filling = true; try { Action action = ctrActions.SelectedAction; m_Action = action; if (action.Change == Parameters.Action_Key) { // For simulated keys we don't update the text on selecting the action; we will update is the user actually types a key // However is there is already text, and there is no key selected yet, then we will fill it in based on the text if (txtText.Text.Length > 0 && (action as KeyAction).Key == Keys.None) { SetKeyFromText(); // The display in the box will be updated by ReflectAction } } else if (action.Change == Parameters.Action_Character) { if (txtText.Text.Length > 0 && (action as CharAction).Character == '\0') { SetKeyFromText(); } } else if (action.Change == Parameters.Action_Text) { if (txtText.Text.Length > 0 && string.IsNullOrEmpty((action as TextAction).Text)) { SetKeyFromText(); } } else if (chkDisplayFromAction.Checked && action.Change != Parameters.None) { string temp; ButtonShape.GetDisplayFromAction(m_Action, out temp, out m_NewImage, m_Transaction); txtText.Text = temp; ImageChanged(); } } finally { m_Filling = false; } ReflectAction(); }
public void txtActionKey_TextChanged(object sender, EventArgs e) { if (m_Action.Change != Parameters.Action_Text) { return; } m_Filling = true; m_Action = new TextAction(txtActionKey.Text); if (chkDisplayFromAction.Checked || chkActionKeyAuto.Checked) { // update the text txtText.Text = txtActionKey.Text; } m_Filling = false; }
private static TreeNode FindAction(Action action, TreeNodeCollection list) { foreach (TreeNode test in list) { if (test != null && action.Equals(test.Tag)) { return(test); } TreeNode found = FindAction(action, test.Nodes); if (found != null) { return(found); } } return(null); }
private TreeNode FindAction(Action action) { switch (action.Change) { case Parameters.Action_Key: return(m_KeyNode); // this won't be found otherwise, because the exact value won't match case Parameters.Action_Character: return(m_CharacterNode); case Parameters.Action_Text: return(m_TextNode); default: return(FindAction(action, TV.Nodes)); } }
private void DisplayKey(Keys key) { m_DisplayedKey = key; bool wasFilling = m_Filling; m_Filling = true; try { pnlKeys.SuspendLayout(); if (key == Keys.None) { txtKey.ForeColor = Color.Silver; txtKey.Text = Strings.Item("Config_PressKey"); pnlCurrentKey.Visible = false; } else { txtKey.ForeColor = Color.Black; txtKey.Text = GUIUtilities.KeyDescription(key); pnlCurrentKey.Visible = true; } m_KeyIsFocal = (key & Keys.KeyCode) == Keys.Tab; // (frmMain.KeyType(eKey) = frmMain.KeyTypes.Focal) Functions.Action objAction = m_SubsequentApplied.KeyAction(m_DisplayedKey); // m_objApplied.KeyAction(m_eDisplayedKey) btnClearKey.Visible = m_DisplayedKey != Keys.None && m_Config.HasValue(Config.KeyKey(m_DisplayedKey)) && !m_KeyIsFocal; // note only displayed if setting is in THIS config lblKeyCurrent.Text = objAction.DescriptionWithoutAccelerator(); if (m_KeyIsFocal) { lblKeyWarning.Text = Strings.Item("Config_KeyFocal"); lblKeyWarning.Visible = true; } else { lblKeyWarning.Visible = false; } btnKeysReset.Visible = Level != Config.Levels.System; EnableKeyAssign(); } finally { pnlKeys.ResumeLayout(); m_Filling = wasFilling; } }
public void tvActions_AfterSelect(object sender, EventArgs e) { Functions.Action action = tvActions.SelectedAction; if (action.IsEmpty) { lblActionCurrentKeys.Visible = false; // no action selected lblKeyAction.Text = Strings.Item("Config_KeyNoAction"); lblKeyAction.ForeColor = Color.Silver; } else { lblKeyAction.ForeColor = Color.Black; lblKeyAction.Text = action.DescriptionWithoutAccelerator(); List <Keys> keys = m_Applied.GetKeysForAction(action); if (keys == null || keys.Count == 0) { lblActionCurrentKeys.Visible = false; } else { System.Text.StringBuilder output = new System.Text.StringBuilder(Strings.Item("Config_ActionCurrentKeys")); output.Append(" "); bool first = true; foreach (Keys key in keys) { if (!first) { output.Append(", "); } output.Append(GUIUtilities.KeyDescription(key)); first = false; } lblActionCurrentKeys.Text = output.ToString(); lblActionCurrentKeys.Visible = true; } m_KeyActionChanged = true; } EnableKeyAssign(); }
public void txtActionKey_KeyPress(object sender, KeyPressEventArgs e) { if (m_Action.Change != Parameters.Action_Character) { return; } e.Handled = true; var ch = e.KeyChar; if (ch < 32) { return; // don't type unprintable "characters". Tab would make some sense, but can probably be done as a key anyway } m_Filling = true; txtActionKey.Text = ch.ToString(); m_Action = new CharAction(ch); if (chkDisplayFromAction.Checked || chkActionKeyAuto.Checked) { // update the text txtText.Text = ch.ToString(); } m_Filling = false; }
public void btnSetKey_Click(object sender, EventArgs e) { if (tvActions.SelectedAction.IsEmpty || m_DisplayedKey == Keys.None) { return; } Functions.Action action = tvActions.SelectedAction; Functions.Action existing = m_Applied.KeyAction(m_DisplayedKey); if (action.Equals(existing)) { return; } if (!existing.IsEmpty) { if (GUIUtilities.QuestionBox(Strings.Item("Config_KeyReplaceWarning").Replace("%0", lblKeyCurrent.Text), MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } } List <Keys> keys = m_Applied.GetKeysForAction(action); if (keys != null && keys.Count == 1 && keys[0] != m_DisplayedKey) { if (GUIUtilities.QuestionBox(Strings.Item("Config_KeyRemoveExisting").Replace("%0", GUIUtilities.KeyDescription(keys[0])), MessageBoxButtons.YesNo) == DialogResult.Yes) { m_Config.Write(Config.KeyKey(keys[0]), ""); } } m_Config.Write(Config.KeyKey(m_DisplayedKey), action.ToString()); WrittenToCurrent(); m_Applied.DiscardKeyLookup(); DisplayKey(m_DisplayedKey); tvActions_AfterSelect(this, null); m_KeyActionChanged = false; m_KeyIsChanged = false; }
public void txtActionKey_KeyDown(object sender, KeyEventArgs e) { if (m_Action.Change == Parameters.Action_Character) { if (e.KeyData == Keys.Back) { } else if (e.KeyData == Keys.Delete) { txtActionKey.Text = ""; m_Action = new CharAction((char)0); e.SuppressKeyPress = true; e.Handled = true; } else if (e.KeyData == (Keys.V | Keys.Control)) { if (Clipboard.ContainsText()) { var strText = Clipboard.GetText(); if (!string.IsNullOrEmpty(strText)) { txtActionKey.Text = strText.Substring(0, 1); m_Action = new CharAction(strText[0]); e.SuppressKeyPress = true; e.Handled = true; } } } } if (m_Action.Change != Parameters.Action_Key) { return; } switch (e.KeyCode) { case Keys.ShiftKey: case Keys.LMenu: case Keys.ControlKey: case Keys.RMenu: case Keys.RShiftKey: case Keys.RWin: case Keys.LWin: case Keys.LControlKey: case Keys.RControlKey: break; case Keys.RButton: case Keys.Menu: break; default: m_Filling = true; CombinedKeyEvent eCombined = new CombinedKeyEvent(e); // on Mac this will modify the key as needed txtActionKey.Text = GUIUtilities.KeyDescription(eCombined.KeyData); m_Action = new KeyAction(eCombined.KeyData); if (chkActionKeyAuto.Checked) { // update the text txtText.Text = eCombined.KeyData.ToCharacter().ToString(); } m_Filling = false; break; } e.SuppressKeyPress = true; e.Handled = true; }
public void PerformAction(Functions.Action action, EditableView.ClickPosition.Sources source = EditableView.ClickPosition.Sources.Irrelevant) { Editor.PerformAction(action, source); }
public static bool ActionApplicable(Action action) { return(action.IsApplicable(Editor?.pnlView)); }
public static void PerformAction(Action action, EditableView.ClickPosition.Sources source) { Editor?.PerformAction(action, source); }
private Action m_Action; // cannot directly update m_Button because the View (on the original document) can have trouble rendering if the action is updated but not the image public frmButton(ButtonStyle style, ButtonShape button, Transaction transaction) { m_Filling = true; InitializeComponent(); Strings.Translate(this); // must not be in Load, as the data occasionally has translatable items Strings.Translate(mnuImage); m_Button = button; m_Style = style; // must be before any parameters are attached m_OriginalStyle = style; m_Transaction = transaction; m_Action = button.Action; FillStylesList(); ReflectCustomState(); ctrStyle.DisplayStyle(m_Style); // content txtText.Text = button.LabelText; pnlImagePreview.Image = button.GetImageForPreview(); if (button.TextRatio < 0) { sldTextRatio.Value = 50; rdoTextRatioDefault.Checked = true; } else { sldTextRatio.Value = (int)(button.TextRatio * 100); rdoTextRatioSet.Checked = true; } pnlImagePreview.NoImageString = Strings.Item("Button_NoImage"); PrepareLayout(); pnlLayout.SelectedIndex = Math.Min((int)m_Button.Layout & ((int)ButtonShape.Layouts.Superimpose - 1), pnlLayout.Controls.Count - 1); chkSuperimpose.Checked = (m_Button.Layout & ButtonShape.Layouts.Superimpose) > 0; ShowRatioAndLayout(); // We need the configuration which will (probably) be in effect when the palette is used. We assume user mode // as this is mainly to detect custom shapes. Any available in user mode will also be available in teacher mode Document document = Globals.Root.CurrentDocument; // document being edited; PROBABLY a palette, although buttons can be placed on pages ?? if (document.PaletteWithin != null) { document = document.PaletteWithin.Document; } AppliedConfig applied = new AppliedConfig(); applied.AddConfigAtEnd(document.UserSettings); // Doesn't matter if any of the items passed to AddConfigAtEnd are nothing applied.AddConfigAtEnd(document.BothSettings); // Add the activity, if there is one specified in the document... if (!document.ActivityID.Equals(Guid.Empty)) { Document activity = Activities.GetActivitySettings(document.ActivityID); if (activity != null) { applied.AddConfigAtEnd(activity.UserSettings); applied.AddConfigAtEnd(activity.BothSettings); } } applied.AddConfigAtEnd(Config.UserCurrent); // User mode is assumed. Any custom shapes only present in teacher mode will be ignored // (Note that the actions list isn't really interested in what is visible; only what is defined) applied.AddConfigAtEnd(Config.SystemConfig); ctrActions.Fill(applied); // Actions data chkDisplayFromAction.Checked = button.DisplayFromAction; ctrActions.SelectedAction = m_Action; if (button.Action.Change == Parameters.Action_Key) { chkActionKeyAuto.Checked = !string.IsNullOrEmpty(button.LabelText) && button.LabelText[0].ToKeyData() == (button.Action as KeyAction).Key; } else if (button.Action.Change == Parameters.Action_Character) { chkActionKeyAuto.Checked = true; // I think the only way of achieving this is using the checkbox } else if (button.Action.Change == Parameters.Action_Text) { chkActionKeyAuto.Checked = button.LabelText == (button.Action as TextAction).Text; } ReflectAction(); m_Filling = false; }