[ENHANCEMENT] Enhance the auto-completion feature : user can define the number of characters to trigger auto-completion popup dialog.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@136 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
donho 2008-02-22 22:55:56 +00:00
parent a9172eee73
commit dbd9afeaca
10 changed files with 90 additions and 13 deletions

View File

@ -1902,12 +1902,18 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case SCN_CHARADDED:
{
charAdded(static_cast<char>(notification->ch));
const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI();
if (nppGUI._autocStatus == nppGUI.autoc_word)
autoCompFromCurrentFile(false);
else if (nppGUI._autocStatus == nppGUI.autoc_func)
showAutoComp();
static const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI();
char s[64];
_pEditView->getWordToCurrentPos(s, sizeof(s));
if (strlen(s) >= nppGUI._autocFromLen)
{
if (nppGUI._autocStatus == nppGUI.autoc_word)
autoCompFromCurrentFile(false);
else if (nppGUI._autocStatus == nppGUI.autoc_func)
showAutoComp();
}
break;
}
@ -3409,6 +3415,27 @@ void Notepad_plus::command(int id)
break;
}
case IDM_SETTING_AUTOCNBCHAR:
{
const int NB_MAX_CHAR = 9;
ValueDlg valDlg;
NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
valDlg.init(_hInst, _hSelf, nppGUI._autocFromLen, "Nb char : ");
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_hParent, &p);
int size = valDlg.doDialog(p, _isRTL);
if (size != -1)
{
if (size > NB_MAX_CHAR)
size = NB_MAX_CHAR;
nppGUI._autocFromLen = size;
}
break;
}
case IDM_SETTING_HISTORY_SIZE :
{
ValueDlg nbHistoryDlg;

View File

@ -2593,6 +2593,9 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
int i;
if (element->Attribute("autoCAction", &i))
_nppGUI._autocStatus = (NppGUI::AutocStatus)i;
if (element->Attribute("triggerFromNbChar", &i))
_nppGUI._autocFromLen = i;
}
else if (!strcmp(nm, "sessionExt"))
{
@ -3148,6 +3151,7 @@ bool NppParameters::writeGUIParams()
{
autocExist = true;
element->SetAttribute("autoCAction", _nppGUI._autocStatus);
element->SetAttribute("triggerFromNbChar", _nppGUI._autocFromLen);
}
else if (!strcmp(nm, "sessionExt"))
{
@ -3275,6 +3279,7 @@ bool NppParameters::writeGUIParams()
TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement("GUIConfig")))->ToElement();
GUIConfigElement->SetAttribute("name", "auto-completion");
GUIConfigElement->SetAttribute("autoCAction", _nppGUI._autocStatus);
GUIConfigElement->SetAttribute("triggerFromNbChar", _nppGUI._autocFromLen);
}
if (!saveOpenFileInSameDirExist)

View File

