@@ -100,6 +100,43 @@ private async void RestoreRecordsFromDb()
100100
101101 public List < Result > Query ( Query query )
102102 {
103+ var results = new List < Result > ( ) ;
104+ if ( query . FirstSearch == _settings . ClearKeyword )
105+ {
106+ results . AddRange (
107+ new [ ]
108+ {
109+ new Result
110+ {
111+ Title = "records" ,
112+ SubTitle = "clear records in memory only" ,
113+ IcoPath = _defaultIconPath ,
114+ Score = 21 ,
115+ Action = _ =>
116+ {
117+ _dataList . Clear ( ) ;
118+ return true ;
119+ } ,
120+ } ,
121+ new Result
122+ {
123+ Title = "database" ,
124+ SubTitle = "clear records in database too" ,
125+ IcoPath = _defaultIconPath ,
126+ Score = 1 ,
127+ Action = _ =>
128+ {
129+ _dataList . Clear ( ) ;
130+ _dbHelper . DeleteAllRecords ( ) ;
131+ CurrentScore = 1 ;
132+ return true ;
133+ } ,
134+ }
135+ }
136+ ) ;
137+
138+ return results ;
139+ }
103140 var displayData =
104141 query . Search . Trim ( ) . Length == 0
105142 ? _dataList . ToArray ( )
@@ -111,22 +148,22 @@ public List<Result> Query(Query query)
111148 )
112149 . ToArray ( ) ;
113150
114- var results = new List < Result > ( ) ;
115151 results . AddRange ( displayData . Select ( ClipDataToResult ) ) ;
116152 _context . API . LogDebug ( ClassName , "Added to result" ) ;
117153 results . Add (
118- new Result ( )
154+ new Result
119155 {
120156 Title = "Clear All Records" ,
121157 SubTitle = "Click to clear all records" ,
122158 IcoPath = _defaultIconPath ,
123159 Score = 1 ,
124160 Action = _ =>
125161 {
126- _dataList . Clear ( ) ;
127- // TODO: Add option in settings to select clear records from database
128- CurrentScore = 1 ;
129- return true ;
162+ _context . API . ChangeQuery (
163+ _context . CurrentPluginMetadata . ActionKeyword + " clear " ,
164+ true
165+ ) ;
166+ return false ;
130167 } ,
131168 }
132169 ) ;
@@ -229,7 +266,7 @@ private void _OnClipboardChange(object? sender, CbMonitor.ClipboardChangedEventA
229266 clipboardData . DisplayTitle = Regex . Replace ( clipboardData . Text . Trim ( ) , @"(\r|\n|\t|\v)" , "" ) ;
230267
231268 // make sure no repeat
232- if ( _dataList . Any ( node => node . GetMd5 ( ) == clipboardData . GetMd5 ( ) ) )
269+ if ( _dataList . Any ( node => node . GetMd5 ( ) == clipboardData . GetMd5 ( ) ) )
233270 return ;
234271 _context . API . LogDebug ( ClassName , "Adding to dataList" ) ;
235272 _dataList . AddFirst ( clipboardData ) ;
@@ -265,8 +302,10 @@ public void Dispose()
265302 } ;
266303 foreach ( var pair in kv )
267304 {
268- _dbHelper ? . DeleteRecordByKeepTime ( ( int ) pair . Item1 ,
269- CmBoxIndexMapper . ToKeepTime ( pair . Item2 ) ) ;
305+ _dbHelper ? . DeleteRecordByKeepTime (
306+ ( int ) pair . Item1 ,
307+ CmBoxIndexMapper . ToKeepTime ( pair . Item2 )
308+ ) ;
270309 }
271310
272311 _dbHelper ? . Close ( ) ;
@@ -306,7 +345,8 @@ public void PinOneRecord(ClipboardData c)
306345
307346 public int GetNewScoreByOrderBy ( ClipboardData clipboardData )
308347 {
309- if ( clipboardData . Pined ) return int . MaxValue ;
348+ if ( clipboardData . Pined )
349+ return int . MaxValue ;
310350 var orderBy = ( CbOrders ) _settings . OrderBy ;
311351 int score = 0 ;
312352 switch ( orderBy )
@@ -336,4 +376,4 @@ public void Save()
336376 {
337377 _settings . Save ( ) ;
338378 }
339- }
379+ }
0 commit comments