Skip to content

Commit

Permalink
Editor: simple add to watch pane implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ericoporto committed Jul 13, 2024
1 parent 3deaf8e commit c021c24
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Editor/AGS.Editor/GUI/GUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ public void HideFindSymbolResults()
_mainForm.pnlFindResults.Hide();
}

public void AddVariableToWatchPanel(string var_name)
{
_mainForm.pnlWatchVariables.AddVariableToWatchList(var_name);
if (_mainForm.pnlWatchVariables.IsHidden)
return;
_mainForm.pnlWatchVariables.Show();
}

public void ShowWatchVariablesPanel(bool ifEnabled)
{
if (ifEnabled && _mainForm.pnlWatchVariables.IsHidden)
Expand Down
8 changes: 8 additions & 0 deletions Editor/AGS.Editor/GUI/WatchVariablesPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ private void listView1_MouseUp(object sender, MouseEventArgs e)
}
}

public void AddVariableToWatchList(string var_name)
{
ListViewItem item = listView1.Items.Add(CreateItem(var_name));
lock (_updateItemLock)
_itemsToUpdate.Add(item);
_updateItemTimer.Start();
}

private void addToolStripMenuItem_Click(object sender, EventArgs e)
{
ListViewItem item;
Expand Down
15 changes: 14 additions & 1 deletion Editor/AGS.Editor/Panes/ScriptEditorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class ScriptEditorBase : EditorContentPanel
private const string CONTEXT_MENU_GO_TO_DEFINITION = "CtxGoToDefiniton";
private const string CONTEXT_MENU_FIND_ALL_USAGES = "CtxFindAllUsages";
private const string CONTEXT_MENU_GO_TO_SPRITE = "CtxGoToSprite";
private const string CONTEXT_MENU_ADD_TO_WATCH_PANE = "CtxAddToWatch";

protected AGSEditor _agsEditor;
// Loaded script reference, is assigned by the child class.
Expand Down Expand Up @@ -322,6 +323,7 @@ private void scintilla_ConstructContextMenu(ContextMenuStrip menuStrip, int clic

_goToSprite = null;
string clickedOnType = string.Empty;
string varName = string.Empty;
if (!_scintilla.InsideStringOrComment(clickedPositionInDocument))
{
float dummy;
Expand All @@ -338,6 +340,7 @@ private void scintilla_ConstructContextMenu(ContextMenuStrip menuStrip, int clic
else if (!float.TryParse(clickedOnType, out dummy))
{
_goToDefinition = clickedOnType;
varName = clickedOnType;
clickedOnType = " of " + clickedOnType;
}
}
Expand All @@ -347,6 +350,12 @@ private void scintilla_ConstructContextMenu(ContextMenuStrip menuStrip, int clic
}
}

menuStrip.Items.Add(new ToolStripMenuItem("Add " + varName + " to Watch Panel", null, onClick, CONTEXT_MENU_ADD_TO_WATCH_PANE));
if (varName == string.Empty)
{
menuStrip.Items[menuStrip.Items.Count - 1].Enabled = false;
}

menuStrip.Items.Add(new ToolStripMenuItem("Go to Definition" + clickedOnType, null, onClick, CONTEXT_MENU_GO_TO_DEFINITION));
if (clickedOnType == string.Empty)
{
Expand Down Expand Up @@ -376,7 +385,11 @@ private void scintilla_ActivateContextMenu(string commandName)
private void ContextMenuChooseOption(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
if (item.Name == CONTEXT_MENU_GO_TO_DEFINITION ||
if(item.Name == CONTEXT_MENU_ADD_TO_WATCH_PANE)
{
Factory.GUIController.AddVariableToWatchPanel(_goToDefinition);
}
else if (item.Name == CONTEXT_MENU_GO_TO_DEFINITION ||
item.Name == CONTEXT_MENU_FIND_ALL_USAGES)
{
string[] structAndMember = _goToDefinition.Split('.');
Expand Down

0 comments on commit c021c24

Please sign in to comment.