[PATCH 1/2] vis: export vis_window_closable

From: Marc André Tanner <mat_AT_brain-dump.org>
Date: Sun, 7 Feb 2016 16:06:31 +0100

---
 vis-cmds.c | 10 ++--------
 vis.c      | 10 ++++++++++
 vis.h      |  3 +++
 3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/vis-cmds.c b/vis-cmds.c
index 3f612f4..b3dad5b 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
_AT_@ -429,19 +429,13 @@ static bool cmd_open(Vis *vis, Filerange *range, enum CmdOpt opt, const char *ar
 	return openfiles(vis, &argv[1]);
 }
 
-static bool is_view_closeable(Win *win) {
-	if (!text_modified(win->file->text))
-		return true;
-	return win->file->refcount > 1;
-}
-
 static void info_unsaved_changes(Vis *vis) {
 	vis_info_show(vis, "No write since last change (add ! to override)");
 }
 
 static bool cmd_edit(Vis *vis, Filerange *range, enum CmdOpt opt, const char *argv[]) {
 	Win *oldwin = vis->win;
-	if (!(opt & CMD_OPT_FORCE) && !is_view_closeable(oldwin)) {
+	if (!(opt & CMD_OPT_FORCE) && !vis_window_closable(oldwin)) {
 		info_unsaved_changes(vis);
 		return false;
 	}
_AT_@ -463,7 +457,7 @@ static bool has_windows(Vis *vis) {
 }
 
 static bool cmd_quit(Vis *vis, Filerange *range, enum CmdOpt opt, const char *argv[]) {
-	if (!(opt & CMD_OPT_FORCE) && !is_view_closeable(vis->win)) {
+	if (!(opt & CMD_OPT_FORCE) && !vis_window_closable(vis->win)) {
 		info_unsaved_changes(vis);
 		return false;
 	}
diff --git a/vis.c b/vis.c
index b65724c..42bc0a0 100644
--- a/vis.c
+++ b/vis.c
_AT_@ -284,6 +284,12 @@ bool vis_window_new(Vis *vis, const char *filename) {
 	return true;
 }
 
+bool vis_window_closable(Win *win) {
+	if (!text_modified(win->file->text))
+		return true;
+	return win->file->refcount > 1;
+}
+
 void vis_window_close(Win *win) {
 	Vis *vis = win->vis;
 	if (vis->event && vis->event->win_close)
_AT_@ -1090,6 +1096,10 @@ View *vis_view(Vis *vis) {
 	return vis->win->view;
 }
 
+Win *vis_window(Vis *vis) {
+	return vis->win;
+}
+
 Text *vis_file_text(File *file) {
 	return file->text;
 }
diff --git a/vis.h b/vis.h
index 3bcd9c7..eb84695 100644
--- a/vis.h
+++ b/vis.h
_AT_@ -67,6 +67,8 @@ void vis_suspend(Vis*);
 bool vis_window_new(Vis*, const char *filename);
 /* reload the file currently displayed in the window from disk */
 bool vis_window_reload(Win*);
+/* check whether closing the window would loose unsaved changes */
+bool vis_window_closable(Win*);
 /* close window, redraw user interface */
 void vis_window_close(Win*);
 /* split the given window. changes to the displayed text will be reflected
_AT_@ -405,6 +407,7 @@ bool vis_signal_handler(Vis*, int signum, const siginfo_t *siginfo, const void *
 /* TODO: expose proper API to iterate through files etc */
 Text *vis_text(Vis*);
 View *vis_view(Vis*);
+Win *vis_window(Vis*);
 Text *vis_file_text(File*);
 const char *vis_file_name(File*);
 
-- 
2.1.4
--BXVAT5kNtrzKuDFl
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-vis-implement-gf-and-C-w-gf-to-open-filename-under-c.patch"
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Feb 08 2016 - 03:48:10 CET