Textmate - change #TODO color inside a doc block - documentation

I'm able to change an entire documentation block's color inside textmate by using the scope comment.block.documentation
However is it possible to change the color of specific words inside that docblock?
I'm refering to change the color of words or even the entire line like
#TODO
#FIXME
#CHANGED
thanks.

Ok... i was able to find the answer.
Bundles > Bundle Editor > Show Bundle Editor
Select the Language Javascript (note... the language has a L icon inside the Javascript item on the left list)
find for the scope named comment.block.documentation.js and modify it accordingly
{ name = 'comment.block.documentation.js';
begin = '(/\*\*)\s*$';
end = '\*/';
beginCaptures = { 1 = { name = 'punctuation.definition.comment.js'; }; };
endCaptures = { 0 = { name = 'punctuation.definition.comment.js'; }; };
patterns = (
{ name = 'meta.documentation.tag.todo.js';
begin = '((\#)TODO)';
end = '(?=^\s*\*?\s*#|\*/)';
},
{ name = 'meta.documentation.tag.fixme.js';
begin = '((\#)FIXME)';
end = '(?=^\s*\*?\s*#|\*/)';
},
{ name = 'meta.documentation.tag.changed.js';
begin = '((\#)CHANGED)';
end = '(?=^\s*\*?\s*#|\*/)';
},
);
},
after you just have to change the color on the prefs window, using the declared selector!

Related

Orchard - Creating Query Programmatically

I am creating a custom module in Orchard. After I enable my module I would like to create a query programmatically.
I do that in my Migrations.cs file thanks to implementation of IDependency interface.
I am able to create the query but I do I programmatically set filters of that query?
var announcementsQuery = _contentManager.Create("Query");
announcementsQuery.As<TitlePart>().Title = "Announcements";
_contentManager.Publish(announcementsQuery);
I found out how to do this:
var announcementsQuery = _contentManager.Create("Query");
announcementsQuery.As<TitlePart>().Title = "Announcements";
announcementsQuery.As<QueryPart>().ContentItem.ContentType = "Announcement";
var filterGroupRecord = new FilterGroupRecord();
var filterRecord = new FilterRecord()
{
Category = "Content",
Type = "ContentTypes",
Description = "Announcement",
Position = 1,
State = "<Form><Description>Announcement</Description><ContentTypes>Announcement</ContentTypes></Form>"
};
filterGroupRecord.Filters.Insert(0, filterRecord);
announcementsQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord);

dojo and dynamically added options to dijit.form.select

