Browse Source

CH: Some major and minor bug fixes

Jean-Francois Goulet 20 years ago
parent
commit
d7c62d9a7e

+ 1 - 9
LuaEdit/Breakpoints.pas

@@ -234,17 +234,9 @@ begin
   if Assigned(lvwBreakpoints.Selected) then
   begin
     if TLuaUnit(lvwBreakpoints.Selected.Data).pDebugInfos.GetBreakpointStatus(StrToInt(lvwBreakpoints.Selected.SubItems.Strings[2])) = BKPT_DISABLED then
-    begin
-      TLuaUnit(lvwBreakpoints.Selected.Data).pDebugInfos.GetBreakpointAtLine(StrToInt(lvwBreakpoints.Selected.SubItems.Strings[2])).iStatus := BKPT_ENABLED;
-      lvwBreakpoints.Selected.Checked := True;
-      lvwBreakpoints.Selected.ImageIndex := 7;
-    end
+      lvwBreakpoints.Selected.Checked := True
     else
-    begin
-      TLuaUnit(lvwBreakpoints.Selected.Data).pDebugInfos.GetBreakpointAtLine(StrToInt(lvwBreakpoints.Selected.SubItems.Strings[2])).iStatus := BKPT_DISABLED;
       lvwBreakpoints.Selected.Checked := False;
-      lvwBreakpoints.Selected.ImageIndex := 8;
-    end;
   end;
 
   if Assigned(frmMain.jvUnitBar.SelectedTab.Data) then

+ 1 - 1
LuaEdit/EditorSettings.dfm

@@ -120,7 +120,7 @@ object frmEditorSettings: TfrmEditorSettings
       Top = 0
       Width = 492
       Height = 375
-      ActivePage = stabGeneral
+      ActivePage = stabColors
       Align = alClient
       TabOrder = 0
       object stabGeneral: TTabSheet

+ 1 - 1
LuaEdit/EditorSettings.pas

@@ -379,7 +379,7 @@ begin
   end;
 
   // Writing environement settings
-  pIniFile.WriteString('Environement', 'LibrariesSearchPaths', txtLibraries.Text);
+  pIniFile.WriteString('Environement', 'LibrariesSearchPaths', '"'+txtLibraries.Text+'"');
 
   //Writing display settings
   pIniFile.WriteBool('Display', 'ShowGutter', chkShowGutter.Checked);

+ 3 - 3
LuaEdit/LuaEdit.dof

@@ -113,9 +113,9 @@ RootDir=
 IncludeVerInfo=1
 AutoIncBuild=1
 MajorVer=2
-MinorVer=2
+MinorVer=3
 Release=1
-Build=882
+Build=903
 Debug=0
 PreRelease=0
 Special=0
@@ -126,7 +126,7 @@ CodePage=1252
 [Version Info Keys]
 CompanyName=Open Source
 FileDescription=IDE for Lua 5.0.2
-FileVersion=2.2.1.882
+FileVersion=2.3.1.903
 InternalName=LuaEdit
 LegalCopyright=LuaEdit Copyright 2004-2005 ©
 LegalTrademarks=

+ 1 - 1
LuaEdit/LuaEdit.dpr

@@ -112,7 +112,7 @@ begin
       begin
         if ExtractFileExt(FileName) = '.lua' then
         begin
-          if not frmMain.FileIsInTree(FileName) then
+          if not Assigned(frmMain.FileIsInTree(FileName)) then
           begin
             pLuaUnit := frmMain.AddFileInProject(FileName, False, LuaSingleUnits);
             pLuaUnit.IsLoaded := True;

BIN
LuaEdit/LuaEdit.res


+ 72 - 55
LuaEdit/Main.pas

@@ -621,7 +621,7 @@ type
     procedure RefreshOpenedUnits;
     procedure synParamsExecute(Kind: SynCompletionType; Sender: TObject; var AString: String; var x, y: Integer; var CanExecute: Boolean);
     procedure FillLookUpList;
-    function FileIsInTree(sFileName: String): Boolean;
+    function FileIsInTree(sFileName: String): PVirtualNode;
     procedure LuaGlobalsToStrings(L: PLua_State; Lines: TStrings; MaxTable: Integer = -1);
     function GetAssociatedTab(pLuaUnit: TLuaUnit): TJvTabBarItem;
     function FindUnitInTabs(sFileName: String): TLuaUnit;
