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.

121 lines
3.0 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. // [[self window] setTitle: script];
  24. [interpreter reloadData];
  25. [interpreter setStringValue: [settings interpreter]];
  26. [honourhashbang setState: [settings honourhashbang]];
  27. [debug setState: [settings debug]];
  28. [verbose setState: [settings verbose]];
  29. [inspect setState: [settings inspect]];
  30. [optimize setState: [settings optimize]];
  31. [nosite setState: [settings nosite]];
  32. [tabs setState: [settings tabs]];
  33. [others setStringValue: [settings others]];
  34. [with_terminal setState: [settings with_terminal]];
  35. // Not scriptargs, it isn't for preferences
  36. [commandline setStringValue: [settings commandLineForScript: @"<your script here>"]];
  37. }
  38. - (void) windowDidLoad
  39. {
  40. [super windowDidLoad];
  41. [self load_defaults];
  42. [self update_display];
  43. }
  44. - (void)update_settings
  45. {
  46. [settings updateFromSource: self];
  47. }
  48. - (IBAction)do_filetype:(id)sender
  49. {
  50. [self load_defaults];
  51. [self update_display];
  52. }
  53. - (IBAction)do_reset:(id)sender
  54. {
  55. [settings reset];
  56. [self update_display];
  57. }
  58. - (IBAction)do_apply:(id)sender
  59. {
  60. [self update_settings];
  61. [self update_display];
  62. }
  63. // FileSettingsSource protocol
  64. - (NSString *) interpreter { return [interpreter stringValue];};
  65. - (BOOL) honourhashbang { return [honourhashbang state]; };
  66. - (BOOL) debug { return [debug state];};
  67. - (BOOL) verbose { return [verbose state];};
  68. - (BOOL) inspect { return [inspect state];};
  69. - (BOOL) optimize { return [optimize state];};
  70. - (BOOL) nosite { return [nosite state];};
  71. - (BOOL) tabs { return [tabs state];};
  72. - (NSString *) others { return [others stringValue];};
  73. - (BOOL) with_terminal { return [with_terminal state];};
  74. - (NSString *) scriptargs { return @"";};
  75. // Delegates
  76. - (void)controlTextDidChange:(NSNotification *)aNotification
  77. {
  78. [self update_settings];
  79. [self update_display];
  80. };
  81. // NSComboBoxDataSource protocol
  82. - (unsigned int)comboBox:(NSComboBox *)aComboBox indexOfItemWithStringValue:(NSString *)aString
  83. {
  84. NSArray *interp_list = [settings interpreters];
  85. unsigned int rv = [interp_list indexOfObjectIdenticalTo: aString];
  86. return rv;
  87. }
  88. - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)index
  89. {
  90. NSArray *interp_list = [settings interpreters];
  91. id rv = [interp_list objectAtIndex: index];
  92. return rv;
  93. }
  94. - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
  95. {
  96. NSArray *interp_list = [settings interpreters];
  97. int rv = [interp_list count];
  98. return rv;
  99. }
  100. @end