Наследование: Gtk.ImageMenuItem
Пример #1
0
        public void AddRecentlyChangedNotes()
        {
            int min_size = (int)Preferences.Get(Preferences.MENU_NOTE_COUNT);
            int max_size = (int)Preferences.Get(Preferences.MENU_MAX_NOTE_COUNT);

            if (max_size < min_size)
            {
                max_size = min_size;
            }
            int          list_size       = 0;
            bool         menuOpensUpward = tray.MenuOpensUpward();
            NoteMenuItem item;

            // Remove the old dynamic items
            RemoveRecentlyChangedNotes();

            // Assume menu opens downward, move common items to top of menu
            Gtk.MenuItem newNoteItem = Tomboy.ActionManager.GetWidget(
                "/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote") as Gtk.MenuItem;
            Gtk.MenuItem searchNotesItem = Tomboy.ActionManager.GetWidget(
                "/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
            tray_menu.ReorderChild(newNoteItem, 0);
            int insertion_point = 1;             // If menu opens downward

            // Find all child widgets under the TrayNewNotePlaceholder
            // element.  Make sure those added by add-ins are
            // properly accounted for and reordered.
            List <Gtk.Widget>  newNotePlaceholderWidgets = new List <Gtk.Widget> ();
            IList <Gtk.Widget> allChildWidgets           =
                Tomboy.ActionManager.GetPlaceholderChildren("/TrayIconMenu/TrayNewNotePlaceholder");

            foreach (Gtk.Widget child in allChildWidgets)
            {
                if (child is Gtk.MenuItem &&
                    child != newNoteItem)
                {
                    newNotePlaceholderWidgets.Add(child);
                    tray_menu.ReorderChild(child, insertion_point);
                    insertion_point++;
                }
            }

            tray_menu.ReorderChild(searchNotesItem, insertion_point);
            insertion_point++;

            DateTime days_ago = DateTime.Today.AddDays(-3);

            // Prevent template notes from appearing in the menu
            Tag template_tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag);

            // List the most recently changed notes, any currently
            // opened notes, and any pinned notes...
            foreach (Note note in manager.Notes)
            {
                if (note.IsSpecial)
                {
                    continue;
                }

                // Skip template notes
                if (note.ContainsTag(template_tag))
                {
                    continue;
                }

                bool show = false;

                // Test for note.IsPinned first so that all of the pinned notes
                // are guaranteed to be included regardless of the size of the
                // list.
                if (note.IsPinned)
                {
                    show = true;
                }
                else if ((note.IsOpened && note.Window.IsMapped) ||
                         note.ChangeDate > days_ago ||
                         list_size < min_size)
                {
                    if (list_size <= max_size)
                    {
                        show = true;
                    }
                }

                if (show)
                {
                    item = new NoteMenuItem(note, true);
                    // Add this widget to the menu (+insertion_point to add after new+search+...)
                    tray_menu.Insert(item, list_size + insertion_point);
                    // Keep track of this item so we can remove it later
                    recent_notes.Add(item);

                    list_size++;
                }
            }

            Note start = manager.FindByUri(NoteManager.StartNoteUri);

            if (start != null)
            {
                item = new NoteMenuItem(start, false);
                if (menuOpensUpward)
                {
                    tray_menu.Insert(item, list_size + insertion_point);
                }
                else
                {
                    tray_menu.Insert(item, insertion_point);
                }
                recent_notes.Add(item);

                list_size++;

                bool enable_keybindings = (bool)
                                          Preferences.Get(Preferences.ENABLE_KEYBINDINGS);
                if (enable_keybindings)
                {
                    GConfKeybindingToAccel.AddAccelerator(
                        item,
                        Preferences.KEYBINDING_OPEN_START_HERE);
                }
            }


            // FIXME: Rearrange this stuff to have less wasteful reordering
            if (menuOpensUpward)
            {
                // Relocate common items to bottom of menu
                insertion_point -= 1;
                tray_menu.ReorderChild(searchNotesItem, list_size + insertion_point);
                foreach (Gtk.Widget widget in newNotePlaceholderWidgets)
                {
                    tray_menu.ReorderChild(widget, list_size + insertion_point);
                }
                tray_menu.ReorderChild(newNoteItem, list_size + insertion_point);
                insertion_point = list_size;
            }

            Gtk.SeparatorMenuItem separator = new Gtk.SeparatorMenuItem();
            tray_menu.Insert(separator, insertion_point);
            recent_notes.Add(separator);
        }
