From 605cdcb5d57137d79f116c4f778522b03b98d9ed Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Wed, 13 Mar 2024 09:35:16 -0700 Subject: [PATCH] Adding a copy button to the source view. --- manual/tracy.tex | 2 +- server/TracySourceContents.cpp | 1 + server/TracySourceContents.hpp | 2 ++ server/TracySourceView.cpp | 12 ++++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/manual/tracy.tex b/manual/tracy.tex index 13d1fbf9..43904f10 100644 --- a/manual/tracy.tex +++ b/manual/tracy.tex @@ -3681,7 +3681,7 @@ This window can operate in one of the two modes. The first one is quite simple, \subsubsection{Source file view} -In source view mode, you can view the source code of the profiled application to take a quick glance at the context of the function behavior you are analyzing. The profiler will highlight the selected line (for example, a location of a profiling zone) both in the source code listing and on the scroll bar. +In source view mode, you can view the source code of the profiled application to take a quick glance at the context of the function behavior you are analyzing. The profiler will highlight the selected line (for example, a location of a profiling zone) both in the source code listing and on the scroll bar. The contents of the file displayed in the source view can be copied to the clipboard using the button adjacent to the file name. \begin{bclogo}[ noborder=true, diff --git a/server/TracySourceContents.cpp b/server/TracySourceContents.cpp index 8ab92f77..9abd7fb4 100644 --- a/server/TracySourceContents.cpp +++ b/server/TracySourceContents.cpp @@ -33,6 +33,7 @@ void SourceContents::Parse( const char* fileName, const Worker& worker, const Vi if( srcCache.data != nullptr ) { m_data = srcCache.data; + m_dataSize = srcCache.len; sz = srcCache.len; } else diff --git a/server/TracySourceContents.hpp b/server/TracySourceContents.hpp index e0b668fe..4e0d8333 100644 --- a/server/TracySourceContents.hpp +++ b/server/TracySourceContents.hpp @@ -27,6 +27,8 @@ public: const char* filename() const { return m_file; } uint32_t idx() const { return m_fileStringIdx; } bool is_cached() const { return m_data != m_dataBuf; } + const char* data() const { return m_data; } + size_t data_size() const { return m_dataSize; } private: const char* m_file; diff --git a/server/TracySourceView.cpp b/server/TracySourceView.cpp index 53168f14..f13943b4 100644 --- a/server/TracySourceView.cpp +++ b/server/TracySourceView.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -1058,6 +1059,17 @@ void SourceView::Render( Worker& worker, View& view ) if( m_symAddr == 0 ) { + ImGui::PushFont( m_bigFont ); + if( ClipboardButton() ) + { + std::ostringstream stream; + stream.write( m_source.data(), m_source.data_size() ); + ImGui::SetClipboardText( stream.str().c_str() ); + } + ImGui::PopFont(); + ImGui::SameLine(); + ImGui::Spacing(); + ImGui::SameLine(); if( m_source.filename() ) { ImGui::PushFont( m_bigFont );