private async void UpdateClipboard() { Indicator.IsBusy = true; if (ProfileComboBox.IsLoaded && ProfileComboBox.SelectedValue != null && ProfileComboBox.SelectedValue as string != "Default") { if (ProfileComboBox.Items.Contains("Default")) { UpdateProfileComboBox(false, ProfileComboBox.SelectedValue as string); } Clipboard.ClearHistory(); using (LiteDatabase db = new LiteDatabase($"Filename={Path.Combine(documents, "Auto Paste Clipboard", "data.db")}; Connection=shared")) { ILiteCollection <ClipboardProfile> collection = db.GetCollection <ClipboardProfile>("clipboard"); ClipboardProfile clipboardProfile = collection.FindOne(x => x.Profile == ProfileComboBox.SelectedValue as string); foreach (string item in clipboardProfile.Clipboard) { DataPackage data = new DataPackage(); data.SetText(item); Clipboard.SetContent(data); await Task.Delay(450); } DelimiterComboBox.SelectedIndex = clipboardProfile.Delimeter; DelayUpDownBox.Value = clipboardProfile.Delay; ProfileNameTextBox.Text = ProfileComboBox.SelectedValue as string; } } UndoChangesBtn.IsEnabled = false; Indicator.IsBusy = false; }
private void DeleteProfile(object sender, RoutedEventArgs e) { if (ProfileComboBox.Text != "Default") { using (LiteDatabase db = new LiteDatabase(Path.Combine(documents, "Auto Paste Clipboard", "data.db"))) { ILiteCollection <ClipboardProfile> collection = db.GetCollection <ClipboardProfile>("clipboard"); ClipboardProfile clipboardProfile = collection.FindOne(x => x.Profile == ProfileComboBox.Text); collection.Delete(clipboardProfile.Profile); } if (ProfileComboBox.Items.Count == 1) { UpdateProfileComboBox(true); } else { UpdateProfileComboBox(false); } } }
private void SaveClipboard(object sender, RoutedEventArgs e) { List <string> clipboard = new List <string>(); foreach (ListViewItem item in ClipboardListView.Items) { clipboard.Add(item.Content as string); } if (ClipboardListView.Items.Count != 0) { ClipboardProfile clipboardProfile = new ClipboardProfile { Profile = ProfileNameTextBox.Text, Clipboard = clipboard, Delimeter = DelimiterComboBox.SelectedIndex, Delay = (int)DelayUpDownBox.Value }; using (LiteDatabase db = new LiteDatabase(Path.Combine(documents, "Auto Paste Clipboard", "data.db"))) { ILiteCollection <ClipboardProfile> collection = db.GetCollection <ClipboardProfile>("clipboard"); if (collection.Exists(c => c.Profile == clipboardProfile.Profile)) { MessageBox.Show("Clipboard has successfully been updated.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); } collection.Upsert(clipboardProfile); //update or insert } UpdateProfileComboBox(false, clipboardProfile.Profile); UndoChangesBtn.IsEnabled = false; } else { MessageBox.Show("There's nothing to save. Try copying a text for it to appear on here.", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }