Browse Source

Applied patch by Scott Ferret: Enhancement to Cut/Copy/Paste

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1118 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e871bbbb6c
  1. 11
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs
  2. 5
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs
  3. 40
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs
  4. 22
      src/Main/Base/Project/Resources/BehaviorTextEditorPanel.xfrm
  5. 10
      src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs
  6. 2
      src/Main/Base/Project/Src/TextEditor/Gui/OptionPanels/BehaviorTextEditorPanel.cs

11
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/DefaultTextEditorProperties.cs

@ -46,6 +46,7 @@ namespace ICSharpCode.TextEditor.Document @@ -46,6 +46,7 @@ namespace ICSharpCode.TextEditor.Document
bool mouseWheelTextZoom = true;
bool hideMouseCursor = false;
bool cutCopyWholeLine = true;
int verticalRulerRow = 80;
LineViewerStyle lineViewerStyle = LineViewerStyle.None;
@ -216,6 +217,16 @@ namespace ICSharpCode.TextEditor.Document @@ -216,6 +217,16 @@ namespace ICSharpCode.TextEditor.Document
hideMouseCursor = value;
}
}
public bool CutCopyWholeLine {
get {
return cutCopyWholeLine;
}
set {
cutCopyWholeLine = value;
}
}
public Encoding Encoding {
get {
return encoding;

5
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/ITextEditorProperties.cs

@ -38,6 +38,11 @@ namespace ICSharpCode.TextEditor.Document @@ -38,6 +38,11 @@ namespace ICSharpCode.TextEditor.Document
set;
}
bool CutCopyWholeLine {
get;
set;
}
bool UseAntiAliasedFont { // is wrapped in text editor control
get;
set;

40
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/TextAreaClipboardHandler.cs

@ -74,12 +74,24 @@ namespace ICSharpCode.TextEditor @@ -74,12 +74,24 @@ namespace ICSharpCode.TextEditor
{
// ((DefaultWorkbench)WorkbenchSingleton.Workbench).UpdateToolbars();
}
string LineSelectedType
{
get {
return "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy
}
}
bool CopyTextToClipboard(string stringToCopy)
bool CopyTextToClipboard(string stringToCopy, bool asLine)
{
if (stringToCopy.Length > 0) {
DataObject dataObject = new DataObject();
dataObject.SetData(DataFormats.UnicodeText, true, stringToCopy);
if (asLine) {
MemoryStream lineSelected = new MemoryStream(1);
lineSelected.WriteByte(1);
dataObject.SetData(LineSelectedType, false, lineSelected);
}
// Default has no highlighting, therefore we don't need RTF output
if (textArea.Document.HighlightingStrategy.Name != "Default") {
dataObject.SetData(DataFormats.Rtf, RtfWriter.GenerateRtf(textArea));
@ -101,6 +113,11 @@ namespace ICSharpCode.TextEditor @@ -101,6 +113,11 @@ namespace ICSharpCode.TextEditor
return false;
}
}
bool CopyTextToClipboard(string stringToCopy)
{
return CopyTextToClipboard(stringToCopy, false);
}
public void Cut(object sender, EventArgs e)
{
@ -110,13 +127,13 @@ namespace ICSharpCode.TextEditor @@ -110,13 +127,13 @@ namespace ICSharpCode.TextEditor
textArea.Caret.Position = textArea.SelectionManager.SelectionCollection[0].StartPosition;
textArea.SelectionManager.RemoveSelectedText();
textArea.EndUpdate();
} else {
} else if (textArea.Document.TextEditorProperties.CutCopyWholeLine){
// No text was selected, select and cut the entire line
int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
LineSegment lineWhereCaretIs = textArea.Document.GetLineSegment(curLineNr);
string caretLineText = textArea.Document.GetText(lineWhereCaretIs.Offset, lineWhereCaretIs.TotalLength);
textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset), textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset + lineWhereCaretIs.TotalLength));
if (CopyTextToClipboard(caretLineText)) {
if (CopyTextToClipboard(caretLineText, true)) {
// remove line
textArea.BeginUpdate();
textArea.Caret.Position = textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset);
@ -129,14 +146,12 @@ namespace ICSharpCode.TextEditor @@ -129,14 +146,12 @@ namespace ICSharpCode.TextEditor
public void Copy(object sender, EventArgs e)
{
if (!CopyTextToClipboard(textArea.SelectionManager.SelectedText)) {
if (!CopyTextToClipboard(textArea.SelectionManager.SelectedText) && textArea.Document.TextEditorProperties.CutCopyWholeLine) {
// No text was selected, select the entire line, copy it, and then deselect
int curLineNr = textArea.Document.GetLineNumberForOffset(textArea.Caret.Offset);
LineSegment lineWhereCaretIs = textArea.Document.GetLineSegment(curLineNr);
string caretLineText = textArea.Document.GetText(lineWhereCaretIs.Offset, lineWhereCaretIs.TotalLength);
textArea.SelectionManager.SetSelection(textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset), textArea.Document.OffsetToPosition(lineWhereCaretIs.Offset + lineWhereCaretIs.TotalLength));
CopyTextToClipboard(caretLineText);
textArea.SelectionManager.ClearSelection();
CopyTextToClipboard(caretLineText, true);
}
}
@ -146,6 +161,7 @@ namespace ICSharpCode.TextEditor @@ -146,6 +161,7 @@ namespace ICSharpCode.TextEditor
for (int i = 0;; i++) {
try {
IDataObject data = Clipboard.GetDataObject();
bool fullLine = data.GetDataPresent(LineSelectedType);
if (data.GetDataPresent(DataFormats.UnicodeText)) {
string text = (string)data.GetData(DataFormats.UnicodeText);
if (text.Length > 0) {
@ -154,7 +170,15 @@ namespace ICSharpCode.TextEditor @@ -154,7 +170,15 @@ namespace ICSharpCode.TextEditor
Delete(sender, e);
redocounter++;
}
textArea.InsertString(text);
if (fullLine) {
int col = textArea.Caret.Column;
textArea.Caret.Column = 0;
textArea.InsertString(text);
textArea.Caret.Column = col;
}
else {
textArea.InsertString(text);
}
if (redocounter > 0) {
textArea.Document.UndoStack.UndoLast(redocounter + 1); // redo the whole operation
}

22
src/Main/Base/Project/Resources/BehaviorTextEditorPanel.xfrm

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
<System.Windows.Forms.UserControl>
<Name value="CreatedObject0" />
<DockPadding value="" />
<ClientSize value="{Width=384, Height=328}" />
<ClientSize value="{Width=384, Height=352}" />
<Controls>
<System.Windows.Forms.GroupBox>
<Name value="CreatedObject2" />
@ -75,7 +75,7 @@ @@ -75,7 +75,7 @@
<TabIndex value="1" />
<Location value="{X=8,Y=128}" />
<Anchor value="Top, Left, Right" />
<ClientSize value="{Width=368, Height=176}" />
<ClientSize value="{Width=368, Height=200}" />
<Text value="${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.BehaviourGroupBox}" />
<Controls>
<System.Windows.Forms.CheckBox>
@ -94,6 +94,14 @@ @@ -94,6 +94,14 @@
<Anchor value="Top, Left, Right" />
<TabIndex value="3" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.CheckBox>
<Name value="cutCopyWholeLine" />
<Location value="{X=8,Y=116}" />
<ClientSize value="{Width=348, Height=24}" />
<Text value="${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.CutCopyWholeLine}" />
<Anchor value="Top, Left, Right" />
<TabIndex value="4" />
</System.Windows.Forms.CheckBox>
<System.Windows.Forms.CheckBox>
<Name value="caretBehindEOLCheckBox" />
<Location value="{X=8,Y=20}" />
@ -113,8 +121,8 @@ @@ -113,8 +121,8 @@
<System.Windows.Forms.ComboBox>
<Name value="mouseWhellDirectionComboBox" />
<Anchor value="Bottom, Left" />
<TabIndex value="5" />
<Location value="{X=8,Y=144}" />
<TabIndex value="6" />
<Location value="{X=8,Y=168}" />
<ClientSize value="{Width=152, Height=21}" />
<DropDownStyle value="DropDownList" />
</System.Windows.Forms.ComboBox>
@ -123,12 +131,12 @@ @@ -123,12 +131,12 @@
<Text value="${res:Dialog.Options.IDEOptions.TextEditor.Behaviour.MouseWhellGroupBox}" />
<TextAlign value="BottomLeft" />
<Anchor value="Top, Left, Right" />
<TabIndex value="4" />
<TabIndex value="5" />
<ClientSize value="{Width=160, Height=24}" />
<Location value="{X=8,Y=118}" />
<Location value="{X=8,Y=142}" />
</System.Windows.Forms.Label>
</Controls>
</System.Windows.Forms.GroupBox>
</Controls>
</System.Windows.Forms.UserControl>
</Components>
</Components>

10
src/Main/Base/Project/Src/TextEditor/Gui/Editor/SharpDevelopTextEditorProperties.cs

@ -215,6 +215,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor @@ -215,6 +215,16 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor
properties.Set("HideMouseCursor", value);
}
}
public bool CutCopyWholeLine {
get {
return properties.Get("CutCopyWholeLine", true);
}
set {
properties.Set("CutCopyWholeLine", value);
}
}
public Encoding Encoding {
get {
return Encoding.GetEncoding(properties.Get("Encoding", 65001));

2
src/Main/Base/Project/Src/TextEditor/Gui/OptionPanels/BehaviorTextEditorPanel.cs

@ -33,6 +33,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels @@ -33,6 +33,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels
((CheckBox)ControlDictionary["hideMouseCursorCheckBox"]).Checked = ((Properties)CustomizationObject).Get("HideMouseCursor", true);
((CheckBox)ControlDictionary["caretBehindEOLCheckBox"]).Checked = ((Properties)CustomizationObject).Get("CursorBehindEOL", false);
((CheckBox)ControlDictionary["auotInsertTemplatesCheckBox"]).Checked = ((Properties)CustomizationObject).Get("AutoInsertTemplates", true);
((CheckBox)ControlDictionary["cutCopyWholeLine"]).Checked = ((Properties)CustomizationObject).Get("CutCopyWholeLine", true);
((CheckBox)ControlDictionary["convertTabsToSpacesCheckBox"]).Checked = ((Properties)CustomizationObject).Get("TabsToSpaces", false);
@ -59,6 +60,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels @@ -59,6 +60,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Gui.OptionPanels
((Properties)CustomizationObject).Set("HideMouseCursor", ((CheckBox)ControlDictionary["hideMouseCursorCheckBox"]).Checked);
((Properties)CustomizationObject).Set("CursorBehindEOL", ((CheckBox)ControlDictionary["caretBehindEOLCheckBox"]).Checked);
((Properties)CustomizationObject).Set("AutoInsertTemplates", ((CheckBox)ControlDictionary["auotInsertTemplatesCheckBox"]).Checked);
((Properties)CustomizationObject).Set("CutCopyWholeLine", ((CheckBox)ControlDictionary["cutCopyWholeLine"]).Checked);
((Properties)CustomizationObject).Set("IndentStyle", (IndentStyle)((ComboBox)ControlDictionary["indentStyleComboBox"]).SelectedIndex);

Loading…
Cancel
Save