public static bool LoadFile(Editor editor, string file, bool updateCursorPosition = true)
        {
            if (string.IsNullOrWhiteSpace(file))
            {
                return(false);
            }
            try
            {
                var parts         = file.Split(new[] { '|' }, 2);
                var filename      = parts[0] ?? "";
                var offset        = ConvertToOffset(parts.Length == 2 ? parts[1] : "0");
                var pathExtension = Path.GetExtension(filename);

                var isWordDoc = pathExtension.Equals(".docx", StringComparison.OrdinalIgnoreCase);

                if (isWordDoc)
                {
                    NewFile(editor);
                    editor.EditBox.Text     = Markdown.FromMicrosoftWord(filename);
                    editor.EditBox.Encoding = Encoding.UTF8;
                    return(true);
                }

                var isHtmlFile = pathExtension.Equals(".html", StringComparison.OrdinalIgnoreCase) ||
                                 pathExtension.Equals(".htm", StringComparison.OrdinalIgnoreCase);

                if (isHtmlFile)
                {
                    NewFile(editor);
                    editor.EditBox.Text     = Markdown.FromHtml(filename);
                    editor.EditBox.Encoding = Encoding.UTF8;
                    return(true);
                }

                var editorEncoding = App.UserSettings.EditorEncoding;

                var encoding = MyEncodingInfo.IsAutoDetectEncoding(editorEncoding)
                    ? MyEncodingInfo.DetectEncoding(filename)
                    : Encoding.GetEncoding(editorEncoding.CodePage);

                editor.EditBox.Text     = File.ReadAllText(filename, encoding);
                editor.EditBox.Encoding = encoding;

                if (updateCursorPosition)
                {
                    if (App.UserSettings.EditorOpenLastCursorPosition)
                    {
                        editor.EditBox.ScrollToLine(editor.EditBox.Document.GetLineByOffset(offset)?.LineNumber ?? 0);
                        editor.EditBox.SelectionStart = offset;
                    }
                    else
                    {
                        editor.EditBox.ScrollToHome();
                    }
                }

                Settings.Default.LastOpenFile = file;
                RecentFilesDialog.UpdateRecentFiles(filename, offset);
                editor.IsModified = false;
                editor.FileName   = filename;
                return(true);
            }
            catch (Exception ex)
            {
                Notify.Alert($"{ex.Message} {file}");
                return(false);
            }
        }
Exemple #2
0
 public static bool ErrorBeep()
 {
     Notify.Beep();
     return false;
 }