예제 #1
0
        public virtual VFileInfo GetFileInfo(IServiceContainer services, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }
            VFileInfo info = new VFileInfo();

            try
            {
                if (fileName.IndexOf(":") < 0)
                {
                    fileName    = System.IO.Path.Combine(System.Environment.CurrentDirectory, fileName);
                    info        = new VFileInfo(new System.IO.FileInfo(fileName));
                    info.Format = WriterUtils.GetFormat(fileName).ToString();
                }
                else
                {
                    Uri uri = new Uri(fileName);
                    if (uri.Scheme == Uri.UriSchemeFile)
                    {
                        info        = new VFileInfo(new System.IO.FileInfo(uri.LocalPath));
                        info.Format = WriterUtils.GetFormat(uri.LocalPath).ToString();
                    }
                    else
                    {
                        info.Exists   = true;
                        info.Format   = FileFormat.XML.ToString();
                        info.Name     = fileName;
                        info.FullPath = fileName;
                        info.BasePath = WriterUtils.GetBaseURL(fileName);
                    }
                }
            }
            catch
            {
                // 出现错误,认为文件不存在
                info.Exists   = false;
                info.Name     = fileName;
                info.FullPath = fileName;
            }
            return(info);
        }
예제 #2
0
        protected void FileOpenUrl(object sender, WriterCommandEventArgs args)
        {
            if (args.Mode == WriterCommandEventMode.QueryState)
            {
                args.Enabled = args.Document != null;
            }
            else if (args.Mode == WriterCommandEventMode.Invoke)
            {
                string url = Convert.ToString(args.Parameter);
                if (args.ShowUI)
                {
                    using (DCSoft.WinForms.Native.dlgInputUrl dlg
                               = new DCSoft.WinForms.Native.dlgInputUrl())
                    {
                        dlg.InputURL = url;
                        if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
                        {
                            url = dlg.InputURL;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                if (string.IsNullOrEmpty(url) == false)
                {
                    url = url.Trim();
                    string basePath = WriterUtils.GetBaseURL(url);

                    args.EditorControl.LoadDocument(url, FileFormat.Html);
                    args.Document.FileName = url;
                    args.Document.Modified = false;
                    args.Document.OnSelectionChanged();
                    args.Document.OnDocumentContentChanged();
                    args.Result       = true;
                    args.RefreshLevel = UIStateRefreshLevel.All;
                }
            }
        }