[NEW_FEATURE] Tab settings per language (in prograss)

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@521 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2009-08-14 00:41:41 +00:00
parent ff1d754ad7
commit 7472160a99
8 changed files with 185 additions and 63 deletions

View File

@ -4128,29 +4128,9 @@ void Notepad_plus::command(int id)
}
case IDM_SETTING_TAB_REPLCESPACE:
{
NppGUI & nppgui = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
nppgui._tabReplacedBySpace = !nppgui._tabReplacedBySpace;
_pEditView->execute(SCI_SETUSETABS, !nppgui._tabReplacedBySpace);
//checkMenuItem(IDM_SETTING_TAB_REPLCESPACE, nppgui._tabReplacedBySpace);
break;
}
case IDM_SETTING_TAB_SIZE:
{
ValueDlg tabSizeDlg;
NppGUI & nppgui = (NppGUI &)((NppParameters::getInstance())->getNppGUI());
tabSizeDlg.init(_hInst, _preference.getHSelf(), nppgui._tabSize, TEXT("Tab Size : "));
POINT p;
::GetCursorPos(&p);
::ScreenToClient(_hParent, &p);
int size = tabSizeDlg.doDialog(p, _isRTL);
if (size != -1)
{
nppgui._tabSize = size;
_pEditView->execute(SCI_SETTABWIDTH, nppgui._tabSize);
}
_pEditView->setTabSettings(_pEditView->getCurrentBuffer()->getCurrentLang());
break;
}

View File

