Пример #1
0
    public Form1()
    {
        FlowLayoutPanel panel = new FlowLayoutPanel();

        TabTextBox tabTextBox1 = new TabTextBox();

        tabTextBox1.Text = "TabTextBox";
        panel.Controls.Add(tabTextBox1);

        TextBox textBox1 = new TextBox();

        textBox1.Text = "Normal TextBox";
        panel.Controls.Add(textBox1);

        this.Controls.Add(panel);
    }
Пример #2
0
 private void AppBarSelectAllButtonClicked(object sender, RoutedEventArgs e)     //全选
 {
     TabTextBox.SelectAll();
 }
Пример #3
0
 private void AppBarCutButtonClicked(object sender, RoutedEventArgs e)       //剪切
 {
     TabTextBox.CutSelectionToClipboard();
 }
Пример #4
0
 private void AppBarPasteButtonClicked(object sender, RoutedEventArgs e)     //粘贴
 {
     TabTextBox.PasteFromClipboard();
 }
Пример #5
0
 private void AppBarRedoButtonClicked(object sender, RoutedEventArgs e)      //重做
 {
     TabTextBox.Redo();
 }
Пример #6
0
 private void AppBarCopyButtonClicked(object sender, RoutedEventArgs e)      //复制
 {
     TabTextBox.CopySelectionToClipboard();
 }
Пример #7
0
        private void HandleSpecialPaste(TabTextBox tx)
        {
            if (Clipboard.ContainsText(TextDataFormat.UnicodeText))
            {
                String s = Clipboard.GetText(TextDataFormat.UnicodeText);
                if ((s != null) && (s != String.Empty))
                {
                    s = System.Text.RegularExpressions.Regex.Replace(s, @"[^a-zA-Z0-9]", "");
                    
                    //String copy = tx.Text;
                    int ss = tx.SelectionStart;
                    int len = tx.Text.Length;
                    if (tx.SelectedText != String.Empty)
                    {
                        len -= tx.SelectionLength;
                        //copy = copy.Remove(tx.SelectionStart, tx.SelectionLength);
                        len += s.Length;
                        //copy = copy.Insert(tx.SelectionStart, s);
                    }
                    else
                    {
                        //copy = copy.Insert(tx.SelectionStart, s);
                        len += s.Length;
                    }

                    ss += s.Length;
                    int diff = 0;
                    if (len > tx.MaxLength)
                    {
                        diff = len - tx.MaxLength;
                    }

                    if (diff > s.Length)
                        s = String.Empty;
                    else if (diff > 0)
                        s = s.Substring(0, s.Length - diff);

                    if ((s.Length > 0) && (s != String.Empty))
                    {
                        tx.Paste(s);
                        if (ss > tx.Text.Length)
                            tx.SelectionStart = tx.Text.Length;
                        else tx.SelectionStart = ss;
                    }

                    tx.SelectionLength = 0;
                }
                else tx.Paste();
            }
        }
Пример #8
0
 private void AppBarUndoButtonClicked(object sender, RoutedEventArgs e)      //撤销
 {
     TabTextBox.Undo();
 }
