Exemple #1
0
void CMain::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	CloseAllPages();
	
	CWnd::OnClose();
}
Exemple #2
0
bool wxSTEditorNotebook::HandleMenuEvent(wxCommandEvent &event)
{
    wxSTERecursionGuard guard(m_rGuard_HandleMenuEvent);
    if (guard.IsInside()) return false;

    int n_page = (int)GetPageCount();
    int win_id = event.GetId();

    switch (win_id)
    {
        case wxID_NEW:
        {
            NewPage();
            return true;
        }
        case wxID_OPEN:
        {
            LoadFiles();
            return true;
        }
        case wxID_SAVEAS:
        {
            wxSTEditor *editor = GetEditor();
            if (!editor) return true; // event handled, but we couldn't do anything with it.

            if (!editor->IsFileFromDisk())
            {
                editor->SaveFile(true);
            }
            else
            {
                wxFileName selectedFileName;
                wxString   selectedFileEncoding;
                bool       selected_file_bom = false;

                bool ok = editor->SaveFileDialog(true, wxEmptyString, &selectedFileName, &selectedFileEncoding, &selected_file_bom);
                if (!ok) return true; // they probably canceled the dialog

                if (selectedFileName == editor->GetFileName())
                {
                    // They want to save to the same filename, update current editor.
                    editor->SaveFile(selectedFileName, selectedFileEncoding, selected_file_bom);
                    return true;
                }
                else
                {
                    // Make a new editor for the new filename, leave the original editor as is.
                    wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY);
                    wxCHECK_MSG(splitter, true, wxT("Invalid splitter"));
                    wxSTEditor *newEditor = splitter->GetEditor();
                    wxCHECK_MSG(newEditor, true, wxT("Invalid splitter editor"));

                    // Make this new editor identical to the original one
                    // these are probably not necessary
                    //splitter->GetEditor()->SetOptions(editor->GetOptions());
                    //splitter->GetEditor()->RegisterPrefs(editor->GetEditorPrefs());
                    //splitter->GetEditor()->RegisterStyles(editor->GetEditorStyles());
                    //splitter->GetEditor()->RegisterLangs(editor->GetEditorLangs());

                    newEditor->SetLanguage(editor->GetLanguageId());
                    newEditor->SetFileName(editor->GetFileName());
                    newEditor->SetFileEncoding(editor->GetFileEncoding());
                    newEditor->SetFileBOM(editor->GetFileBOM());

                    newEditor->SetText(editor->GetText());
                    newEditor->ColouriseDocument();
                    newEditor->GotoPos(editor->PositionFromLine(editor->LineFromPosition(editor->GetCurrentPos())));
                    newEditor->GotoPos(editor->GetCurrentPos());
                    newEditor->ScrollToLine(editor->GetFirstVisibleLine());

                    // if we can save it, then add it to the notebook
                    if (newEditor->SaveFile(selectedFileName, selectedFileEncoding, selected_file_bom))
                    {
                        if (!InsertEditorSplitter(-1, splitter, true))
                            splitter->Destroy();
                    }
                    else
                        splitter->Destroy(); // problem saving, delete new editor
                }
            }
            return true;
        }
        case ID_STN_SAVE_ALL:
        {
            SaveAllFiles();
            return true;
        }
        case ID_STN_CLOSE_PAGE:
        {
            if ((GetSelection() != -1) && GetEditor(GetSelection()))
            {
                ClosePage(GetSelection(), true);
            }
            return true;
        }
        case ID_STN_CLOSE_ALL:
        {
            if (wxYES == wxMessageBox(_("Close all pages?"), _("Confim closing all pages"),
                                   wxICON_QUESTION|wxYES_NO, this))
            {
                CloseAllPages(true, -1);
            }
            return true;
        }
        case ID_STN_CLOSE_ALL_OTHERS:
        {
            CloseAllPages(true, GetSelection());
            return true;
        }
        case ID_STN_WIN_PREVIOUS:
        {
            if ((GetPageCount() > 0) && (GetSelection() - 1 >= 0))
                SetSelection(GetSelection() - 1);
            else if (GetPageCount() > 0)
                SetSelection((int)GetPageCount() - 1);
            return true;
        }
        case ID_STN_WIN_NEXT:
        {
            if ((GetPageCount() > 0) && (GetSelection() + 1 < (int)GetPageCount()))
                SetSelection(GetSelection() + 1);
            else if (GetPageCount() > 0)
                SetSelection(0);
            return true;
        }
        case ID_STN_WINDOWS:
        {
            wxSTEditorWindowsDialog(this, _("Windows"));
            return true;
        }
        case ID_STE_PASTE_NEW:
        {
            wxString text;
            if (wxSTEditor::GetClipboardText(&text))
            {
                NewPage();
                wxSTEditor* editor = GetEditor();
                if (editor)
                {
                    editor->SetText(text);
                    editor->SetModified(false);
                }
            }
            return true;
        }
        default:
        {
            if ((win_id >= ID_STN_GOTO_PAGE_START) && (win_id < ID_STN_GOTO_PAGE_START+n_page))
            {
                SetSelection(win_id - ID_STN_GOTO_PAGE_START);
                return true;
            }
            else if ((win_id >= ID_STN_CLOSE_PAGE_START) && (win_id < ID_STN_CLOSE_PAGE_START+n_page))
            {
                ClosePage(win_id - ID_STN_CLOSE_PAGE_START);
                return true;
            }
            break;
        }
    }
    return false;
}