Reading a hidden text in Word - ms-word

I use the following to read hidden text.
Globals.ThisAddIn.Application.ActiveDocument.Content.TextRetrievalMode.IncludeHiddenText = true;
var Text = Globals.ThisAddIn.Application.ActiveDocument.Content.Text;
But it doesn't return hidden text. Moreover, if I check TextRetrievalMode.IncludeHiddenText, it's still false - my statement is ignored but it doesn't throw any exception.
How to read hidden text please ?

Accessing the text retrieval mode like in your sample will always return a fresh Range object with the default configuration. You need to get a range object, set the TextRetrievalMode on that object and then get the text from that same object:
var range = Globals.ThisAddIn.Application.ActiveDocument.Range();
range.TextRetrievalMode.IncludeHiddenText = true;
var text = range.Text;

Related

vscode API: get Position of last character of line

Following up on this still unanswered question regarding VS Code Extensions with the VS Code API. I didn't answer it because it specifically asked for a solution using the with method of the Position object. I couldn't make that work, nor was I able to loop through the object to get the last character. Trying to manipulate the selection with vscode.commands.executeCommand didn't work either, because vscode.window.activeTextEditor doesn't appear to reflect the actual selection in the window as soon as the Execution Development Host starts running. The only solution I could find was the hoop-jumping exercise below, which gets the first character of one line and the first character of the next line, sets a Range, gets the text of that Range, then reduces the length of that text string by 1 to get the last character of the previous line.
function getCursorPosition() {
const position = editor.selection.active;
curPos = selection.start;
return curPos;
}
curPos = getCursorPosition();
var curLineStart = new vscode.Position(curPos.line, 0);
var nextLineStart = new vscode.Position(curPos.line + 1, 0);
var rangeWithFirstCharOfNextLine = new vscode.Range( curLineStart, nextLineStart);
var contentWithFirstCharOfNextLine = editor.document.getText(rangeWithFirstCharOfNextLine);
var firstLineLength = contentWithFirstCharOfNextLine.length - 1;
var curLinePos = new vscode.Position(curPos.line, firstLineLength);
var curLineEndPos = curLinePos.character;
console.log('curLineEndPos :>> ' + curLineEndPos);
I'm obviously missing something - it can't be impossible to get the last character of a line using the VSCode API without mickey-mousing the thing like this. So the question is simply, what is the right way to do this?
Once you have the cursor Position the TextDocument.lineAt() function returns a TextLine. From which you can get its range and that range.end.character will give you the character number of the last character. - not including the linebreak which if you want to include that see TextLine.rangeIncludingLineBreak().
const editor = vscode.window.activeTextEditor;
const document = editor.document;
const cursorPos = editor.selection.active;
document.lineAt(cursorPos).range.end.character;
Note (from [TextDocument.lineAt documentation][1] ):
Returns a text line denoted by the position. Note that the returned
object is not live and changes to the document are not reflected.

Is therre any crystal coding style to prevent nil error in compiling

I am a newbie of crystal and amber framework, and when I try to rewrite a rails app with db to amber, I encountered a lot of compile error complained about nil matching, even sometime it is clearly not nil I think, such as
doc = Document.first("where id = ?",params[:id])
if doc.title.nil?
title = ""
else
title = doc.title
end
I must write as such
doc = Document.first("where id = ?",params[:id])
title = ""
if doc
if doc.title.nil?
title = ""
else
title = doc.title.not_nil!
end
end
I think maybe it is because of my code style.
So is there some good code style document for crystal or
good practices?
I'm new to crystal too however, you can remove the nested if block with a guard clause.
return unless doc
Also, you can set a default value with granite. So where you put title = "" can be removed if the default value is an empty string. With that in mind, you new code would be:
doc = Document.first("where id = ?",params[:id])
return unless doc
title = doc.title

Check if text binded to a control is null

I'm trying to check if I'm binding a null data on a controller. If the data is null, I need to not show the label as well as the binded data.
Below is my code right now.
var oMatNrRow1 = new sap.ui.commons.layout.MatrixLayoutRow();
control1 = new sap.ui.commons.Label({
text : Appcc.getText("MATERIAL_NO") + ":"
});
matrixCell1 = new sap.ui.commons.layout.MatrixLayoutCell();
matrixCell1.addContent(control1);
control = new sap.ui.commons.Label();
control.bindProperty("text", "matnr");
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
I have tried control.getProperty("text") but it only returns null when it should have return a number if matnr is not null.
I also tried formatter. I will have no problem with formatter if matnr is not null. But if it is null, the point is to destroy/delete contents of both matrixCell1 instances. In my code below, addition of matrixCell1 content will still push through.
...
formatter: function(matnr){
if (matnr !== ''){
return contract
} else{
matrixCell.destroyContent();
}
});
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Not sure if you can move the ff code inside if statement
matrixCell1.addContent(control);
oMatNrRow1.addCell(matrixCell1);
vendorTable.addRow(oMatNrRow1);
Any ideas are appreciated.
I would also suggest to user the visible property.
Are you aware of conditional binding of UI5? Using them you do not need the formatter at all in that case. see
Found a workaround on my issue. It was a simple if else condition. For the if statement, I just added data[j].matnr and it worked! I also noticed that this was how SAP implemented the behavior also e.g. oSearchViewData.description.

