Beispiel #1
0
        private void CreateNotebook(object arg)
        {
            MainWindowInstance.ShowInputAsync("Add notebook", "Name:").ContinueWith(delegate(Task <string> task)
            {
                string newName = task.Result;
                if (string.IsNullOrEmpty(newName))
                {
                    return;
                }

                Notebook nb = new Notebook
                {
                    Name      = newName,
                    Created   = DateTime.Now,
                    SortIndex = 0
                };
                nb.Save();
                var item = new NotebookMenuItem(nb);

                List <NotebookMenuItem> temp = new List <NotebookMenuItem>();
                temp.AddRange(MenuContext.Notebooks.ToArray());
                temp.Add(item);
                temp.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));

                MenuContext.Notebooks.Clear();
                temp.ForEach(MenuContext.Notebooks.Add);

                MenuContext.SelectedNotebook            = item;
                MenuContext.SelectedNotebook.IsSelected = true;
            });
        }
Beispiel #2
0
        private void InitMainMenu()
        {
            List <NotebookMenuItem> items = new List <NotebookMenuItem>();

            foreach (Notebook notebook in Hub.Instance.Storage.GetNotebooks())
            {
                var item = new NotebookMenuItem(notebook);
                NotebookMenuItems.Add(item);
                items.Add(item);
            }

            items.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal));

            MenuContext = new NotebookMenuViewModel
            {
                Notebooks = new ObservableCollection <NotebookMenuItem>(items),
                SelectedItemChangedCommand = new SimpleCommand(SelectedNoteContainerChanged),
                RenameItemCommand          = new SimpleCommand(RenameItem),
                DeleteItemCommand          = new SimpleCommand(DeleteItem),
                AddNotebookCommand         = new SimpleCommand(CreateNotebook),
                EmptyTrashCommand          = new SimpleCommand(EmptyTrash),
                PasteNoteCommand           = new SimpleCommand(PasteNote)
            };

            if (!Hub.Instance.EncryptionManager.SecureNotesEnabled && items.Any())
            {
                MenuContext.SelectedNotebook            = items[0];
                MenuContext.SelectedNotebook.IsSelected = true;
            }

            BindingOperations.EnableCollectionSynchronization(MenuContext.Notebooks, _mainMenuListLockObject);
        }
		List<NotebookMenuItem> GetNotebookMenuItems ()
		{
			List<NotebookMenuItem> items = new List<NotebookMenuItem> ();
			
			Gtk.TreeModel model = NotebookManager.Notebooks;
			Gtk.TreeIter iter;
			
			if (model.GetIterFirst (out iter) == true) {
				do {
					Notebook notebook = model.GetValue (iter, 0) as Notebook;
					NotebookMenuItem item = new NotebookMenuItem (Note, notebook);
					items.Add (item);
				} while (model.IterNext (ref iter) == true);
			}
			
			items.Sort ();
			
			return items;
		}
		void UpdateMenu ()
		{
			//
			// Clear out the old list
			//
			foreach (Gtk.MenuItem oldItem in menu.Children) {
				menu.Remove (oldItem);
			}

			//
			// Build a new menu
			//
			
			// Add the "New Notebook..."
			Gtk.ImageMenuItem newNotebookMenuItem =
				new Gtk.ImageMenuItem (Catalog.GetString ("_New notebook..."));
			newNotebookMenuItem.Image = new Gtk.Image (NewNotebookIcon);
			newNotebookMenuItem.Activated += OnNewNotebookMenuItem;
			newNotebookMenuItem.Show ();
			menu.Append (newNotebookMenuItem);
			
			// Add the "(no notebook)" item at the top of the list
			NotebookMenuItem noNotebookMenuItem = new NotebookMenuItem (Note, null);
			noNotebookMenuItem.ShowAll ();
			menu.Append (noNotebookMenuItem);
			
			// Add in all the real notebooks
			List<NotebookMenuItem> notebookMenuItems = GetNotebookMenuItems ();
			if (notebookMenuItems.Count > 0) {
				Gtk.SeparatorMenuItem separator = new Gtk.SeparatorMenuItem ();
				separator.ShowAll ();
				menu.Append (separator);
				
				foreach (NotebookMenuItem item in GetNotebookMenuItems ()) {
					item.ShowAll ();
					menu.Append (item);
				}
			}
		}