Ejemplo n.º 1
0
        public bool NewDocument()
        {
            try
            {
                _mainForm.Refresh();
                _mainForm.Cursor = Cursors.WaitCursor;

                DocumentType documentType = _applicationManager.NewDocumentType;

                SqlEditForm ef = new SqlEditForm();
                ef.Text                  = _documentManager.GetNextUntitledFileName(documentType);
                ef.FileName              = ef.Text;
                ef.FilePath              = null;
                ef.FileEncoding          = _documentManager.GetDocumentEncoding(documentType);
                ef.LineEnding            = ScintillaNet.EndOfLineMode.Crlf;
                ef.Editor.EndOfLine.Mode = ef.LineEnding;
                ef.LoadSettings(documentType);
                ef.FileTimeStamp = DateTime.Now;
                ef.Show(_mainForm.ClientWindow, DockState.Document);
            }
            finally
            {
                _mainForm.Cursor = Cursors.Default;
            }

            return(true);
        }
Ejemplo n.º 2
0
        public IDockContent OpenDocument(string path, bool readOnly)
        {
            /*
             * Activate the file if already in an editor.
             */

            foreach (Document d in _mainForm.ClientWindow.Documents)
            {
                if (d.FilePath != null &&
                    FileTools.MatchPaths(d.FilePath, path) &&
                    !d.AllowDuplicates())
                {
                    d.Activate();
                    return(null);
                }
            }

            /*
             * Create a new editor and load the file.
             */

            try
            {
                _mainForm.Refresh();
                _mainForm.Cursor = Cursors.WaitCursor;

                string   fileText = null;
                Encoding encoding;

                try
                {
                    fileText = FileTools.ReadFile(path, out encoding);
                    if (fileText == null)
                    {
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    _mainForm.Cursor = Cursors.Default;

                    MessageBox.Show(String.Format("{0}\r\n{1}",
                                                  Resources.OpenErrorMessage,
                                                  ex.Message),
                                    Resources.OpenErrorTitle,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    return(null);
                }

                /*
                 * Populate the form.
                 */

                SqlEditForm ef = new SqlEditForm();
                FileInfo    fi = new FileInfo(path);
                ef.Text                  = fi.Name;
                ef.FileName              = fi.Name;
                ef.FilePath              = fi.FullName;
                ef.FileEncoding          = encoding;
                ef.LineEnding            = _documentManager.DetectLineEnding(fileText);
                ef.Editor.EndOfLine.Mode = ef.LineEnding;
                ef.Editor.Text           = fileText;
                ef.Editor.Modified       = false;
                ef.Editor.UndoRedo.EmptyUndoBuffer();
                ef.Editor.IsReadOnly = readOnly;
                ef.LoadSettings(new DocumentType(fi.Extension));
                ef.FileTimeStamp = DateTime.Now;

                ef.UpdateTab();

                return(ef);
            }
            finally
            {
                _mainForm.Cursor = Cursors.Default;
            }
        }