Skip to content

Commit

Permalink
Fix proxy icon response to modified buffers
Browse files Browse the repository at this point in the history
The proxy icon is only disabled when the current buffer is modified
(previously this happened when any buffer was modified).  This also has
the consequence that the dot in the red "close button" only appears when
the current buffer is modified.
  • Loading branch information
b4winckler committed Dec 19, 2010
1 parent 34d035c commit 50b3a7f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 28 deletions.
13 changes: 5 additions & 8 deletions src/MacVim/MMAppController.m
Expand Up @@ -481,13 +481,11 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:
int reply = NSTerminateNow;
BOOL modifiedBuffers = NO;

// Go through windows, checking for modified buffers. (Each Vim process
// tells MacVim when any buffer has been modified and MacVim sets the
// 'documentEdited' flag of the window correspondingly.)
NSEnumerator *e = [[NSApp windows] objectEnumerator];
id window;
while ((window = [e nextObject])) {
if ([window isDocumentEdited]) {
// Go through Vim controllers, checking for modified buffers.
NSEnumerator *e = [vimControllers objectEnumerator];
id vc;
while ((vc = [e nextObject])) {
if ([vc hasModifiedBuffer]) {
modifiedBuffers = YES;
break;
}
Expand Down Expand Up @@ -519,7 +517,6 @@ - (NSApplicationTerminateReply)applicationShouldTerminate:

// Count the number of open tabs
e = [vimControllers objectEnumerator];
id vc;
while ((vc = [e nextObject]))
numTabs += [[vc objectForVimStateKey:@"numTabs"] intValue];

Expand Down
26 changes: 16 additions & 10 deletions src/MacVim/MMBackend.m
Expand Up @@ -191,7 +191,7 @@ - (void)handleDropString:(NSData *)data;
- (void)startOdbEditWithArguments:(NSDictionary *)args;
- (void)handleXcodeMod:(NSData *)data;
- (void)handleOpenWithArguments:(NSDictionary *)args;
- (BOOL)checkForModifiedBuffers;
- (int)checkForModifiedBuffers;
- (void)addInput:(NSString *)input;
- (void)redrawScreen;
- (void)handleFindReplace:(NSDictionary *)args;
Expand Down Expand Up @@ -1182,12 +1182,10 @@ - (void)setAntialias:(BOOL)antialias

- (void)updateModifiedFlag
{
// Notify MacVim if _any_ buffer has changed from unmodified to modified or
// vice versa.
int msgid = [self checkForModifiedBuffers]
? BuffersModifiedMsgID : BuffersNotModifiedMsgID;

[self queueMessage:msgid data:nil];
int state = [self checkForModifiedBuffers];
NSMutableData *data = [NSMutableData data];
[data appendBytes:&state length:sizeof(int)];
[self queueMessage:SetBuffersModifiedMsgID data:data];
}

- (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data
Expand Down Expand Up @@ -1818,6 +1816,8 @@ - (void)insertVimStateMessage
nil];

// Put the state before all other messages.
// TODO: If called multiple times the oldest state will be used! Should
// remove any current Vim state messages from the queue first.
int msgid = SetVimStateMsgID;
[outputQueue insertObject:[vimState dictionaryAsData] atIndex:0];
[outputQueue insertObject:[NSData dataWithBytes:&msgid length:sizeof(int)]
Expand Down Expand Up @@ -2836,16 +2836,22 @@ - (void)handleOpenWithArguments:(NSDictionary *)args
}
}

- (BOOL)checkForModifiedBuffers
- (int)checkForModifiedBuffers
{
// Return 1 if current buffer is modified, -1 if other buffer is modified,
// otherwise return 0.

if (curbuf && bufIsChanged(curbuf))
return 1;

buf_T *buf;
for (buf = firstbuf; buf != NULL; buf = buf->b_next) {
if (bufIsChanged(buf)) {
return YES;
return -1;
}
}

return NO;
return 0;
}

- (void)addInput:(NSString *)input
Expand Down
2 changes: 2 additions & 0 deletions src/MacVim/MMVimController.h
Expand Up @@ -34,6 +34,7 @@
NSDictionary *vimState;
BOOL isPreloading;
NSDate *creationDate;
BOOL hasModifiedBuffer;
}

- (id)initWithBackend:(id)backend pid:(int)processIdentifier;
Expand All @@ -48,6 +49,7 @@
- (NSMenu *)mainMenu;
- (BOOL)isPreloading;
- (void)setIsPreloading:(BOOL)yn;
- (BOOL)hasModifiedBuffer;
- (NSDate *)creationDate;
- (void)cleanup;
- (void)dropFiles:(NSArray *)filenames forceOpen:(BOOL)force;
Expand Down
24 changes: 20 additions & 4 deletions src/MacVim/MMVimController.m
Expand Up @@ -220,6 +220,11 @@ - (void)setIsPreloading:(BOOL)yn
isPreloading = yn;
}

