mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
GH-229 Send dirty status when changed to the UI
This commit is contained in:
parent
ea31a26676
commit
49cf51077c
@ -34,6 +34,7 @@ typedef NS_ENUM(NSUInteger, NeoVimServerMsgId) {
|
|||||||
NeoVimServerMsgIdSuspend,
|
NeoVimServerMsgIdSuspend,
|
||||||
NeoVimServerMsgIdSetTitle,
|
NeoVimServerMsgIdSetTitle,
|
||||||
NeoVimServerMsgIdSetIcon,
|
NeoVimServerMsgIdSetIcon,
|
||||||
|
NeoVimServerMsgIdDirtyStatusChanged,
|
||||||
NeoVimServerMsgIdStop,
|
NeoVimServerMsgIdStop,
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#import <nvim/event/signal.h>
|
#import <nvim/event/signal.h>
|
||||||
#import <nvim/main.h>
|
#import <nvim/main.h>
|
||||||
#import <nvim/ex_getln.h>
|
#import <nvim/ex_getln.h>
|
||||||
|
#import <nvim/fileio.h>
|
||||||
|
#import <nvim/undo.h>
|
||||||
|
|
||||||
|
|
||||||
#define pun_type(t, x) (*((t *)(&x)))
|
#define pun_type(t, x) (*((t *)(&x)))
|
||||||
@ -65,6 +67,8 @@ static int _marked_delta = 0;
|
|||||||
static int _put_row = -1;
|
static int _put_row = -1;
|
||||||
static int _put_column = -1;
|
static int _put_column = -1;
|
||||||
|
|
||||||
|
static bool _dirty = false;
|
||||||
|
|
||||||
static NSString *_backspace = nil;
|
static NSString *_backspace = nil;
|
||||||
|
|
||||||
static dispatch_queue_t _queue;
|
static dispatch_queue_t _queue;
|
||||||
@ -469,6 +473,22 @@ static void neovim_input(void **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void neovim_send_dirty_status(void **argv) {
|
||||||
|
@autoreleasepool {
|
||||||
|
bool new_dirty_status = server_has_dirty_docs();
|
||||||
|
// log4Debug("dirty status: %d vs. %d", _dirty, new_dirty_status);
|
||||||
|
if (_dirty == new_dirty_status) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_dirty = new_dirty_status;
|
||||||
|
// log4Debug("sending dirty status: %d", _dirty);
|
||||||
|
NSData *data = [[NSData alloc] initWithBytes:&_dirty length:sizeof(bool)];
|
||||||
|
[_neovim_server sendMessageWithId:NeoVimServerMsgIdDirtyStatusChanged data:data];
|
||||||
|
[data release];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void delete_marked_text() {
|
static void delete_marked_text() {
|
||||||
NSUInteger length = [_marked_text lengthOfBytesUsingEncoding:NSUTF32StringEncoding] / 4;
|
NSUInteger length = [_marked_text lengthOfBytesUsingEncoding:NSUTF32StringEncoding] / 4;
|
||||||
|
|
||||||
@ -523,6 +543,24 @@ void custom_ui_start(void) {
|
|||||||
ui_bridge_attach(ui, server_ui_main, server_ui_scheduler);
|
ui_bridge_attach(ui, server_ui_main, server_ui_scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void custom_ui_autocmds_groups(
|
||||||
|
event_T event, char_u *fname, char_u *fname_io, int group, bool force, buf_T *buf, exarg_T *eap
|
||||||
|
) {
|
||||||
|
log4Debug("got event %d for file %s in group %d.", event, fname, group);
|
||||||
|
switch (event) {
|
||||||
|
// Did we get them all?
|
||||||
|
case EVENT_TEXTCHANGED:
|
||||||
|
case EVENT_TEXTCHANGEDI:
|
||||||
|
case EVENT_BUFWRITEPOST:
|
||||||
|
case EVENT_BUFLEAVE:
|
||||||
|
loop_schedule(&main_loop, event_create(1, neovim_send_dirty_status, 0));
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void server_start_neovim() {
|
void server_start_neovim() {
|
||||||
_queue = dispatch_queue_create("com.qvacua.vimr.neovim-server.queue", DISPATCH_QUEUE_SERIAL);
|
_queue = dispatch_queue_create("com.qvacua.vimr.neovim-server.queue", DISPATCH_QUEUE_SERIAL);
|
||||||
|
|
||||||
@ -652,7 +690,11 @@ void server_insert_marked_text(NSString *markedText) {
|
|||||||
|
|
||||||
bool server_has_dirty_docs() {
|
bool server_has_dirty_docs() {
|
||||||
FOR_ALL_BUFFERS(buffer) {
|
FOR_ALL_BUFFERS(buffer) {
|
||||||
if (buffer->b_changed) {
|
if (buffer->b_p_bl == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bufIsChanged(buffer)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -673,6 +715,10 @@ NSString *server_escaped_filename(NSString *filename) {
|
|||||||
NSArray *server_buffers() {
|
NSArray *server_buffers() {
|
||||||
NSMutableArray <NeoVimBuffer *> *result = [[NSMutableArray new] autorelease];
|
NSMutableArray <NeoVimBuffer *> *result = [[NSMutableArray new] autorelease];
|
||||||
FOR_ALL_BUFFERS(buf) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
|
if (buf->b_p_bl == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
NSString *fileName = nil;
|
NSString *fileName = nil;
|
||||||
if (buf->b_ffname != NULL) {
|
if (buf->b_ffname != NULL) {
|
||||||
fileName = [NSString stringWithCString:(const char *) buf->b_ffname encoding:NSUTF8StringEncoding];
|
fileName = [NSString stringWithCString:(const char *) buf->b_ffname encoding:NSUTF8StringEncoding];
|
||||||
|
@ -383,6 +383,12 @@ static CFDataRef local_server_callback(CFMessagePortRef local, SInt32 msgid, CFD
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case NeoVimServerMsgIdDirtyStatusChanged: {
|
||||||
|
bool *values = data_to_bool_array(data, 1);
|
||||||
|
[_bridge setDirtyStatus:values[0]];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
case NeoVimServerMsgIdStop:
|
case NeoVimServerMsgIdStop:
|
||||||
[_bridge stop];
|
[_bridge stop];
|
||||||
return;
|
return;
|
||||||
|
@ -113,6 +113,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
- (void)suspend;
|
- (void)suspend;
|
||||||
- (void)setTitle:(NSString *)title;
|
- (void)setTitle:(NSString *)title;
|
||||||
- (void)setIcon:(NSString *)icon;
|
- (void)setIcon:(NSString *)icon;
|
||||||
|
- (void)setDirtyStatus:(bool)dirty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NeoVim has been stopped.
|
* NeoVim has been stopped.
|
||||||
|
@ -1162,6 +1162,12 @@ extension NeoVimView: NeoVimUiBridgeProtocol {
|
|||||||
public func setIcon(icon: String) {
|
public func setIcon(icon: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func setDirtyStatus(dirty: Bool) {
|
||||||
|
DispatchUtils.gui {
|
||||||
|
self.delegate?.setDirtyStatus(dirty)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func stop() {
|
public func stop() {
|
||||||
DispatchUtils.gui {
|
DispatchUtils.gui {
|
||||||
self.delegate?.neoVimStopped()
|
self.delegate?.neoVimStopped()
|
||||||
|
@ -9,6 +9,7 @@ import Cocoa
|
|||||||
public protocol NeoVimViewDelegate: class {
|
public protocol NeoVimViewDelegate: class {
|
||||||
|
|
||||||
func setTitle(title: String)
|
func setTitle(title: String)
|
||||||
|
func setDirtyStatus(dirty: Bool)
|
||||||
func neoVimReady()
|
func neoVimReady()
|
||||||
func neoVimStopped()
|
func neoVimStopped()
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,10 @@ extension MainWindowComponent {
|
|||||||
self.neoVimView.open(urls: self.urlsToBeOpenedWhenReady)
|
self.neoVimView.open(urls: self.urlsToBeOpenedWhenReady)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setDirtyStatus(dirty: Bool) {
|
||||||
|
self.windowController.setDocumentEdited(dirty)
|
||||||
|
}
|
||||||
|
|
||||||
func neoVimStopped() {
|
func neoVimStopped() {
|
||||||
self.windowController.close()
|
self.windowController.close()
|
||||||
}
|
}
|
||||||
|
2
neovim
2
neovim
@ -1 +1 @@
|
|||||||
Subproject commit f0b9c99c6395f770b1341f8b4270da1e3691143b
|
Subproject commit 504960182eec29a5b5e00547f2d7836eab324e1b
|
Loading…
Reference in New Issue
Block a user