Skip to content

Commit

Permalink
GUI - add preference and menu item for hiding/showing code context
Browse files Browse the repository at this point in the history
  • Loading branch information
samaaron committed Oct 15, 2020
1 parent ad31491 commit 80c3d5a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
32 changes: 31 additions & 1 deletion app/gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ void MainWindow::setupWindowStructure() {

connect(settingsWidget, SIGNAL(checkUpdatesChanged()), this, SLOT(update_check_updates()));
connect(settingsWidget, SIGNAL(forceCheckUpdates()), this, SLOT(check_for_updates_now()));
connect(settingsWidget, SIGNAL(showContextChanged()), this, SLOT(changeShowContext()));

connect(this, SIGNAL(settingsChanged()), settingsWidget, SLOT(settingsChanged()));

Expand Down Expand Up @@ -1296,6 +1297,7 @@ void MainWindow::honourPrefs() {
toggleIcons();
scope();
changeShowAutoCompletion();
changeShowContext();
}

void MainWindow::setMessageBoxStyle() {
Expand Down Expand Up @@ -1987,6 +1989,12 @@ void MainWindow::showAutoCompletionMenuChanged() {
changeShowAutoCompletion();
}

void MainWindow::showContextMenuChanged() {
piSettings->show_context = showContextAct->isChecked();
emit settingsChanged();
changeShowContext();
}

void MainWindow::changeShowLineNumbers(){

bool show = piSettings->show_line_numbers;
Expand Down Expand Up @@ -2022,6 +2030,21 @@ void MainWindow::changeShowAutoCompletion() {
showAutoCompletionAct->setChecked(piSettings->show_autocompletion);
}

void MainWindow::changeShowContext() {
bool show = piSettings->show_context;
if(show) {
statusBar()->showMessage(tr("Show context on"), 2000);
contextWidget->show();
} else {
statusBar()->showMessage(tr("Show context off"), 2000);
contextWidget->hide();
}


QSignalBlocker blocker( showContextAct );
showContextAct->setChecked(piSettings->show_context);
}

void MainWindow::togglePrefs() {
if(prefsWidget->isVisible()) {
prefsWidget->hide();
Expand Down Expand Up @@ -2296,8 +2319,13 @@ void MainWindow::createToolBar()
showAutoCompletionAct->setCheckable(true);
showAutoCompletionAct->setChecked(piSettings->show_autocompletion);

showContextAct = new QAction(tr("Show Code Context"), this);
showContextAct->setCheckable(true);
showContextAct->setChecked(piSettings->show_context);

connect(showLineNumbersAct, SIGNAL(triggered()), this, SLOT(showLineNumbersMenuChanged()));
connect(showAutoCompletionAct, SIGNAL(triggered()), this, SLOT(showAutoCompletionMenuChanged()));
connect(showContextAct, SIGNAL(triggered()), this, SLOT(showContextMenuChanged()));

toolBar->addAction(scopeAct);
toolBar->addAction(infoAct);
Expand Down Expand Up @@ -2327,6 +2355,7 @@ void MainWindow::createToolBar()
displayMenu->addAction(infoAct);
displayMenu->addAction(helpAct);
displayMenu->addAction(prefsAct);
displayMenu->addAction(showContextAct);

focusMenu = menuBar()->addMenu(tr("&Focus"));

Expand Down Expand Up @@ -2599,8 +2628,8 @@ void MainWindow::readSettings() {
piSettings->goto_buffer_shortcuts = settings.value("prefs/goto_buffer_shortcuts", false).toBool();
QString styleName = settings.value("prefs/theme", "").toString();
piSettings->themeStyle = theme->themeNameToStyle(styleName);

piSettings->show_autocompletion = settings.value("prefs/show-autocompletion", true).toBool();
piSettings->show_context = settings.value("prefs/show-context", true).toBool();

emit settingsChanged();
}
Expand Down Expand Up @@ -2653,6 +2682,7 @@ void MainWindow::writeSettings()
settings.setValue("prefs/show-buttons", piSettings->show_buttons);
settings.setValue("prefs/show-tabs", piSettings->show_tabs);
settings.setValue("prefs/show-log", piSettings->show_log);
settings.setValue("prefs/show-context", piSettings->show_context);

for ( auto name : piSettings->scope_names ) {
settings.setValue("prefs/scope/show-"+name.toLower(), piSettings->isScopeActive(name));
Expand Down
4 changes: 3 additions & 1 deletion app/gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class MainWindow : public QMainWindow
void showLineNumbersMenuChanged();
void showAutoCompletionMenuChanged();
void changeShowAutoCompletion();
void changeShowContext();
void showContextMenuChanged();
void toggleScope(QString name);
void toggleLeftScope();
void toggleRightScope();
Expand Down Expand Up @@ -331,7 +333,7 @@ class MainWindow : public QMainWindow

QToolBar *toolBar;

QAction *exitAct, *runAct, *stopAct, *saveAsAct, *loadFileAct, *recAct, *textAlignAct, *textIncAct, *textDecAct, *scopeAct, *infoAct, *helpAct, *prefsAct, *focusEditorAct, *focusLogsAct, *focusContextAct, *focusCuesAct, *focusPreferencesAct, *focusHelpListingAct, *focusHelpDetailsAct, *focusErrorsAct, *showLineNumbersAct, *showAutoCompletionAct;
QAction *exitAct, *runAct, *stopAct, *saveAsAct, *loadFileAct, *recAct, *textAlignAct, *textIncAct, *textDecAct, *scopeAct, *infoAct, *helpAct, *prefsAct, *focusEditorAct, *focusLogsAct, *focusContextAct, *focusCuesAct, *focusPreferencesAct, *focusHelpListingAct, *focusHelpDetailsAct, *focusErrorsAct, *showLineNumbersAct, *showAutoCompletionAct, *showContextAct;
QShortcut *runSc, *stopSc, *saveAsSc, *loadFileSc, *recSc, *textAlignSc, *textIncSc, *textDecSc, *scopeSc, *infoSc, *helpSc, *prefsSc, *focusEditorSc, *focusLogsSc, *focusContextSc, *focusCuesSc, *focusPreferencesSc, *focusHelpListingSc, *focusHelpDetailsSc, *focusErrorsSc;

SettingsWidget *settingsWidget;
Expand Down
1 change: 1 addition & 0 deletions app/gui/qt/model/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SonicPiSettings {
bool log_auto_scroll;
int gui_transparency;
bool show_autocompletion;
bool show_context;
SonicPiTheme::Style themeStyle;

// UpdateSettings;
Expand Down
12 changes: 12 additions & 0 deletions app/gui/qt/widgets/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ QGroupBox* SettingsWidget::createEditorPrefsTab() {
show_autocompletion = new QCheckBox(tr("Show code completion"));
show_autocompletion->setToolTip(tr("When enabled, Sonic Pi's editor will attempt to autocomplete your code with suggestions. When disabled, these suggestions will not be visible."));

show_context = new QCheckBox(tr("Show code context"));
show_context->setToolTip(tr("When enabled, Sonic Pi's editor will show a pane which will display context-specific information for the code such as the current line and position of the cursor."));

show_log = new QCheckBox(tr("Show log"));
show_log->setToolTip(tooltipStrShiftMeta('L', tr("Toggle visibility of the log.")));
show_log->setChecked(true);
Expand Down Expand Up @@ -323,6 +326,7 @@ QGroupBox* SettingsWidget::createEditorPrefsTab() {

editor_display_box_layout->addWidget(show_line_numbers);
editor_display_box_layout->addWidget(show_autocompletion);
editor_display_box_layout->addWidget(show_context);
editor_display_box_layout->addWidget(show_log);
editor_display_box_layout->addWidget(show_cues);
editor_display_box_layout->addWidget(show_buttons);
Expand Down Expand Up @@ -533,6 +537,10 @@ void SettingsWidget::showAutoCompletion() {
emit showAutoCompletionChanged();
}

void SettingsWidget::showContext() {
emit showContextChanged();
}

void SettingsWidget::toggleLog() {
emit showLogChanged();
}
Expand Down Expand Up @@ -610,6 +618,7 @@ void SettingsWidget::updateSettings() {
piSettings->auto_indent_on_run = auto_indent_on_run->isChecked();
piSettings->show_line_numbers = show_line_numbers->isChecked();
piSettings->show_autocompletion = show_autocompletion->isChecked();
piSettings->show_context = show_context->isChecked();
piSettings->show_log = show_log->isChecked();
piSettings->show_cues = show_cues->isChecked();
piSettings->show_buttons = show_buttons->isChecked();
Expand Down Expand Up @@ -672,6 +681,7 @@ void SettingsWidget::settingsChanged() {

check_updates->setChecked(piSettings->check_updates);
show_autocompletion->setChecked(piSettings->show_autocompletion);
show_context->setChecked(piSettings->show_context);
}

void SettingsWidget::connectAll() {
Expand Down Expand Up @@ -713,6 +723,7 @@ void SettingsWidget::connectAll() {
connect(gui_transparency_slider, SIGNAL(valueChanged(int)), this, SLOT(updateSettings()));

connect(show_autocompletion, SIGNAL(clicked()), this, SLOT(updateSettings()));
connect(show_context, SIGNAL(clicked()), this, SLOT(updateSettings()));

connect(show_line_numbers, SIGNAL(clicked()), this, SLOT(toggleLineNumbers()));
connect(show_log, SIGNAL(clicked()), this, SLOT(toggleLog()));
Expand All @@ -739,4 +750,5 @@ void SettingsWidget::connectAll() {
connect(check_updates_now, SIGNAL(clicked()), this, SLOT(checkForUpdatesNow()));

connect(show_autocompletion, SIGNAL(clicked()), this, SLOT(showAutoCompletion()));
connect(show_context, SIGNAL(clicked()), this, SLOT(showContext()));
}
3 changes: 3 additions & 0 deletions app/gui/qt/widgets/settingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ private slots:
void updateSettings();
void updateTransparency(int t);
void settingsChanged();
void showContext();

signals:
void mixerSettingsChanged();
Expand All @@ -79,6 +80,7 @@ private slots:
void transparencyChanged(int t);
void checkUpdatesChanged();
void forceCheckUpdates();
void showContextChanged();

private:
SonicPiSettings* piSettings;
Expand Down Expand Up @@ -106,6 +108,7 @@ private slots:
QCheckBox *check_updates;
QCheckBox *studio_mode;
QCheckBox *show_autocompletion;
QCheckBox *show_context;

QComboBox *midi_default_channel_combo;
QCheckBox *midi_enable_check;
Expand Down

0 comments on commit 80c3d5a

Please sign in to comment.