[gedit: 7/17] Handle stdin
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit: 7/17] Handle stdin
- Date: Fri, 28 Dec 2012 19:03:19 +0000 (UTC)
commit 44761794cb5046eb5776a34a36e2d814c95579d4
Author: Paolo Borelli <pborelli gnome org>
Date: Fri Dec 28 19:54:04 2012 +0100
Handle stdin
Note that we now require "-" to be specified on the command line.
data/gedit.1 | 8 ++++++++
gedit/gedit-app.c | 21 ++++++++++++++++++++-
gedit/gedit-utils.c | 18 ------------------
gedit/gedit-utils.h | 2 --
4 files changed, 28 insertions(+), 21 deletions(-)
---
diff --git a/data/gedit.1 b/data/gedit.1
index f9cf513..e7bdc54 100644
--- a/data/gedit.1
+++ b/data/gedit.1
@@ -3,8 +3,13 @@
\fBgedit\fP \- text editor for the GNOME Desktop
.SH SYNOPSIS
+.br
.B gedit
[\fIOPTION\fR...] [\fIFILE\fR...] [+\fILINE\fR[:\fICOLUMN\fR]]
+.br
+.B gedit
+[\fIOPTION\fR...] -
+
.SH DESCRIPTION
.B gedit
is the official text editor of the GNOME desktop environment.
@@ -75,6 +80,9 @@ of a webpage to
, like "http://www.gnome.org", or load a file from a FTP server,
like "ftp://ftp.gnome.org/robots.txt".
.TP
+\fB-\fR
+.B gedit will read from stdin
+.TP
\fB+LINE\fR
For the first file, go to the line specified by LINE (do not insert a space between the "+" sign and the number).
If LINE is missing, go to the last line.
diff --git a/gedit/gedit-app.c b/gedit/gedit-app.c
index e0d5cbc..dc92016 100644
--- a/gedit/gedit-app.c
+++ b/gedit/gedit-app.c
@@ -114,6 +114,7 @@ static gboolean background = FALSE;
static gboolean standalone = FALSE;
static gchar **remaining_args = NULL;
static const GeditEncoding *encoding = NULL;
+static GInputStream *stdin_stream = NULL;
static GSList *file_list = NULL;
static gint line_position = 0;
static gint column_position = 0;
@@ -485,6 +486,19 @@ gedit_app_activate (GApplication *application)
geometry);
}
+ if (stdin_stream)
+ {
+ gedit_debug_message (DEBUG_APP, "Load stdin");
+
+ doc_created = gedit_window_create_tab_from_stream (window,
+ stdin_stream,
+ encoding,
+ line_position,
+ column_position,
+ TRUE) != NULL;
+ g_input_stream_close (stdin_stream, NULL, NULL);
+ }
+
if (file_list != NULL)
{
GSList *loaded;
@@ -496,7 +510,7 @@ gedit_app_activate (GApplication *application)
line_position,
column_position);
- doc_created = loaded != NULL;
+ doc_created = doc_created || loaded != NULL;
g_slist_free (loaded);
}
@@ -556,6 +570,7 @@ clear_options (void)
g_free (encoding_charset);
g_strfreev (remaining_args);
g_free (geometry);
+ g_clear_object (&stdin_stream);
g_slist_free_full (file_list, g_object_unref);
help = FALSE;
@@ -665,6 +680,10 @@ gedit_app_command_line (GApplication *application,
&column_position);
}
}
+ else if (*remaining_args[i] == '-' && *(remaining_args[i] + 1) == '\0')
+ {
+ stdin_stream = g_application_command_line_get_stdin (command_line);
+ }
else
{
GFile *file;
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index a04c6d1..4f00a60 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -1540,24 +1540,6 @@ gedit_utils_decode_uri (const gchar *uri,
return TRUE;
}
-gboolean
-gedit_utils_can_read_from_stdin (void)
-{
-#ifdef G_OS_UNIX
- if (!isatty (STDIN_FILENO))
- {
- struct stat sbuffer;
-
- if (fstat (STDIN_FILENO, &sbuffer) == 0 &&
- (S_ISREG (sbuffer.st_mode) || S_ISFIFO (sbuffer.st_mode) || S_ISLNK (sbuffer.st_mode)))
- {
- return TRUE;
- }
- }
-#endif
- return FALSE;
-}
-
GeditDocumentCompressionType
gedit_utils_get_compression_type_from_content_type (const gchar *content_type)
{
diff --git a/gedit/gedit-utils.h b/gedit/gedit-utils.h
index 18bda01..ed647f9 100644
--- a/gedit/gedit-utils.h
+++ b/gedit/gedit-utils.h
@@ -148,8 +148,6 @@ gboolean gedit_utils_decode_uri (const gchar *uri,
/* Turns data from a drop into a list of well formatted uris */
gchar **gedit_utils_drop_get_uris (GtkSelectionData *selection_data);
-gboolean gedit_utils_can_read_from_stdin (void);
-
GeditDocumentCompressionType
gedit_utils_get_compression_type_from_content_type
(const gchar *content_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]