Skip to content

Commit 263a755

Browse files
committed
done something
1 parent 1214075 commit 263a755

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

CutCode/DataBase/DataBaseManager.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ public DataBaseManager(IThemeService _themeService)
3131
{
3232
AllCodes.Add(new CodeBoxModel(c.Id, c.title, c.desc, c.isFav, c.lang, c.code, c.timestamp, themeService));
3333
}
34-
PropertyChanged();
34+
35+
var lst = new ObservableCollection<CodeBoxModel>();
36+
foreach (var code in AllCodes)
37+
{
38+
if (code.isFav) lst.Add(code);
39+
}
40+
FavCodes = lst;
3541
}
3642

3743
private int GetIndex(CodeBoxModel code)
@@ -56,8 +62,8 @@ public void PropertyChanged()
5662
}
5763
FavCodes = lst;
5864

59-
AllCodesUpdated.Invoke(AllCodes, EventArgs.Empty);
60-
FavCodesUpdated.Invoke(FavCodes, EventArgs.Empty);
65+
AllCodesUpdated?.Invoke(this, EventArgs.Empty);
66+
FavCodesUpdated?.Invoke(this, EventArgs.Empty);
6167
}
6268

6369
public CodeBoxModel AddCode(string title, string desc, string code, string langType)
@@ -139,7 +145,10 @@ public ObservableCollection<CodeBoxModel> OrderCode(string order, ObservableColl
139145
if (ind > 2)
140146
{
141147
lst = new ObservableCollection<CodeBoxModel>();
142-
foreach (var code in currentCodes) if (code.langType == order) lst.Add(code);
148+
foreach (var code in currentCodes)
149+
{
150+
if (code.langType == order) lst.Add(code);
151+
}
143152
}
144153
else
145154
{
@@ -184,7 +193,7 @@ public bool FavModify(CodeBoxModel code)
184193

185194
public ObservableCollection<CodeBoxModel> SearchCode(string text, string from, ObservableCollection<CodeBoxModel> codes)
186195
{
187-
return codes;
196+
return new ObservableCollection<CodeBoxModel>();
188197
}
189198
}
190199
}

CutCode/ViewModels/AddViewModel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ private void ThemeChanged(Object sender, EventArgs e)
4040

4141
private void SetAppearance()
4242
{
43-
// 40444B
4443
textBoxBackground = themeService.IsLightTheme ? ColorCon.Convert("#DADBDC") : ColorCon.Convert("#2A2E33");
4544
textBoxForeground = themeService.IsLightTheme ? ColorCon.Convert("#1A1A1A") : ColorCon.Convert("#F7F7F7");
4645
richtextBoxBackground = themeService.IsLightTheme ? ColorCon.Convert("#E3E5E8") : ColorCon.Convert("#2C3036");

CutCode/ViewModels/CodeViewModel.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ public void FavCommand()
244244
{
245245
isFav = !isFav;
246246
codeModel.isFav = isFav;
247-
database.FavModify(codeModel);
248-
favAddr = isFav ? "../Resources/Images/Icons/fav.png" : themeService.IsLightTheme ? "../Resources/Images/Icons/fav_black.png" : "../Resources/Images/Icons/fav_white.png";
247+
var isdone = database.FavModify(codeModel);
248+
if(isdone) favAddr = isFav ? "../Resources/Images/Icons/fav.png" : themeService.IsLightTheme ? "../Resources/Images/Icons/fav_black.png" : "../Resources/Images/Icons/fav_white.png";
249249
}
250250

251251
public void CopyCommand()
@@ -255,8 +255,8 @@ public void CopyCommand()
255255

256256
public void DelCommand()
257257
{
258-
database.DelCode(codeModel);
259-
BackCommand();
258+
var isdone = database.DelCode(codeModel);
259+
if(isdone) BackCommand();
260260
}
261261

262262
public void BackCommand() => pageService.Page = MainViewModel.Pages[0];
@@ -283,13 +283,16 @@ public void SaveCommand()
283283
codeModel.desc = desc;
284284
codeModel.code = code;
285285

286-
database.EditCode(codeModel);
286+
var isdone = database.EditCode(codeModel);
287287

288-
isEnabled = false;
289-
oppisEnabled = !isEnabled;
288+
if (isdone)
289+
{
290+
isEnabled = false;
291+
oppisEnabled = !isEnabled;
290292

291-
opacity1 = 1;
292-
opacity2 = 0.3;
293+
opacity1 = 1;
294+
opacity2 = 0.3;
295+
}
293296
}
294297

295298
public void CancelCommand()

CutCode/ViewModels/HomeViewModel.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Text;
88
using System.Threading.Tasks;
9+
using System.Windows;
910
using System.Windows.Media;
1011

1112
namespace CutCode
@@ -23,13 +24,12 @@ public HomeViewModel(IThemeService _themeService, IPageService _pageService, IDa
2324
pageService = _pageService;
2425

2526
database = _dataBase;
27+
AllCodes = database.AllCodes;
2628
database.AllCodesUpdated += AllCodesUpdated;
2729

2830
SetAppearance();
2931
IsSearched = false;
3032

31-
AllCodes = database.AllCodes;
32-
3333
AllLangs = new ObservableCollection<string>()
3434
{
3535
"All languages", "Python", "C++", "C#", "CSS", "Dart", "Golang", "Html", "Java",
@@ -41,8 +41,6 @@ private void ThemeChanged(object sender, EventArgs e)
4141
{
4242
SetAppearance();
4343
}
44-
private void AllCodesUpdated(object sender, EventArgs e) => AllCodes = database.AllCodes;
45-
4644
private void SetAppearance()
4745
{
4846
Theme = themeService.IsLightTheme;
@@ -52,6 +50,7 @@ private void SetAppearance()
5250
comboboxHoverColor = themeService.IsLightTheme ? ColorCon.Convert("#C5C7C9") : ColorCon.Convert("#202326");
5351
comboboxBackgroundColor = themeService.IsLightTheme ? ColorCon.Convert("#E3E5E8") : ColorCon.Convert("#202225");
5452
}
53+
private void AllCodesUpdated(object sender, EventArgs e) => AllCodes = database.AllCodes;
5554

5655
public ObservableCollection<CodeBoxModel> AllCodes { get; set; }
5756
public IList<string> AllLangs { get; set; }
@@ -121,7 +120,7 @@ public string CurrentSort1
121120
set
122121
{
123122
SetAndNotify(ref _CurrentSort1, value);
124-
ComboBoxItemSelected(value);
123+
Application.Current.Dispatcher.Invoke(new Action(() => { ComboBoxItemSelected(value); }));
125124
}
126125
}
127126

@@ -132,7 +131,7 @@ public string CurrentSort2
132131
set
133132
{
134133
SetAndNotify(ref _CurrentSort2, value);
135-
ComboBoxItemSelected(value);
134+
Application.Current.Dispatcher.Invoke(new Action(() => { ComboBoxItemSelected(value); }));
136135
}
137136
}
138137

0 commit comments

Comments
 (0)