• R/O
  • SSH
  • HTTPS

ktx: Commit


Commit MetaInfo

Revision27 (tree)
Zeit2018-03-23 21:17:36
Autorbananajinn

Log Message

ファイル選択画面でファイル名ソートする機能を追加
ファイル選択画面で d キーを押すとリストから選択しているファイルパスを削除する機能を追加

Ändern Zusammenfassung

Diff

--- trunk/ktx/RecentFile.cs (revision 26)
+++ trunk/ktx/RecentFile.cs (revision 27)
@@ -49,5 +49,27 @@
4949 return null;
5050 }
5151
52+ #region Equals and GetHashCode implementation
53+ public override bool Equals(object obj)
54+ {
55+ RecentFile other = obj as RecentFile;
56+ if (other == null)
57+ return false;
58+ return this.FilePath == other.FilePath;
59+ }
60+
61+ public override int GetHashCode()
62+ {
63+ int hashCode = 0;
64+ unchecked {
65+ if (FilePath != null)
66+ hashCode += 1000000007 * FilePath.GetHashCode();
67+ hashCode += 1000000009 * LastOpened.GetHashCode();
68+ if (Encoding != null)
69+ hashCode += 1000000021 * Encoding.GetHashCode();
70+ }
71+ return hashCode;
72+ }
73+ #endregion
5274 }
5375 }
--- trunk/ktx/Registries.cs (revision 26)
+++ trunk/ktx/Registries.cs (revision 27)
@@ -3,6 +3,7 @@
33 */
44 using System;
55 using System.Collections.Generic;
6+using System.Linq;
67 using System.Text;
78 using ktox;
89 using Microsoft.Win32;
@@ -59,6 +60,12 @@
5960 PutRecentFiles(files);
6061 }
6162
63+ public static void DeleteRecentFiles(List<RecentFile> deleteFiles)
64+ {
65+ var files = GetRecentFiles().Where(x => !deleteFiles.Contains(x)).ToList();
66+ PutRecentFiles(files);
67+ }
68+
6269 public static Settings GetSettings()
6370 {
6471 using(var key = GetSubKey()){
--- trunk/ktx/Views/MainForm.cs (revision 26)
+++ trunk/ktx/Views/MainForm.cs (revision 27)
@@ -3,6 +3,7 @@
33 */
44 using System;
55 using System.Collections.Generic;
6+using System.Collections.Specialized;
67 using System.Diagnostics;
78 using System.Drawing;
89 using System.IO;
@@ -309,6 +310,9 @@
309310 if(dlg.ShowDialog() == DialogResult.OK && dlg.SelectedFile != null){
310311 NewFileTail(dlg.SelectedFile.FilePath, dlg.SelectedFile.Encoding);
311312 }
313+ if(dlg.DeletedFiles != null){
314+ Registries.DeleteRecentFiles(dlg.DeletedFiles);
315+ }
312316 }
313317 void OpenEventLog()
314318 {
--- trunk/ktx/Views/RecentFiles.Designer.cs (revision 26)
+++ trunk/ktx/Views/RecentFiles.Designer.cs (revision 27)
@@ -46,7 +46,6 @@
4646 this.timeStamp});
4747 this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
4848 this.listView1.FullRowSelect = true;
49- this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
5049 this.listView1.Location = new System.Drawing.Point(0, 0);
5150 this.listView1.MultiSelect = false;
5251 this.listView1.Name = "listView1";
@@ -54,6 +53,7 @@
5453 this.listView1.TabIndex = 0;
5554 this.listView1.UseCompatibleStateImageBehavior = false;
5655 this.listView1.View = System.Windows.Forms.View.Details;
56+ this.listView1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.ListView1ColumnClick);
5757 this.listView1.DoubleClick += new System.EventHandler(this.ListView1DoubleClick);
5858 this.listView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ListView1KeyDown);
5959 //
--- trunk/ktx/Views/RecentFiles.cs (revision 26)
+++ trunk/ktx/Views/RecentFiles.cs (revision 27)
@@ -2,6 +2,7 @@
22 * Copyright (C) 2017 BananaJinn
33 */
44 using System;
5+using System.Collections;
56 using System.Collections.Generic;
67 using System.Drawing;
78 using System.Windows.Forms;
@@ -15,6 +16,13 @@
1516 {
1617 public RecentFile SelectedFile { get; private set; }
1718
19+ public List<RecentFile> DeletedFiles { get; private set; }
20+
21+ private RecentFileComparer[] _comparers = new []{
22+ new RecentFileComparer(0, true),
23+ new RecentFileComparer(1, false),
24+ };
25+
1826 public RecentFiles()
1927 {
2028 //
@@ -61,11 +69,29 @@
6169 }
6270 }
6371
72+ private void DeleteSelection()
73+ {
74+ if(listView1.SelectedItems.Count == 1){
75+ var selectedItem = listView1.SelectedItems[0];
76+ var selectedFile = selectedItem.Tag as RecentFile;
77+ listView1.Items.Remove(selectedItem);
78+ if(DeletedFiles == null)
79+ DeletedFiles = new List<RecentFile>();
80+ DeletedFiles.Add(selectedFile);
81+ var focused = listView1.FocusedItem;
82+ if(focused != null)
83+ focused.Selected = true;
84+ }
85+ }
86+
6487 void ListView1KeyDown(object sender, KeyEventArgs e)
6588 {
6689 if(e.KeyCode == Keys.Enter){
6790 SelectFile();
6891 }
92+ if(e.KeyCode == Keys.D){
93+ DeleteSelection();
94+ }
6995 }
7096 void ListView1DoubleClick(object sender, EventArgs e)
7197 {
@@ -80,5 +106,39 @@
80106 }
81107 return base.ProcessDialogKey(keyData);
82108 }
109+ void ListView1ColumnClick(object sender, ColumnClickEventArgs e)
110+ {
111+ if(e.Column < _comparers.Length)
112+ listView1.ListViewItemSorter = _comparers[e.Column];
113+ }
114+
115+ public class RecentFileComparer : IComparer
116+ {
117+ private int _column;
118+ private bool _ascending;
119+
120+ /// <summary>
121+ /// コンストラクタ
122+ /// </summary>
123+ /// <param name="column">並び替えする列番号</param>
124+ /// <param name="ascending">昇順かどうか</param>
125+ public RecentFileComparer(int column, bool ascending)
126+ {
127+ _column = column;
128+ _ascending = ascending;
129+ }
130+
131+
132+ #region IComparer implementation
133+
134+ public int Compare(object x, object y)
135+ {
136+ var xx = ((ListViewItem)x).SubItems[_column].Text;
137+ var yy = ((ListViewItem)y).SubItems[_column].Text;
138+ return string.Compare(xx, yy, StringComparison.Ordinal) * (_ascending ? 1 : -1);
139+ }
140+
141+ #endregion
142+ }
83143 }
84144 }
Show on old repository browser