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 Nov 4, 2024
1 parent a920957 commit 5177802
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Editor/AGS.Editor/GUI/GUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,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
27 changes: 24 additions & 3 deletions Editor/AGS.Editor/Panes/ScriptEditorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ScriptEditorBase : EditorContentPanel
private const string GO_TO_DEFINITION_COMMAND = "ScriptGoToDefiniton";
private const string FIND_ALL_USAGES_COMMAND = "ScriptFindAllUsages";
private const string GO_TO_SPRITE_COMMAND = "ScriptGoToSprite";
private const string ADD_TO_WATCH_PANE_COMMAND = "ScriptAddToWatch";

protected AGSEditor _agsEditor;
// Loaded script reference, is assigned by the child class.
Expand All @@ -54,6 +55,7 @@ public class ScriptEditorBase : EditorContentPanel
_menuCmdCopy,
_menuCmdPaste,
_menuCmdGoToDefinition,
_menuCmdAddToWatchPane,
_menuCmdFindAllUsages,
_menuCmdGoToSprite;

Expand Down Expand Up @@ -163,13 +165,16 @@ private void InitEditorMenus()

_menuCmdGoToDefinition = new MenuCommand(GO_TO_DEFINITION_COMMAND, "Go to Definition", Keys.F12);
_menuCmdGoToDefinition.Enabled = false;
_menuCmdAddToWatchPane = new MenuCommand(ADD_TO_WATCH_PANE_COMMAND, "Add to Watch", null);
_menuCmdAddToWatchPane.Enabled = false;
_menuCmdFindAllUsages = new MenuCommand(FIND_ALL_USAGES_COMMAND, "Find All Usages", Keys.Shift | Keys.F12);
_menuCmdFindAllUsages.Enabled = false;
_menuCmdGoToSprite = new MenuCommand(GO_TO_SPRITE_COMMAND, "Go to Sprite", Keys.Shift | Keys.F7);
_menuCmdGoToSprite.Enabled = false;

_extraMenu.Commands.Add(MenuCommand.Separator);
_extraMenu.Commands.Add(_menuCmdGoToDefinition);
_extraMenu.Commands.Add(_menuCmdAddToWatchPane);
_extraMenu.Commands.Add(_menuCmdFindAllUsages);
_extraMenu.Commands.Add(_menuCmdGoToSprite);

Expand Down Expand Up @@ -246,7 +251,11 @@ protected override void OnCommandClick(string command)
}
else if (IsContextCommand(command))
{
if (command == GO_TO_DEFINITION_COMMAND ||
if (command == ADD_TO_WATCH_PANE_COMMAND)
{
Factory.GUIController.AddVariableToWatchPanel(_goToDefinition);
}
else if (command == GO_TO_DEFINITION_COMMAND ||
command == FIND_ALL_USAGES_COMMAND)
{
string[] structAndMember = _goToDefinition.Split('.');
Expand Down Expand Up @@ -340,6 +349,7 @@ protected virtual void UpdateUICommands()
(_menuCmdUndo.Enabled != canUndo) ||
(_menuCmdRedo.Enabled != canRedo) ||
(_menuCmdGoToDefinition.Enabled != canGoToDefinition) ||
(_menuCmdAddToWatchPane.Enabled != canGoToDefinition) ||
(_menuCmdFindAllUsages.Enabled != canGoToDefinition) ||
(_menuCmdGoToSprite.Enabled != canGoToSprite);

Expand All @@ -350,7 +360,9 @@ protected virtual void UpdateUICommands()
_menuCmdPaste.Enabled = canPaste;
_menuCmdUndo.Enabled = canUndo;
_menuCmdRedo.Enabled = canRedo;
_menuCmdGoToDefinition.Enabled = _menuCmdFindAllUsages.Enabled = canGoToDefinition;
_menuCmdGoToDefinition.Enabled = canGoToDefinition;
_menuCmdAddToWatchPane.Enabled = canGoToDefinition;
_menuCmdFindAllUsages.Enabled = canGoToDefinition;
_menuCmdGoToSprite.Enabled = canGoToSprite;

Factory.ToolBarManager.RefreshCurrentPane();
Expand All @@ -365,7 +377,10 @@ protected static bool IsStandardEditCommand(string c)

protected static bool IsContextCommand(string c)
{
return (c == GO_TO_DEFINITION_COMMAND) || (c == FIND_ALL_USAGES_COMMAND) || (c == GO_TO_SPRITE_COMMAND);
return (c == GO_TO_DEFINITION_COMMAND) ||
(c == FIND_ALL_USAGES_COMMAND) ||
(c == GO_TO_SPRITE_COMMAND) ||
(c == ADD_TO_WATCH_PANE_COMMAND);
}

protected void UpdateScriptDocumentContext(int clickedPositionInDocument)
Expand Down Expand Up @@ -421,12 +436,18 @@ private void scintilla_ConstructContextMenu(ContextMenuStrip menuStrip, int clic
UpdateScriptDocumentContext(clickedPositionInDocument);

string typeName = _goToDefinition != null ? (" of " + _goToDefinition) : string.Empty;
string varName = _goToDefinition != null ? (_goToDefinition + " to Watch Panel") : string.Empty;

menuItem = new ToolStripMenuItem(_menuCmdGoToDefinition.Name + typeName, null, onClick, GO_TO_DEFINITION_COMMAND);
menuItem.ShortcutKeys = _menuCmdGoToDefinition.ShortcutKey;
menuItem.Enabled = (_goToDefinition != null);
menuStrip.Items.Add(menuItem);

menuItem = new ToolStripMenuItem("Add " + varName, null, onClick, ADD_TO_WATCH_PANE_COMMAND);
menuItem.ShortcutKeys = _menuCmdAddToWatchPane.ShortcutKey;
menuItem.Enabled = (_goToDefinition != null);
menuStrip.Items.Add(menuItem);

menuItem = new ToolStripMenuItem(_menuCmdFindAllUsages.Name + typeName, null, onClick, FIND_ALL_USAGES_COMMAND);
menuItem.ShortcutKeys = _menuCmdFindAllUsages.ShortcutKey;
menuItem.Enabled = (_goToDefinition != null);
Expand Down

0 comments on commit 5177802

Please sign in to comment.