Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added comment/uncomment line or selection shortcut config #3341

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/gui/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ void MainWindow::setupWindowStructure()
connect(settingsWidget, SIGNAL(enableScsynthInputsChanged()), this, SLOT(changeEnableScsynthInputs()));
connect(settingsWidget, SIGNAL(midiSettingsChanged()), this, SLOT(toggleMidi()));
connect(settingsWidget, SIGNAL(resetMidi()), this, SLOT(resetMidi()));

connect(settingsWidget, SIGNAL(shortcutsChanged()), this, SLOT(changeShortcuts()));

connect(settingsWidget, SIGNAL(oscSettingsChanged()), this, SLOT(toggleOSCServer()));
connect(settingsWidget, SIGNAL(showLineNumbersChanged()), this, SLOT(changeShowLineNumbers()));
connect(settingsWidget, SIGNAL(showAutoCompletionChanged()), this, SLOT(changeShowAutoCompletion()));
Expand Down Expand Up @@ -618,7 +621,11 @@ void MainWindow::setupWindowStructure()
connect(pasteToBufferEmacs, SIGNAL(activated()), workspace, SLOT(sp_paste()));

//comment line
QShortcut* toggleLineComment = new QShortcut(metaKey('/'), workspace);
QString tlc = piSettings->commentUncomment_shrtc_key;
if(tlc == ""){
tlc == "/"; // default
}
QShortcut* toggleLineComment = new QShortcut(metaKey(tlc.toStdString()[0]), workspace);
connect(toggleLineComment, SIGNAL(activated()), this, SLOT(toggleCommentInCurrentWorkspace()));

//upcase next word
Expand Down Expand Up @@ -2038,6 +2045,11 @@ void MainWindow::changeScopeKindVisibility(QString name)
scopeWindow->EnableScope(name, piSettings->isScopeActive(name));
}

void MainWindow::changeShortcuts()
{
emit writeSettings();
}

void MainWindow::scopeKindVisibilityMenuChanged()
{
foreach (QAction* action, scopeKindVisibilityMenu->actions())
Expand Down Expand Up @@ -3517,6 +3529,8 @@ void MainWindow::readSettings()
piSettings->enable_external_synths = gui_settings->value("prefs/enable-external-synths", false).toBool();
piSettings->synth_trigger_timing_guarantees = gui_settings->value("prefs/synth-trigger-timing-guarantees", false).toBool();

piSettings->commentUncomment_shrtc_key = gui_settings->value("prefs/commentShortcut", "").toString();

piSettings->main_volume = gui_settings->value("prefs/system-vol", 80).toInt();
piSettings->mixer_force_mono = gui_settings->value("prefs/mixer-force-mono", false).toBool();
piSettings->mixer_invert_stereo = gui_settings->value("prefs/mixer-invert-stereo", false).toBool();
Expand Down Expand Up @@ -3565,6 +3579,8 @@ void MainWindow::writeSettings()
gui_settings->setValue("prefs/osc-public", piSettings->osc_public);
gui_settings->setValue("prefs/osc-enabled", piSettings->osc_server_enabled);

gui_settings->setValue("prefs/commentShortcut", piSettings->commentUncomment_shrtc_key);

gui_settings->setValue("prefs/check-args", piSettings->check_args);
gui_settings->setValue("prefs/log-synths", piSettings->log_synths);
gui_settings->setValue("prefs/clear-output-on-run", piSettings->clear_output_on_run);
Expand Down
2 changes: 2 additions & 0 deletions app/gui/qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ class MainWindow : public QMainWindow
void focusBPMScrubber();
void focusTimeWarpScrubber();

void changeShortcuts();

private:
SonicPiScintilla* getCurrentWorkspace();
SonicPiEditor* getCurrentEditor();
Expand Down
3 changes: 3 additions & 0 deletions app/gui/qt/model/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class SonicPiSettings {
bool show_context;
SonicPiTheme::Style themeStyle;

// ShortcutsSettings TODO: add more configurable shortcuts
QString commentUncomment_shrtc_key;

// UpdateSettings;
bool check_updates;

Expand Down
60 changes: 60 additions & 0 deletions app/gui/qt/widgets/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QUrl>
#include <iostream>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSignalMapper>
#include <QVBoxLayout>
Expand Down Expand Up @@ -45,6 +46,9 @@ SettingsWidget::SettingsWidget(int tau_osc_cues_port, bool i18n, SonicPiSettings
QGroupBox *editorTab = createEditorPrefsTab();
prefTabs->addTab(editorTab, tr("Editor"));

QGroupBox *shortcutsTab = createShortcutsPrefsTab();
prefTabs->addTab(shortcutsTab, tr("Shortcuts"));

QGroupBox *visualizationTab = createVisualizationPrefsTab();
prefTabs->addTab(visualizationTab, tr("Visuals"));

Expand Down Expand Up @@ -414,6 +418,51 @@ QGroupBox* SettingsWidget::createEditorPrefsTab() {
return editor_box;
}

/**
* create Shortcuts Tab of Preferences Widget
*/
QGroupBox* SettingsWidget::createShortcutsPrefsTab() {
QGroupBox *shortcuts_box = new QGroupBox();
shortcuts_box->setToolTip(tr("Configure shortcuts settings"));
QSizePolicy shortcutsPrefSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
shortcuts_box->setSizePolicy(shortcutsPrefSizePolicy);

shortcuts_option_label = new QLabel;
shortcuts_option_label->setText(tr("View and Customize Shortcuts"));
shortcuts_option_label->setToolTip(tr("Change the Sonic Pi default shortcuts (Requires a restart to take effect)"));

commentUncommentKey_label = new QLabel;
commentUncommentKey_label->setText(tr("Comment/Uncomment current line or selection: M-"));
commentUncommentKey_label->setToolTip(tr("Change the shortcuts key for comment/uncomment"));
commentUncommentKey_select = new QLineEdit;
commentUncommentKey_select->setPlaceholderText(piSettings->commentUncomment_shrtc_key);
commentUncommentKey_select->setStyleSheet("border : 2px solid gray; padding-top: 4px; padding-bottom: 4px;");
commentUncommentKey_select->setMaxLength(1); // 1 char
commentUncommentKey_select->setMaximumWidth(40);

QGridLayout *commentUncommentKey_layout = new QGridLayout();
commentUncommentKey_layout->addWidget(commentUncommentKey_label, 0, 0);
commentUncommentKey_layout->addWidget(commentUncommentKey_select, 0, 1);

QVBoxLayout *shortcuts_box_layout = new QVBoxLayout;

QSpacerItem *spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);

shortcuts_box_layout->addWidget(shortcuts_option_label);
shortcuts_box_layout->addItem(spacer);
shortcuts_box_layout->addLayout(commentUncommentKey_layout);

shortcuts_box->setLayout(shortcuts_box_layout);

QGroupBox *shorcuts_prefs_box = new QGroupBox();

QGridLayout *shorcuts_prefs_box_layout = new QGridLayout;
shorcuts_prefs_box_layout->addWidget(shortcuts_box, 0, 0);

shorcuts_prefs_box->setLayout(shorcuts_prefs_box_layout);
return shorcuts_prefs_box;
}

/**
* Create Visualization Preferences Tab of Settings Widget
*/
Expand Down Expand Up @@ -718,6 +767,11 @@ void SettingsWidget::forceMidiReset() {
emit resetMidi();
}

void SettingsWidget::toggleShortcuts(QString c) {
piSettings->commentUncomment_shrtc_key = c;
emit shortcutsChanged();
}

void SettingsWidget::updateMidiInPorts( QString in ) {
midi_in_ports_label->setText( in );
}
Expand Down Expand Up @@ -882,6 +936,8 @@ void SettingsWidget::updateSettings() {
piSettings->midi_default_channel_str = channel_pat_str;
piSettings->midi_enabled = midi_enable_check->isChecked();

piSettings->commentUncomment_shrtc_key = commentUncommentKey_select->text();

piSettings->auto_indent_on_run = auto_indent_on_run->isChecked();
piSettings->show_line_numbers = show_line_numbers->isChecked();
piSettings->show_autocompletion = show_autocompletion->isChecked();
Expand Down Expand Up @@ -941,6 +997,8 @@ void SettingsWidget::settingsChanged() {
piSettings->midi_default_channel_str = midi_default_channel_combo->currentText(); // TODO find a more elegant solution
midi_enable_check->setChecked(piSettings->midi_enabled);

commentUncommentKey_select->setPlaceholderText(piSettings->commentUncomment_shrtc_key);

auto_indent_on_run->setChecked(piSettings->auto_indent_on_run);

show_line_numbers->setChecked(piSettings->show_line_numbers);
Expand Down Expand Up @@ -995,6 +1053,8 @@ void SettingsWidget::connectAll() {
connect(osc_server_enabled_check, SIGNAL(clicked()), this, SLOT(toggleOscServer()));
connect(osc_public_check, SIGNAL(clicked()), this, SLOT(toggleOscServer()));

connect(commentUncommentKey_select, SIGNAL(textChanged(QString)), this, SLOT(toggleShortcuts(QString)));

connect(auto_indent_on_run, SIGNAL(clicked()), this, SLOT(updateSettings()));
connect(show_line_numbers, SIGNAL(clicked()), this, SLOT(updateSettings()));
connect(show_log, SIGNAL(clicked()), this, SLOT(updateSettings()));
Expand Down
7 changes: 7 additions & 0 deletions app/gui/qt/widgets/settingswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private slots:
void toggleOscServer();
void toggleMidi();
void forceMidiReset();
void toggleShortcuts(QString c);
void changeMainVolume(int);
void toggleLineNumbers();
void showAutoCompletion();
Expand Down Expand Up @@ -85,6 +86,7 @@ private slots:
void oscSettingsChanged();
void midiSettingsChanged();
void resetMidi();
void shortcutsChanged();
void volumeChanged(int vol);
void showLineNumbersChanged();
void showAutoCompletionChanged();
Expand Down Expand Up @@ -179,6 +181,10 @@ private slots:
QSlider *system_vol_slider;
QSlider *gui_transparency_slider;

QLabel *shortcuts_option_label;
QLabel *commentUncommentKey_label;
QLineEdit *commentUncommentKey_select;

QComboBox *language_combo;
QLabel *language_option_label;
QLabel *language_details_label;
Expand All @@ -188,6 +194,7 @@ private slots:
QGroupBox* createAudioPrefsTab();
QGroupBox* createIoPrefsTab();
QGroupBox* createEditorPrefsTab();
QGroupBox* createShortcutsPrefsTab();
QGroupBox* createVisualizationPrefsTab();
QGroupBox* createUpdatePrefsTab();
QGroupBox* createLanguagePrefsTab();
Expand Down