SF.net SVN: geany:[4692] branches/sm

statc at users.sourceforge.net statc at xxxxx
Mon Feb 22 22:11:21 UTC 2010


Revision: 4692
          http://geany.svn.sourceforge.net/geany/?rev=4692&view=rev
Author:   statc
Date:     2010-02-22 22:11:21 +0000 (Mon, 22 Feb 2010)

Log Message:
-----------
Use a separate command-line option to specify a project to be opened.

Modified Paths:
--------------
    branches/sm/ChangeLog
    branches/sm/src/main.c
    branches/sm/src/main.h
    branches/sm/src/socket.c

Modified: branches/sm/ChangeLog
===================================================================
--- branches/sm/ChangeLog	2010-02-21 22:53:02 UTC (rev 4691)
+++ branches/sm/ChangeLog	2010-02-22 22:11:21 UTC (rev 4692)
@@ -1,3 +1,9 @@
+2010-02-22  Eugene Arshinov  <earshinov(at)gmail(dot)com>
+
+ * src/main.c, src/main.h, src/socket.c:
+   Use a separate command-line option to specify a project to be opened.
+
+
 2010-02-15  Eugene Arshinov  <earshinov(at)gmail(dot)com>
 
  * src/project.c, src/sm.c, src/utils.c, src/utils.h:

Modified: branches/sm/src/main.c
===================================================================
--- branches/sm/src/main.c	2010-02-21 22:53:02 UTC (rev 4691)
+++ branches/sm/src/main.c	2010-02-22 22:11:21 UTC (rev 4692)
@@ -119,8 +119,8 @@
 static gchar * libsm_client_id = NULL;
 
 /* WARNING: Do not change values of variables where values of command-line options are stored!
- * This is, they must remain unchanged after `g_option_context_parse' returns.
- * Otherwise, "restart command" for X session management will be filled improperly.
+ * This is, they should remain unchanged after `g_option_context_parse' returns.
+ * Otherwise, "restart command" for X session management may be filled improperly.
  *
  * NOTE: Currently optentries of type G_OPTION_ARG_CALLBACK are not supported by
  * X session management support implementation.
@@ -144,6 +144,7 @@
 	{ "no-plugins", 'p', 0, G_OPTION_ARG_NONE, &no_plugins, N_("Don't load plugins"), NULL },
 #endif
 	{ "print-prefix", 0, 0, G_OPTION_ARG_NONE, &print_prefix, N_("Print Geany's installation prefix"), NULL },
+	{ "project", 'r', 0, G_OPTION_ARG_FILENAME, &cl_options.project, N_("Open this project"), NULL },
 	{ "no-session", 's', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &cl_options.load_session, N_("Don't load and save session's files"), NULL },
 #ifdef HAVE_VTE
 	{ "no-terminal", 't', 0, G_OPTION_ARG_NONE, &no_vte, N_("Don't load terminal support"), NULL },
@@ -174,6 +175,7 @@
 	{TRUE},  /* "no-plugins" */
 #endif
 	{FALSE}, /* "print-prefix" */
+	{FALSE}, /* "project" option is handled separately */
 	{TRUE},  /* "no-session" */
 #ifdef HAVE_VTE
 	{TRUE},  /* "no-terminal" */
@@ -893,7 +895,6 @@
 {
 	gboolean load_default_session = TRUE;
 	gboolean load_session = FALSE;
-	gint files_argv_index = 0;
 	gboolean any_files_opened;
 
 	if (!prefs.load_session)
@@ -902,17 +903,16 @@
 		return;
 	}
 
-	if ((argc > 1) && g_str_has_suffix(argv[1], ".geany"))
+	if (cl_options.project)
 	{
 		/* load project filenames into global session_files variable */
-		main_load_project_from_command_line(argv[1], FALSE);
-		files_argv_index = 1;
+		main_load_project_from_command_line(cl_options.project, FALSE);
 
 		load_default_session = FALSE;
 		load_session = TRUE;
 	}
 
-	any_files_opened = open_cl_files(argc - files_argv_index, argv + files_argv_index);
+	any_files_opened = open_cl_files(argc, argv);
 	if (any_files_opened && !prefs.load_session_even_if_any_files_opened)
 		load_default_session = FALSE;
 
@@ -983,20 +983,20 @@
 		socket_info.lock_socket = socket_init(argc, argv);
 		if (socket_info.lock_socket == -2)
 		{
-			/* Socket exists */
-			if (argc > 1)	/* filenames were sent to first instance, so quit */
-			{
-				gdk_notify_startup_complete();
-				g_free(app->configdir);
-				g_free(app->datadir);
-				g_free(app->docdir);
-				g_free(app);
-				return 0;
-			}
-			/* Start a new instance if no command line strings were passed */
+			/* Socket exists, but there are no files to open. Start a new instance. */
 			socket_info.ignore_socket = TRUE;
 			cl_options.new_instance = TRUE;
 		}
