How to bind multiple keys with hotkey.bind? - hammerspoon

like when I type "aq", to output "Ask a public question"
hs.hotkey.bind({}, "aq", function()
hs.eventtap.keyStrokes("Ask a public question")
end)

Related

Displaying custom controller data in visualforce page after onchange event

I have a picklist containing names of records of an object, "Test_Script".When I select any option from a picklist("selectlist" & selectoption are used for implementing picklist),at onchange event the other fields related to that record name should be displayed on visualforce page.
VF Page:
<h1>Choose Script:</h1>
<apex:selectlist value="{!selectedValue}" size="1"onchange="{!setValues}">
<apex:selectOptions value="{!scriptoptions}" />
</apex:selectlist>
<br/>
Executioner Name:
<outputfield value="{!valueResult.executioner_name}"/>
<br/>Planner Name:
<outputfield value="{!valueResult.planner_name}"/>
<br/>Reviewer Name:
<outputfield value="{!valueResult.reviewer_name}"/>
Controller:
public class ScriptAttributesController
{
public String setValues { get; set; }
public List<Test_script__c> scriptListWithValues = [select name, id, Executioner__c, Planner__c, Reviewer__c from Test_Script__c];
public static Test_Script__c valueResult=new Test_Script__c();
public String selectedValue {get;set;}
public void ScriptAttributesController()
{
}
public List<SelectOption> getScriptoptions()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('select a value','select a value'));
for(Test_Script__c s: scriptListWithValues )
{
options.add(new SelectOption(s.id,s.name));
}
return options;
}
public void setValues()
{
valueResult=[select name, id, Executioner__c, Planner__c, Reviewer__c, Iteration__c from Test_Script__c where name='selectedValue' limit 1];
}
}
I am not able to see value on screen on change og picklist value
I would say that a getter is missing for your valueResult.
public Test_Script__c valueResult {get; set;}
and in the controller you can init the object.

MongoDB: Editing Element In Array

I am wanting to edit an element that might exist in multiple arrays in a collection.
public class Class
{
[BsonId]
public Guid Id { get; set;}
public string Name {get; set;}
public List<Student> Students {get; set;}
}
public class Student
{
[BsonId]
public Guid Id {get; set;}
public string Name {get; set;}
public string Grade {get; set;}
}
Then my class collection would look like
{
"_id" : NUUID("..."),
"Name" : "Computer Science",
"Students" : [
{
"_id" : NUUID("..."),
"Name" : "Chris"
"Grade" : "A"
},
{
"_id" : NUUID("..."),
"Name" : "Bob"
"Grade" : "B"
}
}
And my student collection would look like
{
"_id" : NUUID("..."),
"Name" : "Chris Eastwood"
"Grade": "C
}
Now when a student updates his information I want his information to be updated in each class.
I was trying to do:
// given student that has been edited
var query = Query.EQ("Students._id", student.Id);
var update = Update<Class>
.Pull(c => c.Students, x => x.EQ(q => q.Id, student.Id))
.Push(c => c.Students, student)
Context.Class.Update(query,update,UpdateFlags.Multi);
But that does not work since you "cannot update Students and Students at the same time"
I was wondering is there a way to just update all that student in each array for each Class that contains that Student?
Thanks!
I'm not familiar with the c# driver, but this is the query that you are looking for:
db.classes.update({
'Students._id': some_student_id,
}, {
$set: {
'Students.$.property': some_value
}
},{
multi: true
});
The key concept that you are looking for is the positional $ operator. It is the index of the object that matched in the query.

Binding Datagrid to observablecollection wont display data only rows

I'm having a bit of trouble getting the following to work:
I'm creating an ObservableCollection like this:
ObservableCollection<OverViewItems> ocOrderData = new ObservableCollection<OverViewItems>();
The class OrderViewItems looks like this:
public class OverViewItems
{
public string OrderNo;
public int Pieces;
public string SenderName;
public string ReceiverName;
public string ReceiverAddress;
public string ReceiverZip;
public string ReceiverCity;
public DateTime DelDate;
}
And then I populate it with some sample data (two rows in this case), like this:
ocOrderData.Add(new OverViewItems
{
OrderNo = "TEST",
Pieces = 1,
SenderName = "TEST SENDER",
ReceiverName = "TEST RECEIVER",
ReceiverAddress = "TEST ADDRESS",
ReceiverZip = "TEST ZIP",
ReceiverCity = "TEST CITY",
DelDate = DateTime.Now,
});
ocOrderData.Add(new OverViewItems
{
OrderNo = "TEST 2",
Pieces = 1,
SenderName = "TEST SENDER 2",
ReceiverName = "TEST RECEIVER 2",
ReceiverAddress = "TEST ADDRESS 2",
ReceiverZip = "TEST ZIP 2",
ReceiverCity = "TEST CITY 2",
DelDate = DateTime.Now,
});
And try to bind it to a WPF Datagrid like this:
dataGrid1.ItemsSource = ocOrderData;
And the XAML for the Datagrid looks like this:
<DataGrid
AutoGenerateColumns="True"
Height="200"
HorizontalAlignment="Left"
Margin="23,172,0,0"
Name="dataGrid1"
VerticalAlignment="Top"
Width="1084"
/>
Now, the datagrid displays the two rows ok, but there's no data, no columns, no nothing except a blank datagrid with two rows. Why is this? What do I do wrong?
Any help is appreciated. :)
You have to use properties in the OverViewItems class instead of simple public fields.
Doing that should make the DataGrid create the columns correctly.
public class OverViewItems
{
public string OrderNo { get; set; }
public int Pieces { get; set; }
public string SenderName { get; set; }
public string ReceiverName { get; set; }
public string ReceiverAddress { get; set; }
public string ReceiverZip { get; set; }
public string ReceiverCity { get; set; }
public DateTime DelDate { get; set; }
}
you can just bind to public properties and not to fields.
public class OverViewItems
{
public string OrderNo {get;set};
public int Pieces {get;set};
public string SenderName {get;set};
public string ReceiverName {get;set};
public string ReceiverAddress {get;set};
public string ReceiverZip {get;set};
public string ReceiverCity {get;set};
public DateTime DelDate {get;set};
}

