aviaryan / Clipjump

:clipboard: Clipboard Manager for Windows, built in AutoHotkey
http://clipjump.sourceforge.net/
383 stars 61 forks source link

Move to certain channel based on regular expression #62

Closed danielo515 closed 9 years ago

danielo515 commented 9 years ago

Your tool is awesome, but it could be even more awesome with this feature: define some regular expressions that will move the matching clips to certain channel. Let's say I want all my URLs in certain channel, or all the ticket numbers I ever copied on the tickets channel... then this will make channel and clips management automatic. Maybe it can be implemented as a plugin. If it is possible just point me in the good direction and I will try to do it myself.

Regards.

aviaryan commented 9 years ago

See the plugin linked here. It shows how to copy to a different channel other than the current active one. You can use some regex there to auto-determine the destination channel.

But I like the idea and would like to add it as an inbuilt feature. Let's see. I am currently fixing some bugs.

danielo515 commented 9 years ago

Hello @aviaryan ,

I'm trying to write the plugin we were talking about and I'm using your copy2channel plugin as a guide. But there are some things I don't understand that maybe you can explain to me:

plugin_copy2channel(zChannel, zWhat){
    if !zWhat
        zSend := "^{vk43}"
    else zSend := "^{vk58}"

What are those values? seems like key definitions but I can't understand what are they used for

    zoc := CN.NG
    znc := channel_find(zChannel)

Correct me if I'm wrong but I thing those are original channel (zoc) and destination channel (znc)

    changeChannel(znc)
    ONCLIPBOARD := 3 ; any other positive number other than 1
    Send, % zSend

What is this used for? You move to the destination channel and then you set a variable (that I can't understand why) and you send that... keystrokes? Maybe you just copy the content of the clipboard to the selected channel?

    while ( ONCLIPBOARD != 1 )
        sleep 100

    sleep 500
    changeChannel(zoc)
}

Here you wait until ONCLIPBOARD changes, (again, I don't know why) and then you goes back again to the original channel.

Another question not related to your code is: How can I check what is currently on the clipboard in order to run a regular expression check against it? I think I can use getClipAt(0,1,1) but I'm not sure.

Thank you very much.

danielo515 commented 9 years ago

Based on the parameters I think "^{vk43}" means control+c and "^{vk58}" control+x

danielo515 commented 9 years ago

Here is a prototype, that, does not works and I don't know why:

;@Plugin-Name Move to Channel regexp
;@Plugin-Description Use this plugin to move the selected item to a particular channel based on a regular expression
;@Plugin-Author Danielo
;@Plugin-Tags channel move

plugin_move2channel_regex(){
    zSend := "^{vk58}"
    zoc := CN.NG
    clip := getClipAt(0,1,1)
    tooltip, Hello motherfucker
    regexs := Object()
    regexs["N#\d+"] := "tickets"
    for reg, channelName in regexs 
    {
        hasMatch := RegExMatch(clip,reg)
        if ( hasMatch > 0 ){
            destChannel := channel_find(channelName)
            changeChannel(destChannel)
            Send, % zSend
            break
            }
    }

    ONCLIPBOARD := 3 ; any other positive number other than 1

    while ( ONCLIPBOARD != 1 )
        sleep 100

    sleep 500
    changeChannel(zoc)

}
aviaryan commented 9 years ago

One problem I see is that ONCLIPBOARD := 3 should be before Send. The reason is that sending ^x invokes the clipboard and the clipboard then changes the ONCLIPBOARD to 1. If ONCLIPBOARD is made 3 after Sending, then it may happen clipboard runs before ONCLIPBOARD := 3

So it will be better if you put this part inside the if condition

 ONCLIPBOARD := 3 ; any other positive number other than 1
 Send % zSend
    while ( ONCLIPBOARD != 1 )
        sleep 100
danielo515 commented 9 years ago

Hello @aviaryan

Sorry for posting here something that is some kind of support, but it is related with the issue subject. I changed the code as you described and I added the API. prefix to one API call.

I more or less achieved what I want, but I find what I have done a bit clumsy. What I do currently is

The problem with this is that using that approach the tooltip is barely seen. I think it is because it has some conflict with the defautl tooltip. Can you think in a better approach?

aviaryan commented 9 years ago

Default tooltip and API's showTip are different. Can you try

API.showTip("Moved to " . channelName, 2000)

Notice the space around "." (period) . Maybe "moved to".channelname is being evaluated as some class property.

danielo515 commented 9 years ago

Ok, the space trick did the job. Now I can see both popups but the second lasts enough to be seen. Thank you.

aviaryan commented 9 years ago

Closing this issue because of #71