question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hot and cold MouseEvents?

See original GitHub issue

Is my understanding correct in that there is not currently a cold-key like behaviour for mouse events? I see here that it’s apparently been considered but not yet implemented for having them being bubbled up if the mouse event is not handled (returns false): https://github.com/migueldeicaza/gui.cs/blob/52a5fccdc412367405790dd811ebf5410c1c9a39/Terminal.Gui/Core/Application.cs#L591

If so, you might ask why I want such a thing, so here I’ll try to explain:

class TerminalTextView : TextView
{ 
    // ProcessHotMouseEvent does not yet exist, but to express the idea:
    public override bool ProcessHotMouseEvent(MouseEvent mouseEvent)
    {
        // right click
        if(mouseEvent.Flags == MouseFlags.Button3Pressed) 
        {
            if (HasFocus && Selecting)
            {
                Copy();
                Selecting = false;
            }
            else
            {
                return false; // handle paste in InputTerminalTextView coldkey
            }
        }
        return base.OnMouseEvent(mouseEvent);
    }
}


class InputTerminalTextView: TerminalTextView 
{ 
    // ProcessColdMouseEvent does not yet exist, but to express the idea:
    public override bool ProcessColdMouseEvent(MouseEvent mouseEvent)
    {
        // right click
        if(mouseEvent.Flags == MouseFlags.Button3Pressed)
        {
            SetFocus();
            Paste();
            return true;
        }
        return base.ProcessColdMouseEvent(mouseEvent);
    }
}

So what I’d be trying to accomplish here is right click copy + paste (like in a terminal). The user would be able to select text in another (readonly) textview, right click anywhere to copy selected (assuming ProcessHotMouseEvent would occur before changing View’s focus), and then right clicking again (i.e. without anything selected) would paste it into the InputTerminalTextView.

This is probably quite a niche use-case so it might not be worth a change to core repo. FWIW I’m not entirely sure if this idea requires such functionality and maybe there’s another way of doing it, it’s just the first to come to mind since I’m already doing a similar thing with the hotkey/coldkeys. But I thought I’d mention the idea since I noticed that little note in the code, so maybe it’s sort of considerable? IDK, please correct me if I’m off here - and please if any suggestions on a alternative solution to getting this idea working would be greatly appreciated.

PS: Just want to thank again for all of the time and effort in making this project, I really appreciate it, and all the fantastic help I’ve received getting started on my idea. 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
burettocommented, Aug 2, 2021

What about Application.RootMouseEvent? that should pick up ‘right click anywhere’

So, in that case the Application.RootMouseEvent will be suffice, I think.

Thanks! This is just what I needed, here is a code sample displaying use:

Application.RootMouseEvent = (MouseEvent moueEvent) =>
{
    if (moueEvent.Flags != MouseFlags.Button3Pressed)
        return;
    
    var currentView = Application.Top.MostFocused;
    if (currentView is TextView textView)
    {
        if (textView.Selecting)
        {
            textView.Copy();
            textView.Selecting = false;
        }
        else
        {
            if(currentView != inputTextView)
                inputTextView.SetFocus();
            inputTextView.Paste();
        }
    }
};

Seems to work perfect for what I want. 😃

2reactions
BDispcommented, Aug 2, 2021

Ah, sorry to both. So, in that case the Application.RootMouseEvent will be suffice, I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Genotype of Immunologically Hot or Cold Tumors ...
Genotype of Immunologically Hot or Cold Tumors Determines the Antitumor Immune Response and Efficacy by Fully Virulent Retargeted oHSV.
Read more >
Therapy turned brain cancers from 'cold' to 'hot' in mouse ...
The study showed the treatment cranked tumors from cold to hot enough for immune cells to be able to recognize brain cancers.
Read more >
Cold Tumors: A Therapeutic Challenge for Immunotherapy
We discuss then the different therapeutic approaches that could turn cold into hot tumors. In this way, specific therapies are proposed ...
Read more >
Mild photothermal therapy potentiates anti-PD-L1 treatment ...
SMPAI strategy turns “cold” tumors “hot”. To verify the enhanced antitumor immune response induced by combined mild PTT and anti-PD therapy, we ...
Read more >
The Race to Make Cold Tumors Hot ...
A growing arsenal of new drugs that unleash the body's immune system against tumors has captured the cancer treatment spotlight.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found