SF.net SVN: geany: [1290] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Thu Feb 15 23:56:15 UTC 2007


Revision: 1290
          http://svn.sourceforge.net/geany/?rev=1290&view=rev
Author:   eht16
Date:     2007-02-15 15:56:15 -0800 (Thu, 15 Feb 2007)

Log Message:
-----------
Added possibility to create and open non-existent files from command line (closes #1635094 and #1652917).

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/callbacks.c
    trunk/src/document.c
    trunk/src/document.h
    trunk/src/keybindings.c
    trunk/src/main.c
    trunk/src/socket.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/ChangeLog	2007-02-15 23:56:15 UTC (rev 1290)
@@ -4,6 +4,10 @@
    Added several missing style types for filetype Perl
    (thanks to John Gabriele for reporting).
  * src/treeviews.c: Aligned "No symbols found" label to top.
+ * src/callbacks.c, src/document.c, src/document.h, src/keybindings.c,
+   src/main.c, src/socket.c:
+   Added possibility to create and open non-existent files from command
+   line (closes #1635094 and #1652917).
 
 
 2007-02-14  Frank Lanitz  <frank at frank.uvena.de>

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/src/callbacks.c	2007-02-15 23:56:15 UTC (rev 1290)
@@ -191,7 +191,7 @@
 on_new1_activate                       (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-	document_new_file(NULL);
+	document_new_file(NULL, NULL);
 }
 
 
@@ -199,7 +199,7 @@
 on_new_with_template                   (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-	document_new_file((filetype*) user_data);
+	document_new_file(NULL, (filetype*) user_data);
 }
 
 
@@ -546,7 +546,7 @@
 on_toolbutton8_clicked                 (GtkToolButton   *toolbutton,
                                         gpointer         user_data)
 {
-	document_new_file(NULL);
+	document_new_file(NULL, NULL);
 }
 
 // open file
@@ -1362,7 +1362,7 @@
 on_toolbutton_new_clicked              (GtkToolButton   *toolbutton,
                                         gpointer         user_data)
 {
-	document_new_file(NULL);
+	document_new_file(NULL, NULL);
 }
 
 

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/src/document.c	2007-02-15 23:56:15 UTC (rev 1290)
@@ -389,10 +389,12 @@
 
 
 /* This creates a new document, by clearing the text widget and setting the
-   current filename to NULL. */
-void document_new_file(filetype *ft)
+   current filename to filename or NULL. If ft is NULL and filename is not NULL, then the filetype
+   will be guessed from the given filename.
+   filename is expected in UTF-8 encoding. */
+gint document_new_file(const gchar *filename, filetype *ft)
 {
-	gint idx = document_create_new_sci(NULL);
+	gint idx = document_create_new_sci(filename);
 	gchar *template = templates_get_template_new_file(ft);
 
 	g_assert(idx != -1);
@@ -415,6 +417,9 @@
 	store_saved_encoding(idx);
 
 	//document_set_filetype(idx, (ft == NULL) ? filetypes[GEANY_FILETYPES_ALL] : ft);
+	if (ft == NULL && filename != NULL) // guess the filetype from the filename if one is given
+		ft = filetypes_get_from_filename(idx);
+
 	document_set_filetype(idx, ft);	// also clears taglist
 	if (ft == NULL) filetypes[GEANY_FILETYPES_ALL]->style_func_ptr(doc_list[idx].sci);
 	ui_set_window_title(idx);
@@ -425,7 +430,7 @@
 
 	document_update_tag_list(idx, FALSE);
 	document_set_text_changed(idx);
-	ui_document_show_hide(idx); //update the document menu
+	ui_document_show_hide(idx); // update the document menu
 
 	sci_set_line_numbers(doc_list[idx].sci, app->show_linenumber_margin, 0);
 	sci_goto_pos(doc_list[idx].sci, 0, TRUE);
@@ -434,7 +439,10 @@
 	g_signal_connect((GtkWidget*) doc_list[idx].sci, "sci-notify",
 				G_CALLBACK(on_editor_notification), GINT_TO_POINTER(idx));
 
-	msgwin_status_add(_("New file opened."));
+	msgwin_status_add(_("New file \"%s\" opened."),
+		(doc_list[idx].file_name != NULL) ? doc_list[idx].file_name : GEANY_STRING_UNTITLED);
+
+	return idx;
 }
 
 

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/src/document.h	2007-02-15 23:56:15 UTC (rev 1290)
@@ -123,8 +123,10 @@
 
 
 /* This creates a new document, by clearing the text widget and setting the
-   current filename to NULL. */
-void document_new_file(filetype *ft);
+   current filename to filename or NULL. If ft is NULL and filename is not NULL, then the filetype
+   will be guessed from the given filename.
+   filename is expected in UTF-8 encoding. */
+gint document_new_file(const gchar *filename, filetype *ft);
 
 
 /* If idx is set to -1, it creates a new tab, opens the file from filename and
@@ -133,7 +135,7 @@
  * idx and set the cursor to position 0. In this case, filename should be NULL
  * It returns the idx of the opened file or -1 if an error occurred.
  */
-int document_open_file(gint, const gchar*, gint, gboolean, filetype*, const gchar*);
+gint document_open_file(gint, const gchar*, gint, gboolean, filetype*, const gchar*);
 
 
 /* Takes a new line separated list of filename URIs and opens each file.
@@ -141,7 +143,7 @@
 void document_open_file_list(const gchar *data, gssize length);
 
 
-int document_reload_file(gint idx, const gchar *forced_enc);
+gint document_reload_file(gint idx, const gchar *forced_enc);
 
 
 /* This saves the file.

Modified: trunk/src/keybindings.c
===================================================================
--- trunk/src/keybindings.c	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/src/keybindings.c	2007-02-15 23:56:15 UTC (rev 1290)
@@ -469,7 +469,7 @@
 /* these are the callback functions, each shortcut has its own function, this is only for clear code */
 static void cb_func_menu_new(G_GNUC_UNUSED guint key_id)
 {
-	document_new_file(NULL);
+	document_new_file(NULL, NULL);
 }
 
 static void cb_func_menu_open(G_GNUC_UNUSED guint key_id)

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/src/main.c	2007-02-15 23:56:15 UTC (rev 1290)
@@ -484,7 +484,7 @@
 
 
 // open files from command line
-gboolean open_cl_files(gint argc, gchar **argv)
+static gboolean open_cl_files(gint argc, gchar **argv)
 {
 	gint i;
 
@@ -494,7 +494,7 @@
 	{
 		gchar *filename = get_argv_filename(argv[i]);
 
-		if (filename &&
+		if (filename != NULL &&
 			g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
 		{
 			gint idx;
@@ -504,6 +504,14 @@
 			if (DOC_IDX_VALID(idx))
 				ui_add_recent_file(doc_list[idx].file_name);
 		}
+		else if (filename != NULL)
+		{	// create new file if it doesn't exist
+			gint idx;
+
+			idx = document_new_file(filename, NULL);
+			if (DOC_IDX_VALID(idx))
+				ui_add_recent_file(doc_list[idx].file_name);
+		}
 		else
 		{
 			gchar *msg = _("Could not find file '%s'.");
@@ -648,7 +656,7 @@
 	app->opening_session_files = FALSE;
 
 	// open a new file if no other file was opened
-	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0)	document_new_file(NULL);
+	if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) == 0)	document_new_file(NULL, NULL);
 
 	ui_close_buttons_toggle();
 	ui_save_buttons_toggle(FALSE);

Modified: trunk/src/socket.c
===================================================================
--- trunk/src/socket.c	2007-02-15 23:20:41 UTC (rev 1289)
+++ trunk/src/socket.c	2007-02-15 23:56:15 UTC (rev 1290)
@@ -60,6 +60,7 @@
 #include "socket.h"
 #include "document.h"
 #include "support.h"
+#include "ui_utils.h"
 
 
 
@@ -125,8 +126,8 @@
 	{
 		filename = get_argv_filename(argv[i]);
 
-		if (filename != NULL &&
-			g_file_test(filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
+		// if the filename is valid or if a new file should be opened is check on the other side
+		if (filename != NULL)
 		{
 			socket_fd_write_all(sock, filename, strlen(filename));
 			socket_fd_write_all(sock, "\n", 1);
@@ -409,7 +410,15 @@
 				if (g_file_test(buf, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK))
 					document_open_file(-1, buf, 0, FALSE, NULL, NULL);
 				else
-					geany_debug("got data from socket, but it does not look like a filename");
+				{	// create new file if it doesn't exist
+					gint idx;
+
+					idx = document_new_file(buf, NULL);
+					if (DOC_IDX_VALID(idx))
+						ui_add_recent_file(doc_list[idx].file_name);
+					else
+						geany_debug("got data from socket, but it does not look like a filename");
+				}
 			}
 			gtk_window_deiconify(GTK_WINDOW(app->window));
 #ifdef G_OS_WIN32


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