Skip to content
Permalink
Browse files

rudimentary drag'n'drop support for plugins in the character roster

  • Loading branch information...
ArchonMegalon committed Oct 7, 2019
1 parent bbe2aec commit 0d47d5863cac1ea20451dec495ca24c24ad5600a
@@ -62,6 +62,7 @@ public interface IPlugin
Assembly GetPluginAssembly();
void Dispose();
bool SetCharacterRosterNode(TreeNode objNode);
Task<bool> DoCharacterList_DragDrop(object sender, DragEventArgs dragEventArgs, System.Windows.Forms.TreeView treCharacterList);
}


@@ -676,7 +676,7 @@ private void treCharacterList_OnDefaultDragDrop(object sender, DragEventArgs e)
TreeNode nodDestinationNode = treSenderView.GetNodeAt(pt);
if (nodDestinationNode.Level > 0)
nodDestinationNode = nodDestinationNode.Parent;
string strDestinationNode = nodDestinationNode.Tag.ToString();
string strDestinationNode = nodDestinationNode.Tag?.ToString();
if(strDestinationNode != "Watch")
{
if(!(e.Data.GetData("System.Windows.Forms.TreeNode") is TreeNode nodNewNode))
@@ -695,9 +695,20 @@ private void treCharacterList_OnDefaultDragDrop(object sender, DragEventArgs e)
case "Favourite":
GlobalOptions.FavoritedCharacters.Add(objCache.FilePath);
break;
default:
break;
}
}
}

IPlugin plugintag = null;
while (nodDestinationNode?.Tag != null && plugintag == null)
{
if (nodDestinationNode.Tag is IPlugin temp)
plugintag = temp;
nodDestinationNode = nodDestinationNode.Parent;
}
plugintag?.DoCharacterList_DragDrop(sender, e, treCharacterList);
}
}

@@ -9686,5 +9686,9 @@
<key>Rating_Meters</key>
<text>Meter</text>
</string>
<string>
<key>String_SINners_HowToGroupParentDescription</key>
<text>Eine (fertig) erstellte Gruppe kann per Drag'n'Drop einer andere Gruppe (als Sub-Gruppe) zugeordnet werden.</text>
</string>
</strings>
</chummer>
@@ -9811,5 +9811,9 @@ Only one attribute may be at its Maximum value during character creation.</text>
<text>Meters</text>
</string>
<!-- End Region -->
<string>
<key>String_SINners_HowToGroupParentDescription</key>
<text>A group can be appointed as sub-group per drag'n'drop after its creation.</text>
</string>
</strings>
</chummer>
@@ -44,6 +44,7 @@ public class PluginHandler : IPlugin
{
private static Logger Log = NLog.LogManager.GetCurrentClassLogger();
public static UploadClient MyUploadClient = null;
public static IPlugin MyPluginHandlerInstance = null;

public static frmChummerMain MainForm = null;

@@ -64,6 +65,7 @@ public PluginHandler()
Properties.Settings.Default.Save();
}
MyUploadClient.Id = Properties.Settings.Default.UploadClientId;
MyPluginHandlerInstance = this;
}


@@ -951,5 +953,97 @@ private static async Task<Character> MainFormLoadChar(string fileToLoad)
}

}

public async Task<bool> DoCharacterList_DragDrop(object sender, DragEventArgs e, System.Windows.Forms.TreeView treCharacterList )
{
try
{
// Do not allow the root element to be moved.
if (treCharacterList.SelectedNode == null || treCharacterList.SelectedNode.Level == 0 ||
treCharacterList.SelectedNode.Parent?.Tag?.ToString() == "Watch")
return false;

if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
{
if (!(sender is System.Windows.Forms.TreeView treSenderView))
return false;
System.Drawing.Point pt = treSenderView.PointToClient(new System.Drawing.Point(e.X, e.Y));
TreeNode nodDestinationNode = treSenderView.GetNodeAt(pt);
if (nodDestinationNode.Level > 0)
nodDestinationNode = nodDestinationNode.Parent;
string strDestinationNode = nodDestinationNode.Tag?.ToString();
if (strDestinationNode != "Watch")
{
if (!(e.Data.GetData("System.Windows.Forms.TreeNode") is TreeNode nodNewNode))
return false;
var client = StaticUtils.GetClient();
Guid? mySiNnerId = null;
if (nodNewNode.Tag is SINnerSearchGroup sinGroup)
{
if (nodDestinationNode.Tag == PluginHandler.MyPluginHandlerInstance)
{
var res = await client.PutGroupInGroupWithHttpMessagesAsync(sinGroup.Id, sinGroup.Groupname, null);
var handle = await ChummerHub.Client.Backend.Utils.HandleError(res);
return true;
}
else if (nodDestinationNode.Tag is SINnerSearchGroup destGroup)
{
var res = await client.PutGroupInGroupWithHttpMessagesAsync(sinGroup.Id, sinGroup.Groupname, destGroup.Id, sinGroup.MyAdminIdentityRole, sinGroup.IsPublic);
var handle = await ChummerHub.Client.Backend.Utils.HandleError(res);
return true;
}
}
else if (nodNewNode.Tag is frmCharacterRoster.CharacterCache objCache)
{
Object sinidob = null;
if (objCache.MyPluginDataDic?.TryGetValue("SINnerId", out sinidob) == true)
{
mySiNnerId = (Guid?) sinidob;
}
else
{
var ce = await ChummerHub.Client.Backend.Utils.UploadCharacterFromFile(objCache.FilePath);
mySiNnerId = ce?.MySINnerFile?.Id;
}
}
else if (nodNewNode.Tag is SINner sinner)
{
mySiNnerId = sinner.Id;
}

if (mySiNnerId != null)
{
if (nodDestinationNode.Tag == PluginHandler.MyPluginHandlerInstance)
{
var res = await client.PutSINerInGroupWithHttpMessagesAsync(null, mySiNnerId);
var handle = await ChummerHub.Client.Backend.Utils.HandleError(res);
return true;
}
else if (nodDestinationNode.Tag is SINnerSearchGroup destGroup)
{
string passwd = null;
if (destGroup.HasPassword == true)
{
passwd = ChummerHub.Client.UI.Prompt.ShowDialog("Password", "Password required!");
passwd = SINnerGroup.GetHashString(passwd);
}
var res = await client.PutSINerInGroupWithHttpMessagesAsync(destGroup.Id, mySiNnerId, passwd);
var handle = await ChummerHub.Client.Backend.Utils.HandleError(res);
return true;
}
}
}
}
}
catch (Exception exception)
{
Log.Error(exception);
}
finally
{
PluginHandler.MainForm.CharacterRoster.LoadCharacters(false, false, false, true);
}
return true;
}
}
}

0 comments on commit 0d47d58

Please sign in to comment.
You can’t perform that action at this time.