Пример #2
0
		public void AddRecentlyChangedNotes ()
		{
			int min_size = (int) Preferences.Get (Preferences.MENU_NOTE_COUNT);
			int max_size = (int) Preferences.Get (Preferences.MENU_MAX_NOTE_COUNT);
			if (max_size < min_size)
				max_size = min_size;
			int list_size = 0;
			bool menuOpensUpward = tray.MenuOpensUpward ();
			NoteMenuItem item;

			// Remove the old dynamic items
			RemoveRecentlyChangedNotes ();

			// Assume menu opens downward, move common items to top of menu
			Gtk.MenuItem newNoteItem = Tomboy.ActionManager.GetWidget (
			                                   "/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote") as Gtk.MenuItem;
			Gtk.MenuItem searchNotesItem = Tomboy.ActionManager.GetWidget (
			                                       "/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
			tray_menu.ReorderChild (newNoteItem, 0);
			int insertion_point = 1; // If menu opens downward
			
			// Find all child widgets under the TrayNewNotePlaceholder
			// element.  Make sure those added by add-ins are
			// properly accounted for and reordered.
			List<Gtk.Widget> newNotePlaceholderWidgets = new List<Gtk.Widget> ();
			IList<Gtk.Widget> allChildWidgets =
				Tomboy.ActionManager.GetPlaceholderChildren ("/TrayIconMenu/TrayNewNotePlaceholder");
			foreach (Gtk.Widget child in allChildWidgets) {
				if (child is Gtk.MenuItem &&
				    child != newNoteItem) {
					newNotePlaceholderWidgets.Add (child);
					tray_menu.ReorderChild (child, insertion_point);
					insertion_point++;
				}
			}
			
			tray_menu.ReorderChild (searchNotesItem, insertion_point);
			insertion_point++;

			DateTime days_ago = DateTime.Today.AddDays (-3);
			
			// Prevent template notes from appearing in the menu
			Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);

			// List the most recently changed notes, any currently
			// opened notes, and any pinned notes...
			foreach (Note note in manager.Notes) {
				if (note.IsSpecial)
					continue;
				
				// Skip template notes
				if (note.ContainsTag (template_tag))
					continue;

				bool show = false;

				// Test for note.IsPinned first so that all of the pinned notes
				// are guaranteed to be included regardless of the size of the
				// list.
				if (note.IsPinned) {
					show = true;
				} else if ((note.IsOpened && note.Window.IsMapped) ||
				                note.ChangeDate > days_ago ||
				                list_size < min_size) {
					if (list_size <= max_size)
						show = true;
				}

				if (show) {
					item = new NoteMenuItem (note, true);
					// Add this widget to the menu (+insertion_point to add after new+search+...)
					tray_menu.Insert (item, list_size + insertion_point);
					// Keep track of this item so we can remove it later
					recent_notes.Add (item);

					list_size++;
				}
			}

			Note start = manager.FindByUri (NoteManager.StartNoteUri);
			if (start != null) {
				item = new NoteMenuItem (start, false);
				if (menuOpensUpward)
					tray_menu.Insert (item, list_size + insertion_point);
				else
					tray_menu.Insert (item, insertion_point);
				recent_notes.Add (item);

				list_size++;
				
				bool enable_keybindings = (bool)
					                  Preferences.Get (Preferences.ENABLE_KEYBINDINGS);
				if (enable_keybindings)
					GConfKeybindingToAccel.AddAccelerator (
					        item,
					        Preferences.KEYBINDING_OPEN_START_HERE);
			}


			// FIXME: Rearrange this stuff to have less wasteful reordering
			if (menuOpensUpward) {
				// Relocate common items to bottom of menu
				insertion_point -= 1;
				tray_menu.ReorderChild (searchNotesItem, list_size + insertion_point);
				foreach (Gtk.Widget widget in newNotePlaceholderWidgets)
					tray_menu.ReorderChild (widget, list_size + insertion_point);
				tray_menu.ReorderChild (newNoteItem, list_size + insertion_point);
				insertion_point = list_size;
			}

			Gtk.SeparatorMenuItem separator = new Gtk.SeparatorMenuItem ();
			tray_menu.Insert (separator, insertion_point);
			recent_notes.Add (separator);
		}