Copy link to clipboard
Copied
Lin Sims asked for an option for Paste: Preserve the target formatting.
I want to implement this in the script FMfindRepl. So I developed UnformatClipBoard. I needed to circumvent the following problems:
Details for the function listed hereafter:
The screen shot also shows the result from Paste Special > Unicode Text
Two additional functions are required: ExecuteFCodes → Message .
Edit 2022-06-08: Function corrected (applying a ¶ format is not just setting the new name...)
KLD_Z.UnformatClipboard = function (oDoc, oPgf) { // =========================
// Calling ExecuteFCodes (which calles Message)
// History 2022-06-08 Corrected: apply ¶ format is not just the name...
ApplyPgfFmt = function (oDoc, oPgf, sFormat) {
var oProps;
oPgfFmt = oDoc.GetNamedPgfFmt(sFormat);
if (oPgfFmt.ObjectValid()) {
oProps = oPgfFmt.GetProps();
oPgf.SetProps(oProps);
} else {
oPgf.Name = sFormat;
}
} //--- end ApplyPgfFmt ---------------------
var oDoc, oPage, sPgfFmt, oLocation = {}, oPgfLocal, oTFr, oTL, oTR, MM = 185771;
oDoc = app.ActiveDoc;
if (app.Displaying == true) { // Avoid flicker
app.Displaying = false;
}
oLocation.pgf = oDoc.TextSelection.beg.obj;// Save current loc
oLocation.txtRange = oDoc.TextSelection;
oLocation.page = oDoc.CurrentPage;
sPgfFmt = oPgf.Name; // Name of target paragraph format
// --- begin core function -----------------------
oPage = oDoc.FirstMasterPageInDoc;
oTFr = oDoc.NewTextFrame (oPage.PageFrame); // temporary text frame
oTFr.Width = 150 * MM;
oTFr.Height = 50 * MM;
oPgfLocal = oTFr.FirstPgf;
oTR = new TextRange;
oTR.end.obj = oTR.beg.obj = oPgfLocal;
oTR.end.offset = oTR.beg.offset = 0;
oDoc.TextSelection = (oPgfLocal,oTR);
oDoc.Paste(0); // Paste the clip board
oTR.beg.obj = oPgfLocal;¶
oTR.beg.offset = 0;
oTR.end.obj = oPgfLocal;
oTR.end.offset = Constants.FV_OBJ_END_OFFSET;
oDoc.TextSelection = oTR;
KLD_Z.ExecuteFCodes (["SelectAll","CharacterDefaultPgfFont"]);
ApplyPgfFmt (oDoc, oPgfLocal, sPgfFmt); // Complete format must be applied
oDoc.Copy (0); // not interactive
oTFr.Delete (); // Delete the helper text frame
// --- end core function -------------------------
oDoc.CurrentPage = oLocation.page; // Restore current location
oPgf = oLocation.pgf;
if (oPgf.ObjectValid () === 1) {
oDoc.TextSelection = oLocation.txtRange;
}
oDoc.ScrollToText(oLocation.txtRange);
if (app.Displaying == false) { // Restore previous state
app.Displaying = true;
app.ActiveDoc.Redisplay();
}
} // --- end UnformatClipboard ----------------------------------------
Klaus, that is seriously awesome.
Copy link to clipboard
Copied
As additional background, my want for this comes mostly from needing to replace text strings with variables. There's no paste option for "Variable of Name" so you have to use the clipboard, but it brings along whatever the underlying format was from where you copied it. However, the same annoyance applies to simply pasting text from the clipboard.
Really, when you get down to it, why is it possible to search for things like Variable of Name but not paste them?
Copy link to clipboard
Copied
Lin, I'm on the way...
It works already - but other functions in FMfindRepl must still be tested thoroughly...
The availability of Options and Replace Modes depends on the selected Find Type (Text). The indicated radio button may get different labels - and if set, the drop-down list below is filled with items of the appropriate type.
Compared to the FM Find/Change panel I use radio buttons, because in a drop-down list I can not disable certain items IMHO it does not make sense to allow Regular Expressions for search of Anchored Frames...
Copy link to clipboard
Copied
Klaus, that is seriously awesome.