Example #1
0
 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());
     }
 }
Example #2
0
 public AddSnippetForm(History h)
 {
     InitializeComponent();
     var db = new DataProcess();
     groups = db.LoadGroups();
     _currentHistory = h;
 }
Example #3
0
        public AddSnippetForm()
        {
            InitializeComponent();
            var db = new DataProcess();

            groups = db.LoadGroups();
        }
Example #4
0
        public AddSnippetForm(History h)
        {
            InitializeComponent();
            var db = new DataProcess();

            groups          = db.LoadGroups();
            _currentHistory = h;
        }
Example #5
0
        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);
            });
        }
Example #6
0
        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);
        }
Example #7
0
        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;
        }
Example #8
0
        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();
            }
        }
Example #9
0
        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;
            }
        }
Example #10
0
        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());
                }
            }
        }
Example #11
0
        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();
            }
        }
Example #12
0
        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();
            }
        }
Example #13
0
        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);
            });
        }
Example #14
0
File: Form1.cs Project: venj/Clipy
 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();
     }
 }
Example #15
0
File: Form1.cs Project: venj/Clipy
 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;
     }
 }
Example #16
0
File: Form1.cs Project: venj/Clipy
        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);
            });
        }
Example #17
0
        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;
        }
Example #18
0
File: Form1.cs Project: venj/Clipy
 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());
         }
     }
 }
Example #19
0
File: Form1.cs Project: venj/Clipy
 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);
     });
 }
Example #20
0
File: Form1.cs Project: venj/Clipy
        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;
            }

            
        }
Example #21
0
File: Form1.cs Project: venj/Clipy
        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;
        }
Example #22
0
File: Form1.cs Project: venj/Clipy
        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();
            }
        }
Example #23
0
File: Form1.cs Project: venj/Clipy
 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);
 }
Example #24
0
        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;
                }
            }
        }
Example #25
0
File: Form1.cs Project: venj/Clipy
 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();
     }
 }
Example #26
0
File: Form1.cs Project: venj/Clipy
 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;
 }
Example #27
0
        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;
                }
            }
            
        }
Example #28
0
 public AddSnippetForm()
 {
     InitializeComponent();
     var db = new DataProcess();
     groups = db.LoadGroups();
 }