Skip to content

Commit

Permalink
Add ability to copy peak CSV to pasteboard.
Browse files Browse the repository at this point in the history
On user request, added capability to copy peak CSV to pasteboard, rather than having to download the CSV file.
Seems to work, but actually the data is copied to the clipboard as plain text and HTML, instead of CSV, because apparently that (and png) are the only types browsers will let you copy to the pasteboard in JS.
  • Loading branch information
wcjohns committed Sep 13, 2024
1 parent 3a188b1 commit 6f258bb
Show file tree
Hide file tree
Showing 13 changed files with 508 additions and 101 deletions.
6 changes: 6 additions & 0 deletions InterSpec/PeakInfoDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ class PeakInfoDisplay : public Wt::WContainerWidget
void removeAllPeaks();
void assignNuclidesFromRefLines();

/** Copies the current peak CSV data to `$(this).data({'CsvFullData', 'CsvNoHeaderData', 'CsvCompactData'})`
Called menu copy button is clicked, and copy options menu shown.
*/
void copyCsvPeakDataToClient();
/** Removes the data from the JS; called when copy menu is hidden. */
void removeCsvPeakDatafromClient();

protected:
PeakModel *m_model;
Expand Down
13 changes: 13 additions & 0 deletions InterSpec/PeakModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class PeakModel: public Wt::WAbstractItemModel

std::shared_ptr<const std::deque< PeakModel::PeakShrdPtr > > peaks() const;
std::vector<PeakDef> peakVec() const;

const std::deque<std::shared_ptr<const PeakDef>> &sortedPeaks() const;

//definePeakXRangeAndChi2(...): Inorder to save cpu (and mostly memorry access
// time) later on, this function will define the lower and upper energy range
Expand Down Expand Up @@ -379,10 +381,21 @@ class PeakModel: public Wt::WAbstractItemModel
static std::vector<PeakDef> gadras_peak_csv_to_peaks( std::shared_ptr<const SpecUtils::Measurement> meas,
std::istream &csv );

enum class PeakCsvType
{
Full,
NoHeader,
Compact,
FullHtml,
NoHeaderHtml,
CompactHtml
};

/** Writes the peaks to a CSV file output - e.g., what the user gets when they click on the CSV download on the "Peak Manager" tab.
*/
static void write_peak_csv( std::ostream &outstrm,
std::string specfilename,
const PeakCsvType type,
const std::deque<std::shared_ptr<const PeakDef>> &peaks,
const std::shared_ptr<const SpecUtils::Measurement> &data );

Expand Down
63 changes: 35 additions & 28 deletions InterSpec_resources/InterSpec.css
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,6 @@ width:100%;
}



.Wt-btn .with-label {
font-size: 0.9em;
font-weight: bold;
vertical-align: middle;
border: 1px solid #e1e1e1;
color: #FFFFFF;
background-color: #888888;
border-radius: 5px;
height: 23px;
white-space: nowrap;
}


/* A lighter-appearing button, with no background color, and text matching border.
We will also allow applying this style to WSplitButton
*/
Expand Down Expand Up @@ -645,37 +631,56 @@ ul.Wt-popupmenu > li > a > span > span:hover
}


.PeakInfoDisplayButtonDiv {
.PeakInfoDisplayBottomDiv {
padding-left: 3px;
display: flex;
align-items: center;
}

.PeakInfoDisplayButtonDiv > .LinkBtn.DownloadBtn.Wt-btn.with-label
{
margin-left: auto;
.PeakInfoDisplayBottomDiv button, .PeakInfoDisplayBottomDiv button:hover {
display: flex;
align-items: center;
}

/* Shrink the button sizes a little bit for narrower display */
@media (max-width: 800px) {
.PeakInfoDisplayBottomDiv button, .PeakInfoDisplayBottomDiv button:hover {
font-size: 0.8em;
font-weight: normal;
}

.PeakInfoDisplayBottomDiv .Wt-btn.with-label img{
padding-right: 3px;
}
}


.PeakInfoHlpBtn {
margin-right: 5px;
position: absolute;
left: 1px;
bottom: 0px;
}

.PeakSearchBtn {
.PeakInfoDisplayButtonsDiv, .PeakInfoDisplayCsvBtns {
margin-left: 25px;
}

.PeakInfoDisplayButtonDiv > button {
margin-right: 5px;
display: flex;
flex-wrap: nowrap;
flex-direction: row;
align-items: center;
justify-content: flex-start;
column-gap: 5px
}

.PeakInfoDisplay .PeakEditHint
{
color: gray;
margin-left: 2em;
font-size:66%
color: gray;
margin-left: 2em;
font-size: 66%;
white-space: nowrap;
overflow: hidden;
flex-grow: 1;
flex-shrink: 1;
}


Expand Down Expand Up @@ -853,8 +858,6 @@ button, button:hover,
border:1px solid #e1e1e1;
color: #FFFFFF;
background-color: #888888;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
height: 23px;
}
Expand All @@ -877,6 +880,10 @@ button[disabled]
filter: grayscale(100%);
}

button, button:hover {
padding-top: 2px;
padding-bottom: 2px;
}

li{ padding-top: 0; }
table { margin-bottom:0; }
Expand Down
2 changes: 1 addition & 1 deletion InterSpec_resources/InterSpecSafeArea.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ ul.PopupDivMenuPhone > li:last-of-type
margin-bottom: calc( max(env(safe-area-inset-bottom) - 8px, 0px) + max(env(safe-area-inset-bottom) - 8px, 0px) );
}

