Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: joachimm/dialog
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: textmate/dialog
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.

Commits on Sep 18, 2012

  1. Fix x-insert command

    - now insert_text() and insert_snippet() will look for the front most text view before inserting
    - if no text view was found a new document will be created before inserting
    - for insert_snippet(): after insertion the key input focus will set to the found text view after insertion since a snippet needs user interaction afterwards
    Hans-Jörg Bibiko authored and sorbits committed Sep 18, 2012
    Copy the full SHA
    73e1ad0 View commit details
  2. Use less private selectors

    Those used are likely to change in the future.
    sorbits committed Sep 18, 2012
    Copy the full SHA
    6a1dc94 View commit details
  3. Simplify view search code

    We do a breadth first search starting with first responder and then content view so we still get the advantage of finding the view quickly but avoid duplicated code.
    sorbits committed Sep 18, 2012
    Copy the full SHA
    5eb3c82 View commit details

Commits on Oct 24, 2012

  1. Added command 'filepanel'

    - shows an Open File Panel or a Save File Panel
    - returns a plist with keys 'clickedButton' and 'path' for one file or 'paths' for more than one file
    - see help for option list
    Hans-Jörg Bibiko authored and sorbits committed Oct 24, 2012
    Copy the full SHA
    0894fc3 View commit details

Commits on Nov 16, 2012

  1. Add license.

    infininight committed Nov 16, 2012
    Copy the full SHA
    d251aab View commit details

Commits on Dec 19, 2012

  1. Explicitly disable ARC

    sorbits committed Dec 19, 2012
    Copy the full SHA
    07964e3 View commit details

Commits on Dec 30, 2012

  1. Copy the full SHA
    5d39b24 View commit details

Commits on Jan 17, 2013

  1. Turn nil arguments into empty strings

    With bindings, a text field is likely to set its value to ‘nil’ when the contained string is empty.
    
    Related to textmate/textmate#584 (though the API mentioned there is using the older dialog plug-in).
    sorbits committed Jan 17, 2013
    Copy the full SHA
    80b3c8d View commit details

Commits on Feb 16, 2013

  1. Copy the full SHA
    02733af View commit details

Commits on Mar 20, 2013

  1. Copy the full SHA
    179528b View commit details

Commits on Nov 2, 2013

  1. Copy the full SHA
    60dde1f View commit details

Commits on Mar 3, 2014

  1. Use C++11 for-loop

    sorbits committed Mar 3, 2014
    Copy the full SHA
    f872370 View commit details
  2. Copy the full SHA
    4c8dc61 View commit details

Commits on Mar 5, 2014

  1. Copy the full SHA
    b13159a View commit details
  2. Do not translate NSScrollWheel events to up/down (in pop-up menu)

    Instead we send the events to the window so that the list scrolls (without changing selection).
    sorbits committed Mar 5, 2014
    Copy the full SHA
    2e873f8 View commit details
  3. Adjust pop-up menu width to widest row

    Previously we would go by string length and multiply it by 18 (average width of a character?) to get the width. The width would not be allowed to exceed 340, this has now been increased to 600. Furthermore, the width would never decrease, unsure if this was to limit visual distractions or if it was because the width was a heuristic, so there was a chance that the calculated width was too small to have the rows fit, and by newer shrinking the menu’s width, we would decrease the chance of this happening.
    sorbits committed Mar 5, 2014
    Copy the full SHA
    d32b5c8 View commit details

Commits on Mar 6, 2014

  1. Copy the full SHA
    506388e View commit details

Commits on Apr 1, 2014

  1. Let HTML tool tips use same font as TextMate

    The existing code was for TextMate 1.x (and an OS where Monaco was the default fixed width system font).
    sorbits committed Apr 1, 2014
    Copy the full SHA
    fb41293 View commit details
  2. Copy the full SHA
    ee1cf36 View commit details

