Bend.MainWindow.CommandOpen C# (CSharp) Method

CommandOpen() private method

private CommandOpen ( object sender, System.Windows.Input.ExecutedRoutedEventArgs e ) : void
sender object
e System.Windows.Input.ExecutedRoutedEventArgs
return void
        private void CommandOpen(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.CheckFileExists = true;
            FileExtensions flex = new FileExtensions();
            dlg.Filter = flex.GetFilterString();
            if (this.currentTabIndex >= 0 && this.tab[this.currentTabIndex].FullFileName != null)
            {
                string initialDirectory = System.IO.Path.GetDirectoryName(this.tab[this.currentTabIndex].FullFileName);
                if (initialDirectory != null && initialDirectory.Length != 0)
                {
                    dlg.InitialDirectory = initialDirectory;
                }
            }

            if (dlg.ShowDialog(this) ?? false)
            {
                // No tabs / Non Empty new file / tab has some file open
                if (this.currentTabIndex < 0 || this.tab[this.currentTabIndex].TextEditor.Document.TextLength != 0 || this.tab[this.currentTabIndex].FullFileName != null)
                {
                    if (this.currentTabIndex >= 0)
                    {
                        tab[this.currentTabIndex].Title.Opacity = 0.5;
                        tab[this.currentTabIndex].TextEditor.Visibility = Visibility.Hidden;
                    }

                    this.AddNewTab();

                    this.currentTabIndex = tab.Count - 1;
                    tab[this.currentTabIndex].TextEditor.Focus();
                }

                this.tab[this.currentTabIndex].OpenFile(dlg.FileName);
            }
        }