+		else if (socket_info.lock_socket == -3)
+		{
+			/* Filenames were sent to first instance, so quit */
+			gdk_notify_startup_complete();
+			g_free(app->configdir);
+			g_free(app->datadir);
+			g_free(app->docdir);
+			g_free(app);
+			return 0;
+		}
 	}
 #endif
 

Modified: branches/sm/src/main.h
===================================================================
--- branches/sm/src/main.h	2010-02-21 22:53:02 UTC (rev 4691)
+++ branches/sm/src/main.h	2010-02-22 22:11:21 UTC (rev 4692)
@@ -47,6 +47,7 @@
 	gint		goto_line;
 	gint		goto_column;
 	gboolean	ignore_global_tags;
+	gchar	   *project;
 }
 CommandLineOptions;
 

Modified: branches/sm/src/socket.c
===================================================================
--- branches/sm/src/socket.c	2010-02-21 22:53:02 UTC (rev 4691)
+++ branches/sm/src/socket.c	2010-02-22 22:11:21 UTC (rev 4692)
@@ -42,7 +42,7 @@
  * The command window is only available on Windows and takes no additional data, instead it
  * writes back a Windows handle (HWND) for the main window to set it to the foreground (focus).
  *
- * At the moment the commands window, open, line and column are available.
+ * At the moment the commands window, open, line, column and project are available.
  *
  * About the socket files on Unix-like systems:
  * Geany creates a socket in /tmp (or any other directory returned by g_get_tmp_dir()) and
@@ -121,12 +121,14 @@
 
 
 
-void send_open_command(gint sock, gint argc, gchar **argv)
+/* Returns TRUE if any files were sent */
+gboolean send_open_command(gint sock, gint argc, gchar **argv)
 {
 	gint i;
 	gchar *filename;
 
-	g_return_if_fail(argc > 1);
+	if (argc == 1 && !cl_options.project)
+		return FALSE; /* nothing to send */
 	geany_debug("using running instance of Geany");
 
 	if (cl_options.goto_line >= 0)
@@ -147,6 +149,13 @@
 		g_free(col);
 	}
 
+	if (cl_options.project)
+	{
+		socket_fd_write_all(sock, "project\n", 8);
+		socket_fd_write_all(sock, cl_options.project, strlen(cl_options.project));
+		socket_fd_write_all(sock, "\n", 1);
+	}
+
 	socket_fd_write_all(sock, "open\n", 5);
 
 	for (i = 1; i < argc && argv[i] != NULL; i++)
@@ -167,6 +176,7 @@
 		g_free(filename);
 	}
 	socket_fd_write_all(sock, ".\n", 2);
+	return TRUE; /* files sent */
 }
 
 
@@ -193,8 +203,11 @@
 
 /* (Unix domain) socket support to replace the old FIFO code
  * (taken from Sylpheed, thanks)
- * Returns the created socket, -1 if an error occurred or -2 if another socket exists and files
- * were sent to it. */
+ * Returns
+ *   -1 if an error occurred
+ *   -2 if another socket exists and there are no files to send to it
+ *   -3 if another socket exists and files were sent to it
+ *   the created socket, otherwise */
 gint socket_init(gint argc, gchar **argv)
 {
 	gint sock;
@@ -229,6 +242,7 @@
 	gchar *display_name = gdk_get_display();
 	gchar *hostname = utils_get_hostname();
 	gchar *p;
+	gboolean files_sent;
 
 	if (display_name == NULL)
 		display_name = g_strdup("NODISPLAY");
@@ -263,13 +277,10 @@
 		SetForegroundWindow(hwnd);
 #endif
 	/* now we send the command line args */
-	if (argc > 1)
-	{
-		send_open_command(sock, argc, argv);
-	}
+	files_sent = send_open_command(sock, argc, argv);
 
 	socket_fd_close(sock);
-	return -2;
+	return files_sent ? -3 : -2;
 }
 
 
@@ -492,7 +503,7 @@
 #endif
 
 
-static void handle_input_filename(const gchar *buf)
+static void handle_input_filename(const gchar *buf, gboolean project)
 {
 	gchar *utf8_filename, *locale_filename;
 
@@ -505,7 +516,7 @@
 	locale_filename = utils_get_locale_from_utf8(utf8_filename);
 	if (locale_filename)
 	{
-		if (g_str_has_suffix(locale_filename, ".geany"))
+		if (project)
 			main_load_project_from_command_line(locale_filename, TRUE);
 		else
 			main_handle_filename(locale_filename);
@@ -534,7 +545,7 @@
 		{
 			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
 			{
-				handle_input_filename(g_strstrip(buf));
+				handle_input_filename(g_strstrip(buf), FALSE);
 			}
 			popup = TRUE;
 		}
@@ -556,6 +567,11 @@
 				cl_options.goto_column = atoi(buf);
 			}
 		}
+		else if (strncmp(buf, "project", 7) == 0)
+		{
+			if (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
+				handle_input_filename(g_strstrip(buf), TRUE);
+		}
 #ifdef G_OS_WIN32
 		else if (strncmp(buf, "window", 6) == 0)
 		{
@@ -711,5 +727,3 @@
 
 
 #endif
-
-


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list