CONTEXTE : jN Npp Plugin jN (JavaScript for Notepad++) allows you to extend Notepad++ by…
- User
CONTEXTE : jN Npp Plugin jN (JavaScript for Notepad++) allows you to extend Notepad++ by using JavaScript. jN uses the built-in javascript engine of Microsoft Windows. This powerful engine allows to access a lot of ActiveX base services like Shell, WMI of operating system. Due to automate Notepad++ jN wraps the Notepad++ API into ActiveX interfaces accessible via global objects Editor and System.
=-=-=-=-=-=-=
J'ai actuellement le code suivant dans un fichier dans "Editor.cpp"
❨ #include "Editor.h" #include "common\System.h" #include "DockableDialog.h" #define SUBCLASSING TEXT("jN.Npp.Subclassing") const TCHAR* langs[] ={TEXT("TXT"), /* bla bla bla / , TEXT("EXTERNAL")}; CEditor::~CEditor(void){ // Release Views for(int i=0; i<m_ViewsNumber; i++){ m_Views[i]->Release(); } // Release Scripting elements if (m_Listener){ delete m_Listener; m_Listener = NULL; } // Restore WndProc WNDPROC oldWndProc = (WNDPROC)GetProp(m_NppHandle, SUBCLASSING); SetWindowLongPtr(m_NppHandle, GWLP_WNDPROC, (LPARAM)oldWndProc); AcceleratorHook::getInstance()->remove(&m_Accelerators); } int CEditor::GetCurrentView(){ int currentEdit; NPPM(GETCURRENTSCINTILLA,0,¤tEdit); return currentEdit; } int CEditor::GetMenuItemPosition(HANDLE hMenu, TCHAR text) { /* bla bla bla / } // 1.) because NPP use lets IDs for menu items // and we can not get new IDs for our dynamic menu items. To solve // this problem we switch menu message handling from WM_COMMAND to WM_MENUCOMMAND // see 2.) and 3.) LRESULT CALLBACK CEditor::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ if (message == WM_MENUCOMMAND){ CMenuItem mItem = CMenuItem::GetInstance((HMENU)lParam, wParam); if (mItem){ // here we have our menu item mItem->call(); }else{ // we have menu items from NPP // simulate WM_COMMAND, NPP handles his menu items self MENUITEMINFO mii; mii.cbSize = sizeof(mii); mii.fMask = MIIM_ID | MIIM_DATA; // 2.) WM_MENUCOMMAND + submenu handle and item position help us to // get MenuItemInfo without using of menu item ID BOOL res = GetMenuItemInfo((HMENU)lParam, wParam, TRUE, &mii); if (res) ::SendMessage(hwnd, WM_COMMAND,mii.wID,0); } } else if (message == WM_INITMENUPOPUP){ CMenu* menu = CMenu::GetInstance((HMENU)wParam); if (menu){ menu->oninitpopup(); return NULL; } } WNDPROC oldWndProc = (WNDPROC)GetProp(hwnd, SUBCLASSING); return CallWindowProc(oldWndProc, hwnd, message, wParam, lParam); } CEditor::CEditor(HWND nppHandle):CComDispatch(),m_Accelerators(nppHandle){ AcceleratorHook::getInstance()->add(&m_Accelerators); // 3.) set our wndproc to have WM_MENUCOMMAND instead WM_COMMAND // see 1.) and 2.) m_NppHandle = nppHandle; WNDPROC oldWndProc = (WNDPROC)SetWindowLongPtr(nppHandle, GWLP_WNDPROC, (LPARAM)CEditor::WndProc); SetProp(m_NppHandle, SUBCLASSING, oldWndProc); m_Listener = NULL; // get main menu handle m_mainMenu = (HMENU)NPPM(GETMENUHANDLE,1,0); if (!m_mainMenu){ VARIANT_BOOL hidden; get_menuHidden(&hidden); if (!hidden){ m_mainMenu = GetMenu(nppData._nppHandle); }else{ put_menuHidden(VARIANT_FALSE); m_mainMenu = GetMenu(nppData._nppHandle); put_menuHidden(VARIANT_TRUE); } } // create views for(int i=0; i<m_ViewsNumber; i++){ m_Views[i] = new CEditorView(i+1); } MENUINFO mi; memset(&mi, 0, sizeof(mi)); mi.cbSize = sizeof(mi); mi.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS; mi.dwStyle = MNS_NOTIFYBYPOS; BOOL res = SetMenuInfo( m_mainMenu, &mi); } void CEditor::getViewAndPosFrom(SCNotification* eventArgs, int* view, int* pos){ /* bla bla bla eventArgs){ int r = 0; // provide messages to current view int view = GetCurrentView(); // can be -1 what is not valid if (view >= 0 && view < m_ViewsNumber){ m_Views[view]->DoMessage(eventArgs); } if (m_Listener==NULL) return ; TCHAR* method1 = NULL; TCHAR* method2 = NULL; switch(eventArgs->nmhdr.code){ case SCN_MODIFYATTEMPTRO: method2 = TEXT("MODIFYATTEMPTRO"); break; case NPPN_SHUTDOWN:{ method1 = TEXT("SHUTDOWN"); break; } case NPPN_FILECLOSED:{ method1 = TEXT("FILECLOSED"); break; } case NPPN_READONLYCHANGED:{ method2 = TEXT("READONLYCHANGED"); break; } case NPPN_LANGCHANGED:{ method2 = TEXT("LANGCHANGED"); break; } } if (method1){ CallListener(method1); }else if(method2){ int view, pos; getViewAndPosFrom(eventArgs, &view, &pos); CallListener(method2, view, pos); } } void CEditor::CallListener(TCHAR* method, int view, int file){ if (m_Listener == NULL) return; if (view >= 0 && view < m_ViewsNumber){ VARIANT var[2]; var[0].vt = VT_DISPATCH; var[0].pdispVal = m_Views[view]; var[1].vt = VT_INT; var[1].intVal = file; m_Listener->callMethod(method, var, 2); }else{ m_Listener->callMethod(method); } } HRESULT STDMETHODCALLTYPE CEditor::get_firstView( IView **result){ *result = m_Views[0]; ( HRESULT STDMETHODCALLTYPE CEditor::get_currentView( IView **result){ // bla bla bla HRESULT STDMETHODCALLTYPE CEditor::get_secondView( IView d = new DockableDialog(MyActiveSite::getInstance()->WrapScriptObj(cfg), nppData._nppHandle); d->Init(); d->AddRef(); *result = d; NPPM(MODELESSDIALOG,MODELESSDIALOGADD,d->hwnd()); return S_OK; } HRESULT STDMETHODCALLTYPE CEditor::get_handle(int *result){ *result = (int)m_NppHandle; return S_OK; }
- Assistant
Pour pouvoir fermer un dock créé avec la fonction "Editor.createDockable(options)", vous devez ajouter une nouvelle fonction dans la classe "CEditor" dans le fichier "Editor.cpp". Voici un exemple de fonction "closeDock" que vous pouvez ajouter :
void CEditor::CloseDock(IDispatch* dock) { DockableDialog* dockableDialog = dynamic_cast<DockableDialog*>(getIndex(dock)); if (dockableDialog) { m_Dialogs.remove((DWORD)dockableDialog); LRESULT config = SendMessage(nppData._nppHandle, NPPM_DMMSHOW, FALSE, (LPARAM)dockableDialog->hwnd()); Console::getInstance()->print(config == TRUE ? TEXT("Dock closed: true") : TEXT("Dock closed: false")); } else { Console::getInstance()->print(TEXT("DockableDialog not found.")); } }Cette fonction prend un objet "IDispatch*" en paramètre, qui représente le dock que vous souhaitez fermer. Ensuite, elle recherche ce dock dans la liste des dialogues ouverts ("m_Dialogs") et le supprime de cette liste. Enfin, elle envoie un message à Notepad++ pour cacher le dock ("NPPM_DMMSHOW") et affiche un message de confirmation lorsque l'opération est terminée.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.