Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 1

WPF 界面/SharpDevelop

forked from KribKing/SharpDevelop
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (14)
Tags (60)
master
4.x
nuget-3.0-ctp
reports
filemodels
newNR
newNRILSpyDebugger
addin-manager-package-subdirectories
newNRvisualizers
4.2
4.1
formsdesignerappdomain
4.0
shortcuts
v5.1-archival
5.0.0
5.0-RC1
5.0-Beta5
5.0-Beta4
5.0-Beta3
5.0-Beta2
4.4.1
5.0-Beta1
4.4.0
4.3.3
4.3.2
4.3.1
4.3.0
4.3-Beta1
4.2.2
4.2.1
4.2.0
4.2-RC1
4.2-Beta2
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (14)
Tags (60)
master
4.x
nuget-3.0-ctp
reports
filemodels
newNR
newNRILSpyDebugger
addin-manager-package-subdirectories
newNRvisualizers
4.2
4.1
formsdesignerappdomain
4.0
shortcuts
v5.1-archival
5.0.0
5.0-RC1
5.0-Beta5
5.0-Beta4
5.0-Beta3
5.0-Beta2
4.4.1
5.0-Beta1
4.4.0
4.3.3
4.3.2
4.3.1
4.3.0
4.3-Beta1
4.2.2
4.2.1
4.2.0
4.2-RC1
4.2-Beta2
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (14)
Tags (60)
master
4.x
nuget-3.0-ctp
reports
filemodels
newNR
newNRILSpyDebugger
addin-manager-package-subdirectories
newNRvisualizers
4.2
4.1
formsdesignerappdomain
4.0
shortcuts
v5.1-archival
5.0.0
5.0-RC1
5.0-Beta5
5.0-Beta4
5.0-Beta3
5.0-Beta2
4.4.1
5.0-Beta1
4.4.0
4.3.3
4.3.2
4.3.1
4.3.0
4.3-Beta1
4.2.2
4.2.1
4.2.0
4.2-RC1
4.2-Beta2
SharpTreeView.cs 21.93 KB
Copy Edit Raw Blame History
Daniel Grunwald authored 2014年01月26日 00:06 +08:00 . Change LGPL headers to MIT header.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;
namespace ICSharpCode.TreeView
{
public class SharpTreeView : ListView
{
static SharpTreeView()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(SharpTreeView),
new FrameworkPropertyMetadata(typeof(SharpTreeView)));
SelectionModeProperty.OverrideMetadata(typeof(SharpTreeView),
new FrameworkPropertyMetadata(SelectionMode.Extended));
AlternationCountProperty.OverrideMetadata(typeof(SharpTreeView),
new FrameworkPropertyMetadata(2));
DefaultItemContainerStyleKey =
new ComponentResourceKey(typeof(SharpTreeView), "DefaultItemContainerStyleKey");
VirtualizingStackPanel.VirtualizationModeProperty.OverrideMetadata(typeof(SharpTreeView),
new FrameworkPropertyMetadata(VirtualizationMode.Recycling));
RegisterCommands();
}
public static ResourceKey DefaultItemContainerStyleKey { get; private set; }
public SharpTreeView()
{
SetResourceReference(ItemContainerStyleProperty, DefaultItemContainerStyleKey);
}
public static readonly DependencyProperty RootProperty =
DependencyProperty.Register("Root", typeof(SharpTreeNode), typeof(SharpTreeView));
public SharpTreeNode Root
{
get { return (SharpTreeNode)GetValue(RootProperty); }
set { SetValue(RootProperty, value); }
}
public static readonly DependencyProperty ShowRootProperty =
DependencyProperty.Register("ShowRoot", typeof(bool), typeof(SharpTreeView),
new FrameworkPropertyMetadata(true));
public bool ShowRoot
{
get { return (bool)GetValue(ShowRootProperty); }
set { SetValue(ShowRootProperty, value); }
}
public static readonly DependencyProperty ShowRootExpanderProperty =
DependencyProperty.Register("ShowRootExpander", typeof(bool), typeof(SharpTreeView),
new FrameworkPropertyMetadata(false));
public bool ShowRootExpander
{
get { return (bool)GetValue(ShowRootExpanderProperty); }
set { SetValue(ShowRootExpanderProperty, value); }
}
public static readonly DependencyProperty AllowDropOrderProperty =
DependencyProperty.Register("AllowDropOrder", typeof(bool), typeof(SharpTreeView));
public bool AllowDropOrder
{
get { return (bool)GetValue(AllowDropOrderProperty); }
set { SetValue(AllowDropOrderProperty, value); }
}
public static readonly DependencyProperty ShowLinesProperty =
DependencyProperty.Register("ShowLines", typeof(bool), typeof(SharpTreeView),
new FrameworkPropertyMetadata(true));
public bool ShowLines
{
get { return (bool)GetValue(ShowLinesProperty); }
set { SetValue(ShowLinesProperty, value); }
}
public static bool GetShowAlternation(DependencyObject obj)
{
return (bool)obj.GetValue(ShowAlternationProperty);
}
public static void SetShowAlternation(DependencyObject obj, bool value)
{
obj.SetValue(ShowAlternationProperty, value);
}
public static readonly DependencyProperty ShowAlternationProperty =
DependencyProperty.RegisterAttached("ShowAlternation", typeof(bool), typeof(SharpTreeView),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == RootProperty ||
e.Property == ShowRootProperty ||
e.Property == ShowRootExpanderProperty) {
Reload();
}
}
TreeFlattener flattener;
void Reload()
{
if (flattener != null) {
flattener.Stop();
}
if (Root != null) {
if (!(ShowRoot && ShowRootExpander)) {
Root.IsExpanded = true;
}
flattener = new TreeFlattener(Root, ShowRoot);
flattener.CollectionChanged += flattener_CollectionChanged;
this.ItemsSource = flattener;
}
}
void flattener_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
// Deselect nodes that are being hidden, if any remain in the tree
if (e.Action == NotifyCollectionChangedAction.Remove && Items.Count > 0) {
List<SharpTreeNode> selectedOldItems = null;
foreach (SharpTreeNode node in e.OldItems) {
if (node.IsSelected) {
if (selectedOldItems == null)
selectedOldItems = new List<SharpTreeNode>();
selectedOldItems.Add(node);
}
}
if (selectedOldItems != null) {
var list = SelectedItems.Cast<SharpTreeNode>().Except(selectedOldItems).ToList();
SetSelectedItems(list);
if (SelectedItem == null && this.IsKeyboardFocusWithin) {
// if we removed all selected nodes, then move the focus to the node
// preceding the first of the old selected nodes
SelectedIndex = Math.Max(0, e.OldStartingIndex - 1);
if (SelectedIndex >= 0)
FocusNode((SharpTreeNode)SelectedItem);
}
}
}
}
protected override DependencyObject GetContainerForItemOverride()
{
return new SharpTreeViewItem();
}
protected override bool IsItemItsOwnContainerOverride(object item)
{
return item is SharpTreeViewItem;
}
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
SharpTreeViewItem container = element as SharpTreeViewItem;
container.ParentTreeView = this;
// Make sure that the line renderer takes into account the new bound data
if (container.NodeView != null) {
container.NodeView.LinesRenderer.InvalidateVisual();
}
}
bool doNotScrollOnExpanding;
/// <summary>
/// Handles the node expanding event in the tree view.
/// This method gets called only if the node is in the visible region (a SharpTreeNodeView exists).
/// </summary>
internal void HandleExpanding(SharpTreeNode node)
{
if (doNotScrollOnExpanding)
return;
SharpTreeNode lastVisibleChild = node;
while (true) {
SharpTreeNode tmp = lastVisibleChild.Children.LastOrDefault(c => c.IsVisible);
if (tmp != null) {
lastVisibleChild = tmp;
} else {
break;
}
}
if (lastVisibleChild != node) {
// Make the the expanded children are visible; but don't scroll down
// to much (keep node itself visible)
base.ScrollIntoView(lastVisibleChild);
// For some reason, this only works properly when delaying it...
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(
delegate {
base.ScrollIntoView(node);
}));
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
SharpTreeViewItem container = e.OriginalSource as SharpTreeViewItem;
switch (e.Key) {
case Key.Left:
if (container != null && ItemsControl.ItemsControlFromItemContainer(container) == this) {
if (container.Node.IsExpanded) {
container.Node.IsExpanded = false;
} else if (container.Node.Parent != null) {
this.FocusNode(container.Node.Parent);
}
e.Handled = true;
}
break;
case Key.Right:
if (container != null && ItemsControl.ItemsControlFromItemContainer(container) == this) {
if (!container.Node.IsExpanded && container.Node.ShowExpander) {
container.Node.IsExpanded = true;
} else if (container.Node.Children.Count > 0) {
// jump to first child:
container.MoveFocus(new TraversalRequest(FocusNavigationDirection.Down));
}
e.Handled = true;
}
break;
case Key.Return:
if (container != null && Keyboard.Modifiers == ModifierKeys.None && this.SelectedItems.Count == 1 && this.SelectedItem == container.Node) {
e.Handled = true;
container.Node.ActivateItem(e);
}
break;
case Key.Space:
if (container != null && Keyboard.Modifiers == ModifierKeys.None && this.SelectedItems.Count == 1 && this.SelectedItem == container.Node) {
e.Handled = true;
if (container.Node.IsCheckable) {
if(container.Node.IsChecked == null) // If partially selected, we want to select everything
container.Node.IsChecked = true;
else
container.Node.IsChecked = !container.Node.IsChecked;
} else {
container.Node.ActivateItem(e);
}
}
break;
case Key.Add:
if (container != null && ItemsControl.ItemsControlFromItemContainer(container) == this) {
container.Node.IsExpanded = true;
e.Handled = true;
}
break;
case Key.Subtract:
if (container != null && ItemsControl.ItemsControlFromItemContainer(container) == this) {
container.Node.IsExpanded = false;
e.Handled = true;
}
break;
case Key.Multiply:
if (container != null && ItemsControl.ItemsControlFromItemContainer(container) == this) {
container.Node.IsExpanded = true;
ExpandRecursively(container.Node);
e.Handled = true;
}
break;
}
if (!e.Handled)
base.OnKeyDown(e);
}
void ExpandRecursively(SharpTreeNode node)
{
if (node.CanExpandRecursively) {
node.IsExpanded = true;
foreach (SharpTreeNode child in node.Children) {
ExpandRecursively(child);
}
}
}
/// <summary>
/// Scrolls the specified node in view and sets keyboard focus on it.
/// </summary>
public void FocusNode(SharpTreeNode node)
{
if (node == null)
throw new ArgumentNullException("node");
ScrollIntoView(node);
// WPF's ScrollIntoView() uses the same if/dispatcher construct, so we call OnFocusItem() after the item was brought into view.
if (this.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) {
OnFocusItem(node);
} else {
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new DispatcherOperationCallback(this.OnFocusItem), node);
}
}
public void ScrollIntoView(SharpTreeNode node)
{
if (node == null)
throw new ArgumentNullException("node");
doNotScrollOnExpanding = true;
foreach (SharpTreeNode ancestor in node.Ancestors())
ancestor.IsExpanded = true;
doNotScrollOnExpanding = false;
base.ScrollIntoView(node);
}
object OnFocusItem(object item)
{
FrameworkElement element = this.ItemContainerGenerator.ContainerFromItem(item) as FrameworkElement;
if (element != null) {
element.Focus();
}
return null;
}
#region Track selection
protected override void OnSelectionChanged(SelectionChangedEventArgs e)
{
foreach (SharpTreeNode node in e.RemovedItems) {
node.IsSelected = false;
}
foreach (SharpTreeNode node in e.AddedItems) {
node.IsSelected = true;
}
base.OnSelectionChanged(e);
}
#endregion
#region Drag and Drop
protected override void OnDragEnter(DragEventArgs e)
{
OnDragOver(e);
}
protected override void OnDragOver(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
if (Root != null && !ShowRoot) {
e.Handled = true;
e.Effects = Root.GetDropEffect(e, Root.Children.Count);
}
}
protected override void OnDrop(DragEventArgs e)
{
e.Effects = DragDropEffects.None;
if (Root != null && !ShowRoot) {
e.Handled = true;
e.Effects = Root.GetDropEffect(e, Root.Children.Count);
if (e.Effects != DragDropEffects.None)
Root.InternalDrop(e, Root.Children.Count);
}
}
internal void HandleDragEnter(SharpTreeViewItem item, DragEventArgs e)
{
HandleDragOver(item, e);
}
internal void HandleDragOver(SharpTreeViewItem item, DragEventArgs e)
{
HidePreview();
e.Effects = DragDropEffects.None;
var target = GetDropTarget(item, e);
if (target != null) {
e.Handled = true;
e.Effects = target.Effect;
ShowPreview(target.Item, target.Place);
}
}
internal void HandleDrop(SharpTreeViewItem item, DragEventArgs e)
{
try {
HidePreview();
var target = GetDropTarget(item, e);
if (target != null) {
e.Handled = true;
e.Effects = target.Effect;
target.Node.InternalDrop(e, target.Index);
}
} catch (Exception ex) {
Debug.WriteLine(ex.ToString());
throw;
}
}
internal void HandleDragLeave(SharpTreeViewItem item, DragEventArgs e)
{
HidePreview();
e.Handled = true;
}
class DropTarget
{
public SharpTreeViewItem Item;
public DropPlace Place;
public double Y;
public SharpTreeNode Node;
public int Index;
public DragDropEffects Effect;
}
DropTarget GetDropTarget(SharpTreeViewItem item, DragEventArgs e)
{
var dropTargets = BuildDropTargets(item, e);
var y = e.GetPosition(item).Y;
foreach (var target in dropTargets) {
if (target.Y >= y) {
return target;
}
}
return null;
}
List<DropTarget> BuildDropTargets(SharpTreeViewItem item, DragEventArgs e)
{
var result = new List<DropTarget>();
var node = item.Node;
if (AllowDropOrder) {
TryAddDropTarget(result, item, DropPlace.Before, e);
}
TryAddDropTarget(result, item, DropPlace.Inside, e);
if (AllowDropOrder) {
if (node.IsExpanded && node.Children.Count > 0) {
var firstChildItem = ItemContainerGenerator.ContainerFromItem(node.Children[0]) as SharpTreeViewItem;
TryAddDropTarget(result, firstChildItem, DropPlace.Before, e);
}
else {
TryAddDropTarget(result, item, DropPlace.After, e);
}
}
var h = item.ActualHeight;
var y1 = 0.2 * h;
var y2 = h / 2;
var y3 = h - y1;
if (result.Count == 2) {
if (result[0].Place == DropPlace.Inside &&
result[1].Place != DropPlace.Inside) {
result[0].Y = y3;
}
else if (result[0].Place != DropPlace.Inside &&
result[1].Place == DropPlace.Inside) {
result[0].Y = y1;
}
else {
result[0].Y = y2;
}
}
else if (result.Count == 3) {
result[0].Y = y1;
result[1].Y = y3;
}
if (result.Count > 0) {
result[result.Count - 1].Y = h;
}
return result;
}
void TryAddDropTarget(List<DropTarget> targets, SharpTreeViewItem item, DropPlace place, DragEventArgs e)
{
SharpTreeNode node;
int index;
GetNodeAndIndex(item, place, out node, out index);
if (node != null) {
var effect = node.GetDropEffect(e, index);
if (effect != DragDropEffects.None) {
DropTarget target = new DropTarget() {
Item = item,
Place = place,
Node = node,
Index = index,
Effect = effect
};
targets.Add(target);
}
}
}
void GetNodeAndIndex(SharpTreeViewItem item, DropPlace place, out SharpTreeNode node, out int index)
{
node = null;
index = 0;
if (place == DropPlace.Inside) {
node = item.Node;
index = node.Children.Count;
}
else if (place == DropPlace.Before) {
if (item.Node.Parent != null) {
node = item.Node.Parent;
index = node.Children.IndexOf(item.Node);
}
}
else {
if (item.Node.Parent != null) {
node = item.Node.Parent;
index = node.Children.IndexOf(item.Node) + 1;
}
}
}
SharpTreeNodeView previewNodeView;
InsertMarker insertMarker;
DropPlace previewPlace;
enum DropPlace
{
Before, Inside, After
}
void ShowPreview(SharpTreeViewItem item, DropPlace place)
{
previewNodeView = item.NodeView;
previewPlace = place;
if (place == DropPlace.Inside) {
previewNodeView.TextBackground = SystemColors.HighlightBrush;
previewNodeView.Foreground = SystemColors.HighlightTextBrush;
}
else {
if (insertMarker == null) {
var adornerLayer = AdornerLayer.GetAdornerLayer(this);
var adorner = new GeneralAdorner(this);
insertMarker = new InsertMarker();
adorner.Child = insertMarker;
adornerLayer.Add(adorner);
}
insertMarker.Visibility = Visibility.Visible;
var p1 = previewNodeView.TransformToVisual(this).Transform(new Point());
var p = new Point(p1.X + previewNodeView.CalculateIndent() + 4.5, p1.Y - 3);
if (place == DropPlace.After) {
p.Y += previewNodeView.ActualHeight;
}
insertMarker.Margin = new Thickness(p.X, p.Y, 0, 0);
SharpTreeNodeView secondNodeView = null;
var index = flattener.IndexOf(item.Node);
if (place == DropPlace.Before) {
if (index > 0) {
secondNodeView = (ItemContainerGenerator.ContainerFromIndex(index - 1) as SharpTreeViewItem).NodeView;
}
}
else if (index + 1 < flattener.Count) {
secondNodeView = (ItemContainerGenerator.ContainerFromIndex(index + 1) as SharpTreeViewItem).NodeView;
}
var w = p1.X + previewNodeView.ActualWidth - p.X;
if (secondNodeView != null) {
var p2 = secondNodeView.TransformToVisual(this).Transform(new Point());
w = Math.Max(w, p2.X + secondNodeView.ActualWidth - p.X);
}
insertMarker.Width = w + 10;
}
}
void HidePreview()
{
if (previewNodeView != null) {
previewNodeView.ClearValue(SharpTreeNodeView.TextBackgroundProperty);
previewNodeView.ClearValue(SharpTreeNodeView.ForegroundProperty);
if (insertMarker != null) {
insertMarker.Visibility = Visibility.Collapsed;
}
previewNodeView = null;
}
}
#endregion
#region Cut / Copy / Paste / Delete Commands
static void RegisterCommands()
{
CommandManager.RegisterClassCommandBinding(typeof(SharpTreeView),
new CommandBinding(ApplicationCommands.Cut, HandleExecuted_Cut, HandleCanExecute_Cut));
CommandManager.RegisterClassCommandBinding(typeof(SharpTreeView),
new CommandBinding(ApplicationCommands.Copy, HandleExecuted_Copy, HandleCanExecute_Copy));
CommandManager.RegisterClassCommandBinding(typeof(SharpTreeView),
new CommandBinding(ApplicationCommands.Paste, HandleExecuted_Paste, HandleCanExecute_Paste));
CommandManager.RegisterClassCommandBinding(typeof(SharpTreeView),
new CommandBinding(ApplicationCommands.Delete, HandleExecuted_Delete, HandleCanExecute_Delete));
}
static void HandleExecuted_Cut(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
SharpTreeView treeView = (SharpTreeView)sender;
var nodes = treeView.GetTopLevelSelection().ToArray();
if (nodes.Length > 0)
nodes[0].Cut(nodes);
}
static void HandleCanExecute_Cut(object sender, CanExecuteRoutedEventArgs e)
{
SharpTreeView treeView = (SharpTreeView)sender;
var nodes = treeView.GetTopLevelSelection().ToArray();
e.CanExecute = nodes.Length > 0 && nodes[0].CanCut(nodes);
e.Handled = true;
}
static void HandleExecuted_Copy(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
SharpTreeView treeView = (SharpTreeView)sender;
var nodes = treeView.GetTopLevelSelection().ToArray();
if (nodes.Length > 0)
nodes[0].Copy(nodes);
}
static void HandleCanExecute_Copy(object sender, CanExecuteRoutedEventArgs e)
{
SharpTreeView treeView = (SharpTreeView)sender;
var nodes = treeView.GetTopLevelSelection().ToArray();
e.CanExecute = nodes.Length > 0 && nodes[0].CanCopy(nodes);
e.Handled = true;
}
static void HandleExecuted_Paste(object sender, ExecutedRoutedEventArgs e)
{
SharpTreeView treeView = (SharpTreeView)sender;
var data = Clipboard.GetDataObject();
if (data != null) {
var selectedNode = (treeView.SelectedItem as SharpTreeNode) ?? treeView.Root;
if (selectedNode != null)
selectedNode.Paste(data);
}
e.Handled = true;
}
static void HandleCanExecute_Paste(object sender, CanExecuteRoutedEventArgs e)
{
SharpTreeView treeView = (SharpTreeView)sender;
var data = Clipboard.GetDataObject();
if (data == null) {
e.CanExecute = false;
} else {
var selectedNode = (treeView.SelectedItem as SharpTreeNode) ?? treeView.Root;
e.CanExecute = selectedNode != null && selectedNode.CanPaste(data);
}
e.Handled = true;
}
static void HandleExecuted_Delete(object sender, ExecutedRoutedEventArgs e)
{
e.Handled = true;
SharpTreeView treeView = (SharpTreeView)sender;
var nodes = treeView.GetTopLevelSelection().ToArray();
if (nodes.Length > 0)
nodes[0].Delete(nodes);
}
static void HandleCanExecute_Delete(object sender, CanExecuteRoutedEventArgs e)
{
SharpTreeView treeView = (SharpTreeView)sender;
var nodes = treeView.GetTopLevelSelection().ToArray();
e.CanExecute = nodes.Length > 0 && nodes[0].CanDelete(nodes);
e.Handled = true;
}
/// <summary>
/// Gets the selected items which do not have any of their ancestors selected.
/// </summary>
public IEnumerable<SharpTreeNode> GetTopLevelSelection()
{
var selection = this.SelectedItems.OfType<SharpTreeNode>();
var selectionHash = new HashSet<SharpTreeNode>(selection);
return selection.Where(item => item.Ancestors().All(a => !selectionHash.Contains(a)));
}
#endregion
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wpf-interface/SharpDevelop.git
git@gitee.com:wpf-interface/SharpDevelop.git
wpf-interface
SharpDevelop
SharpDevelop
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /