void ClipboardDataChanged() { try { IDataObject iData = Clipboard.GetDataObject(); if (iData == null) { Console.WriteLine("Empty content."); return; } if (iData.GetDataPresent(DataFormats.Text)) { var content = (string)iData.GetData(DataFormats.Text); if (content == null || content == "") { return; } var history = new History(); history.Content = content; history.CreatedAt = DateTime.Now; var db = new DataProcess(); db.SaveHistory(history); UpdateTrayMenu(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public AddSnippetForm(History h) { InitializeComponent(); var db = new DataProcess(); groups = db.LoadGroups(); _currentHistory = h; }
public AddSnippetForm() { InitializeComponent(); var db = new DataProcess(); groups = db.LoadGroups(); }
private void ReloadGroupsUI() { DataProcess db = new DataProcess(); groupNameTextBox.Text = ""; // clear textbox. groupsList.Items.Clear(); groups = db.LoadGroups(); groups.ForEach((v) => { groupsList.Items.Add(v.Name); }); }
private void Snippet_Click(object sender, EventArgs e) { int tag = (int)((MenuItem)sender).Tag; var db = new DataProcess(); var history = db.LoadHistoryOfId(tag); var content = history?.Content; // In case history is null. if (content == null || content.Trim() == "") { return; } Clipboard.SetText(content); }
public MainForm() { InitializeComponent(); nextClipboardViewer = (IntPtr)SetClipboardViewer((int)this.Handle); // Initialize database. DataProcess db = new DataProcess(); ReloadGroupsUI(); // Initialize Tray Menu. UpdateTrayMenu(); // Hide App When start. Hide(); WindowState = FormWindowState.Minimized; }
private void DeleteHistoriesMenu_Click(object sender, EventArgs e) { string message = resmgr.GetString("__message_box_Warn_Delete_Histories", ci); string caption = resmgr.GetString("__menu_title_Delete_Histories", ci); MessageBoxButtons buttons = MessageBoxButtons.YesNo; var result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { Clipboard.Clear(); var db = new DataProcess(); db.DeleteAllHistories(); histories = db.LoadHistories(); UpdateTrayMenu(); } }
private void renameGroupButton_Click(object sender, EventArgs e) { var index = groupsList.SelectedIndex; var group = groups[index]; var inputBox = new InputBox(resmgr.GetString("__message_box_message_Remane_group", ci), resmgr.GetString("__message_box_title_Remane", ci), group.Name); if (inputBox.ShowDialog() == DialogResult.OK) { string input = inputBox.InputResult; if (input != "") { var db = new DataProcess(); db.RenameGroup(group, input); ReloadGroupsUI(); UpdateTrayMenu(); } groupsList.SelectedIndex = index; } }
private void addGroupButton_Click(object sender, EventArgs e) { var name = groupNameTextBox.Text.Trim(); if (name.Length == 0) { MessageBox.Show(resmgr.GetString("__message_box_Group_name_not_empty", ci)); } else { var db = new DataProcess(); try { db.AddGroup(name); ReloadGroupsUI(); } catch (Exception err) { MessageBox.Show(err.ToString()); } } }
private void deleteGroupButton_Click(object sender, EventArgs e) { int index = groupsList.SelectedIndex; var group = groups[index]; string message = resmgr.GetString("__message_box_message_delete_group_part_1", ci) + group.Name + resmgr.GetString("__message_box_message_delete_group_part_2", ci); //"All the snippets in \"" + group.Name + "\" group will be deleted.\nAre you sure?"; string caption = resmgr.GetString("__message_box_title_delete_group_part_1", ci) + group.Name; MessageBoxButtons buttons = MessageBoxButtons.YesNo; var result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { var db = new DataProcess(); db.DeleteGroup(group); // Reload groups in main UI ReloadGroupsUI(); // Clean up UI snippetsList.Items.Clear(); contentTextBox.Text = ""; // Update tray menu UpdateTrayMenu(); } }
private void deleteSnippetButton_Click(object sender, EventArgs e) { string message = resmgr.GetString("__message_box_message_delete_snippets", ci); string caption = resmgr.GetString("__message_box_title_delete_snippets", ci); MessageBoxButtons buttons = MessageBoxButtons.YesNo; var result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { var db = new DataProcess(); var selectedIndices = snippetsList.SelectedIndices; for (int i = 0; i < selectedIndices.Count; ++i) { int index = selectedIndices[i]; db.DeleteHistory(currentSnippets[index]); } // Clean up UI int selectedGroupIndex = groupsList.SelectedIndex; ReloadSnippetsList(selectedGroupIndex); contentTextBox.Text = ""; // Update tray menu UpdateTrayMenu(); } }
private void ReloadSnippetsList(int selectedGroupIndex) { var group = groups[selectedGroupIndex]; var db = new DataProcess(); currentSnippets = db.LoadSnippetsInGroup(group); snippetsList.Items.Clear(); // Clear snippetsList contentTextBox.Text = ""; // Clear contentTextBox editSnippetButton.Enabled = deleteSnippetButton.Enabled = false; var selectionCount = groupsList.SelectedIndices.Count; if (selectionCount == 1) { deleteGroupButton.Enabled = true; renameGroupButton.Enabled = true; } else if (selectionCount > 1) { deleteGroupButton.Enabled = true; renameGroupButton.Enabled = false; } else { deleteGroupButton.Enabled = false; renameGroupButton.Enabled = false; } currentSnippets.ForEach(s => { var nameText = resmgr.GetString("__window_content_No_Name", ci); if (s.Name.Count() != 0) { nameText = s.Name; } snippetsList.Items.Add(nameText); }); }
void ClipboardDataChanged() { IDataObject iData = Clipboard.GetDataObject(); if (iData == null) { MessageBox.Show("Null!"); } try { if (iData.GetDataPresent(DataFormats.Text)) { var content = (string)iData.GetData(DataFormats.Text); if (content == null || content == "") { return; } var history = new History(); history.Content = content; history.CreatedAt = DateTime.Now; var db = new DataProcess(); db.SaveHistory(history); UpdateTrayMenu(); } } catch (Exception e) { MessageBox.Show(e.ToString()); //throw; } }
private void UpdateTrayMenu() { reloadSettings(); var db = new DataProcess(); histories = db.LoadHistories(); var contextMenu = new ContextMenu(); organizeHistoriesMenu(contextMenu, histories, SubMenu_Click); // Add groups if (groups == null) { groups = new DataProcess().LoadGroups(); } if (groups.Count > 0) { contextMenu.MenuItems.Add("-"); } groups.ForEach((g) => { MenuItem m = new MenuItem(g.Name); contextMenu.MenuItems.Add(m); var historiesInGroup = db.LoadSnippetsInGroup(g); if (historiesInGroup.Count() == 0) { m.Enabled = false; } else { m.Enabled = true; } if (historiesInGroup.Count() > NUMBER_OF_ITEMS_PER_GROUP) //FIXME: Magic { organizeHistoriesMenu(m, historiesInGroup, Snippet_Click); } else { for (int i = 0; i < historiesInGroup.Count(); ++i) { MenuItem subMenu = new MenuItem(); var history = historiesInGroup[i]; var content = history.Content.Trim(); subMenu.Text = shorttenedContent(content.FirstLine()); subMenu.Tag = history.Id; subMenu.Click += Snippet_Click; m.MenuItems.Add(subMenu); } } }); // Add more menus. contextMenu.MenuItems.Add("-"); contextMenu.MenuItems.Add(EditMenu); contextMenu.MenuItems.Add(SettingsMenu); contextMenu.MenuItems.Add(DeleteHistoriesMenu); contextMenu.MenuItems.Add("-"); contextMenu.MenuItems.Add(ExitMenu); notifyIcon1.ContextMenu = contextMenu; }
private void addSnippetButton_Click(object sender, EventArgs e) { if (snippetContentBox.Text.Trim() == "") { MessageBox.Show(resmgr.GetString("__message_box_message_snippet_cannot_empty", ci)); return; } if (groupListCombo.Text.Trim() == "") { MessageBox.Show(resmgr.GetString("__message_box_message_group_cannot_empty", ci)); return; } var db = new DataProcess(); int selectedIndex = groupListCombo.SelectedIndex; string name = groupListCombo.Text; Group selectedGroup; if (selectedIndex == -1) { try { db.AddGroup(name); } catch (Exception err) { // TODO: Catch name unique error. MessageBox.Show(err.Message); return; } selectedGroup = db.LoadGroup(name); } else { selectedGroup = groups[selectedIndex]; } if (_currentHistory == null) { try { db.SaveSnippet(selectedGroup, snippetContentBox.Text, nameTextBox.Text.Trim()); Close(); } catch (Exception err) // catch potential error. { MessageBox.Show(err.Message); return; } } else { try { db.UpdateSnippet(_currentHistory, selectedGroup, snippetContentBox.Text, nameTextBox.Text.Trim()); Close(); } catch (Exception err) // catch potential error. { MessageBox.Show(err.Message); return; } } }