1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 11:38:21 +02:00

Fixed some IDE issues

Fixed some issues related to creating new projects and workspace
Added 'Refresh' option to project
Fixed auto-include refresh
Fixed folder rename
Fixed EOF issue involving DbgModule string table
This commit is contained in:
Brian Fiete 2019-09-05 08:18:24 -07:00
parent 8a02874b51
commit 0ce6e44523
14 changed files with 374 additions and 163 deletions

View file

@ -811,19 +811,29 @@ namespace Beefy.widgets
public static bool HandleTab(int dir, List<Widget> tabWidgets) public static bool HandleTab(int dir, List<Widget> tabWidgets)
{ {
Widget wantFocus = null;
if (tabWidgets.IsEmpty)
return false;
for (int32 idx = 0; idx < tabWidgets.Count; idx++) for (int32 idx = 0; idx < tabWidgets.Count; idx++)
{ {
Widget widget = tabWidgets[idx]; Widget widget = tabWidgets[idx];
if (widget.mHasFocus) if (widget.mHasFocus)
{ {
var nextWidget = tabWidgets[(idx + tabWidgets.Count + dir) % tabWidgets.Count]; var nextWidget = tabWidgets[(idx + tabWidgets.Count + dir) % tabWidgets.Count];
nextWidget.SetFocus(); wantFocus = nextWidget;
if (var editWidget = nextWidget as EditWidget) break;
editWidget.mEditWidgetContent.SelectAll();
return true;
} }
} }
return false;
if (wantFocus == null)
wantFocus = tabWidgets[0];
wantFocus.SetFocus();
if (var editWidget = wantFocus as EditWidget)
editWidget.mEditWidgetContent.SelectAll();
return true;
} }
} }
} }

View file

@ -43,7 +43,6 @@ namespace System.IO
public void Reset() public void Reset()
{ {
//mRootFolder = .Default;
mSelectedPath.Clear(); mSelectedPath.Clear();
mDescriptionText.Clear(); mDescriptionText.Clear();
mSelectedPathNeedsCheck = false; mSelectedPathNeedsCheck = false;

View file

@ -838,6 +838,7 @@ namespace System
public void Append(String str, int offset, int length) public void Append(String str, int offset, int length)
{ {
Debug.Assert((uint)offset <= (uint)str.mLength); Debug.Assert((uint)offset <= (uint)str.mLength);
Debug.Assert(length >= 0);
Debug.Assert((uint)offset + (uint)length <= (uint)str.mLength); Debug.Assert((uint)offset + (uint)length <= (uint)str.mLength);
Append(str.Ptr + offset, length); Append(str.Ptr + offset, length);
} }

View file

@ -55,12 +55,12 @@ bool FileHandleStream::Eof()
::SetFilePointer(mFileHandle, 0, 0, FILE_END); ::SetFilePointer(mFileHandle, 0, 0, FILE_END);
return mVFilePos >= (int)::SetFilePointer(mFileHandle, 0, 0, FILE_CURRENT); return mVFilePos >= (int)::SetFilePointer(mFileHandle, 0, 0, FILE_CURRENT);
} }
return ::SetFilePointer(mFileHandle, 0, 0, FILE_CURRENT) != ::GetFileSize(mFileHandle, NULL); return ::SetFilePointer(mFileHandle, 0, 0, FILE_CURRENT) >= ::GetFileSize(mFileHandle, NULL);
} }
int FileHandleStream::GetSize() int FileHandleStream::GetSize()
{ {
return ::GetFileSize(mFileHandle, NULL);; return ::GetFileSize(mFileHandle, NULL);
} }
void FileHandleStream::Read(void* ptr, int size) void FileHandleStream::Read(void* ptr, int size)

View file

@ -27,7 +27,7 @@ TargetDirectory = "$(WorkspaceDir)/dist"
TargetName = "BeefIDE_d" TargetName = "BeefIDE_d"
OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib" OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib"
CLibType = "Dynamic" CLibType = "Dynamic"
DebugCommandArguments = "-workspace=c:\\beef\\ide -dbgCompileDump" DebugCommandArguments = "-workspace=c:\\beef\\BeefTools\\LogViewer"
DebugWorkingDirectory = "c:\\Beef\\IDE\\Tests\\EmptyTest" DebugWorkingDirectory = "c:\\Beef\\IDE\\Tests\\EmptyTest"
EnvironmentVars = ["_NO_DEBUG_HEAP=1"] EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
@ -56,7 +56,7 @@ TargetName = "BeefIDE_d2"
OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib BeefySysLib64_d.lib wsock32.lib" OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib BeefySysLib64_d.lib wsock32.lib"
CLibType = "Dynamic" CLibType = "Dynamic"
BeefLibType = "DynamicDebug" BeefLibType = "DynamicDebug"
DebugCommandArguments = "-proddir=C:\\Beef\\IDE\\mintest -dbgCompileDump" DebugCommandArguments = "-workspace=c:\\_beef\\testapp"
DebugWorkingDirectory = "$(ProjectDir)\\dist" DebugWorkingDirectory = "$(ProjectDir)\\dist"
EnvironmentVars = ["_NO_DEBUG_HEAP=1"] EnvironmentVars = ["_NO_DEBUG_HEAP=1"]

View file

@ -114,7 +114,7 @@ class Blurg
public static void Hey() public static void Hey()
{ {
function void() func = null;
} }
} }

View file

