Exemple #1
0
        public bool AddTagToNote(string uri, string tag_name)
        {
            if (note_manager.ReadOnly)
            {
                return(false);
            }
            Note note = note_manager.FindByUri(uri);

            if (note == null)
            {
                return(false);
            }
            Tag tag = TagManager.GetOrCreateTag(tag_name);

            note.AddTag(tag);
            note.QueueSave(ChangeType.OtherDataChanged);
            return(true);
        }
        /// <summary>
        /// Get the existing template note or create a new one
        /// if it doesn't already exist.
        /// </summary>
        /// <returns>
        /// A <see cref="Note"/>
        /// </returns>
        public Note GetOrCreateTemplateNote()
        {
            // The default template note will have the system template tag and
            // will belong to zero notebooks. We find this by searching all
            // notes with the TemplateNoteSystemTag and check that it's
            // notebook == null
            Note template_note = null;
            Tag  template_tag  = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag);

            foreach (Note note in template_tag.Notes)
            {
                if (Notebooks.NotebookManager.GetNotebookFromNote(note) == null)
                {
                    template_note = note;
                    break;
                }
            }

            if (template_note == null)
            {
                template_note =
                    Create(NoteTemplateTitle,
                           GetNoteTemplateContent(NoteTemplateTitle));

                // Select the initial text
                NoteBuffer   buffer = template_note.Buffer;
                Gtk.TextIter iter   = buffer.GetIterAtLineOffset(2, 0);
                buffer.MoveMark(buffer.SelectionBound, iter);
                buffer.MoveMark(buffer.InsertMark, buffer.EndIter);

                // Flag this as a template note
                template_note.AddTag(template_tag);

                template_note.QueueSave(ChangeType.ContentChanged);
            }

            return(template_note);
        }
Exemple #3
0
        IEnumerable <Gtk.MenuItem> CurrentMenuItems()
        {
            Gtk.ImageMenuItem item;

            item            = new Gtk.ImageMenuItem(Catalog.GetString("Create New Note"));
            item.Image      = new Gtk.Image(Gtk.Stock.New, Gtk.IconSize.Menu);
            item.Activated += (o, a) => Tomboy.ActionManager["NewNoteAction"].Activate();
            item.Activated += (o, a) => SetMenuItems();
            yield return(item);

            item            = new Gtk.ImageMenuItem(Catalog.GetString("_Search All Notes"));
            item.Image      = new Gtk.Image(Gtk.Stock.Find, Gtk.IconSize.Menu);
            item.Activated += (o, a) => Tomboy.ActionManager["ShowSearchAllNotesAction"].Activate();
            yield return(item);

            yield return(new Gtk.SeparatorMenuItem());

            if (manager != null && manager.Notes != null)
            {
                Tag template_tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag);
                var menuItems    = manager.Notes
                                   .Where(n => !n.IsSpecial && !n.ContainsTag(template_tag))
                                   .OrderByDescending(n => n.ChangeDate)
                                   .Take(10)
                                   .Select(n => CreateNoteMenuItem(n))
                                   .ToArray();
                // avoid lazy eval for menu item construction

                foreach (Gtk.MenuItem mi in menuItems)
                {
                    yield return(mi);
                }
            }

            yield return(new Gtk.SeparatorMenuItem());

            Gtk.MenuItem mitem = new Gtk.MenuItem(Catalog.GetString("S_ynchronize Notes"));
            // setting this changes the menu text to "Convert"
            // item.Image = new Gtk.Image (Gtk.Stock.Convert, Gtk.IconSize.Menu);
            mitem.Activated += (o, a) => Tomboy.ActionManager["NoteSynchronizationAction"].Activate();
            yield return(mitem);

            item            = new Gtk.ImageMenuItem(Catalog.GetString("_Preferences"));
            item.Image      = new Gtk.Image(Gtk.Stock.Preferences, Gtk.IconSize.Menu);
            item.Activated += (o, a) => Tomboy.ActionManager["ShowPreferencesAction"].Activate();
            yield return(item);

            item            = new Gtk.ImageMenuItem(Catalog.GetString("_Help"));
            item.Image      = new Gtk.Image(Gtk.Stock.Help, Gtk.IconSize.Menu);
            item.Activated += (o, a) => Tomboy.ActionManager["ShowHelpAction"].Activate();
            yield return(item);

            item            = new Gtk.ImageMenuItem(Catalog.GetString("_About Tomboy"));
            item.Image      = new Gtk.Image(Gtk.Stock.About, Gtk.IconSize.Menu);
            item.Activated += (o, a) => Tomboy.ActionManager["ShowAboutAction"].Activate();
            yield return(item);

            yield return(new Gtk.SeparatorMenuItem());

            item            = new Gtk.ImageMenuItem(Catalog.GetString("_Quit"));
            item.Image      = new Gtk.Image(Gtk.Stock.Quit, Gtk.IconSize.Menu);
            item.Activated += (o, a) => Tomboy.ActionManager["QuitTomboyAction"].Activate();
            yield return(item);
        }
Exemple #4
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);
        }
Exemple #5
0
        private static void AddRecentNotes(ICustomDestinationList custom_destinationd_list, NoteManager note_manager, uint slots)
        {
            IObjectCollection object_collection =
                (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID.EnumerableObjectCollection));

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

            uint index = 0;

            foreach (Note note in note_manager.Notes)
            {
                if (note.IsSpecial)
                {
                    continue;
                }

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

                string note_title = note.Title;
                if (note.IsNew)
                {
                    note_title = String.Format(Catalog.GetString("{0} (new)"), note_title);
                }

                IShellLink note_link = CreateShellLink(note_title, tomboy_path, "--open-note " + note.Uri,
                                                       System.IO.Path.Combine(icons_path, NoteIcon), -1);
                if (note_link != null)
                {
                    object_collection.AddObject(note_link);
                }

                if (++index == slots - 1)
                {
                    break;
                }
            }

            // Add Start Here note
            Note start_note = note_manager.FindByUri(NoteManager.StartNoteUri);

            if (start_note != null)
            {
                IShellLink start_note_link = CreateShellLink(start_note.Title, tomboy_path, "--open-note " +
                                                             NoteManager.StartNoteUri,
                                                             System.IO.Path.Combine(icons_path, NoteIcon), -1);
                if (start_note_link != null)
                {
                    object_collection.AddObject(start_note_link);
                }
            }

            custom_destinationd_list.AppendCategory(Catalog.GetString("Recent Notes"), (IObjectArray)object_collection);

            Marshal.ReleaseComObject(object_collection);
            object_collection = null;
        }