protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }
public override int GetHashCode() { unchecked { int result = Title.GetHashCode(); result = (result * 397) ^ Command.GetHashCode(); result = (result * 397) ^ Arguments.GetHashCode(); result = (result * 397) ^ InitialDirectory.GetHashCode(); result = (result * 397) ^ OutputToImmediateWindow.GetHashCode(); result = (result * 397) ^ ReportTitle.GetHashCode(); result = (result * 397) ^ ArgsCollectorDllPath.GetHashCode(); result = (result * 397) ^ ArgsCollectorClassName.GetHashCode(); result = (result * 397) ^ ToolDirPath.GetHashCode(); result = (result * 397) ^ (PackageVersion == null ? 0 : PackageVersion.GetHashCode()); result = (result * 397) ^ (PackageIdentifier == null ? 0 : PackageIdentifier.GetHashCode()); result = (result * 397) ^ (PackageName == null ? 0 : PackageName.GetHashCode()); return(result); } }
private int FolderBrowserCallback(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData) { if (uMsg == BFFM_INITIALIZED && !String.IsNullOrEmpty(InitialDirectory)) { // We get in here when the dialog is first displayed. If an initial directory // has been specified we will make this the selection now, and also make sure // that directory is expanded. HandleRef h = new HandleRef(null, hwnd); if (InitialDirectory.Length > 1 && InitialDirectory.StartsWith(":") && InitialDirectory[1] != ':') { int pidli = int.Parse(InitialDirectory.Substring(1)); SendMessage(h, BFFM_SETSELECTIONW, 0, (IntPtr)pidli); SendMessage(h, BFFM_SETEXPANDED, 0, (IntPtr)pidli); } else { SendMessage(h, BFFM_SETSELECTIONW, 1, InitialDirectory); SendMessage(h, BFFM_SETEXPANDED, 1, InitialDirectory); } } else if (uMsg == BFFM_SELCHANGED) { // We get in here whenever the selection in the dialog box changes. To cope with the bug in Win7 // (and above?) whereby the SHBrowseForFolder dialog won't always scroll the selection into view (see // http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/a22b664e-cb30-44f4-bf77-b7a385de49f3/) // we follow the suggestion here: // http://www.codeproject.com/Questions/179097/SHBrowseForFolder-and-SHGetPathFromIDList // to adjust the scroll position when the selection changes. IntPtr hbrowse = FindWindowEx(hwnd, IntPtr.Zero, "SHBrowseForFolder ShellNameSpace Control", null); IntPtr htree = FindWindowEx(hbrowse, IntPtr.Zero, "SysTreeView32", null); IntPtr htir = SendMessage(new HandleRef(null, htree), TVM_GETNEXTITEM, TVGN_ROOT, IntPtr.Zero); IntPtr htis = SendMessage(new HandleRef(null, htree), TVM_GETNEXTITEM, TVGN_CARET, IntPtr.Zero); IntPtr htic = SendMessage(new HandleRef(null, htree), TVM_GETNEXTITEM, TVGN_CHILD, htir); int count = 0; int pos = 0; for (; (int)htic != 0; htic = SendMessage(new HandleRef(null, htree), TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, htic), count++) { if (htis == htic) { pos = count; } } SCROLLINFO si = new SCROLLINFO(); si.cbSize = (uint)Marshal.SizeOf(si); si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; GetScrollInfo(htree, SB_VERT, ref si); si.nPage /= 2; if ((pos > (int)(si.nMin + si.nPage)) && (pos <= (int)(si.nMax - si.nMin - si.nPage))) { si.nMax = si.nPos - si.nMin + (int)si.nPage; for (; pos < si.nMax; pos++) { PostMessage(htree, WM_VSCROLL, SB_LINEUP, 0); } for (; pos > si.nMax; pos--) { PostMessage(htree, WM_VSCROLL, SB_LINEDOWN, 0); } } } return(0); }
private void SetScreen() { try { switch (browserType) { case FolderBrowserType.SelectFile: case FolderBrowserType.SelectMultiFile: Text = "ファイルの選択"; trvFolderList.LabelEdit = false; btnCreate.Visible = false; btnDelete.Visible = false; btnOK.Text = "OK"; lblFileName.Visible = true; txtFileName.Visible = true; txtFileName.ReadOnly = true; txtFileName.BackColor = SystemColors.Control; break; case FolderBrowserType.SaveFile: Text = "ファイルの保存"; trvFolderList.LabelEdit = false; btnCreate.Visible = false; btnDelete.Visible = false; btnOK.Text = "保存"; lblFileName.Visible = true; txtFileName.Visible = true; txtFileName.ReadOnly = false; txtFileName.Text = FileName; break; case FolderBrowserType.SelectFolder: case FolderBrowserType.SelectClientFolder: Text = "フォルダの選択"; trvFolderList.LabelEdit = false; btnCreate.Visible = false; btnDelete.Visible = false; btnOK.Text = "OK"; lblFileName.Visible = false; txtFileName.Visible = false; break; case FolderBrowserType.SelectAndEditFolder: Text = "フォルダの選択"; trvFolderList.LabelEdit = true; btnCreate.Visible = true; btnDelete.Visible = true; btnOK.Text = "OK"; lblFileName.Visible = false; txtFileName.Visible = false; break; } txtPath.ReadOnly = true; trvFolderList.ImageList = imlTreeView; lsvFileList.SmallImageList = imlListView; lsvFileList.MultiSelect = browserType == FolderBrowserType.SelectMultiFile; // アプリケーション・アイコンを取得 SHFILEINFO shinfo = new SHFILEINFO(); IntPtr hFolder = SHGetFileInfo(@"C:\WINDOWS", 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_SMALLICON | SHGFI_ICON); if (hFolder != IntPtr.Zero) { imlTreeView.Images.Add("F_Close", Icon.FromHandle(shinfo.hIcon)); trvFolderList.ImageKey = "F_Close"; DestroyIcon(shinfo.hIcon); } IntPtr hFolderOpen = SHGetFileInfo(@"C:\WINDOWS", 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), SHGFI_OPENICON | SHGFI_SMALLICON | SHGFI_ICON); if (hFolderOpen != IntPtr.Zero) { imlTreeView.Images.Add("F_Open", Icon.FromHandle(shinfo.hIcon)); trvFolderList.ImageKey = "F_Open"; DestroyIcon(shinfo.hIcon); } TreeNode rootNode; if (browserType == FolderBrowserType.SelectClientFolder) { if (SystemInformation.TerminalServerSession) { rootNode = Directory.Exists(InitialDirectory) ? new TreeNode(Directory.GetDirectoryRoot(InitialDirectory)) : new TreeNode(DefaultClient + @"\C"); trvFolderList.Nodes.Add(rootNode); rootNode.Nodes.Add("dummy"); } else { foreach (var drive in Environment.GetLogicalDrives()) { var treeNode = new TreeNode(drive); trvFolderList.Nodes.Add(treeNode); treeNode.Nodes.Add("dummy"); } rootNode = trvFolderList.Nodes[0]; } } else { var rootPath = RootPath; if (rootPath.EndsWith(@"\") && rootPath.Length > 3) { rootPath = rootPath.Substring(0, rootPath.Length - 1); } rootNode = new TreeNode(rootPath); trvFolderList.Nodes.Add(rootNode); rootNode.Nodes.Add("dummy"); } if (rootNode != null) { trvFolderList.SelectedNode = rootNode; rootNode.Expand(); } var isInValidDir = InitialDirectory == null || !Directory.Exists(InitialDirectory) || !InitialDirectory.ToUpper().Contains(rootNode.FullPath.ToUpper()); InitialDirectory = isInValidDir ? string.Empty : InitialDirectory.Replace(rootNode.FullPath, string.Empty); if (!string.IsNullOrEmpty(InitialDirectory)) { string[] dirs = InitialDirectory.Split('\\'); for (int i = 0; i < dirs.Length; i++) { foreach (TreeNode node in trvFolderList.SelectedNode.Nodes) { if (node.Text == dirs[i]) { trvFolderList.SelectedNode = node; node.Expand(); break; } } } } } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); } }
protected override void Execute(CodeActivityContext context) { var isSaveAs = IsSaveAs.Get(context); var initialDirectory = InitialDirectory.Get(context); var title = Title.Get(context); var defaultExt = DefaultExt.Get(context); var filter = Filter.Get(context); var filterIndex = FilterIndex.Get(context); var checkFileExists = CheckFileExists.Get(context); var checkPathExists = CheckPathExists.Get(context); var multiselect = Multiselect.Get(context); System.Windows.Forms.FileDialog dialog; if (isSaveAs) { dialog = new System.Windows.Forms.SaveFileDialog(); } else { dialog = new System.Windows.Forms.OpenFileDialog(); ((System.Windows.Forms.OpenFileDialog)dialog).Multiselect = multiselect; } if (!string.IsNullOrEmpty(title)) { dialog.Title = title; } if (!string.IsNullOrEmpty(defaultExt)) { dialog.DefaultExt = defaultExt; } if (!string.IsNullOrEmpty(filter)) { dialog.Filter = filter; dialog.FilterIndex = filterIndex; } try { if (!string.IsNullOrEmpty(initialDirectory) && !initialDirectory.Contains("\\")) { Enum.TryParse(initialDirectory, out Environment.SpecialFolder specialfolder); initialDirectory = Environment.GetFolderPath(specialfolder); } } catch (Exception) { throw; } if (!string.IsNullOrEmpty(initialDirectory)) { dialog.InitialDirectory = initialDirectory; } dialog.CheckFileExists = checkFileExists; dialog.CheckPathExists = checkPathExists; System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.Cancel; GenericTools.RunUI(() => { result = dialog.ShowDialog(); }); if (result != System.Windows.Forms.DialogResult.OK) { context.SetValue(FileName, null); context.SetValue(FileNames, null); return; } context.SetValue(FileName, dialog.FileName); context.SetValue(FileNames, dialog.FileNames); }