Here's a fully functional version of my row pasting patch. It now always pastes into the * row, and prompts if you want to skip over serial columns or not. It should be good to go.

Ed

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

Index: frm/frmEditGrid.cpp
===================================================================
--- frm/frmEditGrid.cpp	(revision 5113)
+++ frm/frmEditGrid.cpp	(working copy)
@@ -44,6 +44,7 @@
 #include "images/sortfilter.xpm"
 #include "images/help.xpm"
 #include "images/clip_copy.xpm"
+#include "images/clip_paste.xpm"
 
 #define CTRLID_LIMITLABEL       4224
 #define CTRLID_LIMITSPACER      4225
@@ -58,6 +59,7 @@
     EVT_MENU(MNU_OPTIONS,   frmEditGrid::OnOptions)
     EVT_MENU(MNU_HELP,      frmEditGrid::OnHelp)
     EVT_MENU(MNU_COPY,      frmEditGrid::OnCopy)
+    EVT_MENU(MNU_PASTE,     frmEditGrid::OnPaste)
     EVT_CLOSE(              frmEditGrid::OnClose)
     EVT_KEY_DOWN(           frmEditGrid::OnKey)
     EVT_GRID_RANGE_SELECT(frmEditGrid::OnGridSelectCells)
@@ -101,6 +103,8 @@
     toolBar->AddSeparator();
     toolBar->AddTool(MNU_COPY, _("Copy"), wxBitmap(clip_copy_xpm), _("Copy selected lines to clipboard"), wxITEM_NORMAL);
     toolBar->AddSeparator();
+    toolBar->AddTool(MNU_PASTE, _("Paste"), wxBitmap(clip_paste_xpm), _("Paste text from the clipboard"), wxITEM_NORMAL);
+    toolBar->AddSeparator();
     toolBar->AddTool(MNU_DELETE, _("Delete"), wxBitmap(delete_xpm), _("Delete selected lines."), wxITEM_NORMAL);
     toolBar->AddSeparator();
 
@@ -128,14 +132,15 @@
     toolBar->EnableTool(MNU_COPY, true);
     toolBar->EnableTool(MNU_DELETE, false);
 
-    wxAcceleratorEntry entries[6];
+    wxAcceleratorEntry entries[7];
 
     entries[0].Set(wxACCEL_CTRL,                (int)'S',      MNU_SAVE);
     entries[1].Set(wxACCEL_NORMAL,              WXK_F5,        MNU_REFRESH);
     entries[2].Set(wxACCEL_CTRL,                (int)'Z',      MNU_UNDO);
     entries[3].Set(wxACCEL_NORMAL,              WXK_F1,        MNU_HELP);
     entries[4].Set(wxACCEL_CTRL,                (int)'C',      MNU_COPY);
-    entries[5].Set(wxACCEL_NORMAL,              WXK_DELETE,    MNU_DELETE);
+    entries[5].Set(wxACCEL_CTRL,                (int)'V',      MNU_PASTE);
+    entries[6].Set(wxACCEL_NORMAL,              WXK_DELETE,    MNU_DELETE);
     
     wxAcceleratorTable accel(6, entries);
     SetAcceleratorTable(accel);
@@ -236,6 +241,11 @@
 }
 
 
+void frmEditGrid::OnPaste(wxCommandEvent &ev)
+{
+    sqlGrid->GetTable()->Paste();
+}
+
 void frmEditGrid::OnHelp(wxCommandEvent &ev)
 {
     DisplayHelp(this, wxT("editgrid"), viewdata_xpm);
@@ -1722,6 +1732,112 @@
 }
 
 
+void sqlTable::Paste()
+{
+    int row, col;
+    int start, pos, len;
+    wxArrayString data;
+    wxString text, quoteChar, colSep;
+    bool inQuotes, inData, skipSerial;
+
+    if (wxTheClipboard->Open())
+    {
+        if (wxTheClipboard->IsSupported(wxDF_TEXT))
+        {
+            wxTextDataObject textData;
+            wxTheClipboard->GetData(textData);
+            text = textData.GetText();
+        }
+        else {
+            wxTheClipboard->Close();
+            return;
+        }
+        wxTheClipboard->Close();
+    }
+    else {
+        return;
+    }
+
+    start = pos = 0;
+    len = text.Len();
+    quoteChar = settings->GetCopyQuoteChar();
+    colSep = settings->GetCopyColSeparator();
+    inQuotes = inData = false;
+
+    while (pos < len && !(text[pos] == '\n' && !inQuotes))
+    {
+        if (!inData)
+        {
+            if (text[pos] == quoteChar)
+            {
+                inQuotes = inData = true;
+                pos++;
+                start++;
+                continue;
+            }
+            else
+            {
+                inQuotes = false;
+            }
+            inData = true;
+        }
+
+        if (inQuotes && text[pos] == quoteChar &&
+            text[pos+1] == colSep)
+        {
+            data.Add(text.Mid(start, pos - start));
+            start = (pos += 2);
+            inData = false;
+        }
+        else if (!inQuotes && text[pos] == colSep)
+        {
+            data.Add(text.Mid(start, pos - start));
+            start = ++pos;
+            inData = false;
+        }
+        else
+        {
+            pos++;
+        }
+    }
+    if (start < pos)
+    {
+        if (inQuotes && text[pos-1] == quoteChar)
+            data.Add(text.Mid(start, pos - start - 1));
+        else
+            data.Add(text.Mid(start, pos - start));
+    }
+
+    row = GetNumberRows() - 1;
+    skipSerial = false;
+
+    for (col = 0; col < nCols; col++) {
+        if (columns[col].type == PGOID_TYPE_SERIAL ||
+            columns[col].type == PGOID_TYPE_SERIAL8)
+        {
+            wxMessageDialog msg(GetView()->GetParent(),
+                _("This table contains serial columns. Do you want to use the values in the clipboard for these columns?"),
+                _("Paste Data"), wxYES_NO | wxICON_QUESTION);
+            if (msg.ShowModal() != wxID_YES)
+            {
+                skipSerial = true;
+            }
+            break;
+        }
+    }
+
+    for (col = (hasOids ? 1 : 0); col < nCols && col < (int)data.GetCount(); col++)
+    {
+        if (!(skipSerial && (columns[col].type == PGOID_TYPE_SERIAL ||
+            columns[col].type == PGOID_TYPE_SERIAL8)))
+        {
+            SetValue(row, col, data.Item(col));
+        }
+    }
+    GetView()->ForceRefresh();
+}
+
+
     
 
 wxGridCellAttr* sqlTable::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind  kind)
Index: include/frmEditGrid.h
===================================================================
--- include/frmEditGrid.h	(revision 5113)
+++ include/frmEditGrid.h	(working copy)
@@ -119,6 +119,7 @@
 
     bool CheckInCache(int row);
 
+    void Paste();
 
 private:
     pgQueryThread *thread;
@@ -182,6 +183,7 @@
     void OnEditorShown(wxGridEvent& event);
     void OnKey(wxKeyEvent& event);
     void OnCopy(wxCommandEvent& event);
+    void OnPaste(wxCommandEvent& event);
     void OnLabelDoubleClick(wxGridEvent& event);
     void OnLabelRightClick(wxGridEvent& event);
     void Abort();
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Reply via email to