public void Activate (Gdk.EventButton eb, Literal literal, Gtk.Menu popup_menu, bool is_popup)
		{
			//this.literal = literal;

			/*MenuItem attach_item = new MenuItem (Catalog.GetString ("Find With"));
			TagMenu attach_menu = new TagMenu (attach_item, MainWindow.Toplevel.Database.Tags);
			attach_menu.TagSelected += literal.HandleAttachTagCommand;
			attach_item.ShowAll ();
			popup_menu.Append (attach_item);*/

			if (literal.IsNegated) {
				GtkUtil.MakeMenuItem (popup_menu,
						      String.Format (Catalog.GetString ("Include Photos Tagged \"{0}\""), literal.Tag.Name),
						      new EventHandler (literal.HandleToggleNegatedCommand),
						      true);
			} else {
				GtkUtil.MakeMenuItem (popup_menu,
						      String.Format (Catalog.GetString ("Exclude Photos Tagged \"{0}\""), literal.Tag.Name),
						      new EventHandler (literal.HandleToggleNegatedCommand),
						      true);
			}

			GtkUtil.MakeMenuItem (popup_menu, Catalog.GetString ("Remove From Search"),
					      "gtk-remove",
					      new EventHandler (literal.HandleRemoveCommand),
					      true);

			if (is_popup) {
				if (eb != null)
					popup_menu.Popup (null, null, null, eb.Button, eb.Time);
				else
					popup_menu.Popup (null, null, null, 0, Gtk.Global.CurrentEventTime);
			}
		}
		public LiteralMenu (MenuItem item, Literal literal)
		{
			popup = new LiteralPopup ();

			this.literal = literal;

			item.Submenu = this;
			item.Activated += HandlePopulate;
		}
Example #3
0
		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 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);
		}
		private void HandleRemoved (Literal group)
		{
			UpdateQuery ();
		}
		public ArrayList HangersOn (Literal term)
		{
			ArrayList w = new ArrayList ();

			// Find separators that only exist because of this term
			if (term.Parent != null) {
				if (term.Parent.Count > 1)
				{
					if (term == term.Parent.Last)
						w.Add (Children[WidgetPosition (term.Widget) - 1]);
					else
						w.Add (Children[WidgetPosition (term.Widget) + 1]);
				}
				else if (term.Parent.Count == 1)
				{
					if (term.Parent.Parent != null) {
						if (term.Parent.Parent.Count > 1) {
							if (term.Parent == term.Parent.Parent.Last)
								w.Add (Children[WidgetPosition (term.Widget) - 1]);
							else
								w.Add (Children[WidgetPosition (term.Widget) + 1]);
						}
					}
				}
			}
			return w;
		}
		private void HandleRemoving (Literal term)
		{
			foreach (Widget w in HangersOn (term))
			Remove (w);

			// Remove the term's widget
			Remove (term.Widget);
		}
		private void HandleNegated (Literal group)
		{
			UpdateQuery ();
		}
		private void HandleAttachTag (Tag tag, Term parent, Literal after)
		{
			InsertTerm (new Tag [] {tag}, parent, after);
		}
Example #10
0
		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 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 Literal literal;

		public void Activate (Gdk.EventButton eb, Literal literal)
		{
			Activate (eb, literal, new Gtk.Menu (), true);
		}
Example #13
0
		public Literal (Term parent, Tag tag, Literal after) : base (parent, after) {
			this.tag = tag;
		}
Example #14
0
		public AbstractLiteral(Term parent, Literal after) : base (parent, after) {}
Example #15
0
		public OrTerm (Term parent, Literal after) : base (parent, after) {}
Example #16
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;
		}
		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;
		}
		private void HandleTermAdded (Term parent, Literal after)
		{
			InsertTerm (parent, after);
		}