Add new feature "Distraction Free Mode"

This commit is contained in:
Don HO 2021-04-09 19:55:55 +02:00
parent 92038c1653
commit cbf3d2c9cb
13 changed files with 124 additions and 22 deletions

View File

@ -246,6 +246,7 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="43054" name="Mar&amp;k..."/>
<Item id="44009" name="Post-It"/>
<Item id="44010" name="Fold All"/>
<Item id="44011" name="Distraction Free Mode"/>
<Item id="44019" name="Show All Characters"/>
<Item id="44020" name="Show Indent Guide"/>
<Item id="44022" name="Word wrap"/>

View File

@ -233,6 +233,7 @@
<Item id="43054" name="Marquer..."/>
<Item id="44009" name="Post-it"/>
<Item id="44010" name="Replier tous les blocs"/>
<Item id="44011" name="Mode sans distraction"/>
<Item id="44019" name="Afficher tous les caractères"/>
<Item id="44020" name="Afficher le guide d'indentation"/>
<Item id="44022" name="Retour automatique à la ligne"/>

View File

@ -228,6 +228,7 @@
<Item id="43050" name="反向標記書籤"/>
<Item id="44009" name="便條模式"/>
<Item id="44010" name="折疊所有階層"/>
<Item id="44011" name="免干擾模式"/>
<Item id="44011" name="自訂語法對話方塊"/>
<Item id="44019" name="顯示所有字元"/>
<Item id="44020" name="顯示縮排輔助線"/>

View File

