Skip to content

Commit

Permalink
Fix Setting Dialog Too Big Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vinadevs committed Apr 26, 2023
1 parent 077ac77 commit e12fe17
Show file tree
Hide file tree
Showing 26 changed files with 263 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ https://nodejs.org/en/
- After editing this file, please reload (F4) your code file to active settings.

@@ compiler path:
..\Compilers\compiler.exe
..\Compilers\node.exe

@@ debugger path:
..\Compilers\compiler.exe
..\Compilers\node.exe

@@ auto complete:
abstract arguments await boolean break byte case catch char class const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ https://www.python.org/downloads/
- After editing this file, please reload (F4) your code file to active settings.

@@ compiler path:
..\Compilers\Python39_64\python.exe
..\Compilers\python.exe

@@ debugger path:
..\Compilers\Python39_64\python.exe
..\Compilers\python.exe

@@ auto complete:
and as assert async await break class continue def del elif else except finally for
Expand Down
5 changes: 1 addition & 4 deletions src/BracketOutLineDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "PathUtil.h"
#include "EditorDoc.h"
#include "Editor.h"
#include "ScrollHelper.h"
#include "AppSettings.h"

#ifdef _DEBUG
Expand All @@ -38,9 +37,7 @@ CBracketOutLineDlg::CBracketOutLineDlg(CWnd* pParent /*=NULL*/)
m_Font.CreateFontIndirect(&lf);
}

CBracketOutLineDlg::~CBracketOutLineDlg()
{
}
CBracketOutLineDlg::~CBracketOutLineDlg() {}

