Add UI part for Document snapshot feature

Enhance doc snapshot on several points.
This commit is contained in:
Don HO 2017-04-27 13:03:31 +02:00
parent a43c9b9745
commit 8752bcad57
8 changed files with 80 additions and 39 deletions

View File

@ -36,9 +36,6 @@
using namespace std;
bool doSnapshot = true;
bool doSnapshotOnMap = true;
// Only for 2 main Scintilla editors
BOOL Notepad_plus::notify(SCNotification *notification)
{
@ -153,16 +150,22 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case TCN_MOUSEHOVERING:
case TCN_MOUSEHOVERSWITCHING:
{
NppParameters *pNppParam = NppParameters::getInstance();
bool doSnapshot = pNppParam->getNppGUI()._isDocSnapshotOnTab;
bool doSnapshotOnMap = pNppParam->getNppGUI()._isDocSnapshotOnMap;
if (doSnapshot)
{
TBHDR *tbHdr = reinterpret_cast<TBHDR *>(notification);
DocTabView *pTabDocView = isFromPrimary ? &_mainDocTab : (isFromSecondary ? &_subDocTab : nullptr);
if (pTabDocView)
{
BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin);
Buffer *pBuf = MainFileManager->getBufferByID(id);
Buffer *currentBuf = getCurrentBuffer();
Buffer *currentBufMain = _mainEditView.getCurrentBuffer();
Buffer *currentBufSub = _subEditView.getCurrentBuffer();
RECT rect;
TabCtrl_GetItemRect(pTabDocView->getHSelf(), tbHdr->_tabOrigin, &rect);
@ -171,7 +174,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
p.y = rect.bottom;
::ClientToScreen(pTabDocView->getHSelf(), &p);
if (pBuf != currentBuf) // if hover on other tab
if (pBuf != currentBufMain && pBuf != currentBufSub) // if hover on other tab
{
_documentSnapshot.doDialog(p, pBuf, *(const_cast<ScintillaEditView*>(pTabDocView->getScintillaEditView())));
}
@ -182,7 +185,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
}
}
if (_pDocMap && (!_pDocMap->isClosed()) && _pDocMap->isVisible() && doSnapshotOnMap)
if (doSnapshotOnMap && _pDocMap && (!_pDocMap->isClosed()) && _pDocMap->isVisible())
{
TBHDR *tbHdr = reinterpret_cast<TBHDR *>(notification);
DocTabView *pTabDocView = isFromPrimary ? &_mainDocTab : (isFromSecondary ? &_subDocTab : nullptr);
@ -191,9 +194,10 @@ BOOL Notepad_plus::notify(SCNotification *notification)
BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin);
Buffer *pBuf = MainFileManager->getBufferByID(id);
Buffer *currentBuf = getCurrentBuffer();
Buffer *currentBufMain = _mainEditView.getCurrentBuffer();
Buffer *currentBufSub = _subEditView.getCurrentBuffer();
if (pBuf != currentBuf) // if hover on other tab
if (pBuf != currentBufMain && pBuf != currentBufSub) // if hover on other tab
{
_pDocMap->showInMapTemporarily(pBuf, notifyView);
_pDocMap->setSyntaxHiliting();
@ -212,6 +216,10 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case TCN_MOUSELEAVING:
{
NppParameters *pNppParam = NppParameters::getInstance();
bool doSnapshot = pNppParam->getNppGUI()._isDocSnapshotOnTab;
bool doSnapshotOnMap = pNppParam->getNppGUI()._isDocSnapshotOnMap;
if (doSnapshot)
{
_documentSnapshot.display(false);

View File

@ -4805,6 +4805,14 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
if (optNameFolderDroppedOpenFiles)
_nppGUI._isFolderDroppedOpenFiles = (lstrcmp(optNameFolderDroppedOpenFiles, TEXT("yes")) == 0);
const TCHAR * optdocSnapshotOnTab = element->Attribute(TEXT("docSnapshotOnTab"));
if (optdocSnapshotOnTab)
_nppGUI._isDocSnapshotOnTab = (lstrcmp(optdocSnapshotOnTab, TEXT("yes")) == 0);
const TCHAR * optdocSnapshotOnMap = element->Attribute(TEXT("docSnapshotOnMap"));
if (optdocSnapshotOnTab)
_nppGUI._isDocSnapshotOnMap = (lstrcmp(optdocSnapshotOnMap, TEXT("yes")) == 0);
}
}
}
@ -5526,6 +5534,8 @@ void NppParameters::createXmlTreeFromGUIParams()
GUIConfigElement->SetAttribute(TEXT("backSlashIsEscapeCharacterForSql"), _nppGUI._backSlashIsEscapeCharacterForSql ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("newStyleSaveDlg"), _nppGUI._useNewStyleSaveDlg ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("isFolderDroppedOpenFiles"), _nppGUI._isFolderDroppedOpenFiles ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("docSnapshotOnTab"), _nppGUI._isDocSnapshotOnTab ? TEXT("yes") : TEXT("no"));
GUIConfigElement->SetAttribute(TEXT("docSnapshotOnMap"), _nppGUI._isDocSnapshotOnMap ? TEXT("yes") : TEXT("no"));
}
// <GUIConfig name="searchEngine" searchEngineChoice="2" searchEngineCustom="" />

