I am trying to use preferences in tornadofx . but documentation has very few about it.
"unresolved references" to "preferences".
From where to import preferences ?
Please give and clear example.
The Preferences API in JavaFX allows you store store arbitrary configuration options in an OS dependent way. It's a direct alternative to the config functionality in TornadoFX. This example retrieves and stores a value from the default Perferences node:
class UserEditor : View("User Editor") {
val name = SimpleStringProperty()
init {
preferences {
name.value = get("name", "Default Name")
}
}
override val root = form {
fieldset {
field("Name") {
textfield(name)
}
}
button("Save").action {
preferences {
put("name", name.value)
}
}
}
}
TornadoFX merely facilitates easier access to the Preferences store available to JavaFX applications. You can also pass a specific node name as parameter to the preferences function.
Try the official guide to TornadoFX config here.
It shows an example of configuration settings applied to the user login form, communication with ViewModel, and other useful stuff.
Related
On Teamcity, when I click an agent, I get the "Agent Summary", "Build History", "Compatible Configurations", etc. etc. I can also see the running build and the "Miscellaneous" section, like this one:
I would like to know how I can run the "Stop instance after current build" with the Teamcity API. Does that correspond to deleting the agent or is there something else?
If you want to do it from the build itself, then you can emulate the HTTP request that UI sends when a user clicks the "Stop instance after current build" button
The best way I was advised to follow in order to solve my issue is to define a cloud profile which terminates agents after the first build. To achieve that, in my teamcity project, I have defined (in kotlin DSL):
project {
[...]
features {
feature(ProjectFeature({
type = "CloudProfile"
id = "stop_instance_after_current_build"
// various cloud profile parameters, like
// profileServerUrl, secure:access-id, total-work-time, etc.
// which you find by GETting <teamcity-url>/app/rest/projects/id:<project-id>/projectFeatures/
[...]
// there should be no terminate-idle-time parameter
param("terminate-after-build", true.toString())
})
}
}
With that in place, in a build configuration associated to that project, I do
class SomeBuildConfig() : BuildType({
[...]
requirements {
equals("system.cloud.profile_id", "stop_instance_after_current_build")
}
})
If we don't want to rely on %system.cloud.profile_id%, it is also possible to define a dedicated variable in the agent through the user-script parameter of a ProjectFeature of CloudImage type:
project {
[...]
features {
feature(ProjectFeature({
type = "CloudProfile"
id = "stop_instance_after_current_build"
// as above
[...]
})
feature(ProjectFeature({
type = "CloudImage"
// various parameters like e.g. image-name-prefix, key-pair-name, subnet-id, amazon-id, etc.
[...]
param("profileId", "stop_instance_after_current_build")
param("user-script", userData)
})
}
}
where userData is the content of a script like this:
#! /bin/sh
echo "teamcity.agent.killed_after_current_build=true" >> /home/ubuntu/buildAgent/conf/buildAgent.properties
Then, in a build configuration associated to that project, we can do
requirements {
equals("teamcity.agent.killed_after_current_build", "true")
}
I wrote some codes for an application
and I want to save this Settings Like Hide a lineEdit or etc...
and when reopen program last settings will load and when user edit setting
settings that saved updates
what I must do?
note: I Used Qsettings but settings dose not saved!
if Possible one person Write a Sample Code For me That save current index of a combobox
QSettings settings("Mobtakeran Fanavri KabooK","Kabook Physiothrapy");
Secretary::Secretary(QWidget *parent) :
QWidget(parent),
ui(new Ui::Secretary)
{
ui->setupUi(this);
ui->comboBox->setCurrentIndex(settings.value("comboBox").toInt());
}
Secretary::~Secretary()
{
QCoreApplication::setOrganizationName("Mobtakeran Fanavri KabooK");
QCoreApplication::setOrganizationName("WWW.M4RZB4Ni.IR");
QCoreApplication::setApplicationName("Kabook Physiothrapy");
delete ui;
}
void Secretary::on_comboBox_currentIndexChanged(int index)
{
settings.beginGroup("comboBox");
if(ui->comboBox->currentIndex()==2) {
ui->pushButton_3->setDisabled(true);
} else if(ui->comboBox->currentIndex()==1) {
ui->pushButton_3->hide();
settings.setValue("comboBox",ui->comboBox->currentIndex());
} else if(ui->comboBox->currentIndex()==0) {
if(ui->lineEdit_56->text()==NULL) {
ui->pushButton_8->setDisabled(true);
}
}
settings.endGroup();
}
when you are saving your settings in Secretary::on_comboBox_currentIndexChanged you are calling settings.beginGroup("comboBox") then you set the value settings.setValue("comboBox",ui->comboBox->currentIndex()).
According to the documentation, this will set the value of the settings "comboBox/comboBox", meaning that you should read its value using settings.value("comboBox/comboBox").toInt().
Also please note that you are calling settings.setValue only in the case where currentIndex changes to 2, are you sure you mean to do that? didn't you mean to call it after all your if/else blocks?
I'm down to the (hopefully) last hurdle in the process of migrating our extension from XUL to Firefox SDK, but I've got one last sticking point:
Preferences.
There are a number of preferences set that simply MUST be migrated when the SDK version of the addon is installed over the top of the XUL addon. These preferences are not exposed to the end user for various reasons. The preference namespacing between the two architectures are completely different. For example -
A "version_number" preference in XUL is named arbitrarily by the developer, and appears as such in about:config :
my.preference.name
However, in SDK, they are scoped to the extension in question:
extensions.[extension ID].my.preference.name
Can preferences from XUL addons be migrated for re-use inside SDK addons? If so, how?
While it didn't seem possible to read from preferences outside the SDK addon's namespace, it WAS possible to write into the EXPECTED namespace in the old XUL extension. The solution we came up with was to publish a small, final point release of the old XUL addon with a small bit of extra logic responsible for carrying out this migration before we publish the new SDK version to AMO.
Here's a pseudocode representation of our approach:
ContentScript.js
function initNewFFInstallation() {
...
if (checkIsUpgrade()) {
var keys = getPrefKeys()
migratePrefs(keys);
}
}
Utils.js - acts as a bridge to expose Overlay functionality to the content script
Util.prototype.getPrefsBranch = function() {
return Components.classes["#mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService).
getBranch("my.prefs.ns.");
}
Util.prototype.getV2PrefsBranch = function() {
return Components.classes["#mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService).
getBranch("extensions.[SDK_ADDON_ID].");
}
Util.prototype.setBoolPref = function(key, val) {
this.getPrefsBranch().setBoolPref(key, val);
this.getPrefsBranch().setBoolPref(key, val);
}
Util.prototype.setCharPref = function(key, val) {
this.getPrefsBranch().setCharPref (key, val);
this.getV2PrefsBranch().setCharPref (key, val);
}
//copies all the preferences over
Util.prototype.migratePrefs = function(boolPrefKeys, charPrefKeys) {
boolPrefKeys.each(function (key) {
this.getV2PrefsBranch().setBoolPref(key, this.getPrefsBranch().getBoolPref(key));
});
charPrefKeys.forEach(function (key) {
this.getV2PrefsBranch().setCharPref(key, this.getPrefsBranch().getCharPref(key));
});
}
Then in our scriptcompiler.js, which actually injects the scripts onto the page, the util methods are hooked onto the SafeWindow object.
injectScript: function(script, unsafeContentWin) {
var safeWin=new XPCNativeWrapper(unsafeContentWin);
var sandbox=new Components.utils.Sandbox(safeWin, {"sandboxPrototype":safeWin});
sandbox.window=safeWin;
sandbox.document=sandbox.window.document;
sandbox.unsafeWindow=unsafeContentWin;
var util = new Util();
//...other APIs
sandbox.migratePreferences=app_gmCompiler.hitch(util , "migratePreferences");
try {
Components.utils.evalInSandbox("(function(){"+script+"})()", sandbox);
} catch (e) {
}
}
I have a simple Visual Studio extension that is built in a similar manner as the one presented in this walkthrough (using the IWpfTextViewCreationListener interface).
The extension uses two colors that I'd like to make configurable.
How can I define an Options Dialog for this extension? (for example, a properties page that would appear in the Tools/Options menu)
I have tried to do this using the DialogPage Class, but apparently it requires a VSPackage and I'm not sure if this approach is compatible with what I'm doing.
I think you can make your colors customisable without providing a custom OptionsPage.
You can Export your own colors and they will became configurable from Tools-Options-Fonts and Colors
By your linked example:
[Export(typeof(EditorFormatDefinition))]
[Name("EditorFormatDefinition/MyCustomFormatDefinition")]
[UserVisible(true)]
internal class CustomFormatDefinition : EditorFormatDefinition
{
public CustomFormatDefinition( )
{
this.BackgroundColor = Colors.LightPink;
this.ForegroundColor = Colors.DarkBlue;
this.DisplayName = "My Cusotum Editor Format";
}
}
[Export(typeof(EditorFormatDefinition))]
[Name("EditorFormatDefinition/MyCustomFormatDefinition2")]
[UserVisible(true)]
internal class CustomFormatDefinition2 : EditorFormatDefinition
{
public CustomFormatDefinition2( )
{
this.BackgroundColor = Colors.DeepPink;
this.ForegroundColor = Colors.DarkBlue;
this.DisplayName = "My Cusotum Editor Format 2";
}
}
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
internal class TestViewCreationListener : IWpfTextViewCreationListener
{
[Import]
internal IEditorFormatMapService FormatMapService = null;
public void TextViewCreated( IWpfTextView textView )
{
IEditorFormatMap formatMap = FormatMapService.GetEditorFormatMap(textView);
ResourceDictionary selectedText = formatMap.GetProperties("Selected Text");
ResourceDictionary inactiveSelectedText = formatMap.GetProperties("Inactive Selected Text");
ResourceDictionary myCustom = formatMap.GetProperties("EditorFormatDefinition/MyCustomFormatDefinition");
ResourceDictionary myCustom2 = formatMap.GetProperties("EditorFormatDefinition/MyCustomFormatDefinition2");
formatMap.BeginBatchUpdate();
selectedText[EditorFormatDefinition.BackgroundBrushId] = myCustom[EditorFormatDefinition.BackgroundBrushId];
formatMap.SetProperties("Selected Text", selectedText);
inactiveSelectedText[EditorFormatDefinition.BackgroundBrushId] = myCustom2[EditorFormatDefinition.BackgroundBrushId];
formatMap.SetProperties("Inactive Selected Text", myCustom2);
formatMap.EndBatchUpdate();
}
}
Custom EFDs can provide SolidColorBrushes.
If this isn't enought, you can also access to the service provider used by VSPackages. You can make a package for the option page, and communicate with the Editor Extension through the service provider with a custom service.
You can import the service provider like this:
[Import]
internal SVsServiceProvider serviceProvider = null;
This soulution also doesn't require from you to migrate the original logic, only the creation of an additional package.
I know this is old, but I thought some of these links might help you (NB: I haven't actually done this myself).
I'd guess you are missing attributes detailed in the MSDN Page:
MSDN - Walkthrough: Creating an Options Page
[ProvideOptionPage(typeof(OptionPageGrid),
"My Category", "My Grid Page", 0, 0, true)]
Some other options are:
Integrating into Visual Studio Settings
Registering Custom Options Pages
If you do decide to go with making a VSPackage (as I believe that's the recommended approach), see this MSDN page and this other SO answer. I also show how to do this using C# and a WPF User Control for the Options Page on my blog here.
I'm developing my first app and I'm trying to make it multilanguage.
Using AppHub example and some other link I created my resource files, fixed binding strings on my components and set a settings page.
First problem I had was that menu items and appbar buttons couldn't use localization strings (project complained when launched) so I have:
TextBlocks and other components binded with localized strings
Appbar buttons and items localized manually with a procedure loading localized strings
Now that I have my settings page, one item user can change is language.
Well, correct CultureInfo is selected according to user selection and then I use
Thread.CurrentThread.CurrentUICulture = Settings.Language;
When I press back button and return to main page, appbar items are localized correctly, while everything else is not.
The only workaround (that I really don't like, it's just to understand) is this:
public MainPage()
{
Thread.CurrentThread.CurrentUICulture = Settings.Language;
InitializeComponent();
// Everything else I need here
}
so I have to set language before components are created to make it work.
What's wrong? Which is the correct way to make a page refresh after changing language using binded strings?
I did not put a lot of code because I used basically the one provided in the link, but if you need more info I will edit my question.
I finally found a solution to automatically update my application components reacting to language change.
A good tutorial can be found here; briefly you must find a way to notify your app that localized resource is changed.
public class LocalizedStrings : ViewModelBase
{
private static AppResources localizedresources = new AppResources();
public AppResources LocalizedResources
{
get { return localizedresources; }
}
public void UpdateLanguage()
{
localizedresources = new AppResources();
RaisePropertyChanged(() => LocalizedResources);
}
public static LocalizedStrings LocalizedStringsResource
{
get
{
return Application.Current.Resources["LocalizedStrings"]
as LocalizedStrings;
}
}
}
With this when user change language, you should simply run
LocalizedStrings.LocalizedStringsResource.UpdateLanguage();
and the job is done.