Beispiel #1
0
        public IEditor Open(string path)
        {
            path = Tool.FileUtility.GetSystemPath(path);

            if (!System.IO.File.Exists(path) && (path != "StartPage"))
            {
                MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("file_not_exist"), path, MessageType.Error, null);
                md.ShowDialog();
                return(null);
            }

            string ext = System.IO.Path.GetExtension(path);

            /*if(ext.ToLower() ==".ttf"){
             *      if (!String.IsNullOrEmpty(path)){
             *              System.Diagnostics.Process.Start(path);
             *      }
             *      return null;
             * }*/
            IEditor se = FindEditor(path);

            if (se != null)
            {
                this.CurrentPage = this.PageNum(se.Control);
                return(null);
            }

            ExtensionSetting exSet = MainClass.Tools.FindFileTyp(ext);

            if (exSet == null)
            {
                if (path == "StartPage")
                {
                    se = new StartPage(path);
                    //return null;
                }
                else                    //	if (!String.IsNullOrEmpty(path)){
                {
                    System.Diagnostics.Process.Start(path);
                    return(null);
                }
            }
            try {
                if (se == null)
                {
                    switch (exSet.OpenType)
                    {
                    case ExtensionSetting.OpenTyp.IMAGE:
                        se = new ImageEditor(path);
                        break;

                    case ExtensionSetting.OpenTyp.DATABASE:
                        se = new DatabaseEditor(path);
                        break;

                    case ExtensionSetting.OpenTyp.TEXT:
                        se = new SourceEditor(path);
                        break;

                    case ExtensionSetting.OpenTyp.SYSTEM: {
                        System.Diagnostics.Process.Start(path);
                        return(null);
                    }

                    case ExtensionSetting.OpenTyp.EXTERNAL: {
                        MainClass.MainWindow.RunProcess(exSet.ExternalProgram, exSet.Parameter + " " + path, "", false, null);

                        return(null);
                    }

                    default:
                        se = new SourceEditor(path);
                        break;
                    }

                    /*switch (extension) {
                     * case ".png":
                     * case ".jpg":
                     * case ".jpeg":
                     * case ".bmp":
                     * case ".gif":
                     * case ".tif":
                     * case ".svg":
                     *      se = new ImageEditor(path);
                     *      break;
                     * case ".db":
                     *      se = new DatabaseEditor(path);
                     *      break;
                     * //case ".html":
                     * //	se = new WebViewer(path);
                     * //	break;
                     * default:
                     *      se = new SourceEditor(path);
                     *      break;
                     * }*/
                }
            } catch (Exception ex) {
                MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, ex.Message, path, MessageType.Error, null);
                md.ShowDialog();
                Logger.Error(ex.Message);
                Logger.Error(ex.Source);
                Logger.Error(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    Logger.Error(ex.InnerException.Message);
                    Logger.Error(ex.InnerException.Source);
                    Logger.Error(ex.InnerException.StackTrace);
                }
                return(null);
            }

            //se.Caption = System.IO.Path.GetFileName(path);
            listEditor.Add(se);

            NotebookEditorLabel nl = new NotebookEditorLabel(this, se);

            int i = this.AppendPage(se.Control, nl);

            se.ModifiedChanged += delegate(object sender, ModifiedChangedEventArgs e) {
                //IEditor se = IEditor(sender);
                //NotebookLabel nl =  (NotebookLabel)this.GetTabLabel(se);
                if (nl != null)
                {
                    nl.SetSaveState(e.State);
                }
            };

            se.WriteStatusChange += delegate(object sender, WriteStatusEventArgs e) {
                //Console.WriteLine(e.Message);
                MainClass.MainWindow.PushText(e.Message);
            };

            this.CurrentPage = i;
            return(se);
        }
Beispiel #2
0
        public IEditor Open(string path)
        {
            path = Tool.FileUtility.GetSystemPath(path);

            if (!System.IO.File.Exists(path) && (path != "StartPage") ){
                MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("file_not_exist"), path, MessageType.Error,null);
                md.ShowDialog();
                return null;
            }

            string ext = System.IO.Path.GetExtension(path);

            /*if(ext.ToLower() ==".ttf"){
                if (!String.IsNullOrEmpty(path)){
                    System.Diagnostics.Process.Start(path);
                }
                return null;
            }*/
            IEditor se = FindEditor(path);
            if (se != null) {
                this.CurrentPage = this.PageNum(se.Control);
                return null;
            }

            ExtensionSetting exSet =MainClass.Tools.FindFileTyp(ext);
            if(exSet == null){
                if (path == "StartPage"){
                    se = new StartPage(path);
                    //return null;
                } else {//	if (!String.IsNullOrEmpty(path)){
                    System.Diagnostics.Process.Start(path);
                    return null;
                }

            }
            try {
                if(se == null){
                    switch (exSet.OpenType) {
                    case ExtensionSetting.OpenTyp.IMAGE:
                        se = new ImageEditor(path);
                        break;
                    case ExtensionSetting.OpenTyp.DATABASE:
                        se = new DatabaseEditor(path);
                        break;
                    case ExtensionSetting.OpenTyp.TEXT:
                        se = new SourceEditor(path);
                        break;
                    case ExtensionSetting.OpenTyp.SYSTEM:{
                        System.Diagnostics.Process.Start(path);
                        return null;
                    }
                    case ExtensionSetting.OpenTyp.EXTERNAL:{

                        MainClass.MainWindow.RunProcess(exSet.ExternalProgram, exSet.Parameter+" "+path, "", false,null);

                        return null;
                    }
                    default:
                        se = new SourceEditor(path);
                        break;
                    }
                    /*switch (extension) {
                    case ".png":
                    case ".jpg":
                    case ".jpeg":
                    case ".bmp":
                    case ".gif":
                    case ".tif":
                    case ".svg":
                        se = new ImageEditor(path);
                        break;
                    case ".db":
                        se = new DatabaseEditor(path);
                        break;
                    //case ".html":
                    //	se = new WebViewer(path);
                    //	break;
                    default:
                        se = new SourceEditor(path);
                        break;
                    }*/
                }
            } catch(Exception ex) {
                MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, ex.Message, path, MessageType.Error,null);
                md.ShowDialog();
                Logger.Error(ex.Message);
                Logger.Error(ex.Source);
                Logger.Error(ex.StackTrace);
                if (ex.InnerException != null){
                    Logger.Error(ex.InnerException.Message);
                    Logger.Error(ex.InnerException.Source);
                    Logger.Error(ex.InnerException.StackTrace);
                }
                return null;
            }

            //se.Caption = System.IO.Path.GetFileName(path);
            listEditor.Add(se);

            NotebookEditorLabel nl = new NotebookEditorLabel(this, se);

            int i = this.AppendPage(se.Control, nl);

            se.ModifiedChanged += delegate(object sender, ModifiedChangedEventArgs e) {

                //IEditor se = IEditor(sender);
                //NotebookLabel nl =  (NotebookLabel)this.GetTabLabel(se);
                if (nl != null) nl.SetSaveState(e.State);
            };

            se.WriteStatusChange +=  delegate(object sender, WriteStatusEventArgs e) {
                //Console.WriteLine(e.Message);
                MainClass.MainWindow.PushText(e.Message);
            };

            this.CurrentPage = i;
            return se;
        }