📄 wxgcl.cc
字号:
wxMenu *fileSaveMenu = new wxMenu; fileSaveMenu->Append(idSAVE_LOG, "&Log", "Save all input and output"); fileSaveMenu->Append(idSAVE_SCRIPT, "&Script", "Save all input only"); fileMenu->Append(idSAVE, "&Save", fileSaveMenu, "Save input and output"); fileMenu->Append(wxID_EXIT, "&Quit", "Quit program"); wxMenu *editMenu = new wxMenu; editMenu->Append(wxID_CUT, "Cu&t", "Cut selected text"); editMenu->Append(wxID_COPY, "&Copy", "Copy selected text"); editMenu->Append(wxID_PASTE, "&Paste", "Paste selected text"); wxMenu *prefsMenu = new wxMenu; prefsMenu->Append(idPREFS_PROGRESS, "Show progress &display", "Show progress display for algorithms", true); prefsMenu->Append(idPREFS_PROMPT, "Show assignment &prompt", "Include assignment at beginning of prompt", true); prefsMenu->AppendSeparator(); prefsMenu->Append(idPREFS_INPUTFONT, "&Input window font", "Change the font used in the input window"); prefsMenu->Append(idPREFS_OUTPUTFONT, "&Output window font", "Change the font used in the output window"); wxMenu *helpMenu = new wxMenu; helpMenu->Append(wxID_ABOUT, "&About", "About Gambit"); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append(fileMenu, "&File"); menuBar->Append(editMenu, "&Edit"); menuBar->Append(prefsMenu, "&Prefs"); menuBar->Append(helpMenu, "&Help"); SetMenuBar(menuBar); GetMenuBar()->Check(idPREFS_PROGRESS, true); GetMenuBar()->Check(idPREFS_PROMPT, true); CreateStatusBar(); m_outputWindow = new wxTextCtrl(this, -1, "", wxPoint(0, 0), wxSize(400, 300), wxTE_MULTILINE | wxTE_READONLY); m_outputStream = new wxOutputWindowStream(m_outputWindow); m_inputSashWindow = new wxSashWindow(this, idINPUT_SASH_WINDOW, wxPoint(0, 300), wxSize(400, 100));#ifdef __WXMSW__ m_inputWindow = new wxTextCtrl(m_inputSashWindow, idINPUT_WINDOW, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);#else m_inputWindow = new wxTextCtrl(m_inputSashWindow, idINPUT_WINDOW, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_PROCESS_ENTER);#endif // __WXMSW__ // For the moment, default to a fixed-width font. // In the long run, this will be read from wxConfig m_inputWindow->SetFont(wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)); m_outputWindow->SetFont(wxFont(12, wxMODERN, wxNORMAL, wxNORMAL)); m_cancelButton = new wxCancelButton(m_inputSashWindow); m_cancelButton->Enable(false); m_inputSashWindow->SetSashVisible(wxSASH_TOP, true); wxBoxSizer *inputSizer = new wxBoxSizer(wxHORIZONTAL); inputSizer->Add(m_inputWindow, 1, wxEXPAND | wxRIGHT, 5); inputSizer->Add(m_cancelButton, 0, wxCENTER | wxALL, 5); m_inputSashWindow->SetAutoLayout(true); m_inputSashWindow->SetSizer(inputSizer); inputSizer->SetSizeHints(m_inputSashWindow); m_inputSashWindow->Layout(); m_inputWindow->SetFocus(); m_inputWindow->SetValue((char *) FormPrompt()); m_inputWindow->SetInsertionPointEnd(); SetSizeHints(300, 300); _SourceDir = new char[1024]; strncpy(_SourceDir, wxGetWorkingDirectory(), 1023); _ExePath = new char[1024]; strncpy(_ExePath, wxGetWorkingDirectory(), 1023); gStandardInput gin; m_environment = new wxGSM(this, *m_cancelButton, gin, *m_outputStream, *m_outputStream); wxCommandLine cmdline(20); gText initString = "Include[\"gclini.gcl\"]\n"; for (int i = 1; i < wxGetApp().argc; i++) { initString += "Include[\""; initString += wxGetApp().argv[i]; initString += "\"]\n"; } Show(true); gPreprocessor preproc(*m_environment, &cmdline, initString); wxBusyCursor cursor; try { while (!preproc.eof()) { gText line = preproc.GetLine(); gText fileName = preproc.GetFileName(); int lineNumber = preproc.GetLineNumber(); gText rawLine = preproc.GetRawLine(); GCLParse(m_environment, line, fileName, lineNumber, rawLine); } } catch (gSignalBreak &) { m_environment->OutputStream() << "Computation interrupted!\n"; } catch (gclQuitOccurred &) { Close(true); } catch (gException &w) { m_environment->OutputStream() << "GCL EXCEPTION:" << w.Description() << "; Caught in GclFrame::GclFrame()\n"; } m_inputWindow->SetInsertionPointEnd(); m_inputWindow->SetFocus();}GclFrame::~GclFrame(){ }BEGIN_EVENT_TABLE(GclFrame, wxFrame) EVT_MENU(idSAVE_LOG, GclFrame::OnSaveLog) EVT_MENU(idSAVE_SCRIPT, GclFrame::OnSaveScript) EVT_MENU(wxID_EXIT, wxWindow::Close) EVT_MENU(idPREFS_PROGRESS, GclFrame::OnPrefsProgress) EVT_MENU(idPREFS_PROMPT, GclFrame::OnPrefsPrompt) EVT_MENU(idPREFS_INPUTFONT, GclFrame::OnPrefsInputFont) EVT_MENU(idPREFS_OUTPUTFONT, GclFrame::OnPrefsOutputFont) EVT_MENU(wxID_ABOUT, GclFrame::OnHelpAbout) EVT_TEXT_ENTER(idINPUT_WINDOW, GclFrame::OnTextEnter) EVT_CLOSE(GclFrame::OnCloseWindow) EVT_SIZE(GclFrame::OnSize) EVT_SASH_DRAGGED(idINPUT_SASH_WINDOW, GclFrame::OnSashDrag) EVT_BUTTON(idCANCEL_BUTTON, GclFrame::OnCancel)END_EVENT_TABLE()void GclFrame::OnSaveLog(wxCommandEvent &){ wxFileDialog dialog(this, "Save Log As...", "", "", "*.log"); if (dialog.ShowModal() == wxID_OK) { try { gFileOutput file(dialog.GetPath().c_str()); file << m_outputWindow->GetValue(); } catch (gFileOutput::OpenFailed &) { wxMessageBox((char *) (gText("Could not open ") + dialog.GetPath().c_str() + " for writing."), "Error", wxOK); } catch (gFileOutput::WriteFailed &) { wxMessageBox((char *) (gText("Error occurred in writing ") + dialog.GetPath().c_str()), "Error", wxOK); } }}void GclFrame::OnSaveScript(wxCommandEvent &){ wxFileDialog dialog(this, "Save Script As...", "", "", "*.gcl"); if (dialog.ShowModal() == wxID_OK) { try { gFileOutput file(dialog.GetPath().c_str()); for (int i = 1; i <= m_history.Length(); i++) { file << ((char *) m_history[i]) << '\n'; } } catch (gFileOutput::OpenFailed &) { wxMessageBox((char *) (gText("Could not open ") + dialog.GetPath().c_str() + " for writing."), "Error", wxOK); } catch (gFileOutput::WriteFailed &) { wxMessageBox((char *) (gText("Error occurred in writing ") + dialog.GetPath().c_str()), "Error", wxOK); } }}void GclFrame::OnPrefsProgress(wxCommandEvent &){ m_environment->ToggleMonitorStyle();}void GclFrame::OnPrefsPrompt(wxCommandEvent &){}void GclFrame::OnPrefsInputFont(wxCommandEvent &) { wxFontData data; wxFontDialog dialog(this, &data); if (dialog.ShowModal() == wxID_OK) { m_inputWindow->SetFont(dialog.GetFontData().GetChosenFont()); }}void GclFrame::OnPrefsOutputFont(wxCommandEvent &) { wxFontData data; wxFontDialog dialog(this, &data); if (dialog.ShowModal() == wxID_OK) { m_outputWindow->SetFont(dialog.GetFontData().GetChosenFont()); }}void GclFrame::OnHelpAbout(wxCommandEvent &){ dialogAbout dialog(this, "About Gambit...", "Gambit Command Language", "Version " VERSION); dialog.ShowModal();}void GclFrame::OnCloseWindow(wxCloseEvent &){ Destroy();}void GclFrame::OnSize(wxSizeEvent &){ int clientWidth, clientHeight; GetClientSize(&clientWidth, &clientHeight); if (!m_outputWindow || !m_inputSashWindow) { return; } m_outputWindow->SetSize(0, 0, clientWidth, gmax(clientHeight - m_inputSashWindow->GetRect().height, 50)); m_inputSashWindow->SetSize(0, m_outputWindow->GetRect().height, clientWidth, clientHeight - m_outputWindow->GetRect().height); m_inputSashWindow->Layout();}void GclFrame::OnSashDrag(wxSashEvent &p_event){ int clientWidth, clientHeight; GetClientSize(&clientWidth, &clientHeight); int dragHeight = gmax(gmin(clientHeight - 50, p_event.GetDragRect().height), 50); m_outputWindow->SetSize(0, 0, clientWidth, clientHeight - dragHeight); m_inputSashWindow->SetSize(0, clientHeight - dragHeight, clientWidth, dragHeight); m_inputSashWindow->Layout();}void GclFrame::OnTextEnter(wxCommandEvent &){ gText input(m_inputWindow->GetValue().c_str()); if (input.Right(2)[1u] == '\\') { // continuation character m_inputWindow->AppendText("\n"); return; } m_outputWindow->AppendText((char *) input); m_history.Append(input); m_outputWindow->AppendText("\n"); m_inputWindow->Enable(false); m_cancelButton->Enable(true); wxCommandLine cmdline(20); gPreprocessor preproc(*m_environment, &cmdline, input + "\n"); m_inputWindow->SetValue(""); wxBusyCursor cursor; try { while (!preproc.eof()) { gText line = preproc.GetLine(); gText fileName = preproc.GetFileName(); int lineNumber = preproc.GetLineNumber(); gText rawLine = preproc.GetRawLine(); GCLParse(m_environment, line, fileName, lineNumber, rawLine); } } catch (gSignalBreak &) { m_environment->OutputStream() << "Computation interrupted!\n"; } catch (gclQuitOccurred &) { Close(true); } catch (gException &w) { m_environment->OutputStream() << "GCL EXCEPTION:" << w.Description() << "; Caught in GclFrame::OnTextEnter()\n"; } m_cancelButton->Enable(false); m_inputWindow->SetValue((char *) FormPrompt()); m_inputWindow->SetInsertionPointEnd(); m_inputWindow->Enable(true); m_outputWindow->AppendText("\n"); m_inputWindow->SetFocus();}void GclFrame::OnCancel(wxCommandEvent &){ m_cancelButton->Set();}gText GclFrame::FormPrompt(void) { gText prompt; if (GetMenuBar()->IsChecked(idPREFS_PROMPT)) { prompt += "GCL" + ToText(m_history.Length() + 1) + ":= "; } prompt += "<< "; return prompt;}gStandardInput _gin;gInput &gin = _gin;gStandardOutput _gout;gOutput &gout = _gout;gStandardOutput _gerr;gOutput &gerr = _gerr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -