void SimpleCodeStylePreferencesWidget::setPreferences(ICodeStylePreferences *preferences) { if (m_preferences == preferences) return; // nothing changes // cleanup old if (m_preferences) { disconnect(m_preferences, SIGNAL(currentSettingsChanged(TextEditor::TabSettings)), m_tabSettingsWidget, SLOT(setSettings(TextEditor::TabSettings))); disconnect(m_preferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)), this, SLOT(slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences*))); disconnect(m_tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)), this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings))); } m_preferences = preferences; // fillup new if (m_preferences) { slotCurrentPreferencesChanged(m_preferences->currentPreferences()); m_tabSettingsWidget->setTabSettings(m_preferences->currentTabSettings()); connect(m_preferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)), m_tabSettingsWidget, SLOT(setTabSettings(TextEditor::TabSettings))); connect(m_preferences, SIGNAL(currentPreferencesChanged(TextEditor::ICodeStylePreferences*)), this, SLOT(slotCurrentPreferencesChanged(TextEditor::ICodeStylePreferences*))); connect(m_tabSettingsWidget, SIGNAL(settingsChanged(TextEditor::TabSettings)), this, SLOT(slotTabSettingsChanged(TextEditor::TabSettings))); } m_tabSettingsWidget->setEnabled(m_preferences); }
void Plugin::initializeToolsSettings() { // code style factory auto factory = new CodeStylePreferencesFactory; TextEditor::TextEditorSettings::registerCodeStyleFactory(factory); // code style pool auto pool = new TextEditor::CodeStylePool(factory, this); TextEditor::TextEditorSettings::registerCodeStylePool(Constants::SettingsId, pool); // global code style settings auto globalCodeStyle = new TextEditor::SimpleCodeStylePreferences(this); globalCodeStyle->setDelegatingPool(pool); globalCodeStyle->setDisplayName(tr("Global", "Settings")); globalCodeStyle->setId("RubyGlobal"); pool->addCodeStyle(globalCodeStyle); TextEditor::TextEditorSettings::registerCodeStyle(Constants::SettingsId, globalCodeStyle); // built-in settings // Ruby style auto rubyCodeStyle = new TextEditor::SimpleCodeStylePreferences; rubyCodeStyle->setId("ruby"); rubyCodeStyle->setDisplayName(tr("RubyCreator")); rubyCodeStyle->setReadOnly(true); TextEditor::TabSettings tabSettings; tabSettings.m_tabPolicy = TextEditor::TabSettings::SpacesOnlyTabPolicy; tabSettings.m_tabSize = 2; tabSettings.m_indentSize = 2; tabSettings.m_continuationAlignBehavior = TextEditor::TabSettings::ContinuationAlignWithIndent; rubyCodeStyle->setTabSettings(tabSettings); pool->addCodeStyle(rubyCodeStyle); // default delegate for global preferences globalCodeStyle->setCurrentDelegate(rubyCodeStyle); pool->loadCustomCodeStyles(); // load global settings (after built-in settings are added to the pool) globalCodeStyle->fromSettings(QLatin1String(Constants::SettingsId), Core::ICore::settings()); // mimetypes to be handled TextEditor::TextEditorSettings::registerMimeTypeForLanguageId(Constants::MimeType, Constants::SettingsId); }
NimSettings::NimSettings(QObject *parent) : QObject(parent) { // code style factory auto factory = new NimCodeStylePreferencesFactory(); TextEditorSettings::registerCodeStyleFactory(factory); // code style pool auto pool = new CodeStylePool(factory, this); TextEditorSettings::registerCodeStylePool(Nim::Constants::C_NIMLANGUAGE_ID, pool); m_globalCodeStyle = new SimpleCodeStylePreferences(); m_globalCodeStyle->setDelegatingPool(pool); m_globalCodeStyle->setDisplayName(tr("Global", "Settings")); m_globalCodeStyle->setId(Nim::Constants::C_NIMGLOBALCODESTYLE_ID); pool->addCodeStyle(m_globalCodeStyle); TextEditorSettings::registerCodeStyle(Nim::Constants::C_NIMLANGUAGE_ID, m_globalCodeStyle); auto nimCodeStyle = new SimpleCodeStylePreferences(); nimCodeStyle->setId("nim"); nimCodeStyle->setDisplayName(tr("Nim")); nimCodeStyle->setReadOnly(true); TabSettings nimTabSettings; nimTabSettings.m_tabPolicy = TabSettings::SpacesOnlyTabPolicy; nimTabSettings.m_tabSize = 2; nimTabSettings.m_indentSize = 2; nimTabSettings.m_continuationAlignBehavior = TabSettings::ContinuationAlignWithIndent; nimCodeStyle->setTabSettings(nimTabSettings); pool->addCodeStyle(nimCodeStyle); m_globalCodeStyle->setCurrentDelegate(nimCodeStyle); pool->loadCustomCodeStyles(); // load global settings (after built-in settings are added to the pool) QSettings *s = Core::ICore::settings(); m_globalCodeStyle->fromSettings(QLatin1String(Nim::Constants::C_NIMLANGUAGE_ID), s); TextEditorSettings::registerMimeTypeForLanguageId(Nim::Constants::C_NIM_MIMETYPE, Nim::Constants::C_NIMLANGUAGE_ID); TextEditorSettings::registerMimeTypeForLanguageId(Nim::Constants::C_NIM_SCRIPT_MIMETYPE, Nim::Constants::C_NIMLANGUAGE_ID); }