void CBracketOutLineDlg::UpdateFoldingMap(int nFoldingLevel)
{
Expand Down
2 changes: 0 additions & 2 deletions src/BracketOutLineDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
/////////////////////////////////////////////////////////////////////////////
// CBracketOutLineDlg

class CScrollHelper;

class CBracketOutLineDlg : public CDialogEx
{
DECLARE_DYNAMIC(CBracketOutLineDlg)
Expand Down
69 changes: 30 additions & 39 deletions src/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ void CEditorCtrl::InitilizeSetting(CLanguageDatabase* pDatabase)

SetTabSettings(m_tabSpace);

SetLineNumberWidth();
SetDisplayLinenumbers(TRUE);

SetColorForStyle(STYLE_LINENUMBER,
m_AppThemeColorSet._lineNumberColor,
m_AppThemeColorSet._editorMarginBarColor,
Expand Down Expand Up @@ -1191,41 +1192,30 @@ void CEditorCtrl::GotoPointXY(int lX, int lY)
GotoPosition(lPos);
}

void CEditorCtrl::SetLineNumberWidth()
int CEditorCtrl::GetLineNumberWidth(int nLineOnScreen)
{
SetDisplayLinenumbers(TRUE);
}

int CEditorCtrl::GetLineNumberWidth()
{
// get number of chars needed to display highest linenumber
int nChars = GetLinenumberChars();
// get width of character '9' in pixels
char czNine1[2] = "9";
LRESULT lWidth1 = DoCommand(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>(czNine1));
char czNine2[3] = "99";
LRESULT lWidth2 = DoCommand(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>(czNine2));

LRESULT lWidthTarget = 0;
if (GetLineCount() < 10)
{
lWidthTarget = lWidth2;
}
else if (GetLineCount() > 9 && GetLineCount() < 100)
{
nChars -= 1;
lWidthTarget = lWidth2;
}
else if (GetLineCount() > 99 && GetLineCount() < 1000)
{
nChars -= 2;
lWidthTarget = lWidth2;
}
LRESULT lrFirstVisibleLineVis = DoCommand(SCI_GETFIRSTVISIBLELINE);
LRESULT lrLastVisibleLineVis = nLineOnScreen + lrFirstVisibleLineVis + 1;
LRESULT lrLastVisibleLineDoc = DoCommand(SCI_DOCLINEFROMVISIBLE, lrLastVisibleLineVis);
int lineNumberDigits = 0;
if (lrLastVisibleLineDoc < 10) lrLastVisibleLineDoc = 1;
else if (lrLastVisibleLineDoc < 100) lineNumberDigits = 2;
else if (lrLastVisibleLineDoc < 1000) lineNumberDigits = 3;
else if (lrLastVisibleLineDoc < 10000) lineNumberDigits = 4;
else if (lrLastVisibleLineDoc < 100000) lineNumberDigits = 5;
else if (lrLastVisibleLineDoc < 1000000) lineNumberDigits = 6;
else
{
lWidthTarget = lWidth1;
lineNumberDigits = 7;
lrLastVisibleLineDoc /= 1000000;
while (lrLastVisibleLineDoc)
{
lrLastVisibleLineDoc /= 10;
++lineNumberDigits;
}
}
return nChars * (int)(lWidthTarget);
lineNumberDigits = lineNumberDigits < 3 ? 3 : lineNumberDigits;
return 8 + lineNumberDigits * static_cast<int>(DoCommand(SCI_TEXTWIDTH, STYLE_LINENUMBER, reinterpret_cast<LPARAM>("8")));
}

int CEditorCtrl::GetLinenumberChars()
Expand Down Expand Up @@ -1991,16 +1981,17 @@ BOOL CEditorCtrl::SearchBackward(const CString& strText)
void CEditorCtrl::SetDisplayLinenumbers(BOOL bFlag)
{
m_bLinenumbers = bFlag;
// if display is turned off we set margin 0 to 0
if (!bFlag)
if (!bFlag) // if display is turned off we set margin 0 to 0
{
DoCommand(SCI_SETMARGINWIDTHN, 0, 0);
}
// if display is turned on we set margin 0 to the calculated width
else
else // if display is turned on we set margin 0 to the calculated width
{
int nWidth = GetLineNumberWidth();
DoCommand(SCI_SETMARGINWIDTHN, 0, nWidth);
int nLineOnScreen = static_cast<int>(DoCommand(SCI_LINESONSCREEN));
if (nLineOnScreen)
{
DoCommand(SCI_SETMARGINWIDTHN, 0, GetLineNumberWidth(nLineOnScreen));
}
}
}

Expand Down Expand Up @@ -4680,7 +4671,7 @@ void CEditorCtrl::ShowHideFoldingMargin(int nPosMouseX)
else
{
int nMask = static_cast<int>(DoCommand(SCI_GETMARGINMASKN, SC_SETMARGINTYPE_FOLDING));
nMask = nPosMouseX <= 0 || nPosMouseX > VINATEXT_MARGINWIDTH * 2 + GetLineNumberWidth() ? (nMask & ~SC_MASK_FOLDERS) : (nMask | SC_MASK_FOLDERS);
nMask = nPosMouseX <= 0 || nPosMouseX > VINATEXT_MARGINWIDTH * 2 + GetLineNumberWidth(static_cast<int>(DoCommand(SCI_LINESONSCREEN)) ? (nMask & ~SC_MASK_FOLDERS) : (nMask | SC_MASK_FOLDERS));
DoCommand(SCI_SETMARGINMASKN, SC_SETMARGINTYPE_FOLDING, nMask);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ class CEditorCtrl : public CWin32Base
BOOL IsTextSelected();
void GotoPosition(int lPos);
void GotoPointXY(int lX, int lY);
void SetLineNumberWidth();
int GetLineNumberWidth();
int GetLineNumberWidth(int nLineOnScreen);
int GetLinenumberChars();
void IndentAll();
BOOL IsBraceCharacter(int nCharValue);
Expand Down
39 changes: 38 additions & 1 deletion src/EditorSettingDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
#include "afxdialogex.h"
#include "EditorSettingDlg.h"
#include "AppSettings.h"
#include "ScrollHelper.h"

// EditorSettingDlg dialog

IMPLEMENT_DYNAMIC(EditorSettingDlg, CDialogEx)

EditorSettingDlg::EditorSettingDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG_SETTING_EDITOR, pParent) {}
: CDialogEx(IDD_DIALOG_SETTING_EDITOR, pParent) {
m_pScrollHelper = std::make_unique<CScrollHelper>();
m_pScrollHelper->AttachWnd(this);
m_pScrollHelper->SetDisplaySize(0, 800);
}

EditorSettingDlg::~EditorSettingDlg() {}

void EditorSettingDlg::UpdateGUISettings(BOOL bFromGUI)
{
Expand Down Expand Up @@ -841,8 +848,38 @@ void EditorSettingDlg::FromRenderIndicatorActionCombobox()

BEGIN_MESSAGE_MAP(EditorSettingDlg, CDialogEx)
ON_BN_CLICKED(ID_EDITOR_FONT_NAME_BUTTON, &EditorSettingDlg::OnBnClickedEditorFontNameButton)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_MOUSEWHEEL()
ON_WM_SIZE()
END_MESSAGE_MAP()

// for scrolling //////////////////////////////////////////////////////////////

void EditorSettingDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
m_pScrollHelper->OnHScroll(nSBCode, nPos, pScrollBar);
}

void EditorSettingDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
m_pScrollHelper->OnVScroll(nSBCode, nPos, pScrollBar);
}

BOOL EditorSettingDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
BOOL wasScrolled = m_pScrollHelper->OnMouseWheel(nFlags, zDelta, pt);

return wasScrolled;
}

void EditorSettingDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);

m_pScrollHelper->OnSize(nType, cx, cy);
}

void EditorSettingDlg::OnBnClickedEditorFontNameButton()
{
CFontDialog dlg;
Expand Down
11 changes: 9 additions & 2 deletions src/EditorSettingDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#pragma once
#include "afxdialogex.h"

class CScrollHelper;

// EditorSettingDlg dialog

class EditorSettingDlg : public CDialogEx
Expand All @@ -17,7 +19,7 @@ class EditorSettingDlg : public CDialogEx

public:
EditorSettingDlg(CWnd* pParent = nullptr); // standard constructor
virtual ~EditorSettingDlg() {};
virtual ~EditorSettingDlg();

enum { IDD = IDD_DIALOG_SETTING_EDITOR };

Expand All @@ -31,8 +33,11 @@ class EditorSettingDlg : public CDialogEx
virtual BOOL PreTranslateMessage(MSG* pMsg);

DECLARE_MESSAGE_MAP()

afx_msg void OnBnClickedEditorFontNameButton();
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnSize(UINT nType, int cx, int cy);

void InitLanguageSpellCheckCombo();
void InitLanguageTranslateFromCombo();
Expand Down Expand Up @@ -87,4 +92,6 @@ class EditorSettingDlg : public CDialogEx
int m_nEditorLineNumberFontSize{ 0 };
int m_nEditorTextFontSize{ 0 };
int m_nPageAlignmentWidth{ 0 };

std::unique_ptr<CScrollHelper> m_pScrollHelper{ nullptr };
};
8 changes: 3 additions & 5 deletions src/EditorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6075,6 +6075,8 @@ BOOL CEditorView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
{
case SCN_PAINTED:
{
// update dynamic line number width
m_EditorCtrl.SetDisplayLinenumbers(TRUE);
// return previous state
if (!m_bAlreadyRestoreState)
{
Expand Down Expand Up @@ -6315,10 +6317,6 @@ BOOL CEditorView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
}
AppUtils::UpdateModifiedDocumentTitle(m_pDocument);
}
if (pScinNotification->linesAdded)
{
m_EditorCtrl.SetLineNumberWidth();
}
if (m_bEnableSpellChecker && (iModType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) != 0)
{
KillTimer(START_SPELL_CHECKER_TIMER);
Expand Down Expand Up @@ -6386,7 +6384,7 @@ BOOL CEditorView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
break;
case SCN_ZOOM:
{
m_EditorCtrl.SetLineNumberWidth();
m_EditorCtrl.SetDisplayLinenumbers(TRUE);
}
break;
}
Expand Down
39 changes: 38 additions & 1 deletion src/ExplorerSettingDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
#include "ExplorerSettingDlg.h"
#include "AppSettings.h"
#include "PathUtil.h"
#include "ScrollHelper.h"

// ExplorerSettingDlg dialog

IMPLEMENT_DYNAMIC(ExplorerSettingDlg, CDialogEx)

ExplorerSettingDlg::ExplorerSettingDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG_SETTING_EXPLORER, pParent) {}
: CDialogEx(IDD_DIALOG_SETTING_EXPLORER, pParent) {
m_pScrollHelper = std::make_unique<CScrollHelper>();
m_pScrollHelper->AttachWnd(this);
m_pScrollHelper->SetDisplaySize(0, 800);
}