I use dojo 1.8.2 and here is my problem (I have seen this and this question, but they eren't helpful) :
My JS code receives from server some data in JSON format. With that, I dynamically create some options for dijit.form.select:
var select = registry.byId('zgloszenieDoFirmyEdycja');
for (var uzytkownik in dane.uzytkownicy){
var idUzytkownika = dane.uzytkownicy[uzytkownik]['_id']['$oid'];
var imie = dane.uzytkownicy[uzytkownik].imie;
var nazwisko = dane.uzytkownicy[uzytkownik].nazwisko;
var wybrany = (idUzytkownika == id);
var opcja = {};
opcja.label = imie + ' ' + nazwisko;
opcja.value = idUzytkownika;
opcja.selected = wybrany;
console.log(wybrany);
console.log(idUzytkownika + ' | ' + imie + ' ' + nazwisko);
console.log(opcja);
select.addOption(opcja);
/*select.addOption({
label: imie + ' ' + nazwisko,
value: idUzytkownika,
selected: wybrany
});*/
}
This is my console output:
false
5077d2a1e4b0f5734a9850a1 | zero zero
Object { label="zero zero", value="5077d2a1e4b0f5734a9850a1", selected=false}
true
50c0776f096aa0e726d221a3 | raz raz
Object { label="raz raz", value="50c0776f096aa0e726d221a3", selected=true}
false
50d019c3096aa862c6898cdb | dwa dwa
Object { label="dwa dwa", value="50d019c3096aa862c6898cdb", selected=false}
But after the dijit.form.select is updated, the selected parameter gets somehow mixed up and is set to true not for the option that I set it for, but for the first one:
console.log(select);
...
Object[Object { label="zero zero", value="5077d2a1e4b0f5734a9850a1", selected=true},
Object { label="raz raz", value="50c0776f096aa0e726d221a3", selected=false},
Object { label="dwa dwa", value="50d019c3096aa862c6898cdb", selected=false}
]
...
I don't understand why it happens, any clues?
Looking into the source code of dijit/form/_FormSelectWidget the issue is caused by the fact, that if no option is selected then the first option gets selected by default. By the time you add the first option this condition is met and the first option gets selected.
Workaround: add all options at once as an array:
var select = registry.byId("select1");
option1 = { value: "o1", label: "option 1", selected: false };
option2 = { value: "o2", label: "option 2", selected: true };
select.addOption([option1, option2]); // add all options at once as an array
See it in action: http://jsfiddle.net/phusick/BfTXC/

How to render a GWT widget with a clickhandler GWT with a custom table builder?

I'm trying to use a GWT 2.5rc1 custom tablebuilder to render a subtable for each row in my datagrid. I've followed the example in the 2.5 rc1 showcase (url: http://showcase2.jlabanca-testing.appspot.com/#!CwCustomDataGrid).
I'm able to see the newly added sub-rows, but the problem comes when I want to add a clickhandler to a subrow anchor element.. the clickhandler is never invoked, which it seems also quite clear to me since I'm not "registering" the event handler anywhere.
Here the code I'm using now, "relevant part":
private void buildRegRow(Registrazione rowValue,final int absRowIndex, boolean isCommentRow) {
// Calculate the row styles.
SelectionModel<? super Registrazione> selectionModel = cellTable.getSelectionModel();
boolean isSelected =
(selectionModel == null || rowValue == null) ? false : selectionModel
.isSelected(rowValue);
boolean isEven = absRowIndex % 2 == 0;
StringBuilder trClasses = new StringBuilder(rowStyle);
if (isSelected) {
trClasses.append(selectedRowStyle);
}
// Calculate the cell styles.
String cellStyles = cellStyle;
if (isSelected) {
cellStyles += selectedCellStyle;
}
if(isCommentRow)
cellStyles += childCell;
TableRowBuilder row = startRow();
row.className(trClasses.toString());
/*
* Checkbox column.
*
* This table will uses a checkbox column for selection. Alternatively,
* you can call dataGrid.setSelectionEnabled(true) to enable mouse
* selection.
*/
TableCellBuilder td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if (!isCommentRow) {
renderCell(td, createContext(0), cellTable.getColumn(0), rowValue);
}
td.endTD();
/*
* View children column.
*
* Displays a link to "show children". When clicked, the list of friends is
* displayed below the contact.
*/
td = row.startTD();
td.className(cellStyles);
if(!isCommentRow) {
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if(rowValue.hasComments())
//td.className(CellTableResource.INSTANCE.dataGridStyle().showChildren());
renderCell(td, createContext(1), cellTable.getColumn(1), rowValue);
} else {
td.colSpan(getColumns().size() - 1);
// // Draw sub-table header
TableBuilder subTable = td.startTable();
TableSectionBuilder subTableSection = subTable.startTHead();
TableRowBuilder tr2 = subTableSection.startTR();
TableCellBuilder td2 = tr2.startTH();
td2.text(msgs.date());
tr2.endTH();
td2 = tr2.startTH();
td2.text(msgs.username());
tr2.endTH();
td2 = tr2.startTH();
td2.text(msgs.comment());
tr2.endTH();
td2 = tr2.startTH();
td2.text(msgs.actions());
tr2.endTH();
subTableSection.endTR();
subTable.endTHead();
subTableSection = subTable.startTBody();
for(final EntityComment ec : rowValue.getCommentList()) {
tr2 = subTableSection.startTR();
// Date
td2 = tr2.startTD();
td2.text(DateUtil.getDefaultDateTimeFormat().format(ec.getCreationDate()));
tr2.endTD();
// Username
td2 = tr2.startTD();
td2.text(ec.getUsername());
tr2.endTD();
// Text
td2 = tr2.startTD();
td2.text(ec.getText());
tr2.endTD();
// Actions
td2 = tr2.startTD();
// Remove
Anchor removeAnchor = new Anchor("remove");
removeAnchor.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.alert("clicked");
}
});
td2.html(new SafeHtmlBuilder().appendHtmlConstant(removeAnchor.toString()).toSafeHtml());
tr2.endTD();
subTableSection.endTR();
}
subTable.endTBody();
td.endTable();
}
td.endTD();
for(int i = 2; i <= 6; i++) {
// Recorded, list name, callcenter, msisdn
td = row.startTD();
td.className(cellStyles);
td.style().outlineStyle(OutlineStyle.NONE).endStyle();
if(!isCommentRow) {
renderCell(td, createContext(i), cellTable.getColumn(i), rowValue);
}
td.endTD();
}
row.endTR();
}
The subtable shows up, with an anchor at the correct position, but the clickhandler is never invoked. I do not know how to write the handler code to the page, like I've done to render the anchor.
Thanks for any help.
I have tried custom tablebuilder and created a grid. You can add any element using the proper structure. Make sure you set the Unique Id to each element you create. Then through code access the element through the following code,
Element e = DOM.getElementById( id );
Cast the element to its proper widget i.e, if you are using text input element you can always cast it to textbox. To cast the element there is one more step which you can google out. Then add the clickhandler or whichever handler you want.

How to check if a given window is open in Xul?

