I have the following code snippet for creating an input field for entering colors:
DataSourceTextField colorField =
new DataSourceTextField(ZoneDto.ATTR_COLOR, "*localized name*", 7, true);
colorField.setEditorType(new ColorPickerItem());
colorField.setPrompt("*localized instructions*");
This works quite well, since the input field has the localized instructions in its tooltip, but the small square that opens the color picker window has the original english tooltip ("Click to select a new color").
How could I change this message to a localized one?
Is this even possible to accomplish? I read that setEditorType only sets a template, from which instances are generated whenever needed. This means it's not going to work if I add setPrompt("localized instructions") to the ColorPickerItem given to the setEditorType().
Thanks in advance!
If i get you right, why not fill a variable 'localizedStringForColorPicker' with the current selected localization upon startup. And change it, when another localization is selected?
Related
I've pasted a screen shot. The text Area is visible but the title is not showing up in the settings page. I couldn't figure it out.
I found that I needed four fields active and filled out for it to show up properly.
Type: Title
Title: Whatever
Identifier: what_ever
Default Value: [okay to leave blank]
You just need to add a new row, under your Default Value with the key "Identifier". It should works ;)
UPDATE 1:
I've tested with a swift project, and all works fine:
Next, my code in the AppDelegate:
Finally, the result in the simulator:
I'm new to developing firefox addons and was wondering if there is a way to override/modify the link preview text that appears at the bottom of the browser when you hover over a link.
I've looked briefly and wasn't able to find any reference describing this.
Thanks for any thoughts.
You can set the status text like this:
aDOMWindow.XULBrowserWindow.setOverLink('blah')
Where aDOMWindow is a window like that returned from for example Services.wm.getMostRecentWindow('navigator:browser').
So like do link.addEventListener('onmouseenter'.... a function that does setOverLink
and to make it go away set it to blank string. So just window.XULBrowserWindow.setOverLink('')
But you are doing this on mouse enter of a link and by default mouse out of links will blank it so you may not neede to handle blanking it.
edit:
you asked about add-sdk, so the Services.wm.getMostRecentWindow might not make sense, so here's a quick test you can try in sdk:
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
getMostRecentBrowserWindow().XULBrowserWindow.setOverLink('hiiiiiii!!!')
I'm developing an extension for Firefox which searches terms in a page. And I'd like to change found text highlight color and background. For example, I search for a letter "s" and by default it's selected with a blue rectangle with white text color. So I want to change the blue to the red.
How could I do this via JS?
Edit0:
To select a found text I use document.createRange() and selection.addRange() methods.
I don't know how the default finder selects a found term and applies background to it.
So maybe the 'range' method is not the best.
But I think I'm searching a way to highlight this created range...
Edit1:
Now I've partially resolved the color-changing preoblem. Just add a CSS rule with ::-moz-selection and red background when a text is found and selected. Then for document 'onmousedown' I remove this rule not to leave the default selection as red.
But a new problem is when I find say a digit and it gets a selection the background of that selection is gray (so it looks like a text selection of an inactive window). Then when I click with my mouse somewhere in the document text and press F3 the extension finds the next digit and selects it with the red background. And next findings work right (with red background).
So my purpose is change that initial gray background to red.
Maybe I should change the inactive selection color...
Edit2:
Now I updated my JS code:
var selection=w.getSelection()
var range=w.document.createRange()
range.setStart(foundNode,foundOffset)
range.setEnd(foundNode,foundOffset+foundLength)
selection.removeAllRanges()
selection.addRange(range)
var controller=gBrowser.docShell.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISelectionDisplay)
.QueryInterface(Ci.nsISelectionController);
controller.setDisplaySelection(controller.SELECTION_ATTENTION)
controller.repaintSelection(controller.SELECTION_NORMAL)
Thanks to Noitidart's answer I found some information on how to use nsISelectionController XPCOM interface to select found text with background. Still I can't set a custom color for this background so that it be different from the default color of found text in Firefox. But setting the ui.textSelectBackgroundAttention preference in about:config to desired color will work with both my extension and default find engine.
I've found that SELECTION_ATTENTION constant is responsible for that background color and the setDisplaySelection method links the color to the selected text. But I couldn't find any implementation of this method. I saw only nsISelectionController idl file with its structure but no correspondent .cpp or .js file implementing this .idl. So I don't have information on how the color is set.
Edit3:
Recently I added the "Highlight All" functionality to my extension. And a new question about color of this highlight has rised. Using the above tecnique will show all the matches with green find color (by default). But it's more comfortable to use a different color to distinguish the current match and others.
So I couldn't find another helpful nsISelectionController constant for the "Highlight All" selection. I simply set this selection to 'DISABLED' type and changed the ui.textSelectBackgroundDisabled about:config pref. This pref is obviously for the selected text background of an inactive window. And it worked for me.
controller.setDisplaySelection(controller.SELECTION_DISABLED)
Another thing is that I'm not sure that the controller.repaintSelection() in the previous Edit is necessary. I guess the selection didn't work without it when I started my experiments with this stuff. But now I removed that line and all still work.
Plus:
And some additional links if somebody will need:
nsISelectionController Reference
Selection Reference
Forum question about highlight
about:config prefs for highlight
An Add-on using a similar tecnique
Finder.jsm and other sources
Also I used some files from Firefox source archive: Firefox 33 Source:
- nsISelectionController.idl [\content\base\public\]
- nsTypeAheadFind.cpp [\toolkit\components\typeaheadfind\]
- Finder.jsm [\toolkit\modules\]
- findbar.xml [\toolkit\content\widgets\]
I asked this question to quicksilver via email and this is what he told me:
You might find this one helpful: https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsISelectionController
I'm hardly the master you think I am, actually. :) To change those colors I just change the values for preferences:
ui.textHighlightBackground
ui.textHighlightForeground
ui.textSelectBackgroundAttention -> SELECTION_ATTENTION, it's not a highlight, it's a normal selection (as you would select some text with your mouse and it would turn the regular blue blackground, in windows at least) but it's given "attention", so it has the green background that the find operation reports. Basically it's a way of showing the user "Here I am!!" after firefox automatically selecs the text he searched for.
And I really don't know most of those contants, SELECTION_NORMAL is for normal text selection, like it would be when you select text with your mouse, SELECTION_FIND is for the highlights, and I only know the ON/HIDDEN/OFF/DISABLED ones which are self-explanatory. SELECTION_SPELLCHECK is probably for the auto-correct when you are typing in an editable content node, but I'm just guessing that one from the name.
Also, as far as I know, it's not possible to just create custom selection ranges/contants, as the code simply won't recognize them without editing the C++ code as well. Which is actually one of the reasons I haven't implemented https://github.com/Quicksaver/FindBar-Tweak/issues/76 yet.
I need to internationalize some of the labels in a screen; do I need to localize the whole screen?
One more doubt, I have taken a string file and pulling the value of the keys from that file directly from that file using NSLocalizedString, then also do I need to localize the screen or it will by default get localized?
Thanks in advance.
you need not to localize the whole screen.
for two label only, on viewdidLoad
self.lbe1.text = NSLocalizedString(#"Label1", nil)
self.lbe2.text = NSLocalizedString(#"Label2", nil)
your second doubt is not clear to me.
You have to create the localize file. Then label you can use the localized id. Then you don't need to worry the whole screen or particular screen or particular text. Because whatever you can change. If you want more info refer this link
http://www.raywenderlich.com/64401/internationalization-tutorial-for-ios-2014
I have in my settings bundle of my application two text fields , where the user can give latitude and longitude values.
The bundle settings look like this :
As you see the values (43.46 and -3.81) are left aligned.
Is there a way to right align them so it looks better?
It seems the only answer to this question is to add spaces on the title of the text field , till your values move to the left side.
Is not very delicate , but looks better than this.
This worked for me in in-app settings view. I have not tried it with settings.
Open property list file as a source and paste the following to the for each entry you want right-aligned:
<key>IASKTextAlignment</key>
<string>IASKUITextAlignmentCenter</string>
Or do the same through the plist editor.
You can do that in different way. You have to add a Title preference item. and add titles and values inside that.
I have a screenshot here,
And the resulting settings screen will look like this,