-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategoryWindow.xaml.cs
More file actions
119 lines (103 loc) · 4.16 KB
/
CategoryWindow.xaml.cs
File metadata and controls
119 lines (103 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace DownloadsOrganizer
{
public partial class CategoryWindow : Window
{
// Artık sadece isim değil, tüm dosya bilgisini tutuyoruz
private List<FileInfo> _allFiles;
private List<FileInfo> _currentFilteredFiles; // Arama ve sıralama sonucu
// Constructor değişti: List<string> yerine List<FileInfo> alıyor
public CategoryWindow(string categoryName, List<FileInfo> files)
{
InitializeComponent();
this.Title = categoryName;
// Listeyi kopyalıyoruz ki ana pencereyle karışmasın
_allFiles = new List<FileInfo>(files);
_currentFilteredFiles = new List<FileInfo>(files);
// İlk açılışta varsayılan sıralama (Tarih Yeni)
ApplyFilterAndSort();
}
// --- SIRALAMA VE FİLTRELEME MANTIĞI ---
private void ApplyFilterAndSort()
{
string query = txtSearch.Text.ToLower();
int sortIndex = cbSort.SelectedIndex;
// 1. Önce Arama Yap
var tempFiles = _allFiles.Where(f => f.Name.ToLower().Contains(query));
// 2. Sonra Sırala
switch (sortIndex)
{
case 0: // Tarih (En Yeni)
tempFiles = tempFiles.OrderByDescending(f => f.LastWriteTime);
break;
case 1: // Tarih (En Eski)
tempFiles = tempFiles.OrderBy(f => f.LastWriteTime);
break;
case 2: // İsim (A-Z)
tempFiles = tempFiles.OrderBy(f => f.Name);
break;
case 3: // Boyut
tempFiles = tempFiles.OrderByDescending(f => f.Length);
break;
}
_currentFilteredFiles = tempFiles.ToList();
lbFiles.ItemsSource = _currentFilteredFiles;
}
// Arama değişince
private void TxtSearch_TextChanged(object sender, TextChangedEventArgs e)
{
ApplyFilterAndSort();
}
// Sıralama değişince
private void CbSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_allFiles != null) ApplyFilterAndSort();
}
// --- ETKİLEŞİMLER ---
private void LbFiles_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MenuOpen_Click(sender, null);
}
private FileInfo GetSelectedFile()
{
return lbFiles.SelectedItem as FileInfo;
}
private void MenuOpen_Click(object sender, RoutedEventArgs e)
{
var file = GetSelectedFile();
if (file != null)
try { Process.Start(new ProcessStartInfo(file.FullName) { UseShellExecute = true }); } catch { }
}
private void MenuShowInFolder_Click(object sender, RoutedEventArgs e)
{
var file = GetSelectedFile();
if (file != null) Process.Start("explorer.exe", $"/select, \"{file.FullName}\"");
}
private void MenuCopyPath_Click(object sender, RoutedEventArgs e)
{
var file = GetSelectedFile();
if (file != null) Clipboard.SetText(file.FullName);
}
private void MenuDelete_Click(object sender, RoutedEventArgs e)
{
var file = GetSelectedFile();
if (file != null && MessageBox.Show("Bu dosya kalıcı olarak silinecek?", "Dikkat", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
try
{
file.Delete();
_allFiles.Remove(file); // Listeden de düş
ApplyFilterAndSort(); // Listeyi yenile
}
catch { MessageBox.Show("Silinemedi. Dosya açık olabilir."); }
}
}
}
}