private static void BrowseFolderExecute(Window window, ExecutedRoutedEventArgs e) { var tb = (TextBox)e.OriginalSource; if (!tb.AcceptsReturn) { var path = e.Parameter as string ?? tb.GetValue(TextBox.TextProperty) as string; while (!string.IsNullOrEmpty(path) && !Directory.Exists(path)) { try { path = Path.GetDirectoryName(path); } catch (ArgumentException) { path = null; // path was in incorrect format, continue with default (current) directory } } path = Dialogs.BrowseForDirectory( window == null ? IntPtr.Zero : new WindowInteropHelper(window).Handle, path ); if (path != null) { tb.SetCurrentValue(TextBox.TextProperty, path); var binding = BindingOperations.GetBindingExpressionBase(tb, TextBox.TextProperty); if (binding != null) { binding.UpdateSource(); } } } else { var existing = tb.GetValue(TextBox.TextProperty) as string; var path = e.Parameter as string; while (!string.IsNullOrEmpty(path) && !Directory.Exists(path)) { path = Path.GetDirectoryName(path); } path = Dialogs.BrowseForDirectory( window == null ? IntPtr.Zero : new WindowInteropHelper(window).Handle, path ); if (path != null) { if (string.IsNullOrEmpty(existing)) { tb.SetCurrentValue(TextBox.TextProperty, path); } else { tb.SetCurrentValue(TextBox.TextProperty, existing.TrimEnd(new[] { '\r', '\n' }) + Environment.NewLine + path); } var binding = BindingOperations.GetBindingExpressionBase(tb, TextBox.TextProperty); if (binding != null) { binding.UpdateSource(); } } } }
private static void BrowseFolderExecute(Window window, ExecutedRoutedEventArgs e) { var tb = (TextBox)e.OriginalSource; if (!tb.AcceptsReturn) { var path = e.Parameter as string ?? tb.GetValue(TextBox.TextProperty) as string; while (!string.IsNullOrEmpty(path) && !Directory.Exists(path)) { path = Path.GetDirectoryName(path); } path = Dialogs.BrowseForDirectory( window == null ? IntPtr.Zero : new WindowInteropHelper(window).Handle, path ); if (path != null) { tb.SetCurrentValue(TextBox.TextProperty, path); var binding = BindingOperations.GetBindingExpressionBase(tb, TextBox.TextProperty); if (binding != null) { binding.UpdateSource(); } } } else { var existing = tb.GetValue(TextBox.TextProperty) as string; var path = e.Parameter as string; while (!string.IsNullOrEmpty(path) && !Directory.Exists(path)) { path = Path.GetDirectoryName(path); } path = Dialogs.BrowseForDirectory( window == null ? IntPtr.Zero : new WindowInteropHelper(window).Handle, path ); if (path != null) { if (string.IsNullOrEmpty(existing)) { tb.SetCurrentValue(TextBox.TextProperty, path); } else { tb.SetCurrentValue(TextBox.TextProperty, existing.TrimEnd(CharExtensions.LineBreakChars) + Environment.NewLine + path); } var binding = BindingOperations.GetBindingExpressionBase(tb, TextBox.TextProperty); if (binding != null) { binding.UpdateSource(); } } } }
internal void SelectDirectory() { IVsUIShell uiShell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell)); IntPtr dialogOwner; uiShell.GetDialogOwnerHwnd(out dialogOwner); string currentDirectory = RToolsSettings.Current.WorkingDirectory; string newDirectory = Dialogs.BrowseForDirectory(dialogOwner, currentDirectory, Resources.ChooseDirectory); SetDirectory(newDirectory); }
protected override void Handle() { var ps = _workflow.Shell.GetService <IPlatformServices>(); var settings = _workflow.Shell.GetService <IRSettings>(); var currentDirectory = settings.WorkingDirectory; var newDirectory = Dialogs.BrowseForDirectory(ps.ApplicationWindowHandle, currentDirectory, Resources.ChooseDirectory); if (!string.IsNullOrEmpty(newDirectory)) { _workflow.RSession.SetWorkingDirectoryAsync(newDirectory) .SilenceException <RException>() .DoNotWait(); } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { string latestRPath = Environment.SystemDirectory; try { latestRPath = new RInstallation().GetCompatibleEnginePathFromRegistry(); if (string.IsNullOrEmpty(latestRPath) || !Directory.Exists(latestRPath)) { // Force 64-bit PF latestRPath = Environment.GetEnvironmentVariable("ProgramFiles"); } } catch (ArgumentException) { } catch (IOException) { } return(Dialogs.BrowseForDirectory(VsAppShell.Current.GetDialogOwnerWindow(), latestRPath, Resources.ChooseRInstallFolder)); }
protected override void Handle() { IVsUIShell uiShell = VsAppShell.Current.GetGlobalService<IVsUIShell>(typeof(SVsUIShell)); IntPtr dialogOwner; uiShell.GetDialogOwnerHwnd(out dialogOwner); var currentDirectory = RToolsSettings.Current.WorkingDirectory; var newDirectory = Dialogs.BrowseForDirectory(dialogOwner, currentDirectory, Resources.ChooseDirectory); if (!string.IsNullOrEmpty(newDirectory)) { _workflow.RSession.SetWorkingDirectoryAsync(newDirectory) .SilenceException<RException>() .SilenceException<MessageTransportException>() .DoNotWait(); } }
private void ChangeLocation_Executed(object sender, ExecutedRoutedEventArgs e) { var view = ((AddVirtualEnvironmentControl)sender).View; Window window = null; var path = Dialogs.BrowseForDirectory( window == null ? IntPtr.Zero : new WindowInteropHelper(window).Handle, view.LocationPath ); if (path != null) { view.LocationPath = path; } }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IVsUIShell uiShell = VsAppShell.Current.GetGlobalService <IVsUIShell>(typeof(SVsUIShell)); IntPtr dialogOwner; uiShell.GetDialogOwnerHwnd(out dialogOwner); string latestRPath = Environment.SystemDirectory; try { latestRPath = RInstallation.GetCompatibleEnginePathFromRegistry(); if (string.IsNullOrEmpty(latestRPath) || !Directory.Exists(latestRPath)) { // Force 64-bit PF latestRPath = Environment.GetEnvironmentVariable("ProgramFiles"); } } catch (ArgumentException) { } catch (IOException) { } return(Dialogs.BrowseForDirectory(dialogOwner, latestRPath, Resources.ChooseRInstallFolder)); }