Exemplo n.º 1
0
void CFrame::ToggleConsole(bool bShow)
{
#ifdef _WIN32
	GetMenuBar()->FindItem(IDM_CONSOLEWINDOW)->Check(bShow);

	if (bShow)
	{
		// If the console doesn't exist, we create it
		if (!GetConsoleWindow())
		{
			ConsoleListener *Console = LogManager::GetInstance()->GetConsoleListener();
			Console->Open();
		}
		else
			ShowWindow(GetConsoleWindow(), SW_SHOW);

		// Create the parent window if it doesn't exist
		wxPanel *ConsoleParent = (wxPanel*)FindWindowById(IDM_CONSOLEWINDOW);
		if (!ConsoleParent) ConsoleParent = new wxPanel(this, IDM_CONSOLEWINDOW,
				wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("Console"));

		wxWindow *ConsoleWin = new wxWindow();
		ConsoleWin->SetHWND((WXHWND)GetConsoleWindow());
		ConsoleWin->AdoptAttributesFromHWND();
		ConsoleWin->Reparent(ConsoleParent);

		ConsoleParent->Enable();
		const int nbIndex = IDM_CONSOLEWINDOW - IDM_LOGWINDOW;
		DoAddPage(ConsoleParent,
				g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0,
				g_pCodeWindow ? bFloatWindow[nbIndex] : false);
	}
	else // Hide
	{
		if(GetConsoleWindow())
			ShowWindow(GetConsoleWindow(), SW_HIDE); // WIN32

		wxPanel *ConsoleParent = (wxPanel*)FindWindowById(IDM_CONSOLEWINDOW);
		if (ConsoleParent)
			ConsoleParent->Disable();

		// Then close the page
		DoRemovePage(ConsoleParent, true);
	}

	// Hide or Show the pane
	if (!g_pCodeWindow)
		TogglePane();
#endif
}
Exemplo n.º 2
0
void CFrame::ToggleLogConfigWindow(bool bShow)
{
	GetMenuBar()->FindItem(IDM_LOGCONFIGWINDOW)->Check(bShow);

	if (bShow)
	{
		if (!m_LogConfigWindow)
			m_LogConfigWindow = new LogConfigWindow(this, m_LogWindow, IDM_LOGCONFIGWINDOW);
		const int nbIndex = IDM_LOGCONFIGWINDOW - IDM_LOGWINDOW;
		DoAddPage(m_LogConfigWindow,
				g_pCodeWindow ? g_pCodeWindow->iNbAffiliation[nbIndex] : 0,
				g_pCodeWindow ? bFloatWindow[nbIndex] : false);
	}
	else
	{
		DoRemovePage(m_LogConfigWindow, false);
		m_LogConfigWindow = NULL;
	}

	// Hide or Show the pane
	if (!g_pCodeWindow)
		TogglePane();
}
Exemplo n.º 3
0
Frame::Frame()
  : wxExFrameWithHistory(nullptr, wxID_ANY, wxTheApp->GetAppDisplayName())
  , m_Results(new wxExGrid(this))
  , m_Query(new wxExSTC(this))
  , m_Shell(new wxExShell(this, "", ";", true, 50))
{
  SetIcon(wxICON(app));

  wxExMenu* menuFile = new wxExMenu;
  menuFile->Append(wxID_NEW);
  menuFile->Append(wxID_OPEN);
  GetFileHistory().UseMenu(ID_RECENTFILE_MENU, menuFile);
  menuFile->AppendSeparator();
  menuFile->Append(wxID_SAVE);
  menuFile->Append(wxID_SAVEAS);
  menuFile->AppendSeparator();
  menuFile->Append(wxID_EXIT);

  wxExMenu* menuDatabase = new wxExMenu;
  menuDatabase->Append(ID_DATABASE_OPEN, wxExEllipsed(_("&Open")));
  menuDatabase->Append(ID_DATABASE_CLOSE, _("&Close"));

  wxExMenu* menuQuery = new wxExMenu;
  menuQuery->Append(wxID_EXECUTE);
  menuQuery->Append(wxID_STOP);

  wxMenu* menuOptions = new wxMenu();
  menuOptions->Append(wxID_PREFERENCES);

  wxExMenu* menuView = new wxExMenu();
  AppendPanes(menuView);
  menuView->AppendSeparator();
  menuView->AppendCheckItem(ID_VIEW_QUERY, _("Query"));
  menuView->AppendCheckItem(ID_VIEW_RESULTS, _("Results"));
  menuView->AppendCheckItem(ID_VIEW_STATISTICS, _("Statistics"));

  wxMenu* menuHelp = new wxMenu();
  menuHelp->Append(wxID_ABOUT);

  wxMenuBar *menubar = new wxMenuBar;
  menubar->Append(menuFile, wxGetStockLabel(wxID_FILE));
  menubar->Append(menuView, _("&View"));
  menubar->Append(menuDatabase, _("&Connection"));
  menubar->Append(menuQuery, _("&Query"));
  menubar->Append(menuOptions, _("&Options"));
  menubar->Append(menuHelp, wxGetStockLabel(wxID_HELP));
  SetMenuBar(menubar);

  m_Results->CreateGrid(0, 0);
  m_Results->EnableEditing(false); // this is a read-only grid

  m_Shell->SetFocus();

#if wxUSE_STATUSBAR
  SetupStatusBar(std::vector<wxExStatusBarPane>{
    wxExStatusBarPane(),
    wxExStatusBarPane("PaneInfo", 100, _("Lines"))});
#endif

  GetToolBar()->AddControls(false); // no realize yet
  GetToolBar()->AddTool(wxID_EXECUTE, 
    wxEmptyString,
    wxArtProvider::GetBitmap(
      wxART_GO_FORWARD, wxART_TOOLBAR, GetToolBar()->GetToolBitmapSize()),
    wxGetStockLabel(wxID_EXECUTE, wxSTOCK_NOFLAGS));
  GetToolBar()->Realize();

  GetManager().AddPane(m_Shell,
    wxAuiPaneInfo().
      Name("CONSOLE").
      CenterPane());

  GetManager().AddPane(m_Results,
    wxAuiPaneInfo().
      Name("RESULTS").
      Caption(_("Results")).
      CloseButton(true).
      Bottom().
      MaximizeButton(true));

  GetManager().AddPane(m_Query,
    wxAuiPaneInfo().
      Name("QUERY").
      Caption(_("Query")).
      CloseButton(true).
      MaximizeButton(true));

  GetManager().AddPane(m_Statistics.Show(this),
    wxAuiPaneInfo().Left().
      Hide().
      MaximizeButton(true).
      Caption(_("Statistics")).
      Name("STATISTICS"));

  GetManager().LoadPerspective(wxConfigBase::Get()->Read("Perspective"));
  GetManager().GetPane("QUERY").Show(false);

  GetManager().Update();
  
  Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent& event) {
    if (wxExFileDialog(this,
      &m_Query->GetFile()).ShowModalIfChanged()  != wxID_CANCEL)
    {
      wxConfigBase::Get()->Write("Perspective", GetManager().SavePerspective());
      event.Skip();
    }});
    
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    wxAboutDialogInfo info;
    info.SetIcon(GetIcon());
    info.SetDescription(_("This program offers a general ODBC query."));
    info.SetVersion(wxExGetVersionInfo().GetVersionOnlyString());
    info.SetCopyright(wxExGetVersionInfo().GetCopyright());
    info.AddDeveloper(wxExOTL::VersionInfo().GetVersionString());
    wxAboutBox(info);
    }, wxID_ABOUT);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    m_Stopped = false;
    if (m_Query->GetText().empty()) return;
    if (m_Results->IsShown())
    {
      m_Results->ClearGrid();
    }
    // Skip sql comments.
    std::regex re("--.*$");
    wxString output = std::regex_replace(m_Query->GetText().ToStdString(), re, "", std::regex_constants::format_sed);
    // Queries are seperated by ; character.
    wxStringTokenizer tkz(output, ";");
    int no_queries = 0;
    m_Running = true;
    const auto start = std::chrono::system_clock::now();
    // Run all queries.
    while (tkz.HasMoreTokens() && !m_Stopped)
    {
      wxString query = tkz.GetNextToken();
      query.Trim(true);
      query.Trim(false);
      if (!query.empty())
      {
        try
        {
          RunQuery(query, no_queries == 0);
          no_queries++;
        }
        catch (otl_exception& p)
        {
          m_Statistics.Inc(_("Number of query errors"));
          m_Shell->AppendText(
            _("\nerror: ") +  wxString(wxExQuoted(p.msg)) + 
            _(" in: ") + wxString(wxExQuoted(query)));
        }
      }
    }
    const auto end = std::chrono::system_clock::now();
    const auto elapsed = end - start;
    const auto milli = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed);
    m_Shell->Prompt(wxString::Format(_("\n%d queries (%.3f seconds)"),
      no_queries,
      (float)milli.count() / (float)1000).ToStdString());
    m_Running = false;}, wxID_EXECUTE);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    Close(true);}, wxID_EXIT);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    m_Query->GetFile().FileNew(wxExFileName());
    m_Query->SetFocus();
    ShowPane("QUERY");}, wxID_NEW);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    wxExOpenFilesDialog(
      this, 
      wxFD_OPEN | wxFD_CHANGE_DIR, 
      "sql files (*.sql)|*.sql|" + 
      _("All Files") + wxString::Format(" (%s)|%s",
        wxFileSelectorDefaultWildcardStr,
        wxFileSelectorDefaultWildcardStr),
      true);}, wxID_OPEN);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    m_Query->GetFile().FileSave();}, wxID_SAVE);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    wxExFileDialog dlg(
      this, 
      &m_Query->GetFile(), 
      wxGetStockLabel(wxID_SAVEAS), 
      wxFileSelectorDefaultWildcardStr, 
      wxFD_SAVE);
    if (dlg.ShowModal() == wxID_OK)
    {
       m_Query->GetFile().FileSave(dlg.GetPath().ToStdString());
    }}, wxID_SAVEAS);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    m_Running = false;
    m_Stopped = true;}, wxID_STOP);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    if (m_otl.Logoff())
    {
      m_Shell->SetPrompt(">");
    }}, ID_DATABASE_CLOSE);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    if (m_otl.Logon(this))
    {
      m_Shell->SetPrompt(m_otl.Datasource().ToStdString() + ">");
    }}, ID_DATABASE_OPEN);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    if (m_otl.IsConnected())
    {
      try
      {
        const wxString input(event.GetString());
        if (!input.empty())
        {
          const wxString query = input.substr(
            0,
            input.length() - 1);

          m_Stopped = false;
          RunQuery(query, true);
        }
      }
      catch (otl_exception& p)
      {
        if (m_Results->IsShown())
        {
          m_Results->EndBatch();
        }
        m_Shell->AppendText(_("\nerror: ") + wxString(wxExQuoted(p.msg)));
      }
    }
    else
    {
      m_Shell->AppendText(_("\nnot connected"));
    }
    m_Shell->Prompt();}, ID_SHELL_COMMAND);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    m_Stopped = true;
    m_Shell->Prompt("cancelled");}, ID_SHELL_COMMAND_STOP);

  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    TogglePane("QUERY");}, ID_VIEW_QUERY);
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    TogglePane("RESULTS");}, ID_VIEW_RESULTS);
  Bind(wxEVT_MENU, [=](wxCommandEvent& event) {
    TogglePane("STATISTICS");}, ID_VIEW_STATISTICS);
  
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Enable(m_Query->GetModify());}, wxID_SAVE);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Enable(m_Query->GetLength() > 0);}, wxID_SAVEAS);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Enable(m_Running);}, wxID_STOP);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Enable(m_otl.IsConnected());}, ID_DATABASE_CLOSE);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Enable(!m_otl.IsConnected());}, ID_DATABASE_OPEN);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    // If we have a query, you can hide it, but still run it.
    event.Enable(m_Query->GetLength() > 0 && m_otl.IsConnected());}, wxID_EXECUTE);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Enable(!GetFileHistory().GetHistoryFile().empty());}, ID_RECENTFILE_MENU);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Check(GetManager().GetPane("QUERY").IsShown());}, ID_VIEW_QUERY);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Check(GetManager().GetPane("RESULTS").IsShown());}, ID_VIEW_RESULTS);
  Bind(wxEVT_UPDATE_UI, [=](wxUpdateUIEvent& event) {
    event.Check(GetManager().GetPane("STATISTICS").IsShown());}, ID_VIEW_STATISTICS);
  
  // Do automatic connect.
  if (!m_otl.Datasource().empty() && m_otl.Logon())
  {
    m_Shell->SetPrompt(m_otl.Datasource().ToStdString() + ">");
  }
  else
  {
    m_Shell->SetPrompt(">");
  }
}
Exemplo n.º 4
0
void Frame::OnCommand(wxCommandEvent& event)
{
  switch (event.GetId())
  {
  case wxID_ABOUT:
    {
    wxAboutDialogInfo info;
    info.SetIcon(GetIcon());
    info.SetDescription(_("This program offers a general ODBC query."));
    info.SetVersion(wxExGetVersionInfo().GetVersionOnlyString());
    info.SetCopyright(wxExGetVersionInfo().GetCopyright());
    info.AddDeveloper(wxExOTL::VersionInfo().GetVersionString());
    wxAboutBox(info);
    }
    break;

  case wxID_EXECUTE:
    m_Stopped = false;
    RunQueries(m_Query->GetText());
    break;

  case wxID_EXIT:
    Close(true);
    break;

  case wxID_NEW:
    m_Query->GetFile().FileNew(wxExFileName());
    m_Query->SetLexer("sql");
    m_Query->SetFocus();
    GetManager().GetPane("QUERY").Show();
    GetManager().Update();
    break;

  case wxID_OPEN:
    wxExOpenFilesDialog(
      this, 
      wxFD_OPEN | wxFD_CHANGE_DIR, 
      "sql files (*.sql) | *.sql", 
      true);
    break;

  case wxID_SAVE:
    m_Query->GetFile().FileSave();
    break;

  case wxID_SAVEAS:
    {
      wxExFileDialog dlg(
        this, 
        &m_Query->GetFile(), 
        wxGetStockLabel(wxID_SAVEAS), 
        wxFileSelectorDefaultWildcardStr, 
        wxFD_SAVE);

      if (dlg.ShowModal() == wxID_OK)
      {
         m_Query->GetFile().FileSave(dlg.GetPath());
      }
    }
    break;

  case wxID_STOP:
    m_Running = false;
    m_Stopped = true;
    break;

  case ID_DATABASE_CLOSE:
    if (m_otl.Logoff())
    {
      m_Shell->SetPrompt(">");
    }
    break;

  case ID_DATABASE_OPEN:
    if (m_otl.Logon(this))
    {
      m_Shell->SetPrompt(m_otl.Datasource() + ">");
    }
    break;

  case ID_SHELL_COMMAND:
    if (m_otl.IsConnected())
    {
      try
      {
        const wxString query = event.GetString().substr(
          0,
          event.GetString().length() - 1);

        m_Stopped = false;
        RunQuery(query, true);
      }
      catch (otl_exception& p)
      {
        if (m_Results->IsShown())
        {
          m_Results->EndBatch();
        }

        m_Shell->AppendText(_("\nerror: ") + wxExQuoted(p.msg));
      }
    }
    else
    {
      m_Shell->AppendText(_("\nnot connected"));
    }

    m_Shell->Prompt();
    break;

  case ID_SHELL_COMMAND_STOP:
    m_Stopped = true;
    m_Shell->Prompt(_("cancelled"));
    break;

  case ID_VIEW_QUERY: TogglePane("QUERY"); break;
  case ID_VIEW_RESULTS: TogglePane("RESULTS"); break;
  case ID_VIEW_STATISTICS: TogglePane("STATISTICS"); break;

  default: 
    wxFAIL;
  }
}