Пример #1
0
        public void LoadFile(string path)
        {
            string qualifier = null;
            string qualifier2 = null;

            int colon = path.IndexOf(':', Path.IsPathRooted(path) ? 2 : 0);
            if (colon >= 0)
            {
                qualifier = path.Substring(colon + 1);
                path = path.Substring(0, colon);
            }
            if (qualifier != null)
            {
                colon = qualifier.IndexOf(':');
                if (colon >= 0)
                {
                    qualifier2 = qualifier.Substring(colon + 1);
                    qualifier = qualifier.Substring(0, colon);
                }
            }

            ITextStorageFactory factory = null;
            if (!String.IsNullOrEmpty(qualifier2))
            {
                try
                {
                    effectiveBackingStore = (BackingStore)Enum.Parse(typeof(BackingStore), qualifier2);
                }
                catch (ArgumentException)
                {
                    throw new Exception(String.Format("Buffer qualifier '{0}' is not recognized - should be one of '{1}' or '{2}'", qualifier, BackingStore.String, BackingStore.Utf8SplayGapBuffer));
                }
                factory = GetBackingStore(effectiveBackingStore);
            }
            else if (this.textEditControl.TextStorageFactory == null)
            {
                factory = GetBackingStore(MainClass.Config.BackingStore);
            }
            if (factory != null)
            {
                this.textEditControl.Reload(factory, factory.New());
            }

            if (String.IsNullOrEmpty(qualifier))
            {
                EncodingInfo encodingInfo = GuessEncoding(path);
                Type[] permittedEncodings = null;
                if (this.textEditControl.TextStorageFactory != null)
                {
                    permittedEncodings = this.textEditControl.TextStorageFactory.PermittedEncodings;
                }
                if (permittedEncodings != null)
                {
                    if (Array.FindIndex(permittedEncodings, delegate (Type candidate) { return candidate.IsInstanceOfType(encodingInfo.Encoding); }) < 0)
                    {
                        MessageBox.Show("Specified encoding is not permitted by specified backing store. Falling back to 'String' backing store.", "Text Editor", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        TextEditorWindow replacementWindow = new TextEditorWindow(false/*createBackingStore*/);
                        ITextStorageFactory stringStorageFactory = replacementWindow.GetBackingStore(BackingStore.String);
                        replacementWindow.textEditControl.Reload(stringStorageFactory, stringStorageFactory.New());
                        replacementWindow.LoadFile(path, encodingInfo);
                        replacementWindow.Show();
                        throw new ApplicationException(); // cancel the old window
                    }
                }
                LoadFile(path, encodingInfo);
            }
            else
            {
                switch (qualifier.ToLower())
                {
                    default:
                        throw new Exception(String.Format("Encoding qualifier '{0}' is not recognized - should be one of 'ansi', 'utf8', 'utf16', or 'utf16be'", qualifier));
                    case "ansi":
                        LoadFile(path, new EncodingInfo(Encoding_ANSI, 0));
                        break;
                    case "utf8":
                        LoadFile(path, new EncodingInfo(Encoding_UTF8, 0));
                        break;
                    case "utf16":
                        LoadFile(path, new EncodingInfo(Encoding_UTF16, 0));
                        break;
                    case "utf16be":
                        LoadFile(path, new EncodingInfo(Encoding_UTF16BigEndian, 0));
                        break;
                }
            }
        }
Пример #2
0
        private static void Main(string[] args)
        {
            #if WINDOWS
            #else
            Debug.Listeners.Add(new MonoTraceListener());
            #endif

            LoadSettings();

            #region Debugger Attach Helper
            {
                bool waitDebugger = false;
                if ((args.Length > 0) && String.Equals(args[0], "-waitdebugger"))
                {
                    waitDebugger = true;
                    Array.Copy(args, 1, args, 0, args.Length - 1);
                    Array.Resize(ref args, args.Length - 1);
                }

                bool debuggerBreak = false;
                if ((args.Length > 0) && String.Equals(args[0], "-break"))
                {
                    debuggerBreak = true;
                    Array.Copy(args, 1, args, 0, args.Length - 1);
                    Array.Resize(ref args, args.Length - 1);
                }

                if (waitDebugger)
                {
                    while (!Debugger.IsAttached)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
                if (debuggerBreak)
                {
                    Debugger.Break();
                }
            }
            #endregion

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (args.Length != 0)
            {
                foreach (string arg in args)
                {
                    try
                    {
                        TextEditorWindow window = new TextEditorWindow(arg);
                        window.Show();
                    }
                    catch (ApplicationException)
                    {
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                defaultEmptyForm = new TextEditorWindow();
                defaultEmptyForm.Show();
            }

            Application.Idle += new EventHandler(Application_Idle);
            Application.Run();
        }
Пример #3
0
 public static TextEditorWindow GetWindowForLoadHelper()
 {
     TextEditorWindow window;
     if ((MainClass.defaultEmptyForm != null)
         && !MainClass.defaultEmptyForm.textEditControl.Modified
         && MainClass.defaultEmptyForm.textEditControl.Count == 1
         && MainClass.defaultEmptyForm.textEditControl.GetLine(0).Length == 0)
     {
         window = MainClass.defaultEmptyForm;
         MainClass.defaultEmptyForm = null;
         window.Hide();
     }
     else
     {
         window = new TextEditorWindow();
     }
     return window;
 }