@ -84,7 +84,19 @@ namespace IDE
void FileChanged(String filePath, String newPath, WatcherChangeTypes changeType) void FileChanged(String filePath, String newPath, WatcherChangeTypes changeType)
{ {
if (changeType == .Renamed) bool isDirectory = filePath.EndsWith(Path.DirectorySeparatorChar);
var newPath;
if (isDirectory)
{
if (newPath.EndsWith(Path.DirectorySeparatorChar))
{
newPath = scope:: String();
newPath.Append(@newPath, 0, @newPath.Length - 1);
}
}
if ((changeType == .Renamed) && (!isDirectory))
{ {
// ALWAYS interpret 'file rename' notifications as a delete of filePath and a create of newPath // ALWAYS interpret 'file rename' notifications as a delete of filePath and a create of newPath
// A manual rename in the IDE will have manually processed the rename before we get here, so // A manual rename in the IDE will have manually processed the rename before we get here, so
@ -258,7 +270,7 @@ namespace IDE
if (newName != null) if (newName != null)
{ {
var newFullPath = new String(); var newFullPath = new String();
Path.GetDirectoryPath(fullPath, newFullPath); newFullPath.Append(fileSystemWatcher.Directory);
newFullPath.Append(Path.DirectorySeparatorChar); newFullPath.Append(Path.DirectorySeparatorChar);
newFullPath.Append(newName); newFullPath.Append(newName);
queuedFileChange.mNewFileName = newFullPath; queuedFileChange.mNewFileName = newFullPath;
@ -363,7 +375,19 @@ namespace IDE
CheckFileCreated(newName); CheckFileCreated(newName);
} }
else else
QueueFileChanged(fileSystemWatcher, oldName, newName, .Renamed); {
var newFilePath = scope String();
GetPath(newName, newFilePath);
if (Directory.Exists(newFilePath))
{
let dirOldName = scope String()..Concat(oldName, Path.DirectorySeparatorChar);
let dirNewName = scope String()..Concat(newName, Path.DirectorySeparatorChar);
QueueFileChanged(fileSystemWatcher, dirOldName, dirNewName, .Renamed);
}
else
QueueFileChanged(fileSystemWatcher, oldName, newName, .Renamed);
}
} }
}); });
fileSystemWatcher.OnError.Add(new () => QueueFileChanged(fileSystemWatcher, null, null, .Failed)); fileSystemWatcher.OnError.Add(new () => QueueFileChanged(fileSystemWatcher, null, null, .Failed));

View file