@@ -1873,7 +1873,7 @@ begin
     begin
       if ExtractFileExt(odlgOpenUnit.Files.Strings[z]) = '.lua' then
       begin
-        if not FileIsInTree(odlgOpenUnit.Files.Strings[z]) then
+        if not Assigned(FileIsInTree(odlgOpenUnit.Files.Strings[z])) then
         begin
           Result := True;
           pLuaUnit := AddFileInProject(odlgOpenUnit.Files.Strings[z], False, LuaSingleUnits);
@@ -3115,7 +3115,7 @@ begin
   begin
     if ExtractFileExt(mnuSender.Caption) = '.lua' then
     begin
-      if not FileIsInTree(mnuSender.Caption) then
+      if not Assigned(FileIsInTree(mnuSender.Caption)) then
       begin
         pLuaUnit := AddFileInProject(mnuSender.Caption, False, LuaSingleUnits);
         pLuaUnit.IsLoaded := True;
@@ -3213,7 +3213,7 @@ begin
   begin
     if ExtractFileExt(btnSender.Caption) = '.lua' then
     begin
-      if not FileIsInTree(btnSender.Caption) then
+      if not Assigned(FileIsInTree(btnSender.Caption)) then
       begin
         pLuaUnit := AddFileInProject(btnSender.Caption, False, LuaSingleUnits);
         pLuaUnit.IsLoaded := True;
@@ -4347,8 +4347,7 @@ begin
     begin
       // Detecting first line of script...
       if ((AR.event = LUA_HOOKCALL) and (AR.linedefined = 0) and (AR.i_ci = 1) and (AR.what = 'main') and (AR.currentline = -1)) then
-      begin
-        
+      begin        
         AR.event := LUA_HOOKLINE;
         AR.currentline := 1;
         WaitReStart;
@@ -4436,7 +4435,7 @@ begin
       end;
     end;
 
-    if not frmMain.FileIsInTree(sFileName) then
+    if not Assigned(FileIsInTree(sFileName)) then
     begin
       pLuaUnit := TLuaUnit.Create(sFileName);
       pLuaUnit := frmMain.AddFileInProject(sFileName, False, LuaSingleUnits);
@@ -4488,8 +4487,8 @@ begin
   begin
     pItem := frmStack.lstCallStack.Items.Add;
     pItem.Caption := TBreakInfo(CallStack.Items[x]).FileName;
-    pItem.SubItems.Strings[0] := TBreakInfo(CallStack.Items[x]).Call;
-    pItem.SubItems.Strings[1] := TBreakInfo(CallStack.Items[x]).LineOut;
+    pItem.SubItems.Add(TBreakInfo(CallStack.Items[x]).Call);
+    pItem.SubItems.Add(TBreakInfo(CallStack.Items[x]).LineOut);
     pItem.Data := CallStack.Items[x];
   end;
 
@@ -4811,20 +4810,19 @@ end;
 
 function TfrmMain.DoAddWatchExecute(): Boolean;
 var
-  sTemp: string;
-  pData: PWatchNodeData;
   pNode: PVirtualNode;
+  pData: PWatchNodeData;
+  sVarName: String;
 begin
-  Result := False;
+  sVarName := 'VarName';
 
-  if Assigned(jvUnitBar.SelectedTab.Data) then
+  if InputQuery('Add Watch', 'Enter the name of the variable to watch:', sVarName) then
   begin
-    Result := True;
-    sTemp := TLuaUnit(jvUnitBar.SelectedTab.Data).synUnit.SelText;
-    pNode := frmWatch.vstWatch.AddChild(frmWatch.vstWatch.RootNode);
+    frmWatch.vstWatch.RootNodeCount := frmWatch.vstWatch.RootNodeCount + 1;
+    pNode := frmWatch.vstWatch.GetLast;
     pData := frmWatch.vstWatch.GetNodeData(pNode);
-    pData.Name := sTemp;
-    frmMain.PrintWatch(frmMain.LuaState);
+    pData.Name := sVarName;
+    PrintWatch(frmMain.LuaState);
   end;
 end;
 
@@ -5126,6 +5124,7 @@ begin
     TLuaUnit(jvUnitBar.SelectedTab.Data).pDebugInfos.RemoveBreakpointAtLine(iCurrentLine);
 
   TLuaUnit(jvUnitBar.SelectedTab.Data).synUnit.Refresh;
+  frmBreakpoints.RefreshBreakpointList;
 end;
 
 function TfrmMain.DoPauseExecute(): Boolean;
@@ -5302,8 +5301,8 @@ end;
 
 procedure TfrmMain.synEditDblClick(Sender: TObject);
 const
-  OpeningBrackets: set of char = ['(', '[', '{', '<'];
-  ClosingBrackets: set of char = [')', ']', '}', '>'];
+  OpeningBrackets: set of char = ['(', '[', '{', '<', '"'];
+  ClosingBrackets: set of char = [')', ']', '}', '>', '"'];
 var
   pLuaUnit: TLuaUnit;
   pCoord: TBufferCoord;
@@ -5313,36 +5312,42 @@ begin
     // Get current unit and find matching bracket
     pLuaUnit := TLuaUnit(jvUnitBar.SelectedTab.Data);
 
-    if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX] in OpeningBrackets then
+    if pLuaUnit.synUnit.Text <> '' then
     begin
-      if ((FirstClickPos.Line = pLuaUnit.synUnit.CaretXY.Line) and (FirstClickPos.Char = pLuaUnit.synUnit.CaretXY.Char)) then
+      if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1] <> '' then
       begin
-        // Get matching bracket
-        pCoord := pLuaUnit.synUnit.GetMatchingBracket;
+        if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX] in OpeningBrackets then
+        begin
+          if ((FirstClickPos.Line = pLuaUnit.synUnit.CaretXY.Line) and (FirstClickPos.Char = pLuaUnit.synUnit.CaretXY.Char)) then
+          begin
+            // Get matching bracket
+            pCoord := pLuaUnit.synUnit.GetMatchingBracket;
 
-        // Select matching bracket if found one
-        if pCoord.Char <> 0 then
+            // Select matching bracket if found one
+            if pCoord.Char <> 0 then
+            begin
+              Inc(pCoord.Char);
+              pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
+              pLuaUnit.synUnit.BlockEnd := pCoord;
+            end;
+          end;
+        end
+        else if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX - 1] in ClosingBrackets then
         begin
-          Inc(pCoord.Char);
-          pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
-          pLuaUnit.synUnit.BlockEnd := pCoord;
+          // Get matching bracket with previous char
+          pCoord := pLuaUnit.synUnit.CaretXY;
+          Dec(pCoord.Char);
+          pCoord := pLuaUnit.synUnit.GetMatchingBracketEx(pCoord);
+
+          // Select matching bracket if found one
+          if pCoord.Char <> 0 then
+          begin
+            pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
+            pLuaUnit.synUnit.BlockEnd := pCoord;
+          end;
         end;
       end;
-    end
-    else if pLuaUnit.synUnit.Lines[pLuaUnit.synUnit.CaretY - 1][pLuaUnit.synUnit.CaretX - 1] in ClosingBrackets then
-    begin
     end;
-      // Get matching bracket with previous char
-      pCoord := pLuaUnit.synUnit.CaretXY;
-      Dec(pCoord.Char);
-      pCoord := pLuaUnit.synUnit.GetMatchingBracketEx(pCoord);
-
-      // Select matching bracket if found one
-      if pCoord.Char <> 0 then
-      begin
-        pLuaUnit.synUnit.BlockBegin := pLuaUnit.synUnit.CaretXY;
-        pLuaUnit.synUnit.BlockEnd := pCoord;
-      end;
   end;
 end;
 
@@ -5519,7 +5524,7 @@ var
   pFctInfo: TFctInfo;
   hFileSearch: TSearchRec;
   GotTable: Boolean;
-  sTemp, sFormatString, sFunctionName, sNestedTable: String;
+  sPath, sTemp, sFormatString, sFunctionName, sNestedTable: String;
   sTable, sParameters, LineType, Lookup, LookupTable: String;
   lstLocalTable, sFileContent: TStringList;
   i, j, k, Index: Integer;
