Re: [gedit-list] Exporting gedit_tab_save(_as)



Sorry forgot ChangeLog entry:

2006-06-18  Johannes Hoelzl <johannes hoelzl gmx de>
    
    * gedit/gedit-commands.h: New methods 
    gedit_commands_save_current_document(), 
    gedit_commands_save_documents_list(), 
    gedit_commands_save_all_documents().   
    Removed method _gedit_cmd_file_save_document_list().
    
    * gedit/gedit-commands-file.h 
      (gedit_commands_save_current_document, 
    gedit_commands_save_documents_list,      
    gedit_commands_save_all_documents):
    Added functions, to allow plugins to save documents.
    
    * bindings/python/gedit.defs, bindings/python/gedit.overwrite: 
    Added bindings for gedit_commands_load_uri, 
    gedit_commands_load_uris,
    gedit_commands_save_current_document, gedit_commands_save_all,
    gedit_commands_save_documents_list.


regards,
	Johannes
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gedit/ChangeLog,v
retrieving revision 1.778
diff -u -p -r1.778 ChangeLog
--- ChangeLog	18 Jun 2006 09:05:20 -0000	1.778
+++ ChangeLog	18 Jun 2006 14:00:35 -0000
@@ -1,3 +1,18 @@
+2006-06-18  Johannes Hoelzl <johannes hoelzl gmx de>
+    
+    * gedit/gedit-commands.h: New methods gedit_commands_save_current_document(), 
+    gedit_commands_save_documents_list(), gedit_commands_save_all_documents().   
+    Removed method _gedit_cmd_file_save_document_list().
+    
+    * gedit/gedit-commands-file.h (gedit_commands_save_current_document, 
+    gedit_commands_save_documents_list, gedit_commands_save_all_documents):
+    Added functions, to allow plugins to save documents.
+    
+    * bindings/python/gedit.defs, bindings/python/gedit.overwrite: 
+    Added bindings for gedit_commands_load_uri, gedit_commands_load_uris,
+    gedit_commands_save_current_document, gedit_commands_save_all,
+    gedit_commands_save_documents_list.
+    
 2006-06-18  Paolo Maggi  <paolo gnome org>
 
 	Reorganization of the Search menu
Index: bindings/python/gedit.defs
===================================================================
RCS file: /cvs/gnome/gedit/bindings/python/gedit.defs,v
retrieving revision 1.9
diff -u -p -r1.9 gedit.defs
--- bindings/python/gedit.defs	13 Jun 2006 10:51:52 -0000	1.9
+++ bindings/python/gedit.defs	18 Jun 2006 14:00:36 -0000
@@ -107,6 +107,16 @@
   )
 )
 
+(define-flags DocumentSaveFlags
+  (in-module "Gedit")
+  (c-name "GeditDocumentSaveFlags")
+  (values
+    '("save-ignore-mtime" "GEDIT_DOCUMENT_SAVE_IGNORE_MTIME")
+    '("save-ignore-backup" "GEDIT_DOCUMENT_SAVE_IGNORE_BACKUP")
+    '("save-preserve-backup" "GEDIT_DOCUMENT_SAVE_PRESERVE_BACKUP")
+  )
+)
+
 (define-flags WindowState
   (in-module "Gedit")
   (c-name "GeditWindowState")
@@ -934,5 +944,50 @@
   (parameters
     '("const-gchar*" "uri")
   )
+)
+
+;; From ../../gedit/gedit-commands.h
+
+(define-method commands_load_uri
+  (of-object "GeditWindow")
+  (c-name "gedit_commands_load_uri")
+  (return-type "none")
+  (parameters
+    '("const-gchar*" "uri")
+    '("const-GeditEncoding*" "encoding")
+    '("gint" "line_pos")
+  )
+)
+
+(define-method commands_load_uris
+  (of-object "GeditWindow")
+  (c-name "gedit_commands_load_uris")
+  (return-type "gint")
+  (parameters
+    '("GSList" "uris")
+    '("const-GeditEncoding*" "encoding")
+    '("gint" "line_pos")
+  )
+)
+
+(define-method commands_save_current_document
+  (of-object "GeditWindow")
+  (c-name "gedit_commands_save_current_document")
+  (return-type "none")
+)
+
+(define-method commands_save_documents_list
+  (of-object "GeditWindow")
+  (c-name "gedit_commands_save_documents_list")
+  (return-type "none")
+  (parameters
+    '("const-GList*" "docs")
+  )
+)
+
+(define-method commands_save_all_documents
+  (of-object "GeditWindow")
+  (c-name "gedit_commands_save_all_documents")
+  (return-type "none")
 )
 
