Пример #1
0
        public DocumentEditorPage(string FileName, bool enableEdit = true, bool RemoveToolBar = false, string UCTextEditorTitle = null)
        {
            InitializeComponent();

            TextEditorBase TE = GetTextEditorByExtension(FileName);

            if (TE != null)
            {
                ITextEditorPage p = TE.EditorPage;
                if (p != null)
                {
                    // text editor can return customized editor
                    EditorFrame.Content = p;
                    p.Load(FileName);
                }
                else
                {
                    // Load regular UCtextEditor and init with TE
                    UCTextEditor UCTE = new UCTextEditor();
                    UCTE.Init(FileName, TE, enableEdit, RemoveToolBar);
                    if (UCTextEditorTitle != null)
                    {
                        UCTE.SetContentEditorTitleLabel(UCTextEditorTitle);
                    }
                    else if (!string.IsNullOrEmpty(TE.Title()))
                    {
                        UCTE.SetContentEditorTitleLabel(TE.Title());
                    }
                    EditorFrame.Content = UCTE;
                }
            }
            else
            {
                if (IsTextFile(FileName))
                {
                    //Use the default UCTextEditor control
                    UCTextEditor         UCTE = new UCTextEditor();
                    AutoDetectTextEditor AD   = new AutoDetectTextEditor();
                    AD.ext = Path.GetExtension(FileName);
                    TE     = AD;
                    UCTE.Init(FileName, TE, enableEdit, RemoveToolBar, EnableWrite: true);
                    if (UCTextEditorTitle != null)
                    {
                        UCTE.SetContentEditorTitleLabel(UCTextEditorTitle);
                    }
                    EditorFrame.Content = UCTE;
                }
                else
                {
                    // Just put a general shell doc
                    ITextEditorPage p = new OfficeDocumentPage();
                    p.Load(FileName);
                    EditorFrame.Content = p;
                }
            }
        }
Пример #2
0
        public void SetDocumentEditor(TextEditorBase TE)
        {
            mTextEditor = TE;
            IHighlightingDefinition HD = TE.HighlightingDefinition;

            if (HD != null)
            {
                textEditor.SyntaxHighlighting = HD;
            }
            else
            {
                // try to use Avalon highlighting built in to find the correct highlight by file extension
                string ext = Path.GetExtension(FileName).ToLower();
                textEditor.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance.GetDefinitionByExtension(ext);
            }

            IFoldingStrategy FG = TE.FoldingStrategy;

            if (FG != null)
            {
                try
                {
                    mFoldingManager = FoldingManager.Install(textEditor.TextArea);
                }
                catch
                { }
                mFoldingStrategy = FG;
                InitFoldings();
            }

            textEditor.TextArea.Caret.PositionChanged += Caret_PositionChanged;

            //TODO: set indentation manager

            // Add tools in toolbar
            if (TE.Tools != null)
            {
                foreach (ITextEditorToolBarItem t in TE.Tools)
                {
                    if (t is TextEditorToolBarItem)
                    {
                        TextEditorToolBarItem textEditorToolBarItem = (TextEditorToolBarItem)t;
                        AddToolbarTool(textEditorToolBarItem.Image, textEditorToolBarItem.clickHandler, textEditorToolBarItem.toolTip, textEditorToolBarItem.toolVisibility);
                    }
                    else
                    {
                        // Plugin text editor
                        AddPluginToolbarTool(t);
                    }
                }
            }
        }
Пример #3
0
        private TextEditorBase GetTextEditorByExtension(string FileName)
        {
            // We cache the list, so create only once
            if (TextEditors.Count() == 0)
            {
                var list = from type in typeof(TextEditorBase).Assembly.GetTypes()
                           where type.IsSubclassOf(typeof(TextEditorBase))
                           select type;


                foreach (Type t in list)
                {
                    if (t != typeof(PlugInTextEditorWrapper))
                    {
                        TextEditorBase TE = (TextEditorBase)Activator.CreateInstance(t);
                        TextEditors.Add(TE);
                    }
                }
            }

            // Add all plugins TextEditors
            ObservableList <PlugInWrapper> PlugInsList = App.LocalRepository.GetSolutionPlugIns();

            foreach (PlugInWrapper PW in PlugInsList)
            {
                foreach (PlugInTextFileEditorBase TE in PW.TextEditors())
                {
                    PlugInTextEditorWrapper w = new PlugInTextEditorWrapper(TE);
                    PlugInTextEditorWrapper f = (PlugInTextEditorWrapper)TextEditors.Where(x => x is PlugInTextEditorWrapper ? ((PlugInTextEditorWrapper)x).GetEditorID() == w.GetEditorID() : false).FirstOrDefault();
                    if (f == null)
                    {
                        TextEditors.Add(w);
                    }
                }
            }

            //TODO: if there is more than one let the user pick
            string ext = Path.GetExtension(FileName).ToLower();

            foreach (TextEditorBase TE in TextEditors)
            {
                if (TE.Extensions != null)
                {
                    if (TE.Extensions.Contains(ext))
                    {
                        return(TE);
                    }
                }
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// Initialize the text Editor
        /// </summary>
        /// <param name="FileName">The full path of the file to edit/view</param>
        /// <param name="EnableEdit">enable changing the document, if disable some toolbar buttons will not be visible</param>
        /// <param name="TextEditor">Text Editor to use, if null then text editor will be selected based on the extension of the file</param>
        public void Init(string FileName, TextEditorBase TextEditor, bool EnableEdit = true, bool RemoveToolBar = false, bool EnableWrite = false)
        {
            mTextEditor = TextEditor;

            if (mTextEditor is ITextEditor)
            {
                ((ITextEditor)mTextEditor).TextHandler = this;
            }

            //TODO: put it in general func
            string SolutionPath = FileName.Replace(WorkSpace.Instance.Solution.Folder, "~");

            lblTitle.Content = SolutionPath;

            if (EnableWrite)
            {
                SaveButton.Visibility   = Visibility.Visible;
                UndoButton.Visibility   = Visibility.Visible;
                DeleteButton.Visibility = Visibility.Visible;
            }

            textEditor.IsReadOnly = !EnableEdit;
            if (EnableEdit)
            {
                toolbar.IsEnabled = true;
            }
            else
            {
                toolbar.IsEnabled = false;
            }

            this.FileName = FileName;
            if (!string.IsNullOrEmpty(this.FileName) && File.Exists(this.FileName))
            {
                textEditor.Load(this.FileName);
            }
            else
            {
                textEditor.Clear();
            }

            textEditor.ShowLineNumbers = true;

            //TODO: highlight current line;

            SetDocumentEditor(TextEditor);
            if (RemoveToolBar)
            {
                HideToolBar();
            }
        }
Пример #5
0
        void ScanTextEditors()
        {
            if (TextEditors == null)
            {
                TextEditors = new List <TextEditorBase>();

                var list = from type in typeof(TextEditorBase).Assembly.GetTypes()
                           where type.IsSubclassOf(typeof(TextEditorBase))
                           select type;


                foreach (Type t in list)
                {
                    if (t == typeof(PlugInTextEditorWrapper) || t == typeof(ValueExpression.ValueExpressionEditor))
                    {
                        continue;
                    }
                    if (t != typeof(ITextEditor))
                    {
                        TextEditorBase TE = (TextEditorBase)Activator.CreateInstance(t);
                        TextEditors.Add(TE);
                    }
                }

                // Add all plugins TextEditors
                ObservableList <PluginPackage> Plugins = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <PluginPackage>();

                foreach (PluginPackage pluginPackage in Plugins)
                {
                    pluginPackage.PluginPackageOperations = new PluginPackageOperations(pluginPackage);

                    if (string.IsNullOrEmpty(((PluginPackageOperations)pluginPackage.PluginPackageOperations).PluginPackageInfo.UIDLL))
                    {
                        continue;
                    }

                    foreach (ITextEditor TE in PluginTextEditorHelper.GetTextFileEditors(pluginPackage))
                    {
                        PlugInTextEditorWrapper plugInTextEditorWrapper = new PlugInTextEditorWrapper(TE);
                        TextEditors.Add(plugInTextEditorWrapper);
                    }
                }
            }
        }
        void ScanTextEditors()
        {
            if (TextEditors == null)
            {
                TextEditors = new List <TextEditorBase>();

                var list = from type in typeof(TextEditorBase).Assembly.GetTypes()
                           where type.IsSubclassOf(typeof(TextEditorBase))
                           select type;


                foreach (Type t in list)
                {
                    if (t == typeof(PlugInTextEditorWrapper) || t == typeof(ValueExpression.ValueExpressionEditor))
                    {
                        continue;
                    }
                    if (t != typeof(ITextEditor))
                    {
                        TextEditorBase TE = (TextEditorBase)Activator.CreateInstance(t);
                        TextEditors.Add(TE);
                    }
                }

                // Add all plugins TextEditors
                ObservableList <PluginPackage> Plugins = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <PluginPackage>();

                foreach (PluginPackage PP in Plugins)
                {
                    foreach (ITextEditor TE in PP.GetTextFileEditors())
                    {
                        PlugInTextEditorWrapper w = new PlugInTextEditorWrapper(TE);
                        //PlugInTextEditorWrapper f = (PlugInTextEditorWrapper)TextEditors.Where(x => x is PlugInTextEditorWrapper ? ((PlugInTextEditorWrapper)x).GetEditorID() == w.GetEditorID() : false).FirstOrDefault();


                        TextEditors.Add(w);
                    }
                }
            }
        }