/// <summary> /// Wklej. /// </summary> public void Paste() { StringBuilder modifiedContentBuilder = new StringBuilder(subtitlesEditor.SubtitlesContent); SubtitlesContentModificationArea modificationArea = SubtitlesContentModificationArea.PostCaret; SubtitlesEditState editState = subtitlesEditor.EditState; int insertPosition = editState.CaretPosition; Selection selection = editState.Selection; if (selection.Length > 0) { modifiedContentBuilder.Remove(selection.Start, selection.Length); modificationArea = SubtitlesContentModificationArea.Selection; insertPosition = selection.Start; } String contentToInsert = Clipboard.GetText(); modifiedContentBuilder.Insert(insertPosition, contentToInsert); SubtitlesContentModification contentMod = new SubtitlesContentModification(modifiedContentBuilder.ToString(), modificationArea); int postInsertCaret = insertPosition + contentToInsert.Length; SubtitlesEditState newEditState = new SubtitlesEditState(postInsertCaret, new Selection(postInsertCaret, 0)); SubtitlesEditStateModification editMod = new SubtitlesEditStateModification(newEditState); subtitlesEditor.PerformModification(new CompositeModification(contentMod, editMod)); }
private void OnEditStateChanged(SubtitlesEditState oldValue, SubtitlesEditState newValue) { var temporaryEventHolder = EditStateChanged; if (temporaryEventHolder != null) { temporaryEventHolder(this, new SubtitlesEditStateChangedEventArgs(oldValue, newValue)); } }
/// <summary> /// Kopiuj. /// </summary> public void Copy() { SubtitlesEditState editState = subtitlesEditor.EditState; String content = subtitlesEditor.SubtitlesContent; Selection selection = editState.Selection; String contentToCopy = content.Substring(selection.Start, selection.Length); Clipboard.SetText(contentToCopy); }
private void DeleteDifference(Diff differenceItem, int differneceStartIndex) { String content = subtitlesEditor.SubtitlesContent; content = content.Remove(differneceStartIndex, differenceItem.text.Length); subtitlesEditor.SubtitlesContent = content; SubtitlesEditState currentEditState = subtitlesEditor.EditState; SubtitlesEditState newEditState = new SubtitlesEditState(differneceStartIndex, currentEditState.Selection); }
/// <summary> /// Konstruktor. /// </summary> /// <param name="subtitlesEditor"></param> /// <param name="oldContent"></param> /// <param name="newContent"></param> /// <param name="oldEditState"></param> /// <param name="newEditState"></param> public SubtitlesModification(SubtitlesEditor subtitlesEditor, String oldContent, String newContent, SubtitlesEditState oldEditState, SubtitlesEditState newEditState) { this.subtitlesEditor = subtitlesEditor; this.newEditState = newEditState; this.oldEditState = oldEditState; this.currentSelection = newEditState.Selection; String oldContentTrimed = TrimOldContent(oldContent); String newContentTrimed = TrimNewContent(newContent); this.contentChanges = GetContentChanges(oldContentTrimed, newContentTrimed); }
/// <summary> /// Konstruktor. /// </summary> /// <param name="subtitlesManager">Menadżer zarządzający obiektami napisów.</param> /// <param name="undoRedoManager">Obiekt implementujący zachowania menadżera wycofywania/przywracania zmian.</param> public SubtitlesEditor(SubtitlesManager subtitlesManager, IUndoRedoManager undoRedoManager) { this.SubtitlesManager = subtitlesManager; this.SubtitlesManager.CurrentSubtitlesChanged += new EventHandler <SubtitlesChangedEventArgs>(SubtitlesManagerSubtitlesChangedHandler); this.UndoRedoManager = undoRedoManager; this.Subtitles = subtitlesManager.CurrentSubtitles; this.Subtitles.ContentChanged += new EventHandler <SubtitlesContentChangedEventArgs>(SubtitlesContentChangedHandler); this.editState = new SubtitlesEditState(); this.Clipboard = new SubtitlesClipboard(this); }
/// <summary> /// Wytnij. /// </summary> public void Cut() { SubtitlesEditState editState = subtitlesEditor.EditState; String content = subtitlesEditor.SubtitlesContent; Selection selection = editState.Selection; String contentToCut = content.Substring(selection.Start, selection.Length); Clipboard.SetText(contentToCut); String cuttedContent = content.Remove(selection.Start, selection.Length); SubtitlesContentModification contentMod = new SubtitlesContentModification(cuttedContent, SubtitlesContentModificationArea.Selection); SubtitlesEditState newEditState = new SubtitlesEditState(selection.Start, new Selection(selection.Start, 0)); SubtitlesEditStateModification editMod = new SubtitlesEditStateModification(newEditState); subtitlesEditor.PerformModification(new CompositeModification(contentMod, editMod)); }
/// <summary> /// Konstruktor. /// </summary> /// <param name="oldState">Stan przed zdarzeniem.</param> /// <param name="newState">Stan po zdarzeniu.</param> public SubtitlesEditStateChangedEventArgs(SubtitlesEditState oldState, SubtitlesEditState newState) { this.OldState = oldState; this.NewState = newState; }
/// <summary> /// Zanzancza określoną część edytowanego tekstu napisów. /// </summary> /// <param name="selectionStart">Indeks początku zaznaczenia.</param> /// <param name="selectionLength">Długość zaznaczenia.</param> public void SelectContent(int selectionStart, int selectionLength) { EditState = new SubtitlesEditState(selectionStart + selectionLength, new Selection(selectionStart, selectionLength)); }