예제 #1
0
        private void SubmitClipboardObjectForm(object sender, MouseButtonEventArgs e)
        {
            if (ClipboardObjectName.Text.Trim() == "")
            {
                ClipboardObjectName.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFrom(ColorSet.ERROR);
                NameErrorText.Content           = "Name is required";
            }
            else if (NameErrorText.Content.ToString().Trim() == "")
            {
                // TODO: display loading overlay
                try
                {
                    string name = ClipboardObjectName.Text.Trim();

                    if (FormType == FormType.CREATE)
                    {
                        long   categoryId = category.Id;
                        string type       = clipboardObject.GetType().Name;
                        string content    = clipboardObject.GenerateContentString();
                        long   id         = DBManager.Instance.AddClipboardObject(categoryId, name, type, content);
                        category.AddClipboardObject(ClipboardObjectUtils.CreateClipboardObjectByType(ParentWindow, id, name, type, content));
                    }
                    else if (clipboardObject != null)
                    {
                        DBManager.Instance.UpdateClipboardObject(clipboardObject.Id, name);
                        category.RemoveClipboardObject(clipboardObject);
                        clipboardObject.Name = name;
                        category.AddClipboardObject(clipboardObject);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("could not save/update clipboard object: " + ex.Message);
                    // TODO: show error in overlay
                }
                CloseForm(sender, e);
                // TODO: close loading overlay
            }
        }
예제 #2
0
 public void DeleteClipboardObject(long id)
 {
     Dispatcher.CurrentDispatcher.BeginInvoke((Action)(() =>
     {
         Category currentCategory = categories.FirstOrDefault((category) => category.Id == CurrentCategoryId);
         if (currentCategory != null)
         {
             ClipboardObject objectToRemove = currentCategory.ClipboardObjects.FirstOrDefault((clipboardObject) => clipboardObject.Id == id);
             if (objectToRemove != null)
             {
                 if (CurrentCategoryId != Recent.ID)
                 {
                     DBManager.Instance.DeleteClipboardObject(id);
                     if (objectToRemove.UsesInternalStorage)
                     {
                         foreach (string unusedFile in DBManager.Instance.FindUnusedStorageFiles(objectToRemove.GenerateContentString()))
                         {
                             Console.WriteLine("removing unused file: " + unusedFile);
                             try
                             {
                                 File.Delete(unusedFile);
                             }
                             catch (Exception e)
                             {
                                 Console.WriteLine(e);
                             }
                         }
                     }
                     // TODO: cleanup local files if necessary
                 }
                 ContentPanel.Children.Remove(objectToRemove.ClipboardContainer);
                 currentCategory.RemoveClipboardObject(objectToRemove);
             }
         }
     }));
 }