예제 #1
0
        private void CommandsWindow_Loaded(object sender, RoutedEventArgs e)
        {
            string initialValue = null;

            if (Model.AddinConfiguration.Commands.Count > 0)
            {
                CommanderCommand selectedItem = null;
                if (!string.IsNullOrEmpty(CommanderAddinConfiguration.Current.LastCommand))
                {
                    selectedItem =
                        Model.AddinConfiguration.Commands.FirstOrDefault(
                            cmd => cmd.Name == Model.AddinConfiguration.LastCommand);
                }
                else
                {
                    selectedItem = Model.AddinConfiguration.Commands[0];
                }

                ListCommands.SelectedItem = selectedItem;
                if (selectedItem != null)
                {
                    initialValue = selectedItem.CommandText;
                }
            }

            editor = new MarkdownEditorSimple(WebBrowserCommand, initialValue);
            editor.IsDirtyAction = () =>
            {
                string val = editor.GetMarkdown();
                if (val != null && Model.ActiveCommand != null)
                {
                    Model.ActiveCommand.CommandText = val;
                }

                return(true);
            };

            Dispatcher.InvokeAsync(() =>
            {
                ListCommands.Focus();
                editor.SetEditorSyntax("csharp");
            }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);

            pageLoaded = true;
        }
        private async void CommandsWindow_Loaded(object sender, RoutedEventArgs e)
        {
            await Task.Delay(1);

            string initialValue = null;

            if (Model.AddinConfiguration.Commands.Count > 0)
            {
                CommanderCommand selectedItem = null;
                if (!string.IsNullOrEmpty(CommanderAddinConfiguration.Current.LastCommand))
                {
                    selectedItem =
                        Model.AddinConfiguration.Commands.FirstOrDefault(
                            cmd => cmd.Name == Model.AddinConfiguration.LastCommand);
                }
                else
                {
                    selectedItem = Model.AddinConfiguration.Commands[0];
                }

                ListCommands.SelectedItem = selectedItem;
                if (selectedItem != null)
                {
                    initialValue = selectedItem.CommandText;
                }
            }

            editor = new MarkdownEditorSimple(WebBrowserCommand, initialValue, "csharp");
            editor.ShowLineNumbers = true;
            editor.IsDirtyAction   = (isDirty, newText, oldText) =>
            {
                if (newText != null && Model.ActiveCommand != null)
                {
                    Model.ActiveCommand.CommandText = newText;
                }

                return(newText != oldText);
            };

            Dispatcher.Invoke(() => ListCommands.Focus(), DispatcherPriority.ApplicationIdle);

            pageLoaded = true;
        }