How to check if a given window is open in Xul?
I would like to check if a window is already openned in my desktop app. So if it is, I'll not open it again.
-- my attempt
I'm trying to accomplish this using the window title, so I get the list of windows from windowManager and check the title, but the getAttribute is not from an interface that I can query, it's from element, what interface should I use?
var windowManager = Components.classes['#mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getXULWindowEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface(Components.interfaces[" WHICH INTERFACE TO PUT HERE? "]);
write("WINDOW TITLE = " + win.getAttribute("title"));
}
If you set a windowtype="myWindowType" attribute on your document's <window> element then you can just use windowMediator.getMostRecentWindow('myWindowType'); to see whether you already have one open.
var windowManager = Components.classes['#mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface( Components.interfaces.nsIDOMChromeWindow );
write("WINDOW TITLE = " + win.document.documentElement.getAttribute("title") );
}
if you are using getXULWindowEnumerator you should use Components.interfaces.nsIXULWindow
you probably could use the nsIDOMWindow attribute name if you open the windows your self because you set the name of the window in the open function. This is not visible to the user so you have a little more flexibility
var win = window.open( "chrome://myextension/content/about.xul",
"windowName", "chrome,centerscreen" );
write( "WINDOW NAME: " + win.name ); // Should now give WINDOW NAME: windowName
If you are leaving the window name blank it will open a new window every time. If you however use a window name (something else than "" ) it will create it if it does not exists, or load the new content in the already existing window with the name you have specified.
Which seems like almost what you want. Butt you could use name attribute to avoid the reload if you have to.
var openNewWindow = true;
var windowManager = Components.classes['#mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var enum = windowManager.getEnumerator(null);
while(enum.hasMoreElements()) {
var win = enum.getNext().QueryInterface( Components.interfaces.nsIDOMChromeWindow );
if( win.name == "windowName" ) {
openNewWindow = false;
}
}
if( openNewWindow ) {
var win = window.open( "chrome://myextension/content/about.xul",
"windowName", "chrome" );
}

SharePoint get value of rich text box control created programatically

I'm writing a custom web part that need to use a couple of rich text box controls. I'm placing the controls onto the web part programatically. When the web part gets a save postback I'm able to capture the data from all the fields except the two rich text box ones. What's the trick to be able to get the value of a rich text box?
The code I"m using to place my form controls is:
private void CreateInputControls()
{
inputPanel.Controls.Clear();
SPList list = SPContext.Current.Site.RootWeb.Lists["MyList"];
SPContentType cType = list.ContentTypes[0];
Table table = new Table();
table.CellPadding = 3;
table.CellSpacing = 0;
SPContext newContext = SPContext.GetContext(System.Web.HttpContext.Current, list.DefaultView.ID, list.ID, list.ParentWeb);
foreach (SPField field in cType.Fields)
{
if (!field.Hidden && field.CanBeDisplayedInEditForm)
{
FieldLabel fieldLabel = new FieldLabel();
fieldLabel.ControlMode = SPControlMode.New;
fieldLabel.ListId = list.ID;
fieldLabel.FieldName = field.InternalName;
fieldLabel.ItemContext = newContext;
fieldLabel.RenderContext = newContext;
fieldLabel.Field.Required = fieldLabel.Field.Required;
FormField formField = new FormField();
formField.ControlMode = SPControlMode.New;
formField.ListId = list.ID;
formField.FieldName = field.InternalName;
formField.ItemContext = newContext;
formField.RenderContext = newContext;
formField.ID = field.InternalName;
formField.EnableViewState = true;
TableRow row = new TableRow();
table.Rows.Add(row);
TableCell cellLabel = new TableCell();
TableCell cellField = new TableCell();
cellLabel.Controls.Add(fieldLabel);
cellField.Controls.Add(formField);
row.Cells.Add(cellLabel);
row.Cells.Add(cellField);
}
}
inputPanel.Controls.Add(table);
}
The code I'm using to save a new item is:
private void UpdateItem(string bannerImageURL, string thumbnailImageURL)
{
SPList list = SPContext.Current.Site.RootWeb.Lists["MyList"];
SPContentType cType = list.ContentTypes[0];
SPItem item = list.AddItem();
foreach (SPField field in cType.Fields)
{
if (!field.Hidden && field.CanBeDisplayedInEditForm)
{
FormField formField = (FormField)inputPanel.FindControl(field.InternalName);
if (formField != null)
{
// Saves data for all fields EXCEPT for rich text box (sharepoint multiline columns).
item[field.Title] = formField.Value;
}
}
}
item.Update();
}
Maybe there's an issue with the field name. Try to use the InternalName.
item[field.InternalName] = formField.Value;
I have been struggling with this and am using a workaround which I thought I'd post as this was quite frustrating.
The problem is that the RTE control is rendered empty and then populated from a hidden control with JavaScript on the client. However this hidden control is accessible server side thus:
switch (formField.Field.Type)
{
case SPFieldType.Note:
var rtf = (RichTextField)formField.Controls[0];
item[field.Title] = rtf.HiddenInput.Value;
break;
default:
item[field.Title] = formField.Value;
break;
}
This may need extending for other field types but you get the idea...