Web2py SQLFORM.grid Edit page

I'm using SQLFORM.grid for my form. The view is showing up fine and i can hide fields. But when i go into the Edit page, i want to have certain fields not readable and not writeable. I have set it to be readable=False before the SQLFORM.grid call and also in the request.args == 'edit'. I can confirm it detects the edit page but for some reason, it doesn't run the read and write.
following is the controller:
def display_form():
db.items.timeStamp.readable = False
db.items.imageName.readable = False
db.items.isCopied.writeable = True
query = (db.items.numSold > 100)
default_sort_order = [db.items.numSold]
if len(request.args) > 1 and ('edit' in request.args):
db.items.timeStamp.readable = False
db.items.imageName.writeable = False
form = SQLFORM.grid(query=query, orderby=default_sort_order, create=False,
deletable=False, editable=True, maxtextlength=64, paginate=25, csv=False,
user_signature=False,
links=[dict(header=T('Profit'),body=lambda row: row.profit),
dict(header=T('Image'), body = lambda rowB: A(IMG(_src=URL('static', "images/"+
rowB.imageName.replace('\\','/')), _width=50, _height=50),
_href=URL('static', "images/"+ rowB.imageName.replace('\\','/'))))],
selectable=get_chosenItems
)
else:
form = SQLFORM.grid(query=query, orderby=default_sort_order, create=False,
deletable=False, editable=True, maxtextlength=64, paginate=25, csv=False,
user_signature=False,
links=[dict(header=T('Profit'),body=lambda row: row.profit),
dict(header=T('Image'), body = lambda rowB: A(IMG(_src=URL('static', "images/"+
rowB.imageName.replace('\\','/')), _width=50, _height=50),
_href=URL('static', "images/"+ rowB.imageName.replace('\\','/'))))],
selectable=get_chosenItems
)
return dict(form=form)
I can tell that when on the edit page, it would go in the if statement, however, it totally ignores the readables i set there.
Should i be calling the form once again within the edit page?
I feel that it's redundant.
To prevent fields from being included on edit forms, set both the readable and writable attributes to False. If you set writable to False but leave readable as True, then you'll see a read-only value for the field on the form.

as3 - loop over all text fields?

I have a form in as3 flash with textfields and radio buttons with their "instance name" all set consecutively such as:
field_1
field_2
field_3
...etc
Is there an easy way in AS3 code to loop over all those fields and get their values in an array? Ideally I'd like a simply loop to get the values (so I can add in a simple popup if a value is missing) and then with the filled array simply post it using URLRequest.
Thanks!
If you want a way that's a little less work and more maintainable (if the amount of text can change in the future or you need to reuse the code on other forms or don't want to bother with instance names), then you could do something like the code below.
Keep in mind this assumes all your text fields are children of the same parent and is in the scope of that parent (so on a frame in the timeline that holds all your text fields)
function validateTextFields(){
var tmpTf:TextField;
var i:int = numChildren;
while(i--){ //iterate through all the display objects on this timeline
tmpTf = getChildAt(i) as TextField;
if(tmpTf){
//now that you have the textfield, you can check for an appropriate value, or send the value to a server, or store it in an array etc.
//check if the value is blank, if so set the background to red
if(tmpTf.text == ""){
tmpTf.background = true;
tmpTf.backgroundColor = 0xFF0000;
}else{
tmpTf.background = false;
}
}
}
}
It sounds like you want to use a for statement. I've also used a multi-dimensional array to store the instance names, and the text that they contain. I like to use the variable _path to define the scope of my code.
var _path = this;
var text_ar:Array = new Array(['instance_1',''],['instance_2',''],['instance_3','']); //instance name, instance text.
for(var i=0; i<ar.length; i++)
{
text_ar[i][1] = _path[text_ar[i][0]].text
}
trace( text_ar[1][1] ); //Traces the text that's entered in instance_1.