Skip to content

Commit fe42a16

Browse files
committed
GUI: Example button in NewDialog and related main windows modifications.
Signed-off-by: Pavel Pisa <[email protected]>
1 parent 510518a commit fe42a16

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

src/gui/NewDialog.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@
426426
</property>
427427
</spacer>
428428
</item>
429+
<item>
430+
<widget class="QPushButton" name="pushButton_example">
431+
<property name="text">
432+
<string>Example</string>
433+
</property>
434+
</widget>
435+
</item>
429436
<item>
430437
<widget class="QPushButton" name="pushButton_start_empty">
431438
<property name="text">

src/gui/mainwindow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,18 @@ void MainWindow::close_source() {
764764
update_open_file_list();
765765
}
766766

767+
void MainWindow::close_source_by_name(QString &filename, bool ask) {
768+
SrcEditor *editor = source_editor_for_file(filename, false);
769+
if (editor == nullptr)
770+
return;
771+
setCurrentSrcEditor(editor);
772+
if (ask) {
773+
close_source_check();
774+
} else {
775+
close_source();
776+
}
777+
}
778+
767779
void MainWindow::example_source(const QString &source_file) {
768780
auto *editor = new SrcEditor();
769781

src/gui/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public slots:
6565
void close_source();
6666
void close_source_check();
6767
void close_source_decided(int result);
68+
void close_source_by_name(QString &filename, bool ask = false);
6869
void example_source(const QString &source_file);
6970
void compile_source();
7071
void build_execute();

src/gui/newdialog.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ NewDialog::NewDialog(QWidget *parent, QSettings *settings) : QDialog(parent) {
2727
ui_cache_d = new Ui::NewDialogCache();
2828
ui_cache_d->setupUi(ui->tab_cache_data);
2929

30+
connect(
31+
ui->pushButton_example, &QAbstractButton::clicked, this,
32+
&NewDialog::create_example);
3033
connect(
3134
ui->pushButton_start_empty, &QAbstractButton::clicked, this,
3235
&NewDialog::create_empty);
@@ -170,6 +173,18 @@ void NewDialog::create_empty() {
170173
this->close();
171174
}
172175

176+
void NewDialog::create_example() {
177+
auto *p_window = (MainWindow *)parent();
178+
QString example(":/samples/template.S");
179+
p_window->create_core(*config, false, true);
180+
store_settings(); // Save to settings
181+
p_window->close_source_by_name(example, false);
182+
p_window->example_source(example);
183+
p_window->show_program();
184+
p_window->compile_source();
185+
this->close();
186+
}
187+
173188
void NewDialog::browse_elf() {
174189
#ifndef __EMSCRIPTEN__
175190
QFileDialog elf_dialog(this);
@@ -331,7 +346,7 @@ void NewDialog::config_gui() {
331346
ui->osemu_fs_root->setText(config->osemu_fs_root());
332347

333348
// Disable various sections according to configuration
334-
ui->delay_slot->setEnabled(!config->pipelined());
349+
ui->delay_slot->setEnabled(false);
335350
ui->hazard_unit->setEnabled(config->pipelined());
336351
}
337352

src/gui/newdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ private slots:
2727
void cancel();
2828
void create();
2929
void create_empty();
30+
void create_example();
3031
void browse_elf();
3132
void elf_change(QString val);
3233
void set_preset();

0 commit comments

Comments
 (0)