Quoting Dave Page <[email protected]>:
We enable/disable the save button on the entry/exit of a cell - see
frmEditGrid::OnEditorShown() & frmEDitGrid::OnSave(). Does that look
robust enough to use to set a flag?
Got a solution. I set a flag in OnEditorShown, and trapped the editor
hidden event to clear it. Here's a new patch.
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,11 +59,13 @@
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)
EVT_GRID_SELECT_CELL(frmEditGrid::OnCellChange)
EVT_GRID_EDITOR_SHOWN(frmEditGrid::OnEditorShown)
+ EVT_GRID_EDITOR_HIDDEN(frmEditGrid::OnEditorHidden)
EVT_GRID_LABEL_RIGHT_CLICK(frmEditGrid::OnLabelRightClick)
END_EVENT_TABLE()
@@ -81,6 +84,7 @@
relkind=0;
limit=0;
relid=(Oid)obj->GetOid();
+ editorShown = false;
CreateStatusBar();
@@ -101,6 +105,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 +134,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 +243,18 @@
}
+void frmEditGrid::OnPaste(wxCommandEvent &ev)
+{
+ if (editorShown)
+ {
+ ev.Skip();
+ }
+ else
+ {
+ sqlGrid->GetTable()->Paste();
+ }
+}
+
void frmEditGrid::OnHelp(wxCommandEvent &ev)
{
DisplayHelp(this, wxT("editgrid"), viewdata_xpm);
@@ -453,11 +472,18 @@
{
toolBar->EnableTool(MNU_SAVE, true);
toolBar->EnableTool(MNU_UNDO, true);
+ editorShown = true;
event.Skip();
}
+void frmEditGrid::OnEditorHidden(wxGridEvent& event)
+{
+ editorShown = false;
+}
+
+
void frmEditGrid::OnGridSelectCells(wxGridRangeSelectEvent& event)
{
if (sqlGrid->GetEditable())
@@ -1722,6 +1748,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;
@@ -180,8 +181,10 @@
void OnCellChange(wxGridEvent& event);
void OnGridSelectCells(wxGridRangeSelectEvent& event);
void OnEditorShown(wxGridEvent& event);
+ void OnEditorHidden(wxGridEvent& event);
void OnKey(wxKeyEvent& event);
void OnCopy(wxCommandEvent& event);
+ void OnPaste(wxCommandEvent& event);
void OnLabelDoubleClick(wxGridEvent& event);
void OnLabelRightClick(wxGridEvent& event);
void Abort();
@@ -203,6 +206,7 @@
wxString orderBy;
wxString rowFilter;
int limit;
+ bool editorShown;
DECLARE_EVENT_TABLE();
};
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?
http://archives.postgresql.org