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 }; nb.Save(); var newNotebook = ViewModelLocator.Instance.GetNotebookViewModel(nb); List <NotebookViewModel> temp = new List <NotebookViewModel>(); temp.AddRange(Notebooks.ToArray()); temp.Add(newNotebook); temp.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal)); Notebooks.Clear(); temp.ForEach(Notebooks.Add); SelectedNotebook = newNotebook; SelectedNotebook.IsSelected = true; }); }
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; }); }
private void CreateNewSecureNote() { if (!Hub.Instance.EncryptionManager.SecureNotesEnabled) { MainWindowInstance.ShowMessageAsync("Secure notes", "To create secure notes you need to activate this function in settings."); return; } CreateNewNote(true); }
private void CreateNewNote(bool secure) { var settings = DialogHelpers.GetDefaultDialogSettings(); MainWindowInstance.ShowInputAsync("New note", "Name of the new note:", settings).ContinueWith(delegate(Task <string> task) { string name = task.Result; if (!string.IsNullOrWhiteSpace(name)) { CreateNewNote(name, secure); } }); }
private void DeleteCurrentNoteBook() { if (MenuContext.SelectedNotebook != null) { var notes = Hub.Instance.Storage.GetNotes(MenuContext.SelectedNotebook.Notebook); if (!notes.Any()) { var settings = DialogHelpers.GetDefaultDialogSettings(); if (MenuContext.Notebooks.Count == 1) { MainWindowInstance.ShowMessageAsync("Delete", "You can't delete the last notebook, rename it if the name is wrong.", MessageDialogStyle.Affirmative, settings); return; } MainWindowInstance.ShowMessageAsync("Delete", $"Do you want to delete the notebook {MenuContext.SelectedNotebook.Name}?", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task <MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) { InvokeOnCurrentDispatcher(() => { int index = MenuContext.Notebooks.IndexOf(MenuContext.SelectedNotebook); if (index >= MenuContext.Notebooks.Count - 1) { index--; } MenuContext.SelectedNotebook.Notebook.Delete(); if (MenuContext.Notebooks.Contains(MenuContext.SelectedNotebook)) { MenuContext.Notebooks.Remove(MenuContext.SelectedNotebook); } if (NotebookMenuItems.Contains(MenuContext.SelectedNotebook)) { NotebookMenuItems.Remove(MenuContext.SelectedNotebook); } MenuContext.SelectedNotebook = MenuContext.Notebooks[index]; }); } }); } else { MainWindowInstance.ShowMessageAsync("Delete", "You can't delete a notebook that contains notes."); } } }
private void DeleteLibrary() { var settings = DialogHelpers.GetDefaultDialogSettings(); var message = $"Do you want to delete the library '{Library.Name}'?\nAll files will be left untouched, it's just the connection that is removed."; MainWindowInstance.ShowMessageAsync("Delete library", message, MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task<MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) InvokeOnCurrentDispatcher(() => { Hub.Instance.AppSettings.Librarys.Remove(Library); Library.Delete(); }); }); }
public static void CloseEverything() { MainPanelInstance = null; BackUpLoginGridContent = null; BackgroundGrid = null; BackUpMainPanel = null; CurrentUser = null; MainWindowInstance.CloseApp(); MainWindowInstance = null; //new SplashScreen() //{ // Visibility = System.Windows.Visibility.Visible //}; }
private void RenameNote() { // TODO: i18n string name = Note.Name; var settings = DialogHelpers.GetDefaultDialogSettings(); settings.DefaultText = name; MainWindowInstance.ShowInputAsync("Rename", "Enter new name:", settings).ContinueWith(delegate(Task <string> task) { string newName = task.Result; if (!string.IsNullOrWhiteSpace(newName)) { Note.Name = newName; //NoteMenuContext.SelectedNote.Note.Save(); } }); }
private void CopyNote() { if (Note.Encrypted) { var settings = DialogHelpers.GetDefaultDialogSettings(); MainWindowInstance.ShowMessageAsync(Properties.Resources.Note_Copy_SecureTitle, Properties.Resources.Note_Copy_SecureText, MessageDialogStyle.AffirmativeAndNegative, settings). ContinueWith(delegate(Task <MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) { DoCopyNote(Note); } }); } else { DoCopyNote(Note); } }
private SecureString SystemNeedsEncryptionPassword() { //string password = "******"; Task <SecureString> pass = MainWindowInstance.ShowInputAsync("Password required", "Password:"******"Password required."); }); if (pass?.Result == null) { throw new Exception("Password required."); } return(pass.Result); }
private void DeleteNote(DeleteNote message) { // TODO: i18n if (SelectedNote == null || SelectedNote != message.Note) { return; } Note note = SelectedNote.Note; if (note.InTrashCan) { return; } if (note.Protected) { MessengerInstance.Send(new QuickMessage("You cant delete this note, it's protected from that.")); return; } var settings = DialogHelpers.GetDefaultDialogSettings(); MainWindowInstance.ShowMessageAsync("Delete", $"Do you want to delete {note.Name}?", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task <MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) { InvokeOnCurrentDispatcher(() => { note.InTrashCan = true; DataSource.Remove(SelectedNote); SelectedNote = DataSource.FirstOrDefault(); Hub.Instance.Settings.RefreshTags(); }); } }); }
private void EmptyTrash(object arg) { var settings = DialogHelpers.GetDefaultDialogSettings(); MainWindowInstance.ShowMessageAsync("Empty trash", "Do you want to delete all notes in the trashcan?\nThis operation can not be undone.", MessageDialogStyle.AffirmativeAndNegative, settings). ContinueWith(delegate(Task <MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) { // TODO: Send empty trash message instead foreach (NoteViewModel n in ViewModelLocator.Instance.NoteMenu.DataSource) { Guid noteId = n.Note.ID; ViewModelLocator.Instance.Unregister(noteId.ToString()); n.Note.Delete(); } ViewModelLocator.Instance.NoteMenu.SelectedNote = null; ViewModelLocator.Instance.NoteMenu.DataSource.Clear(); } }); }
private void DeleteCurrentNote() { if (SelectedMenuItem == _trashLibraryMenuItem) { return; } if (NoteMenuContext.SelectedNote.Note.Protected) { ShowQuickMessage("You cant delete this note, it's protected from that."); return; } var settings = DialogHelpers.GetDefaultDialogSettings(); MainWindowInstance.ShowMessageAsync("Delete", $"Do you want to delete {NoteMenuContext.SelectedNote.Note.Name}?", MessageDialogStyle.AffirmativeAndNegative, settings).ContinueWith(delegate(Task <MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) { InvokeOnCurrentDispatcher(() => { Guid noteId = NoteMenuContext.SelectedNote.Note.ID; if (NoteViewModels.ContainsKey(noteId)) { //NoteMenuContext.SelectedNote.Note.Delete(); NoteMenuContext.SelectedNote.Note.InTrashCan = true; //NoteMenuContext.SelectedNote.Note.Save(); var nvm = NoteViewModels[noteId]; NoteViewModels.Remove(noteId); NoteMenuContext.DataSource.Remove(nvm); NoteMenuContext.SelectedNote = NoteMenuContext.DataSource.FirstOrDefault(); Hub.Instance.Settings.RefreshTags(); } }); } }); }
private void RenameFile(object obj) { NoteFile nf = SelectedNoteFile; if (nf != null) { string name = nf.Name; var settings = DialogHelpers.GetDefaultDialogSettings(); settings.DefaultText = name; MainWindowInstance.ShowInputAsync("Rename", "Enter new name:", settings).ContinueWith(delegate(Task <string> task) { string newName = task.Result; if (task.IsCanceled) { return; } if (!string.IsNullOrWhiteSpace(newName)) { var existingNoteFile = Note.Files.FirstOrDefault(enf => enf.Name.Equals(newName)); if (existingNoteFile == null) { nf.Name = newName; Note.DecryptedText = Note.DecryptedText.Replace($"[!{name}]", $"[!{newName}]"); IsDirty = true; } else { InvokeOnCurrentDispatcher(() => { MainWindowInstance.ShowMessageAsync("Error", "You already have a file in this note called " + newName); RenameFile(obj); }); } } }); } }
private void EmptyTrash(object arg) { var settings = DialogHelpers.GetDefaultDialogSettings(); MainWindowInstance.ShowMessageAsync("Empty trash", "Do you want to delete all notes in the trashcan?\nThis operation can not be undone.", MessageDialogStyle.AffirmativeAndNegative, settings). ContinueWith(delegate(Task <MessageDialogResult> task) { if (task.Result == MessageDialogResult.Affirmative) { foreach (NoteViewModel n in NoteMenuContext.DataSource) { Guid noteId = n.Note.ID; if (NoteViewModels.ContainsKey(noteId)) { n.Note.Delete(); NoteViewModels.Remove(noteId); } } NoteMenuContext.SelectedNote = null; NoteMenuContext.DataSource.Clear(); } }); }
/// <inheritdoc /> public MainWindow() { InitializeComponent(); var dispatcherTimer = new DispatcherTimer(); IMainWindowInstance mainWindowInstance = new MainWindowInstance(this); IAppSettingFromConfigurationManager appSettingFromConfigurationManager = new AppSettingFromConfigurationManager(); ITaskbarIconInstance taskbarIconInstance = new TaskbarIconInstance(AvailabilityHandlerTaskbarIcon); ITaskbarIconContextMenu taskbarIconContextMenu = new TaskbarIconContextMenu(mainWindowInstance, taskbarIconInstance); ITaskbarIconConfiguration taskbarIconConfiguration = new TaskbarIconConfiguration(mainWindowInstance, taskbarIconInstance, taskbarIconContextMenu); ILyncClientInstance lyncClientInstance = new CachedLyncClientInstance(); ILyncAvailability lyncAvailability = new LyncAvailability(lyncClientInstance); IApplicationList applicationList = new CachedApplicationList(appSettingFromConfigurationManager); IIsProcessRunning isProcessRunning = new IsProcessRunning(); IDispatcherTimerTick dispatcherTimerTick = new DispatcherTimerTick(lyncClientInstance, lyncAvailability, applicationList, isProcessRunning); IDispatcherTimerInstance dispatcherTimerInstance = new DispatcherTimerInstance(dispatcherTimer, dispatcherTimerTick); IProcessDispatcherHandler processDispatcherHandler = new ProcessDispatcherHandler(dispatcherTimerInstance); IAutoStart autoStart = new AutoStart(Title, Assembly.GetExecutingAssembly().Location); IAutoStartByConfiguration autoStartByConfiguration = new AutoStartByConfiguration(appSettingFromConfigurationManager, autoStart); processDispatcherHandler.Run(); taskbarIconConfiguration.Run(); autoStartByConfiguration.Run(); }
private void RenameItem(object arg) { if (SelectedMenuItem is TagViewModel) { return; } string name = SelectedMenuItem.Name; var settings = DialogHelpers.GetDefaultDialogSettings(); settings.DefaultText = name; MainWindowInstance.ShowInputAsync("Rename", "Enter new name:", settings).ContinueWith(delegate(Task <string> task) { string newName = task.Result; if (!string.IsNullOrWhiteSpace(newName)) { if (SelectedMenuItem is NotebookViewModel) { SelectedNotebook.Notebook.Name = newName; SelectedNotebook.Notebook.Save(); } } }); }
public void Execute(UIApplication app) { try { CurrentDocument = app.ActiveUIDocument.Document; switch (MoverRequest.Take()) { case RequestId.SelectLinkInstance: MainWindowInstance.DozeOff(); var picked = PickLinkInstance(out selectedLink); if (picked) { MainWindowInstance.DisplayCategories(selectedLink); } MainWindowInstance.WakeUp(); break; case RequestId.DuplicateElements: MainWindowInstance.DozeOff(); try { selectedLink = ElementMoverUtil.DuplicateSelectedCategories(selectedLink, CurrentDocument, SelectedUpdateMode); if (LinkInstances.ContainsKey(selectedLink.InstanceId)) { LinkInstances.Remove(selectedLink.InstanceId); } LinkInstances.Add(selectedLink.InstanceId, selectedLink); MainWindowInstance.UpdateLinkedInstanceProperties(); } catch (Exception ex) { var message = ex.Message; } MainWindowInstance.WakeUp(); break; case RequestId.SelectMappingElements: MappingWindowInstance.DozeOff(); Element sourceElement = null; Element targetElement = null; var pickedMap = PickMappingElements(out sourceElement, out targetElement); if (pickedMap) { if (LinkInstances.ContainsKey(selectedLink.InstanceId)) { LinkInstances.Remove(selectedLink.InstanceId); } LinkInstances.Add(selectedLink.InstanceId, selectedLink); MappingWindowInstance.RefreshLinkInstance(); } MappingWindowInstance.WakeUp(); break; case RequestId.DeleteMappingElements: MappingWindowInstance.DozeOff(); if (LinkedElementToDelete.Count > 0) { using (var trans = new Transaction(CurrentDocument)) { trans.Start("Delete Element Maps"); try { foreach (var linkedInfo in LinkedElementToDelete) { if (selectedLink.LinkedElements.ContainsKey(linkedInfo.LinkedElementId)) { selectedLink.LinkedElements.Remove(linkedInfo.LinkedElementId); var linkedElement = CurrentDocument.GetElement(linkedInfo.LinkedElementId); if (null != linkedElement) { var removed = MoverDataStorageUtil.RemoveLinkedElementInfo(linkedElement); } } } trans.Commit(); if (LinkInstances.ContainsKey(selectedLink.InstanceId)) { LinkInstances.Remove(selectedLink.InstanceId); LinkInstances.Add(selectedLink.InstanceId, selectedLink); } } catch (Exception ex) { trans.RollBack(); MessageBox.Show("Failed to delete element maps.\n" + ex.Message, "Delete Element Maps", MessageBoxButton.OK, MessageBoxImage.Warning); } } MappingWindowInstance.RefreshLinkInstance(); } MappingWindowInstance.WakeUp(); break; case RequestId.ShowElement: MappingWindowInstance.DozeOff(); if (null != SelectedLinkedInfo) { if (null != CurrentDocument.GetElement(SelectedLinkedInfo.LinkedElementId)) { HighlightElement(); } } MappingWindowInstance.WakeUp(); break; case RequestId.AddFamilyMapping: FamilyWindowInstance.DozeOff(); if (null != SelectedFamilyInfo) { var tType = CurrentDocument.GetElement(SelectedFamilyInfo.TargetTypeId) as ElementType; if (null != tType) { using (var trans = new Transaction(CurrentDocument)) { trans.Start("Add Family Map"); try { if (selectedLink.LinkedFamilies.ContainsKey(SelectedFamilyInfo.TargetTypeId)) { selectedLink.LinkedFamilies.Remove(SelectedFamilyInfo.TargetTypeId); } selectedLink.LinkedFamilies.Add(SelectedFamilyInfo.TargetTypeId, SelectedFamilyInfo); var updated = MoverDataStorageUtil.UpdateLinkedFamilyInfo(SelectedFamilyInfo, tType); if (LinkInstances.ContainsKey(selectedLink.InstanceId)) { LinkInstances.Remove(selectedLink.InstanceId); LinkInstances.Add(selectedLink.InstanceId, selectedLink); } trans.Commit(); MappingWindowInstance.RefreshLinkInstance(); } catch (Exception ex) { trans.RollBack(); var message = ex.Message; } } } } FamilyWindowInstance.WakeUp(); break; case RequestId.DeleteFamilyMapping: MappingWindowInstance.DozeOff(); if (null != SelectedFamilyInfo) { using (var trans = new Transaction(CurrentDocument)) { trans.Start("Delete Family Map"); try { foreach (var familyInfo in LinkedFamilyToDelete) { if (selectedLink.LinkedFamilies.ContainsKey(familyInfo.TargetTypeId)) { selectedLink.LinkedFamilies.Remove(familyInfo.TargetTypeId); var tType = CurrentDocument.GetElement(familyInfo.TargetTypeId) as ElementType; if (null != tType) { var removed = MoverDataStorageUtil.RemoveLinkedFamilyInfo(tType); } } } trans.Commit(); if (LinkInstances.ContainsKey(selectedLink.InstanceId)) { LinkInstances.Remove(selectedLink.InstanceId); LinkInstances.Add(selectedLink.InstanceId, selectedLink); } MappingWindowInstance.RefreshLinkInstance(); } catch (Exception ex) { trans.RollBack(); var message = ex.Message; } } } MappingWindowInstance.WakeUp(); break; case RequestId.None: return; } } catch (Exception ex) { MessageBox.Show("Failed to execute external event handler.\n" + ex.Message, "Execute External Event Handler", MessageBoxButton.OK, MessageBoxImage.Warning); } }