@@ -5554,13 +5559,19 @@ begin
   // Go through all libraries search paths
   for i := 0 to LibrariesSearchPaths.Count - 1 do
   begin
+    // Standarize the path
+    sPath := LibrariesSearchPaths.Strings[i];
+    
+    if Copy(sPath, Length(sPath), 1) <> '\' then
+      sPath := sPath + '\';
+
     // Begin file search
-    if FindFirst(LibrariesSearchPaths.Strings[i]+'*.lib', faAnyFile, hFileSearch) = 0 then
+    if FindFirst(sPath+'*.lib', faAnyFile, hFileSearch) = 0 then
     begin
       repeat
         // Create and initialize temporary content container
         sFileContent := TStringList.Create;
-        sFileContent.LoadFromFile(LibrariesSearchPaths.Strings[i]+hFileSearch.Name);
+        sFileContent.LoadFromFile(sPath+hFileSearch.Name);
 
         // Parse content and add it to the lookup list
         for j := 0 to sFileContent.Count - 1 do
@@ -5735,7 +5746,7 @@ end;
 procedure TfrmMain.synParamsExecute(Kind: SynCompletionType; Sender: TObject; var AString: String; var x, y: Integer; var CanExecute: Boolean);
 var
   locline, lookup, sProposition: String;
-  sFunctionName, sParameters: String;
+  sPath, sFunctionName, sParameters: String;
   TmpX, savepos, StartX, ParenCounter: Integer;
   TmpLocation, i, j: Integer;
   sFileContent: TStringList;
@@ -5811,13 +5822,19 @@ begin
       // Go through all libraries search paths
       for i := 0 to LibrariesSearchPaths.Count - 1 do
       begin
+        // Standarize the path
+        sPath := LibrariesSearchPaths.Strings[i];
+
+        if Copy(sPath, Length(sPath), 1) <> '\' then
+          sPath := sPath +'\';
+        
         // Begin file search
-        if FindFirst(LibrariesSearchPaths.Strings[i]+'*.lib', faAnyFile, hFileSearch) = 0 then
+        if FindFirst(sPath +'*.lib', faAnyFile, hFileSearch) = 0 then
         begin
           repeat
             // Create and initialize temporary content container
             sFileContent := TStringList.Create;
-            sFileContent.LoadFromFile(LibrariesSearchPaths.Strings[i]+hFileSearch.Name);
+            sFileContent.LoadFromFile(sPath+hFileSearch.Name);
 
             // Parse content and add it to the lookup list
             for j := 0 to sFileContent.Count - 1 do
@@ -5977,7 +5994,7 @@ begin
 
   //Background
   EditorColors.Add(TEditorColors.Create);
-  TEditorColors(EditorColors.Items[0]).Background := pIniFile.ReadString('Background', 'Background', 'clWhite');
+  TEditorColors(EditorColors.Items[0]).Background := pIniFile.ReadString('Background', 'BackgroundColor', 'clWhite');
 
   //Comment
   EditorColors.Add(TEditorColors.Create);
@@ -6464,13 +6481,13 @@ begin
   end;
 end;
 
-function TfrmMain.FileIsInTree(sFileName: String): Boolean;
+function TfrmMain.FileIsInTree(sFileName: String): PVirtualNode;
 var
   pNode: PVirtualNode;
   pData: PProjectTreeData;
 begin
   // Initialize stuff before going
-  Result := False;
+  Result := nil;
   pNode := frmProjectTree.vstProjectTree.GetFirst;
 
   while pNode <> nil do
@@ -6489,7 +6506,7 @@ begin
           else
             AddFileInTab(pData.pLuaUnit);
 
-          Result := True;
+          Result := pNode;
           Break;
         end;
       end;
@@ -7278,7 +7295,7 @@ begin
   begin
     if ExtractFileExt(WordAtCursor) = '.lua' then
     begin
-      if not FileIsInTree(WordAtCursor) then
+      if not Assigned(FileIsInTree(WordAtCursor)) then
       begin
         // Creates the file
         pLuaUnit := AddFileInProject(WordAtCursor, False, LuaSingleUnits);
@@ -7538,7 +7555,7 @@ begin
       if ExtractFileExt(FileName) = '.lua' then
       begin
         // Add new single unit to the tree