Silverlight 3 : Datagrid - Editing a cell shows a "Property set method not found." message

I have a silverlight datagrid control bound to a Dictionary<string, string> with autogenerate columns set to true.
In the AutoGeneratingColumn event i change the column Header and IsReadOnly Properties as required(column bound to dictionary value is editable).
if ( string.Compare( e.Column.Header.ToString( ).ToLower( ), "key" ) == 0 )
{
e.Column.Header = "Property Name";
e.Column.IsReadOnly = true;
}
else
{
e.Column.Header = "Property Value";
e.Column.IsReadOnly = false;
}
All this works as intended but when i edit a cell and tab out i get a "Property set method not found." message next to the cell and it does not allow me to modify the grid after that.
A Dictionary<TKey, TValue> is contains a set of KeyValuePair<TKey, TValue> structures. Now that is the problem, the Key and Value properties are readonly, there is no Set, even if there were what is being edited will not be the same item that is held in the dictionary since structures are value types.
Bottom line is you can't edit a Dictionary with the DataGrid. You will need to create your own class:-
public class PropertyItem
{
public string Name { get; set; }
public object Value { get; set; }
}
Then use something like ObservableCollection<PropertyItem>.

How do I programmatically insert rows into a Silverlight DataGrid without binding?

I am using a common Silverlight DataGrid to display results from a search. The "schema" of the search can vary from query to query.
To accommodate this, I am trying to dynamically populate the DataGrid. I can set explicitly set the columns, but I am having trouble setting the ItemSource. All of the MSDN examples set the ItemSource to a collection with a strong type (e.g. a Custom type with public properties matching the schema). The DataGrid then uses reflection to scour the strong type for public properties that will match the columns.
Since my search results are dynamic, I cannot create a strong type to represent what comes back. Can I not just give the DataGrid an arbitrary list of objects so long as the number of objects in each list matches the number of columns? Anyone know if this is possible?
I would like to do something similar to this:
List<List<object>> myResults = <voodoo that populates the result list>
myDataGrid.ItemsSource = myResults;
Colin Eberhardt has posted an ingenious solution to the problem you've described -
http://www.scottlogic.co.uk/blog/colin/2010/03/binding-a-silverlight-3-datagrid-to-dynamic-data-via-idictionary-updated/
The following article gets me close to what I want:
http://blogs.msdn.com/b/scmorris/archive/2008/04/14/defining-silverlight-datagrid-columns-at-runtime.aspx
Essentially, you have to have a bindable property. You can't just create rows based on an arbitrary list of items. I stumbled upon a couple of open source projects that solve this problem by using reflection to build CLR types at runtime and then bind to those types.
Yes, it is possible. Here is a sampel swiped from MSDN
using System;
using System.Collections.Generic;
using System.Windows.Controls;
namespace DataGridSnippets
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
// Set the ItemsSource to autogenerate the columns.
dataGrid1.ItemsSource = Customer.GetSampleCustomerList();
dataGrid3.ItemsSource = Customer.GetSampleCustomerList();
dataGrid4.ItemsSource = Customer.GetSampleCustomerList();
dataGrid5.ItemsSource = Customer.GetSampleCustomerList();
}
}
public class Customer
{
public String FirstName { get; set; }
public String LastName { get; set; }
public String Address { get; set; }
public Boolean IsNew { get; set; }
// A null value for IsSubscribed can indicate
// "no preference" or "no response".
public Boolean? IsSubscribed { get; set; }
public Customer(String firstName, String lastName,
String address, Boolean isNew, Boolean? isSubscribed)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Address = address;
this.IsNew = isNew;
this.IsSubscribed = isSubscribed;
}
public static List<Customer> GetSampleCustomerList()
{
return new List<Customer>(new Customer[4] {
new Customer("A.", "Zero",
"12 North Third Street, Apartment 45",
false, true),
new Customer("B.", "One",
"34 West Fifth Street, Apartment 67",
false, false),
new Customer("C.", "Two",
"56 East Seventh Street, Apartment 89",
true, null),
new Customer("D.", "Three",
"78 South Ninth Street, Apartment 10",
true, true)
});
}
}
}

Resources