Beispiel #1
0
        private void PerformSearch()
        {
            string query = _editHeading.Text.Trim();

            IResource[][] conditions = Controls2Resources(panelConditions.Controls);
            if (query.Length > 0)
            {
                IResource queryCondition = ((FilterRegistry)FMgr).CreateQueryConditionAux(null, query, comboSection.Text);
                FilterRegistry.ReferCondition2Template(queryCondition, FMgr.Std.BodyMatchesSearchQueryXName);

                //  Copy query condition to every subgroup or create the single one.
                if (conditions != null && conditions.Length > 0)
                {
                    for (int i = 0; i < conditions.Length; i++)
                    {
                        IResource[] group    = conditions[i];
                        IResource[] newGroup = new IResource[group.Length + 1];

                        for (int j = 0; j < group.Length; j++)
                        {
                            newGroup[j] = group[j];
                        }
                        newGroup[newGroup.Length - 1] = queryCondition;

                        conditions[i] = newGroup;
                    }
                }
                else
                {
                    conditions = FilterRegistry.Convert2Group(queryCondition);
                }
                UpdateStoredQueriesList(query);
            }

            IResource[] exceptions = ConvertTemplates2Conditions(panelExceptions.Controls);

            //-----------------------------------------------------------------
            //  need to remove existing basic View?
            //  NB: it removes all underlying AUX conditions including query search
            //-----------------------------------------------------------------
            IResource view = RStore.FindUniqueResource(FilterManagerProps.ViewResName, "DeepName", FMgr.ViewNameForSearchResults);

            string[] formTypes = ReformatTypes(CurrentResTypeDeep);
            if (view != null)
            {
                BaseResource = view;
                FMgr.ReregisterView(view, FMgr.ViewNameForSearchResults, formTypes, conditions, exceptions);
            }
            else
            {
                BaseResource = FMgr.RegisterView(FMgr.ViewNameForSearchResults, formTypes, conditions, exceptions);
            }

            //-----------------------------------------------------------------
            bool          showContext = (query.Length > 0) && Core.SettingStore.ReadBool("Resources", "ShowSearchContext", true);
            ResourceProxy proxy       = new ResourceProxy(BaseResource);

            proxy.BeginUpdate();
            proxy.SetProp(Core.Props.Name, SearchViewPrefix + query);
            proxy.SetProp(Core.Props.ShowDeletedItems, true);
            proxy.SetProp("ForceExec", true);
            proxy.SetProp("ShowContexts", showContext);
            if (BaseResource.HasProp(Core.Props.ContentType) || BaseResource.HasProp("ContentLinks"))
            {
                proxy.DeleteProp("ShowInAllTabs");
            }
            else
            {
                proxy.SetProp("ShowInAllTabs", true);
            }
            proxy.EndUpdate();

            //  if search is done specifically for the particular resource
            //  type - set the focus onto that tab.
            Core.ResourceTreeManager.LinkToResourceRoot(BaseResource, 1);
            if ((CurrentResTypeDeep != null) &&
                (CurrentResTypeDeep.IndexOf('|') == -1) && (CurrentResTypeDeep.IndexOf('#') == -1))
            {
                Core.TabManager.SelectResourceTypeTab(CurrentResTypeDeep);
            }
            else
            {
                Core.TabManager.SelectResourceTypeTab("");
            }

            Core.UIManager.BeginUpdateSidebar();
            Core.LeftSidebar.ActivateViewPane(StandardViewPanes.ViewsCategories);
            Core.UIManager.EndUpdateSidebar();
            Core.LeftSidebar.DefaultViewPane.SelectResource(BaseResource);
            BringToFront();
        }
Beispiel #2
0
        public static IResource InstantiateTemplate(IResource template, object param,
                                                    string representation, string[] resTypes)
        {
            #region Preconditions
            if (template.Type != FilterManagerProps.ConditionTemplateResName)
            {
                throw new InvalidOperationException("Input parameter must be of ConditionTemplate resource type");
            }
            #endregion Preconditions

            string      propName = template.GetStringProp("ApplicableToProp");
            ConditionOp op       = (ConditionOp)template.GetProp("ConditionOp");

            //-----------------------------------------------------------------
            IResource condition;
            if (op == ConditionOp.Eq && ResourceTypeHelper.IsDateProperty(propName))
            {
                condition = TimeSpan2Condition((string)param, propName, resTypes);
            }
            else
            if (op == ConditionOp.QueryMatch)
            {
                string sectionName = null;
                if (template.HasProp("SectionOrder"))
                {
                    sectionName = DocSectionHelper.FullNameByOrder((uint)template.GetIntProp("SectionOrder"));
                }

                condition = fMgr.CreateQueryConditionAux(resTypes, (string)param, sectionName);
            }
            else
            if (op == ConditionOp.Eq || op == ConditionOp.Has)
            {
                condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (string)param);
            }
            else
            if (op == ConditionOp.In)
            {
                condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (IResourceList)param);
            }
            else
            if (op == ConditionOp.InRange)
            {
                condition = IntRange2Condition((string)param, propName);
            }
            else
            {
                throw new InvalidOperationException("Not all Operations are supported now");
            }

            FilterRegistry.ReferCondition2Template(condition, template);

            //-----------------------------------------------------------------
            //  Do not forget to set additional parameters from the template
            //  and representation, e.g. if the template has "custom" style,
            //  propagate it to the aux condition.
            //-----------------------------------------------------------------
            ResourceProxy proxy = new ResourceProxy(condition);
            proxy.BeginUpdate();

            if (template.GetStringProp("ConditionType") == "custom")
            {
                proxy.SetProp("ConditionType", "custom");
            }

            if (!String.IsNullOrEmpty(representation))
            {
                proxy.SetProp("SurfaceConditionVal", representation);
            }
            proxy.EndUpdate();

            return(condition);
        }