- (BOOL)hasModifiedBuffer
{
return hasModifiedBuffer;
}

- (NSDate *)creationDate
{
return creationDate;
Expand Down Expand Up @@ -765,10 +770,21 @@ - (void)handleMessage:(int)msgid data:(NSData *)data
[windowController enterFullscreen:fuoptions backgroundColor:back];
} else if (LeaveFullscreenMsgID == msgid) {
[windowController leaveFullscreen];
} else if (BuffersNotModifiedMsgID == msgid) {
[windowController setBuffersModified:NO];
} else if (BuffersModifiedMsgID == msgid) {
[windowController setBuffersModified:YES];
} else if (SetBuffersModifiedMsgID == msgid) {
const void *bytes = [data bytes];
// state < 0 <-> some buffer modified
// state > 0 <-> current buffer modified
int state = *((int*)bytes); bytes += sizeof(int);

// NOTE: The window controller tracks whether current buffer is
// modified or not (and greys out the proxy icon as well as putting a
// dot in the red "close button" if necessary). The Vim controller
// tracks whether any buffer has been modified (used to decide whether
// to show a warning or not when quitting).
//
// TODO: Make 'hasModifiedBuffer' part of the Vim state?
[windowController setBufferModified:(state > 0)];
hasModifiedBuffer = (state != 0);
} else if (SetPreEditPositionMsgID == msgid) {
const int *dim = (const int*)[data bytes];
[[[windowController vimView] textView] setPreEditRow:dim[0]
Expand Down
2 changes: 1 addition & 1 deletion src/MacVim/MMWindowController.h
Expand Up @@ -79,7 +79,7 @@
- (void)leaveFullscreen;
- (void)setFullscreenBackgroundColor:(NSColor *)back;

- (void)setBuffersModified:(BOOL)mod;
- (void)setBufferModified:(BOOL)mod;
- (void)setTopLeft:(NSPoint)pt;
- (BOOL)getDefaultTopLeft:(NSPoint*)pt;

Expand Down
2 changes: 1 addition & 1 deletion src/MacVim/MMWindowController.m
Expand Up @@ -670,7 +670,7 @@ - (void)setFullscreenBackgroundColor:(NSColor *)back
[fullscreenWindow setBackgroundColor:back];
}

- (void)setBuffersModified:(BOOL)mod
- (void)setBufferModified:(BOOL)mod
{
// NOTE: We only set the document edited flag on the decorated window since
// the full-screen window has no close button anyway. (It also saves us
Expand Down
3 changes: 1 addition & 2 deletions src/MacVim/MacVim.h
Expand Up @@ -158,8 +158,7 @@ enum {
SetServerNameMsgID,
EnterFullscreenMsgID,
LeaveFullscreenMsgID,
BuffersNotModifiedMsgID,
BuffersModifiedMsgID,
SetBuffersModifiedMsgID,
AddInputMsgID,
SetPreEditPositionMsgID,
TerminateNowMsgID,
Expand Down
3 changes: 1 addition & 2 deletions src/MacVim/MacVim.m
Expand Up @@ -68,8 +68,7 @@
"SetServerNameMsgID",
"EnterFullscreenMsgID",
"LeaveFullscreenMsgID",
"BuffersNotModifiedMsgID",
"BuffersModifiedMsgID",
"SetBuffersModifiedMsgID",
"AddInputMsgID",
"SetPreEditPositionMsgID",
"TerminateNowMsgID",
Expand Down

0 comments on commit 50b3a7f

Please sign in to comment.