Skip to content

Commit

Permalink
improvements and fixes to copy & paste
Browse files Browse the repository at this point in the history
  • Loading branch information
my-th-os committed May 5, 2019
1 parent 2ac928b commit bbc2ea7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
8 changes: 7 additions & 1 deletion KML/GUI/GuiKebalsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ public void Previous()
/// </summary>
public void CommandExec(string Command)
{
if (KerbalsList.SelectedItem is GuiKerbalsNode)
if (KerbalsDetails.IsKeyboardFocusWithin)
{
// TODO GuiKerbalsManager.CommandExec() for KerbalsDetails
}
else if (KerbalsList.IsKeyboardFocusWithin && KerbalsList.SelectedItem is GuiKerbalsNode)
{
(KerbalsList.SelectedItem as GuiKerbalsNode).CommandExec(Command);
}
}

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion KML/GUI/GuiTreeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,14 @@ public void Previous()
/// </summary>
public void CommandExec(string Command)
{
if (Tree.SelectedItem is GuiTreeNode)
if (TreeDetails.IsKeyboardFocusWithin)
{
// TODO GuiTreeManager.CommandExec() for TreeDetails
}
else if (Tree.IsKeyboardFocusWithin && Tree.SelectedItem is GuiTreeNode)
{
(Tree.SelectedItem as GuiTreeNode).CommandExec(Command);
}
}

/// <summary>
Expand Down
20 changes: 12 additions & 8 deletions KML/GUI/GuiTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ private void ReLoadChildren()
{
Items.Insert(i, new GuiTreeNode(child));
}
//else
//{
// Add(child);
//}
else if (Items.Count <= i)
{
Add(child);
}
}
// Check if there are Items left to delete (in case of reordering)
for (int i = Items.Count - 1; i > DataNode.Children.Count - 1; i--)
Expand Down Expand Up @@ -712,7 +712,7 @@ private void ContextMenuUpdate(ContextMenu menu)
if (o is MenuItem)
{
MenuItem m = (MenuItem)o;
if (m.Tag == "Clipboard.Paste")
if (m.Tag != null && (m.Tag as string).Equals("Clipboard.Paste"))
m.IsEnabled = Clipboard.ContainsText(TextDataFormat.UnicodeText);
}
}
Expand All @@ -728,6 +728,7 @@ private void PasteNode_Click(object sender, RoutedEventArgs e)

var textNode = Clipboard.GetText(TextDataFormat.UnicodeText);

// Pasting top level attributes would paste them to this node, you will notice, so allow it.
var items = KmlItem.ParseItems(new StringReader(textNode)).Where(i => i is KmlNode || i is KmlAttrib).ToList();

if (!items.Any())
Expand All @@ -743,7 +744,8 @@ private void PasteBeforeNode_Click(object sender, RoutedEventArgs e)
{
var textNode = Clipboard.GetText(TextDataFormat.UnicodeText);

var items = KmlItem.ParseItems(new StringReader(textNode)).Where(i => i is KmlNode || i is KmlAttrib).ToList();
// Pasting top level attributes would paste them to parent node, you may never notice, don't allow.
var items = KmlItem.ParseItems(new StringReader(textNode)).Where(i => i is KmlNode).ToList();

if (!items.Any())
DlgMessage.Show("Can not paste node from clipboard", "Paste node", Icons.Warning);
Expand All @@ -768,7 +770,9 @@ private void CopyNode_Click(object sender, RoutedEventArgs e)

var textNode = sr.GetStringBuilder().ToString();

Clipboard.SetText(textNode, TextDataFormat.UnicodeText);
// Sometimes an error occured with SetText(), see https://stackoverflow.com/a/17678542
// Clipboard.SetText(textNode, TextDataFormat.UnicodeText);
Clipboard.SetDataObject(textNode);
}

private void AddChildNode(KmlNode toItem, KmlNode beforeItem)
Expand Down Expand Up @@ -1060,7 +1064,7 @@ private void NodeDelete_Click(object sender, RoutedEventArgs e)
void DataNode_ChildrenChanged(object sender, RoutedEventArgs e)
{
// If not loaded yet, they will be loaded correctly when expanded
if (!NeedsLoadingChildren())
if (!NeedsLoadingChildren() || Items.Count == 0)
{
ReLoadChildren();
}
Expand Down
8 changes: 7 additions & 1 deletion KML/GUI/GuiVesselsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,14 @@ public void Previous()
/// </summary>
public void CommandExec(string Command)
{
if (VesselsList.SelectedItem is GuiVesselsNode)
if (VesselsDetails.IsKeyboardFocusWithin)
{
// TODO GuiVesselsManager.CommandExec() for VesselsDetails
}
else if (VesselsList.IsKeyboardFocusWithin && VesselsList.SelectedItem is GuiVesselsNode)
{
(VesselsList.SelectedItem as GuiVesselsNode).CommandExec(Command);
}
}

/// <summary>
Expand Down

0 comments on commit bbc2ea7

Please sign in to comment.