[DONE]Missing Copy button when right-clicking on the new GUI

Fixed bugs, solved problems, and old reports.
Locked
Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

[DONE]Missing Copy button when right-clicking on the new GUI

Post by Jonty800 »

I noticed that is missing, and could be needed for easiness.
I wrote a fix, to save you time.

Edit: I noticed that I'm only able to paste one line into ConsoleBox when using the KeyDown event to copy the selected text, not sure on a solution just yet.

Code: Select all

KeyDown += KeyDownHandler;
            MenuItem[] menuItems = new MenuItem[] { new MenuItem("Copy", new EventHandler(CopyMenuOnClickHandler)) };
            logBox.ContextMenu = new ContextMenu(menuItems);
            logBox.ContextMenu.Popup += new EventHandler(CopyMenuPopupHandler);


private void KeyDownHandler(object sender, KeyEventArgs e)
        {
            if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.C))
            {
                // Check if selection exists and that it's not null
                if (logBox.SelectedText.Length > 0)
                    // Copy the selected text to the Clipboard
                    Clipboard.SetText(logBox.SelectedText.ToString(), TextDataFormat.Text);
            }
        }

        private void CopyMenuOnClickHandler(object sender, EventArgs e)
        {
            if (logBox.SelectedText.Length > 0)
                Clipboard.SetText(logBox.SelectedText.ToString(), TextDataFormat.Text);
        }

        private void CopyMenuPopupHandler(object sender, EventArgs e)
        {
            ContextMenu menu = sender as ContextMenu;
            if (menu != null)
            {
                menu.MenuItems[0].Enabled = (logBox.SelectedText.Length > 0);
            }
        }
I did set the TextDataFormat to rtf so the colors remained, but that didn't seem to work with the right-click and trying to paste into the console command line.
You cannot use certain BBCodes: [img].

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: Missing "Copy" button when right clicking on the new GUI

Post by fragmer »

Ctrl+C works normally for me.
I will add a context menu though, for sure.

Jonty800
Offline
Posts: 280
Joined: August 21st, 2011, 6:31 am
Location: United Kingdom
Contact:

Re: Missing "Copy" button when right clicking on the new GUI

Post by Jonty800 »

Ah yes, works fine for me too. It didn't work before until I fixed a part in my code, so I've removed that keypress event now :P

Ctrl+c still only pastes one line (in consolebox only) is this the same for you? My contextmenu allows me to copy and paste fine :S
You cannot use certain BBCodes: [img].

User avatar
fragmer
fCraft Developer
Offline
Posts: 1386
Joined: May 21st, 2011, 10:53 pm

Re: [DONE]Missing Copy button when right-clicking on the new

Post by fragmer »

Merged with /branch-0.60x/. Thanks!
fcraft: fragmer * r1631 /branch-0.60x/ (ServerGUI/MainForm.cs fCraft/Utils/Updater.cs): Added a context menu to ServerGUI's log box (thanks to Jonty800).

Locked