📄 configtoolview.cpp
字号:
ctProperty* property = editor->FindSelectedProperty(row) ;
if (property && property->IsCustom())
{
wxString name(property->GetName());
wxString msg;
msg.Printf(_("Delete custom property '%s'?"), (const wxChar*) name);
if (wxYES == wxMessageBox(msg, _("Delete property"), wxICON_EXCLAMATION|wxYES_NO))
{
sel->GetProperties().RemoveProperty(property);
editor->ShowItem(sel);
delete property;
OnChangeFilename();
}
}
}
}
/// Add a custom property: update event
void ctConfigToolView::OnUpdateAddCustomProperty(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
event.Enable( doc && GetSelection() && GetSelection()->GetParent() );
}
/// Edit a custom property: update event
void ctConfigToolView::OnUpdateEditCustomProperty(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor();
int row;
event.Enable( doc && sel && sel->GetParent() && editor &&
editor->FindSelectedProperty(row) &&
editor->FindSelectedProperty(row)->IsCustom() );
}
/// Delete a custom property: update event
void ctConfigToolView::OnUpdateDeleteCustomProperty(wxUpdateUIEvent& event)
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctConfigItem* sel = GetSelection();
ctPropertyEditor* editor = wxGetApp().GetMainFrame()->GetPropertyEditor();
int row;
event.Enable( doc && sel && sel->GetParent() && editor &&
editor->FindSelectedProperty(row) &&
editor->FindSelectedProperty(row)->IsCustom() );
}
/// Regenerate setup.h and configure command
void ctConfigToolView::RegenerateSetup()
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
ctOutputWindow* setupPage = wxGetApp().GetMainFrame()->GetSetupPage() ;
ctOutputWindow* configurePage = wxGetApp().GetMainFrame()->GetConfigurePage() ;
wxString setupStr = doc->GenerateSetup();
wxString configureStr = doc->GenerateConfigureCommand();
setupPage->SetText(setupStr);
configurePage->SetText(configureStr);
}
/// Regenerate if selected a tab
void ctConfigToolView::OnTabSelect(wxNotebookEvent& event)
{
if (wxGetApp().GetMainFrame()->GetMainNotebook() != event.GetEventObject())
{
event.Skip();
return;
}
if (event.GetSelection() > 0)
{
RegenerateSetup();
}
}
void ctConfigToolView::OnSaveSetupFile(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
wxString setupStr = doc->GenerateSetup();
wxString filename = _T("setup.h");
wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir;
if (path.empty())
path = doc->GetFrameworkDir(false);
wxString wildcard = _T("Header files (*.h)|*.h|All files (*.*)|*.*");
wxFileDialog dialog(wxTheApp->GetTopWindow(),
_("Save Setup File As"),
path, filename ,
wildcard, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal() == wxID_OK)
{
wxString fullPath = dialog.GetPath();
wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath);
wxFileOutputStream osFile(fullPath);
if (!osFile.Ok())
{
wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK);
return;
}
wxTextOutputStream stream(osFile);
stream << setupStr;
}
}
void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
wxString configureStr = doc->GenerateConfigureCommand();
wxString filename = _T("configurewx.sh");
wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir;
if (path.empty())
path = doc->GetFrameworkDir(false);
wxString wildcard = _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*");
wxFileDialog dialog(wxTheApp->GetTopWindow(),
_("Save Configure Command File As"),
path, filename ,
wildcard, wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal() == wxID_OK)
{
wxString fullPath = dialog.GetPath();
wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath);
wxFileOutputStream osFile(fullPath);
if (!osFile.Ok())
{
wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION|wxOK);
return;
}
wxTextOutputStream stream(osFile);
stream << configureStr;
}
}
void ctConfigToolView::OnUpdateSaveSetupFile(wxUpdateUIEvent& event)
{
event.Enable(true);
}
void ctConfigToolView::OnUpdateSaveConfigureCommand(wxUpdateUIEvent& event)
{
event.Enable(true);
}
/// Find text
void ctConfigToolView::OnFind(wxCommandEvent& WXUNUSED(event))
{
ctFindReplaceDialog* dialog = wxGetApp().GetMainFrame()->GetFindDialog();
if (dialog)
{
dialog->Raise();
}
if (!dialog)
{
int style = wxFR_NOUPDOWN;
wxString caption(wxT("Find text in settings"));
int flags = wxFR_DOWN;
if (wxGetApp().GetSettings().m_matchCase)
flags|=wxFR_MATCHCASE;
if (wxGetApp().GetSettings().m_matchWholeWord)
flags|=wxFR_WHOLEWORD;
ctFindReplaceDialog::sm_findData.SetFlags(flags);
dialog = new ctFindReplaceDialog(wxGetApp().GetMainFrame(), caption, style);
dialog->Show(true);
}
}
/// Update find text
void ctConfigToolView::OnUpdateFind(wxUpdateUIEvent& event)
{
event.Enable(true);
}
/// Save default file type
void ctConfigToolView::OnGo(wxCommandEvent& WXUNUSED(event))
{
ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument();
wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir;
if (!path.empty())
{
if (wxGetApp().GetSettings().m_defaultFileKind == wxT("Setup file"))
{
// setup.h
wxString setupStr = doc->GenerateSetup();
wxString fullPath = path + wxFILE_SEP_PATH + wxT("setup.h");
if (wxFileExists(fullPath))
{
wxString msg;
msg.Printf(wxT("Overwrite existing file %s?"), (const wxChar*) fullPath);
int ans = wxMessageBox(msg, _("Save Setup File"), wxICON_QUESTION|wxYES_NO|wxCANCEL);
if (ans == wxCANCEL)
return;
if (ans == wxNO)
return;
}
wxFileOutputStream stream(fullPath);
if (!stream.Ok())
{
wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK);
return;
}
stream << setupStr;
}
else if (wxGetApp().GetSettings().m_defaultFileKind == wxT("Configure script"))
{
// configurewx.sh
wxString configureStr = doc->GenerateConfigureCommand();
wxString fullPath = path + wxFILE_SEP_PATH + wxT("configurewx.sh");
if (wxFileExists(fullPath))
{
wxString msg;
msg.Printf(wxT("Overwrite existing file %s?"), (const wxChar*) fullPath);
int ans = wxMessageBox(msg, _("Save Configure Script"), wxICON_QUESTION|wxYES_NO|wxCANCEL);
if (ans == wxCANCEL)
return;
if (ans == wxNO)
return;
}
wxFileOutputStream stream(fullPath);
if (!stream.Ok())
{
wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Script"), wxICON_EXCLAMATION|wxOK);
return;
}
stream << configureStr;
}
else
{
wxMessageBox(wxT("Unrecognised default file type."));
}
}
}
/// Update
void ctConfigToolView::OnUpdateGo(wxUpdateUIEvent& event)
{
wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir;
event.Enable(!path.empty());
}
//----------------------------------------------------------------------------
// ctFindReplaceDialog
//----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(ctFindReplaceDialog, wxFindReplaceDialog)
EVT_FIND(wxID_ANY, ctFindReplaceDialog::OnFind)
EVT_FIND_NEXT(wxID_ANY, ctFindReplaceDialog::OnFind)
EVT_FIND_CLOSE(wxID_ANY, ctFindReplaceDialog::OnClose)
END_EVENT_TABLE()
wxFindReplaceData ctFindReplaceDialog::sm_findData;
wxString ctFindReplaceDialog::sm_currentItem = wxEmptyString;
ctFindReplaceDialog::ctFindReplaceDialog( wxWindow *parent, const wxString& title,
long style):
wxFindReplaceDialog( parent, & sm_findData, title, style )
{
sm_currentItem = wxEmptyString;
if (parent)
((ctMainFrame*) parent)->SetFindDialog(this);
}
void ctFindReplaceDialog::OnFind(wxFindDialogEvent& event)
{
wxString textToFind = event.GetFindString();
bool matchCase = ((event.GetFlags() & wxFR_MATCHCASE) != 0);
bool wholeWord = ((event.GetFlags() & wxFR_WHOLEWORD) != 0);
wxGetApp().GetSettings().m_matchCase = matchCase;
wxGetApp().GetSettings().m_matchWholeWord = wholeWord;
if (!DoFind(textToFind, matchCase, wholeWord))
{
wxMessageBox(wxT("No more matches."), wxT("Search"), wxOK|wxICON_INFORMATION, this);
}
}
bool ctFindReplaceDialog::DoFind(const wxString& textToFind, bool matchCase, bool wholeWord, bool wrap)
{
ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument();
if (!doc)
return false;
ctConfigToolView* view = (ctConfigToolView*) doc->GetFirstView();
ctConfigItem* currentItem = NULL;
ctConfigItem* focusItem = view->GetSelection();
if (!focusItem)
{
focusItem = doc->GetTopItem();
if (!focusItem)
return false;
}
if (!sm_currentItem.empty())
{
currentItem = doc->GetTopItem()->FindItem(sm_currentItem);
}
// If we were at this item last time, skip the first one.
bool skipFirstItem = (currentItem == focusItem);
currentItem = FindNextItem(doc, currentItem, textToFind, matchCase, wholeWord, wrap,
skipFirstItem);
if (currentItem)
{
sm_currentItem = currentItem->GetName();
wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(currentItem->GetTreeItemId());
return true;
}
else
{
sm_currentItem = wxEmptyString;
}
return false;
}
ctConfigItem* ctFindReplaceDialog::FindNextItem(ctConfigToolDoc* doc,
ctConfigItem* item,
const wxString& text,
bool matchCase,
bool matchWordOnly,
bool wrap,
bool skipFirst)
{
ctConfigItem* firstInDoc = NULL;
wxString text2(text);
if (!matchCase)
text2.MakeLower();
ctConfigItem* found = NULL;
ctConfigItem* next = item;
int i = 0;
do
{
// If starting the search from beginning, we can now
// set the value of 'item' in the 2nd iteration without immediately
// dropping out of the while loop because card == next
if (!item && (i > 0))
item = firstInDoc;
// We might want to start from this item if skipFirst is false.
if ((i == 0) && !skipFirst && next)
{
}
else
next = doc->FindNextItem(next, wrap);
// Save to be used in iteration 2
if ((i == 0) && !item)
firstInDoc = next;
if (next)
{
wxString str(next->GetName());
wxString description(next->GetPropertyString(wxT("description")));
wxString notes(next->GetPropertyString(wxT("notes")));
if (!matchCase)
{
str.MakeLower();
description.MakeLower();
notes.MakeLower();
}
if (ctMatchString(str, text2, matchWordOnly) ||
ctMatchString(description, text2, matchWordOnly) ||
ctMatchString(notes, text2, matchWordOnly))
{
found = next;
}
}
else
break; // Didn't find an item at all
i ++;
}
while (!found && item != next);
if (item == found && !firstInDoc)
return NULL;
else
return found;
}
void ctFindReplaceDialog::OnClose(wxFindDialogEvent& event)
{
bool matchCase = ((event.GetFlags() & wxFR_MATCHCASE) != 0);
bool wholeWord = ((event.GetFlags() & wxFR_WHOLEWORD) != 0);
wxGetApp().GetSettings().m_matchCase = matchCase;
wxGetApp().GetSettings().m_matchWholeWord = wholeWord;
this->Destroy();
((ctMainFrame*) GetParent())->SetFindDialog(NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -