We have currently started to evaluate AvalonEdit. We want to use it for a custom language. One of our requirements is to reorder and also to sort document lines by a certain criteria. How can this be accomplished?
Thanks in advance!
AvalonEdit provides the ICSharpCode.AvalonEdit.Document.DocumentLine class but this class just provides meta data on the line's length, starting and ending offset and so on.
In my opinion, there are 2 ways to accomplish your problem
Loop through all lines using TextEditor.LineCount and save the Line into a DocumentLine using TextEditor.Document.GetLineByNumber(int number). Furthermore you can use TextEditor.Document.GetText(DocumentLine.Offset, DocumentLine.Length to get the line's text
Use TextEditor.Text.Split('\n') to get all lines as a string array.
I'd recommend you using the DocumentLine method. Even if you have to use the GetText method in order to get the line's text the meta data on the lines is very nice.
To get all DocumentLines you can use a loop
List<DocumentLine> DocumentLines = new List<DocumentLine>(TextEditor.LineCount - 1);
for (int i = 1; i < TextEditor.LineCount; i++)
{
DocumentLines.Add(TextEditor.Document.GetLineByNumber(i));
}
Related
I am using "PHP Simple HTML DOM Parser" library and looking forward to find elements based on its text value (plaintext)
For example i need to find span element using its value "Red".
<span class="color">Red</span>
I was expecting bellow code to work but seems that it just replaces the value instead of searching it.
$brand = $html->find('span',0)->plaintext='Red';
I read Manual and also i tried to look in library code itself but was not able to find the solution, kindly advise if i am missing something or it is simply not possible to do via Simple Html DOM Parser.
P.S
Kindly note that i am aware of other ways like regex.
Using $html->find('span', 0) will find the (N)th span where in this case n is zero.
Using $html->find('span',0)->plaintext='Red'; will set the plaintext to Red
If you want to find the elements where the text is Red you could use a loop and omit the 0 to find all the spans.
For example, using innertext instead of plaintext:
$spansWithRedText = [];
foreach($html->find('span') as $element) {
if ($element->innertext === "Red") {
$spansWithRedText[] = $element;
}
}
I have the data as below manner.
<Status>Active Leave Terminated</Status>
<date>05/06/2014 09/10/2014 01/10/2015</date>
I want to get the data as in the below manner.
<status>Active</Status>
<date>05/06/2014</date>
<status>Leave</Status>
<date>09/10/2014</date>
<status>Terminated</Status>
<date>01/10/2015</date>
please help me on the query, to retrieve the data as specified above.
Well, you have a string and want to split it at the whitestapces. That's what tokenize() is for and \s is a whitespace. To get the corresponding date you can get the current position in the for loop using at. Together it looks something like this (note that I assume that the input data is the current context item):
let $dates := tokenize(date, "\s+")
for $status at $pos in tokenize(Status, "\s+")
return (
<status>{$status}</status>,
<date>{$dates[$pos]}</date>
)
You did not indicate whether your data is on the file system or already loaded into MarkLogic. It's also not clear if this is something you need to do once on a small set of data or on an on-going basis with a lot of data.
If it's on the file system, you can transform it as it is being loaded. For instance, MarkLogic Content Pump can apply a transformation during load.
If you have already loaded the content and you want to transform it in place, you can use Corb2.
If you have a small amount of data, then you can just loop across it using Query Console.
Regardless of how you apply the transformation code, dirkk's answer shows how you need to change it. If you are updating content already in your database, you'll xdmp:node-delete() the original Status and date elements and xdmp:node-insert-child() the new ones.
Say, for example, I want to bind a key "ctrl+d" to duplicate current line in LightTable. For that, to emulate duplication of the current line, I want to run a series of actions like [:editor.select-line :editor.copy :editor.selection.clear :editor.new-line-indent :editor.line-start :editor.paste]
How do I achieve this?
Note: I am aware of the :editor.sublime.duplicateLine tag which duplicates the line, but this is just the example. In general, I want to map a shortcut to a sequence of tags/tasks.
http://lighttable.com/
Are you trying to bind the key? You seem to have most of it set. Just open up user.keymap (ctrl-space "user keymap") and add this:
[:editor "ctrl+d" :editor.select-line
:editor.copy
:editor.selection.clear
:editor.new-line-indent
:editor.line-start
:editor.paste]
There is no requirement that you put it on separate lines like that of course.
Or are you asking for something more complicated?
I want to show large numbers separated by comma e.g. 123,000 not as 123000 but doing this i have to make it into a string on which the sorting is not working as desired.
Yes you have to convert it to a string. Use locale in order to display numbers based on user settings.
this->locale()->toString(value);
It's a bit easier if you move to a QTableView and QStandardItemModel, rather than a QTableWidget - don't know if this is suitable for you.
Then you can specify a SortRole which is distinct from the DisplayRole. Like this (hope the Python is readable - I use PySide)
tableView = QtGui.QTableView(self)
tableView.setSortingEnabled(True)
model = QtGui.QStandardItemModel(3,2,self)
model.setSortRole(QtCore.Qt.UserRole)
for r in range(3):
for c in range(2):
item = QtGui.QStandardItem(["1,000","200","100"][r])
item.setData(QtCore.Qt.UserRole,[1000,200,100][r])
model.setItem(r,c,item)
tableView.setModel(model)
Try commenting out the setSortRole line to see the two behaviours.
This seems like it should be a simple thing to do, but I can't figure it out.
I have a localized resource that I'm using in two places - one as a col. header in a datagrid, and then as a descriptor beside a field when the user edits a row.
The text of the label looks like:
Text="<%$Resources:Global,keyName%>"
However, I'd like to add a trailing : to the label - except if I change the above to
Text="<%$Resources:Global,keyName%>:"
then the : is the only thing that shows up! I've tried it with simple strings, so there's nothing special about the colon char that causes this.
Surely I don't have to have 2 different resources?
Have you tried Text="<%$Resources:Global,keyName%>" + ":" ?
You'd basically be concatenating two strings. Or treat them as two strings
StringBuilder t;
t.append(<%$Resources:Global,keyName%>)
t.append(":")
Text = t;
Assuming you need to keep the : together for styling reasons, replace the label with a span:
<%=Resources.Global.keyName %>:
Well, sometimes the obvious isn't so obvious until someone else looks at it:
Text="<%$Resources:Global,keyName%>" /> :
Just move the : outside the label tag, and all is well.