{"TotalCount":3,"Files":[{"Ident":"isotope.gitversioncontrol","Path":"Editor/VersionCont.cs","FileName":"VersionCont.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":306347,"IsPrivate":false,"Code":"using System;\r\nusing System.IO;\r\nusing System.Collections.Generic;\r\nusing System.Threading.Tasks;\r\nusing System.Linq;\r\nusing Editor;\r\nusing Sandbox;\r\n\r\nusing Button = Editor.Button;\r\nusing Label = Editor.Label;\r\nusing Checkbox = Editor.Checkbox;\r\nusing LineEdit = Editor.LineEdit;\r\n\r\n/// \u003Csummary\u003E\r\n/// Git Version Control widget for s\u0026box editor.\r\n/// Provides UI for repository management, file change tracking, commit history, and remote synchronization.\r\n/// \u003C/summary\u003E\r\n[Dock( \u0022Editor\u0022, \u0022Version Control\u0022, \u0022account_tree\u0022 )]\r\npublic partial class LocalControlWidget : Widget\r\n{\r\n\tprivate const int MAX_FILES_DISPLAYED = 50;\r\n\tprivate const float REFRESH_DEBOUNCE_TIME = 0.5f;\r\n\tprivate const int FILE_WATCHER_BUFFER_SIZE = 65536;\r\n\r\n\tprivate Widget _changesView;\r\n\tprivate Widget _historyView;\r\n\tprivate Widget _noGitView;\r\n\r\n\tprivate ScrollArea _changesScroll;\r\n\tprivate ScrollArea _historyScroll;\r\n\r\n\tprivate TextEdit _commitMessage;\r\n\tprivate LineEdit _gitRemoteUrl;\r\n\tprivate Button _commitBtn;\r\n\tprivate Button _changesTabBtn;\r\n\tprivate Button _historyTabBtn;\r\n\r\n\tprivate bool _showChangesTab = true;\r\n\tprivate bool _needsRefresh = false;\r\n\tprivate bool _gitOperationInProgress = false;\r\n\tprivate FileSystemWatcher _watcher;\r\n\tprivate TimeSince _lastRefresh = 0;\r\n\r\n\tprivate class ChangeRow\r\n\t{\r\n\t\tpublic string FilePath;\r\n\t\tpublic Checkbox Toggle;\r\n\t}\r\n\tprivate List\u003CChangeRow\u003E _trackedRows = new();\r\n\r\n\tpublic LocalControlWidget( Widget parent ) : base( parent )\r\n\t{\r\n\t\tMinimumSize = new Vector2( 200, 500 );\r\n\t\tLayout = Layout.Column();\r\n\t\tLayout.Margin = 10;\r\n\t\tLayout.Spacing = 8;\r\n\r\n\t\tBuildTopBar();\r\n\t\tLayout.AddSeparator();\r\n\r\n\t\t_noGitView = new Widget( this );\r\n\t\t_noGitView.Layout = Layout.Column();\r\n\r\n\t\t_changesView = new Widget( this );\r\n\t\t_changesView.Layout = Layout.Column();\r\n\t\t_changesView.Visible = false;\r\n\r\n\t\t_historyView = new Widget( this );\r\n\t\t_historyView.Layout = Layout.Column();\r\n\t\t_historyView.Visible = false;\r\n\r\n\t\tLayout.Add( _noGitView );\r\n\t\tLayout.Add( _changesView );\r\n\t\tLayout.Add( _historyView );\r\n\r\n\t\tBuildNoGitView();\r\n\t\tBuildChangesArea();\r\n\t\tBuildHistoryArea();\r\n\r\n\t\tSetupAutoRefresh();\r\n\t\tUpdateRootView();\r\n\r\n\t\tTryPopulateGitRemoteUrlFromOrigin();\r\n\t}\r\n\r\n\tprivate void BuildTopBar()\r\n\t{\r\n\t\tvar topBar = Layout.AddRow();\r\n\t\ttopBar.Spacing = 5;\r\n\r\n\t\t_changesTabBtn = new Button( \u0022\uD83D\uDCDD Changes\u0022 );\r\n\t\t_changesTabBtn.Clicked \u002B= () =\u003E ShowTab( true );\r\n\t\ttopBar.Add( _changesTabBtn );\r\n\r\n\t\t_historyTabBtn = new Button( \u0022\uD83D\uDD52 History\u0022 );\r\n\t\t_historyTabBtn.Clicked \u002B= () =\u003E ShowTab( false );\r\n\t\ttopBar.Add( _historyTabBtn );\r\n\r\n\t\ttopBar.AddStretchCell();\r\n\r\n\t\tvar refreshBtn = new Button( string.Empty, \u0022refresh\u0022 );\r\n\t\trefreshBtn.ToolTip = \u0022Refresh View\u0022;\r\n\t\trefreshBtn.Clicked \u002B= OnRefreshClicked;\r\n\t\ttopBar.Add( refreshBtn );\r\n\t}\r\n\r\n\t// --- first run view ---\r\n\r\n\tprivate void BuildNoGitView()\r\n\t{\r\n\t\t_noGitView.Layout.Margin = 16;\r\n\t\t_noGitView.Layout.Spacing = 12;\r\n\r\n\t\t_noGitView.Layout.Add( new Label( \u0022\u003Cbig\u003E\u003Cb\u003E\u26A0 Git Not Found\u003C/b\u003E\u003C/big\u003E\u0022 ) );\r\n\r\n\t\tvar desc = new Label(\r\n\t\t\t\u0022This Library uses Git for version control. Git does not appear to be installed or is not available in your system PATH.\\n\\n\u0022 \u002B\r\n\t\t\t\u0022Git stores your project history locally \u2014 no account or internet connection is required. You can optionally push to GitHub later.\u0022,\r\n\t\t\t_noGitView\r\n\t\t);\r\n\t\tdesc.WordWrap = true;\r\n\t\t_noGitView.Layout.Add( desc );\r\n\r\n\t\t_noGitView.Layout.AddSeparator();\r\n\r\n\t\t_noGitView.Layout.Add( new Label( \u0022\u003Cb\u003ETo get started:\u003C/b\u003E\u0022 ) );\r\n\r\n\t\tvar steps = new Label(\r\n\t\t\t\u00221. Download and install Git from  git-scm.com/download/win\\n\u0022 \u002B\r\n\t\t\t\u00222. Restart s\u0026box after installing\\n\u0022 \u002B\r\n\t\t\t\u00223. Click Refresh above \u2014 the panel will activate automatically\u0022,\r\n\t\t\t_noGitView\r\n\t\t);\r\n\t\tsteps.WordWrap = true;\r\n\t\t_noGitView.Layout.Add( steps );\r\n\r\n\t\t_noGitView.Layout.AddSeparator();\r\n\r\n\t\tvar footer = new Label( \u0022\u003Cfont color=\u0027#888\u0027\u003EOnce Git is installed, this panel will let you commit, view history, restore previous versions, and optionally push to GitHub.\u003C/font\u003E\u0022, _noGitView );\r\n\t\tfooter.WordWrap = true;\r\n\t\t_noGitView.Layout.Add( footer );\r\n\r\n\t\t_noGitView.Layout.AddStretchCell();\r\n\t}\r\n\r\n\t// --- Changes area ---\r\n\r\n\tprivate Label _syncStatusLabel;\r\n\tprivate void BuildChangesArea()\r\n\t{\r\n\t\t_changesView.Layout.Add( new Label( \u0022\u003Cbig\u003E\u003Cb\u003EUncommitted Changes:\u003C/b\u003E\u003C/big\u003E\u0022 ) );\r\n\r\n\t\t_syncStatusLabel = new Label( \u0022\u003Cfont color=\u0027#888\u0027\u003EChecking sync status...\u003C/font\u003E\u0022, _changesView );\r\n\t\t_changesView.Layout.Add( _syncStatusLabel );\r\n\r\n\t\tvar spacer1 = new Widget( _changesView );\r\n\t\tspacer1.MinimumSize = new Vector2( 0, 8 );\r\n\t\t_changesView.Layout.Add( spacer1 );\r\n\r\n\t\t_changesScroll = new ScrollArea( _changesView );\r\n\t\t_changesView.Layout.Add( _changesScroll );\r\n\r\n\t\t_changesView.Layout.AddSeparator();\r\n\r\n\t\tvar spacer2 = new Widget( _changesView );\r\n\t\tspacer2.MinimumSize = new Vector2( 0, 8 );\r\n\t\t_changesView.Layout.Add( spacer2 );\r\n\r\n\t\t_changesView.Layout.Add( new Label( \u0022\u003Cbig\u003E\u003Cb\u003ECommit Message:\u003C/b\u003E\u003C/big\u003E\u0022 ) );\r\n\r\n\t\tvar textSpacer = new Widget( _changesView );\r\n\t\ttextSpacer.MinimumSize = new Vector2( 0, 4 );\r\n\t\t_changesView.Layout.Add( textSpacer );\r\n\r\n\t\t_commitMessage = new TextEdit(_changesView);\r\n\t\t_commitMessage.MinimumSize = new Vector2(0, 80);\r\n\t\t_commitMessage.MaximumSize = new Vector2(9999, 80);\r\n\t\t_commitMessage.PlaceholderText = \u0022Enter commit message... (Leave blank for default)\u0022;\r\n\r\n\t\t_changesView.Layout.Add(_commitMessage);\r\n\r\n\t\t_commitBtn = new Button( \u0022Commit\u0022, \u0022check_circle\u0022 );\r\n\t\t_commitBtn.Clicked \u002B= OnCommitClicked;\r\n\t\t_changesView.Layout.Add( _commitBtn );\r\n\r\n\t\tvar remoteSpacer = new Widget( _changesView );\r\n\t\tremoteSpacer.MinimumSize = new Vector2( 0, 12 );\r\n\t\t_changesView.Layout.Add( remoteSpacer );\r\n\r\n\t\t// Remote / push-pull section\r\n\t\tvar remoteSection = new Widget( _changesView );\r\n\t\tremoteSection.Layout = Layout.Column();\r\n\t\tremoteSection.Layout.Spacing = 5;\r\n\t\t_changesView.Layout.Add( remoteSection );\r\n\r\n\t\tremoteSection.Layout.Add( new Label( \u0022\u003Cb\u003ERemote URL (optional):\u003C/b\u003E\u0022 ) );\r\n\r\n\t\t_gitRemoteUrl = new LineEdit();\r\n\t\t_gitRemoteUrl.PlaceholderText = \u0022https://github.com/user/repo.git\u0022;\r\n\t\t_gitRemoteUrl.MinimumSize = new Vector2( 0, 24 );\r\n\t\t_gitRemoteUrl.MaximumSize = new Vector2( 9999, 24 );\r\n\t\tremoteSection.Layout.Add( _gitRemoteUrl );\r\n\r\n\t\tvar spacer = new Widget( remoteSection );\r\n\t\tspacer.MinimumSize = new Vector2( 0, 2 );\r\n\t\tremoteSection.Layout.Add( spacer );\r\n\r\n\t\tvar row1 = remoteSection.Layout.AddRow();\r\n\t\trow1.Spacing = 5;\r\n\r\n\t\tvar initBtn = new Button( \u0022Init Git\u0022, \u0022create_new_folder\u0022 );\r\n\t\tinitBtn.ToolTip = \u0022Initialize a new Git repository in this project folder\u0022;\r\n\t\tinitBtn.Clicked \u002B= OnInitGitClicked;\r\n\t\trow1.Add( initBtn, 1 );\r\n\r\n\t\tvar connectBtn = new Button( \u0022Set Remote\u0022, \u0022hub\u0022 );\r\n\t\tconnectBtn.ToolTip = \u0022Set the remote repository URL for this project\u0022;\r\n\t\tconnectBtn.Clicked \u002B= OnConnectOriginClicked;\r\n\t\trow1.Add( connectBtn, 1 );\r\n\r\n\t\tvar row2 = remoteSection.Layout.AddRow();\r\n\t\trow2.Spacing = 5;\r\n\r\n\t\tvar pullBtn = new Button( \u0022Pull\u0022, \u0022download\u0022 );\r\n\t\tpullBtn.ToolTip = \u0022Pull changes from the remote repository. Make sure to commit or stash your local changes first!\u0022;\r\n\t\tpullBtn.Clicked \u002B= OnPullClicked;\r\n\t\trow2.Add( pullBtn, 1 );\r\n\r\n\t\tvar pushBtn = new Button( \u0022Push\u0022, \u0022upload\u0022 );\r\n\t\tpushBtn.ToolTip = \u0022Push your committed changes to the remote repository.\u0022;\r\n\t\tpushBtn.Clicked \u002B= OnPushClicked;\r\n\t\trow2.Add( pushBtn, 1 );\r\n\t}\r\n\r\n\t// --- History area ---\r\n\r\n\tprivate void BuildHistoryArea()\r\n\t{\r\n\t\t_historyView.Layout.Add( new Label( \u0022\u003Cbig\u003E\u003Cb\u003ECommit History:\u003C/b\u003E\u003C/big\u003E\u0022 ) );\r\n\r\n\t\tvar spacer = new Widget( _historyView );\r\n\t\tspacer.MinimumSize = new Vector2( 0, 8 );\r\n\t\t_historyView.Layout.Add( spacer );\r\n\r\n\t\t_historyScroll = new ScrollArea( _historyView );\r\n\t\t_historyView.Layout.Add( _historyScroll );\r\n\t}\r\n\r\n\t// --- View switching ---\r\n\r\n\tprivate void UpdateRootView()\r\n\t{\r\n\t\tbool gitReady = IsGitAvailable();\r\n\r\n\t\t_noGitView.Visible = !gitReady;\r\n\t\t_changesTabBtn.Enabled = gitReady;\r\n\t\t_historyTabBtn.Enabled = gitReady;\r\n\r\n\t\tif ( gitReady )\r\n\t\t{\r\n\t\t\tShowTab( _showChangesTab );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t_changesView.Visible = false;\r\n\t\t\t_historyView.Visible = false;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void ShowTab( bool showChanges )\r\n\t{\r\n\t\t_showChangesTab = showChanges;\r\n\t\t_changesView.Visible = showChanges;\r\n\t\t_historyView.Visible = !showChanges;\r\n\t\t_noGitView.Visible = false;\r\n\r\n\t\tif ( showChanges )\r\n\t\t{\r\n\t\t\tOnRefreshClicked();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tRefreshHistoryUI();\r\n\t\t}\r\n\t}\r\n\r\n\t// --- Helpers ---\r\n\r\n\tprivate void AddChangeItem( Widget parentCanvas, string filePath, string status )\r\n\t{\r\n\t\tvar row = parentCanvas.Layout.AddRow();\r\n\t\trow.Spacing = 5;\r\n\r\n\t\tvar cb = new Checkbox { Value = true };\r\n\t\trow.Add( cb );\r\n\r\n\t\tvar fileLabel = new ClickableLabel( filePath, parentCanvas );\r\n\t\tfileLabel.ToolTip = \u0022Double-click to view diff\u0022;\r\n\t\tfileLabel.DoubleClicked \u002B= () =\u003E OpenDiffWindow( filePath );\r\n\t\tfileLabel.RightClicked \u002B= pos =\u003E ShowChangeItemContextMenu( filePath, pos );\r\n\r\n\t\trow.Add( fileLabel );\r\n\t\trow.AddStretchCell();\r\n\t\trow.Add( new Label( status ) );\r\n\r\n\t\t_trackedRows.Add( new ChangeRow { FilePath = filePath, Toggle = cb } );\r\n\t}\r\n\r\n\tprivate void ShowChangeItemContextMenu( string filePath, Vector2 screenPosition )\r\n\t{\r\n\t\tvar menu = new ContextMenu( this );\r\n\t\tvar normalizedFilePath = filePath.Replace( \u0022\\\\\u0022, \u0022/\u0022 ).Trim();\r\n\r\n\t\tmenu.AddOption( $\u0022Ignore File: {normalizedFilePath}\u0022, \u0022block\u0022, () =\u003E\r\n\t\t{\r\n\t\t\tif ( AddToGitIgnore( normalizedFilePath ) )\r\n\t\t\t{\r\n\t\t\t\tOnRefreshClicked();\r\n\t\t\t}\r\n\t\t} );\r\n\r\n\t\tvar folderPath = GetFolderIgnorePath( normalizedFilePath );\r\n\t\tif ( !string.IsNullOrWhiteSpace( folderPath ) )\r\n\t\t{\r\n\t\t\tmenu.AddOption( $\u0022Ignore Folder: {folderPath}\u0022, \u0022folder_off\u0022, () =\u003E\r\n\t\t\t{\r\n\t\t\t\tif ( AddToGitIgnore( folderPath ) )\r\n\t\t\t\t{\r\n\t\t\t\t\tOnRefreshClicked();\r\n\t\t\t\t}\r\n\t\t\t} );\r\n\t\t}\r\n\r\n\t\tmenu.AddOption( \u0022Discard Changes\u0022, \u0022history\u0022, () =\u003E\r\n\t\t{\r\n\t\t\tEditor.Dialog.AskConfirm(\r\n\t\t\t\t() =\u003E PerformDiscard( normalizedFilePath ),\r\n\t\t\t\t$\u0022Are you sure you want to permanently discard changes to \u0027{normalizedFilePath}\u0027? \\n\\nThis cannot be undone.\u0022,\r\n\t\t\t\t\u0022Discard Changes?\u0022\r\n\t\t\t);\r\n\t\t} );\r\n\r\n\t\tmenu.OpenAt( screenPosition, false );\r\n\t}\r\n\r\n\tprivate void PerformDiscard( string path )\r\n\t{\r\n\t\tvar (ok, _, err) = RunGitCommand( $\u0022restore {QuoteArg( path )}\u0022 );\r\n\t\tif ( ok )\r\n\t\t{\r\n\t\t\tLog.Info( $\u0022Discarded changes to: {path}\u0022 );\r\n\t\t\tOnRefreshClicked();\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tLog.Error( $\u0022Discard failed: {err}\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate static string GetFolderIgnorePath( string filePath )\r\n\t{\r\n\t\tvar dir = Path.GetDirectoryName( filePath )?.Replace( \u0022\\\\\u0022, \u0022/\u0022 );\r\n\t\tif ( string.IsNullOrWhiteSpace( dir ) )\r\n\t\t{\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\treturn dir.EndsWith( \u0022/\u0022 ) ? dir : dir \u002B \u0022/\u0022;\r\n\t}\r\n\r\n\tprivate bool AddToGitIgnore( string entry )\r\n\t{\r\n\t\tif ( string.IsNullOrWhiteSpace( entry ) )\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\ttry\r\n\t\t{\r\n\t\t\tvar gitIgnorePath = Path.Combine( Project.Current.GetRootPath(), \u0022.gitignore\u0022 );\r\n\t\t\tvar normalizedEntry = entry.Replace( \u0022\\\\\u0022, \u0022/\u0022 ).Trim();\r\n\r\n\t\t\tvar lines = File.Exists( gitIgnorePath )\r\n\t\t\t\t? File.ReadAllLines( gitIgnorePath ).ToList()\r\n\t\t\t\t: new List\u003Cstring\u003E();\r\n\r\n\t\t\tif ( lines.Any( x =\u003E string.Equals( x.Trim(), normalizedEntry, StringComparison.Ordinal ) ) )\r\n\t\t\t{\r\n\t\t\t\tLog.Info( $\u0022Already in .gitignore: {normalizedEntry}\u0022 );\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\r\n\t\t\tlines.Add( normalizedEntry );\r\n\t\t\tFile.WriteAllLines( gitIgnorePath, lines );\r\n\t\t\tLog.Info( $\u0022Added to .gitignore: {normalizedEntry}\u0022 );\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tcatch ( Exception e )\r\n\t\t{\r\n\t\t\tLog.Error( $\u0022Failed to add to .gitignore: {e.Message}\u0022 );\r\n\t\t\treturn false;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void OpenDiffWindow( string relativePath )\r\n\t{\r\n\t\tstring currentPath = Path.Combine( Project.Current.GetRootPath(), relativePath );\r\n\t\tstring currentContent = File.Exists( currentPath ) ? File.ReadAllText( currentPath ) : \u0022[File is missing in current workspace]\u0022;\r\n\t\tstring oldContent = ReadGitFileAtRevision( \u0022HEAD\u0022, relativePath );\r\n\r\n\t\tvar diff = new DiffWindow( relativePath, oldContent, currentContent );\r\n\t\tdiff.Show();\r\n\t}\r\n\r\n\tprivate void RefreshHistoryUI()\r\n\t{\r\n\t\ttry\r\n\t\t{\r\n\t\t\t_historyScroll.Canvas?.Destroy();\r\n\t\t\t\r\n\t\t\tvar canvas = new Widget( _historyScroll );\r\n\t\t\tcanvas.Layout = Layout.Column();\r\n\t\t\t_historyScroll.Canvas = canvas;\r\n\r\n\t\t\tRefreshGitHistoryUI( canvas );\r\n\t\t}\r\n\t\tcatch ( Exception e )\r\n\t\t{\r\n\t\t\tLog.Error( $\u0022Failed to refresh history UI: {e.Message}\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void OnRefreshClicked()\r\n\t{\r\n\t\tif ( !IsGitAvailable() )\r\n\t\t{\r\n\t\t\tUpdateRootView();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\ttry\r\n\t\t{\r\n\t\t\t_changesScroll.Canvas?.Destroy();\r\n\r\n\t\t\tvar canvas = new Widget( _changesScroll );\r\n\t\t\tcanvas.Layout = Layout.Column();\r\n\t\t\t_changesScroll.Canvas = canvas;\r\n\r\n\t\t\t_trackedRows.Clear();\r\n\r\n\t\t\tRefreshGitChanges( canvas );\r\n\r\n\t\t\t_ = UpdateSyncStatusAsync();\r\n\r\n\t\t\tcanvas.Layout.AddStretchCell();\r\n\t\t}\r\n\t\tcatch ( Exception e )\r\n\t\t{\r\n\t\t\tLog.Error( $\u0022Failed to refresh changes UI: {e.Message}\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void OnCommitClicked()\r\n\t{\r\n\t\t_ = CommitGitChanges();\r\n\t}\r\n\r\n\t// --- Autorefresh lifecycle ---\r\n\r\n\tprivate void SetupAutoRefresh()\r\n\t{\r\n\t\tif (_watcher != null)\r\n\t\t{\r\n\t\t\t_watcher.EnableRaisingEvents = false;\r\n\t\t\t_watcher.Dispose();\r\n\t\t}\r\n\r\n\t\t_watcher = new FileSystemWatcher(Project.Current.GetRootPath());\r\n\t\t_watcher.IncludeSubdirectories = true;\r\n\r\n\t\t_watcher.InternalBufferSize = FILE_WATCHER_BUFFER_SIZE;\r\n\r\n\t\t_watcher.NotifyFilter = NotifyFilters.LastWrite\r\n\t\t\t\t\t\t\t  | NotifyFilters.FileName\r\n\t\t\t\t\t\t\t  | NotifyFilters.DirectoryName\r\n\t\t\t\t\t\t\t  | NotifyFilters.Size\r\n\t\t\t\t\t\t\t  | NotifyFilters.CreationTime;\r\n\r\n\t\t_watcher.Changed \u002B= OnFileChanged;\r\n\t\t_watcher.Created \u002B= OnFileChanged;\r\n\t\t_watcher.Deleted \u002B= OnFileChanged;\r\n\t\t_watcher.Renamed \u002B= OnFileChanged;\r\n\r\n\t\t_watcher.Error \u002B= OnWatcherError;\r\n\r\n\t\t_watcher.EnableRaisingEvents = true;\r\n\t}\r\n\r\n\tprivate void OnWatcherError(object sender, ErrorEventArgs e)\r\n\t{\r\n\t\tLog.Warning($\u0022Version Control Watcher error: {e.GetException().Message}. Restarting...\u0022);\r\n\r\n\t\t_ = Task.Run(async () =\u003E\r\n\t\t{\r\n\t\t\tawait Task.Delay(1000);\r\n\t\t\tSetupAutoRefresh();\r\n\t\t});\r\n\t}\r\n\r\n\tprivate void OnFileChanged( object sender, FileSystemEventArgs e )\r\n\t{\r\n\t\tif ( IsInternalToolPath( e.FullPath ) )\r\n\t\t{\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t_needsRefresh = true;\r\n\t\t_lastRefresh = 0;\r\n\t}\r\n\r\n\tprivate static bool IsInternalToolPath( string fullPath )\r\n\t{\r\n\t\tif ( string.IsNullOrWhiteSpace( fullPath ) )\r\n\t\t{\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tvar normalized = fullPath.Replace( \u0027\\\\\u0027, \u0027/\u0027 );\r\n\t\treturn normalized.Contains( \u0022/.git/\u0022, StringComparison.OrdinalIgnoreCase )\r\n\t\t\t|| normalized.EndsWith( \u0022/.git\u0022, StringComparison.OrdinalIgnoreCase );\r\n\t}\r\n\r\n\t[EditorEvent.Frame]\r\n\tpublic void FrameUpdate()\r\n\t{\r\n\t\tif (_needsRefresh \u0026\u0026 _lastRefresh \u003E REFRESH_DEBOUNCE_TIME \u0026\u0026 !_gitOperationInProgress)\r\n\t\t{\r\n\t\t\t_needsRefresh = false;\r\n\t\t\t_lastRefresh = 0;\r\n\r\n\t\t\tif (_changesView.Visible)\r\n\t\t\t{\r\n\t\t\t\tOnRefreshClicked();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tpublic override void OnDestroyed()\r\n\t{\r\n\t\tif ( _watcher != null )\r\n\t\t{\r\n\t\t\t_watcher.EnableRaisingEvents = false;\r\n\t\t\t_watcher.Changed -= OnFileChanged;\r\n\t\t\t_watcher.Created -= OnFileChanged;\r\n\t\t\t_watcher.Deleted -= OnFileChanged;\r\n\t\t\t_watcher.Renamed -= OnFileChanged;\r\n\t\t\t_watcher.Dispose();\r\n\t\t\t_watcher = null;\r\n\t\t}\r\n\r\n\t\tbase.OnDestroyed();\r\n\t}\r\n}\r\n"},{"Ident":"isotope.gitversioncontrol","Path":"Editor/VersionCont.Git.cs","FileName":"VersionCont.Git.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":306347,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing Sandbox.UI;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Diagnostics;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing System.Threading.Tasks;\r\nusing Button = Editor.Button;\r\nusing Label = Editor.Label;\r\n\r\npublic partial class LocalControlWidget\r\n{\r\n\tprivate class GitCommitView\r\n\t{\r\n\t\tpublic string Hash;\r\n\t\tpublic string Date;\r\n\t\tpublic string Message;\r\n\t\tpublic List\u003Cstring\u003E Files;\r\n\t}\r\n\r\n\t// --- History UI ---\r\n\r\n\tprivate void RefreshGitHistoryUI( Widget canvas )\r\n\t{\r\n\t\tif ( !EnsureGitRepository() )\r\n\t\t{\r\n\t\t\tcanvas.Layout.Add( new Label( \u0022No Git repository found.\u0022 ) );\r\n\t\t\tcanvas.Layout.AddStretchCell();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar unpushedSet = new HashSet\u003Cstring\u003E();\r\n\t\tvar (syncOk, syncOut, _) = RunGitCommand( \u0022rev-list HEAD --not --remotes\u0022 );\r\n\t\tif ( syncOk \u0026\u0026 !string.IsNullOrWhiteSpace( syncOut ) )\r\n\t\t{\r\n\t\t\tforeach ( var h in syncOut.Split( new[] { \u0027\\n\u0027, \u0027\\r\u0027 }, StringSplitOptions.RemoveEmptyEntries ) )\r\n\t\t\t{\r\n\t\t\t\tunpushedSet.Add( h.Trim().ToLower() );\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tvar (ok, output, error) = RunGitCommand( \u0022log --date=format:%Y-%m-%d_%H:%M --pretty=format:%H|%ad|%s --name-only --max-count=30\u0022 );\r\n\t\tif ( !ok )\r\n\t\t{\r\n\t\t\tcanvas.Layout.Add( new Label( $\u0022Git log failed: {error}\u0022 ) );\r\n\t\t\tcanvas.Layout.AddStretchCell();\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar lines = output.Split( new[] { \u0022\\r\\n\u0022, \u0022\\r\u0022, \u0022\\n\u0022 }, StringSplitOptions.None );\r\n\t\tvar commits = new List\u003CGitCommitView\u003E();\r\n\t\tGitCommitView current = null;\r\n\r\n\t\tforeach ( var raw in lines )\r\n\t\t{\r\n\t\t\tvar line = raw?.TrimEnd() ?? \u0022\u0022;\r\n\t\t\tif ( string.IsNullOrWhiteSpace( line ) ) continue;\r\n\r\n\t\t\tif ( line.Count( c =\u003E c == \u0027|\u0027 ) \u003E= 2 )\r\n\t\t\t{\r\n\t\t\t\tvar parts = line.Split( \u0027|\u0027, 3 );\r\n\t\t\t\tstring dateString = parts[1];\r\n\t\t\t\tvar dateParts = dateString.Split( \u0027_\u0027 );\r\n\t\t\t\tstring formattedTimestamp = dateString.Replace( \u0022_\u0022, \u0022 \u0022 );\r\n\r\n\t\t\t\tif ( dateParts.Length \u003E= 2 )\r\n\t\t\t\t\tformattedTimestamp = $\u0022{dateParts[0]} \u003Cu\u003E{dateParts[1]}\u003C/u\u003E\u0022;\r\n\r\n\t\t\t\tcurrent = new GitCommitView\r\n\t\t\t\t{\r\n\t\t\t\t\tHash = parts[0].Trim().ToLower(),\r\n\t\t\t\t\tDate = formattedTimestamp,\r\n\t\t\t\t\tMessage = parts[2],\r\n\t\t\t\t\tFiles = new List\u003Cstring\u003E()\r\n\t\t\t\t};\r\n\t\t\t\tcommits.Add( current );\r\n\t\t\t}\r\n\t\t\telse if ( current != null )\r\n\t\t\t{\r\n\t\t\t\tcurrent.Files.Add( line.Trim() );\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tforeach ( var commit in commits )\r\n\t\t{\r\n\t\t\tvar card = new Widget( canvas );\r\n\t\t\tcard.Layout = Layout.Column();\r\n\t\t\tcard.Layout.Margin = new Margin( 10, 8 );\r\n\t\t\tcard.Layout.Spacing = 4;\r\n\r\n\t\t\tcard.Layout.Add( new Label( $\u0022\u003Cb\u003E\uD83D\uDCAC {commit.Message}\u003C/b\u003E\u0022, card ) { WordWrap = true } );\r\n\r\n\t\t\tvar actionRow = card.Layout.AddRow();\r\n\t\t\tactionRow.Spacing = 5;\r\n\t\t\tactionRow.Add( new Label( $\u0022\u003Csmall\u003E\u003Cfont color=\u0027#ffffff\u0027\u003E{commit.Date}\u003C/font\u003E\u003C/small\u003E\u0022, card ) );\r\n\r\n\t\t\tstring shortHash = commit.Hash.Length \u003E 7 ? commit.Hash.Substring( 0, 7 ) : commit.Hash;\r\n\t\t\tstring webUrl = GetCommitWebUrl( commit.Hash );\r\n\t\t\tbool isPushed = !unpushedSet.Contains( commit.Hash ) \u0026\u0026 !string.IsNullOrEmpty( webUrl );\r\n\r\n\t\t\tvar hashLabel = new ClickableLabel( string.Empty, card );\r\n\r\n\t\t\tif ( isPushed )\r\n\t\t\t{\r\n\t\t\t\thashLabel.Text = $\u0022\u003Csmall\u003E\u003Cfont color=\u0027#55aaff\u0027\u003E\u003Cb\u003E\u003Cu\u003E\u2022 {shortHash}\u003C/u\u003E\u003C/b\u003E\u003C/font\u003E\u003C/small\u003E\u0022;\r\n\t\t\t\thashLabel.ToolTip = $\u0022Double click to open commit {shortHash} on Web\u0022;\r\n\t\t\t\thashLabel.DoubleClicked = () =\u003E Process.Start( new ProcessStartInfo( webUrl ) { UseShellExecute = true } );\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\thashLabel.Text = $\u0022\u003Csmall\u003E\u003Cfont color=\u0027#bbbbbb\u0027\u003E\u003Cb\u003E\u003Cu\u003E\u2022 {shortHash}\u003C/u\u003E\u003C/b\u003E\u003C/font\u003E\u003C/small\u003E\u0022;\r\n\t\t\t\thashLabel.ToolTip = string.IsNullOrEmpty( webUrl ) ? \u0022Set remote to enable links\u0022 : \u0022Commit local only (Not Pushed)\u0022;\r\n\t\t\t}\r\n\r\n\t\t\tactionRow.Add( hashLabel );\r\n\t\t\tactionRow.AddStretchCell();\r\n\r\n\t\t\tvar viewBtn = new Button( \u0022View\u0022, \u0022visibility\u0022 );\r\n\t\t\tactionRow.Add( viewBtn );\r\n\r\n\t\t\tvar filesContainer = new Widget( card ) { Visible = false };\r\n\t\t\tfilesContainer.Layout = Layout.Column();\r\n\t\t\tfilesContainer.Layout.Margin = new Margin( 20, 5, 0, 5 );\r\n\t\t\tfilesContainer.Layout.Spacing = 8;\r\n\r\n\t\t\tviewBtn.Clicked \u002B= () =\u003E {\r\n\t\t\t\tfilesContainer.Visible = !filesContainer.Visible;\r\n\t\t\t\tviewBtn.Text = filesContainer.Visible ? \u0022Hide\u0022 : \u0022View\u0022;\r\n\t\t\t\tviewBtn.Icon = filesContainer.Visible ? \u0022visibility_off\u0022 : \u0022visibility\u0022;\r\n\t\t\t};\r\n\r\n\t\t\tvar capturedHash = commit.Hash;\r\n\t\t\tvar capturedMsg = commit.Message;\r\n\t\t\tvar restoreBtn = new Button( \u0022Restore to this state\u0022, \u0022settings_backup_restore\u0022 );\r\n\t\t\trestoreBtn.ToolTip = \u0022Restores all files to their state in this commit. This does not move your branch.\\nRestored files will appear in Changes for you to review and commit.\u0022;\r\n\t\t\trestoreBtn.Clicked \u002B= () =\u003E OnGitRestoreClicked( capturedHash, capturedMsg );\r\n\t\t\tfilesContainer.Layout.AddRow().Add( restoreBtn, 1 );\r\n\r\n\t\t\tfilesContainer.Layout.AddSeparator();\r\n\t\t\tfilesContainer.Layout.Add( new Label( $\u0022\u003Csmall\u003E\u003Cb\u003E{commit.Files.Count} file(s) changed:\u003C/b\u003E\u003C/small\u003E\u0022 ) );\r\n\t\t\t\r\n\t\t\tvar filesToShow = commit.Files.Take( MAX_FILES_DISPLAYED ).ToList();\r\n\t\t\t\r\n\t\t\tforeach ( var f in filesToShow ) \r\n\t\t\t{\r\n\t\t\t\tfilesContainer.Layout.Add( new Label( $\u0022\u003Csmall\u003E  \uD83D\uDCC4 {f}\u003C/small\u003E\u0022 ) );\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif ( commit.Files.Count \u003E MAX_FILES_DISPLAYED )\r\n\t\t\t{\r\n\t\t\t\tfilesContainer.Layout.Add( new Label( $\u0022\u003Csmall\u003E\u003Ci\u003E  ... and {commit.Files.Count - MAX_FILES_DISPLAYED} more files.\u003C/i\u003E\u003C/small\u003E\u0022 ) );\r\n\t\t\t}\r\n\r\n\t\t\tcard.Layout.Add( filesContainer );\r\n\t\t\tcanvas.Layout.Add( card );\r\n\t\t\tcanvas.Layout.AddSeparator();\r\n\t\t}\r\n\t\tcanvas.Layout.AddStretchCell();\r\n\t}\r\n\r\n\t// --- Restore ---\r\n\tprivate void OnGitRestoreClicked( string hash, string commitMessage )\r\n\t{\r\n\t\tif ( !EnsureGitRepository() ) return;\r\n\r\n\t\tvar (statusOk, statusOut, _) = RunGitCommand( \u0022status --porcelain\u0022 );\r\n\t\tbool hasUncommitted = statusOk \u0026\u0026 !string.IsNullOrWhiteSpace( statusOut );\r\n\r\n\t\tstring prompt = hasUncommitted\r\n\t\t\t? $\u0022You have uncommitted changes that will be overwritten.\\n\\nRestore files to commit \u0027{commitMessage}\u0027 ({hash})?\\n\\nThis does not move your branch \u2014 restored files will appear in Changes for you to review and commit.\u0022\r\n\t\t\t: $\u0022Restore files to commit \u0027{commitMessage}\u0027 ({hash})?\\n\\nThis does not move your branch \u2014 restored files will appear in Changes for you to review and commit.\u0022;\r\n\r\n\t\tEditor.Dialog.AskConfirm( () =\u003E PerformGitRestore( hash ), prompt, \u0022Restore Git Commit?\u0022 );\r\n\t}\r\n\r\n\tprivate void PerformGitRestore( string hash )\r\n\t{\r\n\t\tvar (restoreOk, _, restoreError) = RunGitCommand( $\u0022restore --source={QuoteArg( hash )} --worktree -- .\u0022 );\r\n\t\tif ( !restoreOk )\r\n\t\t{\r\n\t\t\tvar (checkoutOk, _, checkoutError) = RunGitCommand( $\u0022checkout {QuoteArg( hash )} -- .\u0022 );\r\n\t\t\tif ( !checkoutOk )\r\n\t\t\t{\r\n\t\t\t\tvar finalError = string.IsNullOrWhiteSpace( restoreError ) ? checkoutError : restoreError;\r\n\t\t\t\tLog.Error( $\u0022Git restore failed: {finalError}\u0022 );\r\n\t\t\t\tShowOperationNotification( \u0022Restore Failed\u0022, string.IsNullOrWhiteSpace( finalError ) ? \u0022Unable to restore commit.\u0022 : finalError, \u0022error\u0022, Theme.Red );\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tRunGitCommand( \u0022reset -- .\u0022 );\r\n\t\tShowOperationNotification( \u0022Restore Applied\u0022, \u0022Files restored \u2014 review and commit when ready\u0022, \u0022settings_backup_restore\u0022, Theme.Green );\r\n\t\tShowTab( true );\r\n\t}\r\n\r\n\t// --- Changes ---\r\n\tprivate void RefreshGitChanges( Widget canvas )\r\n\t{\r\n\t\tif ( !EnsureGitRepository() )\r\n\t\t{\r\n\t\t\tvar initRow = canvas.Layout.AddRow();\r\n\t\t\tinitRow.Add( new Label( \u0022No Git repository found in this project.\u0022 ) );\r\n\r\n\t\t\tvar initBtn = new Button( \u0022Init Git Now\u0022, \u0022create_new_folder\u0022 );\r\n\t\t\tinitBtn.Clicked \u002B= () =\u003E { OnInitGitClicked(); OnRefreshClicked(); };\r\n\r\n\t\t\tcanvas.Layout.AddSpacingCell( 8 );\r\n\t\t\tcanvas.Layout.Add( initBtn );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar (ok, output, error) = RunGitCommand( \u0022status --porcelain -uall\u0022 );\r\n\t\tif ( !ok )\r\n\t\t{\r\n\t\t\tcanvas.Layout.Add( new Label( $\u0022Git status failed: {error}\u0022 ) );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar lines = output.Split( new[] { \u0022\\r\\n\u0022, \u0022\\r\u0022, \u0022\\n\u0022 }, StringSplitOptions.RemoveEmptyEntries );\r\n\t\tif ( lines.Length == 0 )\r\n\t\t{\r\n\t\t\tcanvas.Layout.Add( new Label( \u0022No changed files.\u0022 ) );\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tforeach ( var line in lines )\r\n\t\t{\r\n\t\t\tif ( !TryParseGitStatusLine( line, out var code, out var path ) ) continue;\r\n\t\t\tAddChangeItem( canvas, path, MapGitStatus( code ) );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate bool TryParseGitStatusLine(string line, out string code, out string path)\r\n\t{\r\n\t\tcode = \u0022\u0022; path = \u0022\u0022;\r\n\t\tif (string.IsNullOrWhiteSpace(line) || line.Length \u003C 3) return false;\r\n\r\n\t\tcode = line.Substring(0, 2);\r\n\t\tpath = line.Substring(2).TrimStart();\r\n\r\n\t\tconst string renameIndicator = \u0022-\u003E\u0022;\r\n\t\tint renameIdx = path.IndexOf(renameIndicator, StringComparison.Ordinal);\r\n\t\tif (renameIdx \u003E= 0) path = path.Substring(renameIdx \u002B renameIndicator.Length).Trim();\r\n\t\t\r\n\t\tif (path.StartsWith(\u0022\\\u0022\u0022) \u0026\u0026 path.EndsWith(\u0022\\\u0022\u0022) \u0026\u0026 path.Length \u003E= 2) \r\n\t\t\tpath = path.Substring(1, path.Length - 2);\r\n\r\n\t\tpath = path.Replace(\u0022\\\\\u0022, \u0022/\u0022);\r\n\t\treturn !string.IsNullOrWhiteSpace(path);\r\n\t}\r\n\r\n\tprivate static string MapGitStatus(string code)\r\n\t{\r\n\t\tif (code.Contains(\u0022??\u0022)) return \u0022Untracked\u0022;\r\n\t\tif (code.Contains(\u0022A\u0022)) return \u0022Added\u0022;\r\n\t\tif (code.Contains(\u0022D\u0022)) return \u0022Deleted\u0022;\r\n\t\tif (code.Contains(\u0022R\u0022)) return \u0022Renamed\u0022;\r\n\t\tif (code.Contains(\u0022M\u0022)) return \u0022Modified\u0022;\r\n\t\tif (code.Contains(\u0022U\u0022)) return \u0022Unmerged\u0022;\r\n\t\treturn \u0022Changed\u0022;\r\n\t}\r\n\r\n\t// --- Commit ---\r\n\tprivate async Task CommitGitChanges()\r\n\t{\r\n\t\tif (!EnsureGitRepository())\r\n\t\t\treturn;\r\n\r\n\t\tvar filesToCommit = _trackedRows.Where(x =\u003E x.Toggle.Value).ToList();\r\n\t\tif (filesToCommit.Count == 0)\r\n\t\t\treturn;\r\n\r\n\t\t_gitOperationInProgress = true;\r\n\t\t_commitBtn.Enabled = false;\r\n\r\n\t\ttry\r\n\t\t{\r\n\t\t\tvar allPaths = string.Join(\u0022 \u0022, filesToCommit.Select(x =\u003E QuoteArg(x.FilePath)));\r\n\t\t\tvar (addOk, addOut, addErr) = await RunGitCommandAsync($\u0022add -A -- {allPaths}\u0022);\r\n\r\n\t\t\tif (!addOk)\r\n\t\t\t{\r\n\t\t\t\tLog.Error($\u0022Git add failed: {addErr}\u0022);\r\n\t\t\t\tShowOperationNotification(\r\n\t\t\t\t\t\u0022Commit Error\u0022,\r\n\t\t\t\t\t\u0022Failed to stage files.\u0022,\r\n\t\t\t\t\t\u0022error\u0022,\r\n\t\t\t\t\tTheme.Red\r\n\t\t\t\t);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tstring finalCommitMessage = _commitMessage.PlainText?.Trim();\r\n\t\t\tif (string.IsNullOrWhiteSpace(finalCommitMessage))\r\n\t\t\t{\r\n\t\t\t\tif (filesToCommit.Count == 1)\r\n\t\t\t\t{\r\n\t\t\t\t\t// Extract just the file name for a clean message\r\n\t\t\t\t\tstring fileName = Path.GetFileName(filesToCommit[0].FilePath);\r\n\t\t\t\t\tfinalCommitMessage = $\u0022Update {fileName}\u0022;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tfinalCommitMessage = $\u0022Update {filesToCommit.Count} files\u0022;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tvar (commitOk, commitOut, commitErr) = await RunGitCommandAsync(\r\n\t\t\t\t$\u0022commit -m {QuoteArg(finalCommitMessage)}\u0022\r\n\t\t\t);\r\n\r\n\t\t\tif (!commitOk)\r\n\t\t\t{\r\n\t\t\t\tLog.Warning(string.IsNullOrWhiteSpace(commitErr) ? commitOut : commitErr);\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tShowOperationNotification(\r\n\t\t\t\t\u0022Commit Created\u0022,\r\n\t\t\t\t$\u0022{filesToCommit.Count} file(s) committed\u0022,\r\n\t\t\t\t\u0022check_circle\u0022,\r\n\t\t\t\tTheme.Green\r\n\t\t\t);\r\n\r\n\t\t\t_commitMessage.PlainText = \u0022\u0022;\r\n\t\t\tOnRefreshClicked();\r\n\t\t}\r\n\t\tcatch (Exception e)\r\n\t\t{\r\n\t\t\tLog.Error($\u0022Unexpected error during commit: {e.Message}\u0022);\r\n\t\t}\r\n\t\tfinally\r\n\t\t{\r\n\t\t\t_gitOperationInProgress = false;\r\n\t\t\t_commitBtn.Enabled = true;\r\n\t\t}\r\n\t}\r\n\r\n\t// --- Remote actions ---\r\n\tprivate void OnInitGitClicked()\r\n\t{\r\n\t\tif ( !IsGitAvailable() ) { Log.Error( \u0022Git is not installed or not found in PATH.\u0022 ); return; }\r\n\t\tif ( IsGitRepository() ) { Log.Info( \u0022Git repository already exists.\u0022 ); return; }\r\n\r\n\t\tvar (ok, _, error) = RunGitCommand( \u0022init -b main\u0022 );\r\n\t\tif ( !ok ) { Log.Error( $\u0022Failed to initialize Git repository: {error}\u0022 ); return; }\r\n\r\n\t\tLog.Info( \u0022Git repository initialized.\u0022 );\r\n\r\n\t\tCreateDefaultGitIgnoreIfMissing();\r\n\r\n\t\tShowOperationNotification( \u0022Git Initialized\u0022, \u0022Repository created for this project\u0022, \u0022create_new_folder\u0022, Theme.Green );\r\n\t\tOnRefreshClicked();\r\n\t}\r\n\r\n\tprivate void CreateDefaultGitIgnoreIfMissing()\r\n\t{\r\n\t\ttry\r\n\t\t{\r\n\t\t\tstring gitIgnorePath = Path.Combine( Project.Current.GetRootPath(), \u0022.gitignore\u0022 );\r\n\t\t\t\r\n\t\t\tif ( !File.Exists( gitIgnorePath ) )\r\n\t\t\t{\r\n\t\t\t\tstring template = \r\n@\u0022# This file describes files and paths that should not be tracked by Git version control\r\n# https://git-scm.com/docs/gitignore\r\n\r\n# Auto-generated code editor files\r\n.vs/*\r\n.vscode/*\r\n*.csproj\r\nobj\r\nbin\r\nProperties/*\r\ncode/obj/*\r\ncode/Properties/*\r\n\r\n# Auto-generated asset related files\r\n.sbox/*\r\n*.generated.*\r\n*.*_c\r\n!*.shader_c\r\n*.los\r\n*.vpk\r\n*launchSettings.json\r\n*.sln\r\n*.slnx\r\n\r\n*idea\r\n\r\n# Exported / standalone games\r\nExports/\u0022;\r\n\r\n\t\t\t\tFile.WriteAllText( gitIgnorePath, template );\r\n\t\t\t\tLog.Info( \u0022Created default .gitignore template.\u0022 );\r\n\t\t\t}\r\n\t\t}\r\n\t\tcatch ( Exception e )\r\n\t\t{\r\n\t\t\tLog.Warning( $\u0022Failed to create default .gitignore: {e.Message}\u0022 );\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void OnConnectOriginClicked()\r\n\t{\r\n\t\tif ( !EnsureGitRepository() ) { Log.Warning( \u0022Initialize a Git repository first.\u0022 ); return; }\r\n\r\n\t\tvar url = _gitRemoteUrl?.Value?.Trim();\r\n\t\tif ( string.IsNullOrWhiteSpace( url ) ) { Log.Warning( \u0022Enter a remote repository URL first.\u0022 ); return; }\r\n\r\n\t\tvar (hasOrigin, _, _) = RunGitCommand( \u0022remote get-url origin\u0022 );\r\n\t\tvar args = hasOrigin ? $\u0022remote set-url origin {QuoteArg( url )}\u0022 : $\u0022remote add origin {QuoteArg( url )}\u0022;\r\n\r\n\t\tvar (ok, _, error) = RunGitCommand( args );\r\n\t\tif ( !ok ) { Log.Error( $\u0022Failed to configure remote: {error}\u0022 ); return; }\r\n\r\n\t\tLog.Info( $\u0022Remote origin set to: {url}\u0022 );\r\n\t\tShowOperationNotification( \u0022Remote Set\u0022, url, \u0022hub\u0022, Theme.Green );\r\n\t}\r\n\r\n\tprivate void TryPopulateGitRemoteUrlFromOrigin()\r\n\t{\r\n\t\tif ( _gitRemoteUrl == null || !IsGitAvailable() || !IsGitRepository() ) return;\r\n\t\tvar (ok, output, _) = RunGitCommand( \u0022remote get-url origin\u0022 );\r\n\t\tif ( ok \u0026\u0026 !string.IsNullOrWhiteSpace( output ) ) _gitRemoteUrl.Value = output.Trim();\r\n\t}\r\n\r\n\tprivate void OnPullClicked()\r\n\t{\r\n\t\tif ( !EnsureGitRepository() ) return;\r\n\t\tEditor.Dialog.AskConfirm( () =\u003E _ = ExecutePullAsync(), \u0022This will pull remote changes into your local project.\\n\\nContinue?\u0022, \u0022Confirm Pull\u0022 );\r\n\t}\r\n\r\n\tprivate async Task ExecutePullAsync()\r\n\t{\r\n\t\tif ( _gitOperationInProgress ) { Log.Warning( \u0022A Git operation is already in progress.\u0022 ); return; }\r\n\r\n\t\tbool success = false;\r\n\t\t_gitOperationInProgress = true;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tvar (ok, output, error) = await RunGitCommandAsync( \u0022pull\u0022 );\r\n\t\t\tif ( !ok ) { Log.Warning( string.IsNullOrWhiteSpace( error ) ? output : error ); return; }\r\n\r\n\t\t\tLog.Info( \u0022Pull completed.\u0022 );\r\n\t\t\tShowOperationNotification( \u0022Pull Completed\u0022, \u0022Remote changes applied\u0022, \u0022download\u0022, Theme.Primary );\r\n\t\t\tsuccess = true;\r\n\t\t}\r\n\t\tfinally { _gitOperationInProgress = false; }\r\n\r\n\t\tif ( success )\r\n\t\t{\r\n\t\t\tOnRefreshClicked();\r\n\t\t\tif ( _historyView.Visible ) RefreshHistoryUI();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate async Task ExecutePushAsync()\r\n\t{\r\n\t\tif ( _gitOperationInProgress ) { Log.Warning( \u0022A Git operation is already in progress.\u0022 ); return; }\r\n\r\n\t\tbool success = false;\r\n\t\t_gitOperationInProgress = true;\r\n\t\ttry\r\n\t\t{\r\n\t\t\tvar (ok, output, error) = await RunGitCommandAsync( \u0022push -u origin HEAD\u0022 );\r\n\t\t\tif ( !ok ) { Log.Warning( string.IsNullOrWhiteSpace( error ) ? output : error ); return; }\r\n\r\n\t\t\tLog.Info( \u0022Push completed.\u0022 );\r\n\t\t\tShowOperationNotification( \u0022Push Completed\u0022, \u0022Commits uploaded to remote\u0022, \u0022upload\u0022, Theme.Green );\r\n\t\t\tsuccess = true;\r\n\t\t}\r\n\t\tfinally { _gitOperationInProgress = false; }\r\n\r\n\t\tif ( success )\r\n\t\t{\r\n\t\t\t_ = UpdateSyncStatusAsync();\r\n\t\t\tif ( _historyView.Visible ) RefreshHistoryUI();\r\n\t\t}\r\n\t}\r\n\r\n\tprivate void OnPushClicked()\r\n\t{\r\n\t\tif ( !EnsureGitRepository() ) return;\r\n\t\tEditor.Dialog.AskConfirm( () =\u003E _ = ExecutePushAsync(), \u0022This will push your local commits to the remote repository.\\n\\nContinue?\u0022, \u0022Confirm Push\u0022 );\r\n\t}\r\n\r\n\t// --- Git helpers ---\r\n\tprivate async Task UpdateSyncStatusAsync()\r\n\t{\r\n\t\tif ( !IsGitRepository() || _gitOperationInProgress ) return;\r\n\r\n\t\tvar (ok, output, _) = await RunGitCommandAsync( \u0022rev-list --left-right --count HEAD...@{u}\u0022 );\r\n\r\n\t\tif ( !ok || string.IsNullOrWhiteSpace( output ) )\r\n\t\t{\r\n\t\t\t_syncStatusLabel.Text = \u0022\u003Cfont color=\u0027#888\u0027\u003ESync: Local only (no remote origin)\u003C/font\u003E\u0022;\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tvar parts = output.Split( \u0027\\t\u0027 );\r\n\t\tif ( parts.Length == 2 \u0026\u0026 int.TryParse( parts[0], out int ahead ) \u0026\u0026 int.TryParse( parts[1], out int behind ) )\r\n\t\t{\r\n\t\t\tif ( ahead == 0 \u0026\u0026 behind == 0 ) _syncStatusLabel.Text = \u0022\u003Cfont color=\u0027#77ff77\u0027\u003E\uE05E\uE52E Up to date with remote\u003C/font\u003E\u0022;\r\n\t\t\telse if ( ahead \u003E 0 \u0026\u0026 behind == 0 ) _syncStatusLabel.Text = $\u0022\u003Cfont color=\u0027#77ccff\u0027\u003E\uE05E\uE593 {ahead} commit(s) ahead (Ready to Push)\u003C/font\u003E\u0022;\r\n\t\t\telse if ( ahead == 0 \u0026\u0026 behind \u003E 0 ) _syncStatusLabel.Text = $\u0022\u003Cfont color=\u0027#ffcc77\u0027\u003E\uE05E\uE51E {behind} commit(s) behind (Need to Pull)\u003C/font\u003E\u0022;\r\n\t\t\telse _syncStatusLabel.Text = $\u0022\u003Cfont color=\u0027#ff7777\u0027\u003E\uE05E\uE51E {behind} behind / \uE05E\uE593 {ahead} ahead (Diverged)\u003C/font\u003E\u0022;\r\n\t\t}\r\n\t}\r\n\r\n\tprivate bool EnsureGitRepository() { return IsGitAvailable() \u0026\u0026 IsGitRepository(); }\r\n\tprivate bool IsGitRepository() { return Directory.Exists( Path.Combine( Project.Current.GetRootPath(), \u0022.git\u0022 ) ); }\r\n\tprivate bool? _isGitAvailableCache = null;\r\n\r\n\tprivate bool IsGitAvailable()\r\n\t{\r\n\t\tif (_isGitAvailableCache.HasValue)\r\n\t\t\treturn _isGitAvailableCache.Value;\r\n\r\n\t\tvar (ok, _, _) = RunGitCommandRaw(\u0022--version\u0022);\r\n\t\t_isGitAvailableCache = ok;\r\n\t\treturn ok;\r\n\t}\r\n\tprivate string ReadGitFileAtRevision( string revision, string relativePath )\r\n\t{\r\n\t\trelativePath = relativePath.Replace( \u0022\\\\\u0022, \u0022/\u0022 );\r\n\t\tvar (ok, output, _) = RunGitCommand( $\u0022show {revision}:{relativePath}\u0022 );\r\n\t\treturn ok ? output : \u0022[No previous version in Git history]\u0022;\r\n\t}\r\n\r\n\tprivate (bool ok, string output, string error) RunGitCommand( string arguments ) { return RunGitCommandRaw( arguments ); }\r\n\tprivate Task\u003C(bool ok, string output, string error)\u003E RunGitCommandAsync( string arguments ) { return Task.Run( () =\u003E RunGitCommandRaw( arguments ) ); }\r\n\r\n\tprivate (bool ok, string output, string error) RunGitCommandRaw( string arguments )\r\n\t{\r\n\t\ttry\r\n\t\t{\r\n\t\t\tvar startInfo = new ProcessStartInfo( \u0022git\u0022, arguments )\r\n\t\t\t{\r\n\t\t\t\tWorkingDirectory = Project.Current.GetRootPath(),\r\n\t\t\t\tUseShellExecute = false,\r\n\t\t\t\tRedirectStandardOutput = true,\r\n\t\t\t\tRedirectStandardError = true,\r\n\t\t\t\tCreateNoWindow = true\r\n\t\t\t};\r\n\r\n\t\t\tusing var proc = Process.Start( startInfo );\r\n\t\t\tif ( proc == null ) return (false, \u0022\u0022, \u0022Failed to launch git process.\u0022);\r\n\r\n\t\t\tvar outTask = proc.StandardOutput.ReadToEndAsync();\r\n\t\t\tvar errTask = proc.StandardError.ReadToEndAsync();\r\n\t\t\tproc.WaitForExit();\r\n\t\t\t\r\n\t\t\tstring output = outTask.GetAwaiter().GetResult();\r\n\t\t\tstring error = errTask.GetAwaiter().GetResult();\r\n\t\t\treturn (proc.ExitCode == 0, output.Trim(), error.Trim());\r\n\t\t}\r\n\t\tcatch ( Exception e ) { return (false, \u0022\u0022, e.Message); }\r\n\t}\r\n\r\n\tprivate static string QuoteArg( string input )\r\n\t{\r\n\t\tif ( input == null ) return \u0022\\\u0022\\\u0022\u0022;\r\n\t\treturn $\u0022\\\u0022{input.Replace( \u0022\\\\\u0022, \u0022\\\\\\\\\u0022 ).Replace( \u0022\\\u0022\u0022, \u0022\\\\\\\u0022\u0022 )}\\\u0022\u0022;\r\n\t}\r\n\r\n\tprivate string GetCommitWebUrl( string hash )\r\n\t{\r\n\t\tvar url = _gitRemoteUrl?.Value?.Trim();\r\n\t\tif ( string.IsNullOrWhiteSpace( url ) ) return null;\r\n\t\tif ( url.EndsWith( \u0022.git\u0022 ) ) url = url.Substring( 0, url.Length - 4 );\r\n\t\treturn $\u0022{url}/commit/{hash}\u0022;\r\n\t}\r\n}"},{"Ident":"isotope.gitversioncontrol","Path":"Editor/VersionCont.Diff.cs","FileName":"VersionCont.Diff.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":306347,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing Sandbox.UI;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Threading.Tasks;\r\nusing Checkbox = Editor.Checkbox;\r\nusing Label = Editor.Label;\r\n\r\npublic partial class LocalControlWidget\r\n{\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// A visual diff comparison window showing changes between file revisions.\r\n\t/// Features include synchronized scrolling, line-level character highlighting, and optional word wrapping.\r\n\t/// \u003C/summary\u003E\r\n\tpublic class DiffWindow : Window\r\n\t{\r\n\t\tprivate string _oldContent;\r\n\t\tprivate string _newContent;\r\n\t\tprivate string _fileName;\r\n\r\n\t\tprivate Widget _contentArea;\r\n\t\tprivate ScrollArea _leftScroll;\r\n\t\tprivate ScrollArea _rightScroll;\r\n\t\tprivate Checkbox _syncCb;\r\n\r\n\t\tprivate bool _syncScrolling = true;\r\n\t\tprivate bool _lineLeveling = true;\r\n\t\tprivate bool _wordWrap = false;\r\n\r\n\t\tprivate float _lastVerticalScroll = -1;\r\n\r\n\t\tpublic DiffWindow( string fileName, string oldContent, string newContent )\r\n\t\t{\r\n\t\t\t_fileName = fileName;\r\n\t\t\t_oldContent = oldContent ?? \u0022[No previous version]\u0022;\r\n\t\t\t_newContent = newContent ?? \u0022[No current version]\u0022;\r\n\r\n\t\t\tstring escapedFileName = System.Security.SecurityElement.Escape( fileName );\r\n\t\t\tWindowTitle = $\u0022Diff: {escapedFileName}\u0022;\r\n\t\t\tSize = new Vector2( 1300, 850 );\r\n\r\n\t\t\tvar root = new Widget( null );\r\n\t\t\troot.Layout = Layout.Column();\r\n\t\t\troot.Layout.Margin = 10;\r\n\t\t\troot.Layout.Spacing = 0;\r\n\r\n\t\t\tBuildToolbar( root );\r\n\r\n\t\t\t_contentArea = new Widget( root );\r\n\t\t\t_contentArea.Layout = Layout.Column();\r\n\t\t\troot.Layout.Add( _contentArea, 1 );\r\n\r\n\t\t\tRefreshDiffView();\r\n\t\t\tCanvas = root;\r\n\t\t}\r\n\r\n\t\tprivate void BuildToolbar( Widget parent )\r\n\t\t{\r\n\t\t\tvar toolbar = parent.Layout.AddRow();\r\n\t\t\ttoolbar.Spacing = 20;\r\n\t\t\ttoolbar.Margin = new Margin( 0, 0, 0, 12 );\r\n\r\n\t\t\tvar syncGroup = toolbar.AddRow();\r\n\t\t\tsyncGroup.Spacing = 5;\r\n\t\t\t_syncCb = new Checkbox( parent );\r\n\t\t\t_syncCb.Value = _syncScrolling;\r\n\t\t\t_syncCb.Toggled \u002B= () =\u003E { _syncScrolling = _syncCb.Value; };\r\n\t\t\tsyncGroup.Add( _syncCb );\r\n\t\t\tsyncGroup.Add( new Label( \u0022Sync Scroll\u0022, parent ) );\r\n\r\n\t\t\tvar levelGroup = toolbar.AddRow();\r\n\t\t\tlevelGroup.Spacing = 5;\r\n\t\t\tvar levelCb = new Checkbox( parent );\r\n\t\t\tlevelCb.Value = _lineLeveling;\r\n\t\t\tlevelCb.Toggled \u002B= () =\u003E { _lineLeveling = levelCb.Value; RefreshDiffView(); };\r\n\t\t\tlevelGroup.Add( levelCb );\r\n\t\t\tlevelGroup.Add( new Label( \u0022Align Lines\u0022, parent ) );\r\n\r\n\t\t\tvar wrapGroup = toolbar.AddRow();\r\n\t\t\twrapGroup.Spacing = 5;\r\n\t\t\tvar wrapCb = new Checkbox( parent );\r\n\t\t\twrapCb.Value = _wordWrap;\r\n\t\t\twrapCb.Toggled \u002B= () =\u003E { _wordWrap = wrapCb.Value; RefreshDiffView(); };\r\n\t\t\twrapGroup.Add( wrapCb );\r\n\t\t\twrapGroup.Add( new Label( \u0022Word Wrap\u0022, parent ) );\r\n\r\n\t\t\ttoolbar.AddStretchCell();\r\n\t\t}\r\n\r\n\t\tprivate async void RefreshDiffView()\r\n\t\t{\r\n\t\t\ttry\r\n\t\t\t{\r\n\t\t\t\t_contentArea.DestroyChildren();\r\n\t\t\t\t_lastVerticalScroll = -1;\r\n\r\n\t\t\t\tvar header = _contentArea.Layout.AddRow();\r\n\t\t\t\theader.Margin = new Margin(0, 0, 0, 4);\r\n\t\t\t\theader.Add(\r\n\t\t\t\t\tnew Label(\u0022\u003Cb\u003E\u003Cfont color=\u0027#ff7777\u0027\u003E  - PREVIOUS SNAPSHOT\u003C/font\u003E\u003C/b\u003E\u0022),\r\n\t\t\t\t\t1\r\n\t\t\t\t);\r\n\t\t\t\theader.Add(new Label(\u0022\u003Cb\u003E\u003Cfont color=\u0027#77ff77\u0027\u003E  \u002B CURRENT VERSION\u003C/font\u003E\u003C/b\u003E\u0022), 1);\r\n\r\n\t\t\t\tvar loadingLabel = new Label(\u0022\u003Ci\u003EComputing diff, please wait...\u003C/i\u003E\u0022);\r\n\t\t\t\t_contentArea.Layout.Add(loadingLabel);\r\n\r\n\t\t\t\tvar compareRow = _contentArea.Layout.AddRow();\r\n\t\t\t\tcompareRow.Spacing = 10;\r\n\r\n\t\t\t\tvar (oldHtml, newHtml) = await Task.Run(() =\u003E\r\n\t\t\t\t\tGenerateSplitDiffHtml(_oldContent, _newContent)\r\n\t\t\t\t);\r\n\r\n\t\t\t\tloadingLabel.Destroy();\r\n\r\n\t\t\t\t_leftScroll = CreateDiffSide(_contentArea, oldHtml);\r\n\t\t\t\t_rightScroll = CreateDiffSide(_contentArea, newHtml);\r\n\r\n\t\t\t\tcompareRow.Add(_leftScroll, 1);\r\n\t\t\t\tcompareRow.Add(_rightScroll, 1);\r\n\t\t\t}\r\n\t\t\tcatch (Exception e)\r\n\t\t\t{\r\n\t\t\t\tLog.Error($\u0022Failed to refresh diff view: {e.Message}\u0022);\r\n\t\t\t\tvar errorLabel = new Label($\u0022Error generating diff: {e.Message}\u0022);\r\n\t\t\t\t_contentArea.Layout.Add(errorLabel);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate ScrollArea CreateDiffSide( Widget parent, string html )\r\n\t\t{\r\n\t\t\tvar scroll = new ScrollArea( parent );\r\n\t\t\tvar container = new Widget( scroll );\r\n\t\t\tcontainer.Layout = Layout.Column();\r\n\t\t\tvar label = new Label( html, container );\r\n\t\t\tlabel.WordWrap = _wordWrap;\r\n\t\t\tcontainer.Layout.Add( label );\r\n\t\t\tcontainer.Layout.AddStretchCell();\r\n\t\t\tscroll.Canvas = container;\r\n\t\t\treturn scroll;\r\n\t\t}\r\n\r\n\t\t[EditorEvent.Frame]\r\n\t\tpublic void OnFrame()\r\n\t\t{\r\n\t\t\tif ( !_syncScrolling || _leftScroll == null || _rightScroll == null ) return;\r\n\r\n\t\t\tint leftV = _leftScroll.VerticalScrollbar.Value;\r\n\t\t\tint rightV = _rightScroll.VerticalScrollbar.Value;\r\n\r\n\t\t\tif ( leftV != _lastVerticalScroll )\r\n\t\t\t{\r\n\t\t\t\t_rightScroll.VerticalScrollbar.Value = leftV;\r\n\t\t\t\t_lastVerticalScroll = leftV;\r\n\t\t\t}\r\n\t\t\telse if ( rightV != _lastVerticalScroll )\r\n\t\t\t{\r\n\t\t\t\t_leftScroll.VerticalScrollbar.Value = rightV;\r\n\t\t\t\t_lastVerticalScroll = rightV;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate (string oldHtml, string newHtml) GenerateSplitDiffHtml( string oldText, string newText )\r\n{\r\n\tvar oldLines = oldText.Split( new[] { \u0022\\r\\n\u0022, \u0022\\r\u0022, \u0022\\n\u0022 }, StringSplitOptions.None );\r\n\tvar newLines = newText.Split( new[] { \u0022\\r\\n\u0022, \u0022\\r\u0022, \u0022\\n\u0022 }, StringSplitOptions.None );\r\n\tvar diffs = ComputeLineDiff( oldLines, newLines );\r\n\r\n\tstring wrapStyle = _wordWrap ? \u0022white-space: pre-wrap; word-break: break-all;\u0022 : \u0022white-space: pre;\u0022;\r\n\tstring tableBase = $\u0022\u003Ctable border=\u00270\u0027 cellspacing=\u00270\u0027 cellpadding=\u00270\u0027 style=\u0027font-family: Consolas, monospace; font-size: 12px; width: 100%; {wrapStyle} line-height: 1.4;\u0027\u003E\u0022;\r\n\r\n\tvar oldRes = new System.Text.StringBuilder( tableBase );\r\n\tvar newRes = new System.Text.StringBuilder( tableBase );\r\n\tint oPtr = 1; int nPtr = 1;\r\n\r\n\tstring gutter = \u0022background-color: #1d1d1d; color: #555; width: 40px; text-align: right; padding-right: 8px; border-right: 1px solid #333;\u0022;\r\n\tstring content = \u0022padding-left: 8px;\u0022;\r\n\tstring spacerRow = $\u0022\u003Ctr\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E\u0026nbsp;\u003C/td\u003E\u003Ctd style=\u0027background-color: #1a1a1a; {content}\u0027\u003E\u0026nbsp;\u003C/td\u003E\u003C/tr\u003E\u0022;\r\n\r\n\tfor ( int i = 0; i \u003C diffs.Count; i\u002B\u002B )\r\n\t{\r\n\t\tvar d = diffs[i];\r\n\r\n\t\tif ( _lineLeveling \u0026\u0026 d.Type == DiffType.Delete \u0026\u0026 i \u002B 1 \u003C diffs.Count \u0026\u0026 diffs[i \u002B 1].Type == DiffType.Add )\r\n\t\t{\r\n\t\t\tvar next = diffs[i \u002B 1];\r\n\t\t\tvar (hOld, hNew) = DiffCharacters( d.Text, next.Text );\r\n\t\t\toldRes.Append( $\u0022\u003Ctr style=\u0027background-color: #321e1e;\u0027\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E{oPtr\u002B\u002B}\u003C/td\u003E\u003Ctd style=\u0027{content}\u0027\u003E{hOld}\u003C/td\u003E\u003C/tr\u003E\u0022 );\r\n\t\t\tnewRes.Append( $\u0022\u003Ctr style=\u0027background-color: #12261e;\u0027\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E{nPtr\u002B\u002B}\u003C/td\u003E\u003Ctd style=\u0027{content}\u0027\u003E{hNew}\u003C/td\u003E\u003C/tr\u003E\u0022 );\r\n\t\t\ti\u002B\u002B;\r\n\t\t\tcontinue;\r\n\t\t}\r\n\r\n\t\tstring esc = System.Security.SecurityElement.Escape( d.Text );\r\n\t\tif ( d.Type == DiffType.Match )\r\n\t\t{\r\n\t\t\toldRes.Append( $\u0022\u003Ctr\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E{oPtr\u002B\u002B}\u003C/td\u003E\u003Ctd style=\u0027{content}\u0027\u003E{esc}\u003C/td\u003E\u003C/tr\u003E\u0022 );\r\n\t\t\tnewRes.Append( $\u0022\u003Ctr\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E{nPtr\u002B\u002B}\u003C/td\u003E\u003Ctd style=\u0027{content}\u0027\u003E{esc}\u003C/td\u003E\u003C/tr\u003E\u0022 );\r\n\t\t}\r\n\t\telse if ( d.Type == DiffType.Add )\r\n\t\t{\r\n\t\t\tif ( _lineLeveling ) oldRes.Append( spacerRow );\r\n\t\t\tnewRes.Append( $\u0022\u003Ctr style=\u0027background-color: #12261e;\u0027\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E{nPtr\u002B\u002B}\u003C/td\u003E\u003Ctd style=\u0027{content}\u0027\u003E{esc}\u003C/td\u003E\u003C/tr\u003E\u0022 );\r\n\t\t}\r\n\t\telse if ( d.Type == DiffType.Delete )\r\n\t\t{\r\n\t\t\toldRes.Append( $\u0022\u003Ctr style=\u0027background-color: #321e1e;\u0027\u003E\u003Ctd style=\u0027{gutter}\u0027\u003E{oPtr\u002B\u002B}\u003C/td\u003E\u003Ctd style=\u0027{content}\u0027\u003E{esc}\u003C/td\u003E\u003C/tr\u003E\u0022 );\r\n\t\t\tif ( _lineLeveling ) newRes.Append( spacerRow );\r\n\t\t}\r\n\t}\r\n\t\r\n\toldRes.Append( \u0022\u003C/table\u003E\u0022 );\r\n\tnewRes.Append( \u0022\u003C/table\u003E\u0022 );\r\n\t\r\n\treturn (oldRes.ToString(), newRes.ToString());\r\n}\r\n\r\n\t\tprivate enum DiffType { Match, Add, Delete }\r\n\t\tprivate struct LineDiff { public DiffType Type; public string Text; }\r\n\r\n\t\tprivate List\u003CLineDiff\u003E ComputeLineDiff( string[] oldLines, string[] newLines )\r\n\t\t{\r\n\t\t\tint n = oldLines.Length, m = newLines.Length;\r\n\t\t\tint[,] lp = new int[n \u002B 1, m \u002B 1];\r\n\t\t\tfor ( int i = 1; i \u003C= n; i\u002B\u002B )\r\n\t\t\t\tfor ( int j = 1; j \u003C= m; j\u002B\u002B )\r\n\t\t\t\t\tlp[i, j] = (oldLines[i - 1] == newLines[j - 1]) ? lp[i - 1, j - 1] \u002B 1 : Math.Max( lp[i - 1, j], lp[i, j - 1] );\r\n\r\n\t\t\tvar res = new List\u003CLineDiff\u003E();\r\n\t\t\tint x = n, y = m;\r\n\t\t\twhile ( x \u003E 0 || y \u003E 0 )\r\n\t\t\t{\r\n\t\t\t\tif ( x \u003E 0 \u0026\u0026 y \u003E 0 \u0026\u0026 oldLines[x - 1] == newLines[y - 1] )\r\n\t\t\t\t{\r\n\t\t\t\t\tres.Add( new LineDiff { Type = DiffType.Match, Text = oldLines[x - 1] } );\r\n\t\t\t\t\tx--; y--;\r\n\t\t\t\t}\r\n\t\t\t\telse if ( y \u003E 0 \u0026\u0026 (x == 0 || lp[x, y - 1] \u003E= lp[x - 1, y]) )\r\n\t\t\t\t{\r\n\t\t\t\t\tres.Add( new LineDiff { Type = DiffType.Add, Text = newLines[y - 1] } );\r\n\t\t\t\t\ty--;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\tres.Add( new LineDiff { Type = DiffType.Delete, Text = oldLines[x - 1] } );\r\n\t\t\t\t\tx--;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\tres.Reverse();\r\n\t\t\treturn res;\r\n\t\t}\r\n\r\n\t\tprivate (string oldOut, string newOut) DiffCharacters( string oldLine, string newLine )\r\n\t\t{\r\n\t\t\tint start = 0;\r\n\t\t\twhile ( start \u003C oldLine.Length \u0026\u0026 start \u003C newLine.Length \u0026\u0026 oldLine[start] == newLine[start] ) start\u002B\u002B;\r\n\t\t\tint oEnd = oldLine.Length - 1, nEnd = newLine.Length - 1;\r\n\t\t\twhile ( oEnd \u003E= start \u0026\u0026 nEnd \u003E= start \u0026\u0026 oldLine[oEnd] == newLine[nEnd] ) { oEnd--; nEnd--; }\r\n\t\t\tstring sOld = System.Security.SecurityElement.Escape( oldLine.Substring( 0, start ) );\r\n\t\t\tstring mOld = $\u0022\u003Cspan style=\u0027background-color: #792e2d; color: white;\u0027\u003E{System.Security.SecurityElement.Escape( oldLine.Substring( start, Math.Max( 0, oEnd - start \u002B 1 ) ) )}\u003C/span\u003E\u0022;\r\n\t\t\tstring eOld = System.Security.SecurityElement.Escape( oldLine.Substring( oEnd \u002B 1 ) );\r\n\t\t\tstring sNew = System.Security.SecurityElement.Escape( newLine.Substring( 0, start ) );\r\n\t\t\tstring mNew = $\u0022\u003Cspan style=\u0027background-color: #1d572d; color: white;\u0027\u003E{System.Security.SecurityElement.Escape( newLine.Substring( start, Math.Max( 0, nEnd - start \u002B 1 ) ) )}\u003C/span\u003E\u0022;\r\n\t\t\tstring eNew = System.Security.SecurityElement.Escape( newLine.Substring( nEnd \u002B 1 ) );\r\n\t\t\treturn (sOld \u002B mOld \u002B eOld, sNew \u002B mNew \u002B eNew);\r\n\t\t}\r\n\t}\r\n\r\n\tpublic class ClickableLabel : Label\r\n\t{\r\n\t\tpublic Action DoubleClicked { get; set; }\r\n\t\tpublic Action\u003CVector2\u003E RightClicked { get; set; }\r\n\t\tpublic ClickableLabel( string text, Widget parent ) : base( text, parent ) { }\r\n\t\tprotected override void OnDoubleClick( MouseEvent e ) { base.OnDoubleClick( e ); DoubleClicked?.Invoke(); }\r\n\t\tprotected override void OnContextMenu( ContextMenuEvent e ) { base.OnContextMenu( e ); RightClicked?.Invoke( e.ScreenPosition ); e.Accepted = true; }\r\n\t}\r\n\r\n\tprivate void ShowOperationNotification( string title, string subtitle, string icon, Color borderColor, float seconds = 2.5f )\r\n\t{\r\n\t\tvar toast = new OperationToast { Title = title, Subtitle = subtitle, Icon = icon, BorderColor = borderColor, DrawTimer = false, IsRunning = false, FixedWidth = 320, FixedHeight = 72 };\r\n\t\tToastManager.Remove( toast, seconds );\r\n\t}\r\n\r\n\tprivate class OperationToast : ToastWidget\r\n\t{\r\n\t\tpublic override bool WantsVisible =\u003E EditorPreferences.NotificationPopups;\r\n\t\tprotected override void OnPaint() { if ( !EditorPreferences.NotificationPopups ) return; base.OnPaint(); }\r\n\t}\r\n}\r\n"}]}