From 677a156e1f5190fd67e7f1f00fc96b9c1ba8371e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Porto?= Date: Tue, 12 Nov 2024 21:20:57 -0300 Subject: [PATCH] Editor: allow drag and drop to WatchPanel --- .../GUI/WatchVariablesPanel.Designer.cs | 3 ++ Editor/AGS.Editor/GUI/WatchVariablesPanel.cs | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/Editor/AGS.Editor/GUI/WatchVariablesPanel.Designer.cs b/Editor/AGS.Editor/GUI/WatchVariablesPanel.Designer.cs index bb11ac71d63..dbf844ab263 100644 --- a/Editor/AGS.Editor/GUI/WatchVariablesPanel.Designer.cs +++ b/Editor/AGS.Editor/GUI/WatchVariablesPanel.Designer.cs @@ -43,6 +43,7 @@ private void InitializeComponent() // // listView1 // + this.listView1.AllowDrop = true; this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.symbolHeader, this.typeHeader, @@ -60,6 +61,8 @@ private void InitializeComponent() this.listView1.TabIndex = 0; this.listView1.UseCompatibleStateImageBehavior = false; this.listView1.View = System.Windows.Forms.View.Details; + this.listView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.listView1_DragDrop); + this.listView1.DragEnter += new System.Windows.Forms.DragEventHandler(this.listView1_DragEnter); this.listView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listView1_KeyDown); this.listView1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.listView1_MouseUp); // diff --git a/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs b/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs index 1ece58615b7..e0fdc5cd87e 100644 --- a/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs +++ b/Editor/AGS.Editor/GUI/WatchVariablesPanel.cs @@ -522,5 +522,52 @@ private void WatchVariablesPanel_Load(object sender, EventArgs e) Factory.GUIController.ColorThemes.Apply(LoadColorTheme); } } + + private static string GetDraggedVar(DragEventArgs e) + { + string droppedWord = string.Empty; + + try + { + // must be a text we got from somewhere, probably script editor + if (e.Data.GetDataPresent(DataFormats.Text)) + { + // Retrieve the text from the drag-and-drop data + string droppedText = (string)e.Data.GetData(DataFormats.Text); + + if (!string.IsNullOrWhiteSpace(droppedText) && droppedText.IndexOfAny(new[] { ' ', '\n' }) == -1) + { + droppedWord = droppedText; + } + } + } + catch (Exception ex) + { + // do nothing + } + + // TO-DO: make it actually select a valid variable somehow + return droppedWord; + } + + private void listView1_DragDrop(object sender, DragEventArgs e) + { + string droppedVar = GetDraggedVar(e); + if (String.IsNullOrEmpty(droppedVar)) + return; + AddVariableToWatchList(droppedVar); + } + + private void listView1_DragEnter(object sender, DragEventArgs e) + { + string droppedVar = GetDraggedVar(e); + if (String.IsNullOrEmpty(droppedVar)) + { + e.Effect = DragDropEffects.None; + return; + } + + e.Effect = DragDropEffects.Copy; // Allow copy operation + } } }