Exemple #1
0
        public async void OpenInVisualStudio(string filename, int line)
        {
            if (!File.Exists(filename))
            {
                if (TaskDialogHelper.ShowTaskDialog(
                        Handle,
                        "File Not Exists",
                        "File not found. Would you like to locate file by sourself?",
                        "Filename: " + filename,
                        TaskDialogStandardIcon.Error,
                        new string[] { "Browse", "Cancel" },
                        null,
                        new TaskDialogResult[] { TaskDialogResult.Yes, TaskDialogResult.No, }
                        ) != TaskDialogResult.Yes)
                {
                    return;
                }

                string file = PathUtils.GetFilename(filename);
                odSourceFile.Filter   = file + "|" + file;
                odSourceFile.FileName = file;
                if (odSourceFile.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                filename = odSourceFile.FileName;
            }
            string vs = Configs.Instance.GetRecentProperty(mapping.Mapping.Filename, Configs.PROPERTY_EDITOR);

            if (vs == null)
            {
                vs = Configs.Instance.Editor;
            }
            IVisualStudioInfo visualStudio = VisualStudioDetector.GetVisualStudioInfo(vs);

            BeginLoading("Starting the Visual Studio...");
            try
            {
                await Task.Run(() => visualStudio.OpenFile(filename, line));
            }
            catch (Exception ex)
            {
                this.SetTaskbarProgressValue(100, 100);
                this.SetTaskbarProgressState(Taskbar.ThumbnailProgressState.Error);
                TaskDialogHelper.ShowMessageBox(
                    Handle,
                    "Failed to Open in Visual Studio",
                    "Failed to open in Visual Studio. Try to use another version of Visual Studio.",
                    filename + ":" + line + "\n" + ex.Message,
                    TaskDialogStandardIcon.Error
                    );
            }
            EndLoading("");
        }
        /// <summary>
        /// Gets the Visual Studio with highest version available.
        /// </summary>
        /// <returns>Visual Studio info. If no Visual Studio installed, the Noteped info will be returned.</returns>
        /// <remarks>If this call is first, the <see cref="GetVisualStudios"/> will be invoked to obtain list.</remarks>
        public static IVisualStudioInfo GetHighestVisualStudio()
        {
            if (visualStudioCache == null)
            {
                visualStudioCache = new List <IVisualStudioInfo>(DetectVisualStudios());
            }

            IVisualStudioInfo result = null;

            foreach (IVisualStudioInfo info in visualStudioCache)
            {
                if (result == null || info.Version > result.Version)
                {
                    result = info;
                }
            }

            return(result);
        }
        /// <summary>
        /// Detects all existing Visual Studio installations.
        /// No caching provided, every call will invoke new detection procedure.
        /// </summary>
        /// <returns>Visual Studio informations enumeration</returns>
        public static IEnumerable <IVisualStudioInfo> DetectVisualStudios()
        {
            yield return(new NotepadInfo());

            IVisualStudioInfo vsCodeInfo = VsCodeInfo.Probe();

            if (vsCodeInfo != null)
            {
                yield return(vsCodeInfo);
            }

            foreach (IVisualStudioInfo info in DetectOldVisualStudios())
            {
                yield return(info);
            }

            foreach (IVisualStudioInfo info in DetectNewVisualStudios())
            {
                yield return(info);
            }
        }
        public SettingsForm(Mapping mapping, ICommandManager commandManager)
        {
            this.mapping = mapping;
            InitializeComponent();

            string vs = null;

            if (mapping != null)
            {
                vs = Configs.Instance.GetRecentProperty(mapping.Filename, Configs.PROPERTY_EDITOR);
            }
            else
            {
                cbApplyVsToProject.Checked = cbApplyVsToProject.Enabled = false;
            }

            if (vs == null)
            {
                vs = Configs.Instance.Editor;
            }
            IVisualStudioInfo selected = VisualStudioDetector.GetVisualStudioInfo(vs);

            if (selected == null)
            {
                selected = VisualStudioDetector.GetHighestVisualStudio();
            }

            foreach (IVisualStudioInfo info in VisualStudioDetector.GetVisualStudios())
            {
                BrokenListItem item = new BrokenListItem(info.Description);
                try
                {
                    Icon icon = Icon.ExtractAssociatedIcon(info.Path);
                    imageList.Images.Add(icon);
                    item.ImageIndex = imageList.Images.Count - 1;
                }
                catch { }
                item.Tag = info;

                blvEditors.Items.Add(item);

                if (info == selected)
                {
                    item.Selected = true;
                }
            }

            cbShowUnicode.Checked         = Configs.Instance.ShowUnicode;
            cbSimplifySystemNames.Checked = Configs.Instance.SimplifySystemNames;
            cbSimplifyNullable.Checked    = Configs.Instance.SimplifyNullable;
            cbSimplifyRef.Checked         = Configs.Instance.SimplifyRef;
            cbGroupByNamespaces.Checked   = Configs.Instance.GroupNamespaces;
            cbGroupByModules.Checked      = Configs.Instance.GroupModules;
            cbUseColumns.Checked          = Configs.Instance.UseColumns;
            cbWatchClipboard.Checked      = Configs.Instance.WatchClipboard;

            EnumHelper.FillCombobox(cbDoubleClick, Configs.Instance.DoubleClickAction);
            EnumHelper.FillCombobox(cbUpdateInterval, Configs.Instance.UpdateHelper.Interval);

            commandSelector.CommandManager = commandManager;
            commandSelector.CommandType    = typeof(Actions);
        }