Skip to content

Commit

Permalink
make Scintilla AutoC while typing, add optional setting
Browse files Browse the repository at this point in the history
  • Loading branch information
VinsWorldcom committed Jun 18, 2021
2 parents 2c40765 + a197078 commit 8a43682
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 54 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ tags
*.lib
*.iobj
*.ipdb
*.user
*.zip
bin/*
bin64/*
123 changes: 85 additions & 38 deletions QuickText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ const TCHAR dataFileDefault[] = TEXT( "QuickText.default.ini" );
basic_string<TCHAR> confFilePath;
const char sectionName[] = "General";
const char iniKeyAllowedChars[] = "AllowedChars";
const char iniUseSciAutoC[] = "UseSciAutoC";
const char iniInsertOnAutoC[] = "InsertOnAutoC";

NppData nppData; // handles
FuncItem funcItems[nbFunc];

bool g_bInsertOnAutoC = false;
bool g_bUseSciAutoC = false;
bool g_bCharAdded = false;

//+@TonyM: added some characters (._-). more characters I've added, more errors occure.
std::string allowedChars =
Expand Down Expand Up @@ -99,6 +102,8 @@ void pluginCleanUp()

::WritePrivateProfileStringA( sectionName, iniKeyAllowedChars,
allowedChars.c_str(), ini_file_path.c_str() );
::WritePrivateProfileStringA( sectionName, iniUseSciAutoC,
g_bUseSciAutoC ? "1" : "0", ini_file_path.c_str() );
::WritePrivateProfileStringA( sectionName, iniInsertOnAutoC,
g_bInsertOnAutoC ? "1" : "0", ini_file_path.c_str() );
}
Expand Down Expand Up @@ -291,6 +296,16 @@ extern "C" __declspec( dllexport ) void beNotified( SCNotification
}
break;

case SCN_CHARADDED:
{
if ( ! cQuickText.editing && g_bUseSciAutoC )
{
g_bCharAdded = true;
QuickText();
}
}
break;

case SCN_AUTOCCOMPLETED:
{
if ( g_bInsertOnAutoC )
Expand Down Expand Up @@ -364,11 +379,19 @@ void _refreshINIFiles()
if ( !ini_allowedChars.empty() )
allowedChars = ini_allowedChars;

std::string autoC = CIniFile::GetValue( iniInsertOnAutoC,
std::string useAutoC = CIniFile::GetValue( iniUseSciAutoC,
ini_file_section, ini_file_path );
if ( !autoC.empty() )
if ( !useAutoC.empty() )
{
int val = std::stoi( autoC );
int val = std::stoi( useAutoC );
if ( val != 0 )
g_bUseSciAutoC = true;
}
std::string doAutoC = CIniFile::GetValue( iniInsertOnAutoC,
ini_file_section, ini_file_path );
if ( !doAutoC.empty() )
{
int val = std::stoi( doAutoC );
if ( val != 0 )
g_bInsertOnAutoC = true;
}
Expand Down Expand Up @@ -522,10 +545,10 @@ void QuickText()
( LPARAM )allowedChars.c_str() );

// if a block of text is selected for tabbing
textSelectionStart = static_cast<int>( SendMessage( scintilla,
SCI_GETSELECTIONSTART, 0, 0 ) );
textSelectionEnd = static_cast<int>( SendMessage( scintilla,
SCI_GETSELECTIONEND, 0, 0 ) );
// textSelectionStart = static_cast<int>( SendMessage( scintilla,
// SCI_GETSELECTIONSTART, 0, 0 ) );
// textSelectionEnd = static_cast<int>( SendMessage( scintilla,
// SCI_GETSELECTIONEND, 0, 0 ) );

// get 'text' location
curPos = static_cast<int>( SendMessage( scintilla, SCI_GETCURRENTPOS, 0,
Expand Down Expand Up @@ -572,6 +595,46 @@ void QuickText()
//+@TonyM: free memory:
g_tagList.clear();

// sort the combined language and global list
sort( tagList.begin(), tagList.end() );

if ( tagList.size() > 0 && ( endPos - startPos > 0 ) || ( ! g_bCharAdded && ! cQuickText.editing ))
{
// restoring original selection
SendMessage( scintilla, SCI_SETCURRENTPOS, curPos, 0 );
SendMessage( scintilla, SCI_SETSELECTIONSTART, curPos, ( LPARAM )true );
SendMessage( scintilla, SCI_SETSELECTIONEND, curPos, ( LPARAM )true );

stringstream tagList_ss;
TagList::const_iterator tagListEnd = tagList.end();

for ( TagList::const_iterator index = tagList.begin(); index != tagListEnd;
index++ )
{
tagList_ss << *index;
tagList_ss << '?';
tagList_ss << REGIMGID;

if ( ( index + 1 ) != tagListEnd )
tagList_ss << ' ';
}

string newList = tagList_ss.str();

SendMessage( scintilla, SCI_AUTOCSETSEPARATOR, WPARAM( ' ' ), 0 );
SendMessage( scintilla, SCI_AUTOCSETTYPESEPARATOR, WPARAM('?'), 0 );
SendMessage( scintilla, SCI_AUTOCSETIGNORECASE, true, 0 );
SendMessage( scintilla, SCI_REGISTERIMAGE, REGIMGID, (LPARAM)xpmQt );
SendMessage( scintilla, SCI_AUTOCSHOW, ( WPARAM ) strlen( tag ),
( LPARAM )newList.c_str() );
}
if ( g_bCharAdded )
{
restoreKeyStroke( curPos, scintilla );
g_bCharAdded = false;
return;
}

// check exact tag match
if ( tagInCurrentLang || tagInGlobalLang )
{
Expand Down Expand Up @@ -627,37 +690,6 @@ void QuickText()
else if ( cQuickText.editing )
jump( scintilla );
// autoComplete mode for tags
else if ( tagList.size() > 0 )
{
SendMessage( scintilla, SCI_AUTOCSETSEPARATOR, WPARAM( ' ' ), 0 );
SendMessage( scintilla, SCI_AUTOCSETTYPESEPARATOR, WPARAM('?'), 0 );
SendMessage( scintilla, SCI_AUTOCSETIGNORECASE, true, 0 );
SendMessage( scintilla, SCI_REGISTERIMAGE, REGIMGID, (LPARAM)xpmQt );

// restoring original selection
SendMessage( scintilla, SCI_SETCURRENTPOS, curPos, 0 );
SendMessage( scintilla, SCI_SETSELECTIONSTART, curPos, ( LPARAM )true );
SendMessage( scintilla, SCI_SETSELECTIONEND, curPos, ( LPARAM )true );

stringstream tagList_ss;
TagList::const_iterator tagListEnd = tagList.end();

for ( TagList::const_iterator index = tagList.begin(); index != tagListEnd;
index++ )
{
tagList_ss << *index;
tagList_ss << '?';
tagList_ss << REGIMGID;

if ( ( index + 1 ) != tagListEnd )
tagList_ss << ' ';
}

string newList = tagList_ss.str();

SendMessage( scintilla, SCI_AUTOCSHOW, ( WPARAM ) strlen( tag ),
( LPARAM )newList.c_str() );
}
else
restoreKeyStroke( curPos, scintilla );

Expand Down Expand Up @@ -723,6 +755,8 @@ BOOL CALLBACK DlgConfigProc( HWND hwndDlg, UINT message, WPARAM wParam,
version += "</a>";
SetDlgItemTextA( hwndDlg, IDC_STC_VER, version.c_str() );

SendMessage( GetDlgItem( hwndDlg, IDC_CHK_USA ), BM_SETCHECK,
( WPARAM )( g_bUseSciAutoC ? 1 : 0 ), 0 );
SendMessage( GetDlgItem( hwndDlg, IDC_CHK_AIA ), BM_SETCHECK,
( WPARAM )( g_bInsertOnAutoC ? 1 : 0 ), 0 );

Expand Down Expand Up @@ -804,6 +838,19 @@ BOOL CALLBACK DlgConfigProc( HWND hwndDlg, UINT message, WPARAM wParam,

return TRUE;

case IDC_CHK_USA:
{
int check = ( int )::SendMessage( GetDlgItem( hwndDlg, IDC_CHK_USA ),
BM_GETCHECK, 0, 0 );

if ( check & BST_CHECKED )
g_bUseSciAutoC = true;
else
g_bUseSciAutoC = false;

return TRUE;
}

case IDC_CHK_AIA:
{
int check = ( int )::SendMessage( GetDlgItem( hwndDlg, IDC_CHK_AIA ),
Expand Down
8 changes: 5 additions & 3 deletions QuickText.rc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ END
// Dialog
//

IDD_DLGCONFIG DIALOGEX 0, 0, 303, 202
IDD_DLGCONFIG DIALOGEX 0, 0, 303, 220
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "QuickText"
FONT 8, "Verdana", 400, 0, 0x0
Expand All @@ -90,8 +90,10 @@ BEGIN
PUSHBUTTON "&Delete",IDDEL,262,7,34,14
CONTROL "Version",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_DISABLED|WS_GROUP,10,181,30,11
CONTROL "<a></a>",IDC_STC_VER,"SysLink",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|LWS_TRANSPARENT,40,181,40,11
CONTROL "Auto &Insert Autocomplete",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,106,181,100,11
CONTROL "",IDC_CHK_AIA,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,94,181,10,9
CONTROL "&Use Scintilla Autocomplete",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,106,181,100,11
CONTROL "",IDC_CHK_USA,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,94,181,10,9
CONTROL "Auto &Insert Autocomplete",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,106,196,100,11
CONTROL "",IDC_CHK_AIA,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,94,196,10,9
PUSHBUTTON "&Cancel",IDCANCEL,260,181,36,14
END

Expand Down
10 changes: 5 additions & 5 deletions QuickText.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
<ProjectGuid>{9AF7EA4A-9B49-4684-A62F-865469A4DD10}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>QuickText</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>false</UseOfMfc>
<UseOfAtl>false</UseOfAtl>
Expand All @@ -37,7 +37,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>false</UseOfMfc>
<UseOfAtl>false</UseOfAtl>
Expand All @@ -46,14 +46,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
22 changes: 22 additions & 0 deletions QuickText.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project>

<!--
Rename PROJECTNAME to the same as the *.vcxproj file in your project.

Or, import into that file by adding before the last closing tag:

<Import Project="PROJECTNAME.vcxproj.user"/>

Then, call with:

msbuild /target:zip
-->

<Target Name="Zip" DependsOnTargets="Build">
<Exec Command="if not exist $(OutDir)$(TargetName) mkdir $(OutDir)$(TargetName)"/>
<Exec Command="copy $(OutDir)$(TargetName)$(TargetExt) $(OutDir)$(TargetName)"/>
<Exec Command="copy Config\QuickText.default.ini $(OutDir)$(TargetName)"/>
<Exec Command="for /f %%i in ('powershell -Command &quot;(Get-Item $(OutDir)$(TargetName)$(TargetExt)).VersionInfo.ProductVersion&quot;') do del $(OutDir)$(TargetName)-v%%i-%Platform%.zip"/>
<Exec Command="for /f %%i in ('powershell -Command &quot;(Get-Item $(OutDir)$(TargetName)$(TargetExt)).VersionInfo.ProductVersion&quot;') do cd $(OutDir)$(TargetName) %26%26 zip -r ..\$(TargetName)-v%%i-%Platform%.zip *"/>
</Target>
</Project>
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,32 @@ to the Notepad++ plugins folder:
Assign a shortcut key to the Plugins => QuickText => Replace Tag menu to
use QuickText tags from within the current Notepad++ document.

If the Tag insertion hotkey is used and there is no text before it or
no valid expansion for the text before it, the Tag insertion hotkey
If the Replace Tag hotkey is used and there is no text before it or
no valid expansion for the text before it, the Replace Tag hotkey
character is inserted. For example, using "Tab" as the key with
no valid expansion just inserts a tab (as if Tab key press).

Once a Tag is inserted, you can use the Tag insertion hotkey again and
Once a Tag is inserted, you can use the Replace Tag hotkey again and
again to navigate through the hotspots in the inserted Tag snippet.

**NOTE:** Tab can now be used again as the Tag insertion hotkey.
**NOTE:** Tab can now be used again as the Replace Tag hotkey.
There is no default.

## Customization

Settings:

Use to configure Tags for languages.
+ **Use Scintilla Autocomplete**: uses Scintilla autocomplete while typing to
suggest tags for the current language. Without this enabled, you need to
trigger the Replace Tag hotkey to get the autocomplete list or just type
a Tag from memory.
+ **Auto Insert Autocomplete**: when a tag is completed from a Scintilla
autocompletion, expand the tag. Without this enabled, you need to trigger
the Replace Tag hotkey again to expand the Tag.

To make you're own tags:

+ Tags file (QuickText.ini) *MUST* use "Windows (CR LF)" line endings.
+ First make sure the tag's Language Section already exists. This is
done by creating a new section with the code corresponding to the
Expand Down
6 changes: 5 additions & 1 deletion lib/INIMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ TagList INIMap::queryTags( cstring &section, cstring &tag )
tagPointer++;
}

sort( tagList.begin(), tagList.end() );
// Nice to return a sorted list, but if we get a language list (sort)
// then a global list (sort) and then combine, still need to sort the
// result - so 3 sorts? How about skip it and only sort the one time,
// since we only call queryTags() from QuickText()
// sort( tagList.begin(), tagList.end() );
}

return tagList;
Expand Down
5 changes: 3 additions & 2 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/* VERSION DEFINITIONS */
#define VER_MAJOR 0
#define VER_MINOR 2
#define VER_RELEASE 1
#define VER_RELEASE 2
#define VER_BUILD 1
#define VER_STRING STR(VER_MAJOR) "." STR(VER_MINOR) "." STR(VER_RELEASE) "." STR(VER_BUILD)

Expand Down Expand Up @@ -40,7 +40,8 @@
#define IDSMARTEDIT 1017
#define IDC_EDIT1 1018
#define IDC_STC_VER 1019
#define IDC_CHK_AIA 1020
#define IDC_CHK_USA 1020
#define IDC_CHK_AIA 1021

// Next default values for new objects
//
Expand Down

0 comments on commit 8a43682

Please sign in to comment.