Example #1
0
        private void ShowNewQueryWindow(string fileName,
                                        bool show,
                                        Dictionary <string, ParameterResolver> resolvers)
        {
            if (QueryWindows.Activate(fileName))
            {
                return;
            }


            QueryModel       queryModel = new QueryModel(this.Model);
            QueryEditorModel editor     = new QueryEditorModel();

            editor.ParameterResolvers = resolvers;
            editor.LoadFile(fileName);
            QueryEditorView view = new QueryEditorView(editor, queryModel);

            QueryWindows.Create(view, show);

            // Add to the menu collection.
            MenuItem newMenu = new MenuItem();

            newMenu.Click      += (s, eargs) => QueryWindows.Activate(view);
            newMenu.DataContext = view;
            Binding b = new Binding("Title");

            b.Source = view;
            newMenu.SetBinding(MenuItem.HeaderProperty, b);
            int index = QueryWindows.Count();

            if (String.IsNullOrEmpty(fileName))
            {
                //  Add ":" to give create an invalid filename.
                view.Title = string.Format("{0}{1}New Query", index, QueryEditorView.TitleSeperator);
            }
            else
            {
                view.Title = string.Format("{0}{1}{2}", index, QueryEditorView.TitleSeperator, fileName);
            }

            this.QueriesMenu.Items.Add(newMenu);

            // Remove from the menu collection upon close.
            CancelEventHandler closeHandler = (sender, args) =>
            {
                QueryWindows.Activate(view);
                view.Close(args);
            };

            queryModel.OnDisposed += (s, e1) =>
            {
                this.QueriesMenu.Items.Remove(newMenu);
                QueryWindows.Remove(view);
                MainModel.CloseEventHandler -= closeHandler;
            };


            MainModel.CloseEventHandler += closeHandler;
        }
Example #2
0
 void Merlin_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue is QueryEditorModel)
     {
         QueryEditorModel model = e.NewValue as QueryEditorModel;
         model.BuildStartCommand.CanExecuteTargets += () => true;
         model.BuildStartCommand.ExecuteTargets    += (o) =>
         {
             // Source doesn't get updated for we need to move the
             // focus out for the bind to the source.
             TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
             UIElement        element = Keyboard.FocusedElement as UIElement;
             if (element != null)
             {
                 element.MoveFocus(request);
                 element.Focus();
             }
         };
     }
 }
Example #3
0
        private void ShowNewQueryWindow(string fileName,
            bool show,
            Dictionary<string, ParameterResolver> resolvers)
        {
            if (QueryWindows.Activate(fileName))
            {
                return;
            }

            QueryModel queryModel = new QueryModel(this.Model);
            QueryEditorModel editor = new QueryEditorModel();
            editor.ParameterResolvers = resolvers;
            editor.LoadFile(fileName);
            QueryEditorView view = new QueryEditorView(editor, queryModel);
            QueryWindows.Create(view, show);

            // Add to the menu collection.
            MenuItem newMenu = new MenuItem();
            newMenu.Click += (s, eargs) => QueryWindows.Activate(view);
            newMenu.DataContext = view;
            Binding b = new Binding("Title");
            b.Source = view;
            newMenu.SetBinding(MenuItem.HeaderProperty, b);
            int index = QueryWindows.Count();
            if (String.IsNullOrEmpty(fileName))
            {
                //  Add ":" to give create an invalid filename.
                view.Title = string.Format("{0}{1}New Query", index, QueryEditorView.TitleSeperator);
            }
            else
            {
                view.Title = string.Format("{0}{1}{2}", index, QueryEditorView.TitleSeperator, fileName);
            }

            this.QueriesMenu.Items.Add(newMenu);

            // Remove from the menu collection upon close.
            CancelEventHandler closeHandler = (sender, args) =>
            {
                QueryWindows.Activate(view);
                view.Close(args);
            };

            queryModel.OnDisposed += (s, e1) =>
            {
                this.QueriesMenu.Items.Remove(newMenu);
                QueryWindows.Remove(view);
                MainModel.CloseEventHandler -= closeHandler;
            };

            MainModel.CloseEventHandler += closeHandler;
        }
Example #4
0
        public QueryEditorView(QueryEditorModel editor, QueryModel queryModel)
        {
            this.EditorModel             = editor;
            this.QueryModel              = queryModel;
            this.ShowFileExplorerCommand = new DelegateCommand <object>();
            this.ShowWizardCommand       = new DelegateCommand <object>();
            this.ExitCommand             = new DelegateCommand <object>();
            this.SaveCommand             = new DelegateCommand <string>();
            this.SaveAsCommand           = new DelegateCommand <string>();
            this.LoadFileCommand         = new DelegateCommand <string>();
            this.BuildAndRunCommand      = new DelegateCommand <object>();

            this.SaveCommand.CanExecuteTargets += () => this.EditorModel.State == QueryModelState.Changed;
            this.SaveCommand.ExecuteTargets    += (s) =>
            {
                if (this.EditorModel.State == QueryModelState.Changed &&
                    !String.IsNullOrEmpty(this.EditorModel.FileName))
                {
                    this.EditorModel.Save();
                    this.QueryModel.LogActivity(string.Format("Saved {0} on {1}",
                                                              this.EditorModel.FileName,
                                                              DateTime.Now.ToString()));
                }
                else
                {
                    if (this.SaveAsCommand.CanExecute(null))
                    {
                        this.SaveAsCommand.Execute(null);
                    }
                }
            };

            this.LoadFileCommand.CanExecuteTargets += () => true;
            this.LoadFileCommand.ExecuteTargets    += (filename) =>
            {
                CancelEventArgs args = new CancelEventArgs();
                this.ConfirmAndSave(args);
                if (!args.Cancel)
                {
                    this.EditorModel.LoadFile(filename);
                }
            };

            this.BuildAndRunCommand.CanExecuteTargets += () => true;
            this.BuildAndRunCommand.ExecuteTargets    += (o) =>
            {
                if (this.EditorModel.BuildCommand.CanExecute(null))
                {
                    this.EditorModel.BuildCommand.Execute(null);
                }

                if (this.QueryModel.RunCommand.CanExecute(null))
                {
                    this.QueryModel.RunCommand.Execute(null);
                }
            };

            this.EditorModel.PropertyChanged += (sender, args) =>
            {
                if (!String.IsNullOrEmpty(this.Title) && this.Title.Contains(TitleSeperator))
                {
                    this.Title = this.Title.Split(TitleSeperator)[0] + TitleSeperator + this.EditorModel.FileName;
                }
            };

            this.Text = this.EditorModel.QueryString;

            // Bind the Text property to QueryString
            // and setup the editor pane.
            BindingOperations.SetBinding(
                this,
                TextProperty,
                new Binding()
            {
                Source = this.EditorModel,
                Mode   = BindingMode.TwoWay,
                Path   = new PropertyPath(QueryEditorModel.QueryStringPropertyName)
            });
        }