ExplorerSettingDlg::~ExplorerSettingDlg() {}

void ExplorerSettingDlg::UpdateGUISettings(BOOL bFromGUI)
{
Expand Down Expand Up @@ -126,8 +133,38 @@ void ExplorerSettingDlg::OnDropFiles(HDROP hDropInfo)

BEGIN_MESSAGE_MAP(ExplorerSettingDlg, CDialogEx)
ON_WM_DROPFILES()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_MOUSEWHEEL()
ON_WM_SIZE()
END_MESSAGE_MAP()

// for scrolling //////////////////////////////////////////////////////////////

void ExplorerSettingDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
m_pScrollHelper->OnHScroll(nSBCode, nPos, pScrollBar);
}

void ExplorerSettingDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
m_pScrollHelper->OnVScroll(nSBCode, nPos, pScrollBar);
}

BOOL ExplorerSettingDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
BOOL wasScrolled = m_pScrollHelper->OnMouseWheel(nFlags, zDelta, pt);

return wasScrolled;
}

void ExplorerSettingDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);

m_pScrollHelper->OnSize(nType, cx, cy);
}

///////////////////////////////////////////////////////////////////

BOOL ExplorerSettingBrowse::PreTranslateMessage(MSG* pMsg)
Expand Down
10 changes: 9 additions & 1 deletion src/ExplorerSettingDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#pragma once
#include "afxdialogex.h"

class CScrollHelper;

class ExplorerSettingBrowse : public CMFCEditBrowseCtrl
{
virtual BOOL PreTranslateMessage(MSG* pMsg);
Expand All @@ -22,7 +24,7 @@ class ExplorerSettingDlg : public CDialogEx

public:
ExplorerSettingDlg(CWnd* pParent = nullptr); // standard constructor
virtual ~ExplorerSettingDlg() {};
virtual ~ExplorerSettingDlg();

enum { IDD = IDD_DIALOG_SETTING_EXPLORER };

Expand All @@ -41,6 +43,10 @@ class ExplorerSettingDlg : public CDialogEx

DECLARE_MESSAGE_MAP()
afx_msg void OnDropFiles(HDROP hDropInfo);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnSize(UINT nType, int cx, int cy);

BOOL m_bEnablePathNavigation {FALSE};
BOOL m_bEnablePreviewFile{ FALSE };
Expand All @@ -53,6 +59,8 @@ class ExplorerSettingDlg : public CDialogEx
int m_nExplorerExpandLimitLevel{ 0 };
int m_nFilePreviewSizeLimit{ 0 };

std::unique_ptr<CScrollHelper> m_pScrollHelper{ nullptr };

CString m_strAntiVirusArgument;
CString m_strAntiVirusProgram;
ExplorerSettingBrowse m_EditAntiVirusProgram;
Expand Down
Loading

0 comments on commit e12fe17

Please sign in to comment.