From 7b4f3c59c492cdb17e6f8b873dd708c61a9e41d2 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 2 Feb 2015 19:36:20 +0000 Subject: [PATCH] SqlCommander improved #412 git-svn-id: svn://ultimatepp.org/upp/trunk@8128 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/CtrlKbd.cpp | 2 +- uppsrc/SqlCtrl/SqlConsole.cpp | 276 ++++------------------------------ uppsrc/SqlCtrl/SqlCtrl.iml | 44 ++++-- uppsrc/SqlCtrl/SqlCtrl.upp | 5 +- uppsrc/SqlCtrl/init | 3 +- 5 files changed, 72 insertions(+), 258 deletions(-) diff --git a/uppsrc/CtrlCore/CtrlKbd.cpp b/uppsrc/CtrlCore/CtrlKbd.cpp index 82306c2c6..ce8fa8821 100644 --- a/uppsrc/CtrlCore/CtrlKbd.cpp +++ b/uppsrc/CtrlCore/CtrlKbd.cpp @@ -2,7 +2,7 @@ NAMESPACE_UPP -#define LLOG(x) // DLOG(x) +#define LLOG(x) DLOG(x) Ptr Ctrl::focusCtrl; Ptr Ctrl::focusCtrlWnd; diff --git a/uppsrc/SqlCtrl/SqlConsole.cpp b/uppsrc/SqlCtrl/SqlConsole.cpp index 365cbacad..ba0fb86a0 100644 --- a/uppsrc/SqlCtrl/SqlConsole.cpp +++ b/uppsrc/SqlCtrl/SqlConsole.cpp @@ -1,6 +1,7 @@ #include "SqlCtrl.h" #include "SqlDlg.h" #include +#include NAMESPACE_UPP @@ -143,187 +144,6 @@ bool SqlRunScript(int dialect, Stream& script_stream, const String& file_name, void RunDlgSqlExport(Sql& cursor, String command, String tablename); -class MacroSet { - struct Macro { - int n; - String text; - Vector param; - - void Serialize(Stream& s) { s / n % text % param; } - }; - ArrayMap macro; - - static bool Spaces(const char *&s); - static String GetId(const char *&s); - static bool IsId(int c) { return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_'; } - - String Expand(const char *s, Index& used) const; - -public: - void Serialize(Stream& s); - bool Define(const char *s); - String Expand(const char *s) const; - int GetCount() const { return macro.GetCount(); } - String Get(int i) const; -}; - -bool MacroSet::Spaces(const char *&s) { - if(*s != ' ' && *s != '\t') return false; - while(*s == ' ' || *s == '\t') - s++; - return true; -} - -String MacroSet::GetId(const char *&s) { - String result; - while(*s >= 'A' && *s <= 'Z' || *s >= 'a' && *s <= 'z' || *s >= '0' && *s <= '9' || *s == '_') - result.Cat(*s++); - return result; -} - -void MacroSet::Serialize(Stream& s) { - int version = 0; - s % version; - int n = macro.GetCount(); - s / n; - if(s.IsLoading()) { - macro.Clear(); - for(int i = 0; i < n; i++) { - String key; - s % key; - s % macro.Add(key); - } - } - else - for(int i = 0; i < n; i++) { - String key; - key = macro.GetKey(i); - s % key % macro[i]; - } -} - -bool MacroSet::Define(const char *s) { - if(!IsId(*s)) return false; - String name = GetId(s); - Index param; - Spaces(s); - if(*s == '(') { - s++; - Spaces(s); - if(*s != ')') - for(;;) { - Spaces(s); - if(!IsId(*s)) return false; - if(param.GetCount() >= 16) return false; - param.Add(GetId(s)); - Spaces(s); - if(*s == ')') break; - if(*s != ',') return false; - s++; - } - s++; - } - Spaces(s); - Macro& m = macro.GetAdd(name); - m.n = param.GetCount(); - m.param <<= param.GetKeys(); - m.text.Clear(); - while(*s) { - if(IsId(*s)) { - String name = GetId(s); - int i = param.Find(name); - if(i >= 0) - m.text.Cat(i + 16); - else - m.text.Cat(name); - } - else { - if(*s >= 16 && *s < 32) - m.text.Cat(' '); - else - m.text.Cat(*s); - s++; - } - } - return true; -} - -String MacroSet::Expand(const char *s, Index& used) const { - String text; - while(*s) - if(IsId(*s)) { - String name = GetId(s); - int i = macro.Find(name); - if(i >= 0 && used.Find(i) < 0) { - const Macro& m = macro[i]; - Vector param; - const char *t = s; - Spaces(s); - if(*s == '(') { - int level = 0; - String p; - for(;;) { - s++; - if((*s == ',' || *s == ')') && level == 0) { - p = TrimRight(TrimLeft(p)); -// p.TrimLeft(); -// p.TrimRight(); - param.Add(Expand(p)); - p.Clear(); - } - else - p.Cat(*s); - if(*s == '(') level++; - if(*s == ')') { - if(level <= 0) { - s++; - break; - } - level--; - } - } - } - else - s = t; - param.SetCount(16); - Index newused(used, 1); - newused.Add(i); - String mt = Expand(m.text, newused); - for(const char *q = mt; *q; q++) - if(*q >= 16 && *q < 32) - text.Cat(param[*q - 16]); - else - text.Cat(*q); - } - else - text.Cat(name); - } - else - text.Cat(*s++); - return text; -} - -String MacroSet::Expand(const char *s) const { - Index temp; - return Expand(s, temp); -} - -String MacroSet::Get(int i) const { - const Macro& m = macro[i]; - String s = macro.GetKey(i); - if(m.param.GetCount()) { - s.Cat('('); - for(i = 0; i < m.param.GetCount(); i++) { - if(i) s.Cat(", "); - s.Cat(m.param[i]); - } - s.Cat(')'); - } - s.Cat(" "); - s.Cat(Expand(s)); - return s; -} - class SqlConsole : public TopWindow { public: virtual bool Key(dword key, int count); @@ -343,14 +163,15 @@ protected: DocEdit errortext; ArrayCtrl record; ArrayCtrl trace; - WithDropChoice command; + CodeEditor command; + Button execute; Button schema; + ParentCtrl command_pane; // CallbackSet hide; Vector cw; Vector visible; Vector lob; String LastDir; - MacroSet macroset; enum { NORMAL, @@ -369,7 +190,6 @@ protected: void SaveTrace(); void RunScript(bool quiet); void TraceMenu(Bar& menu); - void MacroList(); void ObjectTree() { SQLObjectTree(cursor.GetSession()); } class Exec; @@ -398,42 +218,13 @@ public: SqlConsole(SqlSession& session); }; -void SqlConsole::MacroList() { - list.Reset(); - record.Clear(); - list.AddColumn(t_("Defined macros")); - for(int i = 0; i < macroset.GetCount(); i++) - list.Add('#' + macroset.Get(i)); -} - void SqlConsole::Execute(int type) { list.Reset(); + list.HeaderObject().Absolute().Moving(); visible.Clear(); lob.Clear(); record.Clear(); - String s = command.GetText().ToString(); - if(*s == '#') { - if(s[1] == '\0') { - MacroList(); - command.Clear(); - return; - } - list.AddColumn(t_("Macro definition")); - if(macroset.Define(~s + 1)) { - list.Add("OK"); - trace.Add(s, t_("Macro OK"), ""); - if(type == NORMAL) - command.AddHistory(); - command.Clear(); - } - else { - list.Add(t_("Invalid macro")); - trace.Add(s, t_("Invalid"), ""); - } - return; - } - s = TrimRight(macroset.Expand(s)); -// s.TrimRight(); + String s = ~command; while(*s.Last() == ';') s.Trim(s.GetLength() - 1); int ms0 = GetTickCount(); @@ -481,7 +272,8 @@ void SqlConsole::Execute(int type) { row[i] = temp; } cw[i] = max(cw[i], GetTextSize(StdFormat(row[i]), StdFont()).cx + - 2 * list.HeaderTab(i).GetMargin()); + 2 * list.HeaderTab(i).GetMargin()); + cw[i] = min(cw[i], list.GetSize().cx / 3); } list.Add(row); if(pi.StepCanceled()) break; @@ -505,25 +297,19 @@ void SqlConsole::Execute(int type) { trace.Add(s, rrows, rms); trace.GoEnd(); } - if(type == NORMAL) - command.AddHistory(); - command.Clear(); + command.Remove(0, command.GetLength()); + command.SetSelection(0, 0); } void SqlConsole::ColSize() { int maxw = 18 * StdFont().Info().GetAveWidth(); - int maxx = list.GetSize().cx; int wx = 0; for(int i = 0; i < cursor.GetColumns(); i++) if(visible[i]) { int w = min(maxw, cw[i]); wx += w; - if(wx < maxx) { - list.HeaderObject().SetTabRatio(i, w); - list.HeaderObject().ShowTab(i); - } - else - list.HeaderObject().HideTab(i); + list.HeaderObject().SetTabRatio(i, w); + list.HeaderObject().ShowTab(i); } else list.HeaderObject().HideTab(i); @@ -544,7 +330,7 @@ void SqlConsole::Record() { bool SqlConsole::Key(dword key, int count) { switch(key) { - case K_ENTER: + case K_F5: Execute(); return true; case K_CTRL_R: @@ -556,20 +342,12 @@ bool SqlConsole::Key(dword key, int count) { case K_CTRL_S: SaveTrace(); return true; - case K_CTRL_M: - MacroList(); - return true; - } - if(key >= ' ' && key < 256 || key == K_RIGHT || key == K_LEFT || key == K_ALT_DOWN) { - command.SetFocus(); - command.Key(key, count); - return true; } return TopWindow::Key(key, count); } void SqlConsole::Serialize(Stream& s) { - int version = 2; + int version = 0; s / version; s.Magic(); Rect r = GetRect(); @@ -578,12 +356,9 @@ void SqlConsole::Serialize(Stream& s) { vsplit.Serialize(s); record.SerializeHeader(s); lires.Serialize(s); - command.SerializeList(s); trace.SerializeHeader(s); if(version >= 1) s % LastDir; - if(version >= 2) - s % macroset; } void SqlConsole::Perform() { @@ -607,7 +382,7 @@ void SqlConsole::TraceToCommand() { void SqlConsole::ListToCommand() { int c = list.GetEditColumn(); if(list.IsCursor() && c >= 0 && c < list.GetIndexCount()) - command.Insert(StdFormat(list.Get(c)).ToWString()); + command <<= AsString(list.Get(c)); command.SetFocus(); } @@ -664,7 +439,6 @@ void SqlConsole::TraceMenu(Bar& menu) { menu.Add(t_("Save as script.."), THISBACK(SaveTrace)).Key(K_CTRL_S); menu.Add(t_("Run script.."), THISBACK1(RunScript, false)).Key(K_CTRL_R); menu.Add(t_("Run script quietly.."), THISBACK1(RunScript, true)).Key(K_CTRL_Q); - menu.Add(t_("List macros.."), THISBACK(MacroList)).Key(K_CTRL_M); } void SqlConsole::ListMenu(Bar& bar) @@ -775,6 +549,7 @@ SqlConsole::SqlConsole(SqlSession& session) errortext.SetFont(Courier(12)); errortext.Hide(); vsplit.Vert(lires, trace); + vsplit.Add(command_pane); record.AddColumn(t_("Column"), 5); record.AddColumn(t_("Value"), 10); record.WhenLeftDouble = THISBACK(ViewRecord); @@ -787,11 +562,19 @@ SqlConsole::SqlConsole(SqlSession& session) list.WhenEnterRow = THISBACK(Record); list.WhenLeftDouble = THISBACK(ListToCommand); list.WhenBar = THISBACK(ListMenu); - Add(vsplit.VSizePos(0, ecy + 4).HSizePos(0, 0)); - Add(command.BottomPos(0, ecy).HSizePos(0, 90)); - Add(schema.BottomPos(0, ecy).RightPos(0, 80)); + list.HeaderObject().Absolute(); + Add(vsplit.SizePos()); + command.SetFont(Courier(GetStdFontCy())); + command_pane.Add(command.VSizePos().HSizePos(0, HorzLayoutZoom(90))); + ecy = max(24, ecy); + command_pane.Add(execute.TopPos(0, ecy).RightPos(4, HorzLayoutZoom(80))); + command_pane.Add(schema.TopPos(ecy + 4, ecy).RightPos(4, HorzLayoutZoom(80))); + command.Highlight("sql"); schema.SetLabel(t_("&Schema")); schema <<= THISBACK(ObjectTree); + execute <<= THISBACK1(Execute, NORMAL); + execute.SetImage(SqlConsoleImg::Go()); + execute.SetLabel(t_("Execute")); ActiveFocus(command); } @@ -800,4 +583,9 @@ void SQLCommander(SqlSession& session) { con.Perform(); } +bool IsSqlConsoleActive__() +{ + return dynamic_cast(Ctrl::GetActiveWindow()); +} + END_UPP_NAMESPACE diff --git a/uppsrc/SqlCtrl/SqlCtrl.iml b/uppsrc/SqlCtrl/SqlCtrl.iml index 448ac917c..58f760a27 100644 --- a/uppsrc/SqlCtrl/SqlCtrl.iml +++ b/uppsrc/SqlCtrl/SqlCtrl.iml @@ -1,15 +1,39 @@ PREMULTIPLIED +IMAGE_ID(Go) IMAGE_ID(SqlConsoleIconLarge) IMAGE_ID(SqlConsoleIconSmall) IMAGE_BEGIN_DATA -IMAGE_DATA(120,156,237,86,1,14,195,32,8,244,9,123,66,159,234,207,221,154,166,173,158,7,40,173,233,178,121,13,153,69,224,64) -IMAGE_DATA(197,46,44,97,9,19,19,19,20,73,144,94,59,203,159,114,199,16,83,74,225,144,245,157,197,69,59,98,123,232,27,249) -IMAGE_DATA(105,76,240,23,109,136,125,55,63,169,3,215,79,170,183,200,107,215,223,200,191,213,30,235,26,153,255,62,239,229,183,214) -IMAGE_DATA(147,156,137,128,107,224,225,215,246,182,49,158,151,159,246,146,84,15,158,243,124,236,229,199,216,235,47,238,183,117,198,141) -IMAGE_DATA(245,215,238,3,181,159,242,156,80,47,141,181,152,140,95,218,123,92,107,171,255,243,222,233,225,55,164,41,87,227,254,240) -IMAGE_DATA(220,199,18,212,179,218,209,115,119,194,211,243,195,242,120,144,191,23,45,103,101,168,88,223,211,81,242,45,252,15,203,196) -IMAGE_DATA(196,255,226,245,121,126,15,235,31,128,152,100,221,62,70,155,109,238,188,160,78,251,82,23,97,190,244,69,27,93,39,251) -IMAGE_DATA(215,92,150,191,149,171,205,207,120,189,249,163,109,158,23,171,83,202,63,215,97,172,122,175,172,253,215,228,42,90,56,116) -IMAGE_DATA(241,127,76,175,115,191,1,250,3,139,228,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) -IMAGE_END_DATA(288, 2) +IMAGE_DATA(120,156,237,88,109,76,147,87,20,126,55,10,70,98,140,49,97,139,18,65,127,168,4,19,140,162,254,209,24,21,221,162) +IMAGE_DATA(38,186,32,106,6,178,57,21,191,21,13,161,106,162,77,227,204,130,241,139,248,71,205,38,25,63,212,72,80,183,57,195) +IMAGE_DATA(144,96,9,248,9,98,180,109,52,36,34,188,32,109,223,90,75,161,208,66,50,243,120,79,181,216,190,188,31,109,149,168) +IMAGE_DATA(177,135,156,244,114,238,243,156,231,220,143,115,75,224,70,113,163,56,89,139,77,152,194,37,101,159,29,49,239,152,240,77) +IMAGE_DATA(102,73,15,57,141,41,198,197,141,155,45,79,252,42,134,75,204,171,76,221,107,192,234,138,54,236,50,117,99,95,83,15) +IMAGE_DATA(246,50,207,103,99,138,209,28,97,56,238,107,77,48,85,51,140,155,144,115,106,85,121,51,126,227,189,208,154,156,88,91) +IMAGE_DATA(103,195,154,106,11,114,13,22,228,213,89,177,207,220,233,155,35,12,55,105,115,121,80,142,137,59,175,175,251,183,21,197) +IMAGE_DATA(124,47,86,87,118,96,201,213,14,156,55,187,48,185,180,5,211,46,240,152,117,145,199,130,203,237,200,174,178,224,4,195) +IMAGE_DATA(16,150,56,62,110,124,210,244,239,143,55,160,184,173,15,203,175,89,48,159,225,22,94,121,14,183,167,223,151,35,237,92) +IMAGE_DATA(43,50,43,173,88,202,114,82,124,25,195,16,150,56,92,124,242,140,216,169,91,75,246,223,123,129,159,106,28,200,170,176) +IMAGE_DATA(98,173,193,142,233,127,60,5,239,244,130,236,220,35,7,166,156,110,66,206,13,59,54,212,218,25,198,226,195,18,135,184) +IMAGE_DATA(227,127,46,19,246,152,123,144,103,16,176,251,150,29,235,235,28,62,190,201,226,134,223,202,140,14,36,31,53,98,5,203) +IMAGE_DATA(95,216,224,100,88,27,136,67,220,201,5,213,222,162,102,15,180,119,95,96,217,127,54,164,95,178,34,94,103,198,93,222) +IMAGE_DATA(133,64,179,184,250,145,182,191,30,115,203,59,160,173,127,137,162,230,94,16,119,134,254,142,183,152,239,195,252,191,108,152) +IMAGE_DATA(85,102,67,198,53,7,18,139,30,163,94,196,111,23,186,144,90,112,19,41,165,237,200,184,106,7,113,210,117,183,189,41) +IMAGE_DATA(133,85,194,186,134,110,44,250,71,192,210,10,59,86,212,116,34,169,136,233,183,116,6,213,31,147,127,27,179,47,219,144) +IMAGE_DATA(89,253,18,11,255,22,64,156,84,198,29,185,88,87,242,67,141,19,63,214,185,144,101,112,32,247,190,27,201,71,76,48) +IMAGE_DATA(89,221,3,92,110,83,45,178,31,120,144,115,135,97,216,222,17,150,56,196,213,140,73,155,243,221,165,231,216,102,234,69) +IMAGE_DATA(238,45,39,182,152,61,152,116,216,136,155,77,130,143,155,160,111,196,182,230,255,241,203,61,23,155,239,244,57,97,137,163) +IMAGE_DATA(73,76,95,64,87,96,244,154,51,215,55,52,118,97,23,219,211,252,183,124,63,87,203,191,194,214,70,23,54,54,116,97) +IMAGE_DATA(19,243,221,12,67,88,226,12,220,191,152,216,97,9,89,186,147,59,140,221,208,61,245,250,120,228,25,229,109,216,249,176) +IMAGE_DATA(155,185,27,5,230,94,28,96,115,132,73,220,94,90,197,218,69,35,106,129,225,223,110,249,179,114,101,173,19,133,143,61) +IMAGE_DATA(56,216,218,135,95,91,250,112,136,62,249,126,104,159,120,64,115,132,97,122,113,114,93,168,25,155,50,117,236,250,163,103) +IMAGE_DATA(103,254,110,20,230,94,124,214,67,78,99,138,197,77,72,159,51,136,48,158,253,68,45,106,81,147,52,200,120,184,56,53) +IMAGE_DATA(190,164,182,158,211,179,39,144,27,112,250,93,42,175,24,39,129,29,136,135,168,47,153,83,196,151,197,72,224,195,214,151) +IMAGE_DATA(88,135,120,255,228,214,27,84,151,63,254,1,245,223,172,93,63,120,141,82,124,255,124,164,250,106,251,41,113,39,56,241) +IMAGE_DATA(30,68,162,175,116,182,33,230,139,84,95,178,151,228,214,35,190,231,129,227,72,245,197,185,233,83,124,222,106,119,92,101) +IMAGE_DATA(255,149,222,3,197,126,10,172,73,28,151,27,43,229,148,210,151,59,123,241,94,171,245,127,96,239,132,163,175,226,33,213) +IMAGE_DATA(170,242,126,68,242,30,203,153,226,93,13,163,231,62,164,69,210,243,67,86,199,71,212,15,215,66,185,43,67,234,106,223) +IMAGE_DATA(167,67,229,159,138,254,71,246,168,69,237,203,53,197,255,12,126,182,70,127,0,232,33,31,243,143,197,152,55,115,239,30) +IMAGE_DATA(168,119,248,224,152,94,52,31,204,21,99,148,99,242,252,193,90,106,124,181,90,213,245,165,116,35,173,95,140,13,172,75) +IMAGE_DATA(106,157,114,245,7,198,196,185,6,159,149,218,249,43,249,251,90,40,26,202,30,249,151,233,251,107,191,6,233,198,230,250) +IMAGE_END_DATA(1024, 3) diff --git a/uppsrc/SqlCtrl/SqlCtrl.upp b/uppsrc/SqlCtrl/SqlCtrl.upp index 3ec75f674..f9ef1dc12 100644 --- a/uppsrc/SqlCtrl/SqlCtrl.upp +++ b/uppsrc/SqlCtrl/SqlCtrl.upp @@ -3,10 +3,11 @@ description "GUI widgets and routines for SQL\377"; uses Sql, CtrlLib, - Report; + Report, + CodeEditor; file - SqlCtrl.h options PCH, + SqlCtrl.h options(BUILDER_OPTION) PCH, SqlCtrl.t charset "UTF-8", SqlCtrl_init.icpp, SqlCtrl.cpp, diff --git a/uppsrc/SqlCtrl/init b/uppsrc/SqlCtrl/init index faae1932a..bf702b301 100644 --- a/uppsrc/SqlCtrl/init +++ b/uppsrc/SqlCtrl/init @@ -3,7 +3,8 @@ #include "Sql/init" #include "CtrlLib/init" #include "Report/init" -#define BLITZ_INDEX__ F74ba1cb7d560d8dd7adb49654c110f20 +#include "CodeEditor/init" +#define BLITZ_INDEX__ F96a1ec818c4cc17747e79bf1c64548ae #include "SqlCtrl_init.icpp" #undef BLITZ_INDEX__ #endif