public Term (Term parent, Literal after) { this.parent = parent; if (parent != null) { if (after == null) parent.Add (this); else parent.SubTerms.Insert (parent.SubTerms.IndexOf (after) + 1, this); } }
private void HandleAttachTag (Tag tag, Term parent, Literal after) { InsertTerm (new Tag [] {tag}, parent, after); }
private void HandleTermAdded (Term parent, Literal after) { InsertTerm (parent, after); }
private void HandleLiteralsMoved (ArrayList literals, Term parent, Literal after) { preventUpdate = true; foreach (Literal term in literals) { Tag tag = term.Tag; // Don't listen for it to be removed since we are // moving it. We will update when we're done. term.Removed -= HandleRemoved; term.RemoveSelf (); // Add it to where it was dropped ArrayList groups = InsertTerm (new Tag[] {tag}, parent, after); if (term.IsNegated) foreach (Literal group in groups) group.IsNegated = true; } preventUpdate = false; UpdateQuery (); }
private void Init () { sepBox = null; preview = false; rootAdd = new Gtk.EventBox (); rootAdd.VisibleWindow = false; rootAdd.CanFocus = true; rootAdd.DragMotion += HandleDragMotion; rootAdd.DragDataReceived += HandleDragDataReceived; rootAdd.DragLeave += HandleDragLeave; help = new Gtk.Label ("<i>" + Catalog.GetString ("Drag tags here to search for them") + "</i>"); help.UseMarkup = true; help.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); rootTerm = new OrTerm (null, null); }
private static bool AppendTerm (ArrayList parts, Term term, Tag single_tag) { bool tag_matches = false; if (term != null) { Literal literal = term as Literal; if (literal != null) { if (literal.Tag == single_tag) tag_matches = true; if (literal.IsNegated) parts.Add (String.Format (Catalog.GetString ("Not {0}"), literal.Tag.Name)); else parts.Add (literal.Tag.Name); } else { foreach (Term subterm in term.SubTerms) { tag_matches |= AppendTerm (parts, subterm, single_tag); } } } return tag_matches; }
public Photo [] Query(Term searchexpression, string extra_condition, DateRange range, RollSet importidrange, RatingRange ratingrange) { bool hide = (extra_condition == null); // The SQL query that we want to construct is: // // SELECT photos.id // photos.time // photos.uri, // photos.description, // photos.roll_id, // photos.default_version_id // photos.rating // FROM photos, photo_tags // WHERE photos.time >= time1 AND photos.time <= time2 // AND photos.rating >= rat1 AND photos.rating <= rat2 // AND photos.id NOT IN (select photo_id FROM photo_tags WHERE tag_id = HIDDEN) // AND photos.id IN (select photo_id FROM photo_tags where tag_id IN (tag1, tag2..) // AND extra_condition_string // GROUP BY photos.id StringBuilder query_builder = new StringBuilder(); List <string> where_clauses = new List <string> (); query_builder.Append("SELECT id, " + "time, " + "base_uri, " + "filename, " + "description, " + "roll_id, " + "default_version_id, " + "rating " + "FROM photos "); if (range != null) { where_clauses.Add(String.Format("time >= {0} AND time <= {1}", DateTimeUtil.FromDateTime(range.Start), DateTimeUtil.FromDateTime(range.End))); } if (ratingrange != null) { where_clauses.Add(ratingrange.SqlClause()); } if (importidrange != null) { where_clauses.Add(importidrange.SqlClause()); } if (hide && App.Instance.Database.Tags.Hidden != null) { where_clauses.Add(String.Format("id NOT IN (SELECT photo_id FROM photo_tags WHERE tag_id = {0})", App.Instance.Database.Tags.Hidden.Id)); } if (searchexpression != null) { where_clauses.Add(searchexpression.SqlCondition()); } if (extra_condition != null && extra_condition.Trim() != String.Empty) { where_clauses.Add(extra_condition); } if (where_clauses.Count > 0) { query_builder.Append(" WHERE "); query_builder.Append(String.Join(" AND ", where_clauses.ToArray())); } query_builder.Append(" ORDER BY time"); return(Query(query_builder.ToString())); }
public TextLiteral (Term parent, string text) : base (parent, null) { this.text = text; }
public Literal (Term parent, Tag tag, Literal after) : base (parent, after) { this.tag = tag; }
/** Methods **/ public void Add (Term term) { SubTerms.Add (term); }
public AbstractLiteral(Term parent, Literal after) : base (parent, after) {}
public OrTerm (Term parent, Literal after) : base (parent, after) {}
public static Term TermFromOperator (string op, Term parent, Literal after) { //Console.WriteLine ("finding type for operator {0}", op); //op = op.Trim (); op = op.ToLower (); if (AndTerm.Operators.Contains (op)) { //Console.WriteLine ("AND!"); return new AndTerm (parent, after); } else if (OrTerm.Operators.Contains (op)) { //Console.WriteLine ("OR!"); return new OrTerm (parent, after); } Console.WriteLine ("Do not have Term for operator {0}", op); return null; }
private void InsertTerm (Term parent, Literal after) { if (Literal.FocusedLiterals.Count != 0) { HandleLiteralsMoved (Literal.FocusedLiterals, parent, after); // Prevent them from being removed again Literal.FocusedLiterals = null; } else InsertTerm (tag_selection_widget.TagHighlight, parent, after); }
public void Remove (Term term) { SubTerms.Remove (term); // Remove ourselves if we're now empty if (SubTerms.Count == 0) if (Parent != null) Parent.Remove (this); }
public ArrayList InsertTerm (Tag [] tags, Term parent, Literal after) { int position; if (after != null) position = WidgetPosition (after.Widget) + 1; else position = Children.Length - 1; ArrayList added = new ArrayList (); foreach (Tag tag in tags) { //Console.WriteLine ("Adding tag {0}", tag.Name); // Don't put a tag into a Term twice if (parent != Root && (parent.FindByTag (tag, true)).Count > 0) continue; if (parent.Count > 0) { Widget sep = parent.SeparatorWidget (); InsertWidget (position, sep); position++; } // Encapsulate new OR terms within a new AND term of which they are the // only member, so later other terms can be AND'd with them // // TODO should really see what type of term the parent is, and // encapsulate this term in a term of the opposite type. This will // allow the query system to be expanded to work for multiple levels much easier. if (parent == rootTerm) { parent = new AndTerm (rootTerm, after); after = null; } Literal term = new Literal (parent, tag, after); term.TermAdded += HandleTermAdded; term.LiteralsMoved += HandleLiteralsMoved; term.AttachTag += HandleAttachTag; term.NegatedToggled += HandleNegated; term.Removing += HandleRemoving; term.Removed += HandleRemoved; term.RequireTag += Require; term.UnRequireTag += UnRequire; added.Add (term); // Insert this widget into the appropriate place in the hbox InsertWidget (position, term.Widget); } UpdateQuery (); return added; }
public void CopyAndInvertSubTermsFrom (Term term, bool recurse) { is_negated = true; ArrayList termsToMove = new ArrayList(term.SubTerms); foreach (Term subterm in termsToMove) { if (recurse) subterm.Invert(true).Parent = this; else subterm.Parent = this; } }