OSDN Git Service

AppliStation-GUI,PackageListViewFormからListView関連処理を分離
authorttp <ttp@users.sourceforge.jp>
Sat, 17 Oct 2009 10:36:41 +0000 (19:36 +0900)
committerttp <ttp@users.sourceforge.jp>
Sat, 17 Oct 2009 10:36:41 +0000 (19:36 +0900)
AppliStation/AppliStation.csproj
AppliStation/PackageListView.cs [new file with mode: 0644]
AppliStation/PackageListViewForm.Designer.cs
AppliStation/PackageListViewForm.cs

index c22f4a1..fa294e5 100644 (file)
@@ -72,6 +72,7 @@
     <Compile Include="AppliStation.Util\ToolStripPetitLauncherMenuItem.cs" />\r
     <Compile Include="AppliStation.Util\ToolStripWeb2LikeTextBox.cs" />\r
     <Compile Include="AssemblyInfo.cs" />\r
+    <Compile Include="PackageListView.cs" />\r
     <Compile Include="InstallerInfoForm.cs" />\r
     <Compile Include="InstallerInfoForm.Designer.cs">\r
       <DependentUpon>InstallerInfoForm.cs</DependentUpon>\r
diff --git a/AppliStation/PackageListView.cs b/AppliStation/PackageListView.cs
new file mode 100644 (file)
index 0000000..71f496b
--- /dev/null
@@ -0,0 +1,255 @@
+using System;\r
+using System.Drawing;\r
+using System.Windows.Forms;\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+using NaGet.Packages;\r
+using NaGet.Packages.Install;\r
+\r
+namespace AppliStation\r
+{\r
+       /// <summary>\r
+       /// PackageListViewの表示フィルタ\r
+       /// </summary>\r
+       [Flags]\r
+       public enum PackageListViewPkgTypeFilter : uint\r
+       {\r
+               ViewNothing = 0,\r
+               NotInstalled = 1,\r
+               InstalledAS = 2,\r
+               InstalledSys = 4,\r
+               All = NotInstalled | InstalledAS | InstalledSys\r
+       }\r
+       \r
+       public class PackageListView : ListView\r
+       {\r
+\r
+               PackageListsManager pkgListMan = null;\r
+               \r
+               PackageListViewPkgTypeFilter filteringType = PackageListViewPkgTypeFilter.All;\r
+               \r
+               string filteringKeyword = null;\r
+               \r
+               [Category("Action")]\r
+               public event EventHandler FilterUpdated;\r
+               \r
+               public PackageListView()\r
+               {\r
+               }\r
+               \r
+               /// <summary>\r
+               /// パッケージリストのデータを設定・取得する。\r
+               /// </summary>\r
+               [Category("Behavior")]\r
+               [DefaultValue(null)]\r
+               public PackageListsManager Data\r
+               {\r
+                       get {   return this.pkgListMan; }\r
+                       set {\r
+                               this.pkgListMan = value;\r
+                               \r
+                               if (this.Visible) {\r
+                                       UpdateItems();\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 表示パッケージ種類フィルタを設定・取得する。\r
+               /// </summary>\r
+               [Category("Behavior")]\r
+               [DefaultValue(PackageListViewPkgTypeFilter.All)]\r
+               public PackageListViewPkgTypeFilter FilteringType {\r
+                       get { return filteringType; }\r
+                       set {\r
+                               if (filteringType != value) {\r
+                                       filteringType = value;\r
+                                       \r
+                                       if (this.Visible) {\r
+                                               UpdateItems();\r
+                                       }\r
+                                       \r
+                                       OnFilterUpdated(new EventArgs());\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 表示の際のフィルタリングキーワード\r
+               /// </summary>\r
+               [Category("Behavior")]\r
+               [DefaultValue(typeof(string), null)]\r
+               public string FilteringKeyword {\r
+                       get { return filteringKeyword; }\r
+                       set {\r
+                               if (filteringKeyword != value) {\r
+                                       filteringKeyword = value;\r
+                                       \r
+                                       if (this.Visible) {\r
+                                               UpdateItems();\r
+                                       }\r
+                                       \r
+                                       OnFilterUpdated(new EventArgs());\r
+                               }\r
+                       }\r
+               }\r
+                               \r
+               /// <summary>\r
+               /// 選択されたパッケージを1つ返す\r
+               /// </summary>\r
+               public Package SelectedPackage {\r
+                       get {\r
+                               if (SelectedItems.Count > 0) {\r
+                                       return (Package) (SelectedItems[0].Tag);\r
+                               } else {\r
+                                       return null;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 選択されたパッケージをイテレータとして返す\r
+               /// </summary>\r
+               public IEnumerable<Package> SelectedPackages {\r
+                       get {\r
+                               foreach (ListViewItem item in SelectedItems) {\r
+                                       yield return (Package) item.Tag;\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               #region データ領域作成メソッド群\r
+               \r
+               private ListViewItem createListViewItemForPackage(Package pkg, ImageCategory imageKey)\r
+               {\r
+                       string[] labels = new string[]{\r
+                               pkg.Name, pkg.Version, pkg.Summary,\r
+                       };\r
+                       \r
+                       ListViewItem item = new ListViewItem(labels);\r
+                       item.Tag = pkg;\r
+                       item.ToolTipText = pkg.Summary;\r
+                       item.ImageKey = ImageCategory_ToString(imageKey);\r
+                       \r
+                       return item;\r
+               }\r
+               \r
+               public void UpdateItems()\r
+               {\r
+                       string ImageKeyAvailable = ImageCategory_ToString(ImageCategory.Available);\r
+                       string ImageKeyAvailableNew = ImageCategory_ToString(ImageCategory.AvailableNew);\r
+                       string ImageKeyInstalled = ImageCategory_ToString(ImageCategory.Installed);\r
+                       string ImageKeySystem = ImageCategory_ToString(ImageCategory.System);\r
+                       string keyword = filteringKeyword ?? string.Empty;\r
+                       \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
+                                               bool isInstalledAS = (pkgListMan.InstalledPkgList.GetPackageForName(pkg.Name) != null);\r
+                                               bool isInstalledSys = (pkgListMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) != null);\r
+                                               \r
+                                               // インストールされていて、インストール済みソフトを表示しないならば、次のループへ\r
+                                               if ((((filteringType & PackageListViewPkgTypeFilter.InstalledAS) == 0) && isInstalledAS) ||\r
+                                                   (((filteringType & PackageListViewPkgTypeFilter.InstalledSys) == 0) && isInstalledSys)) {\r
+                                                       continue;\r
+                                               }\r
+                                               \r
+                                               ImageCategory cat = (isInstalledAS || isInstalledSys)? ImageCategory.Available : ImageCategory.AvailableNew;\r
+                                               Items.Add(createListViewItemForPackage(pkg, cat));\r
+                                       }\r
+                               }\r
+                       }\r
+                       \r
+                       // AppliStationにインストール済みのパッケージ\r
+                       if ((filteringType & PackageListViewPkgTypeFilter.InstalledAS) != 0) {\r
+                               foreach (Package pkg in pkgListMan.InstalledPkgList.Search(keyword)) {\r
+                                       Items.Add(createListViewItemForPackage(pkg, ImageCategory.Installed));\r
+                               }\r
+                       }\r
+                       \r
+                       // PCにインストール済みのパッケージ\r
+                       if ((filteringType & PackageListViewPkgTypeFilter.InstalledSys) != 0) {\r
+                               foreach (Package pkg in pkgListMan.SystemInstalledPkgList.Search(keyword)) {\r
+                                       Items.Add(createListViewItemForPackage(pkg, ImageCategory.System));\r
+                               }\r
+                       }\r
+                       \r
+                       this.Refresh();\r
+               }\r
+               \r
+               protected enum ImageCategory : uint {\r
+                       Available,\r
+                       AvailableNew,\r
+                       Installed,\r
+                       System,\r
+               };\r
+               \r
+               protected static string ImageCategory_ToString(ImageCategory cat)\r
+               {\r
+                       switch (cat) {\r
+                       case ImageCategory.Available:           return "available";\r
+                       case ImageCategory.AvailableNew:        return "available-new";\r
+                       case ImageCategory.Installed:           return "installed";\r
+                       case ImageCategory.System:                      return "sys";\r
+                       default:                                                        return string.Empty;\r
+                       }\r
+               }\r
+               \r
+               #endregion\r
+               \r
+               protected virtual void OnFilterUpdated(EventArgs e)\r
+               {\r
+                       if (FilterUpdated != null) {\r
+                               FilterUpdated(this, e);\r
+                       }\r
+               }\r
+               \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
+                       }\r
+                       \r
+                       base.OnColumnClick(e);\r
+               }\r
+               \r
+               private void onColumnClick(ColumnClickEventArgs e)\r
+               {\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
+                                       \r
+                                       sortComparer.Order = order;\r
+                               } else {\r
+                                       order = sortComparer.Order;\r
+                                       sortComparer.Column = e.Column;\r
+                               }\r
+                               \r
+                               Sort();\r
+                       }\r
+                       AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(this, e.Column, 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
+                       } catch (Exception) {   \r
+                       }\r
+               }\r
+               \r
+               #endregion\r
+       }\r
+}\r
index 5bcec8d..a2db9b3 100644 (file)
@@ -59,7 +59,7 @@
                        this.installToolStripButton = new System.Windows.Forms.ToolStripButton();\r
                        this.uninstallToolStripButton = new System.Windows.Forms.ToolStripButton();\r
                        this.splitContainer = new System.Windows.Forms.SplitContainer();\r
-                       this.packageListView = new System.Windows.Forms.ListView();\r
+                       this.packageListView = new AppliStation.PackageListView();\r
                        this.nameHeader = new System.Windows.Forms.ColumnHeader();\r
                        this.versionHeader = new System.Windows.Forms.ColumnHeader();\r
                        this.summaryHeader = new System.Windows.Forms.ColumnHeader();\r
                        // installToolStripMenuItem\r
                        // \r
                        this.installToolStripMenuItem.Name = "installToolStripMenuItem";\r
-                       this.installToolStripButton.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;\r
                        this.installToolStripMenuItem.Size = new System.Drawing.Size(239, 22);\r
                        this.installToolStripMenuItem.Text = "インストール(&I)...";\r
                        this.installToolStripMenuItem.Click += new System.EventHandler(this.InstallToolStripButtonClick);\r
                        // uninstallToolStripMenuItem\r
                        // \r
                        this.uninstallToolStripMenuItem.Name = "uninstallToolStripMenuItem";\r
-                       this.uninstallToolStripMenuItem.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;\r
                        this.uninstallToolStripMenuItem.Size = new System.Drawing.Size(239, 22);\r
                        this.uninstallToolStripMenuItem.Text = "アンインストール(&U)...";\r
                        this.uninstallToolStripMenuItem.Click += new System.EventHandler(this.UninstallToolStripButtonClick);\r
                        // \r
                        this.installToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("installToolStripButton.Image")));\r
                        this.installToolStripButton.Name = "installToolStripButton";\r
+                       this.installToolStripButton.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;\r
                        this.installToolStripButton.Size = new System.Drawing.Size(115, 22);\r
                        this.installToolStripButton.Text = "インストール(&I)";\r
                        this.installToolStripButton.ToolTipText = "選択されているソフトをインストールします";\r
                        // \r
                        this.uninstallToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("uninstallToolStripButton.Image")));\r
                        this.uninstallToolStripButton.Name = "uninstallToolStripButton";\r