@ -2470,6 +2470,9 @@ void NppParameters::feedKeyWordsParameters(TiXmlNode *node)
_langList[_nbLang]->setCommentLineSymbol(element->Attribute(TEXT("commentLine")));
_langList[_nbLang]->setCommentStart(element->Attribute(TEXT("commentStart")));
_langList[_nbLang]->setCommentEnd(element->Attribute(TEXT("commentEnd")));
int i;
if (element->Attribute(TEXT("TabSettings"), &i))
_langList[_nbLang]->setTabInfo(i);
for (TiXmlNode *kwNode = langNode->FirstChildElement(TEXT("Keywords"));
kwNode ;

View File

@ -801,9 +801,11 @@ struct Lang
};
void setTabInfo(int tabInfo) {
if (tabInfo == -1 || tabInfo == 0) return;
if (tabInfo & MASK_TabSize)
{
_isTabReplacedBySpace = (tabInfo & MASK_ReplaceBySpc) != 0;
_tabSize = tabInfo & MASK_TabSize;
}
};
const TCHAR * getDefaultExtList() const {
@ -1376,7 +1378,6 @@ private:
*_pXmlToolIconsDoc, *_pXmlShortcutDoc, *_pXmlContextMenuDoc, *_pXmlSessionDoc;
TiXmlDocumentA *_pXmlNativeLangDocA;
//TiXmlDocumentA *_pXmlEnglishDocA;
vector<TiXmlDocument *> _pXmlExternalLexerDoc;

View File

@ -1318,8 +1318,7 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
Style & styleLN = stylers.getStyler(indexLineNumber);
setSpecialStyle(styleLN);
}
execute(SCI_SETTABWIDTH, ((NppParameters::getInstance())->getNppGUI())._tabSize);
execute(SCI_SETUSETABS, !((NppParameters::getInstance())->getNppGUI())._tabReplacedBySpace);
setTabSettings(_pParameter->getLangFromID(typeDoc));
int bitsNeeded = execute(SCI_GETSTYLEBITSNEEDED);
execute(SCI_SETSTYLEBITS, bitsNeeded);
@ -2584,7 +2583,7 @@ void ScintillaEditView::runMarkers(bool doHide, int searchStart, bool endOfDoc,
void ScintillaEditView::setTabSettings(Lang *lang)
{
if (lang->_tabSize != -1 && lang->_tabSize != 0)
if (lang && lang->_tabSize != -1 && lang->_tabSize != 0)
{
execute(SCI_SETTABWIDTH, lang->_tabSize);
execute(SCI_SETUSETABS, lang->_isTabReplacedBySpace);

View File

@ -89,10 +89,6 @@ BEGIN
COMBOBOX IDC_WIDTH_COMBO,66,22,40,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Blink Rate :",IDC_BLINKRATE_STATIC,138,17,50,8
CONTROL "",IDC_CARETBLINKRATE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,133,29,67,13
GROUPBOX "Tab Setting",IDC_TABSETTING_GB_STATIC,238,4,130,40,BS_CENTER
CONTROL "Replace by space",IDC_CHECK_REPLACEBYSPACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,256,27,100,10
RTEXT "Tab size : ",IDC_TABSIZE_STATIC,251,14,58,8
LTEXT "0",IDC_TABSIZEVAL_STATIC,311,14,18,8
LTEXT "S",IDC_CARETBLINKRATE_S_STATIC,202,29,12,8
LTEXT "F",IDC_CARETBLINKRATE_F_STATIC,121,29,12,8,0,WS_EX_RIGHT
END
@ -162,13 +158,22 @@ IDD_PREFERENCE_LANG_BOX DIALOGEX 0, 0, 390, 185
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD
FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1
BEGIN
LISTBOX IDC_LIST_ENABLEDLANG,85,39,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_LIST_DISABLEDLANG,231,39,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "->",IDC_BUTTON_REMOVE,172,71,50,14
PUSHBUTTON "<-",IDC_BUTTON_RESTORE,173,102,50,14
CTEXT "Available items",IDC_ENABLEDITEMS_STATIC,88,26,72,8
CTEXT "Disabled items",IDC_DISABLEDITEMS_STATIC,234,26,72,8
CONTROL "Make Language Menu compact",IDC_CHECK_LANGMENUCOMPACT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,86,5,174,10
GROUPBOX "Language Menu",IDC_CHECK_LANGMENU_GR_STATIC,5,3,220,172,BS_CENTER
CONTROL "Make Language Menu compact",IDC_CHECK_LANGMENUCOMPACT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,19,14,174,10
CTEXT "Available items",IDC_ENABLEDITEMS_STATIC,23,31,72,8
LISTBOX IDC_LIST_ENABLEDLANG,18,44,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "->",IDC_BUTTON_REMOVE,103,76,25,14
PUSHBUTTON "<-",IDC_BUTTON_RESTORE,103,107,25,14
CTEXT "Disabled items",IDC_DISABLEDITEMS_STATIC,138,31,72,8
LISTBOX IDC_LIST_DISABLEDLANG,135,44,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Tab Setting",IDC_TABSETTING_GB_STATIC,238,3,130,172,BS_CENTER
LISTBOX IDC_LIST_TABSETTNG,260,18,84,100,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
GROUPBOX "",IDC_GR_TABVALUE_STATIC,250,125,110,42,BS_CENTER
CONTROL "Use default value",IDC_CHECK_DEFAULTTABVALUE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,246,125,85,10
RTEXT "Tab size : ",IDC_TABSIZE_STATIC,251,138,58,8
LTEXT "0",IDC_TABSIZEVAL_STATIC,311,138,18,8
CONTROL "Replace by space",IDC_CHECK_REPLACEBYSPACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,258,149,100,10
END
IDD_PREFERENCE_PRINT_BOX DIALOGEX 0, 0, 390, 185

View File

@ -17,6 +17,7 @@
#include <windows.h>
#include "preferenceDlg.h"
#include "lesDlgs.h"
const int BLINKRATE_FASTEST = 50;
const int BLINKRATE_SLOWEST = 2500;
@ -376,15 +377,6 @@ BOOL CALLBACK MarginsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
{
case WM_INITDIALOG :
{
TCHAR nbStr[10];
wsprintf(nbStr, TEXT("%d"), nppGUI._tabSize);
HWND hTabSize_val = ::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC);
::SetWindowText(hTabSize_val, nbStr);
_tabSizeVal.init(_hInst, _hSelf);
_tabSizeVal.create(hTabSize_val, IDM_SETTING_TAB_SIZE);
::SendDlgItemMessage(_hSelf, IDC_CHECK_REPLACEBYSPACE, BM_SETCHECK, nppGUI._tabReplacedBySpace, 0);
_verticalEdgeLineNbColVal.init(_hInst, _hSelf);
_verticalEdgeLineNbColVal.create(::GetDlgItem(_hSelf, IDC_COLONENUMBER_STATIC), IDM_SETTING_EDGE_SIZE);
@ -437,19 +429,6 @@ BOOL CALLBACK MarginsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
int iView = i + 1;
switch (wParam)
{
case IDM_SETTING_TAB_SIZE:
{
::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_TAB_SIZE, 0);
TCHAR nbStr[10];
wsprintf(nbStr, TEXT("%d"), nppGUI._tabSize);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
return TRUE;
}
case IDC_CHECK_REPLACEBYSPACE:
::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_TAB_REPLCESPACE, 0);
return TRUE;
case IDC_CHECK_LINENUMBERMARGE:
svp._lineNumberMarginShow = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_LINENUMBERMARGE, BM_GETCHECK, 0, 0));
::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_LINENUMBER, iView);
@ -1041,6 +1020,27 @@ BOOL CALLBACK LangMenuDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
{
case WM_INITDIALOG :
{
TCHAR nbStr[10];
wsprintf(nbStr, TEXT("%d"), nppGUI._tabSize);
HWND hTabSize_val = ::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC);
::SetWindowText(hTabSize_val, nbStr);
_tabSizeVal.init(_hInst, _hSelf);
_tabSizeVal.create(hTabSize_val, IDM_SETTING_TAB_SIZE);
::SendDlgItemMessage(_hSelf, IDC_CHECK_REPLACEBYSPACE, BM_SETCHECK, nppGUI._tabReplacedBySpace, 0);
int nbLang = pNppParam->getNbLang();
::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_ADDSTRING, 0, (LPARAM)TEXT("[Default]"));
for (int i = 0 ; i < nbLang ; i++)
{
::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_ADDSTRING, 0, (LPARAM)pNppParam->getLangFromIndex(i)->_langName.c_str());
}
const int index2Begin = 0;
::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_SETCURSEL, 0, index2Begin);
::ShowWindow(::GetDlgItem(_hSelf, IDC_GR_TABVALUE_STATIC), SW_HIDE);
::ShowWindow(::GetDlgItem(_hSelf, IDC_CHECK_DEFAULTTABVALUE), SW_HIDE);
for (int i = L_TXT ; i < pNppParam->L_END ; i++)
{
generic_string str;
@ -1078,6 +1078,134 @@ BOOL CALLBACK LangMenuDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPara
{
switch (LOWORD(wParam))
{
case IDM_SETTING_TAB_SIZE:
{
ValueDlg tabSizeDlg;
tabSizeDlg.init(_hInst, _hParent, nppGUI._tabSize, TEXT("Tab Size : "));
POINT p;
::GetCursorPos(&p);//::GetParent(::GetParent(_hParent))
//::ScreenToClient(NULL, &p);
int size = tabSizeDlg.doDialog(p);
if (size == -1) return FALSE;
TCHAR nbStr[10];
wsprintf(nbStr, TEXT("%d"), size);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
int index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
if (index == LB_ERR) return FALSE;
if (index != 0)
{
Lang *lang = pNppParam->getLangFromIndex(index - 1);
if (!lang) return FALSE;
lang->_tabSize = size;
}
else
{
nppGUI._tabSize = size;
}
::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_TAB_SIZE, 0);
return TRUE;
}
case IDC_CHECK_REPLACEBYSPACE:
{
bool isTabReplacedBySpace = BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), BM_GETCHECK, 0, 0);
int index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
if (index == LB_ERR) return FALSE;
if (index != 0)
{
Lang *lang = pNppParam->getLangFromIndex(index - 1);
if (!lang) return FALSE;
lang->_isTabReplacedBySpace = isTabReplacedBySpace;
}
else
{
nppGUI._tabReplacedBySpace = isTabReplacedBySpace;
}
::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_TAB_REPLCESPACE, 0);
return TRUE;
}
case IDC_LIST_TABSETTNG :
{
if (HIWORD(wParam) == CBN_SELCHANGE)
{
int index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
if (index == LB_ERR)
return FALSE;
::ShowWindow(::GetDlgItem(_hSelf, IDC_GR_TABVALUE_STATIC), index?SW_SHOW:SW_HIDE);
::ShowWindow(::GetDlgItem(_hSelf, IDC_CHECK_DEFAULTTABVALUE), index?SW_SHOW:SW_HIDE);
if (index)
{
Lang *lang = pNppParam->getLangFromIndex(index - 1);
if (!lang) return FALSE;
bool useDefaultTab = (lang->_tabSize == -1 || lang->_tabSize == 0);
TCHAR nbStr[16];
wsprintf(nbStr, TEXT("%d"), useDefaultTab?nppGUI._tabSize:lang->_tabSize);
::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_DEFAULTTABVALUE), BM_SETCHECK, useDefaultTab, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDC_TABSIZE_STATIC), !useDefaultTab);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
::EnableWindow(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), !useDefaultTab);
::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), BM_SETCHECK, useDefaultTab?nppGUI._tabReplacedBySpace:lang->_isTabReplacedBySpace, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), !useDefaultTab);
if (!useDefaultTab)
{
TCHAR nbStr[16];
wsprintf(nbStr, TEXT("%d"),lang->_tabSize);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), BM_SETCHECK, lang->_isTabReplacedBySpace, 0);
}
}
else
{
::EnableWindow(::GetDlgItem(_hSelf, IDC_TABSIZE_STATIC), TRUE);
::EnableWindow(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), TRUE);
TCHAR nbStr[16];
wsprintf(nbStr, TEXT("%d"),nppGUI._tabSize);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), TRUE);
::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), BM_SETCHECK, nppGUI._tabReplacedBySpace, 0);
}
}
return TRUE;
}
case IDC_CHECK_DEFAULTTABVALUE:
{
bool useDefaultTab = BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_DEFAULTTABVALUE), BM_GETCHECK, 0, 0);
int index = ::SendDlgItemMessage(_hSelf, IDC_LIST_TABSETTNG, LB_GETCURSEL, 0, 0);
if (index == LB_ERR || index == 0) // index == 0 shouldn't happen
return FALSE;
Lang *lang = pNppParam->getLangFromIndex(index - 1);
if (!lang)
return FALSE;
//- Set tab setting in choosed language
lang->_tabSize = useDefaultTab?0:nppGUI._tabSize;
lang->_isTabReplacedBySpace = useDefaultTab?false:nppGUI._tabReplacedBySpace;
TCHAR nbStr[16];
wsprintf(nbStr, TEXT("%d"), useDefaultTab?nppGUI._tabSize:lang->_tabSize);
//- set visual effect
::EnableWindow(::GetDlgItem(_hSelf, IDC_TABSIZE_STATIC), !useDefaultTab);
::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr);
::EnableWindow(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), !useDefaultTab);
::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), BM_SETCHECK, useDefaultTab?nppGUI._tabReplacedBySpace:lang->_isTabReplacedBySpace, 0);
::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_REPLACEBYSPACE), !useDefaultTab);
return TRUE;
}
case IDC_LIST_DISABLEDLANG :
case IDC_LIST_ENABLEDLANG :
{

View File

@ -57,12 +57,10 @@ class MarginsDlg : public StaticDialog
public :
MarginsDlg() {};
virtual void destroy() {
_tabSizeVal.destroy();
_verticalEdgeLineNbColVal.destroy();
};
private :
URLCtrl _tabSizeVal;
URLCtrl _verticalEdgeLineNbColVal;
BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
void changePanelTo(int index);
@ -93,7 +91,13 @@ class LangMenuDlg : public StaticDialog
{
public :
LangMenuDlg() {};
virtual void destroy() {
_tabSizeVal.destroy();
};
private :
URLCtrl _tabSizeVal;
LexerStylerArray _lsArray;
BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
vector<LangMenuItem> _langList;
};
@ -132,8 +136,6 @@ private :
int _focusedEditCtrl;
DWORD _selStart;
DWORD _selEnd;
//ColourStaticTextHooker _colourHooker;
};
class PreferenceDlg : public StaticDialog

View File

@ -140,6 +140,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#define IDC_ENABLEDITEMS_STATIC (IDD_PREFERENCE_LANG_BOX + 5)
#define IDC_DISABLEDITEMS_STATIC (IDD_PREFERENCE_LANG_BOX + 6)
#define IDC_CHECK_LANGMENUCOMPACT (IDD_PREFERENCE_LANG_BOX + 7)
#define IDC_CHECK_LANGMENU_GR_STATIC (IDD_PREFERENCE_LANG_BOX + 8)
#define IDC_LIST_TABSETTNG (IDD_PREFERENCE_LANG_BOX + 9)
#define IDC_CHECK_DEFAULTTABVALUE (IDD_PREFERENCE_LANG_BOX + 10)
#define IDC_GR_TABVALUE_STATIC (IDD_PREFERENCE_LANG_BOX + 11)
#define IDD_PREFERENCE_PRINT_BOX 6600 //(IDD_PREFERENCE_BOX + 600)
#define IDC_CHECK_PRINTLINENUM (IDD_PREFERENCE_PRINT_BOX + 1)