Skip to content

Commit c6ad95d

Browse files
committed
1.1.2
1 parent a0cbbbb commit c6ad95d

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed
112 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

src/Sample/editdialog.cpp

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,15 @@ EditDialog::EditDialog(MainWindow *mainWindow, QWidget *parent)
4646
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
4747
connect(buttonBox, &QDialogButtonBox::accepted, this, [&]() {
4848
if (promptTextEdit->document()->isModified()) { // If there are changes in the text
49-
50-
QMessageBox::StandardButton reply = QMessageBox::question(this, "Save changes?", "Do you want to save the changes to a new text file?",
51-
QMessageBox::Yes | QMessageBox::No);
52-
if (reply == QMessageBox::Yes) { // If the user wants to save the changes
53-
// Save the text to a new file
54-
QString modelPath = m_mainWindow->getModelPath();
55-
QString fileName = QFileDialog::getSaveFileName(this, "Save Text File", modelPath, "Text files (*.txt)");
56-
if (!fileName.isEmpty()) { // If the user has selected a valid file name
57-
QFile file(fileName);
58-
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
59-
QTextStream stream(&file);
60-
stream << promptTextEdit->toPlainText();
61-
file.close();
62-
}
63-
}
64-
}
49+
saveNewPrompts();
50+
// promptComboBox->clear();
51+
// populateComboBox();
6552
}
6653

6754
// Send the updated prompt to mainwindow.
55+
promptIndex = promptComboBox->currentIndex();
6856
emit sendPrompt(promptTextEdit->toPlainText());
69-
promptComboBox->clear();
70-
populateComboBox();
57+
7158

7259
this->accept(); // Accept the dialog
7360
});
@@ -103,6 +90,49 @@ EditDialog::EditDialog(MainWindow *mainWindow, QWidget *parent)
10390
modelComboBox->setCurrentIndex(0);
10491
}
10592

93+
void EditDialog::saveNewPrompts(){
94+
QMessageBox::StandardButton reply = QMessageBox::question(this, "Save changes?", "Do you want to save the changes to a new text file?",
95+
QMessageBox::Yes | QMessageBox::No);
96+
if (reply == QMessageBox::Yes) { // If the user wants to save the changes
97+
// Save the text to a new file
98+
QString modelPath = m_mainWindow->getModelPath();
99+
QString fullPath = QFileDialog::getSaveFileName(this, "Save Text File", modelPath, "Text files (*.txt)");
100+
if (!fullPath.isEmpty()) { // If the user has selected a valid file name
101+
QFile file(fullPath);
102+
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
103+
QTextStream stream(&file);
104+
stream << promptTextEdit->toPlainText();
105+
file.close();
106+
107+
// Add a new item to the end of the combobox
108+
QFileInfo fileInfo(fullPath);
109+
QString fileName = fileInfo.fileName();
110+
111+
int samePrompt = -1;
112+
for (int i = 0; i < promptComboBox->count(); ++i) {
113+
QString itemText = promptComboBox->itemText(i);
114+
115+
// Compare the item text with the filename
116+
if (itemText == fileName) {
117+
// Item with the same filename exists in the combobox
118+
samePrompt = i;
119+
}
120+
}
121+
122+
if (samePrompt >= 0)
123+
{
124+
promptComboBox->setCurrentIndex(samePrompt);
125+
}
126+
else
127+
{
128+
promptComboBox->addItem(fileName);
129+
promptComboBox->setCurrentIndex(promptComboBox->count() - 1);
130+
}
131+
}
132+
}
133+
}
134+
}
135+
106136
void EditDialog::initAzureSetting()
107137
{
108138
QStringList defaultVoices = {
@@ -164,10 +194,10 @@ void EditDialog::populateComboBox()
164194
int modelIndex = m_mainWindow->getModelIndex();
165195

166196
QDir directory(modelPath);
167-
QStringList txtFiles = directory.entryList(QStringList() << "*.txt", QDir::Files, QDir::Time);
197+
QStringList txtFiles = directory.entryList(QStringList() << "*.txt", QDir::Files, QDir::Name);
168198

169199
initPrompts(modelIndex);
170-
txtFiles = directory.entryList(QStringList() << "*.txt", QDir::Files, QDir::Time);
200+
txtFiles = directory.entryList(QStringList() << "*.txt", QDir::Files, QDir::Name);
171201

172202

173203
for (int i = 0; i < txtFiles.size(); ++i)
@@ -192,12 +222,12 @@ QString EditDialog::parsePrompt(QString txtFileName)
192222
return text;
193223
}
194224

195-
void EditDialog::loadPrompts(int promptIndex)
225+
void EditDialog::loadPrompts(int idx)
196226
{
197227
QString modelPath = m_mainWindow->getModelPath();
198228
QDir directory(modelPath);
199-
QStringList txtFiles = directory.entryList(QStringList() << "*.txt", QDir::Files, QDir::Time);
200-
QString promptFileName = txtFiles.at(promptIndex);
229+
QStringList txtFiles = directory.entryList(QStringList() << "*.txt", QDir::Files, QDir::Name);
230+
QString promptFileName = txtFiles.at(idx);
201231
QString text = parsePrompt(modelPath + promptFileName);
202232

203233
promptTextEdit->clear();
@@ -263,7 +293,7 @@ void EditDialog::initPrompts(int modelIndex)
263293
}
264294

265295
QString str;
266-
rules.append(" ### Instruction ### \nYou are Albert Einstein and you know everything. \n");
296+
rules.append(" You are Albert Einstein and you know everything. \n");
267297

268298
str = "Your reply must be in JSON format with the following keys: Expression, Motion, Content \n";
269299
rules.append(str);

src/Sample/editdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ class EditDialog : public QDialog
3131
void initPrompts(int);
3232
QString parsePrompt(QString);
3333
void loadPrompts(int);
34+
void saveNewPrompts();
3435

3536
private:
3637
MainWindow *m_mainWindow;
38+
int promptIndex = 0;
3739
void initAzureSetting();
3840

3941
signals:

0 commit comments

Comments
 (0)