FontDia::FontDia(QTextCursor* cursor, QWidget* parent) : KDialog(parent), m_cursor(cursor) { //First find out if we have more than one charFormat in our selection. If so, m_initialFormat/m_style will get initialised with the charFormat at the cursor's position. The tabs will get informed of this. if (m_cursor->hasSelection()) { int begin = qMin(m_cursor->anchor(), m_cursor->position()); int end = qMax(m_cursor->anchor(), m_cursor->position()); QTextBlock block = m_cursor->block().document()->findBlock(begin); m_uniqueFormat = true; QTextCursor caret(*m_cursor); caret.setPosition(begin+1); m_initialFormat = caret.charFormat(); while (block.isValid() && block.position() < end) { QTextBlock::iterator iter = block.begin(); while (! iter.atEnd()) { QTextFragment fragment = iter.fragment(); if (fragment.position() >= end) break; if (fragment.position() + fragment.length() <= begin) { iter++; continue; } if (!(m_uniqueFormat = (fragment.charFormat() == m_initialFormat))) break; iter++; } if (!m_uniqueFormat) break; block = block.next(); } } else { m_initialFormat = cursor->charFormat(); m_uniqueFormat = true; } setCaption(i18n("Select Font")); setModal(true); setButtons(Ok | Cancel | Reset | Apply); setDefaultButton(Ok); m_characterGeneral = new CharacterGeneral(this, m_uniqueFormat); m_characterGeneral->hideStyleName(true); setMainWidget(m_characterGeneral); connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); connect(this, SIGNAL(resetClicked()), this, SLOT(slotReset())); initTabs(); }
/*! sets the curves. The properties of the curves in the list \c list can be edited in this widget. */ void XYFitCurveDock::setCurves(QList<XYCurve*> list){ m_initializing=true; m_curvesList=list; m_curve=list.first(); m_fitCurve = dynamic_cast<XYFitCurve*>(m_curve); Q_ASSERT(m_fitCurve); m_aspectTreeModel = new AspectTreeModel(m_curve->project()); this->setModel(); m_fitData = m_fitCurve->fitData(); initGeneralTab(); initTabs(); m_initializing=false; }
bool GameRankLayer::init() { if(!Layer::init()) { return false; } initBG(); initTabs(); initBtnBack(); return true; }
LauncherMainDialog::LauncherMainDialog( const Window& parent_window, LauncherWindow* lwindow ) : tabsInitialized(false) { handler = new LauncherMainDialogHandler; handler->lwindow = lwindow; optionsValueManager->load(); // Initialize main dialog + tab control. dialogData = new DialogData( IDD_MAINWINDOW, parent_window.getWindowHandle(), DialogData::ATTACH_ALL, handler ); handler->dialogData = dialogData; tabs = new DialogData( IDC_MAINTABS, GetDlgItem( parent_window.getWindowHandle(), IDD_MAINWINDOW), DialogData::ATTACH_ALL, handler ); int tabs_x = 0, tabs_y = 0; int tabs_width = 0, tabs_height = 0; initTabs(); tabs->getPosition( tabs_x, tabs_y ); tabs->getSize( tabs_width, tabs_height ); // Sub dialogs' init. HWND tabHwnd = GetDlgItem( dialogData->getHwnd(), IDC_MAINTABS ); handlerList[0] = new LaunchDialogHandler(tabHwnd); handlerList[1] = new GraphicsDialogHandler(tabHwnd); handlerList[2] = new SoundsDialogHandler(tabHwnd); handlerList[3] = new PhysicsDialogHandler(tabHwnd); handlerList[4] = new ModDialogHandler(tabHwnd); handlerList[5] = new UpdateDialogHandler(tabHwnd); handler->handlerList = handlerList; for(int l = 0; l < TAB_AMOUNT; l++) { handlerList[l]->initDialog ( ); handlerList[l]->loadOptions( ); // Adjust dialog's position. int d_w = 0, d_h = 0; handlerList[l]->dialogData->setPosition( 0, 0 ); handlerList[l]->dialogData->getSize( d_w, d_h ); RECT rc = { 0, 0, d_w, d_h }; SendMessage( tabHwnd, TCM_ADJUSTRECT, (WPARAM) FALSE, (LPARAM) &rc ); handlerList[l]->dialogData->setPosition( rc.left, rc.top ); } handlerList[0]->dialogData->show(); }
void MainFrm::newTabs() { qApp->setOverrideCursor( QCursor(Qt::BusyCursor ) ); statusShow(tr("Wait...")); if (pFrmReports->isVisible()) closeSecondaryFrm(pFrmReports); resetTabs(); if (sSample!=0) {delete sSample; sSample=0;} sSample=new Sample; initTabs(); statusShow(tr("Project successfully initialized.")); qApp->setOverrideCursor( QCursor(Qt::ArrowCursor ) ); }
/*! sets the curves. The properties of the curves in the list \c list can be edited in this widget. */ void XYDifferentiationCurveDock::setCurves(QList<XYCurve*> list) { m_initializing = true; m_curvesList = list; m_curve = list.first(); m_differentiationCurve = dynamic_cast<XYDifferentiationCurve*>(m_curve); Q_ASSERT(m_differentiationCurve); m_aspectTreeModel = new AspectTreeModel(m_curve->project()); this->setModel(); m_differentiationData = m_differentiationCurve->differentiationData(); initGeneralTab(); initTabs(); m_initializing = false; //hide the "skip gaps" option after the curves were set ui.lLineSkipGaps->hide(); ui.chkLineSkipGaps->hide(); }
ParagraphSettingsDialog::ParagraphSettingsDialog(TextTool *tool, QTextCursor *cursor, QWidget* parent) : KDialog(parent), m_tool(tool), m_cursor(cursor) { setCaption(i18n("Paragraph Format")); setModal(true); setButtons(Ok | Cancel | Apply); setDefaultButton(Ok); m_paragraphGeneral = new ParagraphGeneral; m_paragraphGeneral->hideStyleName(true); setMainWidget(m_paragraphGeneral); connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); initTabs(); }
ParagraphSettingsDialog::ParagraphSettingsDialog(TextTool *tool, KoTextEditor *editor, QWidget *parent) : KoDialog(parent) , m_tool(tool) , m_editor(editor) , m_styleChanged(false) { setCaption(i18n("Paragraph Format")); setModal(true); setButtons(Ok | Cancel | Apply); setDefaultButton(Ok); m_paragraphGeneral = new ParagraphGeneral; m_paragraphGeneral->hideStyleName(true); setMainWidget(m_paragraphGeneral); connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); initTabs(); // Do this after initTabs so it doesn't cause signals prematurely connect(m_paragraphGeneral, SIGNAL(styleChanged()), this, SLOT(styleChanged())); }
TabbedOptionsDialog::TabbedOptionsDialog(QWidget *parent) : QDialog(parent) { setWindowFlags(Qt::WindowMinMaxButtonsHint); setMinimumSize(MIN_WIDTH, MIN_HEIGHT); tabWidget = new QTabWidget; initTabs(); // buttons for the button box btnClose = new QPushButton("Close"); btnOpen = new QPushButton("Open"); btnSave = new QPushButton("Save"); btnNew = new QPushButton("New"); buttonBox = new QDialogButtonBox; buttonBox->addButton(btnNew, QDialogButtonBox::ActionRole); buttonBox->addButton(btnOpen, QDialogButtonBox::ActionRole); buttonBox->addButton(btnSave, QDialogButtonBox::ActionRole); buttonBox->addButton(btnClose, QDialogButtonBox::RejectRole); // connect to the appropriate slots connect(btnSave, SIGNAL(clicked()), this, SLOT(saveToXML())); connect(btnOpen, SIGNAL(clicked()), this, SLOT(openFromXML())); connect(btnClose, SIGNAL(clicked()), this, SLOT(closeDialog())); connect(btnNew, SIGNAL(clicked()), this, SLOT(newPlant())); // lay it all out QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setSizeConstraint(QLayout::SetNoConstraint); mainLayout->addWidget(tabWidget); mainLayout->addWidget(buttonBox); setLayout(mainLayout); // show title and make dialog modal setWindowTitle("Options"); setModal(false); }
FontDia::FontDia(KoTextEditor *editor, QWidget* parent) : KDialog(parent) , m_editor(editor) , m_styleChanged(false) { m_initialFormat = m_editor->charFormat(); setCaption(i18n("Select Font")); setModal(true); setButtons(Ok | Cancel | Reset | Apply); setDefaultButton(Ok); m_characterGeneral = new CharacterGeneral(this); m_characterGeneral->hideStyleName(true); setMainWidget(m_characterGeneral); connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply())); connect(this, SIGNAL(okClicked()), this, SLOT(slotOk())); connect(this, SIGNAL(resetClicked()), this, SLOT(slotReset())); initTabs(); // Do this after initTabs so it doesn't cause signals prematurely connect(m_characterGeneral, SIGNAL(styleChanged()), this, SLOT(styleChanged())); }
void TabbedOptionsDialog::reloadTabs() { tabWidget->clear(); initTabs(); }
void FontDia::slotReset() { initTabs(); slotApply(); // ### Should reset() apply? }
void MainFrm::loadTabs() { qApp->setOverrideCursor( QCursor(Qt::BusyCursor ) ); statusShow(tr("Wait...")); resetTabs(); initTabs(); if (pFrmFrame==0) return; this->tabWidget->insertTab(0,pFrmFrame, pFrmFrame->title()); if (sSample->frameId==-1 || sSample->frameTimeId==-1) return; QVector<int> vSample; vSample << sSample->frameTimeId; vSample << sSample->minorStrataId; vSample << sSample->cellId; vSample << sSample->vesselTypeId; vSample << sSample->sampVesselId; vSample << sSample->tripId; vSample << sSample->operationId; vSample << sSample->catchId; if (vSample.size() != vTabs.size()){ displayError(tr("Could not load project file!"),true);//TODO: improve errors! }else{ bool bOk=true; int ct=0; QVector<int>::const_iterator it; for (it = vSample.begin(); it != vSample.end(); ++it){ if ( qobject_cast<PreviewTab*>(vTabs.at(ct))!=0){ PreviewTab* pTab=qobject_cast<PreviewTab*>(vTabs.at(ct)); if (*it!=-1){ if (!pTab->tableSelect(*it)){ displayError(tr("Could not find the saved record on form ") + vTabs.at(ct)->title(),true); bOk=false; break; } QVector<int>::const_iterator it2; if (sSample->bLogBook && pTab->title()==tr("Stratum")) it2=it+3; else it2=it+1; //qDebug() << pTab->objectName() << endl; if (*it2!=-1 && ct<vTabs.size()-1){ //|| (sSample->bLogBook && ( pTab->objectName()){ vTabs.at(ct)->setLoading(true); if (!vTabs.at(ct)->next()){ bOk=false; vTabs.at(ct)->setLoading(false); break; } vTabs.at(ct)->setLoading(false); } } ct++; }//cast }//for if (bOk) statusShow(tr("Project successfully loaded.")); else displayError (tr("Could not load tab ") + vTabs.at(ct)->title() + tr("!"),false); } qApp->setOverrideCursor( QCursor(Qt::ArrowCursor ) ); }
BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG : { initBabyGrid(); initTabs(); fillOutBabyGrid(); _babygrid.display(); goToCenter(); return TRUE; } case WM_NOTIFY: { NMHDR nmh = *((NMHDR*)lParam); if (nmh.hwndFrom == _hTabCtrl) { if (nmh.code == TCN_SELCHANGE) { int index = TabCtrl_GetCurSel(_hTabCtrl); switch (index) { case 0: _currentState = STATE_MENU; break; case 1: _currentState = STATE_MACRO; break; case 2: _currentState = STATE_USER; break; case 3: _currentState = STATE_PLUGIN; break; case 4: _currentState = STATE_SCINTILLA; break; } fillOutBabyGrid(); } } break; } case WM_COMMAND : { switch (LOWORD(wParam)) { case IDCANCEL : { ::EndDialog(_hSelf, -1); return TRUE; } case IDOK : { ::EndDialog(_hSelf, 0); return TRUE; } case IDM_BABYGRID_MODIFY : { NppParameters *nppParam = NppParameters::getInstance(); int row = _babygrid.getSelectedRow(); switch(_currentState) { case STATE_MENU: { //Get CommandShortcut corresponding to row vector<CommandShortcut> & shortcuts = nppParam->getUserShortcuts(); CommandShortcut csc = shortcuts[row - 1], prevcsc = shortcuts[row - 1]; csc.init(_hInst, _hSelf); if (csc.doDialog() != -1 && prevcsc != csc) { //shortcut was altered nppParam->addUserModifiedIndex(row-1); shortcuts[row - 1] = csc; _babygrid.setText(row, 2, csc.toString().c_str()); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); } break; } case STATE_MACRO: { //Get MacroShortcut corresponding to row vector<MacroShortcut> & shortcuts = nppParam->getMacroList(); MacroShortcut msc = shortcuts[row - 1], prevmsc = shortcuts[row - 1]; msc.init(_hInst, _hSelf); if (msc.doDialog() != -1 && prevmsc != msc) { //shortcut was altered shortcuts[row - 1] = msc; _babygrid.setText(row, 1, msc.getName()); _babygrid.setText(row, 2, msc.toString().c_str()); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); } break; } case STATE_USER: { //Get UserCommand corresponding to row vector<UserCommand> & shortcuts = nppParam->getUserCommandList(); UserCommand ucmd = shortcuts[row - 1], prevucmd = shortcuts[row - 1]; ucmd.init(_hInst, _hSelf); prevucmd = ucmd; if (ucmd.doDialog() != -1 && prevucmd != ucmd) { //shortcut was altered shortcuts[row - 1] = ucmd; _babygrid.setText(row, 1, ucmd.getName()); _babygrid.setText(row, 2, ucmd.toString().c_str()); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); } break; } case STATE_PLUGIN: { //Get PluginCmdShortcut corresponding to row vector<PluginCmdShortcut> & shortcuts = nppParam->getPluginCommandList(); PluginCmdShortcut pcsc = shortcuts[row - 1], prevpcsc = shortcuts[row - 1]; pcsc.init(_hInst, _hSelf); prevpcsc = pcsc; if (pcsc.doDialog() != -1 && prevpcsc != pcsc) { //shortcut was altered nppParam->addPluginModifiedIndex(row-1); shortcuts[row - 1] = pcsc; _babygrid.setText(row, 2, pcsc.toString().c_str()); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); unsigned long cmdID = pcsc.getID(); ShortcutKey shortcut; shortcut._isAlt = pcsc.getKeyCombo()._isAlt; shortcut._isCtrl = pcsc.getKeyCombo()._isCtrl; shortcut._isShift = pcsc.getKeyCombo()._isShift; shortcut._key = pcsc.getKeyCombo()._key; ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, (LPARAM)&shortcut); } break; } case STATE_SCINTILLA: { //Get ScintillaKeyMap corresponding to row vector<ScintillaKeyMap> & shortcuts = nppParam->getScintillaKeyList(); ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row-1]; skm.init(_hInst, _hSelf); if (skm.doDialog() != -1 && prevskm != skm) { //shortcut was altered nppParam->addScintillaModifiedIndex(row-1); shortcuts[row-1] = skm; _babygrid.setText(row, 2, skm.toString().c_str()); //Notify current Accelerator class to update key nppParam->getScintillaAccelerator()->updateKeys(); } break; } } return TRUE; } case IDM_BABYGRID_DELETE : { NppParameters *nppParam = NppParameters::getInstance(); if (::MessageBox(_hSelf, TEXT("Are you sure you want to delete this shortcut?"), TEXT("Are you sure?"), MB_OKCANCEL) == IDOK) { const int row = _babygrid.getSelectedRow(); int shortcutIndex = row-1; DWORD cmdID = 0; // Menu data size_t posBase = 0; size_t nbElem = 0; HMENU hMenu = NULL; int modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN; switch(_currentState) { case STATE_MENU: case STATE_PLUGIN: case STATE_SCINTILLA: { return FALSE; //this is bad } case STATE_MACRO: { vector<MacroShortcut> & theMacros = nppParam->getMacroList(); vector<MacroShortcut>::iterator it = theMacros.begin(); cmdID = theMacros[shortcutIndex].getID(); theMacros.erase(it + shortcutIndex); fillOutBabyGrid(); // preparing to remove from menu posBase = 6; nbElem = theMacros.size(); hMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_MACRO); modifCmd = IDM_SETTING_SHORTCUT_MAPPER_MACRO; for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps { MacroShortcut ms = theMacros[i]; ms.setID(ms.getID() - 1); //shift all IDs theMacros[i] = ms; } break; } case STATE_USER: { vector<UserCommand> & theUserCmds = nppParam->getUserCommandList(); vector<UserCommand>::iterator it = theUserCmds.begin(); cmdID = theUserCmds[shortcutIndex].getID(); theUserCmds.erase(it + shortcutIndex); fillOutBabyGrid(); // preparing to remove from menu posBase = 2; nbElem = theUserCmds.size(); hMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_RUN); modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN; for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps { UserCommand uc = theUserCmds[i]; uc.setID(uc.getID() - 1); //shift all IDs theUserCmds[i] = uc; } break; } } // updateShortcuts() will update all menu item - the menu items will be shifted nppParam->getAccelerator()->updateShortcuts(); // All menu items are shifted up. So we delete the last item ::RemoveMenu(hMenu, posBase + nbElem - 1, MF_BYPOSITION); if (nbElem == 0) { ::RemoveMenu(hMenu, modifCmd, MF_BYCOMMAND); //remove separator ::RemoveMenu(hMenu, posBase-1, MF_BYPOSITION); ::RemoveMenu(hMenu, posBase-1, MF_BYPOSITION); } } return TRUE; } case IDD_BABYGRID_ID1: { if(HIWORD(wParam) == BGN_CELLDBCLICKED) //a cell was clicked in the properties grid { return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_MODIFY, LOWORD(lParam)); } else if(HIWORD(wParam) == BGN_CELLRCLICKED) //a cell was clicked in the properties grid { POINT p; ::GetCursorPos(&p); if (!_rightClickMenu.isCreated()) { vector<MenuItemUnit> itemUnitArray; itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_MODIFY, TEXT("Modify"))); itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_DELETE, TEXT("Delete"))); _rightClickMenu.create(_hSelf, itemUnitArray); } switch(_currentState) { case STATE_MACRO: case STATE_USER: { _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, true); break; } case STATE_MENU: case STATE_PLUGIN: case STATE_SCINTILLA: { _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, false); break; } } _rightClickMenu.display(p); return TRUE; } } } } default: return FALSE; } return FALSE; }
BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG : { initTabs(); initList(); populateShortCuts(); goToCenter(); GetWindowRect(_hSelf,&default_sm_size); AnchorInit(_hSelf,ShortcutAnchors,sizeof(ShortcutAnchors)/sizeof(CONTROL_ANCHOR)); RestoreWinRelPosition(_hParent,_hSelf,&WinRelPos); return TRUE; } case WM_DESTROY: SaveWinRelPosition(_hParent,_hSelf,&WinRelPos); break; case WM_SIZE: AnchorResize(_hSelf,ShortcutAnchors,sizeof(ShortcutAnchors)/sizeof(CONTROL_ANCHOR)); break; case WM_SIZING: return ClampMinWindowSize(&default_sm_size,wParam,(RECT*)lParam); break; case WM_NOTIFY: { NMHDR nmh = *((NMHDR*)lParam); if (nmh.hwndFrom == _hTabCtrl) { if (nmh.code == TCN_SELCHANGE) { int index = TabCtrl_GetCurSel(_hTabCtrl); switch (index) { case 0: _currentState = STATE_MENU; break; case 1: _currentState = STATE_MACRO; break; case 2: _currentState = STATE_USER; break; case 3: _currentState = STATE_PLUGIN; break; case 4: _currentState = STATE_SCINTILLA; break; } populateShortCuts(); } } else if(nmh.hwndFrom==hlistview){ switch(nmh.code){ case NM_DBLCLK: return ::SendMessage(_hSelf, WM_COMMAND, IDC_SHORTCUT_MODIFY, LOWORD(lParam)); case NM_RCLICK: { POINT p; ::GetCursorPos(&p); if (!_rightClickMenu.isCreated()) { vector<MenuItemUnit> itemUnitArray; itemUnitArray.push_back(MenuItemUnit(IDC_SHORTCUT_MODIFY, TEXT("Modify"))); itemUnitArray.push_back(MenuItemUnit(IDC_SHORTCUT_DISABLE, TEXT("Disable"))); itemUnitArray.push_back(MenuItemUnit(0, 0)); itemUnitArray.push_back(MenuItemUnit(IDC_SHORTCUT_DELETE, TEXT("Delete"))); _rightClickMenu.create(_hSelf, itemUnitArray); } switch(_currentState) { case STATE_MACRO: case STATE_USER: { _rightClickMenu.enableItem(IDC_SHORTCUT_DELETE, true); break; } case STATE_MENU: case STATE_PLUGIN: case STATE_SCINTILLA: { _rightClickMenu.enableItem(IDC_SHORTCUT_DELETE, false); break; } } _rightClickMenu.display(p); return TRUE; } } } break; } case WM_COMMAND : { switch (LOWORD(wParam)) { case IDCANCEL : { ::EndDialog(_hSelf, -1); return TRUE; } case IDOK : { if(GetFocus()==hlistview) return ::SendMessage(_hSelf, WM_COMMAND, IDC_SHORTCUT_MODIFY, LOWORD(lParam)); else ::EndDialog(_hSelf, 0); return TRUE; } case IDC_SHORTCUT_FILTER2: case IDC_SHORTCUT_FILTER1: if(HIWORD(wParam)==EN_CHANGE) populateShortCuts(); break; case IDC_SHORTCUT_DISABLE: { int sel=0; sel=disable_selected(FALSE); if(sel!=0){ if(IDOK==MessageBox(_hSelf,TEXT("Ok to disable selected shortcuts?"),TEXT("Warning!"),MB_OKCANCEL|MB_SYSTEMMODAL)){ disable_selected(TRUE); populateShortCuts(); } } } break; case IDC_SHORTCUT_MODIFY : { NppParameters *nppParam = NppParameters::getInstance(); int index; int selected_row=getselectedrow(); if(selected_row<0) break; index=getitemindex(selected_row); switch(_currentState) { case STATE_MENU: { //Get CommandShortcut corresponding to index vector<CommandShortcut> & shortcuts = nppParam->getUserShortcuts(); CommandShortcut csc = shortcuts[index], prevcsc = shortcuts[index]; csc.init(_hInst, _hSelf); csc.set_shortcut_info(_currentState,index); if (csc.doDialog() != -1 && prevcsc != csc) { //shortcut was altered generic_string keys=csc.toString(); nppParam->addUserModifiedIndex(index); shortcuts[index] = csc; ListView_SetItemText(hlistview,selected_row,2,(LPWSTR)keys.c_str()); update_col_width(keys.c_str(),2); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); TCHAR str[255]; if(0<check_in_use(_currentState,index,&csc.getKeyCombo(),nppParam,str,sizeof(str)/sizeof(TCHAR))) MessageBox(_hSelf,str,L"Duplicates found",MB_OK); } break; } case STATE_MACRO: { //Get MacroShortcut corresponding to index vector<MacroShortcut> & shortcuts = nppParam->getMacroList(); MacroShortcut msc = shortcuts[index], prevmsc = shortcuts[index]; msc.init(_hInst, _hSelf); msc.set_shortcut_info(_currentState,index); if (msc.doDialog() != -1 && prevmsc != msc) { //shortcut was altered generic_string name=msc.getName(); generic_string keys=msc.toString(); shortcuts[index] = msc; ListView_SetItemText(hlistview,selected_row,1,(LPWSTR)name.c_str()); ListView_SetItemText(hlistview,selected_row,2,(LPWSTR)keys.c_str()); update_col_width(keys.c_str(),2); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); TCHAR str[255]; if(0<check_in_use(_currentState,index,&msc.getKeyCombo(),nppParam,str,sizeof(str)/sizeof(TCHAR))) MessageBox(_hSelf,str,L"Duplicates found",MB_OK); } break; } case STATE_USER: { //Get UserCommand corresponding to index vector<UserCommand> & shortcuts = nppParam->getUserCommandList(); UserCommand ucmd = shortcuts[index], prevucmd = shortcuts[index]; ucmd.init(_hInst, _hSelf); ucmd.set_shortcut_info(_currentState,index); prevucmd = ucmd; if (ucmd.doDialog() != -1 && prevucmd != ucmd) { //shortcut was altered generic_string name=ucmd.getName(); generic_string keys=ucmd.toString(); shortcuts[index] = ucmd; ListView_SetItemText(hlistview,selected_row,1,(LPWSTR)name.c_str()); ListView_SetItemText(hlistview,selected_row,2,(LPWSTR)keys.c_str()); update_col_width(name.c_str(),1); update_col_width(keys.c_str(),2); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); TCHAR str[255]; if(0<check_in_use(_currentState,index,&ucmd.getKeyCombo(),nppParam,str,sizeof(str)/sizeof(TCHAR))) MessageBox(_hSelf,str,L"Duplicates found",MB_OK); } break; } case STATE_PLUGIN: { //Get PluginCmdShortcut corresponding to index vector<PluginCmdShortcut> & shortcuts = nppParam->getPluginCommandList(); if(shortcuts.empty()) break; PluginCmdShortcut pcsc = shortcuts[index], prevpcsc = shortcuts[index]; pcsc.init(_hInst, _hSelf); pcsc.set_shortcut_info(_currentState,index); prevpcsc = pcsc; if (pcsc.doDialog() != -1 && prevpcsc != pcsc) { //shortcut was altered nppParam->addPluginModifiedIndex(index); generic_string keys=pcsc.toString(); shortcuts[index] = pcsc; ListView_SetItemText(hlistview,selected_row,2,(LPWSTR)keys.c_str()); update_col_width(keys.c_str(),2); //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); TCHAR str[255]; if(0<check_in_use(_currentState,index,&pcsc.getKeyCombo(),nppParam,str,sizeof(str)/sizeof(TCHAR))) MessageBox(_hSelf,str,L"Duplicates found",MB_OK); unsigned long cmdID = pcsc.getID(); ShortcutKey shortcut; shortcut._isAlt = pcsc.getKeyCombo()._isAlt; shortcut._isCtrl = pcsc.getKeyCombo()._isCtrl; shortcut._isShift = pcsc.getKeyCombo()._isShift; shortcut._key = pcsc.getKeyCombo()._key; ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, (LPARAM)&shortcut); } break; } case STATE_SCINTILLA: { //Get ScintillaKeyMap corresponding to index vector<ScintillaKeyMap> & shortcuts = nppParam->getScintillaKeyList(); ScintillaKeyMap skm = shortcuts[index], prevskm = shortcuts[index]; skm.init(_hInst, _hSelf); skm.set_shortcut_info(_currentState,index); if (skm.doDialog() != -1 && prevskm != skm) { //shortcut was altered nppParam->addScintillaModifiedIndex(index); shortcuts[index] = skm; int i,max; TCHAR str[40]={0}; max=skm.getSize(); for(i=0;i<max;i++){ generic_string keys=skm.toString(i); _sntprintf_s(str,sizeof(str)/sizeof(TCHAR),_TRUNCATE,L"%s%s%c",str,keys.c_str(),i<(max-1)?L';':L''); } ListView_SetItemText(hlistview,selected_row,2,(LPWSTR)str); update_col_width(str,2); if(max>0){ TCHAR str[255]; KeyCombo skmkc=skm.getKeyComboByIndex(0); if(0<check_in_use(_currentState,index,&skmkc,nppParam,str,sizeof(str)/sizeof(TCHAR))) MessageBox(_hSelf,str,L"Duplicates found",MB_OK); } //Notify current Accelerator class to update key nppParam->getScintillaAccelerator()->updateKeys(); } break; } } return TRUE; } case IDC_SHORTCUT_DELETE : { NppParameters *nppParam = NppParameters::getInstance(); int index,selected_row=getselectedrow(); TCHAR str[255]={0},msg[255]={0}; if(selected_row<0) break; index=getitemindex(selected_row); ListView_GetItemText(hlistview,selected_row,1,str,sizeof(str)/sizeof(TCHAR)); _sntprintf_s(msg,sizeof(msg)/sizeof(TCHAR),_TRUNCATE, TEXT("%s\r\n%s"), TEXT("Are you sure you want to delete this shortcut?"), str); if (::MessageBox(_hSelf, msg, TEXT("Are you sure?"), MB_OKCANCEL) == IDOK) { int shortcutIndex = index; DWORD cmdID = 0; // Menu data size_t posBase = 0; size_t nbElem = 0; HMENU hMenu = NULL; int modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN; switch(_currentState) { case STATE_MENU: case STATE_PLUGIN: case STATE_SCINTILLA: { return FALSE; //this is bad } case STATE_MACRO: { vector<MacroShortcut> & theMacros = nppParam->getMacroList(); vector<MacroShortcut>::iterator it = theMacros.begin(); cmdID = theMacros[shortcutIndex].getID(); theMacros.erase(it + shortcutIndex); populateShortCuts(); // preparing to remove from menu posBase = 6; nbElem = theMacros.size(); hMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_MACRO); modifCmd = IDM_SETTING_SHORTCUT_MAPPER_MACRO; for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps { MacroShortcut ms = theMacros[i]; ms.setID(ms.getID() - 1); //shift all IDs theMacros[i] = ms; } break; } case STATE_USER: { vector<UserCommand> & theUserCmds = nppParam->getUserCommandList(); vector<UserCommand>::iterator it = theUserCmds.begin(); cmdID = theUserCmds[shortcutIndex].getID(); theUserCmds.erase(it + shortcutIndex); populateShortCuts(); // preparing to remove from menu posBase = 2; nbElem = theUserCmds.size(); hMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_RUN); modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN; for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps { UserCommand uc = theUserCmds[i]; uc.setID(uc.getID() - 1); //shift all IDs theUserCmds[i] = uc; } break; } } // updateShortcuts() will update all menu item - the menu items will be shifted nppParam->getAccelerator()->updateShortcuts(); // All menu items are shifted up. So we delete the last item ::RemoveMenu(hMenu, posBase + nbElem, MF_BYPOSITION); if (nbElem == 0) { ::RemoveMenu(hMenu, modifCmd, MF_BYCOMMAND); //remove separator ::RemoveMenu(hMenu, posBase-1, MF_BYPOSITION); ::RemoveMenu(hMenu, posBase-1, MF_BYPOSITION); } } return TRUE; } } } default: return FALSE; } return FALSE; }