Пример #9
0
        private void textBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (sender == null)
                return;

            if (sender is TabTextBox)
            {
                TabTextBox src = sender as TabTextBox;
                if ((e.KeyCode == Keys.Back) && (src.SelectionStart == 0))
                {
                    if ((Preferences.EnterCreatesNewLine == 0) ||
                        ((Preferences.EnterCreatesNewLine != 0) && (src == textBoxName) && (src.SelectionStart == 0)))
                    {
                        SendKeys.Send("{UP}");
                        e.SuppressKeyPress = true;
                        e.Handled = true;
                    }
                    else if (((Preferences.EnterCreatesNewLine == 1) || (Preferences.EnterCreatesNewLine == 2)) && (src.SelectionStart == 0) && (src != textBoxName) && (src != textBoxLine1))
                    {
                        int startPos = getNumfromTTB(src);
                        TabTextBox newsrc = getTTBfromNum(startPos - 1);
                        int oldSP = newsrc.TextLength;
                        textBoxBackspace(newsrc);
                        SendKeys.Send("{UP}");
                        newsrc.SelectionStart = oldSP;
                        e.SuppressKeyPress = true;
                        e.Handled = true;
                    }
                }
                else if ((e.KeyCode == Keys.Delete) && (src.SelectionStart == src.TextLength))
                {
                    if (Preferences.EnterCreatesNewLine != 0)
                    {
                        int oldSP = src.TextLength;
                        textBoxBackspace(src);
                        src.SelectionStart = oldSP;
                        e.SuppressKeyPress = true;
                        e.Handled = true;
                    }
                }
                else if (e.KeyCode == Keys.Enter)// handle enter as if we went DOWN
                {
                    if ((Preferences.EnterCreatesNewLine == 0) ||
                        ((Preferences.EnterCreatesNewLine != 0) && 
                            (((src == textBoxLine6) && (src.SelectionStart == src.TextLength))
                            || (src == textBoxName))))
                        SendKeys.Send("{DOWN}");
                    // Just Insert                          Safe Insert
                    else if ((src != textBoxName) && (Preferences.EnterCreatesNewLine == 1) || (Preferences.EnterCreatesNewLine == 2))
                    {
                        bool WarnOnInsert = (Preferences.EnterCreatesNewLine == 2);
                        int startPos = getNumfromTTB(src);

                        if (src.SelectionStart == 0)
                        {
                            textBoxInsertLine(src, startPos, String.Empty, WarnOnInsert);
                        }
                        else if ((src.SelectionStart == src.TextLength) && (src.TextLength > 0))
                        {
                            startPos++;
                            TabTextBox newsrc = getTTBfromNum(startPos);
                            textBoxInsertLine(newsrc, startPos, String.Empty, WarnOnInsert);
                        }
                        else // somewhere in middle of line
                        {
                            String stufftomove = src.Text.Substring(src.SelectionStart);
                            TabTextBox newsrc = getTTBfromNum(startPos + 1);
                            if (src.SelectionLength > 0)
                                stufftomove = src.Text.Substring(src.SelectionStart + src.SelectionLength);
                            if (textBoxInsertLine(newsrc, startPos + 1, stufftomove, WarnOnInsert))
                            {
                                src.Text = src.Text.Remove(src.SelectionStart);
                                src.SelectionLength = 0;

                            }
                        }
                        e.SuppressKeyPress = true;
                        e.Handled = true;
                    }
                }

                if (((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down)) && !(e.Control || e.Alt || e.Shift))
                {
                    #region DONE: ALL TextBox(Name & Line1-6) Up/Down Arrow pressed Move to next
                    TabTextBox upbox = null, downbox = null;

                    if (src == textBoxName)
                    {
                        upbox = textBoxLine6;
                        downbox = textBoxLine1;
                    }
                    else if (src == textBoxLine1)
                    {
                        upbox = textBoxName;
                        downbox = textBoxLine2;
                    }
                    else if (src == textBoxLine2)
                    {
                        upbox = textBoxLine1;
                        downbox = textBoxLine3;
                    }
                    else if (src == textBoxLine3)
                    {
                        upbox = textBoxLine2;
                        downbox = textBoxLine4;
                    }
                    else if (src == textBoxLine4)
                    {
                        upbox = textBoxLine3;
                        downbox = textBoxLine5;
                    }
                    else if (src == textBoxLine5)
                    {
                        upbox = textBoxLine4;
                        downbox = textBoxLine6;
                    }
                    else if (src == textBoxLine6)
                    {
                        upbox = textBoxLine5;
                        downbox = textBoxName;
                    }
                    if (e.KeyCode == Keys.Up)
                    {
                        int ss = upbox.SelectionStart, sL = upbox.SelectionLength;
                        upbox.SelectionLength = 0;
                        upbox.Focus();
                        upbox.SelectionStart = ss;
                        upbox.SelectionLength = sL;
                        e.Handled = true;
                    }
                    if (e.KeyCode == Keys.Down)
                    {
                        int ss = downbox.SelectionStart, sL = downbox.SelectionLength;
                        downbox.SelectionLength = 0;
                        downbox.Focus();
                        downbox.SelectionStart = ss;
                        downbox.SelectionLength = sL;
                        e.Handled = true;
                    }
                    #endregion
                }

                // if alt is held down and key press is left, up, right, or down, special case

                if (((e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right) ||
                    (e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down)))
                {
                    #region If Key is Up, Left, Down, or Right, check modifiers
                    // use current selected node as macro
                    // macro should be selected if textboxname is enabled
                    CMacroFile cmf = FindMacroFileByNode(treeView.SelectedNode);
                    CMacro cm = null;
                    if (cmf != null)
                        cm = GetCurrentMacro(cmf);
                    if ((cmf != null) && (cm != null))
                    {
                        #region If it's a Macro Set ONLY
                        if ((e.Alt) && !(e.Control || e.Shift))
                        {
                            #region Alt is being held down, but not Ctrl or Shift
                            // Alt+Left     goes previous Macro
                            // Alt+Right    goes next Macro
                            // Alt+Down     goes to Alt/Ctrl Bar
                            // Alt+Up        "    "    "      "
                            int mn = cm.MacroNumber;
                            if (e.KeyCode == Keys.Left)
                                mn--;
                            else if (e.KeyCode == Keys.Right)
                                mn++;
                            else if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down))
                            {
                                if ((mn >= 0) && (mn <= 9))
                                    mn += 10;
                                else if ((mn >= 10) && (mn <= 19))
                                    mn -= 10;
                            }
                            if (mn < 0)
                                mn = 19; // skip to last
                            else if (mn > 19)
                                mn = 0;  // skip to first
                            treeView.SelectedNode = cmf.Macros[mn].thisNode;
                            FillForm(cmf.Macros[mn]);
                            e.Handled = true;
                            #endregion
                        }
                        if (!(e.Alt) && (e.Control && e.Shift))
                        {
                            #region if Alt is NOT being held down but both Ctrl+Shift is
                            if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down))
                            {

                                // Ctrl+Shift+Up or Ctrl+Shift+Down
                                // Cycles between Macro Sets (Next/Previous)
                                TreeNode tN = null;
                                if (e.KeyCode == Keys.Up)
                                {
                                    // If Ctrl+Shift+Up
                                    // if there's no PrevNode in this list (first in list for parents nodes)
                                    if (cmf.thisNode.PrevNode == null)
                                        // Skip to Parent's Last Node
                                        tN = cmf.thisNode.Parent.LastNode;
                                    // Else Go To Previous Node
                                    else tN = cmf.thisNode.PrevNode;
                                    // look to see if it's a valid MacroFile Node
                                    CMacroFile cmfnew = FindMacroFileByNode(tN);
                                    if (cmfnew != null)
                                    {
                                        // if it is, select it
                                        this.treeView.SelectedNode = tN;
                                        FillForm(cmfnew.Macros[cm.MacroNumber]);
                                    }
                                    // if not, don't select it
                                    // avoids problems with FillForm
                                    // in the meantime, no matter what, call this keyset as handled
                                    e.Handled = true;
                                }
                                else if (e.KeyCode == Keys.Down)
                                {
                                    // if Ctrl+Shift+Down
                                    // if there's no NextNode in this list (end of list for parent's)
                                    if (cmf.thisNode.NextNode == null)
                                        // Skip to Parent's First Node
                                        tN = cmf.thisNode.Parent.FirstNode;
                                    else tN = cmf.thisNode.NextNode;
                                    CMacroFile cmfnew = FindMacroFileByNode(tN);
                                    if (cmfnew != null)
                                    {
                                        this.treeView.SelectedNode = tN;
                                        FillForm(cmfnew.Macros[cm.MacroNumber]);
                                    }
                                    e.Handled = true;
                                }
                            }
                            #endregion
                        }
                        #endregion
                    }
                    #endregion
                }

                if (src == textBoxName)
                {
                    if ((e.KeyCode == Keys.V) && (e.Control) && (src == textBoxName))
                    {
                        #region if Pasting
                        HandleSpecialPaste(src); // instead of src.Paste()
                        e.SuppressKeyPress = true;
                        e.Handled = true;
                        #endregion
                    }

                    #region TODO?: Determine if keypressed in textBoxName is not valid and handle
                    // Initialize the flag to true.
                    nonAlphaNumEntered = true;
                    if (
                         (e.KeyCode == Keys.Left) || (e.KeyCode == Keys.Right) ||
                         (e.KeyCode == Keys.Delete) || (e.KeyCode == Keys.Back) ||
                        ((e.KeyCode >= Keys.A) && (e.KeyCode <= Keys.Z)) ||
                        (((e.KeyCode >= Keys.D0) && (e.KeyCode <= Keys.D9)) && (!(e.Shift || e.Alt || e.Control))) ||
                        (((e.KeyCode >= Keys.NumPad0) && (e.KeyCode <= Keys.NumPad9)) && (!(e.Shift || e.Alt || e.Control)))
                        )
                    {
                        nonAlphaNumEntered = false;
                    }
                    //else e.SuppressKeyPress = true;
                    #endregion
                }

                if (src != textBoxName)
                {
                    #region DONE: Handle Tab Key Pressed event in anything but textBoxName
                    if ((e.KeyCode == Keys.Tab) && !(e.Shift || e.Alt || e.Control))
                    {
                        Point p;
                        CMacroFile cmf_ref = FindMacroFileByNode(this.treeView.SelectedNode);
                        CMacro cm_ref = GetCurrentMacro(cmf_ref);
                        bool modified = false;

                        if (cm_ref != null)
                        {
                            start_len my_sel = GetWordOrPhraseFromSelection(src.Text, src.SelectionStart, src.SelectionLength);
                            string correct_selection = src.Text.Substring(my_sel.start, my_sel.length);
                            int ss = src.SelectionStart;
                            int sL = src.SelectionLength;
                            string phrasetoSearch = src.SelectedText;
                            string srcText = src.Text;
                            int srcText_len = src.TextLength;

                            // if we have to modify text to make this work right
                            // b/c apparently Japanese characters do not allow
                            // this to report correct info.
                            this.SuppressNodeUpdates = true;

                            // if string isn't empty and SelectionStart is at the end
                            // add one to get a decent position for char index
                            // due to multi-byte chars in Strings...
                            // if it is empty, GetPositionFromCharIndex() will return
                            // correct coords
                            // Basically, if it's at the end of a non-empty string
                            if ((srcText != String.Empty) && (ss == src.TextLength))
                            {
                                src.Text += ' ';
                                src.Select(ss, sL);
                                modified = true;
                            }

                            if (correct_selection.Contains(src.SelectedText))
                            {
                                phrasetoSearch = GetPhraseWordsFromString(correct_selection);
                            }
                            else
                            {
                                phrasetoSearch = GetPhraseWordsFromString(src.SelectedText);
                                my_sel.start = src.SelectionStart;
                                my_sel.length = src.SelectionLength;
                            }
                            #region DONE: If Selection turns up spaces, or nothing, use default menu with default selection
                            if (phrasetoSearch.Trim() == String.Empty)
                            {
                                p = src.GetPositionFromCharIndex(my_sel.start);
                                if (modified)
                                {
                                    lock (src.Text)
                                    {
                                        src.Text = srcText;
                                    }
                                }
                                src.Select(my_sel.start, my_sel.length);
                                caller = src;

                                this.SuppressNodeUpdates = false;

                                if (this.ATPhraseStrip == null)
                                    this.ATPhraseStrip = BuildATMenu(Preferences.Language);
                                if (!Preferences.Include_Header)
                                {
                                    if (this.ATPhraseStrip.Items.Count > 0)
                                        this.ATPhraseStrip.Items[0].Visible = false;
                                    if (this.ATPhraseStrip.Items.Count > 1)
                                        this.ATPhraseStrip.Items[1].Visible = false;
                                }
                                else
                                {
                                    if (this.ATPhraseStrip.Items.Count > 0)
                                        this.ATPhraseStrip.Items[0].Visible = true;
                                    if (this.ATPhraseStrip.Items.Count > 1)
                                        this.ATPhraseStrip.Items[1].Visible = true;
                                }
                                this.ATPhraseStrip.Show(src, p, ToolStripDropDownDirection.AboveRight);
                                return;
                            }
                            #endregion
                            #region Build Context Menu Strip (done) and show at position
                            #region Initialize variables

                            int MAX_MENUITEMS = Preferences.Max_Menu_Items;
                            if (Preferences.Include_Header)
                                MAX_MENUITEMS++;

                            FFXIATPhrase[] atp = this.ATPhraseLoader.GetPhrases(phrasetoSearch.Trim(" \'\"".ToCharArray()), Preferences.Include_Header); // use selected text

                            #region If 0 choices found, send default menu, ala FFXI
                            if ((atp == null) || (atp.Length <= ((Preferences.Include_Header) ? 1 : 0))) // 0 results
                            {
                                p = src.GetPositionFromCharIndex(my_sel.start);
                                if (modified)
                                {
                                    lock (src.Text)
                                    {
                                        src.Text = srcText;
                                    }
                                }
                                src.Select(my_sel.start, my_sel.length);
                                caller = src;

                                this.SuppressNodeUpdates = false;

                                if (this.ATPhraseStrip == null)
                                    this.ATPhraseStrip = BuildATMenu(Preferences.Language);
                                if (!Preferences.Include_Header)
                                {
                                    if (this.ATPhraseStrip.Items.Count > 0)
                                        this.ATPhraseStrip.Items[0].Visible = false;
                                    if (this.ATPhraseStrip.Items.Count > 1)
                                        this.ATPhraseStrip.Items[1].Visible = false;
                                }
                                else
                                {
                                    if (this.ATPhraseStrip.Items.Count > 0)
                                        this.ATPhraseStrip.Items[0].Visible = true;
                                    if (this.ATPhraseStrip.Items.Count > 1)
                                        this.ATPhraseStrip.Items[1].Visible = true;
                                }
                                this.ATPhraseStrip.Show(src, p, ToolStripDropDownDirection.AboveRight);
                                return;
                            }
                            #endregion
                            IComparer atpComparer = new FFXIATPhraseLoader.ATPhraseCompareByValue();
                            Array.Sort(atp, 1, atp.Length - 1, atpComparer);
                            ContextMenuStrip cms = new ContextMenuStrip();
                            ToolStripMenuItem[] weapons = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1],
                                armor = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1],
                                puppet = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1],
                                objects = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1];
                            ToolStripMenuItem[] items = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1],
                                keyitems = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1];
                            ToolStripMenuItem newitem = null;
                            ToolStripMenuItem[][] tsmi_atp = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1][];
                            ToolStripItem[][] tsmi = new ToolStripItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1][];
                            ToolStripItem[] header = null;

                            ToolStripMenuItem[] languages = new ToolStripMenuItem[FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX + 1];

                            if (Preferences.Language == FFXIATPhraseLoader.ffxiLanguages.LANG_ALL)
                            {
                                for (int i = FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN; i <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX; i++)
                                {
                                    languages[i] = new ToolStripMenuItem(FFXIATPhraseLoader.Languages[i]);
                                }
                            }

                            #endregion
                            #region For Loop To Build Menu Dynamically
                            for (int i = 0; i < atp.Length; i++)
                            {
                                if (atp[i].value.Trim() == String.Empty)
                                    continue;

                                string ItemName = atp[i].value; // set the itemname

                                byte b1 = atp[i].StringResource,
                                     b2 = atp[i].Language,
                                     b3 = atp[i].GroupID,
                                     b4 = atp[i].MessageID;

                                #region DONE: ContextMenu: Create Header
                                if ((Preferences.Include_Header) && (ItemName.Contains("similar phrase")))
                                {
                                    if (header == null)
                                        header = new ToolStripLabel[1];
                                    header[0] = new ToolStripLabel(ItemName.Trim('.'));
                                    if (Preferences.Language == FFXIATPhraseLoader.ffxiLanguages.LANG_ALL)
                                        header[0].Text += " in all languages.";
                                    Font f = new Font(header[0].Font, FontStyle.Bold);
                                    header[0].Font = f;
                                    if (i != (atp.Length - 1)) // if more than 0 phrases were found
                                    {
                                        Array.Resize(ref header, 2);
                                        header[1] = new ToolStripSeparator();
                                    }
                                }
                                #endregion
                                #region DONE: ContextMenu: Build Items Category if more than MAX_MENUITEMS
                                else if ((atp.Length > MAX_MENUITEMS) && (b1 == 0x07))
                                {
                                    if (items[b2] == null)
                                        items[b2] = new ToolStripMenuItem("Items", Icons.ItemIcon[0]);
                                    newitem = new ToolStripMenuItem(ItemName, null, ContextAT_Click);
                                    ToolStripMenuItem addto = null;
                                    newitem.Name = atp[i].ToString();
                                    if (atp[i].Type == 4) // Weapons
                                    {
                                        if (weapons[b2] == null)
                                            weapons[b2] = new ToolStripMenuItem("Weapons", Icons.WeaponIcon[0]);
                                        addto = weapons[b2];
                                        if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                            newitem.Image = Icons.WeaponIcon[b2];
                                        else newitem.Image = Icons.WeaponIcon[0];
                                    }
                                    else if (atp[i].Type == 5) // Armors
                                    {
                                        if (armor[b2] == null)
                                            armor[b2] = new ToolStripMenuItem("Armor", Icons.ArmorIcon[0]);
                                        addto = armor[b2];
                                        if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                            newitem.Image = Icons.ArmorIcon[b2];
                                        else newitem.Image = Icons.ArmorIcon[0];
                                    }
                                    else if (atp[i].Type == 13) // Puppet Items
                                    {
                                        if (puppet[b2] == null)
                                            puppet[b2] = new ToolStripMenuItem("Puppet Items", Icons.PuppetIcon[0]);
                                        addto = puppet[b2];
                                        if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                            newitem.Image = Icons.PuppetIcon[b2];
                                        else newitem.Image = Icons.PuppetIcon[0];
                                    }
                                    else
                                    {
                                        if (objects[b2] == null)
                                            objects[b2] = new ToolStripMenuItem("Other Items", Icons.ItemIcon[0]);
                                        addto = objects[b2];
                                        if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                            newitem.Image = Icons.ItemIcon[b2];
                                        else newitem.Image = Icons.ItemIcon[0];
                                    }

                                    addto.DropDownItems.Add(newitem);
                                }
                                #endregion
                                #region DONE: ContextMenu: Build Key Items Category if more than MAX_MENUITEMS
                                else if ((atp.Length > MAX_MENUITEMS) && (b1 == 0x13))
                                {
                                    if (keyitems[b2] == null)
                                        keyitems[b2] = new ToolStripMenuItem("Key Items", Icons.KeyItemIcon[0]);
                                    newitem = new ToolStripMenuItem(ItemName, null, ContextAT_Click);
                                    if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                        (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                        newitem.Image = Icons.KeyItemIcon[b2];
                                    else newitem.Image = Icons.KeyItemIcon[0];
                                    newitem.Name = atp[i].ToString();
                                    keyitems[b2].DropDownItems.Add(newitem);
                                }
                                #endregion
                                #region DONE: ContextMenu: Build Auto-Translate Categories if more than MAX_MENUITEMS
                                else if ((atp.Length > MAX_MENUITEMS) && ((b1 != 0x07) && (b1 != 0x13)))
                                {
                                    int tsmi_cnt = 0;
                                    FFXIATPhrase grp = this.ATPhraseLoader.GetPhraseByID(b1, b2, b3);
                                    string GroupName = "Unknown Group";

                                    if (grp != null)
                                        GroupName = grp.value;

                                    if (tsmi_atp[b2] == null)
                                    {
                                        tsmi_atp[b2] = new ToolStripMenuItem[1];
                                        if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                            tsmi_atp[b2][tsmi_cnt] = new ToolStripMenuItem(GroupName, Icons.GeneralIcon[b2]);
                                        else tsmi_atp[b2][tsmi_cnt] = new ToolStripMenuItem(GroupName);
                                    }
                                    else
                                    {
                                        for (tsmi_cnt = 0; tsmi_cnt < tsmi_atp[b2].Length; tsmi_cnt++)
                                        {
                                            if (GroupName == tsmi_atp[b2][tsmi_cnt].Text)
                                                break;
                                        }
                                        if (tsmi_cnt == tsmi_atp[b2].Length)
                                        {
                                            Array.Resize(ref tsmi_atp[b2], tsmi_atp[b2].Length + 1);
                                            if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                                (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                                tsmi_atp[b2][tsmi_cnt] = new ToolStripMenuItem(GroupName, Icons.GeneralIcon[b2]);
                                            else tsmi_atp[b2][tsmi_cnt] = new ToolStripMenuItem(GroupName);
                                        }
                                    }
                                    newitem = new ToolStripMenuItem(ItemName, null, ContextAT_Click);
                                    if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                        (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                        newitem.Image = Icons.GeneralIcon[b2];
                                    newitem.Name = atp[i].ToString();

                                    tsmi_atp[b2][tsmi_cnt].DropDownItems.Add(newitem);
                                }
                                #endregion
                                #region DONE: ContextMenu: Build Basic Menu if atp.Length <= MAX_MENUITEMS
                                else
                                {
                                    // Build ContextMenu
                                    if (tsmi[b2] == null)
                                        tsmi[b2] = new ToolStripItem[1];
                                    else Array.Resize(ref tsmi[b2], tsmi[b2].Length + 1);
                                    int Index = tsmi[b2].Length - 1;
                                    tsmi[b2][Index] = new ToolStripMenuItem(ItemName, null, ContextAT_Click);
                                    tsmi[b2][Index].Name = atp[i].ToString();

                                    if (atp[i].StringResource == 0x07)
                                    {
                                        tsmi[b2][Index].ForeColor = Icons.ItemColor;
                                        if (atp[i].Type == 4)
                                        //if ((atp[i].ResourceID >= 10000) && (atp[i].ResourceID <= 20000))
                                        {
                                            if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                                (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                                tsmi[b2][Index].Image = Icons.WeaponIcon[b2];
                                            else tsmi[b2][Index].Image = Icons.WeaponIcon[0];
                                        }
                                        else if (atp[i].Type == 5)
                                        //else if ((atp[i].ResourceID >= 50000) && (atp[i].ResourceID <= 60000))
                                        {
                                            if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                                (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                                tsmi[b2][Index].Image = Icons.ArmorIcon[b2];
                                            else tsmi[b2][Index].Image = Icons.ArmorIcon[0];
                                        }
                                        else if (atp[i].Type == 13)
                                        //else if (atp[i].BaseID >= 0x2000)
                                        {
                                            if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                                (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                                tsmi[b2][Index].Image = Icons.PuppetIcon[b2];
                                            else tsmi[b2][Index].Image = Icons.PuppetIcon[0];
                                        }
                                        //else tsmi[Index].Image = Preferences.ItemIcon;
                                        else
                                        {
                                            if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                                (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                                tsmi[b2][Index].Image = Icons.ItemIcon[b2];
                                            else tsmi[b2][Index].Image = Icons.ItemIcon[0];
                                        }
                                    }
                                    else if (atp[i].StringResource == 0x13)
                                    {
                                        tsmi[b2][Index].ForeColor = Icons.KeyItemColor;
                                        if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                            tsmi[b2][Index].Image = Icons.KeyItemIcon[b2];
                                        else tsmi[b2][Index].Image = Icons.KeyItemIcon[0];
                                    }
                                    else if ((b2 >= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN) &&
                                            (b2 <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX))
                                    {
                                        tsmi[b2][Index].Image = Icons.GeneralIcon[b2];
                                    }
                                }
                                #endregion
                            }
                            #endregion
                            cms.SuspendLayout();
                            //cms.ShowImageMargin = false;
                            //cms.ShowCheckMargin = false;
                            if (header != null)
                                cms.Items.AddRange(header);
                            if (Preferences.Language == FFXIATPhraseLoader.ffxiLanguages.LANG_ALL)
                            {
                                #region If user opted to load all, we need to show appropriate selections
                                for (int x = FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MIN; x <= FFXIATPhraseLoader.ffxiLanguages.NUM_LANG_MAX; x++)
                                {
                                    if (atp.Length > MAX_MENUITEMS)
                                    {
                                        #region If total in the whole list is greater than MAX_MENUITEMS, group by language
                                        if (tsmi_atp[x] != null)
                                            languages[x].DropDownItems.AddRange(tsmi_atp[x]);
                                        if (items[x] != null)
                                        {
                                            if (weapons[x] != null)
                                                items[x].DropDownItems.Add(weapons[x]);
                                            if (armor != null)
                                                items[x].DropDownItems.Add(armor[x]);
                                            if (puppet != null)
                                                items[x].DropDownItems.Add(puppet[x]);
                                            if (objects != null)
                                                items[x].DropDownItems.Add(objects[x]);
                                            languages[x].DropDownItems.Add(items[x]);
                                        }
                                        if (keyitems[x] != null)
                                            languages[x].DropDownItems.Add(keyitems[x]);
                                        if (tsmi[x] != null)
                                            languages[x].DropDownItems.AddRange(tsmi[x]);
                                        cms.Items.Add(languages[x]);
                                        #endregion
                                    }
                                    else
                                    {
                                        #region Else, total in list is less than MAX_MENUITEMS, DO NOT group by language
                                        if (tsmi_atp[x] != null)
                                            cms.Items.AddRange(tsmi_atp[x]);
                                        if (items[x] != null)
                                        {
                                            if (weapons[x] != null)
                                                items[x].DropDownItems.Add(weapons[x]);
                                            if (armor[x] != null)
                                                items[x].DropDownItems.Add(armor[x]);
                                            if (puppet[x] != null)
                                                items[x].DropDownItems.Add(puppet[x]);
                                            if (objects[x] != null)
                                                items[x].DropDownItems.Add(objects[x]);
                                            cms.Items.Add(items[x]);
                                        }
                                        if (keyitems[x] != null)
                                            cms.Items.Add(keyitems[x]);
                                        if (tsmi[x] != null)
                                            cms.Items.AddRange(tsmi[x]);
                                        #endregion
                                    }
                                }
                                #endregion
                            }
                            else
                            {
                                #region If user only wanted one language loaded, show it's fields
                                if (tsmi_atp[Preferences.Language] != null)
                                    cms.Items.AddRange(tsmi_atp[Preferences.Language]);
                                if (items[Preferences.Language] != null)
                                {
                                    if (weapons[Preferences.Language] != null)
                                        items[Preferences.Language].DropDownItems.Add(weapons[Preferences.Language]);
                                    if (armor[Preferences.Language] != null)
                                        items[Preferences.Language].DropDownItems.Add(armor[Preferences.Language]);
                                    if (puppet[Preferences.Language] != null)
                                        items[Preferences.Language].DropDownItems.Add(puppet[Preferences.Language]);
                                    if (objects[Preferences.Language] != null)
                                        items[Preferences.Language].DropDownItems.Add(objects[Preferences.Language]);
                                    cms.Items.Add(items[Preferences.Language]);
                                }
                                if (keyitems[Preferences.Language] != null)
                                    cms.Items.Add(keyitems[Preferences.Language]);
                                if (tsmi[Preferences.Language] != null)
                                    cms.Items.AddRange(tsmi[Preferences.Language]);
                                #endregion
                            }
                            cms.ResumeLayout();
                            p = src.GetPositionFromCharIndex(my_sel.start);
                            if (modified)
                            {
                                lock (src.Text)
                                {
                                    src.Text = srcText;
                                }
                            }
                            src.Select(my_sel.start, my_sel.length);
                            caller = src;
                            this.SuppressNodeUpdates = false;
                            cms.Show(src, p, ToolStripDropDownDirection.AboveRight);// cms.Show(textBoxLine1.c
                            #endregion
                        }
                    }
                    #endregion
                }
            }
        }
Пример #10
0
        private void textBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (sender is TabTextBox)
            {
                TabTextBox ttb = sender as TabTextBox;
                ttb.Focus();
                if (ttb.ContextMenuStrip != null)
                {
                    #region Handle the Undo menu item
                    if (ttb.CanUndo)
                    {
                        ttb.ContextMenuStrip.Items["undoToolStripMenuItem"].Enabled = true;
                    }
                    else ttb.ContextMenuStrip.Items["undoToolStripMenuItem"].Enabled = false;
                    #endregion

                    #region Handle the Cut, Copy, Paste, and Delete menu items.
                    if (Clipboard.ContainsText())
                    {
                        ttb.ContextMenuStrip.Items["pasteTextToolStripMenuItem"].Enabled = true;
                    }
                    else ttb.ContextMenuStrip.Items["pasteTextToolStripMenuItem"].Enabled = false;

                    if (ttb.SelectedText != String.Empty)
                    {
                        ttb.ContextMenuStrip.Items["cutTextToolStripMenuItem"].Enabled = true;
                        ttb.ContextMenuStrip.Items["copyTextToolStripMenuItem"].Enabled = true;
                        ttb.ContextMenuStrip.Items["deleteTextToolStripMenuItem"].Enabled = true;
                    }
                    else
                    {
                        ttb.ContextMenuStrip.Items["cutTextToolStripMenuItem"].Enabled = false;
                        ttb.ContextMenuStrip.Items["copyTextToolStripMenuItem"].Enabled = false;
                        ttb.ContextMenuStrip.Items["deleteTextToolStripMenuItem"].Enabled = false;
                    }
                    #endregion

                    #region Handle the Save Changes and Reload This Items
                    CMacroFile cmf = FindMacroFileByNode(this.treeView.SelectedNode);
                    ToolStripItem ts = ttb.ContextMenuStrip.Items["saveCurrentToolStripContextMenuItem"];
                    ToolStripItem rs = ttb.ContextMenuStrip.Items["reloadCurrentToolStripMenuItem"];
                    if (cmf != null)
                    {
                        rs.Enabled = true;
                        ts.Enabled = cmf.Changed;

                        String text = String.Format(" \'{0}\'", cmf.thisNode.Text.Trim('*'));

                        ts.Text = "Save" + text;
                        rs.Text = "Reload" + text;
                        ts.Tag = (object)cmf.thisNode;
                        rs.Tag = (object)cmf.thisNode;
                    }
                    else
                    {
                        ts.Tag = null;
                        rs.Tag = null;
                        ts.Text = "Unable to Save Changes";
                        rs.Text = "Unable to Reload This";
                        ts.Enabled = false;
                        rs.Enabled = false;
                    }
                    #endregion

                    #region Handle the final separator, AT Phrase Menu, and Special Menu
                    ToolStripItem[] separator = ttb.ContextMenuStrip.Items.Find("ContextSeparator", true);
                    ToolStripItem[] atpstrip = ttb.ContextMenuStrip.Items.Find("ATPhraseStrip", true);
                    ToolStripItem[] specials = ttb.ContextMenuStrip.Items.Find("Specials", true);

                    caller = ttb;

                    if (ttb != textBoxName)
                    {
                        #region if ttb is a TextBoxLine
                        #region Add Separator or Make it Visible
                        // if both AtphraseStrip and Specials is null, we don't need a separator
                        if (((separator == null) || (separator.Length < 1)) && ((this.ATPhraseStrip != null) || (this.Specials != null)))
                        {
                            // Add separator for LineBoxes
                            // Include a Separator
                            ToolStripItem separatorItem = new ToolStripSeparator();
                            // Name it as well so I don't repeat it
                            separatorItem.Name = "ContextSeparator";
                            ttb.ContextMenuStrip.Items.Add(separatorItem);
                        }
                        else separator[0].Visible = true;
                        #endregion

                        #region Add Special Character Menu or Make it Visible
                        // Handle Special Character Sub-Menu
                        if ((specials == null) || (specials.Length < 1))
                        {
                            if ((this.Specials != null) && (this.Specials.Items.Count > 0))
                            {
                                // specials not found/non-existant, create a new array
                                specials = new ToolStripItem[this.Specials.Items.Count];
                                // copy the items over
                                this.Specials.Items.CopyTo(specials, 0);
                                specials[0].Visible = false; // header
                                if (Specials.Items.Count > 1)
                                    specials[1].Visible = false; // separator
                                // create the drop-down menu tag with the text of the first label from the Specials Menu
                                ToolStripMenuItem specialcharsMenu = new ToolStripMenuItem(specials[0].Text);
                                // Name it so I can Find() it later
                                specialcharsMenu.Name = "Specials";
                                Bitmap bmp = new Bitmap(32, 32);
                                Graphics g = Graphics.FromImage(bmp);
                                g.DrawString("\u221E", new Font(specialcharsMenu.Font.FontFamily, 20.0f, FontStyle.Bold), new SolidBrush(Color.Black), -7.5f, -2.5f);
                                specialcharsMenu.Image = bmp;
                                // Add the array as a drop-down list
                                specialcharsMenu.DropDownItems.AddRange(specials);

                                // Add the specialcharsMenu to the ContextMenuStrip
                                ttb.ContextMenuStrip.Items.Add(specialcharsMenu);
                            }
                        }
                        else
                        {
                            // if found, set to visible
                            specials[0].Visible = true;
                        }
                        #endregion

                        #region Add Auto-Translate Phrase Sub-Menu or make it visible
                        if ((atpstrip == null) || (atpstrip.Length < 1)) // not found
                        {
                            #region Create if and only if the ATPhraseStrip exists
                            if ((this.backupPhraseStrip != null) && (this.backupPhraseStrip.Items.Count > 0)) // copy PhraseStrip context menu
                            {
                                // Create new menu array
                                atpstrip = new ToolStripItem[this.backupPhraseStrip.Items.Count];
                                // Copy all items to array.
                                this.backupPhraseStrip.Items.CopyTo(atpstrip, 0);
                                // Make header Invisible no matter what.
                                atpstrip[0].Visible = false;
                                if (this.backupPhraseStrip.Items.Count > 1)
                                    atpstrip[1].Visible = false;

                                // Sub-Menu title pulled from the first label in the atpstrip
                                ToolStripMenuItem atp = new ToolStripMenuItem(atpstrip[0].Text);
                                if (Preferences.Language == FFXIATPhraseLoader.ffxiLanguages.LANG_ALL)
                                {
                                    Bitmap bmp = new Bitmap(32, 32);
                                    Graphics g = Graphics.FromImage(bmp);
                                    g.DrawString("\u2202", new Font(atp.Font.FontFamily, 20.0f, FontStyle.Bold), new SolidBrush(Color.Black), -7.5f, -2.5f);
                                    atp.Image = bmp;
                                }
                                else atp.Image = Icons.GeneralIcon[Preferences.Language];

                                //.DropDownItems = this.ATPhraseStrip.Items;
                                // make the list (atpstrip) a range under this as a Drop-Down menu
                                //atp.DropDownItems.AddRange(this.ATPhraseStrip.Items.); // Range(atpstrip);
                                atp.DropDownItems.AddRange(atpstrip);
                                // name it so I can make sure I don't add it twice
                                atp.Name = "ATPhraseStrip";
                                ttb.ContextMenuStrip.Items.Add(atp);
                            }
                            #endregion
                        }
                        else
                        {
                            atpstrip[0].Visible = true;
                        }
                        #endregion
                        #endregion
                    }
                    else // TabTextBox (Name only)  block phrase menu, separator, and specials
                    {
                        #region if ttb is a TextBoxName
                        if ((separator != null) && (separator.Length >= 1))
                            separator[0].Visible = false;
                        if ((atpstrip != null) && (atpstrip.Length >= 1)) // found ATPhrase Strip in ContextMenu
                            atpstrip[0].Visible = false;
                        if ((specials != null) && (specials.Length >= 1))
                            specials[0].Visible = false;
                        #endregion
                    }
                    #endregion
                }
            }
        }
Пример #11
0
 private int getNumfromTTB(TabTextBox src)
 {
     if (src == textBoxName)
         return 0;
     else if (src == textBoxLine1)
         return 1;
     else if (src == textBoxLine2)
         return 2;
     else if (src == textBoxLine3)
         return 3;
     else if (src == textBoxLine4)
         return 4;
     else if (src == textBoxLine5)
         return 5;
     else if (src == textBoxLine6)
         return 6;
     return -1;
 }
Пример #12
0
 private bool textBoxInsertLine(TabTextBox src, int insertstart, String text)
 {
     return textBoxInsertLine(src, insertstart, text, false);
 }
Пример #13
0
 private bool textBoxInsertLine(TabTextBox src, int insertstart, String text, bool WarnOnLoss)
 {
     if ((insertstart < 0) || (insertstart > 6) || (src == null))
         return false;
     if (textBoxLine6.Text != "")
     {
         DialogResult dr = MessageBox.Show("If we insert a line, you'll lose the last line of your macro!\r\n  (To remove this warning, choose change Enter Key Option to 'Insert Line')\r\nIs that ok?", "Possible loss of information warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
         if (dr == DialogResult.No)
             return false;
     }
     if (src.SelectionLength > 0)
         src.Text = src.Text.Remove(src.SelectionStart, src.SelectionLength);
     if (insertstart < 6)
     {
         textBoxLine6.Text = textBoxLine5.Text;
     }
     if (insertstart < 5)
     {
         textBoxLine5.Text = textBoxLine4.Text;
     }
     if (insertstart < 4)
     {
         textBoxLine4.Text = textBoxLine3.Text;
     }
     if (insertstart < 3)
     {
         textBoxLine3.Text = textBoxLine2.Text;
     }
     if (insertstart < 2)
     {
         textBoxLine2.Text = textBoxLine1.Text;
     }
     if (insertstart < 1)
     {
         textBoxLine1.Text = textBoxName.Text;
     }
     src.Text = text;
     src.SelectionStart = 0;
     src.SelectionLength = 0;
     SendKeys.Send("{DOWN}");
     return true;
 }
Пример #14
0
        private bool textBoxBackspace(TabTextBox to)
        {
            int toLine = getNumfromTTB(to);

            if (toLine <= 0)
                return false;
            for (int i = toLine; i < 6; i++)
            {
                getTTBfromNum(i).Text += getTTBfromNum(i + 1).Text;
                getTTBfromNum(i + 1).Text = String.Empty;
            }
            return true;
        }
Пример #15
0
 /// <summary>
 /// Context Menu Strip Click Handler used for replacing the selected text with the Auto-Translate Phrase selected via the Context Menu.
 /// </summary>
 /// <param name="sender">The ToolStripMenuItem that was clicked.</param>
 /// <param name="e">Generic EventArgs variable, unused.</param>
 private void ContextAT_Click(object sender, EventArgs e)
 {
     if (sender is ToolStripMenuItem)
     {
         ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
         if (tsmi != null)
         {
             if (caller != null)
             {
                 TabTextBox ttb = caller as TabTextBox;
                 caller = null;
                 if (ttb != null)
                 {
                     int caret_pos = ttb.SelectionStart;
                     if (ttb.SelectionLength != 0)
                     {
                         string s = ttb.Text.Remove(ttb.SelectionStart, ttb.SelectionLength);
                         ttb.Text = s.Insert(ttb.SelectionStart, tsmi.Name);
                     }
                     else
                     {
                         string s = ttb.Text.Insert(ttb.SelectionStart, tsmi.Name);
                         ttb.Text = s;
                     }
                     ttb.Select(caret_pos, tsmi.Name.Length);
                 }
             }
         }
     }
 }