├── .editorconfig ├── .github ├── dependabot.yml └── workflows │ ├── mingw-build.yml │ └── msbuild.yml ├── .gitignore ├── DlgAbout.cpp ├── DlgAbout.h ├── DlgConsole.cpp ├── DlgConsole.h ├── DlgEditLanguages.cpp ├── DlgEditLanguages.h ├── DlgEditLibrary.cpp ├── DlgEditLibrary.h ├── DlgEditSnippet.cpp ├── DlgEditSnippet.h ├── DlgImportLibrary.cpp ├── DlgImportLibrary.h ├── DlgOptions.cpp ├── DlgOptions.h ├── LICENSE.md ├── Language.cpp ├── Language.h ├── Library.cpp ├── Library.h ├── Makefile ├── NPP ├── Docking.h ├── Notepad_plus_msgs.h ├── Parameters.h ├── PluginInterface.h ├── Sci_Position.h ├── Scintilla.h ├── dockingResource.h ├── menuCmdID.h └── no_ms_shit.props ├── NppOptions.cpp ├── NppOptions.h ├── NppSnippets.cpp ├── NppSnippets.h ├── NppSnippets.sln ├── NppSnippets.vcxproj ├── NppSnippets.vcxproj.filters ├── NppSnippets_res.rc ├── Options.cpp ├── Options.h ├── README.md ├── Res ├── MainToolbar_Snippets.bmp └── Snippets.ico ├── Resource.h ├── Snippets.cpp ├── Snippets.h ├── SnippetsDB.cpp ├── SnippetsDB.h ├── SqliteDB.cpp ├── SqliteDB.h ├── WaitCursor.cpp ├── WaitCursor.h ├── docs ├── .editorconfig ├── Dockerfile ├── Makefile ├── changelog.rst ├── compile.rst ├── conf.py ├── contact.rst ├── database.rst ├── faq.rst ├── gpl-2.rst ├── images │ ├── context-menu-library.png │ ├── context-menu-snippet.png │ ├── edit-snippet.png │ └── main.png ├── index.rst ├── installation.rst ├── introduction.rst ├── known-issues.rst ├── libraries.rst ├── license.rst ├── options.rst ├── requirements.txt ├── usage.rst └── wishlist.rst ├── misc ├── Languages.sql ├── NppSnippets.sql └── Template.sqlite ├── sqlite3.c ├── sqlite3.h ├── version_git.bat └── version_git.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig for main source directory 2 | 3 | root = true 4 | 5 | [*] 6 | end_of_line = crlf 7 | indent_size = 4 8 | indent_style = tab 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [{*.{vcxproj,vcxproj.user,props}}] 13 | indent_size = 2 14 | indent_style = space 15 | insert_final_newline = false 16 | 17 | [*.yml] 18 | indent_size = 2 19 | indent_style = space 20 | end_of_line = lf 21 | 22 | [*.sh] 23 | end_of_line = lf 24 | 25 | [sqlite3.*] 26 | end_of_line = lf 27 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | # Maintain dependencies for GitHub Actions 9 | - package-ecosystem: "github-actions" 10 | directory: "/" 11 | schedule: 12 | interval: "weekly" 13 | -------------------------------------------------------------------------------- /.github/workflows/mingw-build.yml: -------------------------------------------------------------------------------- 1 | name: Mingw Build 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | 7 | build_linux: 8 | runs-on: ubuntu-latest 9 | strategy: 10 | max-parallel: 2 11 | matrix: 12 | build_platform: ["64", "32"] 13 | 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | 20 | - name: Install packages via apt 21 | run: | 22 | sudo apt-get -qq update 23 | sudo apt-get -qq install -y mingw-w64 cppcheck 24 | (for alt in i686-w64-mingw32-g++ i686-w64-mingw32-gcc x86_64-w64-mingw32-g++ x86_64-w64-mingw32-gcc; do sudo update-alternatives --set $alt /usr/bin/$alt-posix; done); 25 | 26 | - name: build x86 27 | if: matrix.build_platform == '32' 28 | run: make ARCH=i686-w64-mingw32 29 | 30 | - name: build x64 31 | if: matrix.build_platform == '64' 32 | run: make ARCH=x86_64-w64-mingw32 33 | 34 | - name: Archive artifacts for x86 35 | if: matrix.build_platform == '32' 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: nppsnippets_dll_linux_x32 39 | path: NppSnippets.dll 40 | 41 | - name: Archive artifacts for x64 42 | if: matrix.build_platform == '64' 43 | uses: actions/upload-artifact@v4 44 | with: 45 | name: nppsnippets_dll_linux_x64 46 | path: NppSnippets.dll 47 | 48 | -------------------------------------------------------------------------------- /.github/workflows/msbuild.yml: -------------------------------------------------------------------------------- 1 | name: MSBuild 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | 7 | build_windows: 8 | runs-on: windows-latest 9 | strategy: 10 | max-parallel: 3 11 | matrix: 12 | build_configuration: [ Release ] 13 | build_platform: [ x64, Win32, ARM64 ] 14 | steps: 15 | - name: Checkout repository 16 | uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 19 | 20 | - name: Add MSBuild to PATH 21 | uses: microsoft/setup-msbuild@v2 22 | 23 | - name: Show MSBuild version 24 | run: msbuild -version 25 | 26 | - name: Run MSBuild 27 | run: msbuild NppSnippets.vcxproj /m /p:configuration="${{ matrix.build_configuration }}" /p:platform="${{ matrix.build_platform }}" 28 | 29 | - name: Archive artifacts for x64 30 | if: matrix.build_platform == 'x64' 31 | uses: actions/upload-artifact@v4 32 | with: 33 | name: nppsnippets_dll_x64 34 | path: ${{ matrix.build_platform }}/${{ matrix.build_configuration }}/NppSnippets.dll 35 | 36 | - name: Archive artifacts for x32 37 | if: matrix.build_platform == 'Win32' 38 | uses: actions/upload-artifact@v4 39 | with: 40 | name: nppsnippets_dll_x32 41 | path: ${{ matrix.build_platform }}/${{ matrix.build_configuration }}/NppSnippets.dll 42 | 43 | - name: Archive artifacts for ARM64 44 | if: matrix.build_platform == 'ARM64' 45 | uses: actions/upload-artifact@v4 46 | with: 47 | name: nppsnippets_dll_arm64 48 | path: ${{ matrix.build_platform }}/${{ matrix.build_configuration }}/NppSnippets.dll 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | _build/ 3 | ARM64/ 4 | Win32/ 5 | x64/ 6 | *.d 7 | *.o 8 | *.user 9 | NppSnippets.dll 10 | version_git.h 11 | -------------------------------------------------------------------------------- /DlgAbout.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2017 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "NPP/PluginInterface.h" 27 | #include "NppSnippets.h" 28 | #include "Resource.h" 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | // 32 | 33 | static BOOL OnInitDialog(HWND hDlg) 34 | { 35 | CenterWindow(hDlg); 36 | return TRUE; 37 | } 38 | 39 | ///////////////////////////////////////////////////////////////////////////// 40 | // 41 | 42 | static BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 43 | { 44 | UNREFERENCED_PARAMETER(lParam); 45 | 46 | switch(message) 47 | { 48 | case WM_INITDIALOG: 49 | { 50 | return OnInitDialog(hDlg); 51 | } 52 | case WM_NOTIFY: 53 | { 54 | switch (((LPNMHDR)lParam)->code) 55 | { 56 | case NM_CLICK: 57 | case NM_RETURN: 58 | { 59 | PNMLINK pNMLink = (PNMLINK) lParam; 60 | LITEM item = pNMLink->item; 61 | ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW); 62 | } 63 | } 64 | return FALSE; 65 | } 66 | case WM_COMMAND: 67 | { 68 | switch(LOWORD(wParam)) 69 | { 70 | case IDCANCEL: 71 | { 72 | EndDialog(hDlg, 0); 73 | return TRUE; 74 | } 75 | } 76 | return FALSE; 77 | } 78 | } 79 | return FALSE; 80 | } 81 | 82 | ///////////////////////////////////////////////////////////////////////////// 83 | // Show the About Dialog, with all version information 84 | 85 | void ShowAboutDlg() 86 | { 87 | DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), g_nppData._nppHandle, (DLGPROC) DlgProc); 88 | } 89 | -------------------------------------------------------------------------------- /DlgAbout.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern void ShowAboutDlg(); 25 | -------------------------------------------------------------------------------- /DlgConsole.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2020 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern void SnippetsConsole(); 25 | extern void CreateConsoleDlg(); 26 | extern void UpdateSnippetsList(); 27 | extern void InvalidateListbox(); 28 | extern void FocusLibraryCombo(); 29 | extern void FocusFilterSnippets(); 30 | extern void FocusSnippetsList(); 31 | -------------------------------------------------------------------------------- /DlgEditLanguages.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include 25 | #include "NPP/PluginInterface.h" 26 | #include "NppSnippets.h" 27 | #include "Library.h" 28 | #include "Language.h" 29 | #include "Resource.h" 30 | #include "WaitCursor.h" 31 | #include "SnippetsDB.h" 32 | 33 | #ifdef _MSC_VER 34 | #pragma comment(lib, "comctl32.lib") 35 | #endif 36 | 37 | static Library* s_pLibrary = NULL; 38 | static HWND s_hWndLangList = NULL; 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | // 42 | 43 | static bool Validate(HWND hDlg) 44 | { 45 | UNREFERENCED_PARAMETER(hDlg); 46 | 47 | // Go through the listview items and collect the required data 48 | bool negative = false; 49 | int checked = 0, count = ListView_GetItemCount(s_hWndLangList); 50 | for (int i = 0; i < count; i++) 51 | { 52 | if (ListView_GetCheckState(s_hWndLangList, i)) 53 | { 54 | checked++; 55 | 56 | // Check if the language-ID is negative 57 | LVITEM lvitem; 58 | ZeroMemory(&lvitem, sizeof(LVITEM)); 59 | lvitem.mask = LVIF_PARAM; 60 | lvitem.iItem = i; 61 | ListView_GetItem(s_hWndLangList, &lvitem); 62 | Language* lang = (Language*) lvitem.lParam; 63 | if (lang != NULL) 64 | if (lang->GetLangID() < 0) 65 | negative = true; 66 | } 67 | } 68 | 69 | // Check if there is at least one language selected 70 | if (checked == 0) 71 | { 72 | MsgBox("No language selected"); 73 | return false; 74 | } 75 | 76 | // If there is a negative language selected, make sure only one language is selected 77 | if (negative && checked > 1) 78 | { 79 | MsgBox("A general language has been choosen,\r\nbut there is more then one language selected."); 80 | return false; 81 | } 82 | 83 | return true; 84 | } 85 | 86 | ///////////////////////////////////////////////////////////////////////////// 87 | // 88 | 89 | static void CleanItems(HWND hDlg) 90 | { 91 | UNREFERENCED_PARAMETER(hDlg); 92 | 93 | int count = ListView_GetItemCount(s_hWndLangList); 94 | for (int i = 0; i < count; i++) 95 | { 96 | LVITEM lvitem; 97 | ZeroMemory(&lvitem, sizeof(LVITEM)); 98 | lvitem.mask = LVIF_PARAM; 99 | lvitem.iItem = i; 100 | ListView_GetItem(s_hWndLangList, &lvitem); 101 | Language* lang = (Language*) lvitem.lParam; 102 | if (lang != NULL) 103 | delete lang; 104 | } 105 | } 106 | 107 | ///////////////////////////////////////////////////////////////////////////// 108 | // 109 | 110 | static void SaveLanguages() 111 | { 112 | // First delete all the current items 113 | SqliteStatement stmt(g_db, "DELETE FROM LibraryLang WHERE LibraryID = @libid"); 114 | 115 | // Bind the language to the statement 116 | const int libid = s_pLibrary->GetLibraryID(); 117 | stmt.Bind("@libid", libid); 118 | 119 | // And save the record 120 | stmt.SaveRecord(); 121 | stmt.Finalize(); 122 | 123 | // Now add records for all selected languages 124 | stmt.Prepare("INSERT INTO LibraryLang(LibraryID, Lang) VALUES (@libid, @lang)"); 125 | 126 | // Go through the selected items 127 | const int count = ListView_GetItemCount(s_hWndLangList); 128 | for (int i = 0; i < count; i++) 129 | { 130 | if (ListView_GetCheckState(s_hWndLangList, i)) 131 | { 132 | // Get the Language-class from this checked item 133 | LV_ITEM lvitem; 134 | ZeroMemory(&lvitem, sizeof(LVITEM)); 135 | lvitem.mask = LVIF_PARAM; 136 | lvitem.iItem = i; 137 | ListView_GetItem(s_hWndLangList, &lvitem); 138 | Language* lang = (Language*) lvitem.lParam; 139 | if (lang != NULL) 140 | { 141 | // Bind the language-id and library-id to the statement 142 | stmt.Bind("@libid", libid); 143 | stmt.Bind("@lang", lang->GetLangID()); 144 | stmt.SaveRecord(); 145 | } 146 | } 147 | } 148 | 149 | stmt.Finalize(); 150 | } 151 | 152 | ///////////////////////////////////////////////////////////////////////////// 153 | // 154 | 155 | static BOOL OnOK(HWND hDlg) 156 | { 157 | if (!Validate(hDlg)) 158 | return TRUE; 159 | 160 | try 161 | { 162 | WaitCursor wait; 163 | 164 | // Save the changes to the database 165 | g_db->Open(); 166 | g_db->BeginTransaction(); 167 | SaveLanguages(); 168 | g_db->CommitTransaction(); 169 | g_db->Close(); 170 | } 171 | catch (SqliteException ex) 172 | { 173 | g_db->RollbackTransaction(); 174 | g_db->Close(); 175 | } 176 | 177 | // We're done 178 | CleanItems(hDlg); 179 | EndDialog(hDlg, IDOK); 180 | return TRUE; 181 | } 182 | 183 | ///////////////////////////////////////////////////////////////////////////// 184 | // 185 | 186 | static BOOL OnCancel(HWND hDlg) 187 | { 188 | CleanItems(hDlg); 189 | EndDialog(hDlg, IDCANCEL); 190 | return TRUE; 191 | } 192 | 193 | ///////////////////////////////////////////////////////////////////////////// 194 | // 195 | 196 | static bool AddItem(Language* lang) 197 | { 198 | LVITEM lvitem; 199 | ZeroMemory(&lvitem, sizeof(LVITEM)); 200 | lvitem.mask = LVIF_TEXT | LVIF_PARAM; 201 | lvitem.iItem = ListView_GetItemCount(s_hWndLangList); 202 | lvitem.lParam = (LPARAM) lang; 203 | lvitem.pszText = lang->GetLangName(); 204 | int actualItem = ListView_InsertItem(s_hWndLangList, &lvitem); 205 | 206 | // Set the text for the first subitem 207 | ZeroMemory(&lvitem, sizeof(LVITEM)); 208 | lvitem.mask = LVIF_TEXT; 209 | lvitem.iItem = actualItem; 210 | lvitem.iSubItem = 1; 211 | lvitem.pszText = lang->GetLangDescr(); 212 | ListView_SetItem(s_hWndLangList, &lvitem); 213 | 214 | return true; 215 | } 216 | 217 | ///////////////////////////////////////////////////////////////////////////// 218 | // 219 | 220 | static bool AddColumn(int col, int width, LPCWSTR name) 221 | { 222 | LVCOLUMN lvc; 223 | lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; 224 | lvc.fmt = LVCFMT_LEFT; 225 | lvc.iSubItem = col; 226 | lvc.cx = width; 227 | lvc.pszText = (LPWSTR) name; 228 | ListView_InsertColumn(s_hWndLangList, col, &lvc); 229 | return true; 230 | } 231 | 232 | ///////////////////////////////////////////////////////////////////////////// 233 | // 234 | 235 | static BOOL OnInitDialog(HWND hDlg) 236 | { 237 | // Just in case 238 | if (s_pLibrary == NULL) 239 | return TRUE; 240 | 241 | WaitCursor wait; 242 | 243 | CenterWindow(hDlg); 244 | SetWindowText(GetDlgItem(hDlg, IDC_NAME), s_pLibrary->WGetName()); 245 | s_hWndLangList = GetDlgItem(hDlg, IDC_LANG_LIST); 246 | ListView_SetExtendedListViewStyle(s_hWndLangList, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); 247 | 248 | // 249 | AddColumn(0, 95, L"Language"); 250 | AddColumn(1, 188, L"Description"); 251 | 252 | // First add the special languages to the list 253 | AddItem(new Language(-2, L"All", L"All languages")); 254 | AddItem(new Language(-1, L"No Lib for lang", L"No other library for this language")); 255 | 256 | // Then add all the normal supported languages 257 | int langid = 0; 258 | for (langid = L_TEXT; langid < L_EXTERNAL; langid++) 259 | AddItem(new Language(langid)); 260 | 261 | // Set the checkboxes for the right languages 262 | g_db->Open(); 263 | 264 | // Create a new statement 265 | SqliteStatement stmt(g_db, "SELECT Lang FROM LibraryLang WHERE LibraryID = @langid ORDER BY Lang"); 266 | 267 | // Bind the library to the statement 268 | stmt.Bind("@langid", s_pLibrary->GetLibraryID()); 269 | 270 | // Go through the records 271 | int item = 0, count = ListView_GetItemCount(s_hWndLangList); 272 | while (stmt.GetNextRecord()) 273 | { 274 | langid = stmt.GetIntColumn("Lang"); 275 | 276 | // Go through the listview items to set the checkbox 277 | for (item = 0; item < count; item++) 278 | { 279 | LVITEM lvitem; 280 | ZeroMemory(&lvitem, sizeof(LVITEM)); 281 | lvitem.mask = LVIF_PARAM; 282 | lvitem.iItem = item; 283 | ListView_GetItem(s_hWndLangList, &lvitem); 284 | Language* lang = (Language*) lvitem.lParam; 285 | if (lang != NULL) 286 | { 287 | if (lang->GetLangID() == langid) 288 | { 289 | ListView_SetCheckState(s_hWndLangList, item, TRUE); 290 | break; 291 | } 292 | } 293 | } 294 | } 295 | stmt.Finalize(); 296 | g_db->Close(); 297 | 298 | // Let windows set focus 299 | return TRUE; 300 | } 301 | 302 | ///////////////////////////////////////////////////////////////////////////// 303 | // 304 | 305 | static BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 306 | { 307 | UNREFERENCED_PARAMETER(lParam); 308 | 309 | switch(message) 310 | { 311 | case WM_INITDIALOG: 312 | { 313 | return OnInitDialog(hDlg); 314 | } 315 | case WM_COMMAND: 316 | { 317 | switch(LOWORD(wParam)) 318 | { 319 | case IDOK: 320 | return OnOK(hDlg); 321 | 322 | case IDCANCEL: 323 | return OnCancel(hDlg); 324 | } 325 | return FALSE; 326 | } 327 | } 328 | return FALSE; 329 | } 330 | 331 | ///////////////////////////////////////////////////////////////////////////// 332 | // Show the Dialog 333 | 334 | bool ShowEditLanguagesDlg(Library* pLibrary) 335 | { 336 | s_pLibrary = pLibrary; 337 | return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_EDIT_LANGUAGES), g_nppData._nppHandle, (DLGPROC) DlgProc) == IDOK; 338 | } 339 | -------------------------------------------------------------------------------- /DlgEditLanguages.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern bool ShowEditLanguagesDlg(Library*); 25 | -------------------------------------------------------------------------------- /DlgEditLibrary.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | #include "Library.h" 27 | #include "Resource.h" 28 | #include "WaitCursor.h" 29 | 30 | static Library* s_pLibrary = NULL; 31 | 32 | ///////////////////////////////////////////////////////////////////////////// 33 | // 34 | 35 | static bool Validate(HWND hDlg) 36 | { 37 | // Check required fields 38 | if (GetDlgTextLength(hDlg, IDC_NAME) == 0) 39 | { 40 | MsgBox("Name needs to be entered!"); 41 | return false; 42 | } 43 | 44 | return true; 45 | } 46 | 47 | ///////////////////////////////////////////////////////////////////////////// 48 | // 49 | 50 | static BOOL OnOK(HWND hDlg) 51 | { 52 | if (!Validate(hDlg)) 53 | return TRUE; 54 | 55 | // Get the data from the dialog 56 | using namespace std; 57 | wstring name = GetDlgText(hDlg, IDC_NAME); 58 | wstring created = GetDlgText(hDlg, IDC_CREATED_BY); 59 | wstring comments = GetDlgText(hDlg, IDC_COMMENTS); 60 | 61 | s_pLibrary->WSetName(name.c_str()); 62 | s_pLibrary->WSetCreatedBy(created.c_str()); 63 | s_pLibrary->WSetComments(comments.c_str()); 64 | s_pLibrary->SetSortAlphabetic(IsDlgButtonChecked(hDlg, IDC_SORT_ALPHABET) == BST_CHECKED); 65 | 66 | // Save the library to the database 67 | try 68 | { 69 | WaitCursor wait; 70 | s_pLibrary->SaveToDB(); 71 | } 72 | catch (SqliteException ex) 73 | { 74 | std::string msg = "Failed to save the library to the database!\n\n"; 75 | msg += ex.what(); 76 | MsgBox(msg.c_str()); 77 | } 78 | 79 | // We're done 80 | EndDialog(hDlg, IDOK); 81 | return TRUE; 82 | } 83 | 84 | ///////////////////////////////////////////////////////////////////////////// 85 | // 86 | 87 | static BOOL OnCancel(HWND hDlg) 88 | { 89 | EndDialog(hDlg, IDCANCEL); 90 | return TRUE; 91 | } 92 | 93 | ///////////////////////////////////////////////////////////////////////////// 94 | // 95 | 96 | static BOOL OnInitDialog(HWND hDlg) 97 | { 98 | if (s_pLibrary == NULL) 99 | return TRUE; 100 | 101 | CenterWindow(hDlg); 102 | 103 | SetDlgItemText(hDlg, IDC_NAME, s_pLibrary->WGetName()); 104 | SetDlgItemText(hDlg, IDC_CREATED_BY, s_pLibrary->WGetCreatedBy()); 105 | SetDlgItemText(hDlg, IDC_COMMENTS, s_pLibrary->WGetComments()); 106 | CheckDlgButton(hDlg, IDC_SORT_ALPHABET, s_pLibrary->GetSortAlphabetic() ? BST_CHECKED : BST_UNCHECKED); 107 | 108 | // Let windows set focus 109 | return TRUE; 110 | } 111 | 112 | ///////////////////////////////////////////////////////////////////////////// 113 | // 114 | 115 | static BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 116 | { 117 | UNREFERENCED_PARAMETER(lParam); 118 | 119 | switch(message) 120 | { 121 | case WM_INITDIALOG: 122 | { 123 | return OnInitDialog(hDlg); 124 | } 125 | case WM_COMMAND: 126 | { 127 | switch(LOWORD(wParam)) 128 | { 129 | case IDOK: 130 | return OnOK(hDlg); 131 | 132 | case IDCANCEL: 133 | return OnCancel(hDlg); 134 | } 135 | return FALSE; 136 | } 137 | } 138 | return FALSE; 139 | } 140 | 141 | ///////////////////////////////////////////////////////////////////////////// 142 | // Show the Dialog 143 | 144 | bool ShowEditLibraryDlg(Library* pLibrary) 145 | { 146 | s_pLibrary = pLibrary; 147 | return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_EDIT_LIBRARY), g_nppData._nppHandle, (DLGPROC) DlgProc) == IDOK; 148 | } 149 | -------------------------------------------------------------------------------- /DlgEditLibrary.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern bool ShowEditLibraryDlg(Library*); 25 | -------------------------------------------------------------------------------- /DlgEditSnippet.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | #include "Snippets.h" 27 | #include "Language.h" 28 | #include "Resource.h" 29 | #include "WaitCursor.h" 30 | 31 | static Snippet* s_pSnippet = NULL; 32 | 33 | ///////////////////////////////////////////////////////////////////////////// 34 | // 35 | 36 | static void CleanItems(HWND hDlg) 37 | { 38 | // Clean up the ItemData 39 | int count = (int) SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_GETCOUNT, (WPARAM) 0, (LPARAM) 0); 40 | for (int item = 0; item < count; item++) 41 | { 42 | int* langid = (int*) SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_GETITEMDATA, (WPARAM) item, (LPARAM) 0); 43 | delete langid; 44 | } 45 | 46 | // Now delete the items from the combobox 47 | SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_RESETCONTENT, (WPARAM) 0, (LPARAM) 0); 48 | } 49 | 50 | ///////////////////////////////////////////////////////////////////////////// 51 | // 52 | 53 | static bool Validate(HWND hDlg) 54 | { 55 | // Check if "Name" is entered 56 | if (GetDlgTextLength(hDlg, IDC_NAME) == 0) 57 | { 58 | MsgBox("Name needs to be entered!"); 59 | return false; 60 | } 61 | 62 | // Check if "Before Selection" is entered 63 | if (GetDlgTextLength(hDlg, IDC_BEFORE_SEL) == 0) 64 | { 65 | MsgBox("Before Selection needs to be entered!"); 66 | return false; 67 | } 68 | 69 | return true; 70 | } 71 | 72 | ///////////////////////////////////////////////////////////////////////////// 73 | // 74 | 75 | static BOOL OnOK(HWND hDlg) 76 | { 77 | if (!Validate(hDlg)) 78 | return TRUE; 79 | 80 | // Get the new data from the dialog 81 | using namespace std; 82 | wstring name = GetDlgText(hDlg, IDC_NAME); 83 | wstring before = GetDlgText(hDlg, IDC_BEFORE_SEL); 84 | wstring after = GetDlgText(hDlg, IDC_AFTER_SEL); 85 | 86 | s_pSnippet->WSetName(name.c_str()); 87 | s_pSnippet->WSetBeforeSelection(before.c_str()); 88 | s_pSnippet->WSetAfterSelection(after.c_str()); 89 | s_pSnippet->SetReplaceSelection(IsDlgButtonChecked(hDlg, IDC_REPLACE_SEL) == BST_CHECKED); 90 | s_pSnippet->SetNewDocument(IsDlgButtonChecked(hDlg, IDC_NEW_DOC) == BST_CHECKED); 91 | 92 | // Get the selected language from the combo 93 | if (g_HasLangMsgs) 94 | { 95 | long item = (long) SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); 96 | if (item != CB_ERR) 97 | { 98 | int* langid = (int*) SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_GETITEMDATA, (WPARAM) item, (LPARAM) 0); 99 | s_pSnippet->SetNewDocumentLang(*langid); 100 | } 101 | } 102 | 103 | // Save the snippet to the database 104 | try 105 | { 106 | WaitCursor wait; 107 | s_pSnippet->SaveToDB(); 108 | } 109 | catch (SqliteException ex) 110 | { 111 | std::string msg = "Failed to save the snippet to the database!\n\n"; 112 | msg += ex.what(); 113 | MsgBox(msg.c_str()); 114 | } 115 | 116 | // We're done 117 | CleanItems(hDlg); 118 | EndDialog(hDlg, IDOK); 119 | return TRUE; 120 | } 121 | 122 | ///////////////////////////////////////////////////////////////////////////// 123 | // 124 | 125 | static BOOL OnCancel(HWND hDlg) 126 | { 127 | CleanItems(hDlg); 128 | EndDialog(hDlg, IDCANCEL); 129 | return TRUE; 130 | } 131 | 132 | ///////////////////////////////////////////////////////////////////////////// 133 | // 134 | 135 | static BOOL OnReplaceSelClick(HWND hDlg) 136 | { 137 | if (IsDlgButtonChecked(hDlg, IDC_REPLACE_SEL) == BST_CHECKED) 138 | { 139 | SetWindowText(GetDlgItem(hDlg, IDC_BEFORE_SEL_TXT), L"&Replace with:"); 140 | SetWindowText(GetDlgItem(hDlg, IDC_AFTER_SEL_TXT), L"&After selection:"); 141 | EnableWindow(GetDlgItem(hDlg, IDC_AFTER_SEL), FALSE); 142 | } 143 | else 144 | { 145 | SetWindowText(GetDlgItem(hDlg, IDC_BEFORE_SEL_TXT), L"Befo&re cursor:"); 146 | SetWindowText(GetDlgItem(hDlg, IDC_AFTER_SEL_TXT), L"&After cursor:"); 147 | EnableWindow(GetDlgItem(hDlg, IDC_AFTER_SEL), TRUE); 148 | } 149 | return TRUE; 150 | } 151 | 152 | ///////////////////////////////////////////////////////////////////////////// 153 | // 154 | 155 | static BOOL OnNewDocumentClick(HWND hDlg) 156 | { 157 | // Only enable the combo if we have a version of Notepad++ that supports NPPM_GETLANGUAGENAME 158 | if (g_HasLangMsgs) 159 | EnableWindow(GetDlgItem(hDlg, IDC_NEW_DOC_LANG), IsDlgButtonChecked(hDlg, IDC_NEW_DOC) == BST_CHECKED); 160 | else 161 | EnableWindow(GetDlgItem(hDlg, IDC_NEW_DOC_LANG), FALSE); 162 | return TRUE; 163 | } 164 | 165 | ///////////////////////////////////////////////////////////////////////////// 166 | // 167 | 168 | static void FillLanguageCombo(HWND hDlg) 169 | { 170 | // Check if we have a version of Notepad++ that supports NPPM_GETLANGUAGENAME 171 | if (!g_HasLangMsgs) 172 | return; 173 | 174 | WCHAR LangName[MAX_PATH]; 175 | long item = 0; 176 | 177 | // Go through all the available languages and put them in the combo 178 | for (int langid = L_TEXT; langid <= L_EXTERNAL; langid++) 179 | { 180 | if (langid != L_EXTERNAL) 181 | { 182 | // Get the language name 183 | SendMessage(g_nppData._nppHandle, NPPM_GETLANGUAGENAME, langid, (LPARAM) LangName); 184 | 185 | // Add the language to the combo 186 | item = (long) SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_ADDSTRING, (WPARAM) 0, (LPARAM) LangName); 187 | } 188 | else 189 | { 190 | // Add the language to the combo 191 | item = (long) SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_ADDSTRING, (WPARAM) 0, (LPARAM) L"Use default"); 192 | } 193 | 194 | int* tmpLangid = new int; 195 | *tmpLangid = langid; 196 | SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_SETITEMDATA, (WPARAM) item, (LPARAM) tmpLangid); 197 | 198 | // Need to select the current language? 199 | if (langid == s_pSnippet->GetNewDocumentLang()) 200 | SendDlgItemMessage(hDlg, IDC_NEW_DOC_LANG, CB_SETCURSEL, (WPARAM) item, (LPARAM) 0); 201 | } 202 | } 203 | 204 | ///////////////////////////////////////////////////////////////////////////// 205 | // 206 | 207 | static BOOL OnInitDialog(HWND hDlg) 208 | { 209 | if (s_pSnippet == NULL) 210 | return TRUE; 211 | 212 | CenterWindow(hDlg); 213 | 214 | SetDlgItemText(hDlg, IDC_NAME, s_pSnippet->WGetName()); 215 | SetDlgItemText(hDlg, IDC_BEFORE_SEL, s_pSnippet->WGetBeforeSelection()); 216 | SetDlgItemText(hDlg, IDC_AFTER_SEL, s_pSnippet->WGetAfterSelection()); 217 | CheckDlgButton(hDlg, IDC_REPLACE_SEL, s_pSnippet->GetReplaceSelection() ? BST_CHECKED : BST_UNCHECKED); 218 | CheckDlgButton(hDlg, IDC_NEW_DOC, s_pSnippet->GetNewDocument() ? BST_CHECKED : BST_UNCHECKED); 219 | 220 | FillLanguageCombo(hDlg); 221 | 222 | OnReplaceSelClick(hDlg); 223 | OnNewDocumentClick(hDlg); 224 | 225 | // Let windows set focus 226 | return TRUE; 227 | } 228 | 229 | ///////////////////////////////////////////////////////////////////////////// 230 | // 231 | 232 | static BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 233 | { 234 | UNREFERENCED_PARAMETER(lParam); 235 | 236 | switch(message) 237 | { 238 | case WM_INITDIALOG: 239 | { 240 | return OnInitDialog(hDlg); 241 | } 242 | case WM_COMMAND: 243 | { 244 | switch(LOWORD(wParam)) 245 | { 246 | case IDOK: 247 | return OnOK(hDlg); 248 | 249 | case IDCANCEL: 250 | return OnCancel(hDlg); 251 | 252 | case IDC_REPLACE_SEL: 253 | { 254 | if (HIWORD(wParam) == BN_CLICKED) 255 | { 256 | return OnReplaceSelClick(hDlg); 257 | } 258 | break; 259 | } 260 | 261 | case IDC_NEW_DOC: 262 | { 263 | if (HIWORD(wParam) == BN_CLICKED) 264 | { 265 | return OnNewDocumentClick(hDlg); 266 | } 267 | break; 268 | } 269 | } 270 | return FALSE; 271 | } 272 | } 273 | return FALSE; 274 | } 275 | 276 | ///////////////////////////////////////////////////////////////////////////// 277 | // Show the Dialog 278 | 279 | bool ShowEditSnippetDlg(Snippet* pSnippet) 280 | { 281 | s_pSnippet = pSnippet; 282 | return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_EDIT_SNIPPET), g_nppData._nppHandle, (DLGPROC) DlgProc) == IDOK; 283 | } 284 | -------------------------------------------------------------------------------- /DlgEditSnippet.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern bool ShowEditSnippetDlg(Snippet*); 25 | -------------------------------------------------------------------------------- /DlgImportLibrary.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | #include "Library.h" 27 | #include "Resource.h" 28 | #include "WaitCursor.h" 29 | #include "SnippetsDB.h" 30 | 31 | static LPCWSTR s_databaseFile = NULL; 32 | 33 | ///////////////////////////////////////////////////////////////////////////// 34 | // 35 | 36 | static bool Validate(HWND hDlg) 37 | { 38 | // Is there a library selected? 39 | if (SendDlgItemMessage(hDlg, IDC_NAME, CB_GETCURSEL, 0, 0L) == CB_ERR) 40 | { 41 | MsgBox("No library selected"); 42 | return false; 43 | } 44 | 45 | return true; 46 | } 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | 51 | static void CleanItems(HWND hDlg) 52 | { 53 | // First need to clean up the ItemData!!! 54 | Library* lib = NULL; 55 | int count = (int) SendDlgItemMessage(hDlg, IDC_NAME, CB_GETCOUNT, 0, 0); 56 | for (int item = 0; item < count; item++) 57 | { 58 | lib = (Library*) SendDlgItemMessage(hDlg, IDC_NAME, CB_GETITEMDATA, (WPARAM) item, 0); 59 | delete lib; 60 | } 61 | 62 | // Now delete the items from the combobox 63 | SendDlgItemMessage(hDlg, IDC_NAME, CB_RESETCONTENT, (WPARAM) 0, (LPARAM) 0); 64 | } 65 | 66 | ///////////////////////////////////////////////////////////////////////////// 67 | // 68 | 69 | static bool AddLibraryToCombo(HWND hDlg) 70 | { 71 | WaitCursor wait; 72 | 73 | g_db->Open(); 74 | g_db->Attach(s_databaseFile, L"Import"); 75 | 76 | // Add the libraries in the attached database to the combobox 77 | SqliteStatement stmt(g_db, "SELECT * FROM Import.Library ORDER BY Name"); 78 | 79 | // Go through the records 80 | long item = 0; 81 | bool first = true; 82 | while (stmt.GetNextRecord()) 83 | { 84 | // Store the library data 85 | Library* lib = new Library(&stmt); 86 | 87 | // Add the item to the combo 88 | item = (long) SendDlgItemMessage(hDlg, IDC_NAME, CB_ADDSTRING, (WPARAM) 0, (LPARAM) lib->WGetName()); 89 | SendDlgItemMessage(hDlg, IDC_NAME, CB_SETITEMDATA, (WPARAM) item, (LPARAM) lib); 90 | 91 | // Need to select the current library? 92 | if (first) 93 | { 94 | SendDlgItemMessage(hDlg, IDC_NAME, CB_SETCURSEL, (WPARAM) item, (LPARAM) 0); 95 | first = false; 96 | } 97 | } 98 | stmt.Finalize(); 99 | 100 | g_db->Detach(L"Import"); 101 | g_db->Close(); 102 | 103 | return true; 104 | } 105 | 106 | ///////////////////////////////////////////////////////////////////////////// 107 | // 108 | 109 | static BOOL OnOK(HWND hDlg) 110 | { 111 | if (!Validate(hDlg)) 112 | return TRUE; 113 | 114 | // Get Library from the selected item 115 | WaitCursor wait; 116 | int item = (int) SendDlgItemMessage(hDlg, IDC_NAME, CB_GETCURSEL, 0, 0L); 117 | Library* lib = (Library*) SendDlgItemMessage(hDlg, IDC_NAME, CB_GETITEMDATA, (WPARAM) item, 0); 118 | 119 | // Import the data 120 | g_db->Open(); 121 | g_db->ImportLibrary(s_databaseFile, lib->GetLibraryID()); 122 | g_db->Close(); 123 | 124 | // We're done 125 | CleanItems(hDlg); 126 | EndDialog(hDlg, IDOK); 127 | return TRUE; 128 | } 129 | 130 | ///////////////////////////////////////////////////////////////////////////// 131 | // 132 | 133 | static BOOL OnCancel(HWND hDlg) 134 | { 135 | CleanItems(hDlg); 136 | EndDialog(hDlg, IDCANCEL); 137 | return TRUE; 138 | } 139 | 140 | ///////////////////////////////////////////////////////////////////////////// 141 | // 142 | 143 | static BOOL OnInitDialog(HWND hDlg) 144 | { 145 | CenterWindow(hDlg); 146 | AddLibraryToCombo(hDlg); 147 | return TRUE; 148 | } 149 | 150 | ///////////////////////////////////////////////////////////////////////////// 151 | // 152 | 153 | static BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 154 | { 155 | UNREFERENCED_PARAMETER(lParam); 156 | 157 | switch(message) 158 | { 159 | case WM_INITDIALOG: 160 | { 161 | return OnInitDialog(hDlg); 162 | } 163 | case WM_COMMAND: 164 | { 165 | switch(LOWORD(wParam)) 166 | { 167 | case IDOK: 168 | return OnOK(hDlg); 169 | 170 | case IDCANCEL: 171 | return OnCancel(hDlg); 172 | } 173 | return FALSE; 174 | } 175 | } 176 | return FALSE; 177 | } 178 | 179 | ///////////////////////////////////////////////////////////////////////////// 180 | // Show the Dialog 181 | 182 | bool ImportLibraryDlg(LPCWSTR databaseFile) 183 | { 184 | s_databaseFile = databaseFile; 185 | return DialogBox(g_hInst, MAKEINTRESOURCE(IDD_IMPORT_LIBRARY), g_nppData._nppHandle, (DLGPROC) DlgProc) == IDOK; 186 | } 187 | -------------------------------------------------------------------------------- /DlgImportLibrary.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern bool ImportLibraryDlg(LPCWSTR databaseFile); 25 | -------------------------------------------------------------------------------- /DlgOptions.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2021 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | #include "Resource.h" 27 | #include "Options.h" 28 | 29 | static bool s_toolbarIcon = false; 30 | 31 | ///////////////////////////////////////////////////////////////////////////// 32 | // This function is not actually used. Keep it here so when it *is* needed 33 | // it gets called already. 34 | 35 | static void CleanItems(HWND hDlg) 36 | { 37 | UNREFERENCED_PARAMETER(hDlg); 38 | } 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | // 42 | 43 | static bool Validate(HWND hDlg) 44 | { 45 | // Do we need to show a warning that N++ may need to be restarted 46 | const bool toolbarIcon = IsDlgButtonChecked(hDlg, IDC_INDENT_SNIPPET) == BST_CHECKED; 47 | if (s_toolbarIcon != toolbarIcon) 48 | MsgBox("Note that changing the toolbar icon only takes effect after restarting Notepad++"); 49 | 50 | return true; 51 | } 52 | 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // 55 | 56 | static BOOL OnOK(HWND hDlg) 57 | { 58 | // Are all the values in the dialog valid? 59 | if (!Validate(hDlg)) 60 | return TRUE; 61 | 62 | // Put the items back in the options 63 | g_Options->SetToolbarIcon(IsDlgButtonChecked(hDlg, IDC_TOOLBAR_ICON) == BST_CHECKED); 64 | g_Options->SetIndentSnippet(IsDlgButtonChecked(hDlg, IDC_INDENT_SNIPPET) == BST_CHECKED); 65 | g_Options->SetDBFile(GetDlgText(hDlg, IDC_DBFILE)); 66 | 67 | // We're done 68 | CleanItems(hDlg); 69 | EndDialog(hDlg, IDOK); 70 | return TRUE; 71 | } 72 | 73 | ///////////////////////////////////////////////////////////////////////////// 74 | // 75 | 76 | static BOOL OnCancel(HWND hDlg) 77 | { 78 | CleanItems(hDlg); 79 | EndDialog(hDlg, IDCANCEL); 80 | return TRUE; 81 | } 82 | 83 | ///////////////////////////////////////////////////////////////////////////// 84 | // 85 | 86 | static BOOL OnBrowse(HWND hDlg) 87 | { 88 | // Init for GetOpenFileName() 89 | WCHAR szFile[_MAX_PATH]; // buffer for file name 90 | szFile[0] = 0; 91 | 92 | OPENFILENAME ofn; 93 | ZeroMemory(&ofn, sizeof(OPENFILENAME)); 94 | ofn.lStructSize = sizeof(OPENFILENAME); 95 | ofn.hwndOwner = hDlg; 96 | ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; 97 | ofn.lpstrFilter = L"NppSnippets.sqlite (NppSnippets.sqlite)\0NppSnippets.sqlite\0All SQLite databases (*.sqlite)\0*.sqlite\0\0"; 98 | ofn.nMaxFile = _MAX_PATH; 99 | ofn.lpstrFile = szFile; 100 | 101 | // Ask for the filename 102 | if (GetOpenFileName(&ofn)) 103 | { 104 | // Put the filename in the dialog item 105 | SetDlgItemText(hDlg, IDC_DBFILE, ofn.lpstrFile); 106 | } 107 | 108 | return TRUE; 109 | } 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | // 113 | 114 | static BOOL OnInitDialog(HWND hDlg) 115 | { 116 | // Center the window 117 | CenterWindow(hDlg); 118 | 119 | // Fill the items of the dialog 120 | CheckDlgButton(hDlg, IDC_TOOLBAR_ICON, g_Options->GetToolbarIcon() ? BST_CHECKED : BST_UNCHECKED); 121 | CheckDlgButton(hDlg, IDC_INDENT_SNIPPET, g_Options->GetIndentSnippet() ? BST_CHECKED : BST_UNCHECKED); 122 | SetDlgItemText(hDlg, IDC_DBFILE, g_Options->GetDBFile().c_str()); 123 | 124 | // Store the current value of `ToolbarIcon` 125 | s_toolbarIcon = g_Options->GetToolbarIcon(); 126 | 127 | // Let windows set focus 128 | return TRUE; 129 | } 130 | 131 | ///////////////////////////////////////////////////////////////////////////// 132 | // 133 | 134 | static BOOL CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) 135 | { 136 | UNREFERENCED_PARAMETER(lParam); 137 | 138 | switch(message) 139 | { 140 | case WM_INITDIALOG: 141 | { 142 | return OnInitDialog(hDlg); 143 | } 144 | case WM_COMMAND: 145 | { 146 | switch(LOWORD(wParam)) 147 | { 148 | case IDOK: 149 | return OnOK(hDlg); 150 | 151 | case IDCANCEL: 152 | return OnCancel(hDlg); 153 | 154 | case IDC_BROWSE: 155 | return OnBrowse(hDlg); 156 | } 157 | return FALSE; 158 | } 159 | } 160 | return FALSE; 161 | } 162 | 163 | ///////////////////////////////////////////////////////////////////////////// 164 | // Show the Dialog 165 | 166 | void ShowOptionsDlg() 167 | { 168 | DialogBox(g_hInst, MAKEINTRESOURCE(IDD_OPTIONS), g_nppData._nppHandle, (DLGPROC) DlgProc); 169 | } 170 | -------------------------------------------------------------------------------- /DlgOptions.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2021 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | extern void ShowOptionsDlg(); 25 | -------------------------------------------------------------------------------- /Language.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | #include "Language.h" 27 | 28 | ///////////////////////////////////////////////////////////////////////////// 29 | // 30 | 31 | Language::Language(int langid) 32 | { 33 | _LangID = langid; 34 | 35 | ZeroMemory(&_LangName, MAX_PATH); 36 | SendMessage(g_nppData._nppHandle, NPPM_GETLANGUAGENAME, langid, (LPARAM) _LangName); 37 | 38 | ZeroMemory(&_LangDescr, MAX_PATH); 39 | SendMessage(g_nppData._nppHandle, NPPM_GETLANGUAGEDESC, langid, (LPARAM) _LangDescr); 40 | } 41 | 42 | Language::Language(int langid, LPCWSTR langName, LPCWSTR langDescr) 43 | { 44 | _LangID = langid; 45 | wcsncpy(_LangName, langName, MAX_PATH); 46 | wcsncpy(_LangDescr, langDescr, MAX_PATH); 47 | } 48 | -------------------------------------------------------------------------------- /Language.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | class Language 25 | { 26 | public: 27 | Language(int langid); 28 | Language(int langid, LPCWSTR langName, LPCWSTR langDescr); 29 | 30 | int GetLangID() { return _LangID; }; 31 | WCHAR* GetLangName() { return _LangName; }; 32 | WCHAR* GetLangDescr() { return _LangDescr; }; 33 | 34 | private: 35 | int _LangID; 36 | WCHAR _LangName[MAX_PATH]; 37 | WCHAR _LangDescr[MAX_PATH]; 38 | }; 39 | -------------------------------------------------------------------------------- /Library.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include 25 | #include "NPP/PluginInterface.h" 26 | #include "NppSnippets.h" 27 | 28 | #include "Library.h" 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | // 32 | 33 | Library::Library() 34 | { 35 | _LibraryID = 0; 36 | _Name = NULL; 37 | _CreatedBy = NULL; 38 | _Comments = NULL; 39 | _SortAlphabetic = true; 40 | } 41 | 42 | Library::Library(SqliteStatement* stmt) 43 | { 44 | _Name = NULL; 45 | _CreatedBy = NULL; 46 | _Comments = NULL; 47 | Set(stmt); 48 | } 49 | 50 | Library::~Library() 51 | { 52 | if (_Name != NULL) 53 | free(_Name); 54 | if (_CreatedBy != NULL) 55 | free(_CreatedBy); 56 | if (_Comments != NULL) 57 | free(_Comments); 58 | } 59 | 60 | ///////////////////////////////////////////////////////////////////////////// 61 | // 62 | 63 | void Library::WSetCreatedBy(LPCWCH txt) 64 | { 65 | if (_CreatedBy != NULL) 66 | free(_CreatedBy); 67 | 68 | _CreatedBy = (txt == NULL ? NULL : wcsdup(txt)); 69 | } 70 | 71 | void Library::WSetComments(LPCWCH txt) 72 | { 73 | if (_Comments != NULL) 74 | free(_Comments); 75 | 76 | _Comments = (txt == NULL ? NULL : wcsdup(txt)); 77 | } 78 | 79 | ///////////////////////////////////////////////////////////////////////////// 80 | // 81 | 82 | void Library::Set(SqliteStatement* stmt) 83 | { 84 | _LibraryID = stmt->GetIntColumn("LibraryID"); 85 | WSetName(stmt->GetWTextColumn("Name").c_str()); 86 | WSetCreatedBy(stmt->GetWTextColumn("CreatedBy").c_str()); 87 | WSetComments(stmt->GetWTextColumn("Comments").c_str()); 88 | SetSortAlphabetic(stmt->GetIntColumn("SortBy")); 89 | } 90 | 91 | ///////////////////////////////////////////////////////////////////////////// 92 | // 93 | 94 | void Library::SaveToDB(bool autoOpen) 95 | { 96 | // Try to open the database 97 | g_db->Open(); 98 | 99 | // Saving a new record or updating an existing? 100 | SqliteStatement stmt(g_db); 101 | if (_LibraryID == 0) 102 | { 103 | // Determine the last used LibraryID 104 | SqliteStatement stmt2(g_db, "SELECT MAX(LibraryID) AS MaxID FROM Library"); 105 | stmt2.GetNextRecord(); 106 | _LibraryID = stmt2.GetIntColumn("MaxID") + 1; 107 | stmt2.Finalize(); 108 | 109 | // Prepare the statement 110 | stmt.Prepare("INSERT INTO Library(LibraryID, Name, CreatedBy, Comments, SortBy) VALUES (@id, @name, @createdby, @comments, @sortby)"); 111 | } 112 | else 113 | { 114 | // Prepare the statement 115 | stmt.Prepare("UPDATE Library SET Name = @name, CreatedBy = @createdby, Comments = @comments, SortBy = @sortby WHERE LibraryID = @id"); 116 | } 117 | 118 | // Bind the values to the parameters 119 | stmt.Bind("@id", _LibraryID); 120 | stmt.Bind("@name", _Name); 121 | stmt.Bind("@createdby", _CreatedBy); 122 | stmt.Bind("@comments", _Comments); 123 | stmt.Bind("@sortby", GetSortBy()); 124 | 125 | // Save the record 126 | stmt.SaveRecord(); 127 | stmt.Finalize(); 128 | 129 | if (autoOpen) 130 | g_db->Close(); 131 | } 132 | 133 | ///////////////////////////////////////////////////////////////////////////// 134 | // 135 | 136 | void Library::DeleteFromDB() 137 | { 138 | g_db->Open(); 139 | SqliteStatement stmt(g_db, "DELETE FROM Library WHERE LibraryID = @id"); 140 | stmt.Bind("@id", _LibraryID); 141 | stmt.SaveRecord(); 142 | stmt.Finalize(); 143 | g_db->Close(); 144 | } 145 | 146 | ///////////////////////////////////////////////////////////////////////////// 147 | // 148 | 149 | void Library::AddLanguageToDB(int lang) 150 | { 151 | LanguageDBHelper("INSERT INTO LibraryLang(LibraryID, Lang) VALUES (@id, @lang)", lang); 152 | } 153 | 154 | ///////////////////////////////////////////////////////////////////////////// 155 | // 156 | 157 | void Library::DeleteLanguageFromDB(int lang) 158 | { 159 | LanguageDBHelper("DELETE FROM LibraryLang WHERE LibraryID = @id AND Lang = @lang)", lang); 160 | } 161 | 162 | ///////////////////////////////////////////////////////////////////////////// 163 | // 164 | 165 | void Library::ExportTo(LPCWCH filename) 166 | { 167 | // Open the db and create/attach the new db 168 | g_db->Open(); 169 | g_db->Attach(filename, L"export"); 170 | g_db->CreateExportDB(); 171 | g_db->Detach(L"export"); 172 | g_db->Close(); 173 | 174 | // Now use that export database as temporary "base" database 175 | // and import the current lib from the temp database 176 | // When all done, restore the original database filename 177 | std::wstring orgFile = g_db->GetFilename(); 178 | g_db->SetFilename(filename); 179 | g_db->Open(); 180 | g_db->ImportLibrary(orgFile.c_str(), _LibraryID); 181 | g_db->Close(); 182 | g_db->SetFilename(orgFile.c_str()); 183 | } 184 | 185 | ///////////////////////////////////////////////////////////////////////////// 186 | // 187 | 188 | void Library::LanguageDBHelper(LPCSTR sql, int lang) 189 | { 190 | g_db->Open(); 191 | SqliteStatement stmt(g_db, sql); 192 | stmt.Bind("@id", _LibraryID); 193 | stmt.Bind("@lang", lang); 194 | stmt.SaveRecord(); 195 | stmt.Finalize(); 196 | g_db->Close(); 197 | } 198 | -------------------------------------------------------------------------------- /Library.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include "Snippets.h" 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | 29 | class Library : public SnippetBase 30 | { 31 | public: 32 | Library(); 33 | Library(SqliteStatement* stmt); 34 | virtual ~Library(); 35 | 36 | WCHAR* WGetCreatedBy() { return _CreatedBy; } 37 | WCHAR* WGetComments() { return _Comments; } 38 | bool GetSortAlphabetic() { return _SortAlphabetic; } 39 | 40 | virtual void Set(SqliteStatement* stmt); 41 | 42 | void WSetCreatedBy(LPCWCH txt); 43 | void WSetComments(LPCWCH txt); 44 | void SetSortAlphabetic(bool b) { _SortAlphabetic = b; } 45 | void SetSortAlphabetic(int i) { _SortAlphabetic = (i == 0); } 46 | 47 | void SaveToDB(bool autoOpen = true) override; 48 | void DeleteFromDB() override; 49 | void AddLanguageToDB(int lang); 50 | void DeleteLanguageFromDB(int lang); 51 | void ExportTo(LPCWCH filename); 52 | 53 | private: 54 | WCHAR* _CreatedBy; 55 | WCHAR* _Comments; 56 | bool _SortAlphabetic; 57 | 58 | int GetSortBy() { return _SortAlphabetic ? 0 : 1; } 59 | void LanguageDBHelper(LPCSTR sql, int lang); 60 | }; 61 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ############################################################################# 2 | # # 3 | # Makefile for building a MinGW-w64 NppSnippets.dll # 4 | # # 5 | ############################################################################# 6 | 7 | .SUFFIXES: .dll .o .c .cpp .rc .h 8 | 9 | ARCH = x86_64-w64-mingw32 10 | CC = $(ARCH)-gcc 11 | CXX = $(ARCH)-g++ 12 | WINDRES = $(ARCH)-windres 13 | 14 | # The main targets 15 | PROGRAM = NppSnippets 16 | TARGET = $(PROGRAM).dll 17 | 18 | now: $(TARGET) 19 | all: clean now 20 | 21 | # The general compiler flags 22 | CFLAGS = -DUNICODE 23 | CXXFLAGS = $(CFLAGS) -Wno-write-strings --std=c++11 24 | LIBS = -static -lshlwapi -lgdi32 -lcomdlg32 -lcomctl32 25 | LDFLAGS = -shared -Wl,--dll 26 | 27 | # Default target is RELEASE, otherwise DEBUG=1 28 | DEBUG ?= 0 29 | ifeq ($(DEBUG), 1) 30 | # Add DEBUG define, debug info and specific optimizations 31 | CFLAGS += -D_DEBUG -g -O0 32 | CXXFLAGS += -D_DEBUG -g -O0 33 | # Add dependencies flags 34 | CFLAGS += -MMD -MP 35 | CXXFLAGS += -MMD -MP 36 | # Enable almost all warnings 37 | CXXFLAGS += -W -Wall 38 | else 39 | # Set the optimizations 40 | OPT = -fexpensive-optimizations -Os -O2 41 | # Strip the dll 42 | LDOPT = -s 43 | endif 44 | 45 | # Silent/verbose commands. For verbose output of commands set V=1 46 | V ?= 0 47 | ifeq ($(V), 0) 48 | SILENT = @ 49 | V_CC = @echo [CC] $@; 50 | V_CXX = @echo [CXX] $@; 51 | V_RES = @echo [WINDRES] $@; 52 | endif 53 | 54 | # All the build targets 55 | .c.o: 56 | $(V_CC) $(CC) -c $(CFLAGS) $(OPT) -o $@ $< 57 | 58 | .cpp.o: 59 | $(V_CXX) $(CXX) -c $(CXXFLAGS) $(OPT) -o $@ $< 60 | 61 | .rc.o: 62 | $(V_RES) $(WINDRES) -o $@ -i $< 63 | 64 | PROGRAM_SRCS_CPP = \ 65 | DlgAbout.cpp \ 66 | DlgConsole.cpp \ 67 | DlgEditSnippet.cpp \ 68 | DlgEditLanguages.cpp \ 69 | DlgEditLibrary.cpp \ 70 | DlgImportLibrary.cpp \ 71 | DlgOptions.cpp \ 72 | Language.cpp \ 73 | Library.cpp \ 74 | NppOptions.cpp \ 75 | NppSnippets.cpp \ 76 | Options.cpp \ 77 | Snippets.cpp \ 78 | SnippetsDB.cpp \ 79 | SqliteDB.cpp \ 80 | WaitCursor.cpp 81 | 82 | PROGRAM_SRCS_C = \ 83 | sqlite3.c 84 | 85 | PROGRAM_OBJS_CPP=$(PROGRAM_SRCS_CPP:.cpp=.o) 86 | PROGRAM_OBJS_C=$(PROGRAM_SRCS_C:.c=.o) 87 | 88 | PROGRAM_RC=$(PROGRAM)_res.rc 89 | PROGRAM_OBJS_RC=$(PROGRAM_RC:.rc=.o) 90 | 91 | PROGRAM_DEP_CPP=$(PROGRAM_SRCS_CPP:.cpp=.d) 92 | PROGRAM_DEP_C=$(PROGRAM_SRCS_C:.c=.d) 93 | 94 | $(PROGRAM).dll: version_git.h $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC) 95 | $(V_CXX) $(CXX) -o $@ $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC) $(LDFLAGS) $(LDOPT) $(LIBS) 96 | 97 | version_git.h: 98 | $(SILENT) ./version_git.sh 99 | 100 | clean: 101 | @echo Cleaning 102 | $(SILENT) rm -f $(PROGRAM_OBJS_CPP) $(PROGRAM_OBJS_C) $(PROGRAM_OBJS_RC) version_git.h 103 | $(SILENT) rm -f $(PROGRAM_DEP_CPP) $(PROGRAM_DEP_C) $(PROGRAM).dll 104 | 105 | cppcheck: 106 | @echo Running cppcheck 107 | $(SILENT) cppcheck --quiet $(PROGRAM_SRCS_CPP) 108 | 109 | # The dependencies 110 | $(PROGRAM)_res.o: $(PROGRAM)_res.rc version_git.h 111 | 112 | -include $(PROGRAM_DEP_CPP) 113 | -include $(PROGRAM_DEP_C) 114 | -------------------------------------------------------------------------------- /NPP/Docking.h: -------------------------------------------------------------------------------- 1 | // This file is part of Notepad++ project 2 | // Copyright (C)2021 Don HO 3 | 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // at your option any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | // ATTENTION : It's a part of interface header, so don't include the others header here 23 | 24 | // styles for containers 25 | #define CAPTION_TOP TRUE 26 | #define CAPTION_BOTTOM FALSE 27 | 28 | // defines for docking manager 29 | #define CONT_LEFT 0 30 | #define CONT_RIGHT 1 31 | #define CONT_TOP 2 32 | #define CONT_BOTTOM 3 33 | #define DOCKCONT_MAX 4 34 | 35 | // mask params for plugins of internal dialogs 36 | #define DWS_ICONTAB 0x00000001 // Icon for tabs are available 37 | #define DWS_ICONBAR 0x00000002 // Icon for icon bar are available (currently not supported) 38 | #define DWS_ADDINFO 0x00000004 // Additional information are in use 39 | #define DWS_USEOWNDARKMODE 0x00000008 // Use plugin's own dark mode 40 | #define DWS_PARAMSALL (DWS_ICONTAB|DWS_ICONBAR|DWS_ADDINFO) 41 | 42 | // default docking values for first call of plugin 43 | #define DWS_DF_CONT_LEFT (CONT_LEFT << 28) // default docking on left 44 | #define DWS_DF_CONT_RIGHT (CONT_RIGHT << 28) // default docking on right 45 | #define DWS_DF_CONT_TOP (CONT_TOP << 28) // default docking on top 46 | #define DWS_DF_CONT_BOTTOM (CONT_BOTTOM << 28) // default docking on bottom 47 | #define DWS_DF_FLOATING 0x80000000 // default state is floating 48 | 49 | 50 | struct tTbData { 51 | HWND hClient = nullptr; // client Window Handle 52 | const TCHAR* pszName = nullptr; // name of plugin (shown in window) 53 | int dlgID = 0; // a funcItem provides the function pointer to start a dialog. Please parse here these ID 54 | 55 | // user modifications 56 | UINT uMask = 0; // mask params: look to above defines 57 | HICON hIconTab = nullptr; // icon for tabs 58 | const TCHAR* pszAddInfo = nullptr; // for plugin to display additional informations 59 | 60 | // internal data, do not use !!! 61 | RECT rcFloat = {}; // floating position 62 | int iPrevCont = 0; // stores the privious container (toggling between float and dock) 63 | const TCHAR* pszModuleName = nullptr; // it's the plugin file name. It's used to identify the plugin 64 | }; 65 | 66 | 67 | struct tDockMgr { 68 | HWND hWnd = nullptr; // the docking manager wnd 69 | RECT rcRegion[DOCKCONT_MAX] = {{}}; // position of docked dialogs 70 | }; 71 | 72 | 73 | #define HIT_TEST_THICKNESS 20 74 | #define SPLITTER_WIDTH 4 75 | 76 | -------------------------------------------------------------------------------- /NPP/PluginInterface.h: -------------------------------------------------------------------------------- 1 | // This file is part of Notepad++ project 2 | // Copyright (C)2021 Don HO 3 | 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // at your option any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | 18 | #pragma once 19 | 20 | #include "Scintilla.h" 21 | #include "Notepad_plus_msgs.h" 22 | 23 | const int nbChar = 64; 24 | 25 | typedef const TCHAR * (__cdecl * PFUNCGETNAME)(); 26 | 27 | struct NppData 28 | { 29 | HWND _nppHandle = nullptr; 30 | HWND _scintillaMainHandle = nullptr; 31 | HWND _scintillaSecondHandle = nullptr; 32 | }; 33 | 34 | typedef void (__cdecl * PFUNCSETINFO)(NppData); 35 | typedef void (__cdecl * PFUNCPLUGINCMD)(); 36 | typedef void (__cdecl * PBENOTIFIED)(SCNotification *); 37 | typedef LRESULT (__cdecl * PMESSAGEPROC)(UINT Message, WPARAM wParam, LPARAM lParam); 38 | 39 | 40 | struct ShortcutKey 41 | { 42 | bool _isCtrl = false; 43 | bool _isAlt = false; 44 | bool _isShift = false; 45 | UCHAR _key = 0; 46 | }; 47 | 48 | struct FuncItem 49 | { 50 | TCHAR _itemName[nbChar] = { '\0' }; 51 | PFUNCPLUGINCMD _pFunc = nullptr; 52 | int _cmdID = 0; 53 | bool _init2Check = false; 54 | ShortcutKey *_pShKey = nullptr; 55 | }; 56 | 57 | typedef FuncItem * (__cdecl * PFUNCGETFUNCSARRAY)(int *); 58 | 59 | // You should implement (or define an empty function body) those functions which are called by Notepad++ plugin manager 60 | extern "C" __declspec(dllexport) void setInfo(NppData); 61 | extern "C" __declspec(dllexport) const TCHAR * getName(); 62 | extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *); 63 | extern "C" __declspec(dllexport) void beNotified(SCNotification *); 64 | extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam); 65 | 66 | // This API return always true now, since Notepad++ isn't compiled in ANSI mode anymore 67 | extern "C" __declspec(dllexport) BOOL isUnicode(); 68 | 69 | -------------------------------------------------------------------------------- /NPP/Sci_Position.h: -------------------------------------------------------------------------------- 1 | // Scintilla source code edit control 2 | /** @file Sci_Position.h 3 | ** Define the Sci_Position type used in Scintilla's external interfaces. 4 | ** These need to be available to clients written in C so are not in a C++ namespace. 5 | **/ 6 | // Copyright 2015 by Neil Hodgson 7 | // The License.txt file describes the conditions under which this software may be distributed. 8 | 9 | #ifndef SCI_POSITION_H 10 | #define SCI_POSITION_H 11 | 12 | #include 13 | 14 | // Basic signed type used throughout interface 15 | typedef ptrdiff_t Sci_Position; 16 | 17 | // Unsigned variant used for ILexer::Lex and ILexer::Fold 18 | typedef size_t Sci_PositionU; 19 | 20 | // For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE 21 | typedef intptr_t Sci_PositionCR; 22 | 23 | #ifdef _WIN32 24 | #define SCI_METHOD __stdcall 25 | #else 26 | #define SCI_METHOD 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /NPP/dockingResource.h: -------------------------------------------------------------------------------- 1 | // This file is part of Notepad++ project 2 | // Copyright (C)2006 Jens Lorenz 3 | 4 | // This program is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // at your option any later version. 8 | // 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | // 14 | // You should have received a copy of the GNU General Public License 15 | // along with this program. If not, see . 16 | 17 | 18 | #pragma once 19 | 20 | #define DM_NOFOCUSWHILECLICKINGCAPTION TEXT("NOFOCUSWHILECLICKINGCAPTION") 21 | 22 | #define IDD_PLUGIN_DLG 103 23 | #define IDC_EDIT1 1000 24 | 25 | 26 | #define IDB_CLOSE_DOWN 137 27 | #define IDB_CLOSE_UP 138 28 | #define IDD_CONTAINER_DLG 139 29 | 30 | #define IDC_TAB_CONT 1027 31 | #define IDC_CLIENT_TAB 1028 32 | #define IDC_BTN_CAPTION 1050 33 | 34 | #define DMM_MSG 0x5000 35 | #define DMM_CLOSE (DMM_MSG + 1) 36 | #define DMM_DOCK (DMM_MSG + 2) 37 | #define DMM_FLOAT (DMM_MSG + 3) 38 | #define DMM_DOCKALL (DMM_MSG + 4) 39 | #define DMM_FLOATALL (DMM_MSG + 5) 40 | #define DMM_MOVE (DMM_MSG + 6) 41 | #define DMM_UPDATEDISPINFO (DMM_MSG + 7) 42 | #define DMM_GETIMAGELIST (DMM_MSG + 8) 43 | #define DMM_GETICONPOS (DMM_MSG + 9) 44 | #define DMM_DROPDATA (DMM_MSG + 10) 45 | #define DMM_MOVE_SPLITTER (DMM_MSG + 11) 46 | #define DMM_CANCEL_MOVE (DMM_MSG + 12) 47 | #define DMM_LBUTTONUP (DMM_MSG + 13) 48 | 49 | #define DMN_FIRST 1050 50 | #define DMN_CLOSE (DMN_FIRST + 1) 51 | //nmhdr.code = DWORD(DMN_CLOSE, 0)); 52 | //nmhdr.hwndFrom = hwndNpp; 53 | //nmhdr.idFrom = ctrlIdNpp; 54 | 55 | #define DMN_DOCK (DMN_FIRST + 2) 56 | #define DMN_FLOAT (DMN_FIRST + 3) 57 | //nmhdr.code = DWORD(DMN_XXX, int newContainer); 58 | //nmhdr.hwndFrom = hwndNpp; 59 | //nmhdr.idFrom = ctrlIdNpp; 60 | 61 | #define DMN_SWITCHIN (DMN_FIRST + 4) 62 | #define DMN_SWITCHOFF (DMN_FIRST + 5) 63 | #define DMN_FLOATDROPPED (DMN_FIRST + 6) 64 | //nmhdr.code = DWORD(DMN_XXX, 0); 65 | //nmhdr.hwndFrom = DockingCont::_hself; 66 | //nmhdr.idFrom = 0; 67 | 68 | -------------------------------------------------------------------------------- /NPP/no_ms_shit.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | <_ProjectFileVersion>10.0.30319.1 5 | <_PropertySheetDisplayName>no ms shit 6 | 7 | 8 | 9 | _CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions) 10 | 11 | 12 | -------------------------------------------------------------------------------- /NppOptions.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2020 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include "NppOptions.h" 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | // Constructor 29 | 30 | NppOptions::NppOptions() noexcept 31 | { 32 | // Get the directory from NP++ and add the filename of the settings file 33 | WCHAR szPath[_MAX_PATH]; 34 | szPath[0] = 0; 35 | SendMessage(g_nppData._nppHandle, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH, (LPARAM)&szPath); 36 | 37 | _IniPath = szPath; 38 | _IniPath += L"\\"; 39 | _IniPath += getName(); 40 | _IniPath += L".ini"; 41 | } 42 | 43 | ////////////////////////////////////////////////////////////////////////////// 44 | // Constructor with .ini filename 45 | 46 | NppOptions::NppOptions(std::wstring filename) 47 | { 48 | // Get the directory from NP++ and add the filename of the settings file 49 | WCHAR szPath[_MAX_PATH]; 50 | szPath[0] = 0; 51 | SendMessage(g_nppData._nppHandle, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH, (LPARAM)&szPath); 52 | 53 | _IniPath = szPath; 54 | _IniPath += L"\\"; 55 | _IniPath += filename; 56 | } 57 | 58 | ///////////////////////////////////////////////////////////////////////////// 59 | // Read a boolean from the ini file 60 | 61 | bool NppOptions::GetBool(const WCHAR* szAppName, const WCHAR* szKeyName, const bool def) noexcept 62 | { 63 | return(GetPrivateProfileInt(szAppName, szKeyName, def ? 1 : 0, _IniPath.c_str()) > 0); 64 | } 65 | 66 | ///////////////////////////////////////////////////////////////////////////// 67 | // Read a int from the ini file 68 | 69 | int NppOptions::GetInt(const WCHAR* szAppName, const WCHAR* szKeyName, const int def) noexcept 70 | { 71 | return GetPrivateProfileInt(szAppName, szKeyName, def, _IniPath.c_str()); 72 | } 73 | 74 | ///////////////////////////////////////////////////////////////////////////// 75 | // Read a string from the ini file 76 | 77 | std::wstring NppOptions::GetString(const WCHAR* szAppName, const WCHAR* szKeyName, const WCHAR* def) noexcept 78 | { 79 | WCHAR szRet[_MAX_PATH]; 80 | GetPrivateProfileString(szAppName, szKeyName, def, szRet, _MAX_PATH, _IniPath.c_str()); 81 | return szRet; 82 | } 83 | 84 | ///////////////////////////////////////////////////////////////////////////// 85 | // Write a boolean to the ini file 86 | 87 | void NppOptions::WriteBool(const WCHAR* szAppName, const WCHAR* szKeyName, const bool val) noexcept 88 | { 89 | WritePrivateProfileString(szAppName, szKeyName, val ? L"1" : L"0", _IniPath.c_str()); 90 | } 91 | 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // Write an integer to the ini file 94 | 95 | void NppOptions::WriteInt(const WCHAR* szAppName, const WCHAR* szKeyName, const int val) noexcept 96 | { 97 | WCHAR temp[256]; 98 | swprintf(temp, _countof(temp), L"%d", val); 99 | WritePrivateProfileString(szAppName, szKeyName, temp, _IniPath.c_str()); 100 | } 101 | 102 | ///////////////////////////////////////////////////////////////////////////// 103 | // Write a string to the ini file 104 | 105 | void NppOptions::WriteString(const WCHAR* szAppName, const WCHAR* szKeyName, const WCHAR* val) noexcept 106 | { 107 | WritePrivateProfileString(szAppName, szKeyName, val, _IniPath.c_str()); 108 | } 109 | -------------------------------------------------------------------------------- /NppOptions.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2020 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | 29 | class NppOptions 30 | { 31 | public: 32 | NppOptions() noexcept; 33 | NppOptions(std::wstring filename); 34 | 35 | protected: 36 | bool GetBool(const WCHAR* szAppName, const WCHAR* szKeyName, const bool def) noexcept; 37 | int GetInt(const WCHAR* szAppName, const WCHAR* szKeyName, const int def) noexcept; 38 | std::wstring GetString(const WCHAR* szAppName, const WCHAR* szKeyName, const WCHAR* def) noexcept; 39 | 40 | void WriteBool(const WCHAR* szAppName, const WCHAR* szKeyName, const bool val) noexcept; 41 | void WriteInt(const WCHAR* szAppName, const WCHAR* szKeyName, const int val) noexcept; 42 | void WriteString(const WCHAR* szAppName, const WCHAR* szKeyName, const WCHAR* val) noexcept; 43 | 44 | std::wstring _IniPath; 45 | }; 46 | -------------------------------------------------------------------------------- /NppSnippets.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2016 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | extern HWND getCurrentScintilla(); 27 | extern LRESULT SendMsg(UINT Msg, WPARAM wParam = 0, LPARAM lParam = 0, int count = 1); 28 | extern void MsgBox(const WCHAR* msg); 29 | extern void MsgBox(const char* msg); 30 | extern bool MsgBoxYesNo(const WCHAR* msg); 31 | extern void CenterWindow(HWND hDlg); 32 | extern std::wstring GetDlgText(HWND hDlg, UINT uID); 33 | extern int GetDlgTextLength(HWND hDlg, UINT uID); 34 | extern std::wstring ConvertLineEnding(LPCWSTR from, int toLineEnding = -1); 35 | 36 | struct NppData; 37 | struct FuncItem; 38 | enum LangType; 39 | 40 | extern HINSTANCE g_hInst; 41 | extern NppData g_nppData; 42 | extern LangType g_currentLang; 43 | extern FuncItem g_funcItem[]; 44 | extern bool g_HasLangMsgs; 45 | 46 | class Options; 47 | extern Options *g_Options; 48 | -------------------------------------------------------------------------------- /NppSnippets.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.136 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NppSnippets", "NppSnippets.vcxproj", "{1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{E268F6A4-45FA-4305-A11F-8E91285AAB82}" 9 | ProjectSection(SolutionItems) = preProject 10 | .editorconfig = .editorconfig 11 | .gitignore = .gitignore 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|ARM64 = Debug|ARM64 18 | Debug|Win32 = Debug|Win32 19 | Debug|x64 = Debug|x64 20 | Release|ARM64 = Release|ARM64 21 | Release|Win32 = Release|Win32 22 | Release|x64 = Release|x64 23 | EndGlobalSection 24 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 25 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|ARM64.ActiveCfg = Debug|ARM64 26 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|ARM64.Build.0 = Debug|ARM64 27 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|Win32.Build.0 = Debug|Win32 29 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|x64.ActiveCfg = Debug|x64 30 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Debug|x64.Build.0 = Debug|x64 31 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|ARM64.ActiveCfg = Release|ARM64 32 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|ARM64.Build.0 = Release|ARM64 33 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|Win32.ActiveCfg = Release|Win32 34 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|Win32.Build.0 = Release|Win32 35 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|x64.ActiveCfg = Release|x64 36 | {1590D7CD-7D3A-4AB7-A355-EE02F7FB987D}.Release|x64.Build.0 = Release|x64 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | GlobalSection(ExtensibilityGlobals) = postSolution 42 | SolutionGuid = {5A531550-B8DB-4A41-BF25-9BCE4D0DE397} 43 | EndGlobalSection 44 | EndGlobal 45 | -------------------------------------------------------------------------------- /NppSnippets.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | Source Files 56 | 57 | 58 | Source Files 59 | 60 | 61 | Source Files 62 | 63 | 64 | Source Files 65 | 66 | 67 | Source Files 68 | 69 | 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Header Files 79 | 80 | 81 | Header Files 82 | 83 | 84 | Header Files 85 | 86 | 87 | Header Files 88 | 89 | 90 | Header Files 91 | 92 | 93 | Header Files 94 | 95 | 96 | Header Files 97 | 98 | 99 | Header Files 100 | 101 | 102 | Header Files 103 | 104 | 105 | Header Files 106 | 107 | 108 | Header Files 109 | 110 | 111 | Header Files 112 | 113 | 114 | Header Files 115 | 116 | 117 | Header Files 118 | 119 | 120 | Header Files 121 | 122 | 123 | Header Files 124 | 125 | 126 | 127 | 128 | Resource Files 129 | 130 | 131 | 132 | 133 | Resource Files 134 | 135 | 136 | Resource Files 137 | 138 | 139 | -------------------------------------------------------------------------------- /NppSnippets_res.rc: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2012 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include "Resource.h" 25 | #include "sqlite3.h" 26 | #include "version_git.h" 27 | 28 | ///////////////////////////////////////////////////////////////////////////// 29 | // Version Information 30 | 31 | VS_VERSION_INFO VERSIONINFO 32 | FILEVERSION VERSION_NUMBER 33 | PRODUCTVERSION VERSION_NUMBER 34 | FILEFLAGSMASK 0x3fL 35 | FILEFLAGS 0 36 | FILEOS VOS_NT_WINDOWS32 37 | FILETYPE VFT_APP 38 | FILESUBTYPE VFT2_UNKNOWN 39 | BEGIN 40 | BLOCK "VarFileInfo" 41 | BEGIN 42 | VALUE "Translation", 0x409, 1200 43 | END 44 | BLOCK "StringFileInfo" 45 | BEGIN 46 | BLOCK "040904b0" 47 | BEGIN 48 | VALUE "CompanyName", "Frank Fesevur" 49 | VALUE "FileDescription", "Code Snippets plug-in for Notepad++" 50 | VALUE "FileVersion", VERSION_NUMBER_STR 51 | VALUE "InternalName", "NppSnippets.dll" 52 | VALUE "LegalCopyright", COPYRIGHT_STR 53 | VALUE "OriginalFilename", "NppSnippets.dll" 54 | VALUE "ProductName", "NppSnippets" 55 | VALUE "ProductVersion", VERSION_NUMBER_STR 56 | END 57 | END 58 | END 59 | 60 | ///////////////////////////////////////////////////////////////////////////// 61 | // Dialogs 62 | 63 | IDD_ABOUTBOX DIALOGEX 0, 0, 224, 132 64 | STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_BORDER | WS_SYSMENU 65 | FONT 8, "MS Shell Dlg", 0, 0, 0x1 66 | BEGIN 67 | GROUPBOX "Code Snippets plug-in",IDC_STATIC,10,9,201,114,BS_CENTER 68 | LTEXT "Author:",IDC_STATIC,30,23,35,8 69 | LTEXT "Frank Fesevur",IDC_STATIC,75,23,74,8 70 | LTEXT "Version:",IDC_STATIC,30,38,31,8 71 | LTEXT VERSION_GIT_STR,IDC_STATIC,75,38,130,8 72 | LTEXT "Using SQLite:",IDC_STATIC,30,52,43,8 73 | LTEXT SQLITE_VERSION,IDC_STATIC,75,52,43,8 74 | LTEXT "Licence:",IDC_STATIC,30,67,43,8 75 | LTEXT "GPL-2",IDC_STATIC,75,67,43,8 76 | LTEXT "Site:",IDC_STATIC,30,84,27,8 77 | CONTROL "https://www.fesevur.com/nppsnippets",IDC_SYSLINK,"SysLink",NOT WS_TABSTOP,75,84,130,8 78 | PUSHBUTTON "Close",IDCANCEL,86,102,50,14 79 | END 80 | 81 | IDD_SNIPPETS DIALOGEX 0, 0, 190, 90 82 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 83 | CAPTION "Snippets" 84 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 85 | BEGIN 86 | COMBOBOX IDC_NAME, 0, 0, 77, 30, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 87 | EDITTEXT IDC_FILTER, 0, 7, 77, 14, ES_AUTOVSCROLL | ES_AUTOHSCROLL 88 | LISTBOX IDC_LIST, 0, 7, 186, 90, LBS_NOTIFY | WS_VSCROLL | WS_BORDER 89 | END 90 | 91 | IDD_EDIT_SNIPPET DIALOGEX 0, 0, 380, 240 92 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 93 | CAPTION "Edit Snippet" 94 | FONT 8, "MS Shell Dlg", 0, 0, 0x1 95 | BEGIN 96 | LTEXT "Snippet &name:",IDC_STATIC,7,5,55,8 97 | EDITTEXT IDC_NAME,75,5,200,14,ES_AUTOVSCROLL | ES_AUTOHSCROLL 98 | CONTROL "Replace &selection",IDC_REPLACE_SEL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,290,7,71,10 99 | LTEXT "&Before selection:",IDC_BEFORE_SEL_TXT,7,31,55,8 100 | EDITTEXT IDC_BEFORE_SEL,75,31,300,100,WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN 101 | LTEXT "&After selection:",IDC_AFTER_SEL_TXT,7,137,55,8 102 | EDITTEXT IDC_AFTER_SEL,75,136,300,60,WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN 103 | CONTROL "Start &new document",IDC_NEW_DOC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,200,81,10 104 | LTEXT "&Language for doc:",IDC_STATIC,210,202,70,8 105 | COMBOBOX IDC_NEW_DOC_LANG,275,200,100,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 106 | DEFPUSHBUTTON "OK",IDOK,125,218,50,14 107 | PUSHBUTTON "Cancel",IDCANCEL,205,218,50,14 108 | END 109 | 110 | IDD_EDIT_LIBRARY DIALOGEX 0, 0, 223, 135 111 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 112 | CAPTION "Edit library" 113 | FONT 8, "MS Shell Dlg", 0, 0, 0x1 114 | BEGIN 115 | LTEXT "Library &name:",IDC_STATIC,7,5,55,8 116 | EDITTEXT IDC_NAME,75,5,128,14,ES_AUTOVSCROLL | ES_AUTOHSCROLL 117 | LTEXT "&Created by:",IDC_STATIC,7,23,55,8 118 | EDITTEXT IDC_CREATED_BY,75,23,128,14,ES_AUTOVSCROLL | ES_AUTOHSCROLL 119 | LTEXT "C&omments:",IDC_STATIC,7,43,55,8 120 | EDITTEXT IDC_COMMENTS,75,43,128,39,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN 121 | CONTROL "Sort &alphabetic",IDC_SORT_ALPHABET,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,75,100,81,10 122 | DEFPUSHBUTTON "OK",IDOK,51,115,50,14 123 | PUSHBUTTON "Cancel",IDCANCEL,121,115,50,14 124 | END 125 | 126 | IDD_EDIT_LANGUAGES DIALOGEX 0, 0, 223, 255 127 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 128 | FONT 8, "MS Shell Dlg", 0, 0, 0x1 129 | CAPTION "Edit langauges" 130 | BEGIN 131 | LTEXT "Library &name:",IDC_STATIC,7,5,55,8 132 | LTEXT "", IDC_NAME,75,5,128,14 133 | CONTROL "List1",IDC_LANG_LIST,"SysListView32", LVS_REPORT | WS_BORDER | WS_TABSTOP,7,23,203,200 134 | DEFPUSHBUTTON "OK",IDOK,51,235,50,14 135 | PUSHBUTTON "Cancel",IDCANCEL,121,235,50,14 136 | END 137 | 138 | IDD_IMPORT_LIBRARY DIALOGEX 0, 0, 223, 70 139 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 140 | FONT 8, "MS Shell Dlg", 0, 0, 0x1 141 | CAPTION "Import library" 142 | BEGIN 143 | LTEXT "Library &name:",IDC_STATIC,7,5,55,8 144 | COMBOBOX IDC_NAME, 75,5,128,14, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP 145 | DEFPUSHBUTTON "&Import",IDOK,51,55,50,14 146 | PUSHBUTTON "Cancel",IDCANCEL,121,55,50,14 147 | END 148 | 149 | IDD_OPTIONS DIALOG 0, 0, 186, 104 150 | STYLE DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU 151 | CAPTION "Options" 152 | FONT 8, "MS Shell Dlg" 153 | BEGIN 154 | CONTROL "Show &Toolbox icon", IDC_TOOLBAR_ICON, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 7,12,81,10 155 | CONTROL "&Indent snippet", IDC_INDENT_SNIPPET, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 7,26,81,10 156 | LTEXT "Path to &database:", IDC_STATIC, 7, 49, 58, 9, SS_LEFT, WS_EX_LEFT 157 | EDITTEXT IDC_DBFILE, 8, 60, 149, 14, ES_AUTOHSCROLL | ES_NUMBER, WS_EX_LEFT 158 | PUSHBUTTON "...", IDC_BROWSE, 162, 60, 16, 14, 0, WS_EX_LEFT 159 | DEFPUSHBUTTON "OK", IDOK, 38, 83, 50, 14, 0, WS_EX_LEFT 160 | PUSHBUTTON "Cancel", IDCANCEL, 95, 83, 50, 14, 0, WS_EX_LEFT 161 | END 162 | 163 | ///////////////////////////////////////////////////////////////////////////// 164 | // Context Menus 165 | 166 | IDCM_SNIPPET MENU PRELOAD DISCARDABLE 167 | BEGIN 168 | POPUP "_POPUP_" 169 | BEGIN 170 | MENUITEM "&Insert", IDC_SNIPPET_INSERT 171 | MENUITEM SEPARATOR 172 | MENUITEM "&Add...", IDC_SNIPPET_ADD 173 | MENUITEM "&Edit...", IDC_SNIPPET_EDIT 174 | MENUITEM "&Delete...", IDC_SNIPPET_DELETE 175 | MENUITEM "Dup&licate...", IDC_SNIPPET_DUPLICATE 176 | MENUITEM SEPARATOR 177 | MENUITEM "Add from &selection...", IDC_SNIPPET_ADD_SELECTION 178 | MENUITEM "Add from &clipboard...", IDC_SNIPPET_ADD_CLIPBOARD 179 | //MENUITEM SEPARATOR 180 | //MENUITEM "Copy to another library...", IDC_SNIPPET_COPY_TO_LIB 181 | //MENUITEM "Paste from another library...", IDC_SNIPPET_PASTE_FROM_LIB 182 | MENUITEM SEPARATOR 183 | MENUITEM "Move &up...", IDC_SNIPPET_MOVE_UP 184 | MENUITEM "Move d&own...", IDC_SNIPPET_MOVE_DOWN 185 | END 186 | END 187 | 188 | IDCM_LIBRARY MENU PRELOAD DISCARDABLE 189 | BEGIN 190 | POPUP "_POPUP_" 191 | BEGIN 192 | MENUITEM "&New library...", IDC_LIB_NEW 193 | MENUITEM "&Edit library...", IDC_LIB_EDIT 194 | MENUITEM "&Delete library...", IDC_LIB_DELETE 195 | MENUITEM SEPARATOR 196 | MENUITEM "&Languages...", IDC_LIB_LANGUAGES 197 | MENUITEM SEPARATOR 198 | MENUITEM "&Import library...", IDC_LIB_IMPORT 199 | MENUITEM "&Export library...", IDC_LIB_EXPORT 200 | END 201 | END 202 | 203 | ///////////////////////////////////////////////////////////////////////////// 204 | // Bitmaps 205 | 206 | IDB_SNIPPETS BITMAP DISCARDABLE "Res/MainToolbar_Snippets.bmp" 207 | 208 | ///////////////////////////////////////////////////////////////////////////// 209 | // Icons 210 | 211 | IDI_SNIPPETS ICON DISCARDABLE "Res/Snippets.ico" 212 | -------------------------------------------------------------------------------- /Options.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2020 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include "Options.h" 24 | #include "NPP/PluginInterface.h" 25 | #include "NppSnippets.h" 26 | #include "version_git.h" 27 | 28 | ///////////////////////////////////////////////////////////////////////////// 29 | // Strings used in the ini file 30 | 31 | static WCHAR s_szOptions[] = L"Options"; 32 | static WCHAR s_szShow[] = L"Show"; 33 | static WCHAR s_szToolbarIcon[] = L"ToolbarIcon"; 34 | static WCHAR s_szIndent[] = L"Indent"; 35 | static WCHAR s_szVersion[] = L"Version"; 36 | static WCHAR s_szDBFile[] = L"DBFile"; 37 | 38 | ///////////////////////////////////////////////////////////////////////////// 39 | // Constructor: read the settings 40 | 41 | Options::Options() noexcept : NppOptions() 42 | { 43 | // Read the settings from the file 44 | Read(); 45 | } 46 | 47 | Options::Options(std::wstring filename) : NppOptions(filename) 48 | { 49 | // Read the settings from the file 50 | Read(); 51 | } 52 | 53 | ///////////////////////////////////////////////////////////////////////////// 54 | // Destructor: write the settings 55 | 56 | Options::~Options() 57 | { 58 | Write(); 59 | } 60 | 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // Write the options to the ini-file 63 | 64 | void Options::Write() 65 | { 66 | WriteBool(s_szOptions, s_szShow, _showConsoleDlg); 67 | WriteBool(s_szOptions, s_szToolbarIcon, _toolbarIcon); 68 | WriteBool(s_szOptions, s_szIndent, _indentSnippet); 69 | WriteString(s_szOptions, s_szDBFile, _DBFile.c_str()); 70 | WriteString(s_szOptions, s_szVersion, VERSION_NUMBER_WSTR); 71 | } 72 | 73 | ///////////////////////////////////////////////////////////////////////////// 74 | // Read the options from the ini-file 75 | 76 | void Options::Read() 77 | { 78 | _showConsoleDlg = GetBool(s_szOptions, s_szShow, true); 79 | _toolbarIcon = GetBool(s_szOptions, s_szToolbarIcon, true); 80 | _indentSnippet = GetBool(s_szOptions, s_szIndent, true); 81 | _prevVersion = GetString(s_szOptions, s_szVersion, L""); 82 | _DBFile = GetString(s_szOptions, s_szDBFile, L""); 83 | } 84 | -------------------------------------------------------------------------------- /Options.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2020 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include "NppOptions.h" 25 | 26 | ///////////////////////////////////////////////////////////////////////////// 27 | // 28 | 29 | class Options : public NppOptions 30 | { 31 | public: 32 | Options() noexcept; 33 | Options(std::wstring filename); 34 | ~Options(); 35 | 36 | bool GetToolbarIcon() noexcept { return _toolbarIcon; }; 37 | bool GetIndentSnippet() noexcept { return _indentSnippet; }; 38 | bool GetShowConsoleDlg() noexcept { return _showConsoleDlg; }; 39 | std::wstring GetPrevVersion() { return _prevVersion; }; 40 | std::wstring GetDBFile() { return _DBFile; }; 41 | 42 | void SetToolbarIcon(bool b) noexcept { _toolbarIcon = b; }; 43 | void SetIndentSnippet(bool b) noexcept { _indentSnippet = b; }; 44 | void SetShowConsoleDlg(bool b) noexcept { _showConsoleDlg = b; }; 45 | void SetDBFile(std::wstring s) { _DBFile = s; }; 46 | 47 | void Write(); 48 | void Read(); 49 | 50 | private: 51 | std::wstring _prevVersion; 52 | std::wstring _DBFile; 53 | bool _toolbarIcon; 54 | bool _indentSnippet; 55 | bool _showConsoleDlg; 56 | }; 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NppSnippets 2 | =========== 3 | 4 | NppSnippets is an easy to use snippet / template plug-in for [Notepad++](https://notepad-plus-plus.org/). Similarity with the TextPad Clip Library is no accident. To insert a snippet simply double click on the item in the list and the snippet is inserted at the current cursor position. To edit right-click on that item. 5 | 6 | The documentation of this plug-in can be found at [Read the Docs](https://nppsnippets.readthedocs.io/). This includes: 7 | 8 | * Instructions [how to install](https://nppsnippets.readthedocs.io/en/latest/installation.html) 9 | * Instructions [how to use](https://nppsnippets.readthedocs.io/en/latest/usage.html) 10 | * Instructions [how to build](https://nppsnippets.readthedocs.io/en/latest/compile.html) 11 | * A complete [changelog](https://nppsnippets.readthedocs.io/en/latest/changelog.html) 12 | -------------------------------------------------------------------------------- /Res/MainToolbar_Snippets.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/Res/MainToolbar_Snippets.bmp -------------------------------------------------------------------------------- /Res/Snippets.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/Res/Snippets.ico -------------------------------------------------------------------------------- /Resource.h: -------------------------------------------------------------------------------- 1 | #ifndef RESOURCE_H 2 | #define RESOURCE_H 3 | 4 | #ifndef IDC_STATIC 5 | #define IDC_STATIC -1 6 | #endif 7 | 8 | // About dialog 9 | #define IDD_ABOUTBOX 250 10 | #define IDC_SYSLINK 251 11 | 12 | // Various 13 | #define IDB_SNIPPETS 260 14 | #define IDI_SNIPPETS 261 15 | 16 | // Snippets Console/Main dialog 17 | #define IDD_SNIPPETS 3000 18 | #define IDC_LIST 3001 19 | #define IDC_FILTER 3002 20 | #define IDC_NAME 3003 21 | 22 | // Edit Snippet dialog 23 | #define IDD_EDIT_SNIPPET 3100 24 | #define IDC_BEFORE_SEL 3101 25 | #define IDC_REPLACE_SEL 3102 26 | #define IDC_AFTER_SEL 3103 27 | #define IDC_NEW_DOC 3104 28 | #define IDC_NEW_DOC_LANG 3105 29 | #define IDC_BEFORE_SEL_TXT 3106 30 | #define IDC_AFTER_SEL_TXT 3107 31 | 32 | // Edit Library dialog 33 | #define IDD_EDIT_LIBRARY 3200 34 | #define IDC_CREATED_BY 3201 35 | #define IDC_COMMENTS 3202 36 | #define IDC_SORT_ALPHABET 3203 37 | 38 | // Edit Languages dialog 39 | #define IDD_EDIT_LANGUAGES 3300 40 | #define IDC_LANG_LIST 3301 41 | 42 | // Import Library dailog 43 | #define IDD_IMPORT_LIBRARY 3400 44 | 45 | // Options dailog 46 | #define IDD_OPTIONS 3500 47 | #define IDC_TOOLBAR_ICON 3501 48 | #define IDC_INDENT_SNIPPET 3502 49 | #define IDC_DBFILE 3503 50 | #define IDC_BROWSE 3504 51 | 52 | // Context Menu Snippet 53 | #define IDCM_SNIPPET 4000 54 | #define IDC_SNIPPET_INSERT 4001 55 | #define IDC_SNIPPET_ADD 4002 56 | #define IDC_SNIPPET_EDIT 4003 57 | #define IDC_SNIPPET_DELETE 4004 58 | #define IDC_SNIPPET_MOVE_UP 4005 59 | #define IDC_SNIPPET_MOVE_DOWN 4006 60 | #define IDC_SNIPPET_ADD_CLIPBOARD 4007 61 | #define IDC_SNIPPET_ADD_SELECTION 4008 62 | #define IDC_SNIPPET_COPY_TO_LIB 4009 63 | #define IDC_SNIPPET_PASTE_FROM_LIB 4010 64 | #define IDC_SNIPPET_DUPLICATE 4011 65 | 66 | // Context Menu Library 67 | #define IDCM_LIBRARY 4100 68 | #define IDC_LIB_NEW 4101 69 | #define IDC_LIB_EDIT 4102 70 | #define IDC_LIB_DELETE 4103 71 | #define IDC_LIB_LANGUAGES 4104 72 | #define IDC_LIB_IMPORT 4105 73 | #define IDC_LIB_EXPORT 4106 74 | 75 | #endif // RESOURCE_H 76 | -------------------------------------------------------------------------------- /Snippets.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include 24 | #include 25 | #include "NPP/PluginInterface.h" 26 | #include "NppSnippets.h" 27 | 28 | #include "Snippets.h" 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | // 32 | 33 | void SnippetBase::WSetName(LPCWCH txt) 34 | { 35 | if (_Name != NULL) 36 | free(_Name); 37 | 38 | _Name = (txt == NULL ? NULL : wcsdup(txt)); 39 | } 40 | 41 | ///////////////////////////////////////////////////////////////////////////// 42 | // 43 | 44 | Snippet::Snippet() 45 | { 46 | _SnippetID = 0; 47 | _LibraryID = 0; 48 | _Name = NULL; 49 | _BeforeSelection = NULL; 50 | _AfterSelection = NULL; 51 | _ReplaceSelection = false; 52 | _NewDocument = false; 53 | _NewDocumentLang = L_EXTERNAL; 54 | _Sort = 0; 55 | } 56 | 57 | Snippet::Snippet(SqliteStatement* stmt) 58 | { 59 | _Name = NULL; 60 | _BeforeSelection = NULL; 61 | _AfterSelection = NULL; 62 | Set(stmt); 63 | } 64 | 65 | /////////////////////////////////////////////////////////////////////////// 66 | // Copy-Constructor. 67 | 68 | Snippet::Snippet(const Snippet& copy) 69 | { 70 | _SnippetID = 0; 71 | _Name = NULL; 72 | _BeforeSelection = NULL; 73 | _AfterSelection = NULL; 74 | CopyValues(copy); 75 | } 76 | 77 | Snippet::~Snippet() 78 | { 79 | if (_Name != NULL) 80 | free(_Name); 81 | if (_BeforeSelection != NULL) 82 | free(_BeforeSelection); 83 | if (_AfterSelection != NULL) 84 | free(_AfterSelection); 85 | } 86 | 87 | /////////////////////////////////////////////////////////////////////////// 88 | // Overloads of the '=' operator 89 | 90 | Snippet& Snippet::operator=(const Snippet& copy) 91 | { 92 | CopyValues(copy); 93 | return(*this); 94 | } 95 | 96 | Snippet& Snippet::operator=(SqliteStatement* stmt) 97 | { 98 | Set(stmt); 99 | return(*this); 100 | } 101 | 102 | ///////////////////////////////////////////////////////////////////////////// 103 | // 104 | 105 | void Snippet::CopyValues(const Snippet& copy) 106 | { 107 | //_SnippetID = copy._SnippetID; 108 | _LibraryID = copy._LibraryID; 109 | WSetName(copy._Name); 110 | WSetBeforeSelection(copy._BeforeSelection); 111 | WSetAfterSelection(copy._AfterSelection); 112 | _ReplaceSelection = copy._ReplaceSelection; 113 | _NewDocument = copy._NewDocument; 114 | _NewDocumentLang = copy._NewDocumentLang; 115 | _Sort = copy._Sort; 116 | } 117 | 118 | ///////////////////////////////////////////////////////////////////////////// 119 | // 120 | 121 | void Snippet::WSetBeforeSelection(LPCWCH txt) 122 | { 123 | if (_BeforeSelection != NULL) 124 | free(_BeforeSelection); 125 | 126 | _BeforeSelection = (txt == NULL ? NULL : wcsdup(txt)); 127 | } 128 | 129 | void Snippet::WSetAfterSelection(LPCWCH txt) 130 | { 131 | if (_AfterSelection != NULL) 132 | free(_AfterSelection); 133 | 134 | _AfterSelection = (txt == NULL ? NULL : wcsdup(txt)); 135 | } 136 | 137 | void Snippet::SetBeforeSelection(LPCSTR txt) 138 | { 139 | if (txt == NULL) 140 | { 141 | WSetBeforeSelection(NULL); 142 | return; 143 | } 144 | 145 | size_t len = strlen(txt); 146 | if (len == 0) 147 | { 148 | WSetBeforeSelection(NULL); 149 | return; 150 | } 151 | 152 | // Convert from UTF-8 to WCHAR and store 153 | size_t sizeInChars = MultiByteToWideChar(CP_UTF8, 0, txt, (int) (len + 1), NULL, 0); 154 | WCHAR* wBuffer = (WCHAR*) malloc(sizeInChars * sizeof(WCHAR)); 155 | ZeroMemory(wBuffer, sizeInChars * sizeof(WCHAR)); 156 | MultiByteToWideChar(CP_UTF8, 0, txt, (int) (len + 1), wBuffer, (int)sizeInChars); 157 | WSetBeforeSelection(wBuffer); 158 | free(wBuffer); 159 | } 160 | 161 | /////////////////////////////////////////////////////////////////////////////// 162 | // Convert the Unicode-string to an Ansi-string 163 | 164 | LPSTR Snippet::Unicode2Ansi(LPCWSTR wszStr) 165 | { 166 | size_t len = wcslen(wszStr); 167 | size_t size = sizeof(char) * (len + 3); 168 | 169 | char* buffer = (char*) malloc(size); 170 | ZeroMemory(buffer, size); 171 | 172 | if (wszStr != NULL) 173 | WideCharToMultiByte(CP_ACP, 0, wszStr, -1, buffer, (int) len, NULL, NULL); 174 | 175 | return buffer; 176 | } 177 | 178 | ///////////////////////////////////////////////////////////////////////////// 179 | // 180 | 181 | void Snippet::Set(SqliteStatement* stmt) 182 | { 183 | _SnippetID = stmt->GetIntColumn("SnippetID"); 184 | _LibraryID = stmt->GetIntColumn("LibraryID"); 185 | WSetName(stmt->GetWTextColumn("Name").c_str()); 186 | WSetBeforeSelection(stmt->GetWTextColumn("BeforeSelection").c_str()); 187 | WSetAfterSelection(stmt->GetWTextColumn("AfterSelection").c_str()); 188 | SetReplaceSelection(stmt->GetIntColumn("ReplaceSelection")); 189 | SetNewDocument(stmt->GetIntColumn("NewDocument")); 190 | SetSort(stmt->GetIntColumn("Sort")); 191 | 192 | // Get the language for a new document 193 | _NewDocumentLang = (LangType) stmt->GetIntColumn("NewDocumentLang"); 194 | if (_NewDocumentLang == 0) 195 | { 196 | //if (sqlite3_column_type(stmt, cNames["NewDocumentLang"]) == SQLITE_NULL) 197 | //{ 198 | // _NewDocumentLang = L_EXTERNAL; 199 | //} 200 | } 201 | } 202 | 203 | ///////////////////////////////////////////////////////////////////////////// 204 | // Save the snippet to the database 205 | 206 | void Snippet::SaveToDB(bool autoOpen) 207 | { 208 | // Try to open the database 209 | g_db->Open(); 210 | 211 | // Saving a new record or updating an existing? 212 | SqliteStatement stmt(g_db); 213 | 214 | bool adding = false; 215 | if (_SnippetID == 0) 216 | { 217 | adding = true; 218 | 219 | // Determine the last used SnippetID 220 | SqliteStatement stmt2(g_db, "SELECT MAX(SnippetID) AS MaxID FROM Snippets"); 221 | stmt2.GetNextRecord(); 222 | _SnippetID = stmt2.GetIntColumn("MaxID") + 1; 223 | stmt2.Finalize(); 224 | 225 | // Prepare the statement 226 | stmt.Prepare("INSERT INTO Snippets(SnippetID, LibraryID, Name, BeforeSelection, AfterSelection, ReplaceSelection, NewDocument, NewDocumentLang, Sort) VALUES (@id, @libid, @name, @before, @after, @replace, @newdoc, @newdoclang, @sort)"); 227 | } 228 | else 229 | { 230 | // Prepare the statement 231 | stmt.Prepare("UPDATE Snippets SET Name = @name, BeforeSelection = @before, AfterSelection = @after, ReplaceSelection = @replace, NewDocument = @newdoc, NewDocumentLang = @newdoclang, Sort = @sort WHERE SnippetID = @id"); 232 | } 233 | 234 | // Bind the values to the parameters 235 | stmt.Bind("@id", _SnippetID); 236 | if (adding) 237 | stmt.Bind("@libid", _LibraryID); 238 | stmt.Bind("@name", _Name); 239 | stmt.Bind("@before", _BeforeSelection); 240 | stmt.Bind("@after", _AfterSelection); 241 | stmt.Bind("@replace", GetReplaceSelectionInt()); 242 | stmt.Bind("@newdoc", GetNewDocumentInt()); 243 | stmt.Bind("@newdoclang", _NewDocumentLang, _NewDocumentLang == L_EXTERNAL); 244 | stmt.Bind("@sort", _Sort, _Sort == 0); 245 | 246 | stmt.SaveRecord(); 247 | stmt.Finalize(); 248 | 249 | if (autoOpen) 250 | g_db->Close(); 251 | } 252 | 253 | ///////////////////////////////////////////////////////////////////////////// 254 | // Delete the snippet from the database 255 | 256 | void Snippet::DeleteFromDB() 257 | { 258 | // Try to open the database 259 | g_db->Open(); 260 | 261 | SqliteStatement stmt(g_db, "DELETE FROM Snippets WHERE SnippetID = @id"); 262 | stmt.Bind("@id", _SnippetID); 263 | stmt.SaveRecord(); 264 | stmt.Finalize(); 265 | 266 | g_db->Close(); 267 | } 268 | 269 | ///////////////////////////////////////////////////////////////////////////// 270 | // Guess the name of the snippet based upon the context of _BeforeSelection 271 | 272 | void Snippet::GuessName() 273 | { 274 | // If the name already set, do nothing 275 | if (_Name != NULL) 276 | return; 277 | 278 | // Is there a text to analyse? 279 | if (_BeforeSelection == NULL) 280 | return; 281 | 282 | // First, try to find the first line containing text and use that as Name 283 | bool foundChar = false; 284 | WCHAR* p = _BeforeSelection; 285 | WCHAR* start = _BeforeSelection; 286 | while (*p) 287 | { 288 | // Did we run into a space character? 289 | if (isspace(*p)) 290 | { 291 | // Did we already find any normal character 292 | if (foundChar) 293 | { 294 | // Did we run into the end of the line 295 | if (*p == '\r' || *p == '\n') 296 | break; 297 | } 298 | } 299 | else 300 | { 301 | // Is the first normal character, store it's position 302 | if (!foundChar) 303 | { 304 | start = p; 305 | foundChar = true; 306 | } 307 | } 308 | p++; 309 | } 310 | // If we didn't find any normal character, we're done 311 | if (!foundChar) 312 | return; 313 | 314 | // Now see if this text is not too long and therefore becomes impractible 315 | size_t len = ((size_t) p - (size_t) start) / sizeof(WCHAR); 316 | if (len > 50) 317 | len = 50; 318 | 319 | // Finally we can set the Name 320 | size_t size = sizeof(WCHAR) * (len + 3); 321 | WCHAR* tmp = (WCHAR*) malloc(size); 322 | ZeroMemory(tmp, size); 323 | memcpy(tmp, start, sizeof(WCHAR) * len); 324 | WSetName(tmp); 325 | free(tmp); 326 | } 327 | -------------------------------------------------------------------------------- /Snippets.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include "SnippetsDB.h" 25 | 26 | class SnippetBase 27 | { 28 | public: 29 | int GetLibraryID() { return _LibraryID; } 30 | WCHAR* WGetName() { return _Name; } 31 | 32 | virtual void Set(SqliteStatement* stmt) = 0; 33 | void SetLibraryID(int i) { _LibraryID = i; } 34 | void WSetName(LPCWCH txt); 35 | 36 | virtual void SaveToDB(bool autoOpen = true) = 0; 37 | virtual void DeleteFromDB() = 0; 38 | 39 | protected: 40 | int _LibraryID; 41 | WCHAR* _Name; 42 | }; 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // 46 | 47 | class Snippet : public SnippetBase 48 | { 49 | public: 50 | Snippet(); 51 | Snippet(SqliteStatement* stmt); 52 | Snippet(const Snippet&); 53 | 54 | virtual ~Snippet(); 55 | 56 | Snippet& operator=(const Snippet&); 57 | Snippet& operator=(SqliteStatement* stmt); 58 | void Set(SqliteStatement* stmt) override; 59 | 60 | int GetSnippetID() { return _SnippetID; } 61 | WCHAR* WGetBeforeSelection() { return _BeforeSelection; } 62 | WCHAR* WGetAfterSelection() { return _AfterSelection; } 63 | char* GetBeforeSelection() { return Unicode2Ansi(_BeforeSelection); } 64 | char* GetAfterSelection() { return Unicode2Ansi(_AfterSelection); } 65 | bool GetReplaceSelection() { return _ReplaceSelection; } 66 | bool GetNewDocument() { return _NewDocument; } 67 | LangType GetNewDocumentLang() { return _NewDocumentLang; } 68 | int GetSort() { return _Sort; } 69 | 70 | void SetSnippetID(int i) { _SnippetID = i; } 71 | void WSetBeforeSelection(LPCWCH txt); 72 | void WSetAfterSelection(LPCWCH txt); 73 | void SetBeforeSelection(LPCSTR txt); 74 | void SetReplaceSelection(bool b) { _ReplaceSelection = b; } 75 | void SetReplaceSelection(int i) { _ReplaceSelection = (i != 0); } 76 | void SetNewDocument(bool b) { _NewDocument = b; } 77 | void SetNewDocument(int i) { _NewDocument = (i != 0); } 78 | void SetNewDocumentLang(int i) { _NewDocumentLang = (LangType) i; } 79 | void SetSort(int i) { _Sort = i; } 80 | 81 | void SaveToDB(bool autoOpen = true) override; 82 | void DeleteFromDB() override; 83 | 84 | void GuessName(); 85 | 86 | private: 87 | int _SnippetID; 88 | WCHAR* _BeforeSelection; 89 | WCHAR* _AfterSelection; 90 | bool _ReplaceSelection; 91 | bool _NewDocument; 92 | LangType _NewDocumentLang; 93 | int _Sort; 94 | 95 | void CopyValues(const Snippet&); 96 | int GetReplaceSelectionInt() { return _ReplaceSelection ? 1 : 0; } 97 | int GetNewDocumentInt() { return _NewDocument ? 1 : 0; } 98 | 99 | LPSTR Unicode2Ansi(LPCWSTR wszStr); 100 | }; 101 | -------------------------------------------------------------------------------- /SnippetsDB.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2013 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include "NPP/PluginInterface.h" 24 | #include "NppSnippets.h" 25 | #include "SnippetsDB.h" 26 | #include "Library.h" 27 | #include "WaitCursor.h" 28 | 29 | SnippetsDB* g_db = NULL; 30 | 31 | ///////////////////////////////////////////////////////////////////////////// 32 | // 33 | 34 | SnippetsDB::SnippetsDB() : SqliteDatabase() 35 | { 36 | SetValues(); 37 | } 38 | 39 | SnippetsDB::SnippetsDB(LPCWSTR file) : SqliteDatabase(file) 40 | { 41 | SetValues(); 42 | } 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | // Nothing is set yet 46 | 47 | void SnippetsDB::SetValues() 48 | { 49 | } 50 | 51 | ///////////////////////////////////////////////////////////////////////////// 52 | // 53 | 54 | void SnippetsDB::Open() 55 | { 56 | if (_db == NULL) 57 | SqliteDatabase::Open(); 58 | 59 | // Make sure the database has the right version 60 | if (!CheckDBVersion()) 61 | { 62 | throw SqliteException("Database has wrong version, please regenerate!"); 63 | return; 64 | } 65 | 66 | EnableForeignKeys(); 67 | } 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | // 71 | 72 | void SnippetsDB::ImportLibrary(LPCWSTR db, int orgLibID) 73 | { 74 | // Start with attaching the database 75 | Attach(db, L"Import"); 76 | 77 | // Get requested library from that database 78 | SqliteStatement stmt(this, "SELECT * FROM Import.Library WHERE LibraryID = @id"); 79 | stmt.Bind("@id", orgLibID); 80 | 81 | if (stmt.GetNextRecord()) 82 | { 83 | Library lib(&stmt); 84 | 85 | lib.SetLibraryID(0); 86 | lib.SaveToDB(false); 87 | 88 | ImportSnippets(orgLibID, lib.GetLibraryID()); 89 | ImportLanguages(orgLibID, lib.GetLibraryID()); 90 | } 91 | stmt.Finalize(); 92 | 93 | Detach(L"Import"); 94 | } 95 | 96 | ///////////////////////////////////////////////////////////////////////////// 97 | // 98 | 99 | void SnippetsDB::ImportSnippets(int orgLibID, int newLibID) 100 | { 101 | // Get all the snippets from the attached database 102 | SqliteStatement stmt(g_db, "SELECT * FROM Import.Snippets WHERE LibraryID = @libid"); 103 | stmt.Bind("@libid", orgLibID); 104 | 105 | // Go through the records and save them to the database 106 | Snippet snip; 107 | while (stmt.GetNextRecord()) 108 | { 109 | snip.Set(&stmt); 110 | snip.SetSnippetID(0); 111 | snip.SetLibraryID(newLibID); 112 | snip.SaveToDB(false); 113 | } 114 | stmt.Finalize(); 115 | } 116 | 117 | ///////////////////////////////////////////////////////////////////////////// 118 | // 119 | 120 | void SnippetsDB::ImportLanguages(int orgLibID, int newLibID) 121 | { 122 | // Get all the languages for this library from the attached database 123 | SqliteStatement stmtSelect(g_db, "SELECT Lang FROM Import.LibraryLang WHERE LibraryID = @libid"); 124 | stmtSelect.Bind("@libid", orgLibID); 125 | 126 | // Open a select stmt to store the new data in the table 127 | SqliteStatement stmtInsert(g_db, "INSERT INTO LibraryLang(LibraryID, Lang) VALUES (@libid, @lang)"); 128 | 129 | // Go through the attached records and save them to the database 130 | while (stmtSelect.GetNextRecord()) 131 | { 132 | stmtInsert.Bind("@libid", newLibID); 133 | stmtInsert.Bind("@lang", stmtSelect.GetIntColumn(0)); 134 | 135 | // Put the record in the database 136 | stmtInsert.SaveRecord(); 137 | } 138 | stmtSelect.Finalize(); 139 | stmtInsert.Finalize(); 140 | } 141 | 142 | ///////////////////////////////////////////////////////////////////////////// 143 | // Create the export database 144 | 145 | void SnippetsDB::CreateExportDB() 146 | { 147 | BeginTransaction(); 148 | Execute("CREATE TABLE IF NOT EXISTS Export.Library(LibraryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, Name TEXT NOT NULL, CreatedBy TEXT, Comments TEXT, SortBy INTEGER NOT NULL DEFAULT 0);"); 149 | Execute("CREATE TABLE IF NOT EXISTS Export.LibraryLang(LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE, Lang INTEGER NOT NULL, PRIMARY KEY (LibraryID, Lang));"); 150 | Execute("CREATE TABLE IF NOT EXISTS Export.Snippets(SnippetID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE, Name TEXT NOT NULL, BeforeSelection TEXT NOT NULL, AfterSelection TEXT, ReplaceSelection BOOL NOT NULL DEFAULT 0, NewDocument BOOL NOT NULL DEFAULT 0, NewDocumentLang INTEGER, Sort INTEGER);"); 151 | Execute("CREATE INDEX IF NOT EXISTS Export.SnipName ON Snippets(LibraryID, Name, Sort);"); 152 | Execute("CREATE INDEX IF NOT EXISTS Export.SnipSort ON Snippets(LibraryID, Sort, Name);"); 153 | Execute("CREATE TABLE IF NOT EXISTS Export.LangLastUsed(Lang INTEGER PRIMARY KEY NOT NULL, LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE);"); 154 | CommitTransaction(); 155 | 156 | // We are at schema version 3 157 | SetUserVersion(3, "Export"); 158 | } 159 | 160 | ///////////////////////////////////////////////////////////////////////////// 161 | // Upgrade the database from schema version 1 to 2 162 | 163 | void SnippetsDB::UpgradeDatabase_1_2() 164 | { 165 | // Create the LibraryLang table and fill it 166 | BeginTransaction(); 167 | Execute("CREATE TABLE LibraryLang(LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE,Lang INTEGER NOT NULL,LastUsed BOOL NOT NULL DEFAULT 0,PRIMARY KEY (LibraryID, Lang));"); 168 | Execute("INSERT INTO LibraryLang SELECT LibraryID, Lang, LastUsed FROM Library;"); 169 | CommitTransaction(); 170 | 171 | // Delete the "Lang" and "LastUsed" column from the Library table 172 | BeginTransaction(); 173 | Execute("DROP INDEX LibLang;"); // Index not needed anymore 174 | Execute("CREATE TEMPORARY TABLE Library_backup(LibraryID INTEGER,Name TEXT,CreatedBy TEXT,Comments TEXT,SortBy INTEGER);"); 175 | Execute("INSERT INTO Library_backup SELECT LibraryID,Name,CreatedBy,Comments,SortBy FROM Library;"); 176 | Execute("DROP TABLE Library;"); 177 | Execute("CREATE TABLE Library (LibraryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,Name TEXT NOT NULL,CreatedBy TEXT,Comments TEXT,SortBy INTEGER NOT NULL DEFAULT 0);"); 178 | Execute("INSERT INTO Library SELECT LibraryID,Name,CreatedBy,Comments,SortBy FROM Library_backup;"); 179 | Execute("DROP TABLE Library_backup;"); 180 | CommitTransaction(); 181 | 182 | // Throw away these old indices. New ones will be created later 183 | Execute("DROP INDEX SnipName;"); 184 | Execute("DROP INDEX SnipSort;"); 185 | 186 | // Add a primary key table to Snippets 187 | BeginTransaction(); 188 | Execute("CREATE TEMPORARY TABLE Snippets_backup(LibraryID INTEGER,Name TEXT,BeforeSelection TEXT,AfterSelection TEXT,ReplaceSelection BOOL,NewDocument BOOL,NewDocumentLang INTEGER,Sort INTEGER);"); 189 | Execute("INSERT INTO Snippets_backup SELECT LibraryID,Name,BeforeSelection,AfterSelection,ReplaceSelection,NewDocument,NewDocumentLang,Sort FROM Snippets;"); 190 | Execute("DROP TABLE Snippets;"); 191 | Execute("CREATE TABLE Snippets(SnippetID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE,Name TEXT NOT NULL,BeforeSelection TEXT NOT NULL,AfterSelection TEXT,ReplaceSelection BOOL NOT NULL DEFAULT 0,NewDocument BOOL NOT NULL DEFAULT 0,NewDocumentLang INTEGER,Sort INTEGER);"); 192 | Execute("INSERT INTO Snippets(LibraryID,Name,BeforeSelection,AfterSelection,ReplaceSelection,NewDocument,NewDocumentLang,Sort) SELECT LibraryID,Name,BeforeSelection,AfterSelection,ReplaceSelection,NewDocument,NewDocumentLang,Sort FROM Snippets_backup;"); 193 | Execute("DROP TABLE Snippets_backup;"); 194 | CommitTransaction(); 195 | 196 | // Create new indices 197 | Execute("CREATE INDEX SnipName ON Snippets(LibraryID, Name, Sort);"); 198 | Execute("CREATE INDEX SnipSort ON Snippets(LibraryID, Sort, Name);"); 199 | 200 | // We are at schema version 2 201 | SetUserVersion(2); 202 | } 203 | 204 | ///////////////////////////////////////////////////////////////////////////// 205 | // Upgrade the database from schema version 2 to 3 206 | 207 | void SnippetsDB::UpgradeDatabase_2_3() 208 | { 209 | // Add the new tabel to store which library is last used for with language 210 | BeginTransaction(); 211 | Execute("CREATE TABLE LangLastUsed(Lang INTEGER PRIMARY KEY NOT NULL,LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE);"); 212 | Execute("INSERT INTO LangLastUsed SELECT Lang,LibraryID FROM LibraryLang WHERE LastUsed = 1;"); 213 | CommitTransaction(); 214 | 215 | // Delete the LastUsed column from the LibraryLang table 216 | BeginTransaction(); 217 | Execute("CREATE TEMPORARY TABLE LibraryLang_backup(LibraryID INTEGER,Lang INTEGER);"); 218 | Execute("INSERT INTO LibraryLang_backup SELECT LibraryID, Lang FROM LibraryLang;"); 219 | Execute("DROP TABLE LibraryLang;"); 220 | Execute("CREATE TABLE LibraryLang(LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE,Lang INTEGER NOT NULL,PRIMARY KEY (LibraryID, Lang));"); 221 | Execute("INSERT INTO LibraryLang SELECT LibraryID, Lang FROM LibraryLang_backup;"); 222 | Execute("DROP TABLE LibraryLang_backup;"); 223 | CommitTransaction(); 224 | 225 | // We are at schema version 3 226 | SetUserVersion(3); 227 | } 228 | 229 | ///////////////////////////////////////////////////////////////////////////// 230 | // 231 | 232 | bool SnippetsDB::CheckDBVersion() 233 | { 234 | WaitCursor wait(false); 235 | switch (GetUserVersion()) 236 | { 237 | case 0: 238 | // Database probably not found 239 | return false; 240 | 241 | case 1: 242 | wait.Show(); 243 | UpgradeDatabase_1_2(); 244 | // fall through 245 | 246 | case 2: 247 | wait.Show(); 248 | UpgradeDatabase_2_3(); 249 | Vacuum(); 250 | // fall through 251 | 252 | case 3: 253 | // The right version! 254 | return true; 255 | } 256 | 257 | // Running with an newer database! 258 | return false; 259 | } 260 | -------------------------------------------------------------------------------- /SnippetsDB.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2013 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | #include "SqliteDB.h" 25 | 26 | class SnippetsDB : public SqliteDatabase 27 | { 28 | public: 29 | SnippetsDB(); 30 | SnippetsDB(LPCWSTR file); 31 | 32 | virtual void Open(); 33 | void CreateExportDB(); 34 | 35 | void ImportLibrary(LPCWSTR db, int orgLibID); 36 | 37 | protected: 38 | void SetValues(); 39 | void UpgradeDatabase_1_2(); 40 | void UpgradeDatabase_2_3(); 41 | bool CheckDBVersion(); 42 | 43 | void ImportSnippets(int orgLibID, int newLibID); 44 | void ImportLanguages(int orgLibID, int newLibID); 45 | }; 46 | 47 | extern SnippetsDB* g_db; 48 | -------------------------------------------------------------------------------- /SqliteDB.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // SqliteDB Classes // 4 | // Version 1.1, 16-Nov-2015 // 5 | // // 6 | // Copyright (c) 2013-2015, Frank Fesevur // 7 | // All rights reserved. // 8 | // // 9 | // Redistribution and use in source and binary forms, with or without // 10 | // modification, are permitted provided that the following conditions // 11 | // are met: // 12 | // // 13 | // 1. Redistributions of source code must retain the above copyright // 14 | // notice, this list of conditions and the following disclaimer. // 15 | // 2. Redistributions in binary form must reproduce the above copyright // 16 | // notice, this list of conditions and the following disclaimer in the // 17 | // documentation and/or other materials provided with the distribution. // 18 | // // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 30 | // // 31 | ///////////////////////////////////////////////////////////////////////////// 32 | 33 | #pragma once 34 | 35 | #include 36 | #include 37 | #include 38 | #include "sqlite3.h" 39 | 40 | class SqliteException : public std::runtime_error 41 | { 42 | public: 43 | SqliteException(const std::string& errorMessage) : std::runtime_error(errorMessage) 44 | { 45 | } 46 | }; 47 | 48 | class SqliteDatabase 49 | { 50 | public: 51 | SqliteDatabase(); 52 | SqliteDatabase(LPCWSTR file); 53 | virtual ~SqliteDatabase(); 54 | 55 | virtual void Open(); 56 | virtual void Open(LPCWSTR file); 57 | void Close(); 58 | void Delete(); 59 | void Vacuum(); 60 | 61 | void Attach(LPCWSTR file, LPCWSTR alias); 62 | void Detach(LPCWSTR alias); 63 | 64 | void SetFilename(LPCWSTR file); 65 | void SetUserVersion(long version, const char* dbname = nullptr); 66 | 67 | const std::wstring GetFilename() { return _dbFile; }; 68 | long GetUserVersion(const char* dbname = nullptr); 69 | bool TableExists(const char* table); 70 | sqlite3* GetDB() { return _db; }; 71 | 72 | void EnableForeignKeys(bool on = true); 73 | 74 | void Execute(LPCSTR szSQL); 75 | void BeginTransaction(); 76 | void CommitTransaction(); 77 | void RollbackTransaction(); 78 | 79 | protected: 80 | std::wstring _dbFile; 81 | sqlite3* _db; 82 | }; 83 | 84 | class SqliteStatement 85 | { 86 | public: 87 | SqliteStatement(SqliteDatabase* db); 88 | SqliteStatement(SqliteDatabase* db, const char* sql); 89 | virtual ~SqliteStatement(); 90 | 91 | void Prepare(const char* sql); 92 | void Reset(); 93 | void SaveRecord(); 94 | bool GetNextRecord(); 95 | void Finalize(); 96 | 97 | int GetColumnCount(); 98 | std::string GetTextColumn(int col); 99 | std::string GetTextColumn(std::string col); 100 | std::wstring GetWTextColumn(int col); 101 | std::wstring GetWTextColumn(std::string col); 102 | int GetIntColumn(int col); 103 | int GetIntColumn(std::string col); 104 | bool GetBoolColumn(int col); 105 | bool GetBoolColumn(std::string col); 106 | int GetBindParameterIndex(std::string col); 107 | 108 | void Bind(const char* param, const WCHAR* val); 109 | void Bind(const char* param, const char *val); 110 | void Bind(const char* param, int val, bool null = false); 111 | void Bind(const char* param, bool val); 112 | void Bind(const char* param); 113 | 114 | void Bind(int col, const WCHAR* val); 115 | void Bind(int col, const char *val); 116 | void Bind(int col, int val, bool null = false); 117 | void Bind(int col, bool val); 118 | void Bind(int col); 119 | 120 | protected: 121 | void ResolveColumnNames(); 122 | 123 | sqlite3* _db; 124 | sqlite3_stmt* _stmt; 125 | std::map _colNames; 126 | }; 127 | -------------------------------------------------------------------------------- /WaitCursor.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010-2011 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #include 23 | #include "WaitCursor.h" 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | // 27 | 28 | WaitCursor::WaitCursor(bool show) noexcept 29 | { 30 | _OldCursor = nullptr; 31 | if (show) 32 | Show(); 33 | } 34 | 35 | WaitCursor::~WaitCursor() noexcept 36 | { 37 | Hide(); 38 | } 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | // 42 | 43 | void WaitCursor::Show() noexcept 44 | { 45 | if (_OldCursor == nullptr) 46 | _OldCursor = SetCursor(LoadCursor(nullptr, IDC_WAIT)); 47 | } 48 | 49 | ///////////////////////////////////////////////////////////////////////////// 50 | // 51 | 52 | void WaitCursor::Hide() noexcept 53 | { 54 | if (_OldCursor != nullptr) 55 | { 56 | SetCursor(_OldCursor); 57 | _OldCursor = nullptr; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /WaitCursor.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // NppSnippets - Code Snippets plugin for Notepad++ // 4 | // Copyright (C) 2010 Frank Fesevur // 5 | // // 6 | // This program is free software; you can redistribute it and/or modify // 7 | // it under the terms of the GNU General Public License as published by // 8 | // the Free Software Foundation; either version 2 of the License, or // 9 | // (at your option) any later version. // 10 | // // 11 | // This program is distributed in the hope that it will be useful, // 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 14 | // GNU General Public License for more details. // 15 | // // 16 | // You should have received a copy of the GNU General Public License // 17 | // along with this program; if not, write to the Free Software // 18 | // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // 19 | // // 20 | ///////////////////////////////////////////////////////////////////////////// 21 | 22 | #pragma once 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | 27 | class WaitCursor 28 | { 29 | public: 30 | WaitCursor(bool show = true) noexcept; 31 | ~WaitCursor() noexcept; 32 | 33 | void Show() noexcept; 34 | void Hide() noexcept; 35 | 36 | private: 37 | HCURSOR _OldCursor; 38 | }; 39 | -------------------------------------------------------------------------------- /docs/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig for reStructedText based documenation 2 | 3 | root = true 4 | 5 | [*] 6 | end_of_line = lf 7 | indent_size = 4 8 | indent_style = space 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [Makefile] 13 | indent_style = tab 14 | -------------------------------------------------------------------------------- /docs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM sphinxdoc/sphinx 2 | 3 | WORKDIR /docs 4 | 5 | # Install the required packages for Python Sphinx 6 | ADD requirements.txt /docs 7 | RUN pip3 install -r requirements.txt 8 | 9 | CMD ["make", "html"] 10 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html epub latexpdf changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " epub to make an epub" 28 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 29 | @echo " changes to make an overview of all changed/added/deprecated items" 30 | @echo " linkcheck to check all external links for integrity" 31 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 32 | 33 | clean: 34 | rm -rf $(BUILDDIR) 35 | 36 | html: 37 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 38 | @echo 39 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 40 | 41 | epub: 42 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 43 | @echo 44 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 45 | 46 | latexpdf: 47 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 48 | @echo "Running LaTeX files through pdflatex..." 49 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 50 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 51 | 52 | changes: 53 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 54 | @echo 55 | @echo "The overview file is in $(BUILDDIR)/changes." 56 | 57 | linkcheck: 58 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 59 | @echo 60 | @echo "Link check complete; look for any errors in the above output " \ 61 | "or in $(BUILDDIR)/linkcheck/output.txt." 62 | 63 | doctest: 64 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 65 | @echo "Testing of doctests in the sources finished, look at the " \ 66 | "results in $(BUILDDIR)/doctest/output.txt." 67 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 5 | Version `1.7.1`_ (4 October 2022) 6 | --------------------------------- 7 | 8 | - ARM64 build (`pr #37`_). 9 | 10 | - Keep using the plugins dark mode to `workaround bug`_ introduced in Notepad++ 8.4.3 (`issue #45`_). 11 | 12 | .. _1.7.1: https://github.com/ffes/nppsnippets/releases/tag/v1.7.1 13 | .. _pr #37: https://github.com/ffes/nppsnippets/pull/37 14 | .. _issue #45: https://github.com/ffes/nppsnippets/issues/45 15 | .. _workaround bug: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/12007 16 | 17 | 18 | Version `1.7.0`_ (25 November 2021) 19 | ----------------------------------- 20 | 21 | - Add box above the list of snippets to filter that list (`issue #32`_). 22 | 23 | - Add options dialog 24 | 25 | - Modernize some snippets in the Template database (`issue #35`_). 26 | 27 | - Upgrade to SQLite version 3.36.0 28 | 29 | .. _1.7.0: https://github.com/ffes/nppsnippets/releases/tag/v1.7.0 30 | .. _issue #32: https://github.com/ffes/nppsnippets/issues/32 31 | .. _issue #35: https://github.com/ffes/nppsnippets/issues/35 32 | 33 | 34 | Version `1.6.0`_ (23 August 2020) 35 | --------------------------------- 36 | 37 | - Indent the snippet when it is inserted. Since this is a new feature and 38 | I can't test it for all possible programming languages indenting 39 | may not always works as indented, so you can disable it in the :ref:`options`. 40 | 41 | - Make the plugin more keyboard friendly (`issue #31`_). 42 | It adds two menu items to the ``Plugins`` menu to set the focus to the lists of libraries and the lists snippets. 43 | In ``Settings``, ``Shortcut Mapper...`` you can assign your own keyboard shortcuts to these actions. 44 | Apart from these menu items the plugin is generally more keyboard friendly. 45 | 46 | - Add more images to the page :ref:`usage`. 47 | 48 | - Upgrade to SQLite version 3.33.0 49 | 50 | .. _1.6.0: https://github.com/ffes/nppsnippets/releases/tag/v1.6.0 51 | .. _issue #31: https://github.com/ffes/nppsnippets/issues/31 52 | 53 | 54 | Version `1.5.1`_ (13 January 2020) 55 | ---------------------------------- 56 | 57 | - Fix crash when ``Before Selection`` was left empty and a snippet was saved (`issue #16`_) 58 | 59 | - Make the Edit Snippet dialog bigger and add scrollbars (`PR #25`_) 60 | 61 | - Make sure to use the proper line endings when creating a snippet from selection or clipboard (`issue #27`_) 62 | 63 | - Upgrade to SQLite version 3.30.1 64 | 65 | .. _1.5.1: https://github.com/ffes/nppsnippets/releases/tag/v1.5.1 66 | .. _PR #25: https://github.com/ffes/nppsnippets/pull/25 67 | .. _issue #16: https://github.com/ffes/nppsnippets/issues/16 68 | .. _issue #27: https://github.com/ffes/nppsnippets/issues/27 69 | 70 | 71 | Version `1.5.0`_ (15 May 2019) 72 | ------------------------------ 73 | 74 | - Adapt to Notepad++ 7.6.x (`issue #20`_) 75 | 76 | - Fixed "Creating Snippet from Selection crashes Notepad++" (`issue #14`_) 77 | 78 | - Add entry to the plugin menu to open the online manual 79 | 80 | - Upgrade to SQLite version 3.27.1 81 | 82 | .. _1.5.0: https://github.com/ffes/nppsnippets/releases/tag/v1.5.0 83 | .. _issue #14: https://github.com/ffes/nppsnippets/issues/14 84 | .. _issue #20: https://github.com/ffes/nppsnippets/issues/20 85 | 86 | 87 | Version `1.4.0`_ (24 May 2017) 88 | ------------------------------ 89 | 90 | - Provide a 64-bit version of the plug-in. 91 | 92 | - Added the possibility to :ref:`export a library ` for easier sharing. 93 | 94 | - The color of the plug-in match the current Notepad++ theme. 95 | 96 | - Converted the documentation from DocBook to reStructuredText. The 97 | documentation is now hosted at `Read The Docs`_. 98 | 99 | - Fixed `bug #6`_ at Google Code and its GitHub duplicate `issue #8`_. 100 | When a snippet had an empty first line it could not be saved. 101 | 102 | - Removed all references to Google Code because that `service has retired`_. 103 | All things that were still on Google Code have been moved to `GitHub`_. 104 | 105 | - Internally use my SqliteDB-class to communicate with the database. 106 | 107 | - Added :ref:`option ` ``ToolbarIcon`` to hide the icon from the toolbar. 108 | 109 | - Update icon on toolbar. It is now a puzzle piece. 110 | 111 | - Fixed issue that sometimes new libraries and/or new snippets could 112 | not be added. 113 | 114 | - Upgrade to SQLite version 3.19.0 115 | 116 | .. _1.4.0: https://github.com/ffes/nppsnippets/releases/tag/v1.4.0 117 | .. _Read The Docs: http://nppsnippets.readthedocs.io 118 | .. _service has retired: http://google-opensource.blogspot.com/2015/03/farewell-to-google-code.html 119 | .. _GitHub: https://github.com/ffes/nppsnippets 120 | .. _bug #6: https://code.google.com/archive/p/nppsnippets/issues/6 121 | .. _issue #8: https://github.com/ffes/nppsnippets/issues/8 122 | 123 | 124 | Version `1.3.0`_ (June 2013) 125 | ---------------------------- 126 | 127 | - Fixed problem with inserting UTF snippets (`issue #3`_). 128 | 129 | - Fixed wrong title of Import Library dialog. 130 | 131 | - Fixed some potential bugs found when trying to fix GCC compilation. 132 | 133 | - Converted the documentation from ODT to DocBook. Because of that an 134 | `on-line version`_ of the documentation is available as well. 135 | 136 | - Upgrade to SQLite version 3.8.0.2 137 | 138 | .. _1.3.0: https://github.com/ffes/nppsnippets/releases/tag/v1.3.0 139 | .. _issue #3: http://code.google.com/archive/p/nppsnippets/issues/3 140 | .. _on-line version: http://nppsnippets.readthedocs.io 141 | 142 | 143 | Version `1.2.0`_ (8 January 2013) 144 | --------------------------------- 145 | 146 | - There was an inconsistency between the documentation and code about 147 | the name of the option to specify your custom path for the database. 148 | Use ``DBFile`` from now on. For backwards compatibility the ``DBPath`` 149 | entry will still be recognized. 150 | 151 | - When a snippets creates a new document and the current document is 152 | empty, it reuses the current one and does not start a new. 153 | 154 | - Added ``Duplicate`` snippet function to context menu. 155 | 156 | - New (simple) templates library. 157 | 158 | - Upgrade to SQLite version 3.7.15.1 159 | 160 | .. _1.2.0: https://github.com/ffes/nppsnippets/releases/tag/v1.2.0 161 | 162 | 163 | Version 1.1.0 (13 December 2011) 164 | -------------------------------- 165 | 166 | - You can now add a new snippet to a library based upon the current 167 | selection or based upon the content of the clipboard. Right-click the 168 | snippets list to use these items. 169 | 170 | - Installation has been improved. A template database is provided and 171 | when the plug-in tries to find an existing database and it can't find 172 | it, it copies this template database to the AppData plugin-config 173 | directory. 174 | 175 | - The About dialog now shows the change-log. 176 | 177 | - When you upgrade the very first time the change-log for the current 178 | version will be shown. 179 | 180 | - When you didn't select a specific library for a certain language, the 181 | automatic selection of the library is improved. The first language 182 | specific library is preferred over the first general library. 183 | 184 | - Resized the edit snippet dialog. 185 | 186 | - Upgrade to SQLite version 3.7.9 187 | 188 | - Moved the download to `Google code`_. This gives me 189 | statistics about downloads and an issue tracker. The project's `web page`_ 190 | stays where it is. 191 | 192 | .. _Google code: https://code.google.com/p/nppsnippets/ 193 | .. _web page: http://www.fesevur.com/nppsnippets 194 | 195 | 196 | Version 1.0.0 (6 September 2011) 197 | -------------------------------- 198 | 199 | - The selection or cursor position are now restored after inserting a 200 | snippet. 201 | 202 | Version 0.7.1 (28 August 2011) 203 | ------------------------------ 204 | 205 | - Fixed a bug in the dialog to edit the languages for a certain 206 | library. This bug could cause a problem that libraries turn 207 | invisible, since all the records in LibraryLang table for that 208 | library were deleted and no new records were added. 209 | 210 | - Added a JavaScript - Math library. 211 | 212 | Version 0.7.0 (1 August 2011) 213 | ----------------------------- 214 | 215 | - A user interface for editing the language selection for libraries has 216 | been added. You need at least Notepad++ version 5.93 for this 217 | feature. 218 | 219 | - You can import a library from another NppSnippet database. 220 | 221 | - Start a new document for a certain snippets, and allow that snippet 222 | to set the language of that new document. There were already fields 223 | in the database for this. It can be very useful to start a new 224 | CSS-file or JavaScript-file from HTML, etc. 225 | 226 | - Added an option DBPath to the ini-file to override the default 227 | location of the database. Made this mainly for my own testing, but 228 | maybe it is useful for others as well (corporate database). You need 229 | to manually edit the ini-file to use this. 230 | 231 | - Added an icon to the tab of the docking interface. 232 | 233 | - Upgrade to SQLite version 3.7.7.1 234 | 235 | Version 0.6.0 (15 June 2011) 236 | ---------------------------- 237 | 238 | - It is now possible to add, edit or delete the snippets and the 239 | libraries from within Notepad++. It is not yet possible to edit the 240 | languages for a library. 241 | 242 | - Added a new ANSI-characters library for all languages. 243 | 244 | - Deleted the useless General library. 245 | 246 | - Upgrade to SQLite version 3.7.6.3 247 | 248 | Version 0.5.0 (21 December 2010) 249 | -------------------------------- 250 | 251 | - Upgrade to SQLite version 3.7.4 252 | 253 | - The focus is returned to the Scintilla window at start-up and after 254 | inserting a snippet. 255 | 256 | - The plug-in remembers if it is shown. 257 | 258 | - Added another special language to the table LibraryLang: ``Lang = -2``. 259 | Libraries with this language will always be shown for all languages. 260 | 261 | - The languages last used is now stored in a separate table. The 262 | database schema version is 3. With this the libraries with special 263 | languages (negative language ID's) can be remembered as last used as 264 | well. 265 | 266 | - Error message when the database can not be opened. 267 | 268 | Version 0.4.0 (8 April 2010) 269 | ---------------------------- 270 | 271 | - The database schema is updated and is now at version 2. The most 272 | important difference is that the "language" and "last used" field of 273 | the library are now in a separate table, allowing it to be 274 | one-to-many. Existing databases will be converted automatically to 275 | the new schema. 276 | 277 | - When there are multiple libraries for a language, changing to another 278 | library works and the last used library is remembered. 279 | 280 | - The plug-in now first tries to find the database in the user's 281 | plug-in config directory. On my Windows XP machine that is 282 | ``C:\\Documents and Settings\\Frank\\Application Data\\Notepad++\\plugins\\config``. 283 | If the database can't be found there it looks in the ``plugin\\config`` directory 284 | in the Notepad++ installation directory, in my case 285 | ``C:\\Program Files\\Notepad++\\plugins\\Config``. 286 | 287 | - Small improvements to the About dialog. 288 | 289 | - There are now 4 HTML libraries, 1 PHP libraries, 1 XML library and 1 290 | (rather useless) General library. 291 | 292 | Version 0.3.0 (10 February 2010) 293 | -------------------------------- 294 | 295 | - First alpha version, released under the GPL2 license. 296 | 297 | - The basics work, no User Interface yet to edit the snippets. 298 | 299 | Version 0.1.0 (22 January 2010) 300 | ------------------------------- 301 | 302 | - Internal proof of concept. 303 | -------------------------------------------------------------------------------- /docs/compile.rst: -------------------------------------------------------------------------------- 1 | How to compile 2 | ============== 3 | 4 | To compile NppSnippets you can use `Visual Studio`_. Project files for VS2019 are 5 | provided and actively used. The free Visual Studio Community gets the job done. 6 | Obviously the paid versions work as well. 7 | To compile with another versions of Visual Studio you can convert an existing 8 | project file. 9 | 10 | There is also a `MinGW-w64`_ makefile, using their 64-bit compilers. It can 11 | be used from `Cygwin`_, MSYS2 and various Linux distributions including WSL. 12 | It compiles, but the resulting dll is not recognized by Notepad++. 13 | 14 | .. _Visual Studio: https://www.visualstudio.com/ 15 | .. _MinGW-w64: https://mingw-w64.org/ 16 | .. _Cygwin: https://www.cygwin.com/ 17 | 18 | 19 | Building the documentation 20 | -------------------------- 21 | 22 | The documentation of NppSnippets is written in `reStructuredText`_ and hosted 23 | on `Read The Docs`_. 24 | 25 | To build on Windows you need `Python Sphinx`_. When using Cygwin you can install 26 | the ``python-sphinx`` and ``make`` packages. 27 | 28 | Use ``make html`` in the ``docs`` directory to generate the documentation. 29 | Other forms of output are not used, but might work. 30 | 31 | 32 | If you want the local docs the look like Read The Docs: 33 | 34 | - Clone the `Sphinx RTD Theme`_. 35 | 36 | - Create a directory named ``_themes`` in the ``docs`` directory. 37 | 38 | - There you need to create a symlink to the ``sphinx_rtd_theme`` subdirectory 39 | in the cloned repo. 40 | 41 | .. _reStructuredText: http://docutils.sourceforge.net/rst.html 42 | .. _Read The Docs: https://readthedocs.org/ 43 | .. _Python Sphinx: http://www.sphinx-doc.org/ 44 | .. _Sphinx RTD Theme: https://github.com/snide/sphinx_rtd_theme/ 45 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # NppSnippets documentation build configuration file 4 | # 5 | # This file is execfile()d with the current directory set to its 6 | # containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | from datetime import datetime 16 | import sphinx_rtd_theme 17 | 18 | # If extensions (or modules to document with autodoc) are in another directory, 19 | # add these directories to sys.path here. If the directory is relative to the 20 | # documentation root, use os.path.abspath to make it absolute, like shown here. 21 | #sys.path.insert(0, os.path.abspath('.')) 22 | 23 | # -- General configuration ------------------------------------------------ 24 | 25 | # If your documentation needs a minimal Sphinx version, state it here. 26 | #needs_sphinx = '1.0' 27 | 28 | # Add any Sphinx extension module names here, as strings. They can be 29 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 30 | # ones. 31 | extensions = [ 32 | 'sphinxcontrib.mermaid' 33 | ] 34 | 35 | # Need at least mermaid 8.5.0 because in that version entity relationship diagrams 36 | # were added. sphinxcontrib.mermaid has 8.4.x at the moment. Once they've updated 37 | # this `mermaid_version` can go. 38 | mermaid_version = "8.6.4" 39 | 40 | # Add any paths that contain templates here, relative to this directory. 41 | templates_path = [] 42 | 43 | # The suffix of source filenames. 44 | source_suffix = '.rst' 45 | 46 | # The encoding of source files. 47 | #source_encoding = 'utf-8-sig' 48 | 49 | # The master toctree document. 50 | master_doc = 'index' 51 | 52 | # General information about the project. 53 | project = 'NppSnippets' 54 | copyright = "2010-{:%Y}, Frank Fesevur" . format(datetime.now()) 55 | 56 | # The version info for the project you're documenting, acts as replacement for 57 | # |version| and |release|, also used in various other places throughout the 58 | # built documents. 59 | # 60 | # The short X.Y version. 61 | version = '1.6.0' 62 | # The full version, including alpha/beta/rc tags. 63 | release = '1.6.0' 64 | 65 | # The language for content autogenerated by Sphinx. Refer to documentation 66 | # for a list of supported languages. 67 | language = 'en' 68 | 69 | # There are two options for replacing |today|: either, you set today to some 70 | # non-false value, then it is used: 71 | #today = '' 72 | # Else, today_fmt is used as the format for a strftime call. 73 | today_fmt = '%d %b %Y' 74 | 75 | # List of patterns, relative to source directory, that match files and 76 | # directories to ignore when looking for source files. 77 | exclude_patterns = ['_build'] 78 | 79 | # The reST default role (used for this markup: `text`) to use for all 80 | # documents. 81 | #default_role = None 82 | 83 | # If true, '()' will be appended to :func: etc. cross-reference text. 84 | #add_function_parentheses = True 85 | 86 | # If true, the current module name will be prepended to all description 87 | # unit titles (such as .. function::). 88 | #add_module_names = True 89 | 90 | # If true, sectionauthor and moduleauthor directives will be shown in the 91 | # output. They are ignored by default. 92 | #show_authors = False 93 | 94 | # The name of the Pygments (syntax highlighting) style to use. 95 | pygments_style = 'sphinx' 96 | 97 | # A list of ignored prefixes for module index sorting. 98 | #modindex_common_prefix = [] 99 | 100 | # If true, keep warnings as "system message" paragraphs in the built documents. 101 | #keep_warnings = False 102 | 103 | 104 | # -- Options for HTML output ---------------------------------------------- 105 | 106 | # The theme to use for HTML and HTML Help pages. See the documentation for 107 | # a list of builtin themes. 108 | #html_theme = 'default' 109 | 110 | # Theme options are theme-specific and customize the look and feel of a theme 111 | # further. For a list of options available for each theme, see the 112 | # documentation. 113 | #html_theme_options = {} 114 | 115 | # Add any paths that contain custom themes here, relative to this directory. 116 | #html_theme_path = [] 117 | 118 | # Based on RTD-theme install instruction 119 | # https://sphinx-rtd-theme.readthedocs.io/en/latest/installing.html 120 | html_theme = 'sphinx_rtd_theme' 121 | 122 | # The name for this set of Sphinx documents. If None, it defaults to 123 | # " v documentation". 124 | #html_title = None 125 | 126 | # A shorter title for the navigation bar. Default is the same as html_title. 127 | #html_short_title = None 128 | 129 | # The name of an image file (relative to this directory) to place at the top 130 | # of the sidebar. 131 | #html_logo = None 132 | 133 | # The name of an image file (within the static path) to use as favicon of the 134 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 135 | # pixels large. 136 | #html_favicon = None 137 | 138 | # Add any paths that contain custom static files (such as style sheets) here, 139 | # relative to this directory. They are copied after the builtin static files, 140 | # so a file named "default.css" will overwrite the builtin "default.css". 141 | #html_static_path = ['_static'] 142 | 143 | # Add any extra paths that contain custom files (such as robots.txt or 144 | # .htaccess) here, relative to this directory. These files are copied 145 | # directly to the root of the documentation. 146 | #html_extra_path = [] 147 | 148 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 149 | # using the given strftime format. 150 | html_last_updated_fmt = '%d %b %Y' 151 | 152 | # If true, SmartyPants will be used to convert quotes and dashes to 153 | # typographically correct entities. 154 | #html_use_smartypants = True 155 | 156 | # Custom sidebar templates, maps document names to template names. 157 | #html_sidebars = {} 158 | 159 | # Additional templates that should be rendered to pages, maps page names to 160 | # template names. 161 | #html_additional_pages = {} 162 | 163 | # If false, no module index is generated. 164 | #html_domain_indices = True 165 | 166 | # If false, no index is generated. 167 | #html_use_index = True 168 | 169 | # If true, the index is split into individual pages for each letter. 170 | #html_split_index = False 171 | 172 | # If true, links to the reST sources are added to the pages. 173 | #html_show_sourcelink = True 174 | 175 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 176 | #html_show_sphinx = True 177 | 178 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 179 | #html_show_copyright = True 180 | 181 | # If true, an OpenSearch description file will be output, and all pages will 182 | # contain a tag referring to it. The value of this option must be the 183 | # base URL from which the finished HTML is served. 184 | #html_use_opensearch = '' 185 | 186 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 187 | #html_file_suffix = None 188 | 189 | # -- Options for LaTeX output --------------------------------------------- 190 | 191 | latex_elements = { 192 | # The paper size ('letterpaper' or 'a4paper'). 193 | 'papersize': 'a4paper', 194 | 195 | # The font size ('10pt', '11pt' or '12pt'). 196 | #'pointsize': '10pt', 197 | 198 | # Additional stuff for the LaTeX preamble. 199 | #'preamble': '', 200 | 201 | 'classoptions': ',openany,oneside', 202 | 'babel': '\\usepackage[english]{babel}' 203 | } 204 | 205 | # Grouping the document tree into LaTeX files. List of tuples 206 | # (source start file, target name, title, 207 | # author, documentclass [howto, manual, or own class]). 208 | latex_documents = [ 209 | ('index', 'NppSnippets.tex', 'NppSnippets Documentation', 210 | 'Frank Fesevur', 'manual'), 211 | ] 212 | 213 | # The name of an image file (relative to this directory) to place at the top of 214 | # the title page. 215 | #latex_logo = None 216 | 217 | # For "manual" documents, if this is true, then toplevel headings are parts, 218 | # not chapters. 219 | #latex_use_parts = False 220 | 221 | # If true, show page references after internal links. 222 | #latex_show_pagerefs = False 223 | 224 | # If true, show URL addresses after external links. 225 | #latex_show_urls = False 226 | 227 | # Documents to append as an appendix to all manuals. 228 | #latex_appendices = [] 229 | 230 | # If false, no module index is generated. 231 | #latex_domain_indices = True 232 | -------------------------------------------------------------------------------- /docs/contact.rst: -------------------------------------------------------------------------------- 1 | .. _contact: 2 | 3 | Contact 4 | ======= 5 | 6 | The project's web page can be found at http://www.fesevur.com/nppsnippets. 7 | 8 | The downloads, issue tracker and git repository can be found at 9 | https://github.com/ffes/nppsnippets. 10 | 11 | If you have problems with, questions about or suggestions for 12 | NppSnippets you can contact me at fesevur@gmail.com. 13 | -------------------------------------------------------------------------------- /docs/database.rst: -------------------------------------------------------------------------------- 1 | .. _database: 2 | 3 | Database 4 | ======== 5 | 6 | NppSnippets uses a `SQLite`_ database named ``NppSnippets.sqlite`` to 7 | store all the content. 8 | 9 | In the archive is a file named ``NppSnippets.sql``. With this you can 10 | generate a new (almost empty) SQLite database. At least SQLite 3.6.19 is 11 | needed because a foreign key constrains are used and the plug-in will 12 | need this when editing the data through the GUI. So be sure not to 13 | create the database with an older SQLite management tool that breaks 14 | this. 15 | 16 | You should only update, insert or delete records and not modify the 17 | structure of the database. That can cause the plug-in (and as a result 18 | of that Notepad++ itself) to crash. 19 | 20 | Why a SQLite database and not plain text files? 21 | ----------------------------------------------- 22 | 23 | All the snippets are stored in one `SQLite`_ database. SQLite is fast and easy 24 | to use. With SQLite most of the file and storage handling is taken care of. 25 | This is much more efficient then designing my own (complex) file format and 26 | implementing a parser and a writer, although I understand that editing a 27 | SQLite database is not as easy to edit for some as editing plain text files. 28 | But there is a :ref:`user interface ` for editing the snippets. 29 | 30 | .. _SQLite: https://www.sqlite.org/ 31 | 32 | 33 | Database structure 34 | ------------------ 35 | 36 | The database structure is quite simple. There are four tables 37 | :ref:`table_library`, :ref:`table_library_lang`, :ref:`table_snippets` 38 | and :ref:`table_lang_last_used`. There are one-to-many relations between 39 | Library and LibraryLang, between Library and Snippets and between Library 40 | and LangLastUsed. They are all linked to each other with the LibraryID field. 41 | It is possible to have multiple libraries per language and one library can be 42 | used for many languages. For every library at least one record in the 43 | LibraryLang and Snippets tables is needed. 44 | 45 | .. mermaid:: 46 | 47 | erDiagram 48 | Library ||--o{ Snippets : has 49 | Library ||--o{ LibraryLang : has 50 | Library ||--|| LangLastUsed : has-one 51 | 52 | The current schema version of the database is stored in ``user_version`` and is 3. 53 | 54 | 55 | Table definitions 56 | ----------------- 57 | 58 | .. _table_library: 59 | 60 | Library 61 | ******* 62 | 63 | +-------------+------------------------------------------------------+ 64 | | Field | Description | 65 | +=============+======================================================+ 66 | | LibraryID | The unique identifier of this library | 67 | +-------------+------------------------------------------------------+ 68 | | Name | Name of the library | 69 | +-------------+------------------------------------------------------+ 70 | | CreatedBy | Who created this library | 71 | +-------------+------------------------------------------------------+ 72 | | Comments | Comments about this library | 73 | +-------------+------------------------------------------------------+ 74 | | SortBy | Which fields of Snippets are used to sort: | 75 | | | 0. "Name, Sort" | 76 | | | 1. "Sort, Name" | 77 | +-------------+------------------------------------------------------+ 78 | 79 | .. _table_library_lang: 80 | 81 | LibraryLang 82 | *********** 83 | 84 | +-------------+-------------------------------------------------------------------+ 85 | | Field | Description | 86 | +=============+===================================================================+ 87 | | LibraryID | The library this item is part of | 88 | +-------------+-------------------------------------------------------------------+ 89 | | Lang | LangType from Notepad\_plus\_msgs.h. There are two special cases: | 90 | | | | 91 | | | - Libs with Lang = -1 are shown when there is no library for | 92 | | | the current language | 93 | | | | 94 | | | - Libs with Lang = -2 are shown for every language | 95 | +-------------+-------------------------------------------------------------------+ 96 | 97 | .. _table_snippets: 98 | 99 | Snippets 100 | ******** 101 | 102 | +--------------------+--------------------------------------------------------------+ 103 | | Field | Description | 104 | +====================+==============================================================+ 105 | | SnippetID | The unique identifier of this snippet | 106 | +--------------------+--------------------------------------------------------------+ 107 | | LibraryID | The library this item is part of | 108 | +--------------------+--------------------------------------------------------------+ 109 | | Name | The name of the snippet | 110 | +--------------------+--------------------------------------------------------------+ 111 | | BeforeSelection | The text inserted before the current cursor / selection | 112 | +--------------------+--------------------------------------------------------------+ 113 | | AfterSelection | The text inserted after the current cursor / selection | 114 | +--------------------+--------------------------------------------------------------+ 115 | | ReplaceSelection | Replace a selection or ignore the selection and insert | 116 | +--------------------+--------------------------------------------------------------+ 117 | | NewDocument | Create a new document before inserting this snippet? | 118 | +--------------------+--------------------------------------------------------------+ 119 | | NewDocumentLang | Change the language of the new document to this language | 120 | +--------------------+--------------------------------------------------------------+ 121 | | Sort | Can determine the order of the snipping in the list. Depends | 122 | | | on Library(SortBy) how the list is sorted. | 123 | +--------------------+--------------------------------------------------------------+ 124 | 125 | .. _table_lang_last_used: 126 | 127 | LangLastUsed 128 | ************ 129 | 130 | +-------------+-------------------------------------------------------+ 131 | | Field | Description | 132 | +=============+=======================================================+ 133 | | Lang | LangType from Notepad\_plus\_msgs.h | 134 | +-------------+-------------------------------------------------------+ 135 | | LibraryID | This library is the last one used for this language | 136 | +-------------+-------------------------------------------------------+ 137 | -------------------------------------------------------------------------------- /docs/faq.rst: -------------------------------------------------------------------------------- 1 | Frequently Asked Questions 2 | ========================== 3 | 4 | Can I assign a shortcut key to a certain snippet? 5 | ------------------------------------------------- 6 | 7 | This is on the wish list, but I don't think it is possible. 8 | Shortcut key are assigned to menu items when the plug-ins are loaded. 9 | But individual snippets are not menu items. And shortcut keys need to be 10 | dynamic. When you change the library, the key assignments need to change 11 | on the fly. 12 | 13 | Consider ``Ctrl-B``: this could be ``bold`` in HTML, ``break`` in a 14 | c-styled languages and a ``begin``/``end`` block in Pascal. 15 | 16 | But a pointer to a way to implement this is, or even better a pull request 17 | that fixes this is much appreciated. 18 | -------------------------------------------------------------------------------- /docs/images/context-menu-library.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/docs/images/context-menu-library.png -------------------------------------------------------------------------------- /docs/images/context-menu-snippet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/docs/images/context-menu-snippet.png -------------------------------------------------------------------------------- /docs/images/edit-snippet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/docs/images/edit-snippet.png -------------------------------------------------------------------------------- /docs/images/main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/docs/images/main.png -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. NppSnippets documentation master file 2 | 3 | Welcome to NppSnippets' documentation! 4 | ====================================== 5 | 6 | Contents: 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | introduction.rst 12 | installation.rst 13 | usage.rst 14 | libraries.rst 15 | database.rst 16 | faq.rst 17 | options.rst 18 | wishlist.rst 19 | known-issues.rst 20 | contact.rst 21 | compile.rst 22 | license.rst 23 | changelog.rst 24 | gpl-2.rst 25 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | How to install or upgrade 2 | ========================= 3 | 4 | The easiest way to install this plugin is by using the Plugins Admin. 5 | From the "Plugins" menu, choose the "Plugins Admin". 6 | Search for "Snippets" plugin, choose "install" and follow the instructions on the screen. 7 | 8 | To manually install the plugin, copy all the files in archive to the ``plugins/NppSnippets`` directory 9 | in the Notepad++ installation directory typically in the ``Program Files`` directory. 10 | You may need to create that directory. 11 | Then (re)start Notepad++. 12 | 13 | When you automatically upgrade through the Plugin Admin your database 14 | is not touched. If you are manually upgrading at least replace the 15 | existing dll. It is up to you if you override your own database with the 16 | template database provided in the archive. If you have not changed 17 | existing snippets or added your own, it is recommended to use the 18 | database in the archive. 19 | -------------------------------------------------------------------------------- /docs/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | NppSnippets is a plug-in for `Notepad++`_. It adds the possibility to add 5 | code snippets to the current document by selecting it from a simple list. 6 | 7 | .. _Notepad++: https://notepad-plus-plus.org/ 8 | -------------------------------------------------------------------------------- /docs/known-issues.rst: -------------------------------------------------------------------------------- 1 | Known Issues 2 | ============ 3 | 4 | - Closing the snippets window with the ``x`` does not update toolbar icon 5 | and menu item. And as a result of that the state is not remembered 6 | properly. I need to find the notification that is send to the window 7 | on clicking the ``x`` (`#26`_). 8 | 9 | - When a library is not alphabetic sorted, and you move an item up or 10 | down, this is slow. This is because the ``Sort``-field of all the 11 | snippets of that library need to be updated in the database. 12 | 13 | - The icon on the docking tab is inverted for some strange reason. 14 | 15 | - When there is no write-access to the database, this is not properly handled. 16 | 17 | .. _#26: https://github.com/ffes/nppsnippets/issues/26 18 | -------------------------------------------------------------------------------- /docs/libraries.rst: -------------------------------------------------------------------------------- 1 | Libraries and Snippets 2 | ====================== 3 | 4 | .. _edit: 5 | 6 | How to add or edit libraries or snippets 7 | ---------------------------------------- 8 | 9 | To add or edit a snippet, right-click the snippet in the list and edit. 10 | To add or edit a library right-click the combo-box where you select the 11 | current library. 12 | 13 | A library can be useful for multiple programming languages. You can specify 14 | for which language the library is visible. 15 | 16 | To add a lot of snippets, I suggest that you look at the section 17 | :ref:`database` that describes the database structure and import your 18 | data with your favorite SQLite management tool. 19 | 20 | 21 | .. _import_export_libs: 22 | 23 | Importing and exporting libraries 24 | --------------------------------- 25 | 26 | NppSnippets has an option to import and export libraries. When you right-click 27 | the combo-box where the current library is selected, you have two options. 28 | When you import a library, select the database you want to import from. 29 | After that a dialog appears that lets you select the library to import. 30 | Note that the imported library could a for a different programming language 31 | then you are currently using. Therefore the library may not appear at first. 32 | 33 | When you export the current library, you can create a new database or you can 34 | export to an existing database. This way you can combine various libraries 35 | for one programming language in one database. 36 | 37 | Note that when you want to share libraries with other users with your 38 | organization there is also :ref:`an option ` to specify the full 39 | path to the database. Maybe you want to put one database on a network share. 40 | 41 | 42 | Provided Snippets Libraries 43 | --------------------------- 44 | 45 | At this moment the template database is filled with these libraries. If 46 | you upgrade from a previous version your databases is not changed. If 47 | you want to try any of the new libraries, you must manually import those 48 | libraries from the template database. 49 | 50 | +----------------------+--------------------+------------+ 51 | | Library Name | Languages | By | 52 | +======================+====================+============+ 53 | | ANSI Characters | All | FFes | 54 | +----------------------+--------------------+------------+ 55 | | Templates | All | FFes | 56 | +----------------------+--------------------+------------+ 57 | | HTML Tags | HTML, PHP, ASP | FFes | 58 | +----------------------+--------------------+------------+ 59 | | HTML Characters | HTML, PHP, ASP | FFes | 60 | +----------------------+--------------------+------------+ 61 | | Greek Characters | HTML, PHP, ASP | FFes | 62 | +----------------------+--------------------+------------+ 63 | | W3C Doctypes | HTML | FFes | 64 | +----------------------+--------------------+------------+ 65 | | CSS2 Tags | CSS, HTML | FFes | 66 | +----------------------+--------------------+------------+ 67 | | CSS2 Tags & Values | CSS, HTML | FFes | 68 | +----------------------+--------------------+------------+ 69 | | JavaScript - Basic | JavaScript, HTML | FFes | 70 | +----------------------+--------------------+------------+ 71 | | JavaScript - Date | JavaScript, HTML | FFes | 72 | +----------------------+--------------------+------------+ 73 | | JavaScript - Math | JavaScript, HTML | FFes | 74 | +----------------------+--------------------+------------+ 75 | | PHP Language | PHP | jvdanilo | 76 | +----------------------+--------------------+------------+ 77 | | XML Tags | XML | jvdanilo | 78 | +----------------------+--------------------+------------+ 79 | 80 | User generated libraries 81 | ------------------------ 82 | 83 | From version 0.7 it is possible to import libraries from another 84 | NppSnippets database. This way redistributing user generated libraries 85 | becomes easy. If you have created your own library and think it can be 86 | useful for others, export that library and :ref:`send it to me `. 87 | I will put them on `my website`_. 88 | 89 | .. _my website: http://www.fesevur.com/nppsnippets 90 | -------------------------------------------------------------------------------- /docs/license.rst: -------------------------------------------------------------------------------- 1 | License 2 | ======= 3 | 4 | This plug-in is published under the GPL-2 license. See :ref:`gpl-2` for the 5 | full license agreement. You can download the sources from 6 | https://github.com/ffes/nppsnippets. 7 | -------------------------------------------------------------------------------- /docs/options.rst: -------------------------------------------------------------------------------- 1 | .. _options: 2 | 3 | Options 4 | ======= 5 | 6 | To edit the settings of the plug-in, select ``Options...`` from the ``Plugin`` menu. 7 | 8 | You can also edit the ini-file manually to change the settings. 9 | This ini-file is normally found in your "Application Data" directory and is named ``NppSnippets.ini``. 10 | On my Windows 10 machine this directory is ``C:\Users\Frank\AppData\Roaming\Notepad++\plugins\config``. 11 | 12 | These are the default settings: 13 | 14 | .. code:: ini 15 | 16 | [Options] 17 | Show=1 18 | ToolbarIcon=1 19 | Indent=1 20 | DBFile= 21 | 22 | When ``Show`` is set to ``0`` the tree will not be shown. 23 | 24 | When ``ToolbarIcon`` is set to ``0`` no icon will be shown on the toolbar. 25 | 26 | When ``Indent`` is set to ``0`` the snippet will not be indented when it is inserted. 27 | 28 | ``DBFile`` can be used to override the default location of the database ``NppSnippets.sqlite`` by specifying the full path name of the database. 29 | When it is not set the plug-in will look in the same directory as where ``NppSnippets.ini`` is located. 30 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx_rtd_theme 2 | sphinxcontrib-mermaid 3 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | .. _usage: 2 | 3 | How to use 4 | ========== 5 | 6 | To open the Snippets window, click on the ``jigsaw`` button on the 7 | toolbar, or via the menu ``Plugins``, ``Snippets``, ``Snippets``. 8 | 9 | .. image:: images/main.png 10 | :alt: Main view 11 | 12 | The window consists of two parts. A combobox where you can select the 13 | library and underneath it is the list of snippets in the chosen library. 14 | In the sample above the library is named ``Templates``. 15 | 16 | To insert a snippet simply double-click on the item in the list and the 17 | snippet is inserted at the current cursor position. 18 | 19 | When you switch to a document with another language the snippets for 20 | that new language are read from the database. 21 | 22 | 23 | Edit a snippet 24 | -------------- 25 | 26 | To edit a snippet, right-click the item and choose ``Edit...``. 27 | 28 | .. image:: images/context-menu-snippet.png 29 | :alt: Context menu to edit a snippet 30 | 31 | A dialog will appear where you can edit the selected snippet. 32 | 33 | .. image:: images/edit-snippet.png 34 | :alt: Dialog to edit the snippet 35 | 36 | 37 | Edit a library 38 | -------------- 39 | 40 | To edit a library, right-click the name of the library. 41 | A context menu will appear and choose ``Edit library...``. 42 | 43 | .. image:: images/context-menu-library.png 44 | :alt: Context menu to edit a library 45 | -------------------------------------------------------------------------------- /docs/wishlist.rst: -------------------------------------------------------------------------------- 1 | Wish List 2 | ========= 3 | 4 | The wish list is in random order. 5 | 6 | - Real template handling: variables in the snippets 7 | 8 | - Select a text, right-click that selection and add as new snippet. 9 | 10 | - If possible, drag-and-drop from the list to the active document. 11 | 12 | - Assign keyboard shortcut keys to a snippet. 13 | 14 | - Add tooltips for the snippets (`#7`_). 15 | 16 | - Remember the last select snippet from the list. Useful when switching 17 | between different languages. 18 | 19 | - Add support for multiple selections (`#2`_). 20 | 21 | - Easier sorting for non-alphabetic libraries. (move to top, move to 22 | bottom, dragging?) 23 | 24 | - Copy a certain snippet to another library. 25 | 26 | - Make the snippets aware of the replace tabs with spaces setting of the 27 | current document. 28 | 29 | - Libraries can be hard to find when there is something wrong with the 30 | languages that are set for this library. 31 | 32 | .. _#2: https://github.com/ffes/nppsnippets/issues/2 33 | .. _#7: https://github.com/ffes/nppsnippets/issues/7 34 | -------------------------------------------------------------------------------- /misc/Languages.sql: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- This is provided as a reference and not used by the plugin -- 3 | ----------------------------------------------------------------------------- 4 | 5 | BEGIN TRANSACTION; 6 | DROP TABLE IF EXISTS Languages; 7 | CREATE TABLE Languages ( 8 | LangID INTEGER PRIMARY KEY NOT NULL, 9 | Name TEXT NOT NULL 10 | ); 11 | INSERT INTO Languages VALUES (0,'Normal Text'); 12 | INSERT INTO Languages VALUES (1,'PHP'); 13 | INSERT INTO Languages VALUES (2,'C'); 14 | INSERT INTO Languages VALUES (3,'C++'); 15 | INSERT INTO Languages VALUES (4,'C#'); 16 | INSERT INTO Languages VALUES (5,'Objective-C'); 17 | INSERT INTO Languages VALUES (6,'Java'); 18 | INSERT INTO Languages VALUES (7,'Resource file'); 19 | INSERT INTO Languages VALUES (8,'HTML'); 20 | INSERT INTO Languages VALUES (9,'XML'); 21 | INSERT INTO Languages VALUES (10,'Makefile'); 22 | INSERT INTO Languages VALUES (11,'Pascal'); 23 | INSERT INTO Languages VALUES (12,'Batch'); 24 | INSERT INTO Languages VALUES (13,'MS INI file'); 25 | INSERT INTO Languages VALUES (14,'MS-DOS Style'); 26 | INSERT INTO Languages VALUES (15,'User-Defined'); 27 | INSERT INTO Languages VALUES (16,'ASP'); 28 | INSERT INTO Languages VALUES (17,'SQL'); 29 | INSERT INTO Languages VALUES (18,'VB'); 30 | INSERT INTO Languages VALUES (19,'JavaScript'); 31 | INSERT INTO Languages VALUES (20,'CSS'); 32 | INSERT INTO Languages VALUES (21,'Perl'); 33 | INSERT INTO Languages VALUES (22,'Python'); 34 | INSERT INTO Languages VALUES (23,'Lua'); 35 | INSERT INTO Languages VALUES (24,'TeX'); 36 | INSERT INTO Languages VALUES (25,'Fortran'); 37 | INSERT INTO Languages VALUES (26,'Shell'); 38 | INSERT INTO Languages VALUES (27,'Flash actionscript'); 39 | INSERT INTO Languages VALUES (28,'NSIS'); 40 | INSERT INTO Languages VALUES (29,'TCL'); 41 | INSERT INTO Languages VALUES (30,'LISP'); 42 | INSERT INTO Languages VALUES (31,'Scheme'); 43 | INSERT INTO Languages VALUES (32,'Assembly'); 44 | INSERT INTO Languages VALUES (33,'Diff'); 45 | INSERT INTO Languages VALUES (34,'Properties'); 46 | INSERT INTO Languages VALUES (35,'PostScript'); 47 | INSERT INTO Languages VALUES (36,'Ruby'); 48 | INSERT INTO Languages VALUES (37,'Smalltalk'); 49 | INSERT INTO Languages VALUES (38,'VHDL'); 50 | INSERT INTO Languages VALUES (39,'KIXtart'); 51 | INSERT INTO Languages VALUES (40,'AutoIt'); 52 | INSERT INTO Languages VALUES (41,'Caml'); 53 | INSERT INTO Languages VALUES (42,'Ada'); 54 | INSERT INTO Languages VALUES (43,'Verilog'); 55 | INSERT INTO Languages VALUES (44,'Matlab'); 56 | INSERT INTO Languages VALUES (45,'Haskell'); 57 | INSERT INTO Languages VALUES (46,'INNO'); 58 | INSERT INTO Languages VALUES (48,'CMake'); 59 | INSERT INTO Languages VALUES (49,'YAML'); 60 | INSERT INTO Languages VALUES (50,'COBOL'); 61 | INSERT INTO Languages VALUES (51,'Gui4Cli'); 62 | INSERT INTO Languages VALUES (52,'D'); 63 | INSERT INTO Languages VALUES (53,'PowerShell'); 64 | INSERT INTO Languages VALUES (54,'R'); 65 | INSERT INTO Languages VALUES (55,'JSP'); 66 | INSERT INTO Languages VALUES (56,'CoffeeScript'); 67 | INSERT INTO Languages VALUES (57,'JSON'); 68 | INSERT INTO Languages VALUES (58,'JavaScript'); 69 | INSERT INTO Languages VALUES (59,'Fortran 77'); 70 | INSERT INTO Languages VALUES (60,'BaanC'); 71 | INSERT INTO Languages VALUES (61,'Motorola S-Record binary data'); 72 | INSERT INTO Languages VALUES (62,'Intel HEX binary data'); 73 | INSERT INTO Languages VALUES (63,'Tektronix extended HEX binary data'); 74 | INSERT INTO Languages VALUES (64,'Swift'); 75 | INSERT INTO Languages VALUES (65,'ASN1'); 76 | INSERT INTO Languages VALUES (66,'AVS'); 77 | INSERT INTO Languages VALUES (67,'Blitz Basic'); 78 | INSERT INTO Languages VALUES (68,'Pure Basic'); 79 | INSERT INTO Languages VALUES (69,'Free Basic'); 80 | INSERT INTO Languages VALUES (70,'CSound'); 81 | INSERT INTO Languages VALUES (71,'Erlang'); 82 | INSERT INTO Languages VALUES (72,'EScript'); 83 | INSERT INTO Languages VALUES (73,'Forth'); 84 | INSERT INTO Languages VALUES (74,'LaTeX'); 85 | INSERT INTO Languages VALUES (75,'MMixal'); 86 | INSERT INTO Languages VALUES (76,'Nimrod'); 87 | INSERT INTO Languages VALUES (77,'NN Crontab'); 88 | INSERT INTO Languages VALUES (78,'OScript'); 89 | INSERT INTO Languages VALUES (79,'Rebol'); 90 | INSERT INTO Languages VALUES (80,'Windows Registry'); 91 | INSERT INTO Languages VALUES (81,'Rust'); 92 | INSERT INTO Languages VALUES (82,'Spice'); 93 | INSERT INTO Languages VALUES (83,'Txt2Tags'); 94 | INSERT INTO Languages VALUES (84,'Visual Prolog'); 95 | COMMIT; 96 | -------------------------------------------------------------------------------- /misc/NppSnippets.sql: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | -- For more details about the schema see -- 3 | -- https://nppsnippets.readthedocs.io/en/latest/database.html -- 4 | ----------------------------------------------------------------------------- 5 | 6 | PRAGMA foreign_keys = ON; 7 | 8 | ----------------------------------------------------------------------------- 9 | -- TABLE Library -- 10 | ----------------------------------------------------------------------------- 11 | DROP TABLE IF EXISTS Library; 12 | CREATE TABLE Library ( 13 | LibraryID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 14 | Name TEXT NOT NULL, 15 | CreatedBy TEXT, 16 | Comments TEXT, 17 | SortBy INTEGER NOT NULL DEFAULT 0 18 | ); 19 | 20 | INSERT INTO Library(LibraryID, Name) VALUES(1,'General'); 21 | 22 | ----------------------------------------------------------------------------- 23 | -- TABLE LibraryLang -- 24 | ----------------------------------------------------------------------------- 25 | DROP TABLE IF EXISTS LibraryLang; 26 | CREATE TABLE LibraryLang ( 27 | LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE, 28 | Lang INTEGER NOT NULL, 29 | PRIMARY KEY (LibraryID, Lang) 30 | ); 31 | 32 | INSERT INTO LibraryLang(LibraryID, Lang) VALUES(1, -1); 33 | 34 | ----------------------------------------------------------------------------- 35 | -- TABLE Snippets -- 36 | ----------------------------------------------------------------------------- 37 | DROP TABLE IF EXISTS Snippets; 38 | CREATE TABLE Snippets ( 39 | SnippetID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 40 | LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE, 41 | Name TEXT NOT NULL, 42 | BeforeSelection TEXT NOT NULL, 43 | AfterSelection TEXT, 44 | ReplaceSelection BOOL NOT NULL DEFAULT 0, 45 | NewDocument BOOL NOT NULL DEFAULT 0, 46 | NewDocumentLang INTEGER, 47 | Sort INTEGER 48 | ); 49 | 50 | CREATE INDEX SnipName ON Snippets(LibraryID, Name, Sort); 51 | CREATE INDEX SnipSort ON Snippets(LibraryID, Sort, Name); 52 | 53 | INSERT INTO Snippets(LibraryID, Name, BeforeSelection) VALUES (1, 'Test Item 1', '11'); 54 | 55 | ----------------------------------------------------------------------------- 56 | -- TABLE LangLastUsed -- 57 | ----------------------------------------------------------------------------- 58 | DROP TABLE IF EXISTS LangLastUsed; 59 | CREATE TABLE LangLastUsed ( 60 | Lang INTEGER PRIMARY KEY NOT NULL, 61 | LibraryID INTEGER NOT NULL REFERENCES Library(LibraryID) ON DELETE CASCADE ON UPDATE CASCADE 62 | ); 63 | 64 | ----------------------------------------------------------------------------- 65 | -- Set the user version of this database -- 66 | ----------------------------------------------------------------------------- 67 | PRAGMA user_version = 3; 68 | -------------------------------------------------------------------------------- /misc/Template.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ffes/nppsnippets/24248b69b45d0ddf45e04f9749b597469a376616/misc/Template.sqlite -------------------------------------------------------------------------------- /version_git.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Is Git for Windows x64 installed? 4 | if exist "%ProgramW6432%\Git\bin\bash.exe" ( 5 | 6 | echo Using bash from Git for Windows x64 7 | setlocal 8 | PATH=%ProgramW6432%\Git\mingw64\bin;%ProgramW6432%\Git\bin 9 | bash version_git.sh 10 | exit /b 0 11 | ) 12 | 13 | REM Is Cygwin installed? 14 | if exist C:\Cygwin\bin\bash.exe ( 15 | 16 | echo Using bash from Cygwin 17 | setlocal 18 | PATH=C:\Cygwin\bin 19 | bash version_git.sh 20 | exit /b 0 21 | ) 22 | 23 | REM Is Cygwin64 installed? 24 | if exist C:\Cygwin64\bin\bash.exe ( 25 | 26 | echo Using bash from Cygwin64 27 | setlocal 28 | PATH=C:\Cygwin64\bin 29 | bash version_git.sh 30 | exit /b 0 31 | ) 32 | 33 | REM No Cygwin or Git for Windows installed 34 | REM If there is a file assume if is properly generated 35 | if exist version_git.h ( 36 | echo No bash found, but version_git.h exists 37 | exit /b 0 38 | ) 39 | 40 | echo No bash found 41 | exit /b 1 42 | -------------------------------------------------------------------------------- /version_git.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | function check_if_installed() 4 | { 5 | # Go through all the tools that need to be checked 6 | for i in $* 7 | do 8 | # Is tool installed? 9 | if ! type "$i" >/dev/null 2>&1 10 | then 11 | echo "Required tool \"$i\" not found!" 12 | exit 1 13 | fi 14 | done 15 | } 16 | 17 | function create_version_git_h() 18 | { 19 | # Make sure there is a file, but don't touch it if not needed 20 | [[ -f version_git.h ]] || touch version_git.h 21 | 22 | # Make sure the locale is set properly 23 | export LANG=en_US.UTF8 24 | 25 | # Get the version info from git 26 | echo "Retrieving version information from git..." 27 | GIT_VERSION=$(git describe --tags --match 'v[0-9]*') 28 | echo "Found version $GIT_VERSION" 29 | 30 | # Has the version changed? 31 | if grep --quiet $GIT_VERSION version_git.h 32 | then 33 | echo "Latest version info already in version_git.h" 34 | exit 0 35 | fi 36 | 37 | # Get additional version info from git 38 | echo "Retrieving additional version information from git..." 39 | VERSION=$(git describe --tags --abbrev=0 | grep -oP '\d+\.\d+\.\d+') 40 | VERSION_NUMBERS=$(echo $VERSION | tr "." ","),0 41 | YEAR=$(date +%Y) 42 | 43 | echo "Generating version_git.h..." 44 | echo "#pragma once" > version_git.h 45 | 46 | echo "#define VERSION_NUMBER $VERSION_NUMBERS" >> version_git.h 47 | echo "#define VERSION_NUMBER_STR \"$VERSION\"" >> version_git.h 48 | echo "#define VERSION_NUMBER_WSTR L\"$VERSION\"" >> version_git.h 49 | echo "#define COPYRIGHT_STR \"Copyright (c) 2010-$YEAR by Frank Fesevur\"" >> version_git.h 50 | 51 | echo "#define VERSION_GIT_STR \"$GIT_VERSION\"" >> version_git.h 52 | echo "#define VERSION_GIT_WSTR L\"$GIT_VERSION\"" >> version_git.h 53 | } 54 | 55 | # Check if all the tools we need are installed 56 | check_if_installed git grep tr date 57 | 58 | create_version_git_h 59 | --------------------------------------------------------------------------------