@ -321,6 +321,8 @@ namespace IDE
None, None,
File, File,
Workspace, Workspace,
NewWorkspace,
NewWorkspaceOrProject,
CrashDump, CrashDump,
DebugSession DebugSession
} }
@ -766,7 +768,7 @@ namespace IDE
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName); Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
LoadWorkspace(); LoadWorkspace(.OpenOrNew);
FinishShowingNewWorkspace(); FinishShowingNewWorkspace();
DeleteAndNullify!(mDeferredOpenFileName); DeleteAndNullify!(mDeferredOpenFileName);
@ -1646,6 +1648,10 @@ namespace IDE
bool SaveWorkspaceUserData(bool showErrors = true) bool SaveWorkspaceUserData(bool showErrors = true)
{ {
// Don't save if we didn't finish creating the workspace
if (mWorkspace.mNeedsCreate)
return false;
if (mWorkspace.IsDebugSession) if (mWorkspace.IsDebugSession)
{ {
bool hasUnsavedProjects = false; bool hasUnsavedProjects = false;
@ -1740,35 +1746,9 @@ namespace IDE
{ {
if (!mWorkspace.IsSingleFileWorkspace) if (!mWorkspace.IsSingleFileWorkspace)
{ {
#if !CLI #if !CLI
if (mWorkspace.mDir == null) if (mWorkspace.mDir == null)
{ {
/*SaveFileDialog dialog = scope .();
dialog.ValidateNames = true;
dialog.DefaultExt = ".toml";
dialog.SetFilter("Beef projects (BeefProj.toml)|BeefProj.toml");
dialog.FileName = "BeefProj.toml";
if (dialog.ShowDialog(GetActiveWindow()).GetValueOrDefault() != .OK)
return false;
bool matches = false;
if (dialog.FileNames.Count == 1)
{
String fileName = scope .();
Path.GetFileName(dialog.FileNames[0], fileName);
matches = fileName == "BeefProj.toml";
}
if (!matches)
{
Fail("Workspace name must be 'BeefProj.toml'");
return false;
}
mWorkspace.mDir = new String();
Path.GetDirectoryPath(dialog.FileNames[0], mWorkspace.mDir);*/
let activeWindow = GetActiveWindow(); let activeWindow = GetActiveWindow();
FolderBrowserDialog folderDialog = scope FolderBrowserDialog(); FolderBrowserDialog folderDialog = scope FolderBrowserDialog();
@ -1960,7 +1940,7 @@ namespace IDE
ProjectOptionsChanged(project, false); ProjectOptionsChanged(project, false);
} }
public void CreateProject(String projName, String projDir, Project.TargetType targetType) public Project CreateProject(String projName, String projDir, Project.TargetType targetType)
{ {
Project project = new Project(); Project project = new Project();
project.mProjectName.Set(projName); project.mProjectName.Set(projName);
@ -1982,6 +1962,7 @@ namespace IDE
mWorkspace.ClearProjectNameCache(); mWorkspace.ClearProjectNameCache();
CurrentWorkspaceConfigChanged(); CurrentWorkspaceConfigChanged();
return project;
} }
void StopDebugging() void StopDebugging()
@ -2175,7 +2156,7 @@ namespace IDE
return .Err; return .Err;
} }
protected void LoadWorkspace() protected void LoadWorkspace(BeefVerb verb)
{ {
scope AutoBeefPerf("IDEApp.LoadWorkspace"); scope AutoBeefPerf("IDEApp.LoadWorkspace");
@ -2210,11 +2191,11 @@ namespace IDE
LoadFailed(); LoadFailed();
return; return;
case .FileError: // Assume 'file not found' case .FileError: // Assume 'file not found'
if (mVerb == .OpenOrNew) if (verb == .OpenOrNew)
{ {
isNew = true; isNew = true;
} }
else if (mVerb == .New) else if (verb == .New)
{ {
isNew = true; isNew = true;
wantSave = true; wantSave = true;
@ -2257,6 +2238,9 @@ namespace IDE
project.mProjectPath.Set(mWorkspace.mDir); project.mProjectPath.Set(mWorkspace.mDir);
Utils.GetDirWithSlash(project.mProjectPath); Utils.GetDirWithSlash(project.mProjectPath);
project.mProjectPath.Append("BeefProj.toml"); project.mProjectPath.Append("BeefProj.toml");
//project.FinishCreate();
project.FinishCreate(false);
var verSpec = new VerSpecRecord(); var verSpec = new VerSpecRecord();
verSpec.SetSemVer("*"); verSpec.SetSemVer("*");
@ -2922,7 +2906,7 @@ namespace IDE
[IDECommand] [IDECommand]
public void Cmd_NewWorkspace() public void Cmd_NewWorkspace()
{ {
OpenWorkspace(); mDeferredOpen = .NewWorkspaceOrProject;
} }
[IDECommand] [IDECommand]
@ -3107,7 +3091,7 @@ namespace IDE
textPanel.ShowQuickFind(isReplace); textPanel.ShowQuickFind(isReplace);
else else
{ {
if (let activeWindow = GetActiveWindow() as WidgetWindow) if (let activeWindow = GetActiveWindow())
{ {
var widget = activeWindow.mFocusWidget; var widget = activeWindow.mFocusWidget;
while (widget != null) while (widget != null)
@ -3207,7 +3191,7 @@ namespace IDE
} }
else else
{ {
if (let activeWindow = GetActiveWindow() as WidgetWindow) if (let activeWindow = GetActiveWindow())
{ {
var widget = activeWindow.mFocusWidget; var widget = activeWindow.mFocusWidget;
while (widget != null) while (widget != null)
@ -5030,11 +5014,16 @@ namespace IDE
return null; return null;
} }
public BFWindow GetActiveWindow() public WidgetWindow GetActiveWindow()
{ {
for (let window in mWindows) for (let window in mWindows)
if (window.mHasFocus) if (window.mHasFocus)
return window; {
var result = window;
while ((result.mWindowFlags.HasFlag(.Modal)) && (result.mParent != null))
result = result.mParent;
return result as WidgetWindow;
}
return mMainWindow; return mMainWindow;
} }
@ -5621,6 +5610,10 @@ namespace IDE
if (showType == SourceShowType.Temp) if (showType == SourceShowType.Temp)
{ {
let prevAutoClose = tabbedView.mAutoClose;
defer { tabbedView.mAutoClose = prevAutoClose; }
tabbedView.mAutoClose = false;
if (tabbedView.mRightTab != null) if (tabbedView.mRightTab != null)
{ {
CloseDocument(tabbedView.mRightTab.mContent); CloseDocument(tabbedView.mRightTab.mContent);
@ -9147,7 +9140,7 @@ namespace IDE
}); });
((DarkButton)dlg.mButtons[0]).Label = "Open Link"; ((DarkButton)dlg.mButtons[0]).Label = "Open Link";
dlg.PopupWindow(GetActiveWindow() as WidgetWindow); dlg.PopupWindow(GetActiveWindow());
MessageBeep(.Error); MessageBeep(.Error);
#endif #endif
} }
@ -9637,13 +9630,13 @@ namespace IDE
{ {
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileName(mWorkspace.mDir, mWorkspace.mName); Path.GetFileName(mWorkspace.mDir, mWorkspace.mName);
LoadWorkspace(); LoadWorkspace(mVerb);
} }
else if (mWorkspace.IsSingleFileWorkspace) else if (mWorkspace.IsSingleFileWorkspace)
{ {
mWorkspace.mName = new String(); mWorkspace.mName = new String();
Path.GetFileNameWithoutExtension(mWorkspace.mCompositeFile.mFilePath, mWorkspace.mName); Path.GetFileNameWithoutExtension(mWorkspace.mCompositeFile.mFilePath, mWorkspace.mName);
LoadWorkspace(); LoadWorkspace(mVerb);
} }
if ((mRunningTestScript) || (!LoadWorkspaceUserData())) if ((mRunningTestScript) || (!LoadWorkspaceUserData()))
@ -11358,6 +11351,117 @@ namespace IDE
DeleteAndNullify!(mDeferredUserRequest); DeleteAndNullify!(mDeferredUserRequest);
} }
void UpdateDeferredOpens()
{
void DoDeferredOpen(DeferredOpenKind openKind)
{
switch (openKind)
{
case .NewWorkspaceOrProject:
var dialog = ThemeFactory.mDefault.CreateDialog("Create Workspace?",
"Do you want to create an empty workspace or a new project?");
dialog.AddButton("Empty Workspace", new (evt) =>
{
mDeferredOpen = .NewWorkspace;
});
dialog.AddButton("New Project", new (evt) =>
{
CloseWorkspace();
FinishShowingNewWorkspace();
Cmd_NewProject();
});
dialog.PopupWindow(GetActiveWindow());
case .NewWorkspace:
if (mDeferredOpenFileName != null)
{
let directoryPath = scope String();
Path.GetDirectoryPath(mDeferredOpenFileName, directoryPath);
if (File.Exists(mDeferredOpenFileName))
{
var dialog = ThemeFactory.mDefault.CreateDialog("Already Exists",
scope String()..AppendF("A Beef workspace already exists at '{}'. Do you want to open it?", directoryPath),
DarkTheme.sDarkTheme.mIconWarning);
dialog.mDefaultButton = dialog.AddButton("Yes", new (evt) =>
{
DoOpenWorkspace();
});
dialog.AddButton("No", new (evt) =>
{
DeleteAndNullify!(mDeferredOpenFileName);
});
dialog.PopupWindow(GetActiveWindow());
return;
}
else if (!IDEUtils.IsDirectoryEmpty(directoryPath))
{
var dialog = ThemeFactory.mDefault.CreateDialog("Already Exists",
scope String()..AppendF("A non-empty directory already exists at '{}'. Are you sure you want to create a workspace there?", directoryPath),
DarkTheme.sDarkTheme.mIconWarning);
dialog.mDefaultButton = dialog.AddButton("Yes", new (evt) =>
{
DoOpenWorkspace();
});
dialog.AddButton("No", new (evt) =>
{
DeleteAndNullify!(mDeferredOpenFileName);
});
dialog.PopupWindow(GetActiveWindow());
return;
}
}
DoOpenWorkspace();
if (mDeferredOpen != .None)
mDeferredOpen = _;
case .Workspace:
DoOpenWorkspace();
case .CrashDump:
DoOpenCrashDump();
default:
}
}
var deferredOpen = mDeferredOpen;
mDeferredOpen = .None;
switch (deferredOpen)
{
case .File:
DoOpenFile();
case .CrashDump:
DoOpenCrashDump();
case .Workspace, .NewWorkspace, .NewWorkspaceOrProject:
if ((mDeferredOpenFileName == null) && (deferredOpen == .Workspace))
{
DoDeferredOpen(_);
break;
}
if (CheckCloseWorkspace(mMainWindow,
new () =>
{
DoDeferredOpen(_);
},
new () =>
{
DoDeferredOpen(_);
},
new () =>
{
DeleteAndNullify!(mDeferredOpenFileName);
}
))
{
DoDeferredOpen(_);
}
case .DebugSession:
DoOpenDebugSession();
default:
}
}
public override void Update(bool batchStart) public override void Update(bool batchStart)
{ {
scope AutoBeefPerf("IDEApp.Update"); scope AutoBeefPerf("IDEApp.Update");
@ -11473,55 +11577,7 @@ namespace IDE
if (mBfResolveSystem != null) if (mBfResolveSystem != null)
mBfResolveSystem.PerfZoneEnd(); mBfResolveSystem.PerfZoneEnd();
void DoDeferredOpen(DeferredOpenKind openKind) UpdateDeferredOpens();
{
switch (openKind)
{
case .Workspace:
DoOpenWorkspace();
case .CrashDump:
DoOpenCrashDump();
default:
}
}
var deferredOpen = mDeferredOpen;
mDeferredOpen = .None;
switch (deferredOpen)
{
case .File:
DoOpenFile();
case .CrashDump:
DoOpenCrashDump();
case .Workspace:
if (mDeferredOpenFileName == null)
{
DoDeferredOpen(_);
break;
}
if (CheckCloseWorkspace(mMainWindow,
new () =>
{
DoDeferredOpen(_);
},
new () =>
{
DoDeferredOpen(_);
},
new () =>
{
DeleteAndNullify!(mDeferredOpenFileName);
}
))
{
DoDeferredOpen(_);
}
case .DebugSession:
DoOpenDebugSession();
default:
}
mHaveSourcesChangedInternallySinceLastCompile = false; mHaveSourcesChangedInternallySinceLastCompile = false;
WithSourceViewPanels(scope (sourceViewPanel) => WithSourceViewPanels(scope (sourceViewPanel) =>

View file

@ -71,6 +71,15 @@ namespace IDE
return true; return true;
} }
public static bool IsDirectoryEmpty(StringView dirPath)
{
for (let entry in Directory.Enumerate(scope String()..AppendF("{}/*.*", dirPath), .Directories | .Files))
{
return false;
}
return true;
}
public static bool FixFilePath(String filePath) public static bool FixFilePath(String filePath)
{ {
return FixFilePath(filePath, cNativeSlash, cOtherSlash); return FixFilePath(filePath, cNativeSlash, cOtherSlash);

View file

@ -391,13 +391,6 @@ namespace IDE
public class ProjectFolder : ProjectFileItem public class ProjectFolder : ProjectFileItem
{ {
public enum AutoIncludeKind
{
Default,
Always,
Never
}
public List<ProjectItem> mChildItems = new List<ProjectItem>() ~ public List<ProjectItem> mChildItems = new List<ProjectItem>() ~
{ {
for (var projectItem in mChildItems) for (var projectItem in mChildItems)
@ -551,7 +544,7 @@ namespace IDE
data.Add("Type", (mIncludeKind == .Ignore) ? "IgnoreFolder" : "Folder"); data.Add("Type", (mIncludeKind == .Ignore) ? "IgnoreFolder" : "Folder");
base.Serialize(data); base.Serialize(data);
if (mAutoInclude != (mIncludeKind == .Auto)) if (mAutoInclude != (mIncludeKind == .Auto))
data.Add("AutoInclude", mAutoInclude); data.ConditionalAdd("AutoInclude", mAutoInclude, true);
} }
if (!mChildItems.IsEmpty) if (!mChildItems.IsEmpty)
{ {
@ -598,12 +591,12 @@ namespace IDE
//var outer = data.Current; //var outer = data.Current;
bool autoInclude = data.GetBool("AutoInclude"); bool doPopulate = false;
bool autoInclude = data.GetBool("AutoInclude", true);
if ((autoInclude) && (!mAutoInclude)) if ((autoInclude) && (!mAutoInclude))
{ doPopulate = true;
mAutoInclude = true; mAutoInclude = autoInclude;
Populate(mPath);
}
for (data.Enumerate("Items")) for (data.Enumerate("Items"))
{ {
@ -670,6 +663,9 @@ namespace IDE
projectItem.mPath = path; projectItem.mPath = path;
AddChild(projectItem); AddChild(projectItem);
} }
if (doPopulate)
Populate(mPath);
} }
public void Populate(String relDir) public void Populate(String relDir)
@ -703,7 +699,11 @@ namespace IDE
String dirName = scope String(); String dirName = scope String();
fileEntry.GetFileName(dirName); fileEntry.GetFileName(dirName);
if (dirName == "build") // Why was this here?
/*if (dirName == "build")
continue;*/
if (mChildMap.ContainsKey(dirName))
continue; continue;
let newRelDir = scope String(relDir); let newRelDir = scope String(relDir);
@ -1925,16 +1925,22 @@ namespace IDE
mRootFolder.StartWatching(); mRootFolder.StartWatching();
} }
public void FinishCreate() public void FinishCreate(bool allowCreateDir = true)
{ {
var path = scope String();
mRootFolder.GetFullImportPath(path);
Directory.CreateDirectory(path).IgnoreError();
if (!mRootFolder.mIsWatching) if (!mRootFolder.mIsWatching)
{ {
String fullPath = scope String(); String fullPath = scope String();
mRootFolder.GetFullImportPath(fullPath); mRootFolder.GetFullImportPath(fullPath);
Directory.CreateDirectory(fullPath).IgnoreError(); if (Directory.Exists(fullPath))
{
mRootFolder.Populate("src");
}
else if (!allowCreateDir)
{
return;
}
else
Directory.CreateDirectory(fullPath).IgnoreError();
mRootFolder.StartWatching(); mRootFolder.StartWatching();
} }
mNeedsCreate = false; mNeedsCreate = false;

View file

@ -7,6 +7,7 @@ using Beefy;
using Beefy.gfx; using Beefy.gfx;
using Beefy.theme.dark; using Beefy.theme.dark;
using Beefy.widgets; using Beefy.widgets;
using Beefy.theme;
namespace IDE.ui namespace IDE.ui
{ {
@ -33,8 +34,14 @@ namespace IDE.ui
mWidth = GS!(320); mWidth = GS!(320);
mHeight = GS!(200); mHeight = GS!(200);
} }
bool CreateProject() enum CreateFlags
{
None,
NonEmptyDirOkay = 1,
}
bool CreateProject(CreateFlags createFlags = .None)
{ {
var app = IDEApp.sApp; var app = IDEApp.sApp;
String projName = scope String(); String projName = scope String();
@ -44,6 +51,13 @@ namespace IDE.ui
mDirectoryEdit.GetText(projDirectory); mDirectoryEdit.GetText(projDirectory);
projDirectory.Trim(); projDirectory.Trim();
if (projName.IsEmpty)
{
while ((projDirectory.EndsWith('/')) || (projDirectory.EndsWith('\\')))
projDirectory.RemoveFromEnd(1);
Path.GetFileName(projDirectory, projName);
}
bool isNameValid = projName.Length > 0; bool isNameValid = projName.Length > 0;
for (int32 i = 0; i < projName.Length; i++) for (int32 i = 0; i < projName.Length; i++)
{ {
@ -75,6 +89,24 @@ namespace IDE.ui
return false; return false;
} }
} }
else
{
if ((!createFlags.HasFlag(.NonEmptyDirOkay)) && (!IDEUtils.IsDirectoryEmpty(projDirectory)))
{
var dialog = ThemeFactory.mDefault.CreateDialog("Create Project?",
scope String()..AppendF("The selected directory '{}' is not empty. Are you sure you want to create a project there?", projDirectory), DarkTheme.sDarkTheme.mIconWarning);
dialog.AddButton("Yes", new (evt) =>
{
CreateProject(createFlags | .NonEmptyDirOkay);
});
dialog.AddButton("No", new (evt) =>
{
mDirectoryEdit.SetFocus();
});
dialog.PopupWindow(mWidgetWindow);
return false;
}
}
String projectFilePath = scope String()..Append(projDirectory, "/BeefProj.toml"); String projectFilePath = scope String()..Append(projDirectory, "/BeefProj.toml");
if (File.Exists(projectFilePath)) if (File.Exists(projectFilePath))
@ -93,7 +125,28 @@ namespace IDE.ui
} }
IDEUtils.FixFilePath(projDirectory); IDEUtils.FixFilePath(projDirectory);
app.CreateProject(projName, projDirectory, targetType);
Project project = null;
// If we don't yet have a workspace then create one now...
if (!app.mWorkspace.IsInitialized)
{
app.mWorkspace.mDir = new String(projDirectory);
app.mWorkspace.mName = new String(projName);
app.[Friend]LoadWorkspace(.OpenOrNew);
app.[Friend]FinishShowingNewWorkspace(false);
project = app.mWorkspace.FindProject(projName);
if (project != null)
{
project.mGeneralOptions.mTargetType = targetType;
project.FinishCreate();
}
}
if (project == null)
project = app.CreateProject(projName, projDirectory, targetType);
app.mWorkspace.SetChanged(); app.mWorkspace.SetChanged();
@ -116,7 +169,7 @@ namespace IDE.ui
{ {
mDefaultButton = AddButton("Create", new (evt) => { if (!CreateProject()) evt.mCloseDialog = false; }); mDefaultButton = AddButton("Create", new (evt) => { if (!CreateProject()) evt.mCloseDialog = false; });
mEscButton = AddButton("Cancel", new (evt) => Close()); mEscButton = AddButton("Cancel", new (evt) => Close());
mNameEdit = AddEdit("NewProject"); mNameEdit = AddEdit("");
mNameEdit.mOnContentChanged.Add(new (dlg) => mNameEdit.mOnContentChanged.Add(new (dlg) =>
{ {
UpdateProjectDir(); UpdateProjectDir();

View file

@ -127,7 +127,7 @@ namespace IDE.ui
if (nextSlash != -1) if (nextSlash != -1)
selStr.Append(editText, startSlash + 1, nextSlash - startSlash - 1); selStr.Append(editText, startSlash + 1, nextSlash - startSlash - 1);
else else
selStr.Append(editText, startSlash + 1, cursorPos - startSlash - 1); selStr.Append(editText, startSlash + 1, Math.Max(cursorPos - startSlash - 1, 0));
String info = scope .(); String info = scope .();
info.Append("uncertain\n"); info.Append("uncertain\n");

View file

@ -415,6 +415,8 @@ namespace IDE.ui
{ {
None = 0, None = 0,
ApplyAutoToChildren = 1, ApplyAutoToChildren = 1,
ClearAutoItems = 2,
FullTraversal = 4,
} }
public void RehupFolder(ProjectFolder projectFolder, RehupFlags rehupFlags = .None) public void RehupFolder(ProjectFolder projectFolder, RehupFlags rehupFlags = .None)
@ -429,7 +431,7 @@ namespace IDE.ui
var dirPath = scope String(); var dirPath = scope String();
projectFolder.GetFullImportPath(dirPath); projectFolder.GetFullImportPath(dirPath);
bool clearAutoItems = (!rehupFlags.HasFlag(.ApplyAutoToChildren)) && (projectFolder.mIncludeKind == .Auto); bool clearAutoItems = (!rehupFlags.HasFlag(.ApplyAutoToChildren)) && (projectFolder.mAutoInclude); // && (rehupFlags.HasFlag(.ClearAutoItems));
HashSet<ProjectItem> foundAutoItems = scope .(); HashSet<ProjectItem> foundAutoItems = scope .();
for (let fileEntry in Directory.EnumerateFiles(dirPath)) for (let fileEntry in Directory.EnumerateFiles(dirPath))
@ -482,6 +484,8 @@ namespace IDE.ui
projectItem.mIncludeKind = .Auto; projectItem.mIncludeKind = .Auto;
if (projectItem.mIncludeKind == .Auto) if (projectItem.mIncludeKind == .Auto)
RehupFolder(childProjectFolder, rehupFlags); RehupFolder(childProjectFolder, rehupFlags);
if ((clearAutoItems) && (projectItem.mIncludeKind == .Auto))
foundAutoItems.Add(projectItem);
} }
continue; continue;
} }
@ -501,6 +505,11 @@ namespace IDE.ui
childProjectFolder.mAutoInclude = true; childProjectFolder.mAutoInclude = true;
projectFolder.AddChild(childProjectFolder); projectFolder.AddChild(childProjectFolder);
if (clearAutoItems)
{
foundAutoItems.Add(childProjectFolder);
}
AddProjectItem(childProjectFolder); AddProjectItem(childProjectFolder);
RehupFolder(childProjectFolder, rehupFlags); RehupFolder(childProjectFolder, rehupFlags);
@ -516,11 +525,19 @@ namespace IDE.ui
for (int childIdx = projectFolder.mChildItems.Count - 1; childIdx >= 0; childIdx--) for (int childIdx = projectFolder.mChildItems.Count - 1; childIdx >= 0; childIdx--)
{ {
var child = projectFolder.mChildItems[childIdx]; var child = projectFolder.mChildItems[childIdx];
if (((rehupFlags.HasFlag(.ApplyAutoToChildren)) && (child.mIncludeKind == .Manual)) || if (((rehupFlags.HasFlag(.ApplyAutoToChildren)) && (child.mIncludeKind == .Manual)) ||
((clearAutoItems) && (child.mIncludeKind == .Auto) && (!foundAutoItems.Contains(child)))) ((clearAutoItems) && (child.mIncludeKind == .Auto) && (!foundAutoItems.Contains(child))))
{ {
var listItem = mProjectToListViewMap[child]; var listItem = mProjectToListViewMap[child];
DoDeleteItem(listItem, null, true); DoDeleteItem(listItem, null, true);
continue;
}
if ((rehupFlags.HasFlag(.FullTraversal)) && (child.mIncludeKind == .Manual) && (var childProjectFolder = child as ProjectFolder))
{
RehupFolder(childProjectFolder, rehupFlags);
} }
} }
} }
@ -583,7 +600,7 @@ namespace IDE.ui
dialog.mDefaultButton = dialog.AddButton("OK", new (evt) => DoNewClass(folder, evt)); dialog.mDefaultButton = dialog.AddButton("OK", new (evt) => DoNewClass(folder, evt));
dialog.mEscButton = dialog.AddButton("Cancel"); dialog.mEscButton = dialog.AddButton("Cancel");
dialog.AddEdit("Unnamed"); dialog.AddEdit("Unnamed");
dialog.PopupWindow(mWidgetWindow); dialog.PopupWindow(gApp.GetActiveWindow());
} }
void DoNewClass(ProjectFolder folder, DialogEvent evt) void DoNewClass(ProjectFolder folder, DialogEvent evt)
@ -596,6 +613,8 @@ namespace IDE.ui
return; return;
let project = folder.mProject; let project = folder.mProject;
if (project.mNeedsCreate)
project.FinishCreate();
String relFileName = scope String(className, ".bf"); String relFileName = scope String(className, ".bf");
String fullFilePath = scope String(); String fullFilePath = scope String();
@ -680,6 +699,11 @@ namespace IDE.ui
if (rightProjectItem == null) if (rightProjectItem == null)
return 1; return 1;
if ((leftProjectItem.mParentFolder == null) && (rightProjectItem.mParentFolder == null))
{
return String.Compare(leftProjectItem.mProject.mProjectName, rightProjectItem.mProject.mProjectName, true);
}
return ProjectItem.Compare(leftProjectItem, rightProjectItem); return ProjectItem.Compare(leftProjectItem, rightProjectItem);
} }
@ -811,7 +835,7 @@ namespace IDE.ui
fileDialog.Multiselect = true; fileDialog.Multiselect = true;
fileDialog.InitialDirectory = fullDir; fileDialog.InitialDirectory = fullDir;
fileDialog.ValidateNames = true; fileDialog.ValidateNames = true;
mWidgetWindow.PreModalChild(); gApp.GetActiveWindow().PreModalChild();
if (fileDialog.ShowDialog(gApp.GetActiveWindow()).GetValueOrDefault() == .OK) if (fileDialog.ShowDialog(gApp.GetActiveWindow()).GetValueOrDefault() == .OK)
{ {
if (mSelectedParentItem.mOpenButton != null) if (mSelectedParentItem.mOpenButton != null)
@ -1291,7 +1315,7 @@ namespace IDE.ui
aDialog.mDefaultButton = aDialog.AddButton("Yes", new (evt) => RemoveSelectedItems(false)); aDialog.mDefaultButton = aDialog.AddButton("Yes", new (evt) => RemoveSelectedItems(false));
aDialog.mEscButton = aDialog.AddButton("No"); aDialog.mEscButton = aDialog.AddButton("No");
aDialog.PopupWindow(mWidgetWindow); aDialog.PopupWindow(gApp.GetActiveWindow());
} }
} }
else if((fileCount > 0) || (folderCount > 0)) else if((fileCount > 0) || (folderCount > 0))
@ -1345,7 +1369,7 @@ namespace IDE.ui
RemoveSelectedItems(true); RemoveSelectedItems(true);
}); });
aDialog.mEscButton = aDialog.AddButton("Cancel"); aDialog.mEscButton = aDialog.AddButton("Cancel");
aDialog.PopupWindow(mWidgetWindow); aDialog.PopupWindow(gApp.GetActiveWindow());
} }
} }
} }
@ -1591,7 +1615,7 @@ namespace IDE.ui
Sort(); Sort();
} }
~ delete oldValue); ~ delete oldValue);
dialog.PopupWindow(mWidgetWindow); dialog.PopupWindow(gApp.GetActiveWindow());
didRename = false; didRename = false;
} }
@ -1712,7 +1736,7 @@ namespace IDE.ui
fileDialog.ValidateNames = true; fileDialog.ValidateNames = true;
fileDialog.DefaultExt = ".toml"; fileDialog.DefaultExt = ".toml";
fileDialog.SetFilter("Beef projects (BeefProj.toml)|BeefProj.toml|All files (*.*)|*.*"); fileDialog.SetFilter("Beef projects (BeefProj.toml)|BeefProj.toml|All files (*.*)|*.*");
mWidgetWindow.PreModalChild(); gApp.GetActiveWindow().PreModalChild();
if (fileDialog.ShowDialog(gApp.GetActiveWindow()).GetValueOrDefault() == .OK) if (fileDialog.ShowDialog(gApp.GetActiveWindow()).GetValueOrDefault() == .OK)
{ {
for (String origProjFilePath in fileDialog.FileNames) for (String origProjFilePath in fileDialog.FileNames)
@ -1734,13 +1758,13 @@ namespace IDE.ui
public void ShowProjectProperties(Project project) public void ShowProjectProperties(Project project)
{ {
var projectProperties = new ProjectProperties(project); var projectProperties = new ProjectProperties(project);
projectProperties.PopupWindow(mWidgetWindow); projectProperties.PopupWindow(gApp.GetActiveWindow());
} }
public void ShowWorkspaceProperties() public void ShowWorkspaceProperties()
{ {
var workspaceProperties = new WorkspaceProperties(); var workspaceProperties = new WorkspaceProperties();
workspaceProperties.PopupWindow(mWidgetWindow); workspaceProperties.PopupWindow(gApp.GetActiveWindow());
} }
public void RehupProjects() public void RehupProjects()
@ -1768,7 +1792,7 @@ namespace IDE.ui
{ {
var newProjectDialog = new NewProjectDialog(); var newProjectDialog = new NewProjectDialog();
newProjectDialog.Init(); newProjectDialog.Init();
newProjectDialog.PopupWindow(mWidgetWindow); newProjectDialog.PopupWindow(gApp.GetActiveWindow());
} }
protected override void ShowRightClickMenu(Widget relWidget, float x, float y) protected override void ShowRightClickMenu(Widget relWidget, float x, float y)
@ -1832,6 +1856,55 @@ namespace IDE.ui
if ((projectItem != null) && (!handled)) if ((projectItem != null) && (!handled))
{ {
Menu item = null; Menu item = null;
if (isProject)
{
item = menu.AddItem("Set as Startup Project");
item.mOnMenuItemSelected.Add(new (item) =>
{
var projectItem = GetSelectedProjectItem();
if (projectItem != null)
SetAsStartupProject(projectItem.mProject);
});
item = menu.AddItem("Lock Project");
if (projectItem.mProject.mLocked)
item.mIconImage = DarkTheme.sDarkTheme.GetImage(.Check);
item.mOnMenuItemSelected.Add(new (item) =>
{
var projectItem = GetSelectedProjectItem();
if (projectItem != null)
{
projectItem.mProject.mLocked = !projectItem.mProject.mLocked;
gApp.mWorkspace.SetChanged();
}
});
item = menu.AddItem("Refresh");
item.mOnMenuItemSelected.Add(new (item) =>
{
var projectItem = GetSelectedProjectItem();
if (projectItem != null)
{
let project = projectItem.mProject;
if (project.mNeedsCreate)
{
project.FinishCreate(false);
RebuildUI();
}
else
{
if (project.mRootFolder.mIsWatching)
project.mRootFolder.StopWatching();
project.mRootFolder.StartWatching();
RehupFolder(project.mRootFolder, .FullTraversal);
}
}
});
menu.AddItem();
}
if ((projectItem != null) && (!isProject)) if ((projectItem != null) && (!isProject))
{ {
item = menu.AddItem("Remove ..."); item = menu.AddItem("Remove ...");
@ -1933,7 +2006,7 @@ namespace IDE.ui
RehupFolder(projectFolder); RehupFolder(projectFolder);
} }
}); });
dialog.PopupWindow(mWidgetWindow); dialog.PopupWindow(gApp.GetActiveWindow());
} }
else else
RehupFolder(projectFolder); RehupFolder(projectFolder);
@ -1988,17 +2061,8 @@ namespace IDE.ui
var process = scope SpawnedProcess(); var process = scope SpawnedProcess();
process.Start(psi).IgnoreError(); process.Start(psi).IgnoreError();
}); });
}
if (isProject) menu.AddItem();
{
item = menu.AddItem("Set as Startup Project");
item.mOnMenuItemSelected.Add(new (item) =>
{
var projectItem = GetSelectedProjectItem();
if (projectItem != null)
SetAsStartupProject(projectItem.mProject);
});
} }
//menu.AddItem(); //menu.AddItem();
@ -2026,19 +2090,7 @@ namespace IDE.ui
if (isProject) if (isProject)
{ {
item = menu.AddItem("Lock Project"); menu.AddItem();
if (projectItem.mProject.mLocked)
item.mIconImage = DarkTheme.sDarkTheme.GetImage(.Check);
item.mOnMenuItemSelected.Add(new (item) =>
{
var projectItem = GetSelectedProjectItem();
if (projectItem != null)
{
projectItem.mProject.mLocked = !projectItem.mProject.mLocked;
gApp.mWorkspace.SetChanged();
}
});
item = menu.AddItem("Properties..."); item = menu.AddItem("Properties...");
item.mOnMenuItemSelected.Add(new (item) => item.mOnMenuItemSelected.Add(new (item) =>
{ {
@ -2047,7 +2099,6 @@ namespace IDE.ui
ShowProjectProperties(projectItem.mProject); ShowProjectProperties(projectItem.mProject);
}); });
} }
} }
/*else if (!handled) /*else if (!handled)
{ {
@ -2070,7 +2121,6 @@ namespace IDE.ui
mMenuWidget = null; mMenuWidget = null;
}); });
//menuWidget.mWidgetWindow.mWindowClosedHandler.Add(new => DeselectFolder);
} }
void ListViewItemClicked(MouseEvent theEvent) void ListViewItemClicked(MouseEvent theEvent)

View file

@ -1315,6 +1315,9 @@ namespace IDE.ui
{ {
var editWidgetContent = (SourceEditWidgetContent)mEditWidget.Content; var editWidgetContent = (SourceEditWidgetContent)mEditWidget.Content;
if (mWidgetWindow == null)
return;
bool wantOpen = (autocompleteInfo.Length > 0); bool wantOpen = (autocompleteInfo.Length > 0);
if ((editWidgetContent.mAutoComplete != null) && (editWidgetContent.mAutoComplete.mIsAsync) && if ((editWidgetContent.mAutoComplete != null) && (editWidgetContent.mAutoComplete.mIsAsync) &&
(editWidgetContent.mAutoComplete.mInvokeWidget != null)) (editWidgetContent.mAutoComplete.mInvokeWidget != null))