Skip to content

Commit 13c4184

Browse files
authored
Merge pull request sabrogden#942 from sabrogden/vacuum
Deleted clip data, don't auto call vacuum after deleting clip, moved …
2 parents 6516d2d + 4093bf6 commit 13c4184

3 files changed

Lines changed: 92 additions & 51 deletions

File tree

CP_Main.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ BEGIN
977977
GROUPBOX "Search Options",IDC_STATIC_GROUP_SEARCH,4,15,778,83
978978
LTEXT "Selected Count:",IDC_STATIC_SELECTED_SIZE_TEXT2,207,300,52,8
979979
LTEXT "Count",IDC_STATIC_SELECTED_COUNT,259,300,39,8
980+
PUSHBUTTON "Compact and Repair Database",IDC_BT_COMPACT_AND_REPAIR,305,295,126,13
980981
END
981982

982983
IDD_OPTIONS_QUICK_PASTE_KEYBOARD DIALOGEX 0, 0, 375, 278

src/DeleteClipData.cpp

Lines changed: 90 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ BEGIN_MESSAGE_MAP(CDeleteClipData, CDialog)
8989
ON_NOTIFY(HDN_ITEMCLICK, 0, &CDeleteClipData::OnLvnColumnclickList2)
9090

9191
ON_WM_CONTEXTMENU()
92+
ON_BN_CLICKED(IDC_BT_COMPACT_AND_REPAIR, &CDeleteClipData::OnBnClickedBtCompactAndRepair)
9293
END_MESSAGE_MAP()
9394

9495
BOOL CDeleteClipData::OnInitDialog()
@@ -109,6 +110,7 @@ BOOL CDeleteClipData::OnInitDialog()
109110
m_Resize.AddControl(IDC_STATIC_DB_SIZE_TEXT, DR_MoveTop);
110111
m_Resize.AddControl(IDC_BUTTON_SEARCH, DR_MoveLeft);
111112
m_Resize.AddControl(IDC_STATIC_GROUP_SEARCH, DR_SizeWidth);
113+
m_Resize.AddControl(IDC_BT_COMPACT_AND_REPAIR, DR_MoveTop | DR_MoveLeft);
112114

113115
InitListCtrlCols();
114116

@@ -135,12 +137,13 @@ void CDeleteClipData::InitListCtrlCols()
135137
{
136138
m_clipList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
137139

138-
m_clipList.InsertColumn(0, theApp.m_Language.GetDeleteClipDataString("Title", "Title"), LVCFMT_LEFT, 350);
139-
m_clipList.InsertColumn(1, theApp.m_Language.GetDeleteClipDataString("QuickPasteText", "Quick Paste Text"), LVCFMT_LEFT, 200);
140-
m_clipList.InsertColumn(2, theApp.m_Language.GetDeleteClipDataString("Created", "Created"), LVCFMT_LEFT, 150);
141-
m_clipList.InsertColumn(3, theApp.m_Language.GetDeleteClipDataString("LastUsed", "Last Used"), LVCFMT_LEFT, 150);
142-
m_clipList.InsertColumn(4, theApp.m_Language.GetDeleteClipDataString("Format", "Format"), LVCFMT_LEFT, 150);
143-
m_clipList.InsertColumn(5, theApp.m_Language.GetDeleteClipDataString("DataSize", "Data Size"), LVCFMT_LEFT, 100);
140+
m_clipList.InsertColumn(0, theApp.m_Language.GetDeleteClipDataString("ID", "ID"), LVCFMT_LEFT, 50);
141+
m_clipList.InsertColumn(1, theApp.m_Language.GetDeleteClipDataString("Title", "Title"), LVCFMT_LEFT, 350);
142+
m_clipList.InsertColumn(2, theApp.m_Language.GetDeleteClipDataString("QuickPasteText", "Quick Paste Text"), LVCFMT_LEFT, 200);
143+
m_clipList.InsertColumn(3, theApp.m_Language.GetDeleteClipDataString("Created", "Created"), LVCFMT_LEFT, 150);
144+
m_clipList.InsertColumn(4, theApp.m_Language.GetDeleteClipDataString("LastUsed", "Last Used"), LVCFMT_LEFT, 150);
145+
m_clipList.InsertColumn(5, theApp.m_Language.GetDeleteClipDataString("Format", "Format"), LVCFMT_LEFT, 150);
146+
m_clipList.InsertColumn(6, theApp.m_Language.GetDeleteClipDataString("DataSize", "Data Size"), LVCFMT_LEFT, 100);
144147
}
145148