+                       this.uninstallToolStripButton.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;\r
                        this.uninstallToolStripButton.Size = new System.Drawing.Size(143, 22);\r
                        this.uninstallToolStripButton.Text = "アンインストール(&U)";\r
                        this.uninstallToolStripButton.ToolTipText = "選択されているソフトをアンインストールします";\r
                                                                        this.summaryHeader});\r
                        this.packageListView.ContextMenuStrip = this.packageListContextMenuStrip;\r
                        this.packageListView.Dock = System.Windows.Forms.DockStyle.Fill;\r
+                       this.packageListView.FilteringKeyword = null;\r
                        this.packageListView.FullRowSelect = true;\r
                        this.packageListView.GridLines = true;\r
                        this.packageListView.Location = new System.Drawing.Point(0, 0);\r
                        this.packageListView.UseCompatibleStateImageBehavior = false;\r
                        this.packageListView.View = System.Windows.Forms.View.Details;\r
                        this.packageListView.ItemActivate += new System.EventHandler(this.PackageListViewItemActivate);\r
+                       this.packageListView.FilterUpdated += new System.EventHandler(this.PackageListViewSelectedIndexChanged);\r
                        this.packageListView.SelectedIndexChanged += new System.EventHandler(this.PackageListViewSelectedIndexChanged);\r
-                       this.packageListView.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.PackageListViewColumnClick);\r
                        // \r
                        // nameHeader\r
                        // \r
                private System.Windows.Forms.ToolStrip packageListFilterToolStrip;\r
                private AppliStation.Util.ToolStripWeb2LikeTextBox searchTextBox;\r
                private System.Windows.Forms.ColumnHeader versionHeader;\r
-               private System.Windows.Forms.ListView packageListView;\r
+               private AppliStation.PackageListView packageListView;\r
                private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;\r
                private System.Windows.Forms.ColumnHeader summaryHeader;\r
                private System.Windows.Forms.ColumnHeader nameHeader;\r
index 3407709..5bea2d6 100644 (file)
@@ -26,6 +26,7 @@ namespace AppliStation
                        uninstallToolStripMenuItem.Font = new Font(uninstallToolStripMenuItem.Font, FontStyle.Bold);\r
                        \r
                        pkgListsMan = new PackageListsManager();\r
+                       packageListView.Data = pkgListsMan;\r
                        \r
                        this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
                        AppliStation.Util.NativeMethods.ListView_EnableVistaExplorerTheme(packageListView);\r
@@ -74,40 +75,45 @@ namespace AppliStation
                \r
                void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
                {\r
+                       updateSelectedPackages();\r
+               }\r
+               \r
+               private void updateSelectedPackages()\r
+               {\r
                        uint installPkgCount = 0;\r
                        uint uninstallPkgCount = 0;\r
                        bool installBtnEnabled, uninstallBtnEnabled;\r
                        \r
-                       Package[] selectedPkgs = NaGet.Utils.IEnumerable2Array<Package>(GetSelectedPackages<Package>());\r
-                       foreach (Package pkg in selectedPkgs) {\r
+                       foreach (Package pkg in packageListView.SelectedPackages) {\r
                                if (pkg is InstalledPackage) {\r
                                        uninstallPkgCount ++;\r
                                } else {\r
                                        installPkgCount ++;\r
                                }\r
                        }\r
+                       uint pkgCount = installPkgCount + uninstallPkgCount;\r
                        installBtnEnabled = (installPkgCount > 0) && (uninstallPkgCount == 0);\r
                        uninstallBtnEnabled = (uninstallPkgCount == 1) && (installPkgCount == 0);\r
                        \r
-                       informationToolStripDropDownButton.Visible = (selectedPkgs.Length == 1);\r
+                       informationToolStripDropDownButton.Visible = (pkgCount == 1);\r
                        uninstallToolStripButton.Visible = uninstallBtnEnabled;\r
                        installToolStripButton.Visible = installBtnEnabled;\r
                        \r
                        // detailBoxのメッセージ設定\r
                        detailBox.Clear();\r
-                       switch (selectedPkgs.Length) {\r
+                       switch (pkgCount) {\r
                                case 0:\r
                                        int count = packageListView.Items.Count;\r
                                        detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count)\r
                                                : "該当するソフトがありません。";\r
                                        break;\r
                                case 1:\r
-                                       ShowInfoToDetailBoxFor(selectedPkgs[0]);\r
+                                       ShowInfoToDetailBoxFor(packageListView.SelectedPackage);\r
                                        break;\r
                                default: // case 2 and over:\r
                                        detailBox.Text = (installBtnEnabled)? string.Format("{0}個のソフトが選択されています。", installPkgCount) :\r
                                                (uninstallBtnEnabled)? string.Format("{0}個のインストール済みのソフトが選択されています。", uninstallPkgCount) :\r
-                                               string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", installPkgCount+uninstallPkgCount, uninstallPkgCount, installPkgCount);\r
+                                               string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", pkgCount, uninstallPkgCount, installPkgCount);\r
                                        break;\r
                        }\r
                        \r
@@ -121,20 +127,14 @@ namespace AppliStation
 \r
                void PackageListViewItemActivate(object sender, EventArgs e)\r
                {\r
-                       if (packageListView.SelectedItems.Count <= 0) {\r
-                               return; // exit \r
-                       }\r
+                       Package pkg = packageListView.SelectedPackage;\r
                        \r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               Package pkg = (Package) item.Tag;\r
-                               \r
+                       if (pkg != null) {\r
                                if (pkg is InstalledPackage) {\r
                                        UninstallToolStripButtonClick(sender, e);\r
                                } else {\r
                                        InstallToolStripButtonClick(sender, e);\r
                                }\r
-                               \r
-                               break;\r
                        }\r
                }\r
                \r
@@ -144,42 +144,6 @@ namespace AppliStation
                        installedDirectoryStripMenuItem.BaseFolderPath = pkg.discoverInstalledLocation();\r
                }\r
                \r
-               #region packageListViewのSort関連\r
-               \r
-               AppliStation.Util.ListViewItemSortComparer packageListViewSortComparer;\r
-\r
-               void PackageListViewColumnClick(object sender, ColumnClickEventArgs e)\r
-               {\r
-                       SortOrder order = SortOrder.None;\r
-                       \r
-                       if (packageListViewSortComparer == null) {\r
-                               order = SortOrder.Ascending;\r
-                               packageListViewSortComparer = new AppliStation.Util.ListViewItemSortComparer(e.Column, order);\r
-                               packageListView.ListViewItemSorter = packageListViewSortComparer;\r
-                       } else {\r
-                               if (packageListViewSortComparer.Column == e.Column) {\r
-                                       order = (packageListViewSortComparer.Order == SortOrder.Ascending)? SortOrder.Descending : SortOrder.Ascending;\r
-                                       \r
-                                       packageListViewSortComparer.Order = order;\r
-                               } else {\r
-                                       order = packageListViewSortComparer.Order;\r
-                                       packageListViewSortComparer.Column = e.Column;\r
-                               }\r
-                               \r
-                               packageListView.Sort();\r
-                       }\r
-                       AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, e.Column, order);\r
-                       \r
-                       // ソート対象列の色付け\r
-                       try {\r
-                               // SendMessage(hWnd, LVM_SETSELECTEDCOLUMN, column, NULL);\r
-                               AppliStation.Util.NativeMethods.SendMessage(packageListView.Handle, 0x1000+140, (uint) e.Column, 0);\r
-                       } catch (Exception) {   \r
-                       }\r
-               }\r
-               \r
-               #endregion\r
-               \r
                void Form_OnLoad(object sender, EventArgs e)\r
                {\r
                        packageListViewImageList.Images.Add("installed", Icon.ExtractAssociatedIcon(Application.ExecutablePath));\r
@@ -188,37 +152,22 @@ namespace AppliStation
                        notInstalledPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["available-new"];\r
                        installedASPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["installed"];\r
                        installedSysPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["sys"];\r
+                       \r
+                       packageListView.UpdateItems();\r
+                       updateSelectedPackages();\r
                }\r
                \r
                #region PackageFilter関連\r
                \r
-               private enum PackageFilterIndex : int\r
-               {\r
-                       All = 0,\r
-                       NotInstalled = 1,\r
-                       InstalledAS = 2,\r
-                       InstalledSys = 3,\r
-               }\r
-               \r
-               private PackageFilterIndex currentPackageFilter = PackageFilterIndex.All;\r
-               \r
-               private PackageFilterIndex CurrentPackageFilter {\r
-                       get {\r
-                               return currentPackageFilter;\r
-                       }\r
-                       set {\r
-                               currentPackageFilter = value;\r
-                               \r
-                               updatePackageFilterToolStripMenuItemCheckState();\r
-                       }\r
-               }\r
-               \r
+               /// <summary>\r
+               /// packgageFilterToolStripのリストを更新する。\r
+               /// </summary>\r
                private void updatePackageFilterToolStripMenuItemCheckState()\r
                {\r
                        ToolStripMenuItem selected = getCheckedPackageFilterToolStripItem();\r
                        \r
                        foreach (ToolStripMenuItem item in packageFilterToolStripDropDownButton.DropDown.Items) {\r
-                               item.Checked = selected == item;\r
+                               item.Checked = (selected == item);\r
                        }\r
                        \r
                        packageFilterToolStripDropDownButton.Text = selected.Text;\r
@@ -228,12 +177,12 @@ namespace AppliStation
                \r
                private ToolStripMenuItem getCheckedPackageFilterToolStripItem()\r
                {\r
-                       switch (currentPackageFilter) {\r
-                               case PackageFilterIndex.NotInstalled:\r
+                       switch (packageListView.FilteringType) {\r
+                               case PackageListViewPkgTypeFilter.NotInstalled:\r
                                        return notInstalledPackageFilterToolStripMenuItem;\r
-                               case PackageFilterIndex.InstalledAS:\r
+                               case PackageListViewPkgTypeFilter.InstalledAS:\r
                                        return installedASPackageFilterToolStripMenuItem;\r
-                               case PackageFilterIndex.InstalledSys:\r
+                               case PackageListViewPkgTypeFilter.InstalledSys:\r
                                        return installedSysPackageFilterToolStripMenuItem;\r
                                default:\r
                                        return allPackageFilterToolStripMenuItem;\r
@@ -243,73 +192,21 @@ namespace AppliStation
                void AnyPackageFilterToolStripMenuItemClicked(object sender, EventArgs e)\r
                {\r
                        if (sender == notInstalledPackageFilterToolStripMenuItem) {\r
-                               currentPackageFilter = PackageFilterIndex.NotInstalled;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.NotInstalled;\r
                        } else if (sender == installedASPackageFilterToolStripMenuItem) {\r
-                               currentPackageFilter = PackageFilterIndex.InstalledAS;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.InstalledAS;\r
                        } else if (sender == installedSysPackageFilterToolStripMenuItem) {\r
-                               currentPackageFilter = PackageFilterIndex.InstalledSys;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.InstalledSys;\r
                        } else {\r
-                               currentPackageFilter = PackageFilterIndex.All;\r
+                               packageListView.FilteringType = PackageListViewPkgTypeFilter.All;\r
                        }\r
                        \r
                        updatePackageFilterToolStripMenuItemCheckState();\r
                        searchTextBox.FireTextChangedTrigger();\r
-                       PackageListViewUpdate();\r
                }\r
                \r
                #endregion\r
                \r
-               void PackageListViewUpdate()\r
-               {\r
-                       this.packageListView.Items.Clear();\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
-                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) {\r
-                                       if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // インストール可能\r
-                                               bool notinstalled = (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) == null&&\r
-                                                    pkgListsMan.SystemInstalledPkgList.GetPackageForName(pkg.Name) == null);\r
-                                               if (currentPackageFilter == PackageFilterIndex.NotInstalled && ! notinstalled) {\r
-                                                       continue; // インストール済みは次のループへ(未インストールソフト抽出時)\r
-                                               }\r
-                                               \r
-                                               ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
-                                               item.Tag = pkg;\r
-                                               item.ToolTipText = pkg.Summary;\r
-                                               item.ImageKey = (notinstalled)? "available-new" : "available";\r
-               \r
-                                               this.packageListView.Items.Add(item);\r
-                                       }\r
-                               }\r
-                       }\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledAS) {\r
-                               foreach (Package pkg in pkgListsMan.InstalledPkgList.Search(searchTextBox.Text)) {\r
-                                       ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
-                                       item.Tag = pkg;\r
-                                       item.ToolTipText = pkg.Summary;\r
-                                       item.ImageKey = "installed";\r
-       \r
-                                       this.packageListView.Items.Add(item);\r
-                               }\r
-                       }\r
-                       \r
-                       if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledSys) {\r
-                               foreach (Package pkg in pkgListsMan.SystemInstalledPkgList.Search(searchTextBox.Text)) {\r
-                                       ListViewItem item = new ListViewItem(new string[]{pkg.Name, pkg.Version, pkg.Summary});\r
-                                       item.Tag = pkg;\r
-                                       item.ToolTipText = pkg.Summary;\r
-                                       item.ImageKey = "sys";\r
-       \r
-                                       this.packageListView.Items.Add(item);\r
-                               }\r
-                       }\r
-                       \r
-                       PackageListViewSelectedIndexChanged(packageListView, null);\r
-                       detailBox.Refresh();\r
-                       \r
-                       //this.packageListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);\r
-               }\r
-               \r
                void DetailBoxLinkClicked(object sender, LinkClickedEventArgs e)\r
                {\r
                        if (System.Text.RegularExpressions.Regex.IsMatch(e.LinkText, "^https?://")){\r
@@ -381,7 +278,7 @@ namespace AppliStation
                \r
                void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e)\r
                {\r
-                       PackageListViewUpdate();\r
+                       packageListView.FilteringKeyword = searchTextBox.Text;\r
                }\r
                \r
                #endregion\r
@@ -403,7 +300,7 @@ namespace AppliStation
                {\r
                        InstallationConfirmForm confirm = new InstallationConfirmForm();\r
                        confirm.PkgListsManager = pkgListsMan;\r
-                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(GetSelectedPackages<Package>()) );\r
+                       confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) );\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
@@ -509,10 +406,7 @@ namespace AppliStation
                void UninstallToolStripButtonClick(object sender, EventArgs e)\r
                {\r
                        PackageUninstallConfirmForm confirm = new PackageUninstallConfirmForm();\r
-                       foreach (InstalledPackage pkg in GetSelectedPackages<InstalledPackage>()) {\r
-                               confirm.UninstallPackage = pkg;\r
-                               break;\r
-                       }\r
+                       confirm.UninstallPackage = (InstalledPackage) packageListView.SelectedPackage;\r
                        confirm.UseRunas = confirm.GetShouldUseRunas();\r
                        DialogResult result = confirm.ShowDialog(this);\r
                        \r
@@ -532,23 +426,24 @@ namespace AppliStation
                \r
                void WebOfficialToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in GetSelectedPackages<Package>()) {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                string linkURL = pkg.Url.Href;\r
                                \r
-                               if (! (pkg == null || string.IsNullOrEmpty(linkURL))) {\r
+                               if (! string.IsNullOrEmpty(linkURL)) {\r
                                        try {\r
                                                System.Diagnostics.Process.Start(linkURL);\r
                                        } catch (System.ComponentModel.Win32Exception) {\r
                                                MessageBox.Show(string.Format("{0}を開くのに失敗しました。", linkURL), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                                        }\r
                                }\r
-                               break;\r
                        }\r
                }\r
                \r
                void WebGoogleSearchToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in GetSelectedPackages<Package>()) {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                string q = System.Web.HttpUtility.UrlEncode(pkg.Name, System.Text.Encoding.UTF8);\r
                                string googleURL = @"http://www.google.co.jp/search?q="+q;\r
                                \r
@@ -557,35 +452,31 @@ namespace AppliStation
                                } catch (System.ComponentModel.Win32Exception) {\r
                                        MessageBox.Show("Googleを開くのに失敗しました。", "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
                                }\r
-\r
-                               break;\r
                        }\r
                }\r
                \r
                void OpenInstalledDirectoryStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (InstalledPackage pkg in GetSelectedPackages<InstalledPackage>()) {\r
+                       InstalledPackage pkg = (InstalledPackage) packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                if (pkg.Type == InstallerType.ARCHIVE || pkg.Type == InstallerType.ITSELF) {\r
                                        System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name));\r
                                } else if (Directory.Exists(pkg.discoverInstalledLocation())) {\r
                                        System.Diagnostics.Process.Start(pkg.discoverInstalledLocation());\r
                                }\r
-\r
-                               break;\r
                        }\r
                }\r
                \r
                \r
                void PropertiesToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
-                       foreach (Package pkg in GetSelectedPackages<Package>()) {\r
+                       Package pkg = packageListView.SelectedPackage;\r
+                       if (pkg != null) {\r
                                PackageInfoForm form = new PackageInfoForm();\r
                                form.SelectedObject = pkg;\r
                                form.Text = string.Format("{0}({1})のプロパティ", pkg.Name, pkg.Version);\r
                                \r
                                form.ShowDialog(this);\r
-\r
-                               break;\r
                        }\r
                }\r
                \r
@@ -606,8 +497,8 @@ namespace AppliStation
                        // 選択パッケージが1つのとき\r
                        bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1;\r
                        if (selectionIsOnlyOne) {\r
-                               Package pkg = GetSelectedPackage<Package>();\r
-                               bool isInstalledPackage = pkg is InstalledPackage;\r
+                               Package pkg = packageListView.SelectedPackage;\r
+                               bool isInstalledPackage = (pkg is InstalledPackage);\r
                                \r
                                webResourcesToolStripMenuItem.Text = string.Format(\r
                                        webResourcesToolStripMenuItem.Tag.ToString(),\r
@@ -625,6 +516,8 @@ namespace AppliStation
                                        if (installedDirectoryStripMenuItemVisible) {\r
                                                buildInstalledDirectoryMenuItemStripChildren((InstalledPackage) pkg);\r
                                        }\r
+                               } else {\r
+                                       installedDirectoryStripMenuItem.Visible = false;\r
                                }\r
                        }\r
                        \r
@@ -697,29 +590,8 @@ namespace AppliStation
                public void UpdatePackageList()\r
                {\r
                        pkgListsMan.LoadPackageLists();\r
-                       this.PackageListViewUpdate();\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストールするよう選択されたパッケージの配列\r
-               /// </summary>\r
-               public IEnumerable<TPackage> GetSelectedPackages<TPackage>() where TPackage : Package\r
-               {\r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               yield return (TPackage) item.Tag;\r
-                       }\r
-               }\r
-               \r
-               /// <summary>\r
-               /// インストールするよう選択されたパッケージをひとつ返す。\r
-               /// </summary>\r
-               /// <returns>選択されたパッケージ(選択されていないときはnull)</returns>\r
-               public TPackage GetSelectedPackage<TPackage>() where TPackage : Package\r
-               {\r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               return (TPackage) item.Tag;\r
-                       }\r
-                       return null;\r
+                       packageListView.UpdateItems();\r
+                       updateSelectedPackages();\r
                }\r
                \r
                /// <summary>\r