You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.9 KiB

  1. #import "PreferencesWindowController.h"
  2. @implementation PreferencesWindowController
  3. + getPreferencesWindow
  4. {
  5. static PreferencesWindowController *_singleton;
  6. if (!_singleton)
  7. _singleton = [[PreferencesWindowController alloc] init];
  8. [_singleton showWindow: _singleton];
  9. return _singleton;
  10. }
  11. - (id) init
  12. {
  13. self = [self initWithWindowNibName: @"PreferenceWindow"];
  14. return self;
  15. }
  16. - (void)load_defaults
  17. {
  18. NSString *title = [filetype titleOfSelectedItem];
  19. settings = [FileSettings getDefaultsForFileType: title];
  20. }
  21. - (void)update_display
  22. {
  23. [interpreter reloadData];
  24. [interpreter setStringValue: [settings interpreter]];
  25. [honourhashbang setState: [settings honourhashbang]];
  26. [debug setState: [settings debug]];
  27. [verbose setState: [settings verbose]];
  28. [inspect setState: [settings inspect]];
  29. [optimize setState: [settings optimize]];
  30. [nosite setState: [settings nosite]];
  31. [tabs setState: [settings tabs]];
  32. [others setStringValue: [settings others]];
  33. [with_terminal setState: [settings with_terminal]];
  34. // Not scriptargs, it isn't for preferences
  35. [commandline setStringValue: [settings commandLineForScript: @"<your script here>"]];
  36. }
  37. - (void) windowDidLoad
  38. {
  39. [super windowDidLoad];
  40. [self load_defaults];
  41. [self update_display];
  42. }
  43. - (void)update_settings
  44. {
  45. [settings updateFromSource: self];
  46. }
  47. - (IBAction)do_filetype:(id)sender
  48. {
  49. [self load_defaults];
  50. [self update_display];
  51. }
  52. - (IBAction)do_reset:(id)sender
  53. {
  54. [settings reset];
  55. [self update_display];
  56. }
  57. - (IBAction)do_apply:(id)sender
  58. {
  59. [self update_settings];
  60. [self update_display];
  61. }
  62. // FileSettingsSource protocol
  63. - (NSString *) interpreter { return [interpreter stringValue];};
  64. - (BOOL) honourhashbang { return [honourhashbang state]; };
  65. - (BOOL) debug { return [debug state];};
  66. - (BOOL) verbose { return [verbose state];};
  67. - (BOOL) inspect { return [inspect state];};
  68. - (BOOL) optimize { return [optimize state];};
  69. - (BOOL) nosite { return [nosite state];};
  70. - (BOOL) tabs { return [tabs state];};
  71. - (NSString *) others { return [others stringValue];};
  72. - (BOOL) with_terminal { return [with_terminal state];};
  73. - (NSString *) scriptargs { return @"";};
  74. // Delegates
  75. - (void)controlTextDidChange:(NSNotification *)aNotification
  76. {
  77. [self update_settings];
  78. [self update_display];
  79. };
  80. // NSComboBoxDataSource protocol
  81. - (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString
  82. {
  83. NSArray *interp_list = [settings interpreters];
  84. unsigned int rv = [interp_list indexOfObjectIdenticalTo: aString];
  85. return rv;
  86. }
  87. - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index
  88. {
  89. NSArray *interp_list = [settings interpreters];
  90. id rv = [interp_list objectAtIndex: index];
  91. return rv;
  92. }
  93. - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
  94. {
  95. NSArray *interp_list = [settings interpreters];
  96. int rv = [interp_list count];
  97. return rv;
  98. }
  99. @end