Beispiel #3
0
        public void  ProcessQuery(string query)
        {
            //-----------------------------------------------------------------
            //  Avoid perform any UI (and other, generally) work if we are
            //  shutting down - some components (like DefaultViewPane) may
            //  already be disposed.
            //-----------------------------------------------------------------
            if (Core.State != CoreState.Running)
            {
                return;
            }

            //-----------------------------------------------------------------
            //  Extract Search Extension subphrases, extract them out of the
            //  query and convert them into the list of conditions.
            //-----------------------------------------------------------------
            int anchorPos;

            string[]  resTypes        = null;
            bool      parseSuccessful = false;
            ArrayList conditions      = new ArrayList();

            do
            {
                string anchor;
                FindSearchExtension(query, out anchor, out anchorPos);
                if (anchorPos != -1)
                {
                    parseSuccessful = ParseSearchExtension(anchor, anchorPos, ref query, out resTypes, conditions);
                }
            }while((anchorPos != -1) && parseSuccessful);

            //-----------------------------------------------------------------
            //  Create condition from the query
            //-----------------------------------------------------------------
            IFilterRegistry fMgr           = Core.FilterRegistry;
            IResource       queryCondition = ((FilterRegistry)fMgr).CreateStandardConditionAux(null, query, ConditionOp.QueryMatch);

            FilterRegistry.ReferCondition2Template(queryCondition, fMgr.Std.BodyMatchesSearchQueryXName);

            conditions.Add(queryCondition);

            //-----------------------------------------------------------------
            bool showContexts = Core.SettingStore.ReadBool("Resources", "ShowSearchContext", true);
            bool showDelItems = Core.SettingStore.ReadBool("Search", "ShowDeletedItems", true);

            IResource[] condsList = (IResource[])conditions.ToArray(typeof(IResource));
            IResource   view      = Core.ResourceStore.FindUniqueResource(FilterManagerProps.ViewResName, "DeepName", Core.FilterRegistry.ViewNameForSearchResults);

            if (view != null)
            {
                fMgr.ReregisterView(view, fMgr.ViewNameForSearchResults, resTypes, condsList, null);
            }
            else
            {
                view = fMgr.RegisterView(fMgr.ViewNameForSearchResults, resTypes, condsList, null);
            }
            Core.FilterRegistry.SetVisibleInAllTabs(view);

            //-----------------------------------------------------------------
            //  Set additional properties characteristic only for "Search Results"
            //  view.
            //-----------------------------------------------------------------
            ResourceProxy proxy = new ResourceProxy(view);

            proxy.BeginUpdate();
            proxy.SetProp(Core.Props.Name, AdvancedSearchForm.SearchViewPrefix + query);
            proxy.SetProp("_DisplayName", AdvancedSearchForm.SearchViewPrefix + query);
            proxy.SetProp(Core.Props.ShowDeletedItems, showDelItems);
            proxy.SetProp("ShowContexts", showContexts);
            proxy.SetProp("ForceExec", true);
            if (Core.SettingStore.ReadBool("Search", "AutoSwitchToResults", true))
            {
                proxy.SetProp("RunToTabIfSingleTyped", true);
            }
            else
            {
                proxy.DeleteProp("RunToTabIfSingleTyped");
            }
            proxy.EndUpdate();

            //-----------------------------------------------------------------
            //  Add new view to the panel
            //  Some steps to specify the correct user-ordering for the new view.
            //-----------------------------------------------------------------
            Core.ResourceTreeManager.LinkToResourceRoot(view, int.MinValue);

            new UserResourceOrder(Core.ResourceTreeManager.ResourceTreeRoot).Insert(0, new int[] { view.Id }, false, null);

            //-----------------------------------------------------------------
            //  If we still in the Running mode we can do some UI work...
            //-----------------------------------------------------------------
            if (Core.State == CoreState.Running)
            {
                Core.UIManager.BeginUpdateSidebar();
                Core.LeftSidebar.ActivateViewPane(StandardViewPanes.ViewsCategories);
                Core.UIManager.EndUpdateSidebar();
                Core.LeftSidebar.DefaultViewPane.SelectResource(view);
            }
        }