@ -5338,10 +5338,9 @@ void Notepad_plus::fullScreenToggle()
void Notepad_plus::postItToggle()
{
NppParameters& nppParam = NppParameters::getInstance();
if (!_beforeSpecialView._isPostIt) // PostIt disabled, enable it
{
NppGUI & nppGUI = const_cast<NppGUI &>(nppParam.getNppGUI());
NppGUI & nppGUI = const_cast<NppGUI &>(NppParameters::getInstance().getNppGUI());
// get current status before switch to postIt
//check these always
{
@ -5448,6 +5447,51 @@ void Notepad_plus::postItToggle()
::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
}
// Distraction Free mode uses full screen mode + post-it mode + setting padding on the both left & right sides.
// In order to keep the coherence of data, when full screen mode or (and) post-it mode is (are) active,
// Distraction Free mode should be innaccible, and vice versa.
void Notepad_plus::distractionFreeToggle()
{
// Toggle Distraction Free Mode
fullScreenToggle();
postItToggle();
// Get padding info
const ScintillaViewParams& svp = NppParameters::getInstance().getSVP();
int paddingLeft = 0;
int paddingRight = 0;
// Enable or disable Distraction Free Mode
if (_beforeSpecialView._isDistractionFree)
{
// disable it
paddingLeft = svp._paddingLeft;
paddingRight = svp._paddingRight;
_restoreButton.setButtonStatus(0);
_restoreButton.display(false);
}
else
{
// enable it
const int defaultDiviser = 4;
int diviser = svp._distractionFreeDivPart > 2 ? svp._distractionFreeDivPart : defaultDiviser;
int w = _pEditView->getWidth();
int paddingLen = w / diviser;
if (paddingLen <= 0)
paddingLen = w / defaultDiviser;
paddingLeft = paddingRight = paddingLen;
_restoreButton.setButtonStatus(buttonStatus_distractionFree);
}
_beforeSpecialView._isDistractionFree = !_beforeSpecialView._isDistractionFree;
// set Distraction Free Mode paddin or restore the normal padding
_pEditView->execute(SCI_SETMARGINLEFT, 0, paddingLeft);
_pEditView->execute(SCI_SETMARGINRIGHT, 0, paddingRight);
}
void Notepad_plus::doSynScorll(HWND whichView)
{
int column = 0;

View File

@ -82,8 +82,9 @@ struct VisibleGUIConf final
{
bool _isPostIt = false;
bool _isFullScreen = false;
bool _isDistractionFree = false;
//Used by 2 modes
//Used by 3 modes
bool _isMenuShown = true;
DWORD_PTR _preStyle = (WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN);
@ -336,6 +337,7 @@ private:
VisibleGUIConf _beforeSpecialView;
void fullScreenToggle();
void postItToggle();
void distractionFreeToggle();
// Keystroke macro recording and playback
Macro _macro;

View File

@ -480,6 +480,7 @@ BEGIN
MENUITEM "Always on Top", IDM_VIEW_ALWAYSONTOP
MENUITEM "Toggle Full Screen Mode", IDM_VIEW_FULLSCREENTOGGLE
MENUITEM "Post-It", IDM_VIEW_POSTIT
MENUITEM "Distraction Free Mode", IDM_VIEW_DISTRACTIONFREE
MENUITEM SEPARATOR
POPUP "View Current File in"

View File

@ -1835,10 +1835,6 @@ void Notepad_plus::command(int id)
inverseMarks();
break;
case IDM_VIEW_FULLSCREENTOGGLE :
fullScreenToggle();
break;
case IDM_VIEW_ALWAYSONTOP:
{
int check = (::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED)?MF_UNCHECKED:MF_CHECKED;
@ -2015,9 +2011,25 @@ void Notepad_plus::command(int id)
break;
}
case IDM_VIEW_FULLSCREENTOGGLE:
{
if (!_beforeSpecialView._isDistractionFree)
fullScreenToggle();
}
break;
case IDM_VIEW_POSTIT :
{
postItToggle();
if (!_beforeSpecialView._isDistractionFree)
postItToggle();
}
break;
case IDM_VIEW_DISTRACTIONFREE:
{
if (((_beforeSpecialView._isDistractionFree && _beforeSpecialView._isFullScreen && _beforeSpecialView._isPostIt)) ||
((!_beforeSpecialView._isDistractionFree && !_beforeSpecialView._isFullScreen && !_beforeSpecialView._isPostIt)))
distractionFreeToggle();
}
break;

View File

@ -238,6 +238,7 @@ static const WinMenuKeyDefinition winKeyDefs[] =
{ VK_NULL, IDM_VIEW_ALWAYSONTOP, false, false, false, nullptr },
{ VK_F11, IDM_VIEW_FULLSCREENTOGGLE, false, false, false, nullptr },
{ VK_F12, IDM_VIEW_POSTIT, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_DISTRACTIONFREE, false, false, false, nullptr },
{ VK_NULL, IDM_VIEW_IN_FIREFOX, false, false, false, TEXT("View current file in Firefox") },
{ VK_NULL, IDM_VIEW_IN_CHROME, false, false, false, TEXT("View current file in Chrome") },
@ -5528,6 +5529,27 @@ void NppParameters::feedScintillaParam(TiXmlNode *node)
else if (!lstrcmp(nm, TEXT("no")))
_svp._doSmoothFont = false;
}
nm = element->Attribute(TEXT("paddingLeft"), &val);
if (nm)
{
if (val >= 0 && val <= 9)
_svp._paddingLeft = static_cast<unsigned char>(val);
}
nm = element->Attribute(TEXT("paddingRight"), &val);
if (nm)
{
if (val >= 0 && val <= 9)
_svp._paddingRight = static_cast<unsigned char>(val);
}
nm = element->Attribute(TEXT("distractionFreeDivPart"), &val);
if (nm)
{
if (val >= 3 && val <= 255)
_svp._borderWidth = static_cast<unsigned char>(val);
}
}
@ -5781,6 +5803,9 @@ bool NppParameters::writeScintillaParams()
(scintNode->ToElement())->SetAttribute(TEXT("eolShow"), _svp._eolShow?TEXT("show"):TEXT("hide"));
(scintNode->ToElement())->SetAttribute(TEXT("borderWidth"), _svp._borderWidth);
(scintNode->ToElement())->SetAttribute(TEXT("smoothFont"), _svp._doSmoothFont ? TEXT("yes") : TEXT("no"));
(scintNode->ToElement())->SetAttribute(TEXT("paddingLeft"), _svp._paddingLeft);
(scintNode->ToElement())->SetAttribute(TEXT("paddingRight"), _svp._paddingRight);
(scintNode->ToElement())->SetAttribute(TEXT("distractionFreeDivPart"), _svp._distractionFreeDivPart);
return true;
}

View File

@ -935,6 +935,13 @@ struct ScintillaViewParams
bool _disableAdvancedScrolling = false;
bool _doSmoothFont = false;
bool _showBorderEdge = true;
unsigned char _paddingLeft = 0; // 0-9 pixel
unsigned char _paddingRight = 0; // 0-9 pixel
// distractionFreeDivPart is used for divising the fullscreen pixel width.
// the result of division will be the left & right padding in Distraction Free mode
unsigned char _distractionFreeDivPart = 4; // 3-255 parts
};
const int NB_LIST = 20;

