Exemplo n.º 1
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:

            #line 10 "..\..\..\MainWindow.xaml"
                ((Editor.MainWindow)(target)).TextInput += new System.Windows.Input.TextCompositionEventHandler(this.Window_TextInput);

            #line default
            #line hidden

            #line 11 "..\..\..\MainWindow.xaml"
                ((Editor.MainWindow)(target)).KeyDown += new System.Windows.Input.KeyEventHandler(this.Window_KeyDown);

            #line default
            #line hidden
                return;

            case 2:

            #line 23 "..\..\..\MainWindow.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.CloseCommandHandler);

            #line default
            #line hidden
                return;

            case 3:

            #line 24 "..\..\..\MainWindow.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.DecreaseZoomCommandHandler);

            #line default
            #line hidden
                return;

            case 4:

            #line 25 "..\..\..\MainWindow.xaml"
                ((System.Windows.Input.CommandBinding)(target)).Executed += new System.Windows.Input.ExecutedRoutedEventHandler(this.IncreaseZoomCommandHandler);

            #line default
            #line hidden
                return;

            case 5:
                this.mainDock = ((System.Windows.Controls.DockPanel)(target));
                return;

            case 6:

            #line 32 "..\..\..\MainWindow.xaml"
                ((System.Windows.Controls.ToolBar)(target)).Loaded += new System.Windows.RoutedEventHandler(this.ToolBar_Loaded);

            #line default
            #line hidden
                return;

            case 7:
                this.zoomoutButton = ((System.Windows.Controls.Button)(target));
                return;

            case 8:
                this.zoominButton = ((System.Windows.Controls.Button)(target));
                return;

            case 9:
                this.underbarToggle = ((System.Windows.Controls.Primitives.ToggleButton)(target));

            #line 40 "..\..\..\MainWindow.xaml"
                this.underbarToggle.Unchecked += new System.Windows.RoutedEventHandler(this.underbarToggleCheckChanged);

            #line default
            #line hidden

            #line 40 "..\..\..\MainWindow.xaml"
                this.underbarToggle.Checked += new System.Windows.RoutedEventHandler(this.underbarToggleCheckChanged);

            #line default
            #line hidden
                return;

            case 10:
                this.button = ((System.Windows.Controls.Button)(target));

            #line 46 "..\..\..\MainWindow.xaml"
                this.button.Click += new System.Windows.RoutedEventHandler(this.button_Click);

            #line default
            #line hidden
                return;

            case 11:
                this.mathToolBar = ((Editor.MathToolBar)(target));
                return;

            case 12:
                this.statusBarLeftLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 13:
                this.statusBarRightLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 14:
                this.scrollViwer = ((System.Windows.Controls.ScrollViewer)(target));

            #line 57 "..\..\..\MainWindow.xaml"
                this.scrollViwer.ScrollChanged += new System.Windows.Controls.ScrollChangedEventHandler(this.scrollViwer_ScrollChanged);

            #line default
            #line hidden
                return;

            case 15:
                this.editor = ((Editor.EditorControl)(target));
                return;
            }
            this._contentLoaded = true;
        }
Exemplo n.º 2
0
        private void OpenFile(string fileName)
        {
            try
            {
                using (Stream stream = File.OpenRead(fileName))
                {
                    MainTabControl.Items.Clear();
                    Stream finstr = null;

                    try {
                        ZipInputStream zipInputStream = new ZipInputStream(stream);
                        ZipEntry       zipEntry       = zipInputStream.GetNextEntry();
                        MemoryStream   outputStream   = new MemoryStream();
                        if (zipEntry != null)
                        {
                            byte[] buffer = new byte[4096];
                            StreamUtils.Copy(zipInputStream, outputStream, buffer);
                        }
                        outputStream.Position = 0;
                        finstr = outputStream;
                    }
                    catch {
                        stream.Position = 0;
                        finstr          = stream;
                    }

                    XDocument xDoc = XDocument.Load(finstr, LoadOptions.PreserveWhitespace);
                    XElement  root = xDoc.Root;

                    XElement   formattingElement    = root.Element("TextManager");
                    XAttribute fileVersionAttribute = root.Attributes("fileVersion").FirstOrDefault();
                    XAttribute appVersionAttribute  = root.Attributes("appVersion").FirstOrDefault();
                    string     appVersion           = appVersionAttribute != null ? appVersionAttribute.Value : "Unknown";
                    if (fileVersionAttribute == null || fileVersionAttribute.Value != fileVersion)
                    {
                        MessageBox.Show("The file was created by a different version (v." + appVersion + ") of Math Editor and uses a different format." + Environment.NewLine + Environment.NewLine +
                                        "Math Editor will still try to open and convert the file to the current version. The operation may fail. " + Environment.NewLine + Environment.NewLine +
                                        "Please create a backup if you want to keep the original file intact.", "Message");
                    }

                    foreach (XElement rowCont in root.Elements("RowContainer"))
                    {
                        EditorControl newEditorControl = new EditorControl();
                        //newEditorControl.Background = Transparent;
                        newEditorControl.Focusable = true;
                        //newEditorControl.FocusVisualStyle = "{x:Null}";
                        newEditorControl.LoadTab(rowCont, formattingElement);
                        newEditorControl.ZoomChanged      += new EventHandler(editor_ZoomChanged);
                        newEditorControl.IsVisibleChanged += new DependencyPropertyChangedEventHandler(IsVisibleChanged);

                        ScrollViewer newScrollViewer = new ScrollViewer();
                        //FocusVisualStyle = "{x:Null}"
                        newScrollViewer.Focusable      = true;
                        newScrollViewer.ScrollChanged += scrollViewer_ScrollChanged;
                        newScrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
                        newScrollViewer.Content = newEditorControl;

                        TabItem newTabItem = new TabItem();
                        newTabItem.Content = newScrollViewer;
                        newTabItem.Header  = (rowCont.Attribute("Name") != null ? rowCont.Attribute("Name").Value : "Tab " + (MainTabControl.Items.Count + 1));
                        MainTabControl.Items.Add(newTabItem);
                    }

                    TabItem newTI = new TabItem();
                    newTI.Header = "+";
                    MainTabControl.Items.Add(newTI);
                }
                currentLocalFile = fileName;
            }
            catch (Exception e)
            {
                currentLocalFile = "";
                MessageBox.Show("File is corrupt or inaccessible OR it was created by an incompatible version of Math Editor.\n\n" +
                                e.ToString(), "Error");
            }
            SetTitle();
        }