Skip to content

Commit de60a20

Browse files
committed
variables: add button to send clipboard list to L1. Fix #536
1 parent a009b0d commit de60a20

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

gui/qt/debugger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ void MainWindow::debugGuiState(bool state) const {
635635

636636
ui->buttonSend->setEnabled(!state);
637637
ui->buttonResendFiles->setEnabled(!state);
638+
ui->buttonClipboardListToL1->setEnabled(!state);
638639

639640
QList<QDockWidget*> docks = findChildren<QDockWidget*>();
640641
foreach (QDockWidget* dock, docks) {

gui/qt/mainwindow.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "capture/animated-png.h"
99
#include "keypad/qtkeypadbridge.h"
1010
#include "tivars_lib_cpp/src/TIModels.h"
11+
#include "tivars_lib_cpp/src/TIVarFile.h"
1112
#include "tivars_lib_cpp/src/TIVarTypes.h"
1213
#include "tivars_lib_cpp/src/TypeHandlers/TypeHandlers.h"
1314
#include "../../core/emu.h"
@@ -24,6 +25,7 @@
2425
#include <QtCore/QLocale>
2526
#include <QtCore/QProcess>
2627
#include <QtCore/QRegularExpression>
28+
#include <QtCore/QTemporaryFile>
2729
#include <QtGui/QFont>
2830
#include <QtGui/QWindow>
2931
#include <QtGui/QDesktopServices>
@@ -264,6 +266,7 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U
264266
connect(ui->buttonReceiveFile, &QPushButton::clicked, this, &MainWindow::varSaveSelected);
265267
connect(ui->buttonReceiveFiles, &QPushButton::clicked, this, &MainWindow::varSaveSelectedFiles);
266268
connect(ui->buttonResendFiles, &QPushButton::clicked, this, &MainWindow::varResend);
269+
connect(ui->buttonClipboardListToL1, &QPushButton::clicked, this, &MainWindow::varClipboardListToL1);
267270

268271
// autotester
269272
connect(ui->buttonOpenJSONconfig, &QPushButton::clicked, this, &MainWindow::autotesterLoad);
@@ -528,14 +531,17 @@ MainWindow::MainWindow(CEmuOpts &cliOpts, QWidget *p) : QMainWindow(p), ui(new U
528531
m_shortcutFullscreen = new QShortcut(QKeySequence(Qt::Key_F11), this);
529532
m_shortcutAsm = new QShortcut(QKeySequence(Qt::Key_Pause), this);
530533
m_shortcutResend = new QShortcut(QKeySequence(Qt::CTRL | Qt::Key_X), this);
534+
m_shortcutClipboardListToL1 = new QShortcut(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_L), this);
531535

532536
m_shortcutFullscreen->setAutoRepeat(false);
533537
m_shortcutDebug->setAutoRepeat(false);
534538
m_shortcutAsm->setAutoRepeat(false);
535539
m_shortcutResend->setAutoRepeat(false);
540+
m_shortcutClipboardListToL1->setAutoRepeat(false);
536541

537542
connect(m_shortcutFullscreen, &QShortcut::activated, [this]{ setFullscreen(m_fullscreen + 1); });
538543
connect(m_shortcutResend, &QShortcut::activated, this, &MainWindow::varResend);
544+
connect(m_shortcutClipboardListToL1, &QShortcut::activated, this, &MainWindow::varClipboardListToL1);
539545
connect(m_shortcutAsm, &QShortcut::activated, [this]{ sendEmuKey(CE_KEY_ASM); });
540546
connect(m_shortcutDebug, &QShortcut::activated, this, &MainWindow::debugToggle);
541547
connect(m_shortcutStepIn, &QShortcut::activated, this, &MainWindow::stepIn);
@@ -2338,6 +2344,46 @@ void MainWindow::varResend() {
23382344
sendingHandler->resendSelected();
23392345
}
23402346

2347+
void MainWindow::varClipboardListToL1() {
2348+
const QString cbStr = qApp->clipboard()->text().replace(" ", "").trimmed();
2349+
if (cbStr.isEmpty()) {
2350+
QMessageBox::warning(this, MSG_WARNING, tr("Empty clipboard"));
2351+
return;
2352+
}
2353+
2354+
QTemporaryFile tempFile{"CEmu_temp_list_XXXXXX.8xl"};
2355+
if (!tempFile.open()) {
2356+
QMessageBox::warning(this, MSG_ERROR, tr("Could not create temporary file"));
2357+
return;
2358+
}
2359+
2360+
ui->buttonClipboardListToL1->setEnabled(false);
2361+
2362+
const QString tempFilePath = tempFile.fileName();
2363+
bool ok = false;
2364+
2365+
try
2366+
{
2367+
tivars::TIVarFile testRealList = tivars::TIVarFile::createNew("RealList", "\x5D\x00"); // L₁
2368+
testRealList.setContentFromString(cbStr.toStdString());
2369+
testRealList.saveVarToFile(tempFilePath.toStdString());
2370+
ok = true;
2371+
} catch (const std::exception &e)
2372+
{
2373+
QMessageBox::warning(this, MSG_ERROR, tr("Could not convert the clipboard's list: ") + e.what());
2374+
}
2375+
2376+
if (ok)
2377+
{
2378+
sendingHandler->sendFiles({ tempFilePath }, LINK_RAM);
2379+
while (guiSend) {
2380+
guiDelay(10);
2381+
}
2382+
}
2383+
2384+
ui->buttonClipboardListToL1->setEnabled(true);
2385+
}
2386+
23412387
// ------------------------------------------------
23422388
// Autotester things
23432389
// ------------------------------------------------

gui/qt/mainwindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ private slots:
528528
void varSaveSelected();
529529
void varSaveSelectedFiles();
530530
static void varResend();
531+
void varClipboardListToL1();
531532
void varToggle();
532533

533534
// recent
@@ -712,6 +713,7 @@ private slots:
712713
QShortcut *m_shortcutFullscreen;
713714
QShortcut *m_shortcutAsm;
714715
QShortcut *m_shortcutResend;
716+
QShortcut *m_shortcutClipboardListToL1;
715717

716718
QAction *m_actionToggleUI;
717719
QAction *m_actionAddMemory;

gui/qt/mainwindow.ui

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7264,6 +7264,23 @@
72647264
</property>
72657265
</spacer>
72667266
</item>
7267+
<item>
7268+
<widget class="QPushButton" name="buttonClipboardListToL1">
7269+
<property name="sizePolicy">
7270+
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
7271+
<horstretch>0</horstretch>
7272+
<verstretch>0</verstretch>
7273+
</sizepolicy>
7274+
</property>
7275+
<property name="text">
7276+
<string>Send clipboard list to L₁</string>
7277+
</property>
7278+
<property name="icon">
7279+
<iconset resource="resources.qrc">
7280+
<normaloff>:/icons/resources/icons/variables.png</normaloff>:/icons/resources/icons/variables.png</iconset>
7281+
</property>
7282+
</widget>
7283+
</item>
72677284
<item>
72687285
<layout class="QHBoxLayout" name="horizontalLayout_29">
72697286
<property name="rightMargin">

0 commit comments

Comments
 (0)