Commits on Sep 11, 2014

  1. Copy the full SHA
    fdb66f6 View commit details
  2. Remove workaround for signatureWithObjCTypes:

    This was made public in 10.5.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    2ff5a03 View commit details
  3. Remove workaround for WebView setDrawsBackground:

    We no longer support versions of Mac OS X where is this not available.
    
    Also, updated usage string to remove mention of 10.5.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    87a8532 View commit details
  4. Update to new APIs for reading/writing plists

    These do not cause a problem yet, but the new APIs follow proper Cocoa memory management rules and will make upgrading to ARC easier.
    
    Also, since we now return an NSError instead of an NSString, we should not expect upon successful completion that these methods will return nil for the passed NSError object.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    2f5d738 View commit details
  5. Copy the full SHA
    d0f1869 View commit details
  6. camelCase local variables

    rdwampler committed Sep 11, 2014
    Copy the full SHA
    9b21d9f View commit details
  7. Don't mix BOOL and bool

    rdwampler committed Sep 11, 2014
    Copy the full SHA
    4ca66bc View commit details
  8. Copy the full SHA
    1d46482 View commit details
  9. Use anonymous categories to declare private interfaces

    Anonymous and named categories actual behave differently. Using the latter, prevents us from declaring (private) properties.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    7019c37 View commit details
  10. Copy the full SHA
    fe560ab View commit details
  11. Update to ARC

    rdwampler committed Sep 11, 2014
    Copy the full SHA
    fff3e32 View commit details
  12. Don't use the pre-processor to declare a string constant

    Also, renamed DialogServerConnectionName → kDialogServerConnectionName. This is more consistent with the TextMate coding style.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    8e281dc View commit details
  13. Use proper exit codes

    rdwampler committed Sep 11, 2014
    Copy the full SHA
    4bb393e View commit details
  14. Remove debug statements

    rdwampler committed Sep 11, 2014
    Copy the full SHA
    675612f View commit details
  15. Remove include guard

    rdwampler committed Sep 11, 2014
    Copy the full SHA
    8d94714 View commit details
  16. Improve help message

    I added a usage statement to the help message and did some refactoring in order to alphabetize the list of registered commands along with some minor fixes, such as removing the redundant "help" in the invocation string when running "$DIALOG" help help.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    813a177 View commit details
  17. Use Core Animation to fade out tooltips

    This code was based on recent changes (db2c7982929a16da8abf9a0da20ac0b1ccccad01) made to OakToolTip in the main TextMate repository.
    rdwampler committed Sep 11, 2014
    Copy the full SHA
    68fadb9 View commit details

Commits on Sep 13, 2014

  1. Copy the full SHA
    de96a2d View commit details
  2. Avoid typecast and return instancetype from factory class method

    The typecast was required because there are multiple initWithOptions: methods and alloc used to return ‘id’, but it now returns ‘instancetype’ (which is why we need to send the alloc message to ‘CLIProxy’ instead of ‘[self class]’).
    sorbits committed Sep 13, 2014
    Copy the full SHA
    8a5317d View commit details
  3. Speedup tool-tip fadeout except when closing due to mouse moved

    This mimics commit 5d4fe11e707672f43f95c33a1bf975919ecf1733 (in the TextMate source).
    sorbits committed Sep 13, 2014
    Copy the full SHA
    1612829 View commit details

