Exemplo n.º 1
0
void MIDIEventKeyDialog::FillKeylist(wxChoice* select, unsigned shortcut)
{
	const GOShortcutKey* keys = GetShortcutKeys();
	unsigned count = GetShortcutKeyCount();
	select->Append(_("None"), (void*)0);
	select->SetSelection(0);
	for(unsigned i = 0; i < count; i++)
	{
		select->Append(wxGetTranslation(keys[i].name), (void*)&keys[i]);
		if (keys[i].key_code == shortcut)
			select->SetSelection(i + 1);
	}
}
Exemplo n.º 2
0
void ShortcutMapper::populateShortCuts()
{
	TCHAR filter1[40]={0},filter2[40]={0};
	NppParameters *nppParam = NppParameters::getInstance();
	size_t nrItems = 0;

	switch(_currentState) {
		case STATE_MENU: {
			nrItems = nppParam->getUserShortcuts().size();
			break; }
		case STATE_MACRO: {
			nrItems = nppParam->getMacroList().size();
			break; }
		case STATE_USER: {
			nrItems = nppParam->getUserCommandList().size();
			break; }
		case STATE_PLUGIN: {
			nrItems = nppParam->getPluginCommandList().size();
			break; }
		case STATE_SCINTILLA: {
			nrItems = nppParam->getScintillaKeyList().size();
			break; }
	}
	ListView_DeleteAllItems(hlistview);

	if(nrItems==0){
        ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), false);
        ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DISABLE), false);
        ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), false);
		return;
	}
	else
		::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DISABLE), true);

	switch(_currentState) {
		case STATE_MENU: {
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), true);
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), false);
			break; }
		case STATE_MACRO: {
            bool shouldBeEnabled = nrItems > 0;
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), shouldBeEnabled);
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), shouldBeEnabled);
			break; }
		case STATE_USER: {
            bool shouldBeEnabled = nrItems > 0;
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), shouldBeEnabled);
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), shouldBeEnabled);
			break; }
		case STATE_PLUGIN: {
            bool shouldBeEnabled = nrItems > 0;
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), shouldBeEnabled);
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), false);
			break; }
		case STATE_SCINTILLA: {
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), true);
            ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), false);
			break; }
	}
	int index=0;
	int widths[3];
	widths[0]=gettextwidth(hlistview,L"Index");
	widths[1]=gettextwidth(hlistview,L"Name");
	widths[2]=gettextwidth(hlistview,L"Shortcut");
	GetWindowText(GetDlgItem(_hSelf,IDC_SHORTCUT_FILTER1),filter1,sizeof(filter2)/sizeof(TCHAR));
	GetWindowText(GetDlgItem(_hSelf,IDC_SHORTCUT_FILTER2),filter2,sizeof(filter2)/sizeof(TCHAR));
	_tcslwr(filter1);
	_tcslwr(filter2);

	for(size_t i = 0; i < nrItems; i++) {
		TCHAR keys[40]={0};
		const TCHAR *name=GetShortcutName(_currentState,i,nppParam);
		GetShortcutKeys(_currentState,i,nppParam,keys,sizeof(keys)/sizeof(TCHAR));
		if((filter1[0]==L'\0' && filter2[0]==L'\0') 
			|| (filter1[0]!=L'\0' && CheckFilter(name,filter1))
			|| (filter2[0]!=L'\0' && CheckFilter(keys,filter2))){
			TCHAR str[10]={0};
			LV_ITEM lvitem={0};
			int w;
			_sntprintf_s(str,sizeof(str)/sizeof(TCHAR),_TRUNCATE,L"%i",i);
			w=gettextwidth(hlistview,str);
			if(w>widths[0])
				widths[0]=w;
			w=gettextwidth(hlistview,name);
			if(w>widths[1])
				widths[1]=w;
			w=gettextwidth(hlistview,keys);
			if(w>widths[2])
				widths[2]=w;

			lvitem.mask=LVIF_TEXT|LVIF_PARAM;
			lvitem.iItem=index;
			lvitem.pszText=(LPWSTR)str;
			lvitem.lParam=i;
			ListView_InsertItem(hlistview,&lvitem);
			lvitem.mask=LVIF_TEXT;
			lvitem.iSubItem=1;
			lvitem.pszText=(LPWSTR)name;
			ListView_SetItem(hlistview,&lvitem);
			lvitem.iSubItem=2;
			lvitem.pszText=(LPWSTR)keys;
			ListView_SetItem(hlistview,&lvitem);
			index++;
		}
	}
	ListView_SetColumnWidth(hlistview,0,widths[0]);
	ListView_SetColumnWidth(hlistview,1,widths[1]);
	ListView_SetColumnWidth(hlistview,2,widths[2]);
	ListView_SetItemState(hlistview,0,LVIS_SELECTED,LVIS_SELECTED);
	if(index==0){
	    ::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_MODIFY), false);
		::EnableWindow(::GetDlgItem(_hSelf, IDC_SHORTCUT_DELETE), false);
	}
}