@ -522,7 +522,7 @@ struct NppGUI
_tabReplacedBySpace(false), _fileAutoDetection(cdEnabled), _checkHistoryFiles(true),\
_isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _backup(bak_none), _useDir(false),\
_doTaskList(true), _maitainIndent(true), _saveOpenKeepInSameDir(false), _styleMRU(true), _styleURL(0),
_autocStatus(autoc_none), _definedSessionExt(""), _neverUpdate(false), _doesExistUpdater(false){
_autocStatus(autoc_none), _autocFromLen(1), _definedSessionExt(""), _neverUpdate(false), _doesExistUpdater(false){
_appPos.left = 0;
_appPos.top = 0;
_appPos.right = 700;
@ -579,6 +579,8 @@ struct NppGUI
GlobalOverride _globalOverride;
enum AutocStatus{autoc_none, autoc_func, autoc_word};
AutocStatus _autocStatus;
size_t _autocFromLen;
string _definedSessionExt;
bool _neverUpdate;
bool _doesExistUpdater;

View File

@ -1159,7 +1159,7 @@ void ScintillaEditView::removeAllUnusedDocs()
_buffers.clear();
}
void ScintillaEditView::getText(char *dest, int start, int end)
void ScintillaEditView::getText(char *dest, int start, int end) const
{
TextRange tr;
tr.chrg.cpMin = start;

View File

@ -194,7 +194,7 @@ public:
void removeAllUnusedDocs();
void getText(char *dest, int start, int end);
void getText(char *dest, int start, int end) const;
void setCurrentDocState(bool isDirty) {
_buffers[_currentIndex]._isDirty = isDirty;
@ -270,6 +270,15 @@ public:
return crange;
};
void getWordToCurrentPos(char *str, int strLen) const {
int caretPos = execute(SCI_GETCURRENTPOS);
int startPos = static_cast<int>(execute(SCI_WORDSTARTPOSITION, caretPos, true));
str[0] = '\0';
if ((caretPos - startPos) < strLen)
getText(str, startPos, caretPos);
};
LangType getCurrentDocType() const {
return _buffers[_currentIndex]._lang;
};

View File

@ -203,7 +203,7 @@ IDD_PREFERENCE_BACKUP_BOX DIALOGEX 0, 0, 370, 180
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
GROUPBOX "Backup",IDC_BACKUPDIR_GRP_STATIC,46,14,289,83,BS_CENTER
GROUPBOX "Backup",IDC_BACKUPDIR_GRP_STATIC,46,11,289,86,BS_CENTER
CONTROL "None",IDC_RADIO_BKNONE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,71,24,87,10
CONTROL "Simple Backup",IDC_RADIO_BKSIMPLE,"Button",BS_AUTORADIOBUTTON,195,24,111,10
CONTROL "Verbose Backup",IDC_RADIO_BKVERBOSE,"Button",BS_AUTORADIOBUTTON,195,38,111,10
@ -212,9 +212,12 @@ BEGIN
RTEXT "Directory :",IDD_BACKUPDIR_STATIC,66,67,40,8
EDITTEXT IDC_BACKUPDIR_EDIT,113,65,179,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDD_BACKUPDIR_BROWSE_BUTTON,299,65,16,14
GROUPBOX "Auto-completion",IDD_AUTOC_GRPSTATIC,46,103,289,56,BS_CENTER
GROUPBOX "Auto-completion",IDD_AUTOC_GRPSTATIC,46,103,289,59,BS_CENTER
CONTROL "Enable Auto-completion on each input",IDD_AUTOC_ENABLECHECK,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,61,113,150,10
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,51,114,150,10
CONTROL "Function completion",IDD_AUTOC_FUNCRADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP,78,128,145,10
CONTROL "Word completion",IDD_AUTOC_WORDRADIO,"Button",BS_AUTORADIOBUTTON,78,144,145,10
RTEXT "From",IDD_AUTOC_STATIC_FROM,208,114,47,8
CTEXT "1",IDD_AUTOC_STATIC_N,259,114,8,8
LTEXT "th characters",IDD_AUTOC_STATIC_CHAR,273,114,57,8
END

View File

@ -427,10 +427,11 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
{
char nbStr[10];
itoa(nppGUI._tabSize, nbStr, 10);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
HWND hTabSize_val = ::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC);
::SetWindowText(hTabSize_val, nbStr);
_tabSizeVal.init(_hInst, _hSelf);
_tabSizeVal.create(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), IDM_SETTING_TAB_SIZE);
_tabSizeVal.create(hTabSize_val, IDM_SETTING_TAB_SIZE);
itoa(pNppParam->getNbMaxFile(), nbStr, 10);
::SetWindowText(::GetDlgItem(_hSelf, IDC_MAXNBFILEVAL_STATIC), nbStr);
@ -584,6 +585,7 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
return TRUE;
}
case IDM_SETTING_HISTORY_SIZE:
{
::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_HISTORY_SIZE, 0);
@ -592,6 +594,7 @@ BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
::SetWindowText(::GetDlgItem(_hSelf, IDC_MAXNBFILEVAL_STATIC), nbStr);
return TRUE;
}
case IDC_CHECK_ENABLEDOCSWITCHER :
{
NppGUI & nppGUI = (NppGUI &)NppParameters::getInstance()->getNppGUI();
@ -1284,6 +1287,14 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
case WM_INITDIALOG :
{
char nbStr[10];
itoa(nppGUI._autocFromLen, nbStr, 10);
HWND hNbChar_val = ::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N);
::SetWindowText(hNbChar_val, nbStr);
_nbCharVal.init(_hInst, _hSelf);
_nbCharVal.create(hNbChar_val, IDM_SETTING_AUTOCNBCHAR);
int ID2Check = 0;
switch (nppGUI._backup)
@ -1314,6 +1325,9 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), FALSE);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_CHAR), FALSE);
}
updateBackupGUI();
return TRUE;
@ -1386,6 +1400,9 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
}
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), isEnableAutoC);
::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_CHAR), isEnableAutoC);
return TRUE;
}
@ -1400,6 +1417,15 @@ BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
nppGUI._autocStatus = nppGUI.autoc_word;
return TRUE;
}
case IDM_SETTING_AUTOCNBCHAR :
{
::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_AUTOCNBCHAR, 0);
char nbStr[10];
sprintf(nbStr, "%d", pNppParam->getNppGUI()._autocFromLen);
::SetWindowText(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), nbStr);
return TRUE;
}
default :
return FALSE;

View File

@ -106,6 +106,7 @@ class BackupDlg : public StaticDialog
public :
BackupDlg() {};
private :
URLCtrl _nbCharVal;
void updateBackupGUI();
BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
};

View File

@ -170,3 +170,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define IDD_AUTOC_ENABLECHECK (IDD_PREFERENCE_BACKUP_BOX + 8)
#define IDD_AUTOC_FUNCRADIO (IDD_PREFERENCE_BACKUP_BOX + 9)
#define IDD_AUTOC_WORDRADIO (IDD_PREFERENCE_BACKUP_BOX + 10)
#define IDD_AUTOC_STATIC_FROM (IDD_PREFERENCE_BACKUP_BOX + 11)
#define IDD_AUTOC_STATIC_N (IDD_PREFERENCE_BACKUP_BOX + 12)
#define IDD_AUTOC_STATIC_CHAR (IDD_PREFERENCE_BACKUP_BOX + 13)

View File

@ -273,6 +273,7 @@
#define IDM_SETTING_FILE_AUTODETECTION_ENABLE (IDM_SETTING + 12)
#define IDM_SETTING_FILE_AUTODETECTION_DISABLE (IDM_SETTING + 13)
#define IDM_SETTING_FILE_AUTODETECTION_ENABLESILENTLY (IDM_SETTING + 14)
#define IDM_SETTING_AUTOCNBCHAR (IDM_SETTING + 15)
// Menu macro
#define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18)