.LandscapeLeft .PeakInfoDisplayButtonDiv, .LandscapeRight .PeakInfoDisplayButtonDiv {
.LandscapeLeft .PeakInfoDisplayBottomDiv, .LandscapeRight .PeakInfoDisplayBottomDiv {
margin-bottom: 2px;
}

Expand Down
1 change: 1 addition & 0 deletions InterSpec_resources/app_text/PeakInfoDisplay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<message id="pid-better-editor-hint">Right click on peaks for better editor</message>
<message id="pid-better-editor-hint-mobile">Tap and hold on peaks for better editor</message>
<message id="pid-tt-csv-export">Export information about the identified peaks to a comma separated format.</message>
<message id="pid-tt-csv-copy">Copy peak CSV information to your pasteboard, in a CSV format.</message>
</messages>
4 changes: 4 additions & 0 deletions InterSpec_resources/images/copy_small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions src/BatchActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,8 @@ void fit_activities_in_files( const std::string &exemplar_filename,
warnings.push_back( "Failed to open '" + outcsv + "', for writing.");
}else
{
PeakModel::write_peak_csv( output_csv, leaf_name, fit_peaks, peak_fit_res.spectrum );
PeakModel::write_peak_csv( output_csv, leaf_name, PeakModel::PeakCsvType::Full,
fit_peaks, peak_fit_res.spectrum );
cout << "Have written '" << outcsv << "'" << endl;
}
}//if( SpecUtils::is_file( outcsv ) ) / else
Expand All @@ -1766,7 +1767,8 @@ void fit_activities_in_files( const std::string &exemplar_filename,
{
const string leaf_name = SpecUtils::filename(filename);
cout << "peaks for '" << leaf_name << "':" << endl;
PeakModel::write_peak_csv( cout, leaf_name, fit_peaks, peak_fit_res.spectrum );
PeakModel::write_peak_csv( cout, leaf_name, PeakModel::PeakCsvType::Full,
fit_peaks, peak_fit_res.spectrum );
cout << endl;
}
}//if( fit_results.m_peak_fit_results )
Expand Down
6 changes: 4 additions & 2 deletions src/BatchPeak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ void fit_peaks_in_files( const std::string &exemplar_filename,
warnings.push_back( "Failed to open '" + outcsv + "', for writing.");
}else
{
PeakModel::write_peak_csv( output_csv, leaf_name, fit_peaks, fit_results.spectrum );
PeakModel::write_peak_csv( output_csv, leaf_name,
PeakModel::PeakCsvType::Full, fit_peaks, fit_results.spectrum );
cout << "Have written '" << outcsv << "'" << endl;
}
}//if( SpecUtils::is_file( outcsv ) ) / else
Expand All @@ -355,7 +356,8 @@ void fit_peaks_in_files( const std::string &exemplar_filename,
{
const string leaf_name = SpecUtils::filename(filename);
cout << "peaks for '" << leaf_name << "':" << endl;
PeakModel::write_peak_csv( cout, leaf_name, fit_peaks, fit_results.spectrum );
PeakModel::write_peak_csv( cout, leaf_name, PeakModel::PeakCsvType::Full,
fit_peaks, fit_results.spectrum );
cout << endl;
}
}//for( const string filename : files )
Expand Down
6 changes: 4 additions & 2 deletions src/FluxTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ extern void android_download_workaround( Wt::WResource *resource, std::string de


#if( FLUX_USE_COPY_TO_CLIPBOARD )

// See also CopyUrlToClipboard in QrCode.cpp
WT_DECLARE_WT_MEMBER
(CopyFluxDataTextToClipboard, Wt::JavaScriptFunction, "CopyFluxDataTextToClipboard",
function( sender, event, id )
Expand Down Expand Up @@ -118,11 +120,11 @@ WT_DECLARE_WT_MEMBER
console.log( 'Will try to copy HTML to copyboard' );

//We failed to copy richtext, lets just copy the HTML as text.
// ToDo: We could probably try the clipboard API to copy formated text
// ToDo: We could probably try the clipboard API to copy formatted text
// See https://developer.mozilla.org/en-US/docs/Web/API/Clipboard

if( window.clipboardData && window.clipboardData.setData ) {
return clipboardData.setData("Text", text); // IE
return window.clipboardData.setData("Text", text); // IE
}else if( document.queryCommandSupported && document.queryCommandSupported("copy") ) {
var temparea = document.createElement("textarea");
temparea.textContent = text;
Expand Down
21 changes: 21 additions & 0 deletions src/InterSpecApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,27 @@ void InterSpecApp::miscSignalHandler( const std::string &signal )
}//if( SpecUtils::istarts_with( signal, "showMultimedia" ) )


if( SpecUtils::istarts_with( signal, "peakCsvCopy-" ) )
{
string msg = signal.substr(12);
WarningWidget::WarningMsgLevel level = WarningWidget::WarningMsgLevel::WarningMsgInfo;

if( SpecUtils::istarts_with( msg, "success-" ) )
{
msg = msg.substr(8);
level = WarningWidget::WarningMsgLevel::WarningMsgInfo;
}else if( SpecUtils::istarts_with( msg, "error-" ) )
{
msg = msg.substr(6);
level = WarningWidget::WarningMsgLevel::WarningMsgHigh;
}

passMessage( msg, level );
return;
}//if( SpecUtils::istarts_with( signal, "showMultimedia" ) )



// shouldnt ever make it here..
const string errmsg = "InterSpecApp::miscSignalHandler: unhandled signal '" + signal + "'";
passMessage( errmsg, WarningWidget::WarningMsgHigh );
Expand Down
Loading

0 comments on commit 6f258bb

Please sign in to comment.