Exemplo n.º 1
0
        /// <summary>
        /// Warning: does not check for unsaved changes. Use OpenProject() if you need to.
        /// </summary>
        /// <param name="fileName"></param>
        private void OpenProject(string fileName, FileLoadedHandler OnLoaded)
        {
            try
            {
                if (!string.IsNullOrEmpty(fileName) && File.Exists(fileName))
                {
                    listPluginsAlreadyInitialized.Clear();

                    var ext = new FileInfo(fileName).Extension;
                    if (ext.Length < 2)
                    {
                        return;
                    }

                    ext = ext.Remove(0, 1);
                    if (ComponentInformations.EditorExtension.ContainsKey(ext))
                    {
                        Type editorType = ComponentInformations.EditorExtension[ext];

                        var editor = AddEditorDispatched(editorType);
                        if (editor == null)
                        {
                            return;
                        }

                        if (OnLoaded != null)
                        {
                            editor.OnFileLoaded += OnLoaded;
                            editor.OnFileLoaded += delegate { editor.OnFileLoaded -= OnLoaded; };
                        }

                        editor.Open(fileName);
                        if (editor.Presentation != null)
                        {
                            editor.Presentation.ToolTip = fileName;
                        }

                        SetCurrentEditorAsDefaultEditor();
                        this.ProjectFileName = fileName;

                        recentFileList.AddRecentFile(fileName);
                    }
                }
                else
                {
                    MessageBox.Show(string.Format(Properties.Resources.File__0__doesn_t_exist_, fileName), Properties.Resources.Error_loading_file);
                    recentFileList.RemoveFile(fileName);
                }
            }
            catch (Exception ex)
            {
                GuiLogMessage(string.Format("Couldn't open project file {0}:{1}", fileName, ex.Message), NotificationLevel.Error);
            }
        }
Exemplo n.º 2
0
        private void TemplateItemDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var infos = ((KeyValuePair <string, string>)((FrameworkElement)sender).Tag);

            if (infos.Key != null && Path.GetExtension(infos.Key) != null)
            {
                var fileExt = Path.GetExtension(infos.Key).ToLower().Substring(1);
                if (ComponentInformations.EditorExtension != null && ComponentInformations.EditorExtension.ContainsKey(fileExt))
                {
                    Type    editorType = ComponentInformations.EditorExtension[fileExt];
                    TabInfo info       = new TabInfo();
                    if (sender is CTTreeViewItem)
                    {
                        var templateItem = (CTTreeViewItem)sender;

                        info = new TabInfo()
                        {
                            Filename = templateItem.File,
                        };
                        //var tooltipInline = ((TextBlock) templateItem.ToolTip).Inlines.FirstOrDefault();
                        //if (tooltipInline != null)
                        //{
                        //    editor.Presentation.ToolTip = new TextBlock(tooltipInline) { TextWrapping = TextWrapping.Wrap, MaxWidth = 400 };
                        //}
                    }
                    else if (sender is ListBoxItem)
                    {
                        var searchItem = (ListBoxItem)sender;
                        info = (TabInfo)((System.Collections.ArrayList)((FrameworkElement)searchItem.Content).Tag)[0];

                        //var tooltipInline = ((TextBlock)searchItem.ToolTip).Inlines.FirstOrDefault();
                        //if (tooltipInline != null)
                        //{
                        //    editor.Presentation.ToolTip = new TextBlock(tooltipInline) { TextWrapping = TextWrapping.Wrap, MaxWidth = 400 };
                        //}
                        //editor.Presentation.Tag = ((Image)((StackPanel)searchItem.Content).Children[0]).Source;
                    }

                    if (TemplateLoaded != null)
                    {
                        TemplateLoaded.Invoke(this, new TemplateOpenEventArgs()
                        {
                            Info = info, Type = editorType
                        });
                    }
                    //OnOpenTab(editor, info, null);     //rename tab header
                    _recentFileList.AddRecentFile(infos.Key);
                }
            }
        }
Exemplo n.º 3
0
        private void OpenSelectedTemplate()
        {
            if (RecentFileListBox.SelectedItem == null)
            {
                return;
            }

            var selectedItem = (RecentFileInfo)RecentFileListBox.SelectedItem;

            if (TemplateLoaded != null)
            {
                var info = new TabInfo()
                {
                    Filename = new FileInfo(selectedItem.File)
                };
                TemplateLoaded.Invoke(this, new TemplateOpenEventArgs()
                {
                    Type = typeof(WorkspaceManager.WorkspaceManagerClass), Info = info
                });
            }
            _recentFileList.AddRecentFile(selectedItem.File);
        }