2014-09-25 00:18:14 +04:00
# include "settings.h"
2014-12-30 04:37:16 +03:00
# include "printutils.h"
# include <boost/assign/std/vector.hpp>
using namespace boost : : assign ; // bring 'operator+=()' into scope
2014-09-25 00:18:14 +04:00
2014-12-27 04:17:15 +03:00
namespace Settings {
2014-12-30 04:37:16 +03:00
static std : : list < SettingsEntry * > entries ;
2014-12-29 02:29:09 +03:00
2014-12-30 04:37:16 +03:00
SettingsEntry : : SettingsEntry ( const std : : string category , const std : : string name , const Value range , const Value def )
: _category ( category ) , _name ( name ) , _value ( def ) , _range ( range ) , _default ( def )
2014-12-29 02:29:09 +03:00
{
entries . push_back ( this ) ;
}
2014-12-30 04:37:16 +03:00
SettingsEntry : : ~ SettingsEntry ( )
2014-12-29 02:29:09 +03:00
{
}
2014-12-30 04:37:16 +03:00
const std : : string & SettingsEntry : : category ( ) const
2014-12-29 02:29:09 +03:00
{
return _category ;
}
2014-12-30 04:37:16 +03:00
const std : : string & SettingsEntry : : name ( ) const
2014-12-29 02:29:09 +03:00
{
return _name ;
}
2014-12-30 04:37:16 +03:00
const Value & SettingsEntry : : defaultValue ( ) const
2014-09-25 00:18:14 +04:00
{
2014-12-30 04:37:16 +03:00
return _default ;
2014-09-25 00:18:14 +04:00
}
2014-12-30 04:37:16 +03:00
const Value & SettingsEntry : : range ( ) const
2014-09-25 00:18:14 +04:00
{
2014-12-30 04:37:16 +03:00
return _range ;
2014-09-25 00:18:14 +04:00
}
2014-12-30 04:37:16 +03:00
bool SettingsEntry : : is_default ( ) const
2014-12-29 02:29:09 +03:00
{
2014-12-30 04:37:16 +03:00
return _value = = _default ;
2014-12-29 02:29:09 +03:00
}
2014-12-30 04:37:16 +03:00
static Value value ( std : : string s1 , std : : string s2 ) {
Value : : VectorType v ;
v + = Value ( s1 ) , Value ( s2 ) ;
return v ;
2014-12-29 02:29:09 +03:00
}
2014-12-30 04:37:16 +03:00
static Value values ( std : : string s1 , std : : string s1disp , std : : string s2 , std : : string s2disp ) {
Value : : VectorType v ;
v + = value ( s1 , s1disp ) , value ( s2 , s2disp ) ;
return v ;
2014-12-29 02:29:09 +03:00
}
2014-12-30 04:37:16 +03:00
static Value values ( std : : string s1 , std : : string s1disp , std : : string s2 , std : : string s2disp , std : : string s3 , std : : string s3disp ) {
Value : : VectorType v ;
v + = value ( s1 , s1disp ) , value ( s2 , s2disp ) , value ( s3 , s3disp ) ;
return v ;
2014-12-29 02:29:09 +03:00
}
2014-12-30 04:37:16 +03:00
static Value values ( std : : string s1 , std : : string s1disp , std : : string s2 , std : : string s2disp , std : : string s3 , std : : string s3disp , std : : string s4 , std : : string s4disp ) {
Value : : VectorType v ;
v + = value ( s1 , s1disp ) , value ( s2 , s2disp ) , value ( s3 , s3disp ) , value ( s4 , s4disp ) ;
return v ;
2014-12-29 02:29:09 +03:00
}
2014-09-25 00:18:14 +04:00
Settings * Settings : : inst ( bool erase )
{
static Settings * instance = new Settings ;
if ( erase ) {
delete instance ;
instance = NULL ;
}
return instance ;
}
Settings : : Settings ( )
{
}
Settings : : ~ Settings ( )
{
}
2014-12-30 04:37:16 +03:00
void Settings : : visit ( Visitor & visitor )
2014-12-29 02:29:09 +03:00
{
2014-12-30 04:37:16 +03:00
for ( std : : list < SettingsEntry * > : : iterator it = entries . begin ( ) ; it ! = entries . end ( ) ; it + + ) {
visitor . handle ( * ( * it ) ) ;
2014-12-29 02:29:09 +03:00
}
}
2014-12-30 04:37:16 +03:00
Value Settings : : get ( const SettingsEntry & entry )
2014-12-27 04:17:15 +03:00
{
2014-12-30 04:37:16 +03:00
return entry . _value ;
2014-12-27 04:17:15 +03:00
}
2014-12-30 04:37:16 +03:00
void Settings : : set ( SettingsEntry & entry , const Value val )
2014-12-27 04:17:15 +03:00
{
2014-12-30 04:37:16 +03:00
entry . _value = val ;
2014-12-27 04:17:15 +03:00
}
2014-12-29 02:29:09 +03:00
Visitor : : Visitor ( )
{
}
Visitor : : ~ Visitor ( )
{
}
2014-12-30 04:37:16 +03:00
/*
* Supported settings entry types are : bool / int and string selection
*
* String selection is used to handle comboboxes and has two values
* per config selection . The first value is used internally for both
* finding the combobox selection and for storing the value in the
* external settings file . The second value is the display value that
* can be translated .
*/
SettingsEntry Settings : : indentationWidth ( " editor " , " indentationWidth " , Value ( Value : : RangeType ( 1 , 16 ) ) , Value ( 4 ) ) ;
SettingsEntry Settings : : tabWidth ( " editor " , " tabWidth " , Value ( Value : : RangeType ( 1 , 16 ) ) , Value ( 8 ) ) ;
SettingsEntry Settings : : lineWrap ( " editor " , " lineWrap " , values ( " None " , _ ( " None " ) , " Char " , _ ( " Wrap at character boundaries " ) , " Word " , _ ( " Wrap at word boundaries " ) ) , Value ( " Word " ) ) ;
SettingsEntry Settings : : lineWrapIndentationStyle ( " editor " , " lineWrapIndentationStyle " , values ( " Fixed " , _ ( " Fixed " ) , " Same " , _ ( " Same " ) , " Indented " , _ ( " Indented " ) ) , Value ( " Fixed " ) ) ;
SettingsEntry Settings : : lineWrapIndentation ( " editor " , " lineWrapIndentation " , Value ( Value : : RangeType ( 0 , 999 ) ) , Value ( 4 ) ) ;
SettingsEntry Settings : : lineWrapVisualizationBegin ( " editor " , " lineWrapVisualizationBegin " , values ( " None " , _ ( " None " ) , " Text " , _ ( " Text " ) , " Border " , _ ( " Border " ) , " Margin " , _ ( " Margin " ) ) , Value ( " None " ) ) ;
SettingsEntry Settings : : lineWrapVisualizationEnd ( " editor " , " lineWrapVisualizationEnd " , values ( " None " , _ ( " None " ) , " Text " , _ ( " Text " ) , " Border " , _ ( " Border " ) , " Margin " , _ ( " Margin " ) ) , Value ( " Border " ) ) ;
SettingsEntry Settings : : showWhitespace ( " editor " , " showWhitespaces " , values ( " Never " , _ ( " Never " ) , " Always " , _ ( " Always " ) , " AfterIndentation " , _ ( " After indentation " ) ) , Value ( " Never " ) ) ;
SettingsEntry Settings : : showWhitespaceSize ( " editor " , " showWhitespacesSize " , Value ( Value : : RangeType ( 1 , 16 ) ) , Value ( 2 ) ) ;
SettingsEntry Settings : : autoIndent ( " editor " , " autoIndent " , Value ( true ) , Value ( true ) ) ;
SettingsEntry Settings : : indentStyle ( " editor " , " indentStyle " , values ( " Spaces " , _ ( " Spaces " ) , " Tabs " , _ ( " Tabs " ) ) , Value ( " Spaces " ) ) ;
SettingsEntry Settings : : tabKeyFunction ( " editor " , " tabKeyFunction " , values ( " Indent " , _ ( " Indent " ) , " InsertTab " , _ ( " Insert Tab " ) ) , Value ( " Indent " ) ) ;
SettingsEntry Settings : : highlightCurrentLine ( " editor " , " highlightCurrentLine " , Value ( true ) , Value ( true ) ) ;
SettingsEntry Settings : : enableBraceMatching ( " editor " , " enableBraceMatching " , Value ( true ) , Value ( true ) ) ;
2014-12-29 02:29:09 +03:00
}