Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Paste rows rough patch


  • From: "Edward Di Geronimo Jr." <edigeronimo(at)xtracards(dot)com>
  • To: pgadmin-hackers(at)postgresql(dot)org
  • Subject: Paste rows rough patch
  • Date: Tue, 02 May 2006 01:26:06 -0400
  • Message-id: <20060502012606(dot)6u8464mor0e8o08w(at)webmail(dot)picoip(dot)com>

Attached is a rough patch to allow pasting of rows into the edit grid. It's not intended to be a final solution, but rather enough to start some discussion.

This patch is rather simple - it always deliminates columns by tabs, and stops if it hits a new line. It pastes data starting at the first column of the row the cursor is on. Right now it doesn't pay any attention to the column details, so it will gladly insert data into serial columns or whatever.

I figure the proper solution should probably be to obey the copy settings for deliminating columns.

As to things like serial & oid columns, how does everyone feel about that? Maybe we could add an option to paste values in, skip the columns, or prompt?

Any other thoughts on how this should work?

Ed

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

Index: frm/frmEditGrid.cpp
===================================================================
--- frm/frmEditGrid.cpp	(revision 5099)
+++ 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,56 @@
 }
 
 
+void frmEditGrid::OnPaste(wxCommandEvent &ev)
+{
+    unsigned int row, col, numCols;
+    int start, pos, len;
+    wxArrayString columns;
+    wxString text;
+
+    if (wxTheClipboard->Open())
+    {
+        if (wxTheClipboard->IsSupported(wxDF_TEXT))
+        {
+            wxTextDataObject data;
+            wxTheClipboard->GetData(data);
+            text = data.GetText();
+        }
+        else {
+            wxTheClipboard->Close();
+            return;
+        }
+        wxTheClipboard->Close();
+    }
+    else {
+        return;
+    }
+
+    start = pos = 0;
+    len = text.Len();
+    while (pos < len && text[pos] != '\n') {
+        if (text[pos] == '\t') {
+            columns.Add(text.Mid(start, pos - start));
+            start = ++pos;
+        }
+        else {
+            pos++;
+        }
+    }
+    if (start < pos) {
+        columns.Add(text.Mid(start, pos - start));
+    }
+
+    row = sqlGrid->GetGridCursorRow();
+    numCols = sqlGrid->GetNumberCols();
+
+    for (col = 0; col < numCols && col < columns.GetCount(); col++) {
+        sqlGrid->GetTable()->SetValue(row, col, columns.Item(col));
+    }
+    sqlGrid->ForceRefresh();
+}
+
+
 void frmEditGrid::OnHelp(wxCommandEvent &ev)
 {
     DisplayHelp(this, wxT("editgrid"), viewdata_xpm);
Index: include/frmEditGrid.h
===================================================================
--- include/frmEditGrid.h	(revision 5099)
+++ include/frmEditGrid.h	(working copy)
@@ -182,6 +182,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();


Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group