146149
void CDeleteClipData::LoadItems()
@@ -514,38 +517,44 @@ void CDeleteClipData::OnLvnGetdispinfoList2(NMHDR *pNMHDR, LRESULT *pResult)
514517
switch (pDispInfo->item.iSubItem)
515518
{
516519
case 0:
520+
{
521+
lstrcpyn(pDispInfo->item.pszText, StrF(_T("%d"), m_data[pDispInfo->item.iItem].m_lID), pDispInfo->item.cchTextMax);
522+
pDispInfo->item.pszText[pDispInfo->item.cchTextMax - 1] = '\0';
523+
}
524+
break;
525+
case 1:
517526
{
518527
lstrcpyn(pDispInfo->item.pszText, m_data[pDispInfo->item.iItem].m_Desc, pDispInfo->item.cchTextMax);
519528
pDispInfo->item.pszText[pDispInfo->item.cchTextMax - 1] = '\0';
520529
}
521530
break;
522-
case 1:
531+
case 2:
523532
{
524533
lstrcpyn(pDispInfo->item.pszText, m_data[pDispInfo->item.iItem].m_quickPasteText, pDispInfo->item.cchTextMax);
525534
pDispInfo->item.pszText[pDispInfo->item.cchTextMax - 1] = '\0';
526535
}
527536
break;
528-
case 2:
537+
case 3:
529538
{
530539
COleDateTime dtTime(m_data[pDispInfo->item.iItem].m_createdDateTime.GetTime());
531540
lstrcpyn(pDispInfo->item.pszText, dtTime.Format(), pDispInfo->item.cchTextMax);
532541
pDispInfo->item.pszText[pDispInfo->item.cchTextMax - 1] = '\0';
533542
}
534543
break;
535-
case 3:
544+
case 4:
536545
{
537546
COleDateTime dtTime(m_data[pDispInfo->item.iItem].m_lastUsedDateTime.GetTime());
538547
lstrcpyn(pDispInfo->item.pszText, dtTime.Format(), pDispInfo->item.cchTextMax);
539548
pDispInfo->item.pszText[pDispInfo->item.cchTextMax - 1] = '\0';
540549
}
541550
break;
542-
case 4:
551+
case 5:
543552
{
544553
lstrcpyn(pDispInfo->item.pszText, m_data[pDispInfo->item.iItem].m_clipboardFormat, pDispInfo->item.cchTextMax);
545554
pDispInfo->item.pszText[pDispInfo->item.cchTextMax - 1] = '\0';
546555
}
547556
break;
548-
case 5:
557+
case 6:
549558
{
550559
const int MAX_FILE_SIZE_BUFFER = 255;
551560
TCHAR szFileSize[MAX_FILE_SIZE_BUFFER];
@@ -590,8 +599,6 @@ void CDeleteClipData::ApplyDelete()
590599

591600
try
592601
{
593-
theApp.m_db.execDML(_T("PRAGMA auto_vacuum = 2"));
594-
595602
POSITION pos = m_clipList.GetFirstSelectedItemPosition();
596603
std::vector<int> rowsToDelete;
597604

@@ -606,7 +613,7 @@ void CDeleteClipData::ApplyDelete()
606613

607614
CProgressWnd progress;
608615
progress.Create(this, _T("Deleting clip items"), TRUE);
609-
progress.SetRange(0, (int)rowsToDelete.size() + 4);
616+
progress.SetRange(0, (int)rowsToDelete.size() + 2);
610617
progress.SetText(_T("Deleting selected items"));
611618
progress.SetStep(1);
612619

@@ -643,47 +650,29 @@ void CDeleteClipData::ApplyDelete()
643650
}
644651
CATCH_SQLITE_EXCEPTION
645652
}
646-
647-
progress.StepIt();
648-
progress.SetText(_T("Shrinking database"));
649-
650-
try
651-
{
652-
for(int i = 0; i < 100; i++)
653-
{
654-
int toDeleteCount = theApp.m_db.execScalar(_T("SELECT COUNT(clipID) FROM MainDeletes"));
655-
if(toDeleteCount <= 0)
656-
break;
657-
658-
RemoveOldEntries(false);
659-
}
660-
}
661-
CATCH_SQLITE_EXCEPTION
662-
663-
theApp.m_db.execDML(_T("PRAGMA auto_vacuum = 1"));
664-
theApp.m_db.execQuery(_T("VACUUM"));
665653

666654
progress.StepIt();
667655
progress.SetText(_T("Refreshing database size"));
668-
669-
SetDbSize();
670-
671-
progress.StepIt();
672-
progress.SetText(_T("Reloading list"));
673-
674-
//LoadItems();
656+
SetDbSize();
675657

676658
progress.StepIt();
677-
progress.SetText(_T("Applying filter"));
678-
659+
progress.SetText(_T("Applying filter"));
679660
FilterItems();
680661

681662
m_clipList.SetItemCountEx((int)m_data.size(), 0);
663+
664+
POSITION selectedPos = m_clipList.GetFirstSelectedItemPosition();
665+
if (selectedPos != nullptr)
666+
{
667+
INT_PTR row = m_clipList.GetNextSelectedItem(selectedPos);
668+
SelectRow((int)row);
669+
}
682670
}
683671
CATCH_SQLITE_EXCEPTION
684672

685673
m_applyingDelete = false;
686674
m_clipList.EnableWindow();
675+
m_clipList.SetFocus();
687676
}
688677
}
689678

@@ -741,10 +730,25 @@ void CDeleteClipData::OnBnClickedCheckDataFormat()
741730
::SetFocus(::GetDlgItem(m_hWnd, IDC_COMBO_DATA_FORMAT));
742731
}
743732

