Ejemplo n.º 1
0
        /// <summary>
        /// Tentatively add a new view of the specified type to the current page
        /// </summary>
        /// <param name="viewType"></param>
        /// <param name="query"></param>
        /// <param name="qrc"></param>
        /// <returns></returns>

        private static ResultsViewProps AddTentativeNewView(
            ResultsViewModel rvm)
        {
            ResultsPage  rp;
            DialogResult dr;
            int          intVal, max;

            ResultsViewType     viewType    = rvm.ViewType;
            string              viewSubtype = rvm.ViewSubtype;
            string              viewTitle   = rvm.Title;
            Query               query       = rvm.Query;
            QueryResultsControl qrc         = rvm.QueryResultsControl as QueryResultsControl;

            LastAddedViewType = viewType;

            int pi = qrc.CurrentPageIndex;

            if (pi < 0 ||                                          // add a page if no pages
                query.Root.ResultsPages.Pages[pi].Views.Count > 0) // or (for now) already a view on the current page
            {
                rp = ResultsPages.AddNewPage(query);
                pi = query.Root.ResultsPages.Pages.Count - 1;
                qrc.AddResultsPageTabPage(rp);
            }

            ResultsPage      page = query.ResultsPages[pi];
            ResultsViewProps view = page.AddNewView(rvm);

            if (view == null)
            {
                throw new Exception("Failed to add new view: " + viewType);
            }

            //view.CustomViewTypeImageName = rvm.CustomViewTypeImageName; // (should already be set)

            if (Lex.IsDefined(viewTitle) && Lex.Ne(viewTitle, viewType.ToString()))
            {
                view.Title = page.AddSequentialSuffixToTitle(viewTitle, query.ResultsPages);                 // set custom title (sequentially-numbered) if defined
            }
            qrc.SetCurrentPageTabTitleAndImage();

            dr = view.ShowInitialViewSetupDialog();

            if (dr != DialogResult.OK)
            {
                RemoveTentativeView(view, qrc);
                return(null);                // not added
            }

            qrc.ConfigureResultsPage(page);             // render the default view in the current page

            dr = view.ShowInitialViewPropertiesDialog();
            if (dr == DialogResult.OK)
            {
                //view.ConfigureRenderingControl(); // be sure it's configured (not a good idea, adds overhead)

                qrc.SetCurrentPageTabTitleAndImage();                 // update tab title & image accordingly

                return(view);
            }

            else             // cancelled, remove view
            {
                RemoveTentativeView(view, qrc);
                return(null);                // not added
            }
        }