// 移動(剪下/貼上) 操作 private void moveTo_Btn_Click(object sender, RoutedEventArgs e) { String newPath = folderPath.Text.ToString(); GloableObject.moveTo(GloableObject.img_path, newPath); GloableObject.folderInfo(); }
private void imgFileName_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { if (imgFileName.Text != GloableObject.preFileName) { try { System.IO.File.Move(GloableObject.img_path, GloableObject.curPath + '\\' + imgFileName.Text); GloableObject.logger($"✔🔁 [Renmae File] {GloableObject.img_filename} > {imgFileName.Text}"); System.IO.File.Delete(GloableObject.img_filename); GloableObject.img_path = GloableObject.curPath + '\\' + imgFileName.Text; GloableObject.img_filename = imgFileName.Text; } catch (System.IO.IOException) { GloableObject.logger($"❌⚠ [Error] [ReName File] - File Has Been Exsit."); } catch (System.ArgumentException) { GloableObject.logger($"❌⚠ [Error] [ReName File] - Can Not Empty File Name."); } finally { imgFileName.Text = GloableObject.img_filename; } } }
// Pre Img private void pre_img_Click(object sender, RoutedEventArgs e) { if (GloableObject.cur_img_position > 0) { GloableObject.cur_img_position--; GloableObject.change_img(GloableObject.file_list[GloableObject.cur_img_position]); } }
// Next Img private void next_img_Click(object sender, RoutedEventArgs e) { if (GloableObject.cur_img_position == 0 || GloableObject.cur_img_position < GloableObject.file_list.Count() - 1) { GloableObject.cur_img_position++; GloableObject.change_img(GloableObject.file_list[GloableObject.cur_img_position]); } }
// 開啟資料夾 private void colorTag_Click(object sender, RoutedEventArgs e) { if (Directory.Exists(this.folderPath.Text)) { Process.Start("explorer.exe", this.folderPath.Text + '\\'); } else { GloableObject.logger($"❌📤 [Error] [Open File Location] - Can't Not Open, File Dosen't Exsit."); } }
// Next按鈕 Next Button private void nextBtn_Click(object sender, RoutedEventArgs e) { if (GloableObject.img_filename == string.Empty) { GloableObject.logger($"❌🔎 [Error][Loading File] - No File Exsit."); return; } //string path = targetFolder_path.Text.ToString(); GloableObject.random_image(GloableObject.curPath); imgFileName.Text = GloableObject.img_filename; }
// 開啟檔案位置按鈕 Open File Location private void openImg_Btn_Click(object sender, RoutedEventArgs e) { if (File.Exists(GloableObject.img_path)) { Process.Start("explorer.exe", "/select, " + GloableObject.img_path); } else { GloableObject.logger($"❌📤 [Error] [Open File Location] - Can't Not Open, File Dosen't Exsit."); } }
// 複製圖片路徑 private void Button_Click_2(object sender, RoutedEventArgs e) { if (GloableObject.img_path == string.Empty) { GloableObject.logger($"❌📑 [Error] [Copy File Path] - No File Exsit."); } else { Clipboard.SetText(GloableObject.img_path); GloableObject.logger($"✔📑 [Error] [Copy File Path] - Copy [ {GloableObject.img_path} ] To ClipBoard."); copyBtn.IsChecked = false; } }
// 圖片瀏覽模式 // 前後 private void preview_mode_Checked(object sender, RoutedEventArgs e) { if (GloableObject.curPath == string.Empty) { preview_mode.IsChecked = false; GloableObject.logger($"❌ [Error] - NotFound Directory. Pls Choose The Main Directoy"); return; } else if (GloableObject.curPath != string.Empty || GloableObject.curPath != null) { GloableObject.file_list = new List <string>(Directory.GetFiles(GloableObject.curPath, "*", SearchOption.TopDirectoryOnly)); GloableObject.cur_img_position = GloableObject.file_list.IndexOf(GloableObject.img_path); } randomBtn.Visibility = Visibility.Collapsed; pre_img.Visibility = Visibility.Visible; next_img.Visibility = Visibility.Visible; }
// 選擇Favorite private void Favorite_Click(object sender, RoutedEventArgs e) { GloableObject.mainWin.preview_mode.IsChecked = false; GloableObject.mainWin.targetFolder_path.Text = this.favorite_path.Text; GloableObject.mainWin.targetFolder_path.ToolTip = this.favorite_path.Text; GloableObject.curPath = this.favorite_path.Text; GloableObject.random_image(GloableObject.curPath); Properties.Settings.Default.Current_Favorite = this.favorite_aka.Text; // 控件 GloableObject.mainWin.control_panel.Children.Clear(); foreach (string name in Properties.Settings.Default.Favorite_Controls_List) { string[] ary = name.Split(':', '"'); string key = ary[1].ToString(); // 解第一層dict if (key == this.favorite_aka.Text) { // {"favorite_name":{"control_x":["color","aka","paht"], "control_x":["color","aka","paht"]}} Dictionary <string, Dictionary <string, List <string> > > favorite_controls_list = (Dictionary <string, Dictionary <string, List <string> > >)JsonConvert.DeserializeObject(name, typeof(Dictionary <string, Dictionary <string, List <string> > >)); // "{control_x":["color","aka","paht"], "control_x":["color","aka","paht"]} Dictionary <string, List <string> > controls = favorite_controls_list[key]; foreach (string control in controls.Keys) { List <string> data = controls[control]; Folder_Control folder_control = new Folder_Control(); // 顏色 BrushConverter tagColor = new BrushConverter(); // 轉換顏色 folder_control.colorTag.Background = (Brush)tagColor.ConvertFrom(data[0]); // aka folder_control.akaLabel.Text = data[1]; // path folder_control.folderPath.Text = data[2]; folder_control.akaLabel.ToolTip = data[2]; folder_control.Height = 25; GloableObject.mainWin.control_panel.Children.Add(folder_control); } } } GloableObject.folderInfo(); GloableObject.logger($"✔🔄 [Switch Favorite] - Switch to Favorite {this.favorite_aka.Text}", "HighLight"); Window.GetWindow(this.Parent).Close(); }
// 確認創建 private void createBtn_Click(object sender, RoutedEventArgs e) { string color = choossColorBtn.SelectedColorText; if (color == string.Empty) { color = "#FFFFFF"; } Folder_Control folder_control = new Folder_Control(); // 創建 Folder_Control 實例 BrushConverter tagColor = new BrushConverter(); // 轉換顏色 folder_control.colorTag.Background = (Brush)tagColor.ConvertFrom(color); // 設定Lable控件 colorTag 的顏色 if (folderAKA_label.Text == string.Empty || folderAKA_label.Text == "A.K.A") { Console.WriteLine("00"); if (choseFolder_path.Text != string.Empty) { string dirName = new DirectoryInfo(@choseFolder_path.Text).Name; folder_control.akaLabel.Text = dirName; folder_control.akaLabel.Foreground = Brushes.Gray; Console.WriteLine("0"); } } else { Console.WriteLine("1"); folder_control.akaLabel.Text = folderAKA_label.Text; } folder_control.folderPath.Text = choseFolder_path.Text; folder_control.ToolTip = choseFolder_path.Text; folder_control.akaLabel.FontFamily = new FontFamily("Consolas Bold"); folder_control.Height = 25; //將Folder_Control 實例 添加到 MainWindow 的 control_panel 中 GloableObject.mainWin.control_panel.Children.Add(folder_control); GloableObject.logger($"✔🕹[Create Target Folder Control] AKA :[{folderAKA_label.Text}] ; Path: [{choseFolder_path.Text}]"); // 清空此Dialog元件的所有訊息 folderAKA_label.Text = string.Empty; choseFolder_path.Text = string.Empty; choossColorBtn.SelectedColor = Color.FromRgb(255, 255, 255); }
// 選取主要路徑 private void chooseTargetFolder_Btn_Click(object sender, RoutedEventArgs e) { preview_mode.IsChecked = false; WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog(); folderDialog.ShowNewFolderButton = false; folderDialog.RootFolder = Environment.SpecialFolder.Desktop; folderDialog.SelectedPath = GloableObject.lastPath; WinForms.DialogResult result = folderDialog.ShowDialog(); if (result == WinForms.DialogResult.Cancel) { return; } string sPath = folderDialog.SelectedPath; GloableObject.curPath = sPath; GloableObject.lastPath = sPath; GloableObject.random_image(sPath); GloableObject.folderInfo(); GloableObject.logger($"✔⚙ [Set Main Directory] - Path: [ {sPath} ]", "HighLight"); }
// 複製圖片 private void copy_img_Click(object sender, RoutedEventArgs e) { if (GloableObject.img == null) { copyBtn.IsChecked = false; GloableObject.logger("❌📑 [Error] [Copy Image] - No Image Exsit."); return; } else { var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnLoad; image.UriSource = new Uri(GloableObject.img_path); image.EndInit(); Clipboard.SetImage(image); GC.Collect(); GloableObject.logger($"✔📑 [Copy Image] - Copy [ {GloableObject.img_filename} ] To ClipBoard."); copyBtn.IsChecked = false; } }
// 刪除檔案 Delte File private void deleteImg_Btn_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Delete File Forever?", "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } else { if (File.Exists(GloableObject.img_path)) { System.IO.File.Delete(GloableObject.img_path); GloableObject.logger($"♻🗑 [Delete File] - FileName: [ {GloableObject.img_filename} ]"); GloableObject.random_image(GloableObject.curPath); GloableObject.folderInfo(); } else { GloableObject.logger($"❌🗑 [Error] [Delete File] - Can't Not Delete, File Dosen't Exsit."); } } }
// 資料夾拖曳進Target Folder private void ScrollViewer_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file_path in files) { string filename = System.IO.Path.GetFileName(file_path); // 判斷是否為資料夾 if (System.IO.Path.GetExtension(filename) == string.Empty) { // 生成Controls Folder_Control folder_Control = new Folder_Control(); folder_Control.akaLabel.Text = filename; folder_Control.folderPath.Text = file_path; folder_Control.ToolTip = file_path; folder_Control.Height = 25; control_panel.Children.Add(folder_Control); GloableObject.logger($"✔🕹[Create Target Folder Control] AKA :[{filename}] ; Path: [{file_path}]"); } } } }
// 資料夾拖曳進 Image Viewer / Main Folder private void Grid_Drop(object sender, DragEventArgs e) { preview_mode.IsChecked = false; if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (files.Length == 1) { string file = files[0]; string filename = System.IO.Path.GetFileName(file); string file_ex = System.IO.Path.GetExtension(filename); if (file_ex != string.Empty) { GloableObject.change_src(file); folder_info.Text = "..."; targetFolder_path.Text = System.IO.Path.GetFileName(file); targetFolder_path.ToolTip = file; GloableObject.logger($"✔🔽 [Load File] - Loaded:[{filename}] Path:[{file}]"); } else { GloableObject.curPath = file; GloableObject.random_image(file + '\\'); targetFolder_path.Text = file; GloableObject.logger($"✔🔽 [Load Folder] - Loaded:[{filename}] Path:[{file}]"); GloableObject.logger($"✔⚙ [Set Main Directory] - Path: [ {file} ]", "HighLight"); GloableObject.folderInfo(); } } else { MessageBox.Show("Only Can Drop One File / Folder."); return; } } }
// 儲存使用者Favorite設定 Save Current Favorite private void Button_Click_1(object sender, RoutedEventArgs e) { // 當前無使用Favorite if (Properties.Settings.Default.Current_Favorite == "None") { Window.GetWindow(this).Close(); Create_Favorite create_favorite = new Create_Favorite(); Window newWin = new Window { Height = 160, Width = 400, Content = create_favorite, Topmost = true, WindowStyle = WindowStyle.None, WindowStartupLocation = WindowStartupLocation.CenterScreen }; newWin.ShowDialog(); } // 當前正使用Favorite if (Properties.Settings.Default.Current_Favorite != "None") { // 刪除原來路徑 string target_path = string.Empty; foreach (string path in Properties.Settings.Default.Favorite_Path_List) { string[] ary = path.Split(':', '"'); string key = ary[1].ToString(); if (key == Properties.Settings.Default.Current_Favorite) { target_path = path; } } Properties.Settings.Default.Favorite_Path_List.Remove(target_path); // 存取更新路徑 Dictionary <string, string> favorite_path = new Dictionary <string, string>(); favorite_path.Add(Properties.Settings.Default.Current_Favorite, GloableObject.curPath); //{"name":"path"} string path_jsonStr = JsonConvert.SerializeObject(favorite_path, Formatting.Indented); StringCollection favorite_path_list = new StringCollection(); // 加回已存在的資料 if (Properties.Settings.Default.Favorite_Path_List != null) { foreach (string path in Properties.Settings.Default.Favorite_Path_List) { favorite_path_list.Add(path); } } favorite_path_list.Add(path_jsonStr); // 加入新資料 // 更新控件 // 刪除目前的 StringCollection favorite_controls_list = new StringCollection(); string target_controls = string.Empty; foreach (string name in Properties.Settings.Default.Favorite_Controls_List) { string[] ary = name.Split(':', '"'); string key = ary[1].ToString(); if (key == Properties.Settings.Default.Current_Favorite) { target_path = name; } favorite_controls_list.Add(name); } favorite_controls_list.Remove(target_path); // 刪除目標 Dictionary <string, Dictionary <string, List <string> > > favorite_controls = new Dictionary <string, Dictionary <string, List <string> > >(); Dictionary <string, List <string> > controls_list = new Dictionary <string, List <string> >(); int controls_counter = 0; foreach (Folder_Control control in GloableObject.mainWin.control_panel.Children) { string control_num = "control_" + controls_counter.ToString(); List <string> control_data = new List <string>(); //顏色 string color = control.colorTag.Background.ToString(); control_data.Add(color); //aka string aka = control.akaLabel.Text; control_data.Add(aka); //path string path = control.folderPath.Text; control_data.Add(path); controls_list.Add(control_num, control_data); //{"control_x":"[color, aka, path]"} controls_counter += 1; } favorite_controls.Add(Properties.Settings.Default.Current_Favorite, controls_list); //{"favor_name":{"control_x":"[color, aka, path]}} string controls_jsonStr = JsonConvert.SerializeObject(favorite_controls, Formatting.Indented); favorite_controls_list.Add(controls_jsonStr); Properties.Settings.Default.Favorite_Controls_List = favorite_controls_list; Properties.Settings.Default.Favorite_Path_List = favorite_path_list; Window.GetWindow(this).Close(); GloableObject.logger($"✔🤍 [Save Favorite] - Success Save Favorite {Properties.Settings.Default.Current_Favorite}.", "HighLight"); Properties.Settings.Default.Save(); } }
// 創建新Favorite private void Favorite_Create_Click(object sender, RoutedEventArgs e) { Properties.Settings.Default.Current_Favorite = Favorite_Name.Text; if (Favorite_Name.Text == string.Empty) { MessageBox.Show("Please Enter Favorite Name"); return; } else { if (Properties.Settings.Default.Favorite_List == null) { // 存名稱 StringCollection favorite_list = new StringCollection(); favorite_list.Add(Favorite_Name.Text); // 加入新資料 // 存路徑 Dictionary <string, string> favorite_path = new Dictionary <string, string>(); favorite_path.Add(Favorite_Name.Text, GloableObject.curPath); string jsonStr = JsonConvert.SerializeObject(favorite_path, Formatting.Indented); StringCollection favorite_path_list = new StringCollection(); favorite_path_list.Add(jsonStr); // 加入新資料 // 存控件 Dictionary <string, Dictionary <string, List <string> > > favorite_controls = new Dictionary <string, Dictionary <string, List <string> > >(); Dictionary <string, List <string> > controls_list = new Dictionary <string, List <string> >(); int controls_counter = 0; foreach (Folder_Control control in GloableObject.mainWin.control_panel.Children) { string control_num = "control_" + controls_counter.ToString(); List <string> control_data = new List <string>(); //顏色 string color = control.colorTag.Background.ToString(); control_data.Add(color); //aka string aka = control.akaLabel.Text; control_data.Add(aka); //path string path = control.folderPath.Text; control_data.Add(path); controls_list.Add(control_num, control_data); //{"control_x":"[color, aka, path]"} controls_counter += 1; } favorite_controls.Add(Favorite_Name.Text, controls_list); //{"favor_name":{"control_x":"[color, aka, path]}} string controls_jsonStr = JsonConvert.SerializeObject(favorite_controls, Formatting.Indented); StringCollection favorite_controls_list = new StringCollection(); favorite_controls_list.Add(controls_jsonStr); // 存檔 Properties.Settings.Default.Favorite_List = favorite_list; Properties.Settings.Default.Favorite_Path_List = favorite_path_list; Properties.Settings.Default.Favorite_Controls_List = favorite_controls_list; Properties.Settings.Default.Save(); } else { // 存名稱 StringCollection favorite_list = new StringCollection(); // 加回已存在的資料 foreach (string favorite in Properties.Settings.Default.Favorite_List) { favorite_list.Add(favorite); } favorite_list.Add(Favorite_Name.Text); // 加入新資料 // 存路徑 Dictionary <string, string> favorite_path = new Dictionary <string, string>(); favorite_path.Add(Favorite_Name.Text, GloableObject.curPath); //{"name":"path"} string path_jsonStr = JsonConvert.SerializeObject(favorite_path, Formatting.Indented); StringCollection favorite_path_list = new StringCollection(); // 加回已存在的資料 if (Properties.Settings.Default.Favorite_Path_List != null) { foreach (string path in Properties.Settings.Default.Favorite_Path_List) { favorite_path_list.Add(path); } } favorite_path_list.Add(path_jsonStr); // 加入新資料 // 存控件 Dictionary <string, Dictionary <string, List <string> > > favorite_controls = new Dictionary <string, Dictionary <string, List <string> > >(); Dictionary <string, List <string> > controls_list = new Dictionary <string, List <string> >(); // 加回已存在的資料 StringCollection favorite_controls_list = new StringCollection(); foreach (string name in Properties.Settings.Default.Favorite_Controls_List) { favorite_controls_list.Add(name); } int controls_counter = 0; foreach (Folder_Control control in GloableObject.mainWin.control_panel.Children) { string control_num = "control_" + controls_counter.ToString(); List <string> control_data = new List <string>(); //顏色 string color = control.colorTag.Background.ToString(); control_data.Add(color); //aka string aka = control.akaLabel.Text; control_data.Add(aka); //path string path = control.folderPath.Text; control_data.Add(path); controls_list.Add(control_num, control_data); //{"control_x":"[color, aka, path]"} controls_counter += 1; } favorite_controls.Add(Favorite_Name.Text, controls_list); //{"favor_name":{"control_x":"[color, aka, path]}} string controls_jsonStr = JsonConvert.SerializeObject(favorite_controls, Formatting.Indented); favorite_controls_list.Add(controls_jsonStr); Properties.Settings.Default.Favorite_List = favorite_list; Properties.Settings.Default.Favorite_Path_List = favorite_path_list; Properties.Settings.Default.Favorite_Controls_List = favorite_controls_list; Properties.Settings.Default.Save(); } Window.GetWindow(this).Close(); GloableObject.logger($"✔🤍 [Create Favorite] - Create Favorite {Favorite_Name.Text}.", "HighLight"); } }