View File

@ -132,10 +132,16 @@ INT_PTR CALLBACK ButtonDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
case IDC_RESTORE_BUTTON :
{
int bs = getButtonStatus();
bool isDistractionFree = (bs & buttonStatus_distractionFree) != 0;
bool isFullScreen = (bs & buttonStatus_fullscreen) != 0;
bool isPostIt = (bs & buttonStatus_postit) != 0;
int cmd = 0;
if (isFullScreen && isPostIt)
if (isDistractionFree)
{
cmd = IDM_VIEW_DISTRACTIONFREE;
}
else if (isFullScreen && isPostIt)
{
// remove postit firstly
cmd = IDM_VIEW_POSTIT;

View File

@ -44,12 +44,14 @@ private :
POINT _p = {0, 0};
};
// 0 : sans fullscreen
// 0 : normal window
// 1 : fullscreen
// 2 : postit
const int buttonStatus_nada = 0;
const int buttonStatus_fullscreen = 1;
const int buttonStatus_postit = 2;
// 4 : distractionFree
const int buttonStatus_nada = 0; // 0000 0000
const int buttonStatus_fullscreen = 1; // 0000 0001
const int buttonStatus_postit = 2; // 0000 0010
const int buttonStatus_distractionFree = 4; // 0000 0100
class ButtonDlg : public StaticDialog
{

View File

@ -63,14 +63,14 @@ MenuPosition menuPos[] = {
{ 2, 23, -1, "search-copyStyledText" },
{ 2, 25, -1, "search-bookmark" },
{ 3, 4, -1, "view-currentFileIn" },
{ 3, 6, -1, "view-showSymbol" },
{ 3, 7, -1, "view-zoom" },
{ 3, 8, -1, "view-moveCloneDocument" },
{ 3, 9, -1, "view-tab" },
{ 3, 18, -1, "view-collapseLevel" },
{ 3, 19, -1, "view-uncollapseLevel" },
{ 3, 23, -1, "view-project" },
{ 3, 5, -1, "view-currentFileIn" },
{ 3, 7, -1, "view-showSymbol" },
{ 3, 8, -1, "view-zoom" },
{ 3, 9, -1, "view-moveCloneDocument" },
{ 3, 10, -1, "view-tab" },
{ 3, 19, -1, "view-collapseLevel" },
{ 3, 20, -1, "view-uncollapseLevel" },
{ 3, 24, -1, "view-project" },
{ 4, 5, -1, "encoding-characterSets" },
{ 4, 5, 0, "encoding-arabic" },

View File

@ -258,7 +258,7 @@
#define IDM_VIEW_DRAWTABBAR_INACIVETAB (IDM_VIEW + 8)
#define IDM_VIEW_POSTIT (IDM_VIEW + 9)
#define IDM_VIEW_TOGGLE_FOLDALL (IDM_VIEW + 10)
//#define IDM_VIEW_USER_DLG (IDM_VIEW + 11)
#define IDM_VIEW_DISTRACTIONFREE (IDM_VIEW + 11)
#define IDM_VIEW_LINENUMBER (IDM_VIEW + 12)
#define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13)
#define IDM_VIEW_FOLDERMAGIN (IDM_VIEW + 14)