New Feature - Re: CVS: commit msevior abi/src/text/fmt/unix fv_UnixVisualDrag.cpp

From: <msevior_at_physics.unimelb.edu.au>
Date: Tue Mar 13 2007 - 08:58:53 CET

Hi everyone,
           This commit gives us a new feature on unix builds.We can now
drag and drop selections to Nautilus. Also dragging and
dropping a file from Nautilus to AbiWord now gives a regular
abiword the option of pasting the file into AbiWord via a
message box. The content of the message is:

dcl(MSG_PasteOrLoad, "Do you want to paste this into your document?
Answering \"No\" will open a new window with this file.")

The default is "yes" (I had to fix the Unix message box to make it honour
putting the default to yes.)

The behaviour for dropping the text on abiwidget window will be to paste
the text into the widget at the current caret point or selection.

The string will need to be translated for all Languages of course.

If you drag the text and drop it either on the background window or in a
Nautilus file browser, a new file appears containing the rtf
representation of the text with file name being the first 20 characters of
the dragged text.

I plan to now implement dragging and dropping of single emails to Nautilus
and the sugar shell next.

Cheers

Martin

>
> Update of /cvsroot/abi/src/text/fmt/unix
> In directory abiword.snt.utwente.nl:/tmp/cvs-serv1922/src/text/fmt/unix
>
> Modified Files:
> fv_UnixVisualDrag.cpp
> Log Message:
>
> Drag and drop content from AbiWord onto Nautilus. Drag and drop files from
> Nautilus to AbiWord now pops up an option to paste the file into abiword.
>
>
> Index: fv_UnixVisualDrag.cpp
> ===================================================================
> RCS file: /cvsroot/abi/src/text/fmt/unix/fv_UnixVisualDrag.cpp,v
> retrieving revision 1.3
> retrieving revision 1.4
> diff -u -d -r1.3 -r1.4
> --- fv_UnixVisualDrag.cpp 10 Mar 2007 00:45:39 -0000 1.3
> +++ fv_UnixVisualDrag.cpp 13 Mar 2007 05:16:08 -0000 1.4
> @@ -21,9 +21,25 @@
> #include "fv_View.h"
> #include "xap_Frame.h"
> #include "xap_UnixFrameImpl.h"
> +#include "xap_UnixApp.h"
> +#include "xap_App.h"
> +#include "ut_string.h"
> +#include <stdio.h>
> +#include "ut_uuid.h"
> +#include "pd_Document.h"
> +#include "ie_exp.h"
> +#include "ie_imp.h"
> +#include "ie_imp_RTF.h"
> +
> +#include <gsf/gsf-input.h>
> +#include <gsf/gsf-output.h>
> +#include <gsf/gsf-input-memory.h>
> +#include <gsf/gsf-output-memory.h>
> +#include <gsf/gsf-utils.h>
>
> static const GtkTargetEntry targets[] = {
> - {"text/rtf", 0, 0}};
> + {"text/rtf", 0, 0},
> + { "text/uri-list",0,0}};
>
> FV_UnixVisualDrag::FV_UnixVisualDrag (FV_View * pView)
> : FV_VisualDragText (pView),m_bDragOut(false)
> @@ -48,12 +64,94 @@
> }
> if(!m_bDragOut)
> {
> + //
> + // OK write text to a local file
> + //
> + XAP_UnixApp * pXApp = static_cast<XAP_UnixApp *>(XAP_App::getApp());
> + pXApp->removeTmpFile();
> + char ** pszTmpName = pXApp->getTmpFile();
> + const UT_ByteBuf * pBuf = m_pView->getLocalBuf();
> + UT_return_if_fail(pBuf);
> + //
> + // Create filename from contents
> + //
> + PD_Document * newDoc = new PD_Document(XAP_App::getApp());
> + newDoc->createRawDocument();
> + //
> + // This code is to generate a file name from the contents of the
> + // dragged text. The idea is to give user some clue as to the
> + // contents of the file dropped onto Nautilus
> + //
> + GsfInput * source = static_cast<GsfInput
> *>(gsf_input_memory_new(pBuf->getPointer(0),
> + pBuf->getLength(),
> + FALSE));
> + IE_Imp_RTF * imp = new IE_Imp_RTF(newDoc);
> + imp->importFile(source);
> + delete(imp);
> + newDoc->finishRawCreation();
> + g_object_unref(G_OBJECT(source));
> + //
> + // OK we've created a document with the contents of the drag
> + // buffer, now extract the first 20 characters and use it
> + // as the file name.
> + //
> + IEFileType file_type = IE_Exp::fileTypeForSuffix(".txt");
> + GsfOutputMemory* sink = GSF_OUTPUT_MEMORY(gsf_output_memory_new());
> + newDoc->saveAs(GSF_OUTPUT(sink),file_type, true);
> + gsf_output_close(GSF_OUTPUT(sink));
> + UT_UTF8String sRaw = reinterpret_cast<const char
> *>(gsf_output_memory_get_bytes (sink));
> + UT_UCS4String sUCS4 = sRaw.ucs4_str ();
> + UT_UCS4String sProc;
> + sProc.clear();
> + UT_uint32 size = sRaw.size();
> + if(size > 20 )
> + size = 20;
> + UT_uint32 i = 0;
> + //
> + // remove illegal filename characters
> + //
> + for(i=0; i<size; i++)
> + {
> + UT_UCS4Char u = sUCS4[i];
> + gchar c = static_cast<gchar>(sUCS4[i]);
> + bool b = true;
> + if((u < 128) && (c == ':' || c == ';' || c=='\'' || c==',' ||
> c=='"'
> + || c == '@' || c=='!' || c=='~' || c=='`' || c=='$' || c=='#'
> + || c == '%' || c=='*' || c=='(' || c==')' || c=='+'
> + || c == '{' || c=='[' || c=='}' || c==']' || c=='|'
> + || c == '\\' || c== '<' || c== '>' || c== '.' || c=='?'
> + || c=='/' || (c<32)))
> + {
> + b = false;
> + }
> + if(b)
> + {
> + sProc += u;
> + }
> + }
> + sRaw = sProc.utf8_str();
> + g_object_unref(G_OBJECT(sink));
> + UNREFP(newDoc);
> + UT_UTF8String sTmpF = g_get_tmp_dir();
> + sTmpF += "/";
> + sTmpF += sRaw;
> + sTmpF += ".rtf";
> + //
> + // Now write the contents of the buffer to a temp file.
> + //
> + FILE * fd = fopen(sTmpF.utf8_str(),"w");
> + fwrite(pBuf->getPointer(0),sizeof(UT_Byte),pBuf->getLength(),fd);
> + fclose(fd);
> + //
> + // Now setup the gtk drag and drop code to handle this.
> + //
> XAP_Frame * pFrame =
> static_cast<XAP_Frame*>(m_pView->getParentData());
> XAP_UnixFrameImpl * pFrameImpl =static_cast<XAP_UnixFrameImpl *>(
> pFrame->getFrameImpl());
> GtkWidget * pWindow = pFrameImpl->getTopLevelWindow();
> GtkTargetList *target_list = gtk_target_list_new(targets,
> G_N_ELEMENTS(targets));
> GdkDragContext *context = gtk_drag_begin(pWindow, target_list,
> (GdkDragAction)(GDK_ACTION_COPY ), 1, NULL);
> +
> gdk_drag_status(context, GDK_ACTION_COPY, 0);
> gtk_target_list_unref(target_list);
> m_bDragOut = true;
> @@ -62,6 +160,9 @@
> getGraphics()->setClipRect(NULL);
> setMode(FV_VisualDrag_NOT_ACTIVE);
> m_pView->setPrevMouseContext(EV_EMC_VISUALTEXTDRAG);
> + *pszTmpName = g_strdup(sTmpF.utf8_str());
> + UT_DEBUGMSG(("Created Tmp File %s XApp %s
> \n",sTmpF.utf8_str(),*pXApp->getTmpFile()));
> + m_bDragOut = true;
> return;
> }
> m_bDragOut = true;
>
> -----------------------------------------------
> To unsubscribe from this list, send a message to
> abisource-cvs-commit-request@abisource.com with the word
> unsubscribe in the message body.
>
Received on Tue Mar 13 08:58:49 2007

This archive was generated by hypermail 2.1.8 : Tue Mar 13 2007 - 08:58:50 CET