static void OnLibraryEdit(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); bool oldSortAlphabetic = s_curLibrary->GetSortAlphabetic(); if (ShowEditLibraryDlg(s_curLibrary)) { /* bool newSortAlphabetic = s_curLibrary->GetSortAlphabetic(); if (oldSortAlphabetic != newSortAlphabetic) { if (OpenDB()) { if (newSortAlphabetic) { //RunSQL("UPDATE Snippets SET Sort = NULL WHERE LibraryID = %d"); } else { //"SELECT SnippetID, Sort FROM Snippets WHERE LibraryID = %d ORDER BY Name, Sort" i = 1; //UPDATE Snippets SET Sort = %d WHERE SnippetID = %d } } } */ UpdateSnippetsList(); } }
static void OnSnippetAddClipboard(HWND hWnd) { if (!OpenClipboard(hWnd)) return; // Get the content of the clipboard HANDLE hData = GetClipboardData(CF_UNICODETEXT); WCHAR* buffer = (WCHAR*) GlobalLock(hData); if (buffer != NULL) { // Create the new snippet and init some required members Snippet* snip = new Snippet(); snip->SetLibraryID(s_curLibrary->GetLibraryID()); snip->SetSort(GetMaxSort() + 1); snip->WSetBeforeSelection(buffer); snip->GuessName(); // Let the user edit the new snippet bool closedOK = ShowEditSnippetDlg(snip); // We don't need the object anymore, it was stored in the database if OK was pressed delete snip; // If the users pressed OK, refresh everything from the database if (closedOK) UpdateSnippetsList(); } GlobalUnlock(hData); CloseClipboard(); }
static void OnSnippetAddSelection(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); // Get the text in current selection int selsize = (int) SendMsg(SCI_GETSELECTIONEND) - (int) SendMsg(SCI_GETSELECTIONSTART); if (selsize == 0) { MsgBox("No selection found"); return; } char* pszText = new char[selsize + 2]; SendMsg(SCI_GETSELTEXT, 0, (LPARAM) pszText); // Create the new snippet and init some required members Snippet* snip = new Snippet(); snip->SetLibraryID(s_curLibrary->GetLibraryID()); snip->SetSort(GetMaxSort() + 1); snip->SetBeforeSelection(pszText); snip->GuessName(); delete [] pszText; // Let the user edit the new snippet bool closedOK = ShowEditSnippetDlg(snip); // We don't need the object anymore, it was stored in the database if OK was pressed delete snip; // If the users pressed OK, refresh everything from the database if (closedOK) UpdateSnippetsList(); }
static void OnSnippetDuplicate(HWND hWnd) { // Get the current item and its snippet int item = (int) SendDlgItemMessage(hWnd, IDC_LIST, LB_GETCURSEL, 0, 0L); // Was there an item selected? if (item == LB_ERR) return; // Get the data for this item Snippet* snip = (Snippet*) SendDlgItemMessage(s_hDlg, IDC_LIST, LB_GETITEMDATA, (WPARAM) item, 0); if (snip == NULL) return; WCHAR wszTmp[MAX_PATH]; wcsncpy(wszTmp, L"Are you sure you want to duplicate the snippet:\r\n", MAX_PATH); wcsncat(wszTmp, snip->WGetName(), MAX_PATH); // Ask for confirmation if (!MsgBoxYesNo(wszTmp)) return; // Make a copy of the selected snippet Snippet* pNew = new Snippet(*snip); // Adjust the name of the duplicate wcsncpy(wszTmp, snip->WGetName(), MAX_PATH); wcsncat(wszTmp, L" - Dup", MAX_PATH); pNew->WSetName(wszTmp); // Save to the database and refresh the list pNew->SaveToDB(); UpdateSnippetsList(); }
static void OnLibraryImport(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); // Init for GetOpenFileName() WCHAR szFile[_MAX_PATH]; // buffer for file name szFile[0] = 0; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = g_nppData._nppHandle; ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; ofn.lpstrFilter = L"SQLite databases (*.sqlite)\0*.sqlite\0All Files (*.*)\0*.*\0\0"; ofn.nMaxFile = _MAX_PATH; ofn.lpstrFile = szFile; // Ask for the filename if (GetOpenFileName(&ofn)) { if (ImportLibraryDlg(ofn.lpstrFile)) { // Fill the snippets again UpdateSnippetsList(); } } }
static void OnLibraryLanguages(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); // Check if we have a version of Notepad++ that supports NPPM_GETLANGUAGENAME if (!g_HasLangMsgs) { MsgBox("Editing the languages requires at least version 5.93 of Notepad++"); return; } if (ShowEditLanguagesDlg(s_curLibrary)) UpdateSnippetsList(); }
static void OnLibraryDelete(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); WCHAR wszTmp[MAX_PATH]; wcsncpy(wszTmp, L"Are you sure you want to delete the library:\r\n", MAX_PATH); wcsncat(wszTmp, s_curLibrary->WGetName(), MAX_PATH); // Ask for confirmation if (!MsgBoxYesNo(wszTmp)) return; // Delete from the database if (!s_curLibrary->DeleteFromDB()) return; // Fill the snippets again UpdateSnippetsList(); }
static void OnSnippetAdd(HWND hWnd) { UNREFERENCED_PARAMETER(hWnd); // Create the new snippet and init some required members Snippet* snip = new Snippet(); snip->SetLibraryID(s_curLibrary->GetLibraryID()); snip->SetSort(GetMaxSort() + 1); // Let the user edit the new snippet bool closedOK = ShowEditSnippetDlg(snip); // We don't need the object anymore, it was stored in the database if OK was pressed delete snip; // If the users pressed OK, refresh everything from the database if (closedOK) UpdateSnippetsList(); }
void SnippetsConsole() { if (s_bConsoleVisible) { // Hide the window and uncheck the menu item SendMessage(g_nppData._nppHandle, NPPM_DMMHIDE, 0, (LPARAM) s_hDlg); SendMessage(g_nppData._nppHandle, NPPM_SETMENUITEMCHECK, (WPARAM) g_funcItem[0]._cmdID, (LPARAM) FALSE); // The console is not visible anymore s_bConsoleVisible = false; } else { // The console window will become visible. // Set it now already so other routines work properly s_bConsoleVisible = true; if (!s_bConsoleInitialized) { // Get the right database filename if (!GetDatabaseFile()) { MsgBox("Unable to find the database, check your installation!"); return; } // Check if we have a version of Notepad++ that supports NPPM_GETLANGUAGENAME DWORD ver = (DWORD) SendMessage(g_nppData._nppHandle, NPPM_GETNPPVERSION, (WPARAM) 0, (LPARAM) 0); g_HasLangMsgs = (ver >= MAKELONG(93, 5)); // Load the icon s_hTabIcon = (HICON) LoadImage(g_hInst, MAKEINTRESOURCE(IDI_SNIPPETS), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_COLOR | LR_LOADTRANSPARENT); // Initialize everything for the console window tTbData tbd; ZeroMemory(&tbd, sizeof(tTbData)); tbd.dlgID = -1; // Nr of menu item to assign (!= _cmdID, beware) tbd.pszModuleName = L"Snippets"; // name of the dll this dialog belongs to tbd.pszName = L"Snippets"; // Name for titlebar tbd.hClient = s_hDlg; // HWND Handle of window this dock belongs to tbd.uMask = DWS_DF_CONT_RIGHT | DWS_ICONTAB; // Put it on the right tbd.hIconTab = s_hTabIcon; // Put the icon in SendMessage(g_nppData._nppHandle, NPPM_DMMREGASDCKDLG, 0, (LPARAM) &tbd); // Register it // It should initialize now s_bConsoleInitialized = true; } // Put the items in the combo and the list UpdateSnippetsList(); // Show the window and check the menu item SendMessage(g_nppData._nppHandle, NPPM_DMMSHOW, 0, (LPARAM) s_hDlg); SendMessage(g_nppData._nppHandle, NPPM_SETMENUITEMCHECK, (WPARAM) g_funcItem[0]._cmdID, (LPARAM) TRUE); // Set the focus back on the main window SetFocusOnEditor(); } // Store the visiblity in the options g_Options->showConsoleDlg = s_bConsoleVisible; }
extern "C" __declspec(dllexport) void beNotified(SCNotification* notifyCode) { switch (notifyCode->nmhdr.code) { case NPPN_READY: { // Initialize the database g_db = new SnippetsDB(); if (g_Options->showConsoleDlg) SnippetsConsole(); // Check if we are running a newer version Version curVer, prevVer(g_Options->GetPrevVersion()); if (curVer > prevVer) g_Options->Write(); break; } case NPPN_SHUTDOWN: { break; } case NPPN_TBMODIFICATION: { // First initialize the options g_Options = new Options(); // Do we need to load the toolbar icon? if (g_Options->toolbarIcon) { // Add the button to the toolbar toolbarIcons tbiFolder; hbmpToolbar = CreateMappedBitmap(g_hInst, IDB_SNIPPETS, 0, 0, 0); tbiFolder.hToolbarBmp = hbmpToolbar; tbiFolder.hToolbarIcon = NULL; SendMessage((HWND) notifyCode->nmhdr.hwndFrom, NPPM_ADDTOOLBARICON, (WPARAM) g_funcItem[0]._cmdID, (LPARAM) &tbiFolder); } break; } case NPPN_LANGCHANGED: case NPPN_BUFFERACTIVATED: { LangType lang; SendMessage(g_nppData._nppHandle, NPPM_GETCURRENTLANGTYPE, 0, (LPARAM) &lang); if (g_currentLang != lang) { g_currentLang = lang; UpdateSnippetsList(); } break; } case NPPN_WORDSTYLESUPDATED: { InvalidateListbox(); break; } } }