Пример #1
0
        private async void OpenFindSourceFileDialog(object sender, EventArgs e)
        {
            var sf = DebuggingService.CurrentFrame;

            if (sf == null)
            {
                LoggingService.LogWarning($"CurrentFrame was null in {nameof (OpenFindSourceFileDialog)}");
                return;
            }
            var dlg = new Ide.Gui.Dialogs.OpenFileDialog(GettextCatalog.GetString("File to Open") + " " + sf.SourceLocation.FileName, FileChooserAction.Open)
            {
                TransientFor         = IdeApp.Workbench.RootWindow,
                ShowEncodingSelector = true,
                ShowViewerSelector   = true
            };

            dlg.DirectoryChangedHandler = (s, path) => {
                return(SourceCodeLookup.TryDebugSourceFolders(sf.SourceLocation.FileName, sf.SourceLocation.FileHash, new string [] { path }));
            };
            if (!dlg.Run())
            {
                return;
            }
            var newFilePath = dlg.SelectedFile;

            try {
                if (File.Exists(newFilePath))
                {
                    var ignoreButton = new AlertButton(GettextCatalog.GetString("Ignore"));
                    if (SourceCodeLookup.CheckFileHash(newFilePath, sf.SourceLocation.FileHash) ||
                        MessageService.AskQuestion(GettextCatalog.GetString("File checksum doesn't match."), 1, ignoreButton, new AlertButton(GettextCatalog.GetString("Cancel"))) == ignoreButton)
                    {
                        SourceCodeLookup.AddLoadedFile(newFilePath, sf.SourceLocation.FileName);
                        sf.UpdateSourceFile(newFilePath);

                        var doc = await IdeApp.Workbench.OpenDocument(newFilePath, null, sf.SourceLocation.Line, 1, OpenDocumentOptions.Debugger);

                        if (doc != null)
                        {
                            await Document.Close(false);
                        }
                    }
                }
                else
                {
                    MessageService.ShowWarning(GettextCatalog.GetString("File not found."));
                }
            } catch (Exception) {
                MessageService.ShowWarning(GettextCatalog.GetString("Error opening file."));
            }
        }
Пример #2
0
        void ShowLoadSourceFile(StackFrame sf)
        {
            if (messageOverlayContent != null)
            {
                editor.RemoveOverlay(messageOverlayContent);
                messageOverlayContent = null;
            }
            messageOverlayContent = new HBox();

            var hbox = new HBox();

            hbox.Spacing = 8;
            var label = new Label(GettextCatalog.GetString("{0} not found. Find source file at alternative location.", Path.GetFileName(sf.SourceLocation.FileName)));

            hbox.TooltipText = sf.SourceLocation.FileName;

            var color = SyntaxHighlightingService.GetColor(editor.Options.GetEditorTheme(), EditorThemeColors.NotificationText);

            label.ModifyFg(StateType.Normal, color);

            int w, h;

            label.Layout.GetPixelSize(out w, out h);

            hbox.PackStart(label, true, true, 0);
            var openButton = new Button(Gtk.Stock.Open);

            openButton.WidthRequest = 60;
            hbox.PackEnd(openButton, false, false, 0);

            const int containerPadding = 8;

            messageOverlayContent.PackStart(hbox, true, true, containerPadding);
            editor.AddOverlay(messageOverlayContent, () => openButton.SizeRequest().Width + w + hbox.Spacing * 5 + containerPadding * 2);

            openButton.Clicked += delegate {
                var dlg = new OpenFileDialog(GettextCatalog.GetString("File to Open"), MonoDevelop.Components.FileChooserAction.Open)
                {
                    TransientFor         = IdeApp.Workbench.RootWindow,
                    ShowEncodingSelector = true,
                    ShowViewerSelector   = true
                };
                if (!dlg.Run())
                {
                    return;
                }
                var newFilePath = dlg.SelectedFile;
                try {
                    if (File.Exists(newFilePath))
                    {
                        if (SourceCodeLookup.CheckFileMd5(newFilePath, sf.SourceLocation.FileHash))
                        {
                            SourceCodeLookup.AddLoadedFile(newFilePath, sf.SourceLocation.FileName);
                            sf.UpdateSourceFile(newFilePath);
                            if (IdeApp.Workbench.OpenDocument(newFilePath, null, sf.SourceLocation.Line, 1, OpenDocumentOptions.Debugger) != null)
                            {
                                this.WorkbenchWindow.CloseWindow(false);
                            }
                        }
                        else
                        {
                            MessageService.ShowWarning(GettextCatalog.GetString("File checksum doesn't match."));
                        }
                    }
                    else
                    {
                        MessageService.ShowWarning(GettextCatalog.GetString("File not found."));
                    }
                } catch (Exception) {
                    MessageService.ShowWarning(GettextCatalog.GetString("Error opening file."));
                }
            };
        }