-        if not frmMain.FileIsInTree(FileName) then
+        if not Assigned(FileIsInTree(FileName)) then
         begin
           pLuaUnit := frmMain.AddFileInProject(FileName, False, LuaSingleUnits);
           pLuaUnit.IsLoaded := True;

+ 1 - 0
LuaEdit/ProjectTree.dfm

@@ -47,6 +47,7 @@ object frmProjectTree: TfrmProjectTree
       PopupMenu = ppmProjectTree
       TabOrder = 0
       TreeOptions.MiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toInitOnSave, toReportMode, toToggleOnDblClick, toWheelPanning]
+      TreeOptions.SelectionOptions = [toRightClickSelect]
       OnAfterItemPaint = vstProjectTreeAfterItemPaint
       OnDblClick = vstProjectTreeDblClick
       OnGetText = vstProjectTreeGetText

+ 151 - 33
LuaEdit/ProjectTree.pas

@@ -14,6 +14,7 @@ type
     pLuaUnit: TLuaUnit;
     pLuaPrj: TLuaProject;
     ActiveProject: Boolean;
+    ToKeep: Boolean;
   end;
 
   TfrmProjectTree = class(TForm)
@@ -38,6 +39,7 @@ type
     procedure vstProjectTreeDblClick(Sender: TObject);
     procedure vstProjectTreeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
     procedure vstProjectTreeAfterItemPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; ItemRect: TRect);
+    function GetNodeInTree(sFileName, sProjectName: String): PVirtualNode;
   private
     { Private declarations }
   public
@@ -94,12 +96,94 @@ begin
   frmMain.CheckButtons;
 end;
 
+function TfrmProjectTree.GetNodeInTree(sFileName, sProjectName: String): PVirtualNode;
+var
+  pNode: PVirtualNode;
+  pData: PProjectTreeData;
+begin
+  Result := nil;
+  pNode := vstProjectTree.GetFirst;
+
+  while Assigned(pNode) do
+  begin
+    pData := vstProjectTree.GetNodeData(pNode);
+
+    if sProjectName <> '' then
+    begin
+      if Assigned(pData.pLuaUnit) then
+      begin
+        if ((pData.pLuaUnit.pPrjOwner.sPrjName = sProjectName) or (sProjectName = '[@@SingleUnits@@]')) then
+        begin
+          if pData.pLuaUnit.sName = sFileName then
+          begin
+            Result := pNode;
+            Break;
+          end;
+        end;
+      end;
+    end
+    else
+    begin
+      if Assigned(pData.pLuaPrj) then
+      begin
+        if pData.pLuaPrj.sPrjName = sFileName then
+        begin
+          Result := pNode;
+          Break;
+        end;
+      end;
+    end;
+
+    pNode := vstProjectTree.GetNext(pNode);
+  end;
+end;
+
 procedure TfrmProjectTree.BuildProjectTree(HandleNotifier: Boolean);
 var
   pTempPrj: TLuaProject;
-  pNewPrjNode, pNewNode, pSingleUnitLastNode: PVirtualNode;
+  pNode, pNewPrjNode, pNewNode, pSingleUnitLastNode: PVirtualNode;
   pData: PProjectTreeData;
   x, y: Integer;
+
+  // Go through all nodes of the tree and set their ToKeep flag to false
+  procedure UnflagAllExpanded(pTree: TVirtualStringTree);
+  var
+    pNode: PVirtualNode;
+    pData: PProjectTreeData;
+  begin
+    pNode := pTree.GetFirst;
+
+    while Assigned(pNode) do
+    begin
+      pData := pTree.GetNodeData(pNode);
+      pData.ToKeep := False;
+      pNode := pTree.GetNext(pNode);
+    end;
+  end;
+
+  // Deletes all nodes for wich their ToKeep flag is still on false
+  procedure CleanTree(pTree: TVirtualStringTree);
+  var
+    pNode, pPrevious: PVirtualNode;
+    pData: PProjectTreeData;
+  begin
+    pNode := pTree.GetFirst;
+
+    while Assigned(pNode) do
+    begin
+      pData := pTree.GetNodeData(pNode);
+      
+      if not pData.ToKeep then
+      begin
+        pPrevious := pTree.GetPrevious(pNode);
+        pTree.DeleteNode(pNode);
+        pNode := pPrevious;
+      end;
+      
+      pNode := pTree.GetNext(pNode);
+    end;
+  end;
+  
 begin
   // Initialize stuff
   pNewNode := nil;
