1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Added multi-line custom build command

This commit is contained in:
Brian Fiete 2020-06-22 08:49:23 -07:00
parent c4544f67d3
commit c6f1f358a9
8 changed files with 110 additions and 17 deletions

View file

@ -2159,7 +2159,10 @@ namespace Beefy.widgets
Redo(); Redo();
case .Return: case .Return:
if (mIsMultiline) if (mIsMultiline)
{
mEditWidget.Submit(); mEditWidget.Submit();
return;
}
default: default:
} }
} }

View file

@ -304,6 +304,12 @@ namespace System.Collections
#endif #endif
} }
public void AddRange(IEnumerator<T> items)
{
for (let item in items)
Add(item);
}
/// Returns a pointer to the start of the added uninitialized section /// Returns a pointer to the start of the added uninitialized section
public T* GrowUnitialized(int addSize) public T* GrowUnitialized(int addSize)
{ {

View file

@ -130,7 +130,7 @@ namespace IDE
bool isCommand = false; bool isCommand = false;
for (let c in origCustomCmd.RawChars) for (let c in origCustomCmd.RawChars)
{ {
if ((c == '\"') || (c == '$')) if ((c == '\"') || (c == '$') || (c == '\n'))
break; break;
if (c == '(') if (c == '(')
isCommand = true; isCommand = true;
@ -146,6 +146,9 @@ namespace IDE
{ {
customCmd.Append("%exec "); customCmd.Append("%exec ");
gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, origCustomCmd, "custom command", customCmd); gApp.ResolveConfigString(gApp.mPlatformName, workspaceOptions, project, options, origCustomCmd, "custom command", customCmd);
// For multi-line execs
customCmd.Replace('\n', '\v');
} }
if (customCmd.IsWhiteSpace) if (customCmd.IsWhiteSpace)

View file

@ -7480,8 +7480,9 @@ namespace IDE
{ {
None, None,
ShellCommand = 1, ShellCommand = 1,
NoRedirect = 2, BatchCommand = 2,
NoWait = 4, NoRedirect = 4,
NoWait = 8,
} }
public ExecutionInstance DoRun(String inFileName, String args, String workingDir, ArgsFileKind useArgsFile, Dictionary<String, String> envVars = null, String stdInData = null, RunFlags runFlags = .None) public ExecutionInstance DoRun(String inFileName, String args, String workingDir, ArgsFileKind useArgsFile, Dictionary<String, String> envVars = null, String stdInData = null, RunFlags runFlags = .None)
@ -7506,8 +7507,31 @@ namespace IDE
startInfo.CreateNoWindow = true; startInfo.CreateNoWindow = true;
} }
var executionInstance = new ExecutionInstance();
#if BF_PLATFORM_WINDOWS #if BF_PLATFORM_WINDOWS
if (runFlags.HasFlag(.ShellCommand)) if (runFlags.HasFlag(.BatchCommand))
{
String tempFileName = scope String();
Path.GetTempFileName(tempFileName);
tempFileName.Append(".bat");
String shellArgs = scope .();
IDEUtils.AppendWithOptionalQuotes(shellArgs, fileName);
shellArgs.Append(" ");
shellArgs.Append(args);
var result = File.WriteAllText(tempFileName, shellArgs, Encoding.UTF8);
if (result case .Err)
OutputLine("Failed to create temporary batch file");
startInfo.SetFileName(tempFileName);
startInfo.SetArguments("");
executionInstance.mTempFileName = new String(tempFileName);
}
else if (runFlags.HasFlag(.ShellCommand))
{ {
String shellArgs = scope .(); String shellArgs = scope .();
shellArgs.Append("/c "); shellArgs.Append("/c ");
@ -7525,8 +7549,6 @@ namespace IDE
startInfo.AddEnvironmentVariable(envKV.key, envKV.value); startInfo.AddEnvironmentVariable(envKV.key, envKV.value);
} }
var executionInstance = new ExecutionInstance();
if (useArgsFile != .None) if (useArgsFile != .None)
{ {
String tempFileName = scope String(); String tempFileName = scope String();
@ -7542,7 +7564,8 @@ namespace IDE
String arguments = scope String(); String arguments = scope String();
arguments.Concat("@", tempFileName); arguments.Concat("@", tempFileName);
startInfo.SetArguments(arguments); startInfo.SetArguments(arguments);
delete executionInstance.mTempFileName;
executionInstance.mTempFileName = new String(tempFileName); executionInstance.mTempFileName = new String(tempFileName);
} }

View file

@ -1369,9 +1369,18 @@ namespace IDE
{ {
var exeArgs = scope String(); var exeArgs = scope String();
exeArgs.Append(cmd, spacePos + 1); exeArgs.Append(cmd, spacePos + 1);
IDEApp.RunFlags runFlags = .None;
if (!exePath.EndsWith(".exe", .OrdinalIgnoreCase))
runFlags = .ShellCommand;
bool wantsShellCommand = !exePath.EndsWith(".exe", .OrdinalIgnoreCase); // Hande re-encoded embedded newlines
gApp.DoRun(exePath, exeArgs, gApp.mInstallDir, .None, null, null, wantsShellCommand ? .ShellCommand : .None); if (exeArgs.Contains('\v'))
{
exeArgs.Replace('\v', '\n');
runFlags = .BatchCommand;
}
gApp.DoRun(exePath, exeArgs, gApp.mInstallDir, .None, null, null, runFlags);
} }
} }

