示例#1
0
        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();
                    }
                }
            }
        }
示例#2
0
文件: Commands.cs 项目: xoriath/RTVS
        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();
                    }
                }
            }
        }
示例#3
0
        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);
        }
示例#4
0
        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();
            }
        }
示例#5
0
        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;
            }
        }
示例#8
0
        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));
        }