private void ClipboardObjectName_TextChanged(object sender, TextChangedEventArgs e) { if (category != null && clipboardObject != null) { if (category.Status == LoadStatus.UNLOADED) { ClipboardObjectName.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFrom(ColorSet.LOADING); NameErrorText.Foreground = (SolidColorBrush) new BrushConverter().ConvertFrom(ColorSet.LOADING); NameErrorText.Content = "Loading saved clips..."; Dispatcher.BeginInvoke((Action)(() => { IEnumerable <ClipboardObject> loader = category.ClipboardObjects; ClipboardObjectName_TextChanged(sender, e); })); } else if (category.Status == LoadStatus.LOADED) { ClipboardObject sameNameClipboardObject = category.ClipboardObjects.FirstOrDefault((clipboard) => clipboard.Name == ClipboardObjectName.Text.Trim()); if (sameNameClipboardObject != null && (FormType == FormType.CREATE || (clipboardObject != null && sameNameClipboardObject.Id != clipboardObject.Id))) { ClipboardObjectName.BorderBrush = (SolidColorBrush) new BrushConverter().ConvertFrom(ColorSet.ERROR); NameErrorText.Foreground = (SolidColorBrush) new BrushConverter().ConvertFrom(ColorSet.ERROR); NameErrorText.Content = "Name already taken"; } else if (ClipboardObjectName.Text.Trim() != "") { ClipboardObjectName.BorderBrush = new SolidColorBrush(Colors.White); NameErrorText.Content = ""; } } } }
private void CloseForm(object sender, MouseButtonEventArgs e) { category = null; clipboardObject = null; ClipboardObjectName.Text = ""; ClipboardObjectName.BorderBrush = new SolidColorBrush(Colors.White); NameErrorText.Content = ""; Visibility = Visibility.Hidden; }
public void OpenUpdateForm(Category category, ClipboardObject clipboardObject) { FormType = FormType.EDIT; this.category = category; this.clipboardObject = clipboardObject; TitleLabel.Content = "Edit Clip"; ClipboardObjectName.Text = clipboardObject.Name; ClipboardPanel.Children.Clear(); FrameworkElement previewPanel = clipboardObject.GenerateClipboardPreviewPanel(); previewPanel.Height = 150; ClipboardPanel.Children.Add(previewPanel); Visibility = Visibility.Visible; }
public void OpenCreateForm(Category category, ClipboardObject clipboardObject) { FormType = FormType.CREATE; this.category = category; this.clipboardObject = clipboardObject; TitleLabel.Content = "Save to " + (category.Name.Length > FormConstants.ADD_TO_CATEGORY_NAME_LIMIT ? category.Name.Substring(0, FormConstants.ADD_TO_CATEGORY_NAME_LIMIT) + "..." : category.Name); ClipboardObjectName.Text = clipboardObject.Name; ClipboardPanel.Children.Clear(); FrameworkElement previewPanel = clipboardObject.GenerateClipboardPreviewPanel(); previewPanel.Height = 150; ClipboardPanel.Children.Add(previewPanel); Visibility = Visibility.Visible; }
public int CompareTo(object obj) { if (obj == null) { return(1); } ClipboardObject other = obj as ClipboardObject; if (other != null) { return(Name.ToLower().CompareTo(other.Name.ToLower())); } else { throw new ArgumentException("Object is not a ClipboardObject"); } }
public void HandleDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("ClipboardObject") && parentWindow.CurrentCategoryId != Id) { ClipboardObject clipboardObject = (ClipboardObject)e.Data.GetData("ClipboardObject"); Console.WriteLine("dropped " + clipboardObject.Name + " on " + Name); parentWindow.ClipboardForm.OpenCreateForm(this, clipboardObject); } else if (e.Data.GetDataPresent("Category")) { Category category = (Category)e.Data.GetData("Category"); Console.WriteLine("dropped " + category.Name + " on " + Name); parentWindow.MoveCategory(category, this); } else { Console.WriteLine("invalid drop"); } }
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); } } })); }
public void RemoveClipboardObject(ClipboardObject clipboardObject) { clipboardObjects.Remove(clipboardObject); }
public void AddClipboardObject(ClipboardObject clipboardObject) { clipboardObjects.Add(clipboardObject); }
public void SaveClipboardToRecent() { Console.WriteLine("attempting to save clipboard to recent"); if (!selfCopy) { Console.WriteLine("checking for recent duplicate"); ClipboardObject duplicateObject = null; foreach (ClipboardObject clipboardObject in categories[0].ClipboardObjects) { if (clipboardObject.MatchesClipboard()) { duplicateObject = clipboardObject; break; } } if (duplicateObject != null) { Console.WriteLine("moving duplicate clipboard to most recent"); categories[0].RemoveClipboardObject(duplicateObject); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.Remove(duplicateObject.ClipboardContainer); } duplicateObject.Name = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); categories[0].AddClipboardObject(duplicateObject); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.Insert(1, duplicateObject.ClipboardContainer); } } else { ClipboardObject newClipboardObject = null; Console.WriteLine("not a duplicate, finding format to save as"); foreach (string format in Clipboard.GetDataObject().GetFormats()) { Console.WriteLine(format); } if (Clipboard.ContainsText()) { newClipboardObject = new TextClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetText()); } else if (Clipboard.ContainsImage()) { newClipboardObject = new ImageClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetDataObject()); } else if (Clipboard.ContainsFileDropList()) { newClipboardObject = new FileDropListClipboardObject(this, DateTime.Now.ToString(Recent.DATE_FORMAT), Clipboard.GetFileDropList()); } if (newClipboardObject != null) { categories[0].AddClipboardObject(newClipboardObject); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.Insert(1, newClipboardObject.ClipboardContainer); } if (categories[0].ClipboardObjects.Count() > MAX_RECENTS) { categories[0].RemoveClipboardObject(categories[0].ClipboardObjects.Last()); if (CurrentCategoryId == categories[0].Id) { ContentPanel.Children.RemoveAt(categories[0].ClipboardObjects.Count() + 1); } } } } SetActiveCategory(Recent.ID); } else { Console.WriteLine("ignoring self copy"); selfCopy = false; } }