Commits on Sep 16, 2014

  1. CLIProxy: Use properties

    rdwampler committed Sep 16, 2014
    Copy the full SHA
    10f7f29 View commit details
  2. Don't use ASCII format property list for returning results

    All the other commands return an XML formatted plist. I do not think this will break anything, unless someone is manually parsing the results from this command. If so, they should use the tm_helpers `from_plist`.
    rdwampler committed Sep 16, 2014
    Copy the full SHA
    3048f8d View commit details
  3. Remove NSFileHandle category

    This category was introduced (9630995) to avoid repeatedly typing:
    
        [foo writeData:[@"bar" dataUsingEncoding:NSUTF8StringEncoding]];.
    
    However, it has since been superseded by `writeStringToOutput` and `writeStringToError`. So let's remove it and let these methods use the original call shown above.
    rdwampler committed Sep 16, 2014
    Copy the full SHA
    580bbc0 View commit details
  4. Copy the full SHA
    0781f47 View commit details
  5. Copy the full SHA
    60305f6 View commit details
  6. Copy the full SHA
    926a36f View commit details
  7. Remove ErrorAndReturn macro

    This macro was called multiple times before commit 2030fd1 but now this is the only place where it's used, so let's just remove it.
    rdwampler committed Sep 16, 2014
    Copy the full SHA
    e1ea1b3 View commit details
  8. Move ivar declarations to their class extensions

    This is really just to make the code style more similar to the TextMate source.
    rdwampler committed Sep 16, 2014
    Copy the full SHA
    83dd3d4 View commit details
  9. Copy the full SHA
    fda2794 View commit details
  10. Copy the full SHA
    36b9e81 View commit details
  11. Delete Dialog2_Prefix.pch on disk

    We removed the Xcode project (6388785), which contained the original build system. Since we now use the custom build system in the TextMate source (along with it's precompiled headers), let's delete it.
    rdwampler committed Sep 16, 2014
    Copy the full SHA
    a93bf26 View commit details
57 changes: 14 additions & 43 deletions CLIProxy.h
Original file line number Diff line number Diff line change
@@ -5,50 +5,21 @@
// Created by Ciaran Walsh on 16/02/2008.
//

#import <Cocoa/Cocoa.h>
#import "OptionParser.h"

@interface CLIProxy : NSObject
{
NSDictionary* environment;
NSString* workingDirectory;

NSFileHandle* inputHandle;
NSFileHandle* outputHandle;
NSFileHandle* errorHandle;

option_t const* optionTemplate;
size_t optionCount;
NSArray* arguments;
NSDictionary* parsedOptions;

NSDictionary* parameters;
}
+ (id)proxyWithOptions:(NSDictionary*)options;
- (id)initWithOptions:(NSDictionary*)options;

- (void)writeStringToOutput:(NSString*)text;
- (void)writeStringToError:(NSString*)text;
@property (nonatomic, readonly) NSFileHandle* inputHandle;
@property (nonatomic, readonly) NSFileHandle* outputHandle;
@property (nonatomic, readonly) NSFileHandle* errorHandle;
@property (nonatomic, readonly) NSDictionary* parameters;
@property (nonatomic, readonly) NSDictionary* environment;
@property (nonatomic, readonly) NSString* workingDirectory;

+ (instancetype)proxyWithOptions:(NSDictionary*)options;
- (instancetype)initWithOptions:(NSDictionary*)options;

- (void)writeStringToOutput:(NSString*)aString;
- (void)writeStringToError:(NSString*)aString;
- (id)readPropertyListFromInput;

- (NSDictionary*)parameters;

- (NSFileHandle*)inputHandle;
- (NSFileHandle*)outputHandle;
- (NSFileHandle*)errorHandle;

- (NSDictionary*)environment;

- (NSString*)workingDirectory;

- (NSString*)argumentAtIndex:(int)index;
- (int)numberOfArguments;

- (id)valueForOption:(NSString*)option;
- (void)setOptionTemplate:(option_t const*)options count:(size_t)count;
- (NSString*)argumentAtIndex:(NSUInteger)index;
- (NSUInteger)numberOfArguments;
@end

template <size_t optionCount> void SetOptionTemplate(CLIProxy* proxy, option_t const (&options)[optionCount])
{
[proxy setOptionTemplate:options count:optionCount];
}
158 changes: 49 additions & 109 deletions CLIProxy.mm
Original file line number Diff line number Diff line change
@@ -8,162 +8,102 @@
#import "CLIProxy.h"
#import "TMDCommand.h"

@interface CLIProxy (Private)
- (NSArray*)arguments;
@interface CLIProxy ()
{
NSArray* _arguments;
NSDictionary* _parameters;
}
@end

@implementation CLIProxy
+ (id)proxyWithOptions:(NSDictionary*)options;
+ (instancetype)proxyWithOptions:(NSDictionary*)options;
{
return [[(CLIProxy*)[[self class] alloc] initWithOptions:options] autorelease];
return [[CLIProxy alloc] initWithOptions:options];
}

- (id)initWithOptions:(NSDictionary*)options
- (instancetype)initWithOptions:(NSDictionary*)options
{
if(self = [super init])
{
inputHandle = [[NSFileHandle fileHandleForReadingAtPath:[options objectForKey:@"stdin"]] retain];
outputHandle = [[NSFileHandle fileHandleForWritingAtPath:[options objectForKey:@"stdout"]] retain];
errorHandle = [[NSFileHandle fileHandleForWritingAtPath:[options objectForKey:@"stderr"]] retain];
arguments = [[options objectForKey:@"arguments"] retain];
environment = [[options objectForKey:@"environment"] retain];
workingDirectory = [[options objectForKey:@"cwd"] retain];
_inputHandle = [NSFileHandle fileHandleForReadingAtPath:[options objectForKey:@"stdin"]];
_outputHandle = [NSFileHandle fileHandleForWritingAtPath:[options objectForKey:@"stdout"]];
_errorHandle = [NSFileHandle fileHandleForWritingAtPath:[options objectForKey:@"stderr"]];
_arguments = [options objectForKey:@"arguments"];
_environment = [options objectForKey:@"environment"];
_workingDirectory = [options objectForKey:@"cwd"];
}
return self;
}

- (void)dealloc
{
[inputHandle release];
[outputHandle release];
[errorHandle release];
[arguments release];
[environment release];
[workingDirectory release];
[parameters release];
[super dealloc];
}

- (NSDictionary*)parameters
{
if(!parameters)
if(!_parameters)
{
NSMutableDictionary* res = [NSMutableDictionary dictionary];
if(id plist = [TMDCommand readPropertyList:[self inputHandle] error:NULL])
if(id plist = [TMDCommand readPropertyList:self.inputHandle error:NULL])
{
if([plist isKindOfClass:[NSDictionary class]])
res = plist;
}

NSString* lastKey = nil;
for(size_t i = 2; i < [arguments count]; ++i)
for(NSUInteger i = 2; i < [_arguments count]; )
{
NSString* arg = [arguments objectAtIndex:i];
BOOL isOption = [arg hasPrefix:@"--"];
if(lastKey)
[res setObject:(isOption ? [NSNull null] : arg) forKey:lastKey];
lastKey = isOption ? [arg substringFromIndex:2] : nil;
NSString* key = _arguments[i++];
if(![key hasPrefix:@"--"])
continue; // TODO Report unexpected argument to user

key = [key substringFromIndex:2];
NSString* value = i < _arguments.count ? _arguments[i] : @"";

if([value hasPrefix:@"--"] && ![value isEqualToString:@"--"])
{
value = @""; // We use NSString instead of NSNull because we may send mutableCopy to parameters
}
else
{
++i;
if([value isEqualToString:@"--"])
value = i < _arguments.count ? _arguments[i++] : @"";
}
res[key] = value;
}

if(lastKey)
[res setObject:[NSNull null] forKey:lastKey];

parameters = [res retain];
_parameters = res;
}
return parameters;
}

- (NSString*)workingDirectory
{
return workingDirectory;
return _parameters;
}

- (NSDictionary*)environment
- (NSUInteger)numberOfArguments;
{
return environment;
return [_arguments count];
}

- (NSArray*)arguments
- (NSString*)argumentAtIndex:(NSUInteger)index;
{
if(!parsedOptions)
return arguments;
return [parsedOptions objectForKey:@"literals"];
}

- (int)numberOfArguments;
{
return [[self arguments] count];
}

- (NSString*)argumentAtIndex:(int)index;
{
id argument = nil;
if([[self arguments] count] > index)
argument = [[self arguments] objectAtIndex:index];
return argument;
}

- (id)valueForOption:(NSString*)option;
{
if(!parsedOptions)
{
NSLog(@"Error: -valueForOption: called without first setting an option template");
return nil;
}
return [[parsedOptions objectForKey:@"options"] objectForKey:option];
}

- (void)parseOptions
{
parsedOptions = ParseOptions([self arguments], optionTemplate, optionCount);
}

- (void)setOptionTemplate:(option_t const*)options count:(size_t)count;
{
optionTemplate = options;
optionCount = count;
[self parseOptions];
return index < [_arguments count] ? _arguments[index] : nil;
}

// ===================
// = Reading/Writing =
// ===================
- (void)writeStringToOutput:(NSString*)text;
- (void)writeStringToOutput:(NSString*)aString;
{
[[self outputHandle] writeString:text];
[self.outputHandle writeData:[aString dataUsingEncoding:NSUTF8StringEncoding]];
}

- (void)writeStringToError:(NSString*)text;
- (void)writeStringToError:(NSString*)aString;
{
[[self errorHandle] writeString:text];
[self.errorHandle writeData:[aString dataUsingEncoding:NSUTF8StringEncoding]];
}

- (id)readPropertyListFromInput;
{
NSString* error = nil;
id plist = [TMDCommand readPropertyList:[self inputHandle] error:&error];
NSError* error = nil;
id plist = [TMDCommand readPropertyList:self.inputHandle error:&error];

if(error || !plist)
[self writeStringToError:error ?: @"unknown error parsing property list\n"];
if(!plist)
[self writeStringToError:[error localizedDescription] ?: @"unknown error parsing property list\n"];

return plist;
}

// ================
// = File handles =
// ================
- (NSFileHandle*)inputHandle;
{
return inputHandle;
}

- (NSFileHandle*)outputHandle;
{
return outputHandle;
}

- (NSFileHandle*)errorHandle;
{
return errorHandle;
}
@end
102 changes: 97 additions & 5 deletions Commands/Utilities/TextMate.mm
Original file line number Diff line number Diff line change
@@ -1,17 +1,109 @@
#import "TextMate.h"

static CGFloat insertionDelayForNewDoc = 0.1;

// Declarations to avoid compiler warnings
@interface NSObject (OakTextViewPrivate)
- (id)insertSnippetWithOptions:(NSDictionary*)options;
- (void)insertSnippetWithOptions:(NSDictionary*)options;
- (void)makeTextViewFirstResponder:(id)sender;
- (void)newDocument:(id)sender;
@end

/**
Returns the front most text view and by reference:
- “isNew” – “YES” if no text view was found it was created a new document
- “winForTextView” – the NSWindow which contains the the front most text view
It returns “nil” if no text view could be found or created.
*/
id frontMostTextViewForSelector (SEL selector, BOOL* isNew, NSWindow** winForTextView)
{

// Return value if a new doc was created
if(isNew)
*isNew = NO;

// unique method for identifying a OakTextView
SEL checkSelector = @selector(insertSnippetWithOptions:);

// Find the front most OakTextView
for(NSWindow* win in [NSApp orderedWindows])
{
NSMutableArray* views = [NSMutableArray array];
if(id firstResponder = [win firstResponder])
[views addObject:firstResponder];
[views addObject:[win contentView]];

for(NSUInteger i = 0; i < [views count]; ++i)
{
id view = [views objectAtIndex:i];
if([view respondsToSelector:checkSelector] && [view respondsToSelector:selector])
{
if(winForTextView)
*winForTextView = win;
return view;
}

if([view respondsToSelector:@selector(subviews)])
[views addObjectsFromArray:[view performSelector:@selector(subviews)]];
}
}

// If no textView was found create a new document
if(id tmApp = [NSApp targetForAction:@selector(newDocument:)])
{

[tmApp newDocument:nil];

if([[NSApp orderedWindows] count]
&& [[[[NSApp orderedWindows] objectAtIndex:0] windowController] tryToPerform:
@selector(makeTextViewFirstResponder:) with:nil])
{
id textView = [NSApp targetForAction:checkSelector];
if(textView && [textView respondsToSelector:selector])
{
if(isNew)
*isNew = YES;
if(winForTextView)
*winForTextView = [[NSApp orderedWindows] objectAtIndex:0];
return textView;
}
}
}

return nil;

}

/**
Tries to insert “someText” as text into the front most text view.
*/
void insert_text (NSString* someText)
{
if(id textView = [NSApp targetForAction:@selector(insertText:)])
[textView insertText:someText];
BOOL isNewDocument = NO;
if(id textView = frontMostTextViewForSelector(@selector(insertText:), &isNewDocument, NULL))
{
if(isNewDocument) // delay the insertion to let TM finish the initialization of the new doc
[textView performSelector:@selector(insertText:) withObject:someText afterDelay:insertionDelayForNewDoc];
else [textView insertText:someText];
}
}

/**
Tries to insert “aSnippet” as snippet into the front most text view
and set the key focus to the current document.
*/
void insert_snippet (NSString* aSnippet)
{
if(id textView = [NSApp targetForAction:@selector(insertSnippetWithOptions:)])
[textView insertSnippetWithOptions:[NSDictionary dictionaryWithObject:aSnippet forKey:@"content"]];
BOOL isNewDocument = NO;
NSWindow* win = nil;
if(id textView = frontMostTextViewForSelector(@selector(insertSnippetWithOptions:), &isNewDocument, &win))
{
if(isNewDocument) // delay the insertion to let TM finish the initialization of the new doc
[textView performSelector:@selector(insertSnippetWithOptions:) withObject:[NSDictionary dictionaryWithObject:aSnippet forKey:@"content"] afterDelay:insertionDelayForNewDoc];
else [textView insertSnippetWithOptions: [NSDictionary dictionaryWithObject:aSnippet forKey:@"content"]];

// Since after inserting a snippet the user should interact with the snippet
// set key focus to current textView
[win makeKeyWindow];
}
}
Loading