I am new to scripting in Adobe Software.
I would like to write a script, which shows me, where I can hyphenate a word. I wonder, if there is any way to get this information from the build in spellchecker. It should also take the current language into consideration.
This is what I came up with so far:
// Get the current selection
var mySelection = app.selection;
// Check, if it is a word
if (mySelection instanceof Word) {
// Get the possible hypenation options
var hyphenated =
// Add all hyphenation options to the text string
mySelection[0].contents = hyphenated;
}
I know it is not much, but I can’t find any way to access the spellchecker manually.
No, you can't get hyphenation info via scripting.
I suppose the best you could do would be to create a text frame, insert the word, than make the frame increasingly narrow and see where InDesign hyphenates. But that is a pretty klydgy workaround!
Related
I need to check the width of text that a user enters and not allow any further entry if it exceeds a maximum value. I know how to measure the width of the text in a div, using the current font and font size. I test the width of the text with the following function:
editor.on("change", function (ev) {
var imprintText = editor.getData();
var textWidth = measureText(imprintText);
var hfMaxImprintWidth = document.getElementById("<%=hfMaxImprintWidth.ClientID%>");
var maxWidth = hfMaxImprintWidth.value;
if (textWidth >= maxWidth) {
};
});
But I don't know how to keep additional characters from being added to the textarea. I'd also like to limit the text to one line (no line breaks or new paragraphs). Can someone please help me with this? Thanks!
Too long to be a comment - how appropriate.
Sounds like something that I would solve by using a workaround. For example, if the text is too long, set CKEditor background color to red and prevent saving. Like some websites do for comments - for example stackoverflow shows "too long by 27 characters". Do a similar message on save: display an alert that whines to the user that they have too much content but just leave the character count out.
As for "no line breaks or new paragraphs" - this could be a little more complex. Advanced Content Filter can easily deal with the line breaks, but for the one paragraph only limit I think what you could do is again always check during save and alert the user.
As for automated trickery, how about something like capturing the key event and checking if (evt.data.keyCode === 13) {} and deleting the new element from the editable.
Better still, if the enter key event is cancelable, you could try evt.cancel() as well to ignore it completely. Sorry no example code.
I'm working on a concept that works like copy & paste but uses my own algorithm instead of using the clipboard.
We have users that use many different programs that contain part numbers. This is how my concept would work.
User highlights part number from any application (word, excel, pdf, JDE, etc)
Either by hotkey or clicking on another application the user launches my routine.
My routine grabs that text from the original application and processes it accordingly.
I know how to use the clipboard to get text.
What I'm not sure of is how to get currently selected text from the application that was active prior to running my code? Do I need to force my user to copy to clipboard first and then run my app or can I create my own copy/paste type windows add-in?
Preferred VB for this but can also use C++ or C# if easier.
As to the question why, because we want to the action to be seamless to the user. There will be several behind the scenes actions that take place and then the user will be presented a browser with pertinent information related to that part number. Ultimately, I don't want an in-between screen to pop up, but rather completely hidden from the user. If I require them to copy and then run my routine then I'm adding in one extra step to the user path that I'm hoping to avoid.
I looked into right click menu context a bit but found that each program can have their own override. I wasn't able to locate a way to globally override all right click context menus to include a new action.
From this article:
var element = AutomationElement.FocusedElement;
if (element != null)
{
object pattern;
if (element.TryGetCurrentPattern(TextPattern.Pattern, out pattern))
{
var tp = (TextPattern) pattern;
var sb = new StringBuilder();
foreach (var r in tp.GetSelection())
{
sb.AppendLine(r.GetText(-1));
}
var selectedText = sb.ToString();
}
}
It's in C# but it should be pretty trivial to translate.
I've been searching and reading how firefox addons manages preferences, but all the samples I found involves GUI windows and other complex things I don't need.
What I need is, I have a list of some regex patterns, which needs to be updated often without user interaction whenever it's needed.
So I want to have the initial regex stored in the firefox addon like preferences but without any gui to edit them, and then be able to edit those hardcoded preferences.
Can someone show me an example on how to do this?
I don't want a full example, just how should I store these preferences and then edit them programmatically, without involving gui windows like all the .xul files I found does.
Something like this:
Components.utils.import("resource://gre/modules/Services.jsm");
// Reading the preference
var regexp = /foobar/; // default value
try
{
regexp = new RegExp(Services.prefs.getCharPref("extensions.myExtension.regexp"));
}
catch (e)
{
// Errors are expected, the preference might not exist yet
}
// Setting the preference
Services.prefs.setCharPref("extensions.myExtension.regexp", regexp.source);
You will be able to see this preference under about:config. More code examples
I have a page with possibly several content-editable iframes (editors).
Now I would like to use my custom Firefox extension to do the following:
Setting the cursor to the end (or last HTML element) of the editor the cursor actually is in.
I found many solutions to get the cursor's position, but I need one to set it.
Any suggestions?
XPCOM likely includes such functionality as part of the testing rig. Mochitest at least is capable of this (again, probably though XPCOM).
On the other hand, when a user is on the system this a generally a gross violation of user interaction practices. Be sure you have a good justification for doing it. It may seem convenient but what if they're doing something else whilst using your addon? I usually have various apps open at once, Fx extensions are only part of that. I don't want it taking control of my mouse, EVER.
Is there something wrong with setting the focus? At least that only forces the user's hand at a window level.
It also suspect it make it quite difficult to get past AMO review. You'd have to justify why it was necessary to invoke such low-level functionality. If you interact with a window, for example, the window might be able to affect the input of your functions which in turn control the mouse... and then a random web site has access to the user's window!
Found the solution to my problem myself. This code myself will set the Cursor position to the last Paragraph of my editor:
var frame = window.content.document.getElementsByTagName('iframe')[2];
var win = frame.contentWindow;
var editingSession = Components.classes["#mozilla.org/editor/editingsession;1"].createInstance(Components.interfaces.nsIEditingSession);
var editor = editingSession.getEditorForWindow(win);
selection = window.getSelection();
var body = frame.contentDocument.body;
text = frame.contentDocument.createTextNode(".");
body.lastChild.appendChild(text); // add textnode to be selected
var range = editor.document.createRange();
range.setStartBefore(text);
range.setEndAfter(text);
editor.selection.removeAllRanges();
editor.selection.addRange(range);
body.lastChild.removeChild(text); // remove Child
I have a single line CEikLabel in my application that needs to scroll text.
The simple solution that comes to mind (but possibly naive) would be something like..
[begin pseduo code]
on timer.fire {
set slightly shifted text in label
redraw label
}
start timer
[end pseudo code]
Using a CPeriodic class as the timer and label.DrawDeferred() on each update.
Do you think this is the best way, it may be rather inefficient redrawing the label two or three times a second.. but is there any other way?
Thanks :)
I've seen the timer based solution used for scrolling item names in listboxes.
A couple of things to watch out for are that it could flicker a bit while scrolling and that you need to make sure the text you put on the label is not too long, otherwise it will automatically clip the string and add an elipsis (...)
Use TextUtils::ClipToFit to get a string that fits on the label and remove the elipsis it adds before putting the text on the label (search for KTextUtilClipEndChar in your clipped string). You will need to work out how many characters to skip at the beginning of the string before passing it to the clip function.
I don't know whether there is another way to do it and can't say whether the approach you have in your mind will be inefficient. However, you may want to take a look at this thread which discusses pretty much the same question as yours and also briefly mentions somewhat the same solution as the one you have conceived of.
I have done it like this
TTimeIntervalMicroSeconds32 scrolltime(70000);
iPeriodicScroll = CPeriodic::NewL(CActive::EPriorityIdle);
iPeriodicScroll->Start(scrolltime, scrolltime, TCallBack(CVisTagContainerView::ScrollTextL, this));
and then in the repeated function
CEikLabel *label = iContainer->Label();
const TDesC16 *temp = label->Text();
if (temp->Length() <= 0) {
if (iTextState != ETextIdle) { return; }
DownloadMoreTextL();
return;
}
TPtrC16 right = temp->Right(temp->Length()-1);
label->SetTextL(right);
label->DrawDeferred();
So text moves right to left, and when all gone, the label is repopulated by DownloadMoreTextL