Lost password? | Help

[ advanced search ]

Context Menu mod - 'Open in New Tab AND Search'

Forums » Opera Community » General Opera topics » Customizing Opera

Go to last post

Wednesday, 21. November 2007, 19:12:27

skye11

avatar

Posts: 418

Context Menu mod - 'Open in New Tab AND Search'

What is the code to combine 2 context menu tasks, triggered upon double-click'g a word or highlighting a phrase (NOT a LINK):
- Open New Tab AND Search

ie. syntax combining:
Item, MI_IDM_MENU_PAGEBAR_LINK_IN_NEW_PAGE=Open link in new page
WITH...
Item, MI_IDM_SELSEARCH=Hotclick search, 200

Wednesday, 21. November 2007, 21:09:29

sgunhouse

Volunteer

avatar

Posts: 52967

Flag City, USA

You really can't as such, the selection loses focus when you open the new tab and makes the search impossible. Holding Shift will work of course, but that's different. Unless you could write a search itself using a javascript URL, you can't get search to automatically open a new tab.

Wednesday, 21. November 2007, 21:25:17

skye11

avatar

Posts: 418

thanks sgunhouse
Shift key will do for now
I'd like to eventually learn javascript, when I have sufficient time to devote to it
:smile:

Sunday, 10. August 2008, 04:39:33 (edited)

bpm

avatar

Posts: 1029

Canada

To set the record straight: search opening in new or background tab, and not requiring shift keys, was always possible with macros (i.e. sequences of Opera commands); it did not require javascript. There were three cases, covered by two options - each with a drawback:
  1. if "reuse current tabs" was unchecked, a search which avoided using Opera functions (which ignore the setting) would automatically open in a new window. And there was no focus issue, because the command was issued in the context where the selection existed. One could use the %t (selected text) variable - and leave the clipboard (%c) untouched.
  2. unfortunately, %t doesn't work in editable text. If one wanted to search for an editable selection, it was necessary to use Copy, and then %c. This of course obliterates anything which had been in the clipboard.
  3. if "reuse current tab" was checked, one needed New Page, to prevent the search from opening in the current tab - which creates the focus issue, because the context in which a subsequent command involving %t might be tried is no longer the context in which a selection is defined. So this branch too requires Copy, to get the selection onto the clipboard where it can be cited in any context.
It turns out that New Page & Go to page doesn't open two windows even if "reuse" is unchecked - so the same macro could be used for cases 2 and 3 without ill effect. Also, the fact that capitalization of variables adds quotes to the string made phrase searches possible. So the options looked like this:

New-window search macros

requiring "reuse" unchecked, rendered text only, but not obliterating clipboard
  • Wordset search, new tab: go to page, "g %t"
  • Phrase search, new tab: go to page, "g %T"
  • Wordset search, background: go to page, "g %t" & minimize page
  • Phrase search, background: go to page, "g %T" & minimize page

either "reuse" setting, any text, but obliterating clipboard
  • Wordset search, new tab: Copy & new page & go to page, "g %c"
  • Phrase search, new tab: Copy & new page & go to page, "g %C"
  • Wordset search, background: Copy & new page & go to page, "g %c" & minimize page
  • Phrase search, background: Copy & new page & go to page, "g %C" & minimize page
That was the status as of January - Dude09 and I worked it out, and developed what macros could provide. We realized that the %t flaw prevented us from achieving unflawed functions - and fortunately the argument caught the notice of Lex1. He came up with the javascript versions, which don't use the flawed variable or the clipboard. Like the %c functions, they don't depend on the "reuse" setting and work on any text - the gain is that they don't obliterate the clipboard. They're posted in my blog, here:

Perfected search: •new page or background •wordset or phrase •works on editable text •button or menu item

The context is that Opera's built-in new-tab searches require two-handed gestures to generate (which is obligatory - they can't be re-assigned), lack any provision for phrase search, and don't work on editable text.

Here's a button you can try: %c BackgroundPhraseSearch Best macros can do, not much wrong with it - only that it obliterates the clipboard; but to some people that sort of thing just doesn't seem good enough. Perfection is attainable - so why not have it?

A couple of academic notes:
  • the above button doesn't work on editable text - Copy doesn't happen. A context issue (it works when assigned to a keystroke), which means that the macro form should be assigned elsewhere. But it belongs elsewhere - only put on a button to provide a handy demo.
  • macro form is not entirely obsolete: it works in sourceview and Notes - which defy javascript - so worth keeping around.

Monday, 11. August 2008, 04:00:32

skye11

avatar

Posts: 418

good post bpm
thanks!

Monday, 11. August 2008, 08:32:34 (edited)

bpm

avatar

Posts: 1029

Canada

You're welcome! Alas, there's an error in that, and I'm a little too late to correct the post. In fact Opera searches do honour "reuse=0", and open in a new tab - so there's no gain from using %t. Thus, two of the eight branches are handled by Opera functions.

In passing - a confusing point is that %s in Opera search strings means "selected text", and appears to be exactly the same variable as %t everywhere else (while %s is apparently "file spec of source in cache" in non-search contexts). This is bizarrely inconsistent - why not use %t to mean the same thing everywhere? Oh well...

I had a look, after writing yesterday's post, at what could be done within the confines of the search-dialog / search.ini system. I checked whether %S would give phrase searches, and whether %c could be substituted to allow editable-text sources. Alas, no: deviate from %s and they are dead as doornails: nothing happens. However it is possible to add phrase searches by bracketing %s with quotes - escaped, "%s" becomes %22%s%22. So if anyone's interested they can add a Google phrase search to their hotclick menu (for example) that way. It makes sense, compared to not having phrase search. In a larger view Opera's functions, based on a broken variable, just aren't competitive - but persons unversed in these matters are unlikely to be able to process the proof of that: they will feel like what 's inside the shrinkwrap is of a higher class - even though it malfunctions in front of their eyes.

Forums » Opera Community » General Opera topics » Customizing Opera