Index: bindings/python/gedit.override
===================================================================
RCS file: /cvs/gnome/gedit/bindings/python/gedit.override,v
retrieving revision 1.5
diff -u -p -r1.5 gedit.override
--- bindings/python/gedit.override	13 Jun 2006 10:51:52 -0000	1.5
+++ bindings/python/gedit.override	18 Jun 2006 14:00:37 -0000
@@ -321,3 +321,151 @@ _wrap_gedit_tab_get_from_document_deprec
 	return NULL;
     return _wrap_gedit_tab_get_from_document(self, args, kwargs);
 }
+%%
+override gedit_commands_load_uris kwargs
+static PyObject *
+_wrap_gedit_commands_load_uris (PyGObject *self,
+				PyObject  *args,
+				PyObject  *kwargs)
+{
+    static char *kwlist[] = { "uris", "encoding", "line_pos", NULL };
+    PyObject *list, *item, *py_encoding = NULL;
+    int line_pos = 0;
+    GSList *gslist = NULL;
+    GeditEncoding *encoding = NULL;
+    int len, i;
+
+    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
+				  "O|Oi:GeditWindow.commands_load_uris", kwlist,
+				  &list, &py_encoding, &line_pos))
+	   return NULL;
+
+    if (py_encoding)
+    {
+        if (pyg_boxed_check(py_encoding, GEDIT_TYPE_ENCODING))
+            encoding = pyg_boxed_get(py_encoding, GeditEncoding);
+        else {
+            PyErr_SetString(PyExc_TypeError, "encoding should be a GeditEncoding");
+            return NULL;
+        }
+    }
+    
+    if (!PySequence_Check (list))
+    {
+        PyErr_SetString (PyExc_TypeError,
+                         "first argument must be a sequence");
+        return NULL;
+    }
+
+    len = PySequence_Length (list);
+
+    for (i = 0; i < len; i++)
+    {
+        item = PySequence_GetItem (list, i);
+        Py_DECREF(item);
+
+        if (!PyString_Check(item))
+        {
+            PyErr_SetString (PyExc_TypeError,
+                             "sequence item not a string");
+            g_slist_free (gslist);
+            return NULL;
+        }
+
+        gslist = g_slist_append (gslist, PyString_AsString(item));
+    }
+
+    gedit_commands_load_uris (GEDIT_WINDOW(self->obj), gslist, encoding, line_pos);
+
+    g_slist_free (gslist);
+    Py_INCREF (Py_None);
+    return Py_None;
+}
+%%
+override gedit_commands_load_uri kwargs
+static PyObject *
+_wrap_gedit_commands_load_uri (PyGObject *self,
+				PyObject  *args,
+				PyObject  *kwargs)
+{
+    static char *kwlist[] = { "uri", "encoding", "line_pos", NULL };
+    PyObject *uri, *py_encoding = NULL;
+    int line_pos = 0;
+    GeditEncoding *encoding = NULL;
+
+    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
+				  "O|Oi:GeditWindow.commands_load_uri", kwlist,
+				  &uri, &py_encoding, &line_pos))
+    	return NULL;
+
+    if (py_encoding)
+    {
+        if (pyg_boxed_check(py_encoding, GEDIT_TYPE_ENCODING))
+            encoding = pyg_boxed_get(py_encoding, GeditEncoding);
+        else {
+            PyErr_SetString(PyExc_TypeError, "encoding should be a GeditEncoding");
+            return NULL;
+        }
+    }
+    
+    if (!PyString_Check(uri))
+    {
+        PyErr_SetString (PyExc_TypeError,
+                         "uri not a string");
+        return NULL;
+    }
+
+    gedit_commands_load_uri (GEDIT_WINDOW(self->obj), PyString_AsString(uri), encoding, line_pos);
+
+    Py_INCREF (Py_None);
+    return Py_None;
+}
+%%
+override gedit_commands_save_documents_list kwargs
+static PyObject *
+_wrap_gedit_commands_save_documents_list (PyGObject *self,
+                                          PyObject  *args,
+                                          PyObject  *kwargs)
+{
+    static char *kwlist[] = { "docs", NULL };
+    PyObject *list, *item;
+    GList *glist = NULL;
+    int len, i;
+
+    if (!PyArg_ParseTupleAndKeywords (args, kwargs,
+				  "O:GeditWindow.commands_save_documents_list", kwlist,
+				  &list))
+        return NULL;
+
+    if (!PySequence_Check (list))
+    {
+        PyErr_SetString (PyExc_TypeError,
+                         "first argument must be a sequence");
+        return NULL;
+    }
+
+    len = PySequence_Length (list);
+
+    for (i = 0; i < len; i++)
+    {
+        item = PySequence_GetItem (list, i);
+        Py_DECREF(item);
+
+        if (!pygobject_check (item, &PyGeditDocument_Type))
+        {
+            PyErr_SetString (PyExc_TypeError,
+                             "sequence item not a GeditDocument object.");
+            g_list_free (glist);
+            return NULL;
+        }
+
+        glist = g_list_append (glist, pygobject_get (item));
+    }
+
+    gedit_commands_save_documents_list (GEDIT_WINDOW(self->obj), glist);
+
+    g_list_free (glist);
+    Py_INCREF (Py_None);
+    return Py_None;
+}
+%%
Index: gedit/gedit-commands-file.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands-file.c,v
retrieving revision 1.10
diff -u -p -r1.10 gedit-commands-file.c
--- gedit/gedit-commands-file.c	31 May 2006 15:40:12 -0000	1.10
+++ gedit/gedit-commands-file.c	18 Jun 2006 14:00:39 -0000
@@ -194,6 +194,12 @@ load_file_list (GeditWindow         *win
  * gedit_commands_load_uri:
  *
  * Do nothing if URI does not exist
+ *
+ * @window: The GEdit window in which the new file is loaded.
+ * @uri: The uri from which the file is loaded.
+ * @encoding: Either #NULL or the encoding in which the file is stored.
+ * @line_pos: The line at which the view is at the beginning. Set to 0 if no 
+ *            start line is requested.
  */
 void
 gedit_commands_load_uri (GeditWindow         *window,
@@ -216,9 +222,17 @@ gedit_commands_load_uri (GeditWindow    
 }
 
 /**
- * gedit_commands_load_uri:
+ * gedit_commands_load_uris:
+ *
+ * Do nothing if URI does not exist
  *
  * Ignore non-existing URIs 
+ *
+ * @window: The GEdit window in which the new file is loaded.
+ * @uris: A list of uris from which the files are loaded.
+ * @encoding: Either #NULL or the encoding in which the files are stored.
+ * @line_pos: The line at which the view is at the beginning. Set to 0 if no 
+ *            start line is requested.
  */
 gint
 gedit_commands_load_uris (GeditWindow         *window,
@@ -855,14 +869,19 @@ file_save (GeditTab    *tab,
 	_gedit_tab_save (tab);
 }
 
+
+/**
+ * gedit_commands_save_current_file:
+ *
+ * Saves the currently viewed file.
+ *
+ * @window: This windows current tab will be saved.
+ */
 void
-_gedit_cmd_file_save (GtkAction   *action,
-		     GeditWindow *window)
+gedit_commands_save_current_document (GeditWindow *window)
 {
 	GeditTab *tab;
 
-	gedit_debug (DEBUG_COMMANDS);
-
 	tab = gedit_window_get_active_tab (window);
 	if (tab == NULL)
 		return;
@@ -871,6 +890,15 @@ _gedit_cmd_file_save (GtkAction   *actio
 }
 
 void
+_gedit_cmd_file_save (GtkAction   *action,
+		     GeditWindow *window)
+{
+	gedit_debug (DEBUG_COMMANDS);
+
+	gedit_commands_save_current_document(window);
+}
+
+void
 _gedit_cmd_file_save_as (GtkAction   *action,
 			GeditWindow *window)
 {
@@ -885,12 +913,15 @@ _gedit_cmd_file_save_as (GtkAction   *ac
 	file_save_as (tab, window);
 }
 
-/*
- * The docs in the list must belong to the same GeditWindow.
+/**
+ * Saves a list of documents. 
+ *
+ * @window: The window whose documents are saved.
+ * @docs:   All documents in thsi list must belong to @window.
  */
 void
-_gedit_cmd_file_save_documents_list (GeditWindow *window,
-				     GList       *docs)
+gedit_commands_save_documents_list (GeditWindow *window,
+				    GList       *docs)
 {
 	GList *l;
 	GSList *tabs_to_save_as = NULL;
@@ -996,19 +1027,29 @@ _gedit_cmd_file_save_documents_list (Ged
 	}
 }
 
+/**
+ * Saves all unsaved documents of a window. 
+ *
+ * @window: The window whose documents are saved.
+ */
 void
-_gedit_cmd_file_save_all (GtkAction   *action,
-			 GeditWindow *window)
+gedit_commands_save_all_documents (GeditWindow *window)
 {
 	GList *docs;
 
-	gedit_debug (DEBUG_COMMANDS);
-
 	docs = gedit_window_get_documents (window);
 
-	_gedit_cmd_file_save_documents_list (window, docs);
+	gedit_commands_save_documents_list (window, docs);
 
 	g_list_free (docs);
+}
+
+void
+_gedit_cmd_file_save_all (GtkAction   *action,
+			 GeditWindow *window)
+{
+	gedit_debug (DEBUG_COMMANDS);
+	gedit_commands_save_all_documents(window);
 }
 
 /* File revert */
Index: gedit/gedit-commands.h
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-commands.h,v
retrieving revision 1.17
diff -u -p -r1.17 gedit-commands.h
--- gedit/gedit-commands.h	18 Jun 2006 09:05:20 -0000	1.17
+++ gedit/gedit-commands.h	18 Jun 2006 14:00:39 -0000
@@ -52,6 +52,11 @@ gint		 gedit_commands_load_uris		(GeditW
 							 const GeditEncoding *encoding,
 							 gint                 line_pos);
 
+void		 gedit_commands_save_current_document	(GeditWindow         *window);
+void		 gedit_commands_save_documents_list	(GeditWindow         *window,
+							 GList               *docs);
+void		 gedit_commands_save_all_documents	(GeditWindow         *window);
+
 /*
  * Non-exported functions
  */
@@ -150,9 +155,6 @@ void		_gedit_cmd_help_about			(GtkAction
 
 void		_gedit_cmd_file_close_tab 		(GeditTab    *tab,
 							 GeditWindow *window);
-
-void		_gedit_cmd_file_save_documents_list	(GeditWindow *window,
-							 GList       *docs);
 
 G_END_DECLS
 
Index: gedit/gedit-session.c
===================================================================
RCS file: /cvs/gnome/gedit/gedit/gedit-session.c,v
retrieving revision 1.13
diff -u -p -r1.13 gedit-session.c
--- gedit/gedit-session.c	22 May 2006 15:53:10 -0000	1.13
+++ gedit/gedit-session.c	18 Jun 2006 14:00:40 -0000
@@ -393,7 +393,7 @@ close_confirmation_dialog_response_handl
 					   GEDIT_SESSION_LIST_OF_DOCS_TO_SAVE,
 					   selected_documents);
 
-			_gedit_cmd_file_save_documents_list (window, selected_documents);
+			gedit_commands_save_documents_list (window, selected_documents);
 
 			/* FIXME: also need to lock the window to prevent further changes... */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]