From f6a7779fdd8cf670ded32a9485e09bc7dea54d21 Mon Sep 17 00:00:00 2001 From: d3cod3 Date: Sat, 21 Oct 2023 09:59:28 +0200 Subject: [PATCH] Added comment/uncomment line or selection shortcut config ( select your key ) to solve international keyboard problem with special characters ( []{}/\ ) shortcuts --- app/gui/qt/mainwindow.cpp | 18 +++++++- app/gui/qt/mainwindow.h | 2 + app/gui/qt/model/settings.h | 3 ++ app/gui/qt/widgets/settingswidget.cpp | 60 +++++++++++++++++++++++++++ app/gui/qt/widgets/settingswidget.h | 7 ++++ 5 files changed, 89 insertions(+), 1 deletion(-) diff --git a/app/gui/qt/mainwindow.cpp b/app/gui/qt/mainwindow.cpp index d487e82b28..05c0544665 100644 --- a/app/gui/qt/mainwindow.cpp +++ b/app/gui/qt/mainwindow.cpp @@ -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())); @@ -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 @@ -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()) @@ -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(); @@ -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); diff --git a/app/gui/qt/mainwindow.h b/app/gui/qt/mainwindow.h index ebf871455e..d1e2a420de 100644 --- a/app/gui/qt/mainwindow.h +++ b/app/gui/qt/mainwindow.h @@ -305,6 +305,8 @@ class MainWindow : public QMainWindow void focusBPMScrubber(); void focusTimeWarpScrubber(); + void changeShortcuts(); + private: SonicPiScintilla* getCurrentWorkspace(); SonicPiEditor* getCurrentEditor(); diff --git a/app/gui/qt/model/settings.h b/app/gui/qt/model/settings.h index 6332d1d5e3..f4db0f98c7 100644 --- a/app/gui/qt/model/settings.h +++ b/app/gui/qt/model/settings.h @@ -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; diff --git a/app/gui/qt/widgets/settingswidget.cpp b/app/gui/qt/widgets/settingswidget.cpp index e981df69e6..671ee44c7c 100644 --- a/app/gui/qt/widgets/settingswidget.cpp +++ b/app/gui/qt/widgets/settingswidget.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -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")); @@ -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 */ @@ -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 ); } @@ -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(); @@ -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); @@ -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())); diff --git a/app/gui/qt/widgets/settingswidget.h b/app/gui/qt/widgets/settingswidget.h index f984f0d48c..b48c4c5b6f 100644 --- a/app/gui/qt/widgets/settingswidget.h +++ b/app/gui/qt/widgets/settingswidget.h @@ -45,6 +45,7 @@ private slots: void toggleOscServer(); void toggleMidi(); void forceMidiReset(); + void toggleShortcuts(QString c); void changeMainVolume(int); void toggleLineNumbers(); void showAutoCompletion(); @@ -85,6 +86,7 @@ private slots: void oscSettingsChanged(); void midiSettingsChanged(); void resetMidi(); + void shortcutsChanged(); void volumeChanged(int vol); void showLineNumbersChanged(); void showAutoCompletionChanged(); @@ -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; @@ -188,6 +194,7 @@ private slots: QGroupBox* createAudioPrefsTab(); QGroupBox* createIoPrefsTab(); QGroupBox* createEditorPrefsTab(); + QGroupBox* createShortcutsPrefsTab(); QGroupBox* createVisualizationPrefsTab(); QGroupBox* createUpdatePrefsTab(); QGroupBox* createLanguagePrefsTab();