示例#1
0
        void Init()
        {
            sepBox  = null;
            preview = false;

            rootAdd = new Gtk.EventBox {
                VisibleWindow = false,
                CanFocus      = true
            };
            rootAdd.DragMotion       += HandleDragMotion;
            rootAdd.DragDataReceived += HandleDragDataReceived;
            rootAdd.DragLeave        += HandleDragLeave;

            help = new Gtk.Label($"<i>{Strings.DragTagsHereToSearchForThem}</i>")
            {
                UseMarkup = true,
                Visible   = true
            };

            rootBox = new HBox();
            rootBox.Add(help);
            rootBox.Show();

            rootAdd.Child = rootBox;
            rootAdd.Show();

            Gtk.Drag.DestSet(rootAdd, DestDefaults.All, tag_dest_target_table,
                             DragAction.Copy | DragAction.Move);

            PackEnd(rootAdd, true, true, 0);

            Root = new OrTerm(null, null);
        }
示例#2
0
 public override Term Invert(bool recurse)
 {
     var newme = new OrTerm (Parent, null);
     newme.CopyAndInvertSubTermsFrom (this, recurse);
     if (Parent != null)
         Parent.Remove (this);
     return newme;
 }
示例#3
0
        public override Term Invert(bool recurse)
        {
            OrTerm newme = new OrTerm(Parent, null);

            newme.CopyAndInvertSubTermsFrom(this, recurse);
            if (Parent != null)
            {
                Parent.Remove(this);
            }
            return(newme);
        }
示例#4
0
        public static OrTerm FromTags(Tag [] fromTags)
        {
            if (fromTags == null || fromTags.Length == 0)
            {
                return(null);
            }

            var or = new OrTerm(null, null);

            foreach (Literal l in fromTags.Select(t => new Literal(t)))
            {
                l.Parent = or;
            }
            return(or);
        }
示例#5
0
        public static OrTerm FromTags(Tag [] from_tags)
        {
            if (from_tags == null || from_tags.Length == 0)
            {
                return(null);
            }

            OrTerm or = new OrTerm(null, null);

            foreach (Tag t in from_tags)
            {
                Literal l = new Literal(t);
                l.Parent = or;
            }
            return(or);
        }
示例#6
0
文件: FindBar.cs 项目: GNOME/f-spot
        private bool ConstructQuery(Term parent, int depth, string txt, bool negated)
        {
            if (string.IsNullOrEmpty(txt))
                return true;

            string indent = String.Format ("{0," + depth*2 + "}", " ");

            //Log.DebugFormat (indent + "Have text: {0}", txt);

            // Match the query the user typed against our regular expression
            Match match = term_regex.Match (txt);

            if (!match.Success) {
                //Log.Debug (indent + "Failed to match.");
                return false;
            }

            bool op_valid = true;
            string op = String.Empty;

            // For the moment at least we don't support operator precedence, so we require
            // that only a single operator is used for any given term unless it is made unambiguous
            // by using parenthesis.
            foreach (Capture capture in match.Groups ["Ops"].Captures) {
                if (op == String.Empty)
                    op = capture.Value;
                else if (op != capture.Value) {
                    op_valid = false;
                    break;
                }
            }

            if (!op_valid) {
                Log.Information (indent + "Ambiguous operator sequence.  Use parenthesis to explicitly define evaluation order.");
                return false;
            }

            if (match.Groups ["Terms"].Captures.Count == 1 && match.Groups["NotTerm"].Captures.Count != 1) {
                //Log.DebugFormat (indent + "Unbreakable term: {0}", match.Groups ["Terms"].Captures [0]);
                string literal;
                bool is_negated = false;
                Tag tag = null;

                if (match.Groups ["NotTag"].Captures.Count == 1) {
                    literal = match.Groups ["NotTag"].Captures [0].Value;
                    is_negated = true;
                } else {
                    literal = match.Groups ["Terms"].Captures [0].Value;
                }

                is_negated = is_negated || negated;

                tag = App.Instance.Database.Tags.GetTagByName (literal);

                // New OR term so we can match against both tag and text search
                parent = new OrTerm(parent, null);

                // If the literal is the name of a tag, include it in the OR
                //AbstractLiteral term = null;
                if (tag != null) {
                    new Literal (parent, tag, null);
                }

                // Always include the literal text in the search (path, comment, etc)
                new TextLiteral (parent, literal);

                // If the term was negated, negate the OR parent term
                if (is_negated) {
                    parent = parent.Invert(true);
                }

                if (RootTerm == null)
                    root_term = parent;

                return true;
            } else {
                Term us = null;
                if (op != null && op != String.Empty) {
                    us = Term.TermFromOperator (op, parent, null);
                    if (RootTerm == null)
                        root_term = us;
                }

                foreach (Capture capture in match.Groups ["Term"].Captures) {
                    string subterm = capture.Value.Trim ();

                    if (subterm == null || subterm.Length == 0)
                        continue;

                    // Strip leading/trailing parens
                    if (subterm [0] == '(' && subterm [subterm.Length - 1] == ')') {
                        subterm = subterm.Remove (subterm.Length - 1, 1);
                        subterm = subterm.Remove (0, 1);
                    }

                    //Log.DebugFormat (indent + "Breaking subterm apart: {0}", subterm);

                    if (!ConstructQuery (us, depth + 1, subterm, negated))
                        return false;
                }

                foreach (Capture capture in match.Groups ["NotTerm"].Captures) {
                    string subterm = capture.Value.Trim ();

                    if (subterm == null || subterm.Length == 0)
                        continue;

                    // Strip leading/trailing parens
                    if (subterm [0] == '(' && subterm [subterm.Length - 1] == ')') {
                        subterm = subterm.Remove (subterm.Length - 1, 1);
                        subterm = subterm.Remove (0, 1);
                    }

                    //Log.DebugFormat (indent + "Breaking not subterm apart: {0}", subterm);

                    if (!ConstructQuery (us, depth + 1, subterm, true))
                        return false;
                }

                if (negated && us != null) {
                    if (us == RootTerm)
                        root_term = us.Invert(false);
                    else
                        us.Invert(false);
                }

                return true;
            }
        }
示例#7
0
        public static OrTerm FromTags(Tag [] fromTags)
        {
            if (fromTags == null || fromTags.Length == 0)
                return null;

            var or = new OrTerm (null, null);
            foreach (Literal l in fromTags.Select(t => new Literal (t)))
            {
                l.Parent = or;
            }
            return or;
        }
示例#8
0
		public static OrTerm FromTags(Tag [] from_tags)
		{
			if (from_tags == null || from_tags.Length == 0)
				return null;

			OrTerm or = new OrTerm(null, null);
			foreach (Tag t in from_tags) {
				Literal l = new Literal(t);
				l.Parent = or;
			}
			return or;
		}