View File

@ -846,6 +846,9 @@ struct NppGUI final
generic_string _searchEngineCustom;
bool _isFolderDroppedOpenFiles = false;
bool _isDocSnapshotOnTab = true;
bool _isDocSnapshotOnMap = false;
};
struct ScintillaViewParams

View File

@ -36,15 +36,15 @@ INT_PTR CALLBACK DocumentSnapshot::run_dlgProc(UINT message, WPARAM /*wParam*/,
case WM_INITDIALOG :
{
HWND hwndScintilla = reinterpret_cast<HWND>(::SendMessage(_hParent, NPPM_CREATESCINTILLAHANDLE, 0, reinterpret_cast<LPARAM>(_hSelf)));
_pScintillaEditView = reinterpret_cast<ScintillaEditView *>(::SendMessage(_hParent, NPPM_INTERNAL_GETSCINTEDTVIEW, 0, reinterpret_cast<LPARAM>(hwndScintilla)));
_pScintillaEditView->execute(SCI_SETZOOM, static_cast<WPARAM>(-10), 0);
_pScintillaEditView->execute(SCI_SETVSCROLLBAR, FALSE, 0);
_pScintillaEditView->execute(SCI_SETHSCROLLBAR, FALSE, 0);
_pSnapshotView = reinterpret_cast<ScintillaEditView *>(::SendMessage(_hParent, NPPM_INTERNAL_GETSCINTEDTVIEW, 0, reinterpret_cast<LPARAM>(hwndScintilla)));
_pSnapshotView->execute(SCI_SETZOOM, static_cast<WPARAM>(-10), 0);
_pSnapshotView->execute(SCI_SETVSCROLLBAR, FALSE, 0);
_pSnapshotView->execute(SCI_SETHSCROLLBAR, FALSE, 0);
_pScintillaEditView->showIndentGuideLine(false);
_pSnapshotView->showIndentGuideLine(false);
::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE);
_pScintillaEditView->display();
::MoveWindow(_pSnapshotView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE);
_pSnapshotView->display();
}
break;
}
@ -70,16 +70,16 @@ void DocumentSnapshot::goTo(POINT p)
void DocumentSnapshot::syncDisplay(Buffer *buf, ScintillaEditView & scintSource)
{
if (_pScintillaEditView)
if (_pSnapshotView)
{
_pScintillaEditView->execute(SCI_SETDOCPOINTER, 0, static_cast<LPARAM>(buf->getDocument()));
_pScintillaEditView->setCurrentBuffer(buf);
_pSnapshotView->execute(SCI_SETDOCPOINTER, 0, static_cast<LPARAM>(buf->getDocument()));
_pSnapshotView->setCurrentBuffer(buf);
//
// folding
//
const std::vector<size_t> & lineStateVector = buf->getHeaderLineState(&scintSource);
_pScintillaEditView->syncFoldStateWith(lineStateVector);
_pSnapshotView->syncFoldStateWith(lineStateVector);
//
// Wraping & scrolling
@ -88,23 +88,25 @@ void DocumentSnapshot::syncDisplay(Buffer *buf, ScintillaEditView & scintSource)
if (mp.isValid())
scrollSnapshotWith(mp);
Buffer *buf = _pScintillaEditView->getCurrentBuffer();
_pScintillaEditView->defineDocType(buf->getLangType());
_pScintillaEditView->showMargin(ScintillaEditView::_SC_MARGE_FOLDER, false);
Buffer *buf = _pSnapshotView->getCurrentBuffer();
_pSnapshotView->defineDocType(buf->getLangType());
_pSnapshotView->showMargin(ScintillaEditView::_SC_MARGE_FOLDER, false);
_pScintillaEditView->showMargin(0, false);
_pScintillaEditView->showMargin(1, false);
_pScintillaEditView->showMargin(2, false);
_pScintillaEditView->showMargin(3, false);
_pSnapshotView->showMargin(0, false);
_pSnapshotView->showMargin(1, false);
_pSnapshotView->showMargin(2, false);
_pSnapshotView->showMargin(3, false);
_pSnapshotView->execute(SCI_SETREADONLY, true);
_pSnapshotView->execute(SCI_SETCARETSTYLE, CARETSTYLE_INVISIBLE);
Window::display();
}
Window::display();
}
void DocumentSnapshot::scrollSnapshotWith(const MapPosition & mapPos)
{
if (_pScintillaEditView)
if (_pSnapshotView)
{
bool hasBeenChanged = false;
//
@ -121,34 +123,31 @@ void DocumentSnapshot::scrollSnapshotWith(const MapPosition & mapPos)
hasBeenChanged = true;
}
if (hasBeenChanged)
::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE);
::MoveWindow(_pSnapshotView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE);
//
// Wrapping
//
_pScintillaEditView->wrap(mapPos._isWrap);
_pScintillaEditView->execute(SCI_SETWRAPINDENTMODE, mapPos._wrapIndentMode);
_pSnapshotView->wrap(mapPos._isWrap);
_pSnapshotView->execute(SCI_SETWRAPINDENTMODE, mapPos._wrapIndentMode);
//
// Reset to zero
//
_pScintillaEditView->execute(SCI_HOMEDISPLAY);
_pSnapshotView->execute(SCI_HOMEDISPLAY);
//
// Visible line for the code view
//
// Get the first visible display line from the first visible document line
//auto firstVisibleDisplayLine = _pScintillaEditView->execute(SCI_VISIBLEFROMDOCLINE, mapPos._firstVisibleDocLine);
// scroll to the first visible display line
_pScintillaEditView->execute(SCI_LINESCROLL, 0,mapPos._firstVisibleDisplayLine);
_pSnapshotView->execute(SCI_LINESCROLL, 0,mapPos._firstVisibleDisplayLine);
}
}
void DocumentSnapshot::saveCurrentSnapshot(ScintillaEditView & editView)
{
if (_pScintillaEditView)
if (_pSnapshotView)
{
Buffer *buffer = editView.getCurrentBuffer();
MapPosition mapPos = buffer->getMapPosition();
@ -159,7 +158,7 @@ void DocumentSnapshot::saveCurrentSnapshot(ScintillaEditView & editView)
mapPos._nbLine = static_cast<int32_t>(editView.execute(SCI_LINESONSCREEN, mapPos._firstVisibleDisplayLine));
mapPos._lastVisibleDocLine = static_cast<int32_t>(editView.execute(SCI_DOCLINEFROMVISIBLE, mapPos._firstVisibleDisplayLine + mapPos._nbLine));
auto lineHeight = _pScintillaEditView->execute(SCI_TEXTHEIGHT, mapPos._firstVisibleDocLine);
auto lineHeight = _pSnapshotView->execute(SCI_TEXTHEIGHT, mapPos._firstVisibleDocLine);
mapPos._height = static_cast<int32_t>(mapPos._nbLine * lineHeight);
// Width

View File

@ -61,5 +61,5 @@ protected:
void goTo(POINT p);
private:
ScintillaEditView *_pScintillaEditView = nullptr;
ScintillaEditView *_pSnapshotView = nullptr;
};

View File

@ -119,7 +119,9 @@ STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
CONTROL "Enable",IDC_CHECK_ENABLEDOCSWITCHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,15,140,10
CONTROL "Snapshot on tab",IDC_CHECK_ENABLEDOCSNAPSHOT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,58,140,10
CONTROL "Enable MRU behaviour",IDC_CHECK_STYLEMRU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,28,140,10
CONTROL "Snapshot on map",IDC_CHECK_ENABLEDOCSNAPSHOTONMAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,45,71,140,10
CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE,
"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,83,150,10
CONTROL "Autodetect character encoding",IDC_CHECK_DETECTENCODING,
@ -141,6 +143,7 @@ BEGIN
EDITTEXT IDC_EDIT_WORKSPACEFILEEXT,381,152,34,14,ES_AUTOHSCROLL
GROUPBOX "Document Switcher (Ctrl+TAB)",IDC_DOCUMENTSWITCHER_STATIC,37,4,155,39,BS_CENTER
GROUPBOX "Clickable Link Settings",IDC_CLICKABLELINK_STATIC,259,4,155,39,BS_CENTER
GROUPBOX "Document Snapshot",IDC_DOCUMENTSNAPSHOT_STATIC,37,47,155,39,BS_CENTER
GROUPBOX "File Status Auto-Detection",IDC_FILEAUTODETECTION_STATIC,259,47,155,50,BS_CENTER
RTEXT "Session file ext.:",IDC_SESSIONFILEEXT_STATIC,271,138,108,8
RTEXT "Workspace file ext.:",IDC_WORKSPACEFILEEXT_STATIC,271,155,108,8

View File

@ -897,6 +897,8 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
::SendDlgItemMessage(_hSelf, IDC_CHECK_DETECTENCODING, BM_SETCHECK, nppGUI._detectEncoding, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_AUTOUPDATE, BM_SETCHECK, nppGUI._autoUpdateOpt._doAutoUpdate, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL, BM_SETCHECK, nppGUI._backSlashIsEscapeCharacterForSql, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCSNAPSHOT, BM_SETCHECK, nppGUI._isDocSnapshotOnTab ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCSNAPSHOTONMAP, BM_SETCHECK, nppGUI._isDocSnapshotOnMap ? BST_CHECKED : BST_UNCHECKED, 0);
::ShowWindow(::GetDlgItem(_hSelf, IDC_CHECK_AUTOUPDATE), nppGUI._doesExistUpdater?SW_SHOW:SW_HIDE);
@ -1078,6 +1080,18 @@ INT_PTR CALLBACK SettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
nppGUI._backSlashIsEscapeCharacterForSql = isCheckedOrNot(IDC_CHECK_BACKSLASHISESCAPECHARACTERFORSQL);
return TRUE;
}
case IDC_CHECK_ENABLEDOCSNAPSHOT:
{
nppGUI._isDocSnapshotOnTab = isCheckedOrNot(IDC_CHECK_ENABLEDOCSNAPSHOT);
return TRUE;
}
case IDC_CHECK_ENABLEDOCSNAPSHOTONMAP:
{
nppGUI._isDocSnapshotOnMap = isCheckedOrNot(IDC_CHECK_ENABLEDOCSNAPSHOTONMAP);
return TRUE;
}
}
}
}

View File

@ -201,6 +201,10 @@
#define IDC_REMEMBEREDITVIEWPERFILE_STATIC (IDD_PREFERENCE_SETTING_BOX + 42)
#define IDC_EDIT_REMEMBEREDITVIEWPERFILE (IDD_PREFERENCE_SETTING_BOX + 43)
#define IDC_DOCUMENTSNAPSHOT_STATIC (IDD_PREFERENCE_SETTING_BOX + 44)
#define IDC_CHECK_ENABLEDOCSNAPSHOT (IDD_PREFERENCE_SETTING_BOX + 45)
#define IDC_CHECK_ENABLEDOCSNAPSHOTONMAP (IDD_PREFERENCE_SETTING_BOX + 46)
#define IDD_PREFERENCE_NEWDOCSETTING_BOX 6400 //(IDD_PREFERENCE_BOX + 400)
#define IDC_FORMAT_GB_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 1)