View file

@ -282,7 +282,7 @@ namespace IDE.ui
let valueItem = propEntry.mListViewItem.GetSubItem(1); let valueItem = propEntry.mListViewItem.GetSubItem(1);
if (!valueItem.Label.IsEmpty) if (!valueItem.Label.IsEmpty)
{ {
let dialog = ThemeFactory.mDefault.CreateDialog("Remove?", "Are you sure you want to remove the selected custom build options?"); let dialog = ThemeFactory.mDefault.CreateDialog("Remove?", "Are you sure you want to remove the selected distinct build options?");
dialog.AddYesNoButtons(new (evt) => dialog.AddYesNoButtons(new (evt) =>
{ {
DeleteDistinctBuildOptions(propEntry.mListViewItem); DeleteDistinctBuildOptions(propEntry.mListViewItem);

View file

@ -675,6 +675,7 @@ namespace IDE.ui
(listViewItem, propEntry) = AddPropertiesItem(root, "Rebuild Dependencies", "mBuildOptions.mLinkDependencies"); (listViewItem, propEntry) = AddPropertiesItem(root, "Rebuild Dependencies", "mBuildOptions.mLinkDependencies");
(listViewItem, propEntry) = AddPropertiesItem(root, "Prebuild Commands", "mBuildOptions.mPreBuildCmds"); (listViewItem, propEntry) = AddPropertiesItem(root, "Prebuild Commands", "mBuildOptions.mPreBuildCmds");
(listViewItem, propEntry) = AddPropertiesItem(root, "Postbuild Commands", "mBuildOptions.mPostBuildCmds"); (listViewItem, propEntry) = AddPropertiesItem(root, "Postbuild Commands", "mBuildOptions.mPostBuildCmds");
propEntry.mAllowMultiline = true;
(listViewItem, propEntry) = AddPropertiesItem(root, "Clean Commands", "mBuildOptions.mCleanCmds"); (listViewItem, propEntry) = AddPropertiesItem(root, "Clean Commands", "mBuildOptions.mCleanCmds");
(listViewItem, propEntry) = AddPropertiesItem(root, "Build Commands on Compile", "mBuildOptions.mBuildCommandsOnCompile"); (listViewItem, propEntry) = AddPropertiesItem(root, "Build Commands on Compile", "mBuildOptions.mBuildCommandsOnCompile");
(listViewItem, propEntry) = AddPropertiesItem(root, "Build Commands on Run", "mBuildOptions.mBuildCommandsOnRun"); (listViewItem, propEntry) = AddPropertiesItem(root, "Build Commands on Run", "mBuildOptions.mBuildCommandsOnRun");

View file

@ -188,6 +188,12 @@ namespace IDE.ui
BrowseForFolder, BrowseForFolder,
} }
public enum MultiEncodeKind
{
Semicolon,
Extended // Uses /v to split
}
public Flags mFlags; public Flags mFlags;
public DarkListViewItem mListViewItem; public DarkListViewItem mListViewItem;
public Object mTarget; public Object mTarget;
@ -203,9 +209,11 @@ namespace IDE.ui
public PropertyBag mProperties ~ delete _; public PropertyBag mProperties ~ delete _;
public Event<delegate bool()> mOnUpdate ~ _.Dispose(); public Event<delegate bool()> mOnUpdate ~ _.Dispose();
public bool mDisabled; public bool mDisabled;
public bool mMultiRootReadOnly;
public uint32? mColorOverride; public uint32? mColorOverride;
public String mRelPath ~ delete _; public String mRelPath ~ delete _;
public bool mIsTypeWildcard; public bool mIsTypeWildcard;
public bool mAllowMultiline;
public Insets mEditInsets ~ delete _; public Insets mEditInsets ~ delete _;
public ~this() public ~this()
@ -817,6 +825,9 @@ namespace IDE.ui
Rect rect = .(xPos, yPos, GetValueEditWidth(editItem), GS!(20)); Rect rect = .(xPos, yPos, GetValueEditWidth(editItem), GS!(20));
propEntry.mEditInsets?.ApplyTo(ref rect); propEntry.mEditInsets?.ApplyTo(ref rect);
if (mPropEditWidget.mEditWidgetContent.mIsMultiline)
rect.mHeight *= 4;
mPropEditWidget.Resize(rect.Left, rect.Top, rect.Width, rect.mHeight); mPropEditWidget.Resize(rect.Left, rect.Top, rect.Width, rect.mHeight);
//mPropEditWidget.Resize(mPropEditWidget.mX, mPropEditWidget.mY, GetValueEditWidth(mEditingListViewItem.GetSubItem(1)), mPropEditWidget.mHeight); //mPropEditWidget.Resize(mPropEditWidget.mX, mPropEditWidget.mY, GetValueEditWidth(mEditingListViewItem.GetSubItem(1)), mPropEditWidget.mHeight);
@ -961,7 +972,8 @@ namespace IDE.ui
} }
else if (curVariantType == typeof(List<String>)) else if (curVariantType == typeof(List<String>))
{ {
let entryViews = scope List<StringView>(newValue.Split(';')); let entryViews = scope List<StringView>();
entryViews.AddRange(newValue.Split(';'));
let entries = new List<String>(); let entries = new List<String>();
for (int32 i = 0; i < entryViews.Count; i++) for (int32 i = 0; i < entryViews.Count; i++)
@ -969,7 +981,9 @@ namespace IDE.ui
String entry = scope String(entryViews[i]); String entry = scope String(entryViews[i]);
entry.Trim(); entry.Trim();
if (entry.Length > 0) if (entry.Length > 0)
entries.Add(new String(entry)); {
entries.Add(new String(entry));
}
} }
editingProp.mCurValue = Variant.Create(entries, true); editingProp.mCurValue = Variant.Create(entries, true);
} }
@ -1200,6 +1214,9 @@ namespace IDE.ui
var propEntry = propEntries[0]; var propEntry = propEntries[0];
if ((propEntry.mMultiRootReadOnly) && (subValueIdx == -1))
return;
var valueItem = propEntry.mListViewItem.GetSubItem(1); var valueItem = propEntry.mListViewItem.GetSubItem(1);
let type = propEntry.mCurValue.VariantType; let type = propEntry.mCurValue.VariantType;
@ -1219,6 +1236,12 @@ namespace IDE.ui
} }
else else
editWidget = new DarkEditWidget(); editWidget = new DarkEditWidget();
let ewc = editWidget.mEditWidgetContent;
ewc.mIsMultiline = propEntry.mAllowMultiline;
if (ewc.mIsMultiline)
editWidget.InitScrollbars(false, true);
editWidget.mScrollContentInsets.Set(GS!(3), GS!(3), GS!(1), GS!(3)); editWidget.mScrollContentInsets.Set(GS!(3), GS!(3), GS!(1), GS!(3));
editWidget.Content.mTextInsets.Set(GS!(-3), GS!(2), 0, GS!(2)); editWidget.Content.mTextInsets.Set(GS!(-3), GS!(2), 0, GS!(2));
//editWidget.RehupSize(); //editWidget.RehupSize();
@ -1236,7 +1259,8 @@ namespace IDE.ui
moveItemWidget.Resize(6, editWidget.mY - GS!(16), GS!(20), GS!(20)); moveItemWidget.Resize(6, editWidget.mY - GS!(16), GS!(20), GS!(20));
moveItemWidget.mArrowDir = -1; moveItemWidget.mArrowDir = -1;
moveItemWidget.mOnMouseDown.Add(new (evt) => { MoveEditingItem(subValueIdx, -1); }); moveItemWidget.mOnMouseDown.Add(new (evt) => { MoveEditingItem(subValueIdx, -1); });
editWidget.mOnKeyDown.Add(new (evt) => { if (evt.mKeyCode == KeyCode.Up) MoveEditingItem(subValueIdx, -1); }); if (!ewc.mIsMultiline)
editWidget.mOnKeyDown.Add(new (evt) => { if (evt.mKeyCode == KeyCode.Up) MoveEditingItem(subValueIdx, -1); });
} }
if (subValueIdx < stringList.Count - 1) if (subValueIdx < stringList.Count - 1)
@ -1246,7 +1270,8 @@ namespace IDE.ui
moveItemWidget.Resize(6, editWidget.mY + GS!(16), GS!(20), GS!(20)); moveItemWidget.Resize(6, editWidget.mY + GS!(16), GS!(20), GS!(20));
moveItemWidget.mArrowDir = 1; moveItemWidget.mArrowDir = 1;
moveItemWidget.mOnMouseDown.Add(new (evt) => { MoveEditingItem(subValueIdx, 1); }); moveItemWidget.mOnMouseDown.Add(new (evt) => { MoveEditingItem(subValueIdx, 1); });
editWidget.mOnKeyDown.Add(new (evt) => { if (evt.mKeyCode == KeyCode.Down) MoveEditingItem(subValueIdx, 1); }); if (!ewc.mIsMultiline)
editWidget.mOnKeyDown.Add(new (evt) => { if (evt.mKeyCode == KeyCode.Down) MoveEditingItem(subValueIdx, 1); });
} }
} }
else else
@ -1260,7 +1285,20 @@ namespace IDE.ui
if (label == "Not Set") if (label == "Not Set")
label = ""; label = "";
}*/ }*/
if (editWidget is KeysEditWidget)
if (propEntry.mCurValue.VariantType == typeof(List<String>))
{
List<String> stringList = propEntry.mCurValue.Get<List<String>>();
String allValues = scope .();
for (int i = 0; i < stringList.Count; i++)
{
if (i > 0)
allValues.Append(";");
allValues.Append(stringList[i]);
}
editWidget.SetText(allValues);
}
else if (editWidget is KeysEditWidget)
editWidget.SetText("< Press Key >"); editWidget.SetText("< Press Key >");
else else
editWidget.SetText(label); editWidget.SetText(label);
@ -1276,7 +1314,6 @@ namespace IDE.ui
editWidget.SetFocus(); editWidget.SetFocus();
mWidgetWindow.mOnMouseWheel.Add(new => HandleMouseWheel); mWidgetWindow.mOnMouseWheel.Add(new => HandleMouseWheel);
mWidgetWindow.mOnWindowMoved.Add(new => HandleWindowMoved); mWidgetWindow.mOnWindowMoved.Add(new => HandleWindowMoved);
editWidget.mEditWidgetContent.ClearUndoData(); editWidget.mEditWidgetContent.ClearUndoData();
mEditingListViewItem = item; mEditingListViewItem = item;
@ -1350,6 +1387,13 @@ namespace IDE.ui
} }
} }
void FixLabel(ListViewItem lvItem)
{
if (!lvItem.mLabel.Contains('\n'))
return;
lvItem.mLabel.Replace('\n', ' ');
}
if (handled) if (handled)
{ {
if (curVariantType == typeof(String)) if (curVariantType == typeof(String))
@ -1410,9 +1454,11 @@ namespace IDE.ui
if (i < strVals.Count) if (i < strVals.Count)
{ {
if (i > 0) if (i > 0)
allValues.Append(";"); allValues.Append(";");
curValue = strVals[i]; curValue = strVals[i];
allValues.Append(curValue); allValues.Append(curValue);
if (curValue.Contains(';')) // Don't allow editing if the parsing will mess up
propEntry.mMultiRootReadOnly = true;
} }
DarkListViewItem childItem; DarkListViewItem childItem;
@ -1456,12 +1502,14 @@ namespace IDE.ui
childSubItem.mTextColor = 0xFFC0C0C0; childSubItem.mTextColor = 0xFFC0C0C0;
} }
childSubItem.Label = curValue; childSubItem.Label = curValue;
FixLabel(childSubItem);
} }
while (propEntry.mListViewItem.GetChildCount() > strVals.Count + 1) while (propEntry.mListViewItem.GetChildCount() > strVals.Count + 1)
propEntry.mListViewItem.RemoveChildItem(propEntry.mListViewItem.GetChildAtIndex(propEntry.mListViewItem.GetChildCount() - 1)); propEntry.mListViewItem.RemoveChildItem(propEntry.mListViewItem.GetChildAtIndex(propEntry.mListViewItem.GetChildCount() - 1));
valueItem.Label = allValues; valueItem.Label = allValues;
FixLabel(valueItem);
} }
else if (propEntry.mCheckBox != null) else if (propEntry.mCheckBox != null)
{ {