・ビューがアクティブになったときに表示中のフォルダのファイルに変更があったら表示を更新する
・表示を更新したときに、選択状態をできるだけ保持するように変更
@@ -124,6 +124,14 @@ | ||
124 | 124 | this.targetView.EnsureVisible(index); |
125 | 125 | } |
126 | 126 | |
127 | + public void BeginUpdate() { | |
128 | + this.targetView.BeginUpdate(); | |
129 | + } | |
130 | + | |
131 | + public void EndUpdate() { | |
132 | + this.targetView.EndUpdate(); | |
133 | + } | |
134 | + | |
127 | 135 | /// <summary> |
128 | 136 | /// 指定した座標にあるアイテムを取得する |
129 | 137 | /// </summary> |
@@ -25,6 +25,8 @@ | ||
25 | 25 | private const bool EventHandled = true; |
26 | 26 | private const bool EventNotHandled = false; |
27 | 27 | |
28 | + private bool isNeedToUpdateView = false; | |
29 | + | |
28 | 30 | public enum ViewModeType { |
29 | 31 | Normal, |
30 | 32 | /// <summary> |
@@ -168,7 +170,11 @@ | ||
168 | 170 | /// </summary> |
169 | 171 | public FilerItem FocusedFilerItem { |
170 | 172 | get { |
171 | - return this.virtualListView.FocusedItem.FilerItem; | |
173 | + if (this.virtualListView.FocusedItem != null) { | |
174 | + return this.virtualListView.FocusedItem.FilerItem; | |
175 | + } else { | |
176 | + return null; | |
177 | + } | |
172 | 178 | } |
173 | 179 | } |
174 | 180 |
@@ -207,6 +213,8 @@ | ||
207 | 213 | SetPath(previousPath, currentPath); |
208 | 214 | } |
209 | 215 | } |
216 | + this.fileSystemWatcher.Path = fullName; | |
217 | + this.isNeedToUpdateView = false; | |
210 | 218 | } |
211 | 219 | |
212 | 220 | /// <summary> |
@@ -321,9 +329,58 @@ | ||
321 | 329 | |
322 | 330 | folderInfoLabel.Text = "Folder Info: " + folders.Length + " folders / " + files.Length + " files" |
323 | 331 | + " (Hidden: " + hiddenFolderNum + " folders / " + hiddenFileNum + " files)"; |
332 | + | |
333 | + this.isNeedToUpdateView = false; | |
324 | 334 | } |
325 | 335 | |
326 | 336 | /// <summary> |
337 | + /// 選択状態とフォーカスを可能な限り維持しながらビューを更新する | |
338 | + /// </summary> | |
339 | + public void UpdateView(bool isKeepSelectingAndFocus) { | |
340 | + List<FilerItem> old_selection = this.SelectedFilerItems; | |
341 | + FilerItem old_focus = this.FocusedFilerItem; | |
342 | + | |
343 | + this.virtualListView.BeginUpdate(); | |
344 | + this.UpdateView(); | |
345 | + | |
346 | + if (isKeepSelectingAndFocus) { | |
347 | + this.virtualListView.SelectedItems.Clear(); | |
348 | + | |
349 | + //古い選択状態とフォーカス状態をFullNameが一致したものに対して反映 | |
350 | + foreach (VirtualListViewItem vItem in this.virtualListView.Items) { | |
351 | + if (old_focus != null && vItem.FilerItem.Info.FullName == old_focus.Info.FullName) { | |
352 | + vItem.Focused = true; | |
353 | + } | |
354 | + | |
355 | + foreach (FilerItem item in old_selection) { | |
356 | + if (vItem.FilerItem.Info.FullName == item.Info.FullName) { | |
357 | + vItem.Selected = true; | |
358 | + break; | |
359 | + } | |
360 | + } | |
361 | + } | |
362 | + | |
363 | + if (this.virtualListView.SelectedItems.Count == 0) { | |
364 | + this.virtualListView.Items[0].Focused = true; | |
365 | + this.virtualListView.Items[0].Selected = true; | |
366 | + } | |
367 | + } | |
368 | + this.virtualListView.EndUpdate(); | |
369 | + } | |
370 | + | |
371 | + /// <summary> | |
372 | + /// Viewの更新 | |
373 | + /// </summary> | |
374 | + /// <param name="isKeepSelectingAndFocus">ファイルの選択状態を保持するかどうか</param> | |
375 | + /// <param name="isUpdateOnlyWhenFileSystemChanged">ファイルシステムが更新された時のみ実行するならtrue</param> | |
376 | + public void UpdateView(bool isKeepSelectingAndFocus, bool isUpdateOnlyWhenFileSystemChanged) { | |
377 | + if (isUpdateOnlyWhenFileSystemChanged && !this.isNeedToUpdateView) { | |
378 | + return; | |
379 | + } | |
380 | + this.UpdateView(isKeepSelectingAndFocus); | |
381 | + } | |
382 | + | |
383 | + /// <summary> | |
327 | 384 | /// ファイルの選択状態(選択されている数など)を表示するためのメソッド。現在使われていない |
328 | 385 | /// SelectedIndexChangedのタイミングではSelectedIndiceが選択状態を表していないため、どのタイミングで描画すればよいかわからないので未使用 |
329 | 386 | /// </summary> |
@@ -676,5 +733,27 @@ | ||
676 | 733 | } |
677 | 734 | } |
678 | 735 | |
736 | + private void fileSystemWatcher_Changed(object sender, System.IO.FileSystemEventArgs e) { | |
737 | + this.isNeedToUpdateView = true; | |
738 | + } | |
739 | + | |
740 | + private void fileSystemWatcher_Created(object sender, System.IO.FileSystemEventArgs e) { | |
741 | + this.isNeedToUpdateView = true; | |
742 | + } | |
743 | + | |
744 | + private void fileSystemWatcher_Deleted(object sender, System.IO.FileSystemEventArgs e) { | |
745 | + this.isNeedToUpdateView = true; | |
746 | + } | |
747 | + | |
748 | + private void fileSystemWatcher_Renamed(object sender, System.IO.RenamedEventArgs e) { | |
749 | + this.isNeedToUpdateView = true; | |
750 | + } | |
751 | + | |
752 | + private void listView_Enter(object sender, EventArgs e) { | |
753 | + if (this.isNeedToUpdateView) { | |
754 | + this.UpdateView(true); | |
755 | + } | |
756 | + } | |
757 | + | |
679 | 758 | } |
680 | 759 | } |
@@ -1,11 +1,12 @@ | ||
1 | 1 | 更新履歴 |
2 | 2 | |
3 | 3 | ■0.26 |
4 | +・ビューがアクティブになったときに表示中のフォルダのファイルに変更があったら表示を更新する | |
5 | +・表示を更新したときに、選択状態をできるだけ保持するように変更 | |
4 | 6 | ・時刻の表示を修正(a.m.とp.m.が区別できなかったので12時間制から24時間制へ) |
7 | +・ツールバーのカスタマイズに、外部ツールを選んだときに外部ツールのアイコンを自動的に取り込むオプションを追加 | |
5 | 8 | ・マウスとキーボードを両方使っているときに、ファイルのフォーカス/選択状態がおかしくなるいくつかのケースを修正(完全には直っていない) |
6 | 9 | |
7 | - | |
8 | - | |
9 | 10 | ■0.25 |
10 | 11 | ・メニューの「ゴミ箱へ移動」のキーが(R)で、「名前の変更」とかぶっていたので、(G)に変更 |
11 | 12 | ・ファイル履歴の右クリックメニューに”フォルダを開く”を追加 |
@@ -395,6 +395,8 @@ | ||
395 | 395 | |
396 | 396 | private void MainForm_Activated(object sender, EventArgs e) { |
397 | 397 | CheckAndShowClipboard(); |
398 | + this.leftFileView.UpdateView(true, true); | |
399 | + this.rightFileView.UpdateView(true, true); | |
398 | 400 | } |
399 | 401 | |
400 | 402 | private void クリップボードへコピーToolStripMenuItem_Click(object sender, EventArgs e) { |
@@ -17,9 +17,11 @@ | ||
17 | 17 | |
18 | 18 | mainForm.CheckUpdateAllView();//TODO 最終的にはこれだけ呼び出せばいいようにする |
19 | 19 | |
20 | - mainForm.LeftFileView.UpdateView(); | |
20 | + //mainForm.LeftFileView.UpdateView(); | |
21 | + mainForm.LeftFileView.UpdateView(true); | |
21 | 22 | mainForm.LeftFileView.ChangeViewController(SCFiler2.ListViewControl.ListViewController.ControllerType.Normal); |
22 | - mainForm.RightFileView.UpdateView(); | |
23 | + //mainForm.RightFileView.UpdateView(); | |
24 | + mainForm.RightFileView.UpdateView(true); | |
23 | 25 | mainForm.RightFileView.ChangeViewController(SCFiler2.ListViewControl.ListViewController.ControllerType.Normal); |
24 | 26 | foreach (HistoryView historyView in mainForm.AllHistoryView) { |
25 | 27 | historyView.UpdateView(); |
@@ -29,8 +29,10 @@ | ||
29 | 29 | this.listView = new System.Windows.Forms.ListView(); |
30 | 30 | this.currentPathText = new System.Windows.Forms.TextBox(); |
31 | 31 | this.previewPictureBox = new System.Windows.Forms.PictureBox(); |
32 | + this.fileSystemWatcher = new System.IO.FileSystemWatcher(); | |
32 | 33 | this.driveInfoPanel.SuspendLayout(); |
33 | 34 | ((System.ComponentModel.ISupportInitialize)(this.previewPictureBox)).BeginInit(); |
35 | + ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher)).BeginInit(); | |
34 | 36 | this.SuspendLayout(); |
35 | 37 | // |
36 | 38 | // driveInfoPanel |
@@ -78,6 +80,7 @@ | ||
78 | 80 | this.listView.SelectedIndexChanged += new System.EventHandler(this.listView_SelectedIndexChanged); |
79 | 81 | this.listView.DoubleClick += new System.EventHandler(this.listView_DoubleClick); |
80 | 82 | this.listView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listView_MouseUp); |
83 | + this.listView.Enter += new System.EventHandler(this.listView_Enter); | |
81 | 84 | this.listView.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView_DragDrop); |
82 | 85 | this.listView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView_ColumnClick); |
83 | 86 | this.listView.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.listView_RetrieveVirtualItem); |
@@ -104,6 +107,15 @@ | ||
104 | 107 | this.previewPictureBox.TabIndex = 4; |
105 | 108 | this.previewPictureBox.TabStop = false; |
106 | 109 | // |
110 | + // fileSystemWatcher | |
111 | + // | |
112 | + this.fileSystemWatcher.EnableRaisingEvents = true; | |
113 | + this.fileSystemWatcher.SynchronizingObject = this; | |
114 | + this.fileSystemWatcher.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcher_Renamed); | |
115 | + this.fileSystemWatcher.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Deleted); | |
116 | + this.fileSystemWatcher.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Created); | |
117 | + this.fileSystemWatcher.Changed += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Changed); | |
118 | + // | |
107 | 119 | // FileView |
108 | 120 | // |
109 | 121 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); |
@@ -119,6 +131,7 @@ | ||
119 | 131 | this.driveInfoPanel.ResumeLayout(false); |
120 | 132 | this.driveInfoPanel.PerformLayout(); |
121 | 133 | ((System.ComponentModel.ISupportInitialize)(this.previewPictureBox)).EndInit(); |
134 | + ((System.ComponentModel.ISupportInitialize)(this.fileSystemWatcher)).EndInit(); | |
122 | 135 | this.ResumeLayout(false); |
123 | 136 | this.PerformLayout(); |
124 | 137 |
@@ -132,5 +145,6 @@ | ||
132 | 145 | private System.Windows.Forms.Label driveInfoLabel; |
133 | 146 | private System.Windows.Forms.TextBox currentPathText; |
134 | 147 | private System.Windows.Forms.PictureBox previewPictureBox; |
148 | + private System.IO.FileSystemWatcher fileSystemWatcher; | |
135 | 149 | } |
136 | 150 | } |