733+
static bool SortByIDDesc(const CDeleteData& a1, const CDeleteData& a2)
734+
{
735+
return a1.m_lID > a2.m_lID;
736+
}
737+
static bool SortByIDAsc(const CDeleteData& a1, const CDeleteData& a2)
738+
{
739+
return a1.m_lID < a2.m_lID;
740+
}
741+
742+
744743
static bool SortByTitleDesc(const CDeleteData& a1, const CDeleteData& a2)
745744
{
746745
return a1.m_Desc > a2.m_Desc;
747746
}
747+
static bool SortByTitleAsc(const CDeleteData& a1, const CDeleteData& a2)
748+
{
749+
return a1.m_Desc < a2.m_Desc;
750+
}
751+
748752

749753
static bool SortByQuickPaste(const CDeleteData& a1, const CDeleteData& a2)
750754
{
@@ -771,10 +775,7 @@ static bool SortByDataSizeDesc(const CDeleteData& a1, const CDeleteData& a2)
771775
return a1.m_dataSize > a2.m_dataSize;
772776
}
773777

774-
static bool SortByTitleAsc(const CDeleteData& a1, const CDeleteData& a2)
775-
{
776-
return a1.m_Desc < a2.m_Desc;
777-
}
778+
778779

779780
static bool SortByCreatedDateAsc(const CDeleteData& a1, const CDeleteData& a2)
780781
{
@@ -804,36 +805,42 @@ void CDeleteClipData::OnLvnColumnclickList2(NMHDR *pNMHDR, LRESULT *pResult)
804805
switch (phdn->iItem)
805806
{
806807
case 0:
808+
if (desc)
809+
std::sort(m_data.begin(), m_data.end(), SortByIDDesc);
810+
else
811+
std::sort(m_data.begin(), m_data.end(), SortByIDAsc);
812+
break;
813+
case 1:
807814
if(desc)
808815
std::sort(m_data.begin(), m_data.end(), SortByTitleDesc);
809816
else
810817
std::sort(m_data.begin(), m_data.end(), SortByTitleAsc);
811818
break;
812-
case 1:
819+
case 2:
813820
if (desc)
814821
std::sort(m_data.begin(), m_data.end(), SortByQuickPaste);
815822
else
816823
std::sort(m_data.begin(), m_data.end(), SortByQuickPaste);
817824
break;
818-
case 2:
825+
case 3:
819826
if(desc)
820827
std::sort(m_data.begin(), m_data.end(), SortByCreatedDateDesc);
821828
else
822829
std::sort(m_data.begin(), m_data.end(), SortByCreatedDateAsc);
823830
break;
824-
case 3:
831+
case 4:
825832
if(desc)
826833
std::sort(m_data.begin(), m_data.end(), SortByLastUsedDateDesc);
827834
else
828835
std::sort(m_data.begin(), m_data.end(), SortByLastUsedDateAsc);
829836
break;
830-
case 4:
837+
case 5:
831838
if(desc)
832839
std::sort(m_data.begin(), m_data.end(), SortByFormatDesc);
833840
else
834841
std::sort(m_data.begin(), m_data.end(), SortByFormatAsc);
835842
break;
836-
case 5:
843+
case 6:
837844
if(desc)
838845
std::sort(m_data.begin(), m_data.end(), SortByDataSizeDesc);
839846
else
@@ -1205,3 +1212,35 @@ void CDeleteClipData::OnCancel()
12051212
{
12061213
//don't close on escape key
12071214
}
1215+
1216+
void CDeleteClipData::OnBnClickedBtCompactAndRepair()
1217+
{
1218+
auto msg = theApp.m_Language.GetString("CompactRepairWarning", "Warning this can take quite a long time and require up to double the hard drive space as your current database size, Continue?");
1219+
int ret = MessageBox(msg, _T("Ditto"), MB_OKCANCEL);
1220+
1221+
if (ret == IDOK)
1222+
{
1223+
CWaitCursor wait;
1224+
1225+
try
1226+
{
1227+
try
1228+
{
1229+
for (int i = 0; i < 100; i++)
1230+
{
1231+
int toDeleteCount = theApp.m_db.execScalar(_T("SELECT COUNT(clipID) FROM MainDeletes"));
1232+
if (toDeleteCount <= 0)
1233+
break;
1234+
1235+
RemoveOldEntries(false);
1236+
}
1237+
}
1238+
CATCH_SQLITE_EXCEPTION
1239+
1240+
theApp.m_db.execDML(_T("PRAGMA auto_vacuum = 1"));
1241+
theApp.m_db.execQuery(_T("VACUUM"));
1242+
SetDbSize();
1243+
}
1244+
CATCH_SQLITE_EXCEPTION
1245+
}
1246+
}

src/DeleteClipData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,5 @@ class CDeleteClipData : public CDialog
119119
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
120120
void ShowClipPropertiesWindow();
121121
virtual void OnCancel();
122+
afx_msg void OnBnClickedBtCompactAndRepair();
122123
};

0 commit comments

Comments
 (0)