using System; using System.Drawing; using System.Windows.Forms; using NaGet.Packages; using NaGet.Packages.Install; using System.IO; using System.Collections.Generic; using AppliStation.PackageInfo; namespace AppliStation { /// /// Description of PackageListViewForm. /// public partial class PackageListViewForm : Form { private PackageListsManager pkgListsMan = null; public PackageListViewForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); installToolStripMenuItem.Font = new Font(installToolStripMenuItem.Font, FontStyle.Bold); uninstallToolStripMenuItem.Font = new Font(uninstallToolStripMenuItem.Font, FontStyle.Bold); pkgListsMan = new PackageListsManager(); packageListView.Data = pkgListsMan; this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); AppliStation.Util.NativeMethods.ListView_EnableVistaExplorerTheme(packageListView); AppliStation.Util.NativeMethods.ListView_SetDoubleBuffer(packageListView, true); } private void ShowInfoToDetailBoxFor(Package pkg) { detailBox.Clear(); detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 12); detailBox.SelectedText += string.Format("{0} ({1})\r\n", pkg.Name, pkg.Version); if (! string.IsNullOrEmpty(pkg.Tags) ) { detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8); detailBox.SelectedText += "タグ:"; foreach (string tag in pkg.Tags.Split(' ')) { detailBox.AppendText(" "); AppliStation.Util.NativeMethods.RichTextBox_AddTextLink(detailBox, tag); } detailBox.AppendText("\r\n"); } // インストール済みパッケージの場合 InstalledPackage iPkg = pkg as InstalledPackage; if (iPkg != null) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (iPkg.UninstallInfo.InstallDate != null) { sb.AppendFormat("インストールした日: {0:d} ", iPkg.UninstallInfo.InstallDate.Value); } if (iPkg.UninstallInfo.EstimatedSize > 0) { sb.AppendFormat("サイズ: {0} ", NaGet.Utils.FormatSize(iPkg.UninstallInfo.EstimatedSize*1024)); } if (sb.Length > 0) { detailBox.SelectionFont = new Font(detailBox.Font.FontFamily, 8); detailBox.SelectedText += sb.ToString(); detailBox.SelectedText += "\r\n"; } } detailBox.SelectionFont = detailBox.Font; if (pkg.Url != null && pkg.Url.Href != null) { detailBox.SelectedText += "公式サイト: "; AppliStation.Util.NativeMethods.RichTextBox_AddTextLink(detailBox, pkg.Url.Href); detailBox.SelectedText += "\r\n"; } detailBox.SelectedText += pkg.Summary; } void PackageListViewSelectedIndexChanged(object sender, EventArgs e) { updateSelectedPackages(); } private void updateSelectedPackages() { uint installPkgCount = 0; uint uninstallPkgCount = 0; bool installBtnEnabled, uninstallBtnEnabled; foreach (Package pkg in packageListView.SelectedPackages) { if (pkg is InstalledPackage) { uninstallPkgCount ++; } else { installPkgCount ++; } } uint pkgCount = installPkgCount + uninstallPkgCount; installBtnEnabled = (installPkgCount > 0) && (uninstallPkgCount == 0); uninstallBtnEnabled = (uninstallPkgCount == 1) && (installPkgCount == 0); // ToolStrip informationToolStripDropDownButton.Visible = (pkgCount == 1); uninstallToolStripButton.Visible = uninstallBtnEnabled; installToolStripButton.Visible = installBtnEnabled; // MenuStrip webResourceToolStripMenuItem.Visible = (pkgCount == 1); uninstallToolStripMenuItem.Visible = uninstallBtnEnabled; installToolStripMenuItem.Visible = installBtnEnabled; downloadToolStripMenuItem.Visible = (pkgCount > 0); // detailBoxのメッセージ設定 switch (pkgCount) { case 0: int count = packageListView.Items.Count; detailBox.Clear(); detailBox.Text = (count > 0) ? string.Format("{0}個のソフトがあります。", count) : "該当するソフトがありません。"; break; case 1: ShowInfoToDetailBoxFor(packageListView.SelectedPackage); break; default: // case 2 and over: detailBox.Clear(); detailBox.Text = (installBtnEnabled)? string.Format("{0}個のソフトが選択されています。", installPkgCount) : (uninstallBtnEnabled)? string.Format("{0}個のインストール済みのソフトが選択されています。", uninstallPkgCount) : string.Format("{0}個のソフトが選択されています。\r\n(うち{1}個はインストール済み、{2}個はインストール可能)", pkgCount, uninstallPkgCount, installPkgCount); break; } try { detailBox.Select(0, 0); detailBox.ScrollToCaret(); } catch (System.Runtime.InteropServices.COMException) { // ScrollToCaretでこけることがある } } void PackageListViewItemActivate(object sender, EventArgs e) { Package pkg = packageListView.SelectedPackage; if (pkg != null) { if (pkg is InstalledPackage) { UninstallToolStripButtonClick(sender, e); } else { InstallToolStripButtonClick(sender, e); } } } void Form_OnLoad(object sender, EventArgs e) { packageListViewImageList.Images.Add("installed", Icon.ExtractAssociatedIcon(Application.ExecutablePath)); updatePackageFilterToolStripMenuItemCheckState(); notInstalledPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["available-new"]; installedASPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["installed"]; installedSysPackageFilterToolStripMenuItem.Image = packageListViewImageList.Images["sys"]; packageListView.UpdateItems(); updateSelectedPackages(); } #region PackageFilter関連 /// /// packgageFilterToolStripのリストを更新する。 /// private void updatePackageFilterToolStripMenuItemCheckState() { ToolStripMenuItem selected = getCheckedPackageFilterToolStripItem(); foreach (ToolStripMenuItem item in packageFilterToolStripDropDownButton.DropDown.Items) { item.Checked = (selected == item); } packageFilterToolStripDropDownButton.Text = selected.Text; packageFilterToolStripDropDownButton.Image = selected.Image; packageFilterToolStripDropDownButton.ToolTipText = selected.ToolTipText; } private ToolStripMenuItem getCheckedPackageFilterToolStripItem() { switch (packageListView.FilteringType) { case PackageListViewPkgTypeFilter.NotInstalled: return notInstalledPackageFilterToolStripMenuItem; case PackageListViewPkgTypeFilter.InstalledAS: return installedASPackageFilterToolStripMenuItem; case PackageListViewPkgTypeFilter.InstalledSys: return installedSysPackageFilterToolStripMenuItem; default: return allPackageFilterToolStripMenuItem; } } void AnyPackageFilterToolStripMenuItemClicked(object sender, EventArgs e) { if (sender == notInstalledPackageFilterToolStripMenuItem) { packageListView.FilteringType = PackageListViewPkgTypeFilter.NotInstalled; } else if (sender == installedASPackageFilterToolStripMenuItem) { packageListView.FilteringType = PackageListViewPkgTypeFilter.InstalledAS; } else if (sender == installedSysPackageFilterToolStripMenuItem) { packageListView.FilteringType = PackageListViewPkgTypeFilter.InstalledSys; } else { packageListView.FilteringType = PackageListViewPkgTypeFilter.All; } updatePackageFilterToolStripMenuItemCheckState(); searchTextBox.FireTextChangedTrigger(); } #endregion void DetailBoxLinkClicked(object sender, LinkClickedEventArgs e) { if (System.Text.RegularExpressions.Regex.IsMatch(e.LinkText, "^https?://")){ /* URLの場合はブラウザ起動 */ try { System.Diagnostics.Process.Start(e.LinkText); } catch (System.ComponentModel.Win32Exception) { MessageBox.Show(string.Format("{0}を開くのに失敗しました。", e.LinkText), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { /* それ以外はタグとみなして検索 */ searchTextBox.Text = e.LinkText; } } internal void updateActionInvoke(bool downloadPackageListsFlag) { AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); prog.Shown += delegate(object sender2, EventArgs e2) { NaGet.SubCommands.NaGetUpdate2 tasks = new NaGet.SubCommands.NaGetUpdate2(pkgListsMan, downloadPackageListsFlag); prog.SetTaskSet(tasks); prog.Refresh(); prog.StartTaskSet(); }; prog.Text = "リストの更新"; prog.ShowDialog(this); } void UpdateToolStripMenuItemClick(object sender, EventArgs e) { updateActionInvoke(true); UpdatePackageList(); } void LocalupdateToolStripMenuItemClick(object sender, EventArgs e) { updateActionInvoke(false); UpdatePackageList(); } void SoftCollectionFileImportToolStripMenuItemClick(object sender, EventArgs e) { string pwd = Directory.GetCurrentDirectory(); OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt"; fd.DefaultExt = "txt"; fd.CheckFileExists = true; fd.CheckPathExists = true; fd.Multiselect = false; fd.ShowDialog(); if (fd.FileNames.Length > 0) { string filepath = Path.GetFullPath(fd.FileName); Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す IList pkgs; IList invalid; try { PackageCollectionFileData collectionData = new PackageCollectionFileData(); collectionData.load(filepath); collectionData.generatePackages(pkgListsMan, out pkgs, out invalid); if (invalid.Count > 0) { DialogResult result = MessageBox.Show("一部読み込みの失敗したパッケージがありますが続行しますか?", "インポート", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (result != DialogResult.OK) { return; } } } catch (IOException) { MessageBox.Show("ファイルの読み込みに失敗しました", "インポート", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } { InstallationConfirmForm confirm = new InstallationConfirmForm(); confirm.PkgListsManager = pkgListsMan; confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(pkgs) ); confirm.UseRunas = confirm.GetShouldUseRunas(); DialogResult result = confirm.ShowDialog(this); if (result == DialogResult.OK) { Installation[] insts = confirm.CheckedInstallations; if (confirm.UseRunas) { installRunasActionInvoke(insts); } else { installActionInvoke(insts); } UpdatePackageList(); } } } else { Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す } } void SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e) { string pwd = Directory.GetCurrentDirectory(); string[] softtargets = new string[]{ "PCにインストールされたソフト", "AppliStation内でインストールされたソフト", "インストールされたソフトすべて;PCとAppliStationにインストールされたソフトの両方" }; int softtargetid = softtargets.Length - 1; { AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createCommandSelectionDialog( "ソフトコレクションファイルに出力するソフトの種類を選択してください。", "エクスポート", "エクスポートするソフト", System.Drawing.SystemIcons.Question, softtargets, softtargets.Length-1); if (optdialog.ShowDialog(this) != DialogResult.OK) { return; // canceled } else if (optdialog.UserInputValue != null) { softtargetid = (int) optdialog.UserInputValue; } } SaveFileDialog fd = new SaveFileDialog(); fd.Filter = "ソフトコレクションファイル (*.txt)|*.txt"; fd.DefaultExt = "txt"; fd.CheckPathExists = true; fd.OverwritePrompt = true; fd.ShowDialog(); if (fd.FileNames.Length > 0) { string filepath = Path.GetFullPath(fd.FileName); Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す PackageCollectionFileData collectionData = new PackageCollectionFileData(); switch (softtargetid) { case 0: // PCにインストール collectionData.loadPackages(pkgListsMan.SystemInstalledPkgList.GetEnumerator()); break; case 1: // AppliStation内にインストール collectionData.loadPackages(pkgListsMan.InstalledPkgList.GetEnumerator()); break; case 2: // すべて default: collectionData.loadPackages(pkgListsMan.GetAllInstalledPackages()); break; } try { collectionData.saveAs(fd.FileName); } catch (UnauthorizedAccessException) { if ((File.GetAttributes(fd.FileName) & FileAttributes.ReadOnly) != 0) { MessageBox.Show("読み取り専用属性が設定されています。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("ファイルへの書き込みが許可されていません。\n別のファイルを指定してください。", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } catch (IOException) { MessageBox.Show("ファイルの書き込みに失敗しました", "エクスポート", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { Directory.SetCurrentDirectory(pwd); // ファイルダイアログで変わったカレントディレクトリを戻す } } void OptionToolStripMenuItemClick(object sender, EventArgs e) { UserPrefForm userPrefForm = new UserPrefForm(); DialogResult result = userPrefForm.ShowDialog(this); if (result == DialogResult.OK) { if (userPrefForm.IsRepositoryListSettingChanged) { updateActionInvoke(true); UpdatePackageList(); } } } #region searchTextBoxまわり void SearchTextBoxKeyPress(object sender, KeyPressEventArgs e) { switch (e.KeyChar) { case (char)Keys.Enter: searchTextBox.FireTextChangedTrigger(); break; case (char)Keys.Escape: searchTextBox.Text = string.Empty; break; } } void SearchTextBoxTextChangedTriggerFired(object sender, EventArgs e) { packageListView.FilteringKeyword = searchTextBox.Text; } #endregion internal void installActionInvoke(Installation[] insts) { AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); prog.Shown += delegate(object sender2, EventArgs e2) { NaGet.SubCommands.NaGetInstall2 tasks = new NaGet.SubCommands.NaGetInstall2(pkgListsMan, insts); prog.SetTaskSet(tasks); prog.Refresh(); prog.StartTaskSet(); }; prog.Text = string.Format("ソフトウェアのインストール"); prog.ShowDialog(this); } void InstallToolStripButtonClick(object sender, EventArgs e) { InstallationConfirmForm confirm = new InstallationConfirmForm(); confirm.PkgListsManager = pkgListsMan; confirm.Installations = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) ); confirm.UseRunas = confirm.GetShouldUseRunas(); DialogResult result = confirm.ShowDialog(this); if (result == DialogResult.OK) { Installation[] insts = confirm.CheckedInstallations; if (confirm.UseRunas) { installRunasActionInvoke(insts); } else { installActionInvoke(insts); } UpdatePackageList(); } } public void installRunasActionInvoke(Installation[] insts) { this.setWindowEnabled(false); string tmpfileName = Path.GetTempFileName(); try { NaGet.Utils.PutSerializeObject(tmpfileName, insts); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo(); procInfo.FileName = Application.ExecutablePath; procInfo.Arguments = string.Format("--noupdate --cmd=install \"--instsref={0}\"", tmpfileName); procInfo.Verb = "runas"; procInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo); hProc.EnableRaisingEvents = true; hProc.SynchronizingObject = this; hProc.Exited += delegate(object sender, EventArgs e) { UpdatePackageList(); this.setWindowEnabled(true); this.BringToFront(); if (File.Exists(tmpfileName)) { File.Delete(tmpfileName); } }; } catch (System.ComponentModel.Win32Exception ex) { MessageBox.Show(ex.Message, "インストール", MessageBoxButtons.OK, MessageBoxIcon.Error); if (File.Exists(tmpfileName)) { File.Delete(tmpfileName); } this.setWindowEnabled(true); } } internal void uninstallActionInvoke(InstalledPackage[] pkgs) { AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); prog.Shown += delegate(object sender2, EventArgs e2) { NaGet.SubCommands.NaGetUninstall2 tasks = new NaGet.SubCommands.NaGetUninstall2(pkgListsMan, pkgs); prog.SetTaskSet(tasks); prog.Refresh(); prog.StartTaskSet(); }; prog.Text = string.Format("ソフトウェアのアンインストール"); prog.ShowDialog(this); } internal void uninstallRunasActionInvoke(InstalledPackage[] pkgs) { this.setWindowEnabled(false); string tmpfileName = Path.GetTempFileName(); try { NaGet.Utils.PutSerializeObject(tmpfileName, pkgs); System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo(); procInfo.FileName = Application.ExecutablePath; procInfo.Arguments = string.Format("--noupdate --cmd=uninstall \"--pkgsref={0}\"", tmpfileName); procInfo.Verb = "runas"; procInfo.WorkingDirectory = Environment.CurrentDirectory; System.Diagnostics.Process hProc = System.Diagnostics.Process.Start(procInfo); hProc.EnableRaisingEvents = true; hProc.SynchronizingObject = this; hProc.Exited += delegate(object sender, EventArgs e) { UpdatePackageList(); this.setWindowEnabled(true); this.BringToFront(); if (File.Exists(tmpfileName)) { File.Delete(tmpfileName); } }; } catch (System.ComponentModel.Win32Exception ex) { MessageBox.Show(ex.Message, "アンインストール", MessageBoxButtons.OK, MessageBoxIcon.Error); this.setWindowEnabled(true); if (File.Exists(tmpfileName)) { File.Delete(tmpfileName); } } } void UninstallToolStripButtonClick(object sender, EventArgs e) { PackageUninstallConfirmForm confirm = new PackageUninstallConfirmForm(); confirm.UninstallPackage = (InstalledPackage) packageListView.SelectedPackage; confirm.UseRunas = confirm.GetShouldUseRunas(); DialogResult result = confirm.ShowDialog(this); if (result == DialogResult.OK) { InstalledPackage[] instPkgs = new InstalledPackage[]{confirm.UninstallPackage}; if (confirm.UseRunas) { uninstallRunasActionInvoke(instPkgs); } else { uninstallActionInvoke(instPkgs); } UpdatePackageList(); } } internal void downloadActionInvoke(Installation[] pkgs) { AppliStation.Util.ExecutionProgressViewer prog = new AppliStation.Util.ExecutionProgressViewer(); prog.Shown += delegate(object sender2, EventArgs e2) { NaGet.SubCommands.NaGetDownloadToCache2 tasks = new NaGet.SubCommands.NaGetDownloadToCache2(pkgListsMan, pkgs); prog.SetTaskSet(tasks); prog.Refresh(); prog.StartTaskSet(); }; prog.Text = string.Format("キャッシュへのダウンロード"); prog.ShowDialog(this); } void DownloadToolStripMenuItemClick(object sender, EventArgs e) { Installation[] insts = Installation.ConvertInstallations( NaGet.Utils.IEnumerable2Array(packageListView.SelectedPackages) ); downloadActionInvoke(insts); UpdatePackageList(); } void WebOfficialMenuItemClick(object sender, EventArgs e) { Package pkg = packageListView.SelectedPackage; if (pkg != null) { string linkURL = pkg.Url.Href; if (! string.IsNullOrEmpty(linkURL)) { try { System.Diagnostics.Process.Start(linkURL); } catch (System.ComponentModel.Win32Exception) { MessageBox.Show(string.Format("{0}を開くのに失敗しました。", linkURL), "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } void WebGoogleSearchMenuItemClick(object sender, EventArgs e) { Package pkg = packageListView.SelectedPackage; if (pkg != null) { string q = System.Web.HttpUtility.UrlEncode(pkg.Name, System.Text.Encoding.UTF8); string googleURL = @"http://www.google.co.jp/search?q="+q; try { System.Diagnostics.Process.Start(googleURL); } catch (System.ComponentModel.Win32Exception) { MessageBox.Show("Googleを開くのに失敗しました。", "ブラウザ起動エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } void OpenInstalledDirectoryStripMenuItemClick(object sender, EventArgs e) { InstalledPackage pkg = (InstalledPackage) packageListView.SelectedPackage; if (pkg != null) { if (pkg.Type == InstallerType.ARCHIVE || pkg.Type == InstallerType.ITSELF) { System.Diagnostics.Process.Start(Path.Combine(NaGet.Env.ArchiveProgramFiles, pkg.Name)); } else if (Directory.Exists(pkg.DiscoverInstalledLocation())) { System.Diagnostics.Process.Start(pkg.DiscoverInstalledLocation()); } } } void PropertiesCommonMenuItemClick(object sender, EventArgs e) { if (packageListView.SelectedItems.Count >= 5) { string msg = string.Format("{0}個のプロパティダイアログを開こうとしています。\n継続しますか?", packageListView.SelectedItems.Count); if (MessageBox.Show(msg, "プロパティ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK) { return; } } foreach (Package pkg in packageListView.SelectedPackages) { PackageInfoForm form = new PackageInfoForm(); form.SelectedObject = pkg; form.Text = string.Format("{0}({1})のプロパティ", pkg.Name, pkg.Version); form.Show(this); } } private void updateLauncherMenuItem(AppliStation.Util.ToolStripPetitLauncherMenuItem launcherMenuItem) { bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1; if (selectionIsOnlyOne) { Package pkg = packageListView.SelectedPackage; InstalledPackage iPkg = pkg as InstalledPackage; // インストール済みパッケージのとき if (iPkg != null) { bool launcherMenuItemVisible = (pkg.Type == InstallerType.ARCHIVE) || (pkg.Type == InstallerType.ITSELF) || Directory.Exists(iPkg.DiscoverInstalledLocation()); launcherMenuItem.Visible = launcherMenuItemVisible; if (launcherMenuItemVisible) { launcherMenuItem.BaseFolderPath = iPkg.DiscoverInstalledLocation(); } } else { launcherMenuItem.Visible = false; } } else { launcherMenuItem.Visible = false; } } void PackageListContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e) { bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1; bool hasSelection = packageListView.SelectedItems.Count > 0; updateSelectedPackages(); // インストール先のフォルダの設定 updateLauncherMenuItem(installedDirectoryToolStripMenuItem); if (packageListView.View == View.Details) { // ヘッダ部がクリックされたとき、パッケージが選択されていないものとして扱って処理をする。 int headerHeight = AppliStation.Util.NativeMethods.ColumnHeader_GetSize(packageListView).Height; if (packageListView.PointToClient(packageListContextMenuStrip.Location).Y < headerHeight) { selectionIsOnlyOne = hasSelection = false; uninstallToolStripMenuItem.Visible = false; installToolStripMenuItem.Visible = false; downloadToolStripMenuItem.Visible = false; installedDirectoryToolStripMenuItem.Visible = false; } } packageListContextMenuStripSeparator.Visible = selectionIsOnlyOne; webResourceToolStripMenuItem.Visible = selectionIsOnlyOne; propertiesToolStripMenuItem.Visible = hasSelection; columnToolStripMenuItem.Visible = (! hasSelection) && (packageListView.View == View.Details); } void InformationToolStripDropDownButtonDropDownOpening(object sender, EventArgs e) { bool selectionIsOnlyOne = packageListView.SelectedItems.Count == 1; bool hasSelection = packageListView.SelectedItems.Count > 0; // インストール先のフォルダの設定 updateLauncherMenuItem(installedDirectoryMenuItem); webResourceMenuItem.Visible = selectionIsOnlyOne; propertiesMenuItem.Visible = hasSelection; } void WebResourceCommonContextMenuStripOpening(object sender, System.ComponentModel.CancelEventArgs e) { Package pkg = packageListView.SelectedPackage; if (pkg != null && pkg.Url != null && !string.IsNullOrEmpty(pkg.Url.Href)) { webOfficialMenuItem.Enabled = true; webOfficialMenuItem.ToolTipText = pkg.Url.Href; } else { webOfficialMenuItem.Enabled = false; webOfficialMenuItem.ToolTipText = null; } // webGoogleSearchMenuItem always active. } void UpgradeToolStripButtonClick(object sender, EventArgs e) { List pkgs = new List( UpgradeFinder.GetUpgradePackages(pkgListsMan) ); if (pkgs.Count <= 0) { MessageBox.Show(this, "更新されたソフトはありません", "ソフトの更新"); return; } InstallationConfirmForm confirm = new InstallationConfirmForm(); confirm.PkgListsManager = pkgListsMan; confirm.Installations = Installation.ConvertInstallations(pkgs.ToArray()); DialogResult result = confirm.ShowDialog(this); if (result == DialogResult.OK) { Installation[] insts = confirm.CheckedInstallations; if (confirm.UseRunas) { installRunasActionInvoke(insts); } else { installActionInvoke(insts); } UpdatePackageList(); } } protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if ((int)keyData == (int)Keys.Control + (int)Keys.E) { searchTextBox.SelectAll(); searchTextBox.Focus(); return true; } return base.ProcessCmdKey(ref msg, keyData); } public void UpdatePackageList() { pkgListsMan.LoadPackageLists(); packageListView.UpdateItems(); updateSelectedPackages(); } /// /// 自ウィンドウの有効無効(Enabled)を(必要あればInvokeして)実行する /// /// 有効か否か。Enabledの値に入れられる private void setWindowEnabled(bool enabled) { MethodInvoker process = (MethodInvoker) delegate() { this.Enabled = enabled; }; if (InvokeRequired) { Invoke(process); } else { process.Invoke(); } } void ColumnCommonToolStripMenuItemClick(object sender, EventArgs e) { packageListView.BeginUpdate(); ColumnHeader sortcolumn = packageListView.SortColumn; // 列の追加と削除 foreach (ToolStripItem item in columnToolStripMenuItem.DropDownItems) { ToolStripMenuItem menu = item as ToolStripMenuItem; if (menu != null) { bool exists = false; // 列が存在しているがチェックが外れていたら削除する。 foreach (ColumnHeader header in packageListView.Columns) { if (header.Tag == menu.Tag) { exists = true; if (sortcolumn == header) { packageListView.SortColumn = sortcolumn = null; } if (menu.Checked == false) { packageListView.Columns.Remove(header); } break; } } // 列が存在していなく、チェックがされているなら追加する。 if (menu.Checked && !exists) { ColumnHeader header = new ColumnHeader(); header.Text = menu.Text; header.Tag = menu.Tag; packageListView.Columns.Add(header); } } } AppliStation.Util.NativeMethods.ColumnHeader_SetSortState(packageListView, (sortcolumn != null)? sortcolumn.Index : -1, SortOrder.None); packageListView.UpdateItems(); packageListView.EndUpdate(); } } }