@@ -113,51 +197,81 @@ begin
   end;
 
   vstProjectTree.BeginUpdate;
-  vstProjectTree.Clear;
+  UnflagAllExpanded(vstProjectTree);
 
   for x := 0 to LuaProjects.Count - 1 do
   begin
     pTempPrj := TLuaProject(LuaProjects.Items[x]);
+    pNode := GetNodeInTree(pTempPrj.sPrjName, '');
 
-    if pTempPrj.sPrjName <> '[@@SingleUnits@@]' then
+    if not Assigned(pNode) then
+    begin
+      if pTempPrj.sPrjName <> '[@@SingleUnits@@]' then
+      begin
+        // Create the node
+        pNewPrjNode := vstProjectTree.AddChild(vstProjectTree.RootNode);
+        pData := vstProjectTree.GetNodeData(pNewPrjNode);
+        pData.pLuaUnit := nil;
+        pData.pLuaPrj := pTempPrj;
+        pData.ActiveProject := (pTempPrj = ActiveProject);
+        pData.ToKeep := True;
+
+        // Adding project root to change notifier...
+        if ((not pTempPrj.IsNew) and HandleNotifier) then
+          frmMain.AddToNotifier(ExtractFileDir(pTempPrj.sPrjPath));
+      end
+      else
+        pNewPrjNode := pSingleUnitLastNode;
+    end
+    else
     begin
-      // Create the node
-      pNewPrjNode := vstProjectTree.AddChild(vstProjectTree.RootNode);
-      pData := vstProjectTree.GetNodeData(pNewPrjNode);
+      // Update the node's data
+      pData := vstProjectTree.GetNodeData(pNode);
       pData.pLuaUnit := nil;
       pData.pLuaPrj := pTempPrj;
       pData.ActiveProject := (pTempPrj = ActiveProject);
-
-      // Adding project root to change notifier...
-      if ((not pTempPrj.IsNew) and HandleNotifier) then
-        frmMain.AddToNotifier(ExtractFileDir(pTempPrj.sPrjPath));
-    end
-    else
-      pNewPrjNode := pSingleUnitLastNode;
+      pData.ToKeep := True;
+    end;
 
     for y := 0 to pTempPrj.lstUnits.Count - 1 do
     begin
-      // Adding single unit (projectless) to the tree
-      if pTempPrj.sPrjName = '[@@SingleUnits@@]' then
-        pNewNode := vstProjectTree.InsertNode(pNewPrjNode, amInsertAfter)
-      else
-        pNewNode := vstProjectTree.AddChild(pNewPrjNode);
-
-      // Update last single unit node
-      pSingleUnitLastNode := pNewNode;
-
-      // Create the node
-      pData := vstProjectTree.GetNodeData(pNewNode);
-      pData.pLuaUnit := TLuaUnit(pTempPrj.lstUnits.Items[y]);
-      pData.pLuaPrj := nil;
-      pData.ActiveProject := False;
+      pNode := GetNodeInTree(TLuaUnit(pTempPrj.lstUnits.Items[y]).sName, pTempPrj.sPrjName);
 
-      // Adding unit root to change notifier...
-      if ((not TLuaUnit(pTempPrj.lstUnits.Items[y]).IsNew) and HandleNotifier) then
-        frmMain.AddToNotifier(ExtractFileDir(TLuaUnit(pTempPrj.lstUnits.Items[y]).sUnitPath));
+      if not Assigned(pNode) then
+      begin
+        // Adding single unit (projectless) to the tree
+        if pTempPrj.sPrjName = '[@@SingleUnits@@]' then
+          pNewNode := vstProjectTree.InsertNode(pNewPrjNode, amInsertAfter)
+        else
+          pNewNode := vstProjectTree.AddChild(pNewPrjNode);
+
+        // Update last single unit node
+        pSingleUnitLastNode := pNewNode;
+
+        // Create the node
+        pData := vstProjectTree.GetNodeData(pNewNode);
+        pData.pLuaUnit := TLuaUnit(pTempPrj.lstUnits.Items[y]);
+        pData.pLuaPrj := nil;
+        pData.ActiveProject := False;
+        pData.ToKeep := True;
+
+        // Adding unit root to change notifier...
+        if ((not TLuaUnit(pTempPrj.lstUnits.Items[y]).IsNew) and HandleNotifier) then
+          frmMain.AddToNotifier(ExtractFileDir(TLuaUnit(pTempPrj.lstUnits.Items[y]).sUnitPath));
+      end
+      else
+      begin
+        // Update the node's data
+        pData := vstProjectTree.GetNodeData(pNode);
+        pData.pLuaUnit := TLuaUnit(pTempPrj.lstUnits.Items[y]);
+        pData.pLuaPrj := nil;
+        pData.ActiveProject := False;
+        pData.ToKeep := True;
+      end;
     end;
   end;
 
+  CleanTree(vstProjectTree);
   vstProjectTree.EndUpdate;
 
   // Set back on the changes notifier if required
@@ -313,9 +427,9 @@ begin
     pData := vstProjectTree.GetNodeData(pNode);
 
     // setting menu status
-    AddUnitToProject1.Enabled := (pData.pLuaPrj = ActiveProject);
-    RemoveUnitFromProject1.Enabled := (pData.pLuaPrj = ActiveProject);
-    Options1.Enabled := (pData.pLuaPrj = ActiveProject);
+    AddUnitToProject1.Enabled := ((pData.pLuaPrj = ActiveProject) and Assigned(ActiveProject));
+    RemoveUnitFromProject1.Enabled := ((pData.pLuaPrj = ActiveProject) and Assigned(ActiveProject));
+    Options1.Enabled := ((pData.pLuaPrj = ActiveProject) and Assigned(ActiveProject));
     UnloadFileProject1.Enabled := (((Assigned(pData.pLuaUnit)) and (pNode.Parent = vstProjectTree.RootNode)) or (Assigned(pData.pLuaPrj)));
   end;
 end;
@@ -331,6 +445,8 @@ begin
       0:
       begin
         pData := Sender.GetNodeData(Node);
+        pData.ToKeep := True;
+        
         if Assigned(pData.pLuaPrj) then
           CellText := pData.pLuaPrj.sPrjName
         else
@@ -339,6 +455,8 @@ begin
       1:
       begin
         pData := Sender.GetNodeData(Node);
+        pData.ToKeep := True;
+        
         if Assigned(pData.pLuaPrj) then
           CellText := pData.pLuaPrj.sPrjPath
         else

+ 1 - 0
LuaEdit/Watch.dfm

@@ -51,6 +51,7 @@ object frmWatch: TfrmWatch
     TreeOptions.AutoOptions = [toAutoDropExpand, toAutoScrollOnExpand, toAutoSpanColumns, toAutoTristateTracking, toAutoDeleteMovedNodes]
     TreeOptions.MiscOptions = [toEditable, toFullRepaintOnResize, toInitOnSave, toReportMode, toToggleOnDblClick, toWheelPanning]
     TreeOptions.PaintOptions = [toShowButtons, toShowDropmark, toShowHorzGridLines, toShowRoot, toShowTreeLines, toShowVertGridLines, toThemeAware, toUseBlendedImages]
+    TreeOptions.SelectionOptions = [toRightClickSelect]
     OnAfterItemPaint = vstWatchAfterItemPaint
     OnChange = vstWatchChange
     OnCreateEditor = vstWatchCreateEditor

+ 2 - 3
LuaEdit/Watch.pas

@@ -61,8 +61,7 @@ type
     procedure tbtnAddWatchClick(Sender: TObject);
     procedure vstWatchEdited(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
     procedure vstWatchChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
-    procedure FEditKeyDown(Sender: TObject; var Key: Word;
-      Shift: TShiftState);
+    procedure FEditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
   private
     { Private declarations }
     procedure WMStartEditing(var Message: TMessage); message WM_STARTEDITING;
@@ -193,7 +192,7 @@ begin
       1:
       begin
         pData := Sender.GetNodeData(Node);
-        CellText := pData.Value
+        CellText := pData.Value;
       end;
     end;
   end;