diff --git a/Quasar.Server/Controls/ListViewEx.cs b/Quasar.Server/Controls/ListViewEx.cs
index afcabd2f..c773addd 100644
--- a/Quasar.Server/Controls/ListViewEx.cs
+++ b/Quasar.Server/Controls/ListViewEx.cs
@@ -14,7 +14,7 @@ internal class AeroListView : ListView
private const short UISF_HIDEFOCUS = 0x1;
private readonly IntPtr _removeDots = new IntPtr(NativeMethodsHelper.MakeWin32Long(UIS_SET, UISF_HIDEFOCUS));
- private ListViewColumnSorter LvwColumnSorter { get; set; }
+ public ListViewColumnSorter LvwColumnSorter { get; set; }
///
/// Initializes a new instance of the class.
diff --git a/Quasar.Server/Forms/FrmConnections.Designer.cs b/Quasar.Server/Forms/FrmConnections.Designer.cs
index 1b819905..1062e74b 100644
--- a/Quasar.Server/Forms/FrmConnections.Designer.cs
+++ b/Quasar.Server/Forms/FrmConnections.Designer.cs
@@ -87,6 +87,7 @@ private void InitializeComponent()
this.lstConnections.TabIndex = 0;
this.lstConnections.UseCompatibleStateImageBehavior = false;
this.lstConnections.View = System.Windows.Forms.View.Details;
+ this.lstConnections.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lstConnections_ColumnClick);
//
// columnHeader1
//
diff --git a/Quasar.Server/Forms/FrmConnections.cs b/Quasar.Server/Forms/FrmConnections.cs
index 5f633633..17f0a257 100644
--- a/Quasar.Server/Forms/FrmConnections.cs
+++ b/Quasar.Server/Forms/FrmConnections.cs
@@ -160,5 +160,10 @@ private void closeConnectionToolStripMenuItem_Click(object sender, EventArgs e)
_connectionsHandler.RefreshTcpConnections();
}
}
+
+ private void lstConnections_ColumnClick(object sender, ColumnClickEventArgs e)
+ {
+ lstConnections.LvwColumnSorter.NeedNumberCompare = (e.Column == 2 || e.Column == 4);
+ }
}
}
diff --git a/Quasar.Server/Forms/FrmFileManager.Designer.cs b/Quasar.Server/Forms/FrmFileManager.Designer.cs
index 9900f794..80810def 100644
--- a/Quasar.Server/Forms/FrmFileManager.Designer.cs
+++ b/Quasar.Server/Forms/FrmFileManager.Designer.cs
@@ -332,6 +332,7 @@ private void InitializeComponent()
this.lstDirectory.DragDrop += new System.Windows.Forms.DragEventHandler(this.lstDirectory_DragDrop);
this.lstDirectory.DragEnter += new System.Windows.Forms.DragEventHandler(this.lstDirectory_DragEnter);
this.lstDirectory.DoubleClick += new System.EventHandler(this.lstDirectory_DoubleClick);
+ this.lstDirectory.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lstDirectory_ColumnClick);
//
// hName
//
diff --git a/Quasar.Server/Forms/FrmFileManager.cs b/Quasar.Server/Forms/FrmFileManager.cs
index af0c660a..649e42f7 100644
--- a/Quasar.Server/Forms/FrmFileManager.cs
+++ b/Quasar.Server/Forms/FrmFileManager.cs
@@ -250,7 +250,6 @@ private string NavigateUp()
private void FrmFileManager_Load(object sender, EventArgs e)
{
this.Text = WindowHelper.GetWindowTitle("File Manager", _connectClient);
-
_fileManagerHandler.RefreshDrives();
}
@@ -269,9 +268,9 @@ private void lstDirectory_DoubleClick(object sender, EventArgs e)
{
if (lstDirectory.SelectedItems.Count > 0)
{
- FileType type = (FileType) lstDirectory.SelectedItems[0].Tag;
+ FileManagerListTag tag = (FileManagerListTag) lstDirectory.SelectedItems[0].Tag;
- switch (type)
+ switch (tag.Type)
{
case FileType.Back:
SwitchDirectory(NavigateUp());
@@ -283,13 +282,18 @@ private void lstDirectory_DoubleClick(object sender, EventArgs e)
}
}
+ private void lstDirectory_ColumnClick(object sender, ColumnClickEventArgs e)
+ {
+ lstDirectory.LvwColumnSorter.NeedNumberCompare = (e.Column == 1);
+ }
+
private void downloadToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem files in lstDirectory.SelectedItems)
{
- FileType type = (FileType)files.Tag;
+ FileManagerListTag tag = (FileManagerListTag)files.Tag;
- if (type == FileType.File)
+ if (tag.Type == FileType.File)
{
string remotePath = GetAbsolutePath(files.SubItems[0].Text);
@@ -324,9 +328,9 @@ private void executeToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem files in lstDirectory.SelectedItems)
{
- FileType type = (FileType) files.Tag;
+ FileManagerListTag tag = (FileManagerListTag) files.Tag;
- if (type == FileType.File)
+ if (tag.Type == FileType.File)
{
string remotePath = GetAbsolutePath(files.SubItems[0].Text);
@@ -339,9 +343,9 @@ private void renameToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem files in lstDirectory.SelectedItems)
{
- FileType type = (FileType)files.Tag;
+ FileManagerListTag tag = (FileManagerListTag)files.Tag;
- switch (type)
+ switch (tag.Type)
{
case FileType.Directory:
case FileType.File:
@@ -351,7 +355,7 @@ private void renameToolStripMenuItem_Click(object sender, EventArgs e)
if (InputBox.Show("New name", "Enter new name:", ref newName) == DialogResult.OK)
{
newName = GetAbsolutePath(newName);
- _fileManagerHandler.RenameFile(path, newName, type);
+ _fileManagerHandler.RenameFile(path, newName, tag.Type);
}
break;
}
@@ -367,14 +371,14 @@ private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem files in lstDirectory.SelectedItems)
{
- FileType type = (FileType)files.Tag;
+ FileManagerListTag tag = (FileManagerListTag)files.Tag;
- switch (type)
+ switch (tag.Type)
{
case FileType.Directory:
case FileType.File:
string path = GetAbsolutePath(files.SubItems[0].Text);
- _fileManagerHandler.DeleteFile(path, type);
+ _fileManagerHandler.DeleteFile(path, tag.Type);
break;
}
}
@@ -385,9 +389,9 @@ private void addToStartupToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem files in lstDirectory.SelectedItems)
{
- FileType type = (FileType)files.Tag;
+ FileManagerListTag tag = (FileManagerListTag)files.Tag;
- if (type == FileType.File)
+ if (tag.Type == FileType.File)
{
string path = GetAbsolutePath(files.SubItems[0].Text);
@@ -413,9 +417,9 @@ private void openDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
if (lstDirectory.SelectedItems.Count == 1)
{
var item = lstDirectory.SelectedItems[0];
- FileType type = (FileType)item.Tag;
+ FileManagerListTag tag = (FileManagerListTag)item.Tag;
- if (type == FileType.Directory)
+ if (tag.Type == FileType.Directory)
{
path = GetAbsolutePath(item.SubItems[0].Text);
}
@@ -513,7 +517,7 @@ private void AddItemToFileBrowser(string name, long size, FileType type, int ima
(type != FileType.Back) ? type.ToString() : string.Empty
})
{
- Tag = type,
+ Tag = new FileManagerListTag(type, size),
ImageIndex = imageIndex
};
diff --git a/Quasar.Server/Forms/FrmTaskManager.Designer.cs b/Quasar.Server/Forms/FrmTaskManager.Designer.cs
index 68904aa0..5c5650cc 100644
--- a/Quasar.Server/Forms/FrmTaskManager.Designer.cs
+++ b/Quasar.Server/Forms/FrmTaskManager.Designer.cs
@@ -119,6 +119,7 @@ private void InitializeComponent()
this.lstTasks.TabIndex = 1;
this.lstTasks.UseCompatibleStateImageBehavior = false;
this.lstTasks.View = System.Windows.Forms.View.Details;
+ this.lstTasks.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lstTasks_ColumnClick);
//
// hProcessname
//
diff --git a/Quasar.Server/Forms/FrmTaskManager.cs b/Quasar.Server/Forms/FrmTaskManager.cs
index 2df0451e..feaef137 100644
--- a/Quasar.Server/Forms/FrmTaskManager.cs
+++ b/Quasar.Server/Forms/FrmTaskManager.cs
@@ -157,5 +157,10 @@ private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
{
_taskManagerHandler.RefreshProcesses();
}
+
+ private void lstTasks_ColumnClick(object sender, ColumnClickEventArgs e)
+ {
+ lstTasks.LvwColumnSorter.NeedNumberCompare = (e.Column == 1);
+ }
}
}
diff --git a/Quasar.Server/Models/FileManagerListTag.cs b/Quasar.Server/Models/FileManagerListTag.cs
new file mode 100644
index 00000000..1229c5f4
--- /dev/null
+++ b/Quasar.Server/Models/FileManagerListTag.cs
@@ -0,0 +1,17 @@
+using Quasar.Common.Enums;
+
+namespace Quasar.Server.Models
+{
+ public class FileManagerListTag
+ {
+ public FileType Type { get; set; }
+
+ public long FileSize { get; set; }
+
+ public FileManagerListTag(FileType type, long fileSize)
+ {
+ this.Type = type;
+ this.FileSize = fileSize;
+ }
+ }
+}
diff --git a/Quasar.Server/Utilities/ListViewColumnSorter.cs b/Quasar.Server/Utilities/ListViewColumnSorter.cs
index d63cf3d6..908ebe27 100644
--- a/Quasar.Server/Utilities/ListViewColumnSorter.cs
+++ b/Quasar.Server/Utilities/ListViewColumnSorter.cs
@@ -1,4 +1,5 @@
-using System.Collections;
+using Quasar.Server.Models;
+using System.Collections;
using System.Windows.Forms;
namespace Quasar.Server.Utilities
@@ -20,6 +21,11 @@ public class ListViewColumnSorter : IComparer
///
private readonly CaseInsensitiveComparer _objectCompare;
+ ///
+ /// Specifies if number or text comparision is needed
+ ///
+ private bool _needNumberCompare;
+
///
/// Class constructor. Initializes various elements
///
@@ -33,6 +39,8 @@ public ListViewColumnSorter()
// Initialize the CaseInsensitiveComparer object
_objectCompare = new CaseInsensitiveComparer();
+
+ _needNumberCompare = false;
}
///
@@ -51,8 +59,39 @@ public int Compare(object x, object y)
return 0;
// Compare the two items
- var compareResult = _objectCompare.Compare(listviewX.SubItems[_columnToSort].Text,
- listviewY.SubItems[_columnToSort].Text);
+ int compareResult;
+
+ if (_needNumberCompare)
+ {
+ long a, b;
+
+ if (listviewX.Tag is FileManagerListTag)
+ {
+ // fileSize to be compared
+ a = (listviewX.Tag as FileManagerListTag).FileSize;
+ b = (listviewY.Tag as FileManagerListTag).FileSize;
+ compareResult = a >= b ? (a == b ? 0 : 1) : -1;
+
+ }
+ else
+ {
+ if (long.TryParse(listviewX.SubItems[_columnToSort].Text, out a)
+ && long.TryParse(listviewY.SubItems[_columnToSort].Text, out b))
+ {
+ compareResult = a >= b ? (a == b ? 0 : 1) : -1;
+ }
+ else
+ {
+ compareResult = _objectCompare.Compare(listviewX.SubItems[_columnToSort].Text,
+ listviewY.SubItems[_columnToSort].Text);
+ }
+ }
+ }
+ else
+ {
+ compareResult = _objectCompare.Compare(listviewX.SubItems[_columnToSort].Text,
+ listviewY.SubItems[_columnToSort].Text);
+ }
// Calculate correct return value based on object comparison
if (_orderOfSort == SortOrder.Ascending)
@@ -89,5 +128,14 @@ public SortOrder Order
set { _orderOfSort = value; }
get { return _orderOfSort; }
}
+
+ ///
+ /// Specifies if number or text comparision is needed.
+ ///
+ public bool NeedNumberCompare
+ {
+ set { _needNumberCompare = value; }
+ get { return _needNumberCompare; }
+ }
}
}
\ No newline at end of file