OSDN Git Service

AppliStation-GUI,「複数ソフト同時インストール機能」とりあえず複数選択できるようにした。
authorttp <ttp@users.sourceforge.jp>
Thu, 14 Aug 2008 11:51:36 +0000 (11:51 +0000)
committerttp <ttp@users.sourceforge.jp>
Thu, 14 Aug 2008 11:51:36 +0000 (11:51 +0000)
 * それを取りこぼさずにインストールプロセスクラスに渡すことができた模様
 * 右クリックの表示がバギーであるのでそれの修正が必要

git-svn-id: http://localhost/svn/AppliStation/trunk@948 34ed2c89-c49f-4a4b-abdb-c318350108cf

AppliStation/PackageListViewForm.Designer.cs
AppliStation/PackageListViewForm.cs

index e1338c7..2ac2548 100644 (file)
@@ -44,6 +44,7 @@
                        this.updateToolStripButton = new System.Windows.Forms.ToolStripSplitButton();\r
                        this.localUpdateToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        this.upgradeToolStripButton = new System.Windows.Forms.ToolStripButton();\r
+                       this.packageCommandsToolStripSeparator = new System.Windows.Forms.ToolStripSeparator();\r
                        this.installToolStripButton = new System.Windows.Forms.ToolStripButton();\r
                        this.uninstallToolStripButton = new System.Windows.Forms.ToolStripButton();\r
                        this.splitContainer = new System.Windows.Forms.SplitContainer();\r
@@ -60,7 +61,6 @@
                        this.openInstalledDirectoryStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        this.propertiesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();\r
                        this.detailBox = new System.Windows.Forms.RichTextBox();\r
-                       this.packageCommandsToolStripSeparator = new System.Windows.Forms.ToolStripSeparator();\r
                        this.tableLayoutPanel1.SuspendLayout();\r
                        this.toolStripContainer.SuspendLayout();\r
                        this.packageListFilterToolStrip.SuspendLayout();\r
                        this.upgradeToolStripButton.Text = "ソフトの更新(&G)";\r
                        this.upgradeToolStripButton.Click += new System.EventHandler(this.UpgradeToolStripButtonClick);\r
                        // \r
+                       // packageCommandsToolStripSeparator\r
+                       // \r
+                       this.packageCommandsToolStripSeparator.Name = "packageCommandsToolStripSeparator";\r
+                       this.packageCommandsToolStripSeparator.Size = new System.Drawing.Size(6, 25);\r
+                       this.packageCommandsToolStripSeparator.Visible = false;\r
+                       // \r
                        // installToolStripButton\r
                        // \r
                        this.installToolStripButton.Image = ((System.Drawing.Image)(resources.GetObject("installToolStripButton.Image")));\r
                        this.packageListView.FullRowSelect = true;\r
                        this.packageListView.GridLines = true;\r
                        this.packageListView.Location = new System.Drawing.Point(0, 0);\r
-                       this.packageListView.MultiSelect = false;\r
                        this.packageListView.Name = "packageListView";\r
                        this.packageListView.Size = new System.Drawing.Size(486, 225);\r
                        this.packageListView.TabIndex = 0;\r
                                                                        this.openInstalledDirectoryStripMenuItem,\r
                                                                        this.propertiesToolStripMenuItem});\r
                        this.packageListContextMenuStrip.Name = "packageListContextMenuStrip";\r
-                       this.packageListContextMenuStrip.Size = new System.Drawing.Size(232, 120);\r
+                       this.packageListContextMenuStrip.Size = new System.Drawing.Size(232, 142);\r
                        this.packageListContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.PackageListContextMenuStripOpening);\r
                        // \r
                        // installToolStripMenuItem\r
                        this.detailBox.Text = "";\r
                        this.detailBox.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.PackageDetailBoxLinkClicked);\r
                        // \r
-                       // packageCommandsToolStripSeparator\r
-                       // \r
-                       this.packageCommandsToolStripSeparator.Name = "packageCommandsToolStripSeparator";\r
-                       this.packageCommandsToolStripSeparator.Size = new System.Drawing.Size(6, 25);\r
-                       this.packageCommandsToolStripSeparator.Visible = false;\r
-                       // \r
                        // PackageListViewForm\r
                        // \r
                        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);\r
index 304db17..8634bc8 100644 (file)
@@ -30,59 +30,76 @@ namespace AppliStation
                        this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
                }\r
                \r
-               void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
+               private void ShowInfoToDetailBoxFor(Package pkg)\r
                {\r
-                       bool installBtnEnabled = false;\r
-                       bool uninstallBtnEnabled = false;\r
-                       \r
                        detailBox.Clear();\r
-                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                               Package pkg = (Package) item.Tag;\r
-                               \r
-                               bool isInstalledPackage = pkg is InstalledPackage;\r
-                               uninstallBtnEnabled = isInstalledPackage;\r
-                               installBtnEnabled = ! isInstalledPackage;\r
+                       \r
+                       detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
+                       detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
+                       if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
+                               detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
+                               detailBox.SelectedText += string.Format("タグ: {0}\r\n", pkg.Tags);\r
+                       }\r
+                       if (pkg is InstalledPackage) {\r
+                               InstalledPackage iPkg = (InstalledPackage) pkg;\r
+                               System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
+                               if (iPkg.UninstallInfo.InstallDate != null) {\r
+                                       sb.AppendFormat("インストールした日: {0:d}  ", iPkg.UninstallInfo.InstallDate.Value);\r
+                               }\r
+                               if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
+                                       sb.AppendFormat("サイズ: {0}  ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
+                               }\r
                                \r
-                               detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12);\r
-                               detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version);\r
-                               if (! string.IsNullOrEmpty(pkg.Tags) ) {\r
+                               if (sb.Length > 0) {\r
                                        detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
-                                       detailBox.SelectedText += string.Format("タグ: {0}\r\n", pkg.Tags);\r
-                               }\r
-                               if (isInstalledPackage) {\r
-                                       InstalledPackage iPkg = (InstalledPackage) pkg;\r
-                                       System.Text.StringBuilder sb = new System.Text.StringBuilder();\r
-                                       if (iPkg.UninstallInfo.InstallDate != null) {\r
-                                               sb.AppendFormat("インストールした日: {0:d}  ", iPkg.UninstallInfo.InstallDate.Value);\r
-                                       }\r
-                                       if (iPkg.UninstallInfo.EstimatedSize > 0) {\r
-                                               sb.AppendFormat("サイズ: {0}  ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024));\r
-                                       }\r
-                                       \r
-                                       if (sb.Length > 0) {\r
-                                               detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8);\r
-                                               detailBox.SelectedText += sb.ToString();\r
-                                               detailBox.SelectedText += "\r\n";\r
-                                       }\r
+                                       detailBox.SelectedText += sb.ToString();\r
+                                       detailBox.SelectedText += "\r\n";\r
                                }\r
-                               detailBox.SelectionFont = detailBox.Font;\r
-                               if (pkg.Url != null && pkg.Url.Href != null) {\r
-                                       detailBox.SelectedText += "公式サイト: " + pkg.Url.Href + "\r\n";\r
+                       }\r
+                       detailBox.SelectionFont = detailBox.Font;\r
+                       if (pkg.Url != null && pkg.Url.Href != null) {\r
+                               detailBox.SelectedText += "公式サイト: " + pkg.Url.Href + "\r\n";\r
+                       }\r
+                       detailBox.SelectedText += pkg.Summary;\r
+               }\r
+               \r
+               void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
+               {\r
+                       uint installPkgCount = 0;\r
+                       uint uninstallPkgCount = 0;\r
+                       bool installBtnEnabled, uninstallBtnEnabled;\r
+                       \r
+                       Package[] selectedPkgs = SelectedPackages<Package>();\r
+                       foreach (Package pkg in selectedPkgs) {\r
+                               if (pkg is InstalledPackage) {\r
+                                       uninstallPkgCount ++;\r
+                               } else {\r
+                                       installPkgCount ++;\r
                                }\r
-                               detailBox.SelectedText += pkg.Summary;\r
-                               \r
-                               break;\r
                        }\r
+                       installBtnEnabled = (installPkgCount > 0) && (uninstallPkgCount == 0);\r
+                       uninstallBtnEnabled = (uninstallPkgCount == 1) && (installPkgCount == 0);\r
                        \r
                        uninstallToolStripButton.Visible = uninstallBtnEnabled;\r
                        installToolStripButton.Visible = installBtnEnabled;\r
                        packageCommandsToolStripSeparator.Visible = uninstallBtnEnabled || installBtnEnabled;\r
                        \r
-                       if (packageListView.SelectedItems.Count <= 0) {\r
-                               detailBox.SelectionFont = detailBox.Font;\r
-                               int count = packageListView.Items.Count;\r
-                               detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count)\r
-                                       : "該当するソフトがありません。";\r
+                       switch (selectedPkgs.Length) {\r
+                               case 0:\r
+                                       detailBox.SelectionFont = detailBox.Font;\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
+                                       break;\r
+                               default: // case 2 and over:\r
+                                       detailBox.SelectionFont = detailBox.Font;\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
+                                       break;\r
                        }\r
                        \r
                        detailBox.SelectionStart = 0;\r
@@ -529,12 +546,15 @@ namespace AppliStation
                                return;\r
                        }\r
                        \r
-                       foreach (Package pkg in SelectedPackages<Package>()) {\r
+                       // メニューアイテムのインストール/アンインストールの表示はツールストリップに同じ\r
+                       installToolStripMenuItem.Visible = installToolStripButton.Visible;\r
+                       uninstallToolStripMenuItem.Visible = uninstallToolStripButton.Visible;\r
+                       \r
+                       // 選択パッケージが1つのとき\r
+                       if (packageListView.SelectedItems.Count == 1) {\r
+                               Package pkg = SelectedPackage<Package>();\r
                                bool isInstalledPackage = pkg is InstalledPackage;\r
                                \r
-                               installToolStripMenuItem.Visible = ! isInstalledPackage;\r
-                               uninstallToolStripMenuItem.Visible = isInstalledPackage;\r
-                               \r
                                webResourcesToolStripMenuItem.Text = string.Format(\r
                                        webResourcesToolStripMenuItem.Tag.ToString(),\r
                                        pkg.Name.Replace("&", "&&")); // pkg.Nameに&が含まれているときはエンコード\r
@@ -543,8 +563,6 @@ namespace AppliStation
                                \r
                                openInstalledDirectoryStripMenuItem.Visible = isInstalledPackage &&\r
                                        ( (pkg.Type == InstallerType.ARCHIVE) || Directory.Exists(((InstalledPackage) pkg).UninstallInfo.InstallLocation) );\r
-\r
-                               break;\r
                        }\r
                }\r
                \r
@@ -606,12 +624,24 @@ namespace AppliStation
                /// </summary>\r
                public TPackage[] SelectedPackages<TPackage>() where TPackage : Package\r
                {\r
-                               List<TPackage> pkgs = new List<TPackage>();\r
-                               foreach (ListViewItem item in packageListView.SelectedItems) {\r
-                                       pkgs.Add((TPackage) item.Tag);\r
-                               }\r
-                               \r
-                               return pkgs.ToArray();\r
+                       List<TPackage> pkgs = new List<TPackage>();\r
+                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
+                               pkgs.Add((TPackage) item.Tag);\r
+                       }\r
+                       \r
+                       return pkgs.ToArray();\r
+               }\r
+               \r
+               /// <summary>\r
+               /// インストールするよう選択されたパッケージをひとつ返す。\r
+               /// </summary>\r
+               /// <returns>選択されたパッケージ(選択されていないときはnull)</returns>\r
+               public TPackage SelectedPackage<TPackage>() where TPackage : Package\r
+               {\r
+                       foreach (ListViewItem item in packageListView.SelectedItems) {\r
+                               return (TPackage) item.Tag;\r
+                       }\r
+                       return null;\r
                }\r
                \r
                /// <summary>\r