OSDN Git Service

AppliStation-GUI,名前に"&"を含むソフトの場合アクセスキーの&と競合してしまい表示が変になる問題を対処
[applistation/AppliStation.git] / AppliStation / PackageListViewForm.cs
index 66e5c56..2d95efb 100644 (file)
@@ -26,6 +26,8 @@ namespace AppliStation
                        uninstallToolStripMenuItem.Font = new Font(uninstallToolStripMenuItem.Font, FontStyle.Bold);\r
                        \r
                        pkgListsMan = new PackageListsManager();\r
+                       \r
+                       this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);\r
                }\r
                \r
                void PackageListViewSelectedIndexChanged(object sender, EventArgs e)\r
@@ -74,6 +76,7 @@ namespace AppliStation
                        \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
@@ -213,7 +216,8 @@ namespace AppliStation
                        }\r
                        \r
                        updatePackageFilterToolStripMenuItemCheckState();\r
-                       searchTextBoxUpdate(false);\r
+                       searchTextBox.FireTextChangedTrigger();\r
+                       PackageListViewUpdate();\r
                }\r
                \r
                #endregion\r
@@ -223,7 +227,7 @@ namespace AppliStation
                        this.packageListView.Items.Clear();\r
                        \r
                        if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.NotInstalled) {\r
-                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(this.SearchKeyword)) {\r
+                               foreach (Package pkg in pkgListsMan.AvailablePkgList.Search(searchTextBox.Text)) {\r
                                        if (Installation.GetPreferInstallerIndex(pkg) >= 0) { // \83C\83\93\83X\83g\81[\83\8b\89Â\94\\r
                                                if (currentPackageFilter == PackageFilterIndex.NotInstalled &&\r
                                                    (pkgListsMan.InstalledPkgList.GetPackageForName(pkg.Name) != null||\r
@@ -241,7 +245,7 @@ namespace AppliStation
                        }\r
                        \r
                        if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledAS) {\r
-                               foreach (Package pkg in pkgListsMan.InstalledPkgList.Search(this.SearchKeyword)) {\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
@@ -252,7 +256,7 @@ namespace AppliStation
                        }\r
                        \r
                        if (currentPackageFilter == PackageFilterIndex.All || currentPackageFilter == PackageFilterIndex.InstalledSys) {\r
-                               foreach (Package pkg in pkgListsMan.SystemInstalledPkgList.Search(this.SearchKeyword)) {\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
@@ -303,68 +307,20 @@ namespace AppliStation
                \r
                #region searchTextBox\82Ü\82í\82è\r
                \r
-               private bool searchTextBoxIsEmpty = true;\r
-               \r
-               private Timer searchUpdateTimer = null;\r
-               \r
-               string SearchKeyword {\r
-                       get {\r
-                               return searchTextBoxIsEmpty? string.Empty : searchTextBox.Text;\r
-                       }\r
-               }\r
-               \r
-               void SearchTextBoxEnter(object sender, EventArgs e)\r
-               {\r
-                       if (searchTextBoxIsEmpty) {\r
-                               searchTextBox.Text = string.Empty;\r
-                               searchTextBox.ForeColor = DefaultForeColor;\r
-                               searchTextBoxIsEmpty = false;\r
-                       }\r
-               }\r
-               \r
-               void SearchTextBoxLeave(object sender, EventArgs e)\r
-               {\r
-                       if (string.IsNullOrEmpty(searchTextBox.Text)) {\r
-                               searchTextBox.Text = "\8c\9f\8dõ";\r
-                               searchTextBox.ForeColor = SystemColors.GrayText;\r
-                               searchTextBoxIsEmpty = true;\r
-                       }\r
-               }\r
-               \r
                void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e)\r
                {\r
                        switch (e.KeyChar) {\r
                                case (char)Keys.Enter:\r
-                                       searchTextBoxUpdate(true);\r
+                                       searchTextBox.FireTextChangedTrigger();\r
                                        break;\r
                                case (char)Keys.Escape:\r
-                                       searchTextBox.Text = "";\r
-                                       searchTextBoxUpdate(false);\r
-                                       break;\r
-                               default:\r
-                                       searchTextBoxUpdate(false);\r
+                                       searchTextBox.Text = string.Empty;\r
                                        break;\r
                        }\r
                }\r
                \r
-               private void searchTextBoxUpdate(bool force)\r
-               {\r
-                       if (! this.Created) return;\r
-                       \r
-                       if (searchUpdateTimer != null) {\r
-                               searchUpdateTimer.Stop();\r
-                       } else {\r
-                               searchUpdateTimer = new Timer();\r
-                               searchUpdateTimer.Tick += searchUpdateTimerTick;\r
-                       }\r
-                       searchUpdateTimer.Interval = (force)? 10 : 500;\r
-                       searchUpdateTimer.Start();\r
-               }\r
-               \r
-               private void searchUpdateTimerTick(object sender, EventArgs e)\r
+               void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e)\r
                {\r
-                       searchUpdateTimer.Stop();\r
-                       \r
                        PackageListViewUpdate();\r
                }\r
                \r
@@ -396,10 +352,7 @@ namespace AppliStation
                                Package[] instPkgs = confirm.CheckedPackages;\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
                                        installRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
-                                       this.Focus();\r
                                } else {\r
                                        installActionInvoke(instPkgs);\r
                                }\r
@@ -410,7 +363,9 @@ namespace AppliStation
                \r
                public void installRunasActionInvoke(Package[] pkgs)\r
                {\r
-                       string tmpfileName = System.IO.Path.GetTempFileName();\r
+                       this.setWindowEnabled(false);\r
+                       \r
+                       string tmpfileName = Path.GetTempFileName();\r
                        try {\r
                                NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
                                \r
@@ -420,17 +375,26 @@ namespace AppliStation
                                procInfo.Verb = "runas";\r
                                procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
                                \r
-                               using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
-                                       hProc.WaitForExit();\r
-                               }\r
-                               \r
-                               pkgListsMan.LoadPackageLists();\r
+                               System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
+                               hProc.EnableRaisingEvents = true;\r
+                               hProc.SynchronizingObject = this;\r
+                               hProc.Exited += delegate(object sender, EventArgs e) {\r
+                                       pkgListsMan.LoadPackageLists();\r
+                                       \r
+                                       this.setWindowEnabled(true);\r
+                                       this.BringToFront();\r
+                                       \r
+                                       if (File.Exists(tmpfileName)) {\r
+                                               File.Delete(tmpfileName);\r
+                                       }\r
+                               };\r
                        } catch (System.ComponentModel.Win32Exception ex) {\r
                                MessageBox.Show(ex.Message, "\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                       } finally {\r
+                               \r
                                if (File.Exists(tmpfileName)) {\r
                                        File.Delete(tmpfileName);\r
                                }\r
+                               this.setWindowEnabled(true);\r
                        }\r
                }\r
                \r
@@ -448,8 +412,10 @@ namespace AppliStation
                }\r
                \r
                internal void uninstallRunasActionInvoke(InstalledPackage[] pkgs)\r
-               {\r
-                       string tmpfileName = System.IO.Path.GetTempFileName();\r
+               {                       \r
+                       this.setWindowEnabled(false);\r
+                       \r
+                       string tmpfileName = Path.GetTempFileName();\r
                        try {\r
                                NaGet.Utils.PutSerializeObject(tmpfileName, pkgs);\r
                                \r
@@ -459,14 +425,23 @@ namespace AppliStation
                                procInfo.Verb = "runas";\r
                                procInfo.WorkingDirectory = Environment.CurrentDirectory;\r
                                \r
-                               using (System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo)) {\r
-                                       hProc.WaitForExit();\r
-                               }\r
-                               \r
-                               pkgListsMan.LoadPackageLists();\r
+                               System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo);\r
+                               hProc.EnableRaisingEvents = true;\r
+                               hProc.SynchronizingObject = this;\r
+                               hProc.Exited += delegate(object sender, EventArgs e) {\r
+                                       pkgListsMan.LoadPackageLists();\r
+                                       \r
+                                       this.setWindowEnabled(true);\r
+                                       this.BringToFront();\r
+                                       \r
+                                       if (File.Exists(tmpfileName)) {\r
+                                               File.Delete(tmpfileName);\r
+                                       }\r
+                               };\r
                        } catch (System.ComponentModel.Win32Exception ex) {\r
                                MessageBox.Show(ex.Message, "\83A\83\93\83C\83\93\83X\83g\81[\83\8b", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
-                       } finally {\r
+                               \r
+                               this.setWindowEnabled(true);\r
                                if (File.Exists(tmpfileName)) {\r
                                        File.Delete(tmpfileName);\r
                                }\r
@@ -487,10 +462,7 @@ namespace AppliStation
                                InstalledPackage[] instPkgs = new InstalledPackage[]{confirm.UninstallPackage};\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
                                        uninstallRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
-                                       this.Focus();\r
                                } else {\r
                                        uninstallActionInvoke(instPkgs);\r
                                }\r
@@ -537,6 +509,20 @@ namespace AppliStation
                        }\r
                }\r
                \r
+               \r
+               void PropertiesToolStripMenuItemClick(object sender, EventArgs e)\r
+               {\r
+                       foreach (Package pkg in SelectedPackages<Package>()) {\r
+                               PackageInfoForm form = new PackageInfoForm();\r
+                               form.SelectedObject = pkg;\r
+                               form.Text = string.Format("{0}({1})\82Ì\83v\83\8d\83p\83e\83B", pkg.Name, pkg.Version);\r
+                               \r
+                               form.ShowDialog(this);\r
+\r
+                               break;\r
+                       }\r
+               }\r
+               \r
                void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e)\r
                {\r
                        // \91I\91ð\82³\82ê\82Ä\82¢\82È\82¢\82È\82ç\8aJ\82©\82È\82¢\r
@@ -551,7 +537,6 @@ namespace AppliStation
                                installToolStripMenuItem.Visible = ! isInstalledPackage;\r
                                uninstallToolStripMenuItem.Visible = isInstalledPackage;\r
                                \r
-                               webResourcesToolStripMenuItem.Text = string.Format(webResourcesToolStripMenuItem.Tag.ToString(), pkg.Name);\r
                                webOfficialToolStripMenuItem.Enabled = ! (pkg.Url == null || string.IsNullOrEmpty(pkg.Url.Href));\r
                                // webGoogleSearchToolStripMenuItem always active.\r
                                \r
@@ -600,9 +585,7 @@ namespace AppliStation
                                Package[] instPkgs = confirm.CheckedPackages;\r
                                \r
                                if (confirm.UseRunas) {\r
-                                       this.Enabled = false;\r
                                        installRunasActionInvoke(instPkgs);\r
-                                       this.Enabled = true;\r
                                } else {\r
                                        installActionInvoke(instPkgs);\r
                                }\r
@@ -629,6 +612,23 @@ namespace AppliStation
                                \r
                                return pkgs.ToArray();\r
                }\r
+               \r
+               /// <summary>\r
+               /// \8e©\83E\83B\83\93\83h\83E\82Ì\97L\8cø\96³\8cø(Enabled)\82ð(\95K\97v\82 \82ê\82ÎInvoke\82µ\82Ä)\8eÀ\8ds\82·\82é \r
+               /// </summary>\r
+               /// <param name="enabled">\97L\8cø\82©\94Û\82©\81BEnabled\82Ì\92l\82É\93ü\82ê\82ç\82ê\82é</param>\r
+               private void setWindowEnabled(bool enabled)\r
+               {\r
+                       MethodInvoker process = (MethodInvoker) delegate() {\r
+                               this.Enabled = enabled;\r
+                       };\r
+                       \r
+                       if (InvokeRequired) {\r
+                               Invoke(process);\r
+                       } else {\r
+                               process.Invoke();\r
+                       }\r
+               }\r
        }\r
 \r
 }\r