OSDN Git Service

AppliStation,チケット #23338 AVGをアンインストールしようとするとエラーが発生してしまう 対策
[applistation/AppliStation.git] / AppliStation / PackageListView.cs
index 71f496b..484ceeb 100644 (file)
@@ -5,6 +5,7 @@ using System.Collections.Generic;
 using System.ComponentModel;\r
 using NaGet.Packages;\r
 using NaGet.Packages.Install;\r
+using AppliStation.PackageInfo;\r
 \r
 namespace AppliStation\r
 {\r
@@ -12,9 +13,9 @@ namespace AppliStation
        /// PackageListViewの表示フィルタ\r
        /// </summary>\r
        [Flags]\r
-       public enum PackageListViewPkgTypeFilter : uint\r
+       public enum PackageListViewPkgTypeFilter\r
        {\r
-               ViewNothing = 0,\r
+               None = 0,\r
                NotInstalled = 1,\r
                InstalledAS = 2,\r
                InstalledSys = 4,\r
@@ -30,11 +31,14 @@ namespace AppliStation
                \r
                string filteringKeyword = null;\r
                \r
+               AppliStation.Util.ListViewItemSortComparer sortComparer;\r
+               \r
                [Category("Action")]\r
                public event EventHandler FilterUpdated;\r
                \r
                public PackageListView()\r
                {\r
+                       ListViewItemSorter = sortComparer = new AppliStation.Util.ListViewItemSortComparer();\r
                }\r
                \r
                /// <summary>\r
@@ -122,9 +126,22 @@ namespace AppliStation
                \r
                private ListViewItem createListViewItemForPackage(Package pkg, ImageCategory imageKey)\r
                {\r
-                       string[] labels = new string[]{\r
-                               pkg.Name, pkg.Version, pkg.Summary,\r
-                       };\r
+                       string[] labels = new string[this.Columns.Count];\r
+                       foreach (ColumnHeader header in this.Columns) {\r
+                               string tag = header.Tag as string;\r
+                               \r
+                               if (tag == "Name")                              labels[header.Index] = pkg.Name;\r
+                               if (tag == "Version")                   labels[header.Index] = pkg.Version;\r
+                               if (tag == "Summary")                   labels[header.Index] = pkg.Summary;\r
+                               if (tag == "PackageListName")   labels[header.Index] = pkg.PackageListName;\r
+                               if (tag == "License")                   labels[header.Index] = PackageDescripter.GetLicenseValueLabel(pkg);\r
+                               if (tag == "InstallDate") {\r
+                                       InstalledPackage instPkg = pkg as InstalledPackage;\r
+                                       if (instPkg != null && instPkg.UninstallInfo.InstallDate.HasValue) {\r
+                                               labels[header.Index] = instPkg.UninstallInfo.InstallDate.Value.ToShortDateString();\r
+                                       }\r
+                               }\r
+                       }\r
                        \r
                        ListViewItem item = new ListViewItem(labels);\r
                        item.Tag = pkg;\r
@@ -142,12 +159,13 @@ namespace AppliStation
                        string ImageKeySystem = ImageCategory_ToString(ImageCategory.System);\r
                        string keyword = filteringKeyword ?? string.Empty;\r
                        \r
+                       this.BeginUpdate();\r
                        this.Items.Clear();\r
                        \r
                        // ソフトリストの中身のパッケージ\r
                        if ((filteringType & PackageListViewPkgTypeFilter.NotInstalled) != 0) {\r
                                foreach (Package pkg in pkgListMan.AvailablePkgList.Search(keyword)) {\r
-                                       if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // インストール可能\r
+                                       if (Installation.IsInstallablePackage(pkg)) { // インストール可能\r
                                                bool isInstalledAS = (pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) != null);\r
                                                bool isInstalledSys = (pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) != null);\r
                                                \r
@@ -177,10 +195,12 @@ namespace AppliStation
                                }\r
                        }\r
                        \r
+                       this.EndUpdate();\r
+                       \r
                        this.Refresh();\r
                }\r
                \r
-               protected enum ImageCategory : uint {\r
+               protected enum ImageCategory {\r
                        Available,\r
                        AvailableNew,\r
                        Installed,\r
@@ -209,47 +229,54 @@ namespace AppliStation
                \r
                #region Sort関連\r
                \r
-               AppliStation.Util.ListViewItemSortComparer sortComparer;\r
-               \r
-               protected override void OnColumnClick(ColumnClickEventArgs e)\r
-               {\r
-                       if (this.HeaderStyle == ColumnHeaderStyle.Clickable) {\r
-                               onColumnClick(e);\r
+               /// <summary>\r
+               /// 選択しているコラムを設定あるいは取得を行う。\r
+               /// </summary>\r
+               public ColumnHeader SortColumn {\r
+                       get {\r
+                               return sortComparer.Column;\r
+                       }\r
+                       set {\r
+                               sortColumn(value);\r
                        }\r
-                       \r
-                       base.OnColumnClick(e);\r
                }\r
                \r
-               private void onColumnClick(ColumnClickEventArgs e)\r
+               protected void sortColumn(ColumnHeader column)\r
                {\r
+                       int columnIndex = (column != null)? column.Index : -1;\r
                        SortOrder order = SortOrder.None;\r
                        \r
-                       if (sortComparer == null) {\r
-                               order = SortOrder.Ascending;\r
-                               sortComparer = new AppliStation.Util.ListViewItemSortComparer(e.Column, order);\r
-                               ListViewItemSorter = sortComparer;\r
-                       } else {\r
-                               if (sortComparer.Column == e.Column) {\r
-                                       order = (sortComparer.Order == SortOrder.Ascending)? SortOrder.Descending : SortOrder.Ascending;\r
+                       if (columnIndex < 0) {\r
+                               sortComparer.Order = order = SortOrder.None;\r
+                       } else if (sortComparer.ColumnIndex == columnIndex) {\r
+                               order = (sortComparer.Order == SortOrder.Ascending)? SortOrder.Descending : SortOrder.Ascending;\r
                                        \r
-                                       sortComparer.Order = order;\r
-                               } else {\r
-                                       order = sortComparer.Order;\r
-                                       sortComparer.Column = e.Column;\r
-                               }\r
-                               \r
-                               Sort();\r
+                               sortComparer.Order = order;\r
+                       } else {\r
+                               order = SortOrder.Ascending;\r
+                               sortComparer.Column = column;\r
                        }\r
-                       AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(this, e.Column, order);\r
+                       Sort();\r
+                       \r
+                       AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(this, columnIndex, order);\r
                        \r
                        // ソート対象列の色付け\r
                        try {\r
-                               // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
-                               AppliStation.Util.NativeMethods.SendMessage(this.Handle, 0x1000+140, (uint) e.Column, 0);\r
+                               // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, columnIndex, NULL);\r
+                               AppliStation.Util.NativeMethods.SendMessage(this.Handle, 0x1000+140, new IntPtr(columnIndex), IntPtr.Zero);\r
                        } catch (Exception) {   \r
                        }\r
                }\r
                \r
+               protected override void OnColumnClick(ColumnClickEventArgs e)\r
+               {\r
+                       if (this.HeaderStyle == ColumnHeaderStyle.Clickable) {\r
+                               sortColumn(this.Columns[e.Column]);\r
+                       }\r
+                       \r
+                       base.OnColumnClick(e);\r
+               }\r
+               \r
                #endregion\r
        }\r
 }\r