Skip to content

Commit

Permalink
Added double-click to close for more dialogs: enity, AI head, vocal s…
Browse files Browse the repository at this point in the history
…et, shader (refactored), sound, skin, model, prefab

Unrelated changes for: git ignore, close dialog shortcut, sound chooser quick play
  • Loading branch information
duzenko committed Sep 18, 2021
1 parent 57536d2 commit 9cfda49
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -84,3 +84,5 @@ Makefile.in
/tools/msvc/packages
/install/*.testdurations
*.ilk
.vs/
windeps.7z
14 changes: 14 additions & 0 deletions libs/wxutil/EntityClassChooser.cpp
Expand Up @@ -297,12 +297,26 @@ void EntityClassChooser::setupTreeView()
_treeView->AppendIconTextColumn(_("Classname"), _columns.iconAndName.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &EntityClassChooser::_onItemActivated, this );

_treeViewToolbar = new ResourceTreeViewToolbar(parent, _treeView);

parent->GetSizer()->Prepend(_treeView, 1, wxEXPAND | wxBOTTOM | wxRIGHT, 6);
parent->GetSizer()->Prepend(_treeViewToolbar, 0, wxEXPAND | wxALIGN_LEFT | wxBOTTOM | wxLEFT | wxRIGHT, 6);
}

// tree double click or enter key
void EntityClassChooser::_onItemActivated( wxDataViewEvent& ev ) {
wxDataViewItem item = _treeView->GetSelection();
if ( item.IsOk() ) {
TreeModel::Row row( item, *_treeView->GetModel() );

if ( !row[_columns.isFolder].getBool() ) {
onOK( ev );
}
}
}

// Update the usage information
void EntityClassChooser::updateUsageInfo(const std::string& eclass)
{
Expand Down
2 changes: 2 additions & 0 deletions libs/wxutil/EntityClassChooser.h
Expand Up @@ -71,6 +71,8 @@ class EntityClassChooser final :
// Sets the tree selection to the given entity class
const std::string& getSelectedEntityClass() const;

void _onItemActivated( wxDataViewEvent& ev );

// Overridden from wxDialog
int ShowModal() override;

Expand Down
2 changes: 1 addition & 1 deletion libs/wxutil/dialog/MessageBox.cpp
Expand Up @@ -17,7 +17,7 @@ Messagebox::Messagebox(const std::string& title, const std::string& text,
{
if (type == ui::IDialog::MESSAGE_SAVECONFIRMATION)
{
_dialog->SetYesNoLabels(wxString(_("Save")), wxString(_("Close without saving")));
_dialog->SetYesNoLabels(wxString(_("Save")), wxString(_("Close without savi&ng")));
}
}

Expand Down
6 changes: 6 additions & 0 deletions plugins/dm.editing/AIHeadChooserDialog.cpp
Expand Up @@ -70,6 +70,12 @@ AIHeadChooserDialog::AIHeadChooserDialog() :

// Load the found heads into the GtkListStore
populateHeadStore();

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &AIHeadChooserDialog::_onItemActivated, this );
}

void AIHeadChooserDialog::_onItemActivated( wxDataViewEvent& ev ) {
EndModal( wxID_OK );
}

void AIHeadChooserDialog::setSelectedHead(const std::string& headDef)
Expand Down
1 change: 1 addition & 0 deletions plugins/dm.editing/AIHeadChooserDialog.h
Expand Up @@ -58,6 +58,7 @@ class AIHeadChooserDialog :

void handleSelectionChanged();
void onHeadSelectionChanged(wxDataViewEvent& ev);
void _onItemActivated( wxDataViewEvent& ev );
};

} // namespace ui
6 changes: 6 additions & 0 deletions plugins/dm.editing/AIVocalSetChooserDialog.cpp
Expand Up @@ -84,6 +84,12 @@ AIVocalSetChooserDialog::AIVocalSetChooserDialog() :

// Load the found sets into the GtkListStore
populateSetStore();

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &AIVocalSetChooserDialog::_onItemActivated, this );
}

void AIVocalSetChooserDialog::_onItemActivated( wxDataViewEvent& ev ) {
EndModal( wxID_OK );
}

void AIVocalSetChooserDialog::setSelectedVocalSet(const std::string& setName)
Expand Down
1 change: 1 addition & 0 deletions plugins/dm.editing/AIVocalSetChooserDialog.h
Expand Up @@ -60,6 +60,7 @@ class AIVocalSetChooserDialog :

void handleSetSelectionChanged();
void onSetSelectionChanged(wxDataViewEvent& ev);
void _onItemActivated( wxDataViewEvent& ev );
};

} // namespace ui
17 changes: 9 additions & 8 deletions radiant/ui/common/ShaderChooser.cpp
Expand Up @@ -38,14 +38,7 @@ ShaderChooser::ShaderChooser(wxWindow* parent, wxTextCtrl* targetEntry) :

// Set the cursor of the tree view to the currently selected shader
_selector->setSelection(_initialShader);
Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, [&]( wxCommandEvent& ev )
{
if ( !this->_selector->getSelection().empty() ) {
_targetEntry->SetValue( _selector->getSelection() );
shutdown();
EndModal( wxID_OK );
}
} );
Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &ShaderChooser::_onItemActivated, this );
}

// Pack in the ShaderSelector and buttons panel
Expand All @@ -66,6 +59,14 @@ void ShaderChooser::shutdown()
_windowPosition.saveToPath(RKEY_WINDOW_STATE);
}

void ShaderChooser::_onItemActivated( wxDataViewEvent& ev ) {
if ( !_selector->getSelection().empty() ) {
_targetEntry->SetValue( _selector->getSelection() );
shutdown();
EndModal( wxID_OK );
}
}

// Construct the buttons
void ShaderChooser::createButtons(wxPanel* mainPanel, wxBoxSizer* dialogVBox)
{
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/common/ShaderChooser.h
Expand Up @@ -70,6 +70,7 @@ class ShaderChooser :
// button callbacks
void callbackCancel(wxCommandEvent& ev);
void callbackOK(wxCommandEvent& ev);
void _onItemActivated( wxDataViewEvent& ev );
};

} // namespace ui
12 changes: 11 additions & 1 deletion radiant/ui/common/SoundChooser.cpp
Expand Up @@ -154,14 +154,19 @@ SoundChooser::SoundChooser(wxWindow* parent) :
reloadButton->Bind(wxEVT_BUTTON, &SoundChooser::_onReloadSounds, this);

buttonSizer->Prepend(reloadButton, 0, wxRIGHT, 32);
auto* dblClickHint = new wxStaticText( this, wxID_ANY, _( "Ctrl + Double Click on treeview items for quick play" ), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
auto* grid = new wxFlexGridSizer( 2 );
grid->AddGrowableCol( 1 );
grid->Add( dblClickHint, 0, wxALIGN_CENTER_VERTICAL );
grid->Add( buttonSizer, 0, wxALIGN_RIGHT );

auto* treeView = createTreeView(this);
auto* toolbar = new wxutil::ResourceTreeViewToolbar(this, treeView);

GetSizer()->Add(toolbar, 0, wxEXPAND | wxALIGN_LEFT | wxALL, 12);
GetSizer()->Add(treeView, 1, wxEXPAND | wxLEFT | wxRIGHT, 12);
GetSizer()->Add(_preview, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 12);
GetSizer()->Add(buttonSizer, 0, wxALIGN_RIGHT | wxBOTTOM | wxLEFT | wxRIGHT, 12);
GetSizer()->Add(grid, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 12);

_treeView->AddCustomMenuItem(std::make_shared<wxutil::MenuItem>(
new wxutil::IconTextMenuItem(_(SHOW_SHADER_DEF_TEXT), SHOW_SHADER_DEF_ICON),
Expand Down Expand Up @@ -251,6 +256,11 @@ void SoundChooser::_onItemActivated(wxDataViewEvent& ev)
return;
}

if ( !wxGetKeyState( WXK_CONTROL ) ) { // simple double click closes modal, ctrl+dblclk plays sound
EndModal( wxID_OK );
return;
}

// It's a regular item, try to play it back
_preview->playRandomSoundFile();
}
Expand Down
3 changes: 2 additions & 1 deletion radiant/ui/common/SoundShaderPreview.cpp
Expand Up @@ -131,7 +131,8 @@ void SoundShaderPreview::playRandomSoundFile()

if (numFiles > 0)
{
int selected = rand() % numFiles;
static int nextFileToPlay = 0;
int selected = nextFileToPlay++ % numFiles;
_treeView->Select(children[selected]);
handleSelectionChange();

Expand Down
7 changes: 7 additions & 0 deletions radiant/ui/einspector/SkinChooser.cpp
Expand Up @@ -99,6 +99,8 @@ void SkinChooser::populateWindow()
// Overall vbox for treeview/preview and buttons
vbox->Add(splitter, 1, wxEXPAND);
vbox->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_RIGHT | wxTOP, 12);

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &SkinChooser::_onItemActivated, this );
}

int SkinChooser::ShowModal()
Expand Down Expand Up @@ -128,6 +130,11 @@ int SkinChooser::ShowModal()
return returnCode;
}

void SkinChooser::_onItemActivated( wxDataViewEvent& ev ) {
_lastSkin = getSelectedSkin();
EndModal( wxID_OK );
}

// Populate the list of skins
void SkinChooser::populateSkins()
{
Expand Down
2 changes: 2 additions & 0 deletions radiant/ui/einspector/SkinChooser.h
Expand Up @@ -87,6 +87,8 @@ class SkinChooser :
void handleSelectionChange();
void onMainFrameShuttingDown();

void _onItemActivated( wxDataViewEvent& ev );

public:

// Override Dialogbase
Expand Down
9 changes: 9 additions & 0 deletions radiant/ui/modelselector/ModelSelector.cpp
Expand Up @@ -287,6 +287,15 @@ void ModelSelector::setupTreeView(wxWindow* parent)
parent->GetSizer()->Prepend(_treeView, 1, wxEXPAND);
parent->GetSizer()->Prepend(toolbar, 0, wxEXPAND | wxALIGN_LEFT | wxBOTTOM | wxLEFT | wxRIGHT, 6);
parent->GetSizer()->Layout();

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &ModelSelector::_onItemActivated, this );
}

void ModelSelector::_onItemActivated( wxDataViewEvent& ev ) {
std::string modelName = _treeView->GetSelectedModelPath();
if ( !modelName.empty() ) {
onOK( ev );
}
}

void ModelSelector::populateModels()
Expand Down
4 changes: 3 additions & 1 deletion radiant/ui/modelselector/ModelSelector.h
Expand Up @@ -114,7 +114,9 @@ class ModelSelector :
void onRescanFolders(wxCommandEvent& ev);
void onTreeViewPopulationFinished(wxutil::ResourceTreeView::PopulationFinishedEvent& ev);

// Update the info table with information from the currently-selected model, and
void _onItemActivated( wxDataViewEvent& ev );

// Update the info table with information from the currently-selected model, and
// update the displayed model.
void onSelectionChanged(wxDataViewEvent& ev);

Expand Down
6 changes: 6 additions & 0 deletions radiant/ui/particles/ParticlesChooser.cpp
Expand Up @@ -45,6 +45,8 @@ ParticlesChooser::ParticlesChooser() :
GlobalParticlesManager().signal_particlesReloaded().connect(
sigc::mem_fun(this, &ParticlesChooser::reloadParticles)
);

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &ParticlesChooser::_onItemActivated, this );
}

// Create the tree view
Expand All @@ -69,6 +71,10 @@ wxutil::ResourceTreeView* ParticlesChooser::createTreeView(wxWindow* parent)
return _treeView;
}

void ParticlesChooser::_onItemActivated( wxDataViewEvent& ev ) {
EndModal( wxID_OK );
}

/**
* Visitor class to retrieve particle system names and add them to a
* treemodel.
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/particles/ParticlesChooser.h
Expand Up @@ -48,6 +48,7 @@ class ParticlesChooser :
void populateParticleList();

void setSelectedParticle(const std::string& particleName);
void _onItemActivated( wxDataViewEvent& ev );

private:
void reloadParticles();
Expand Down
8 changes: 8 additions & 0 deletions radiant/ui/prefabselector/PrefabSelector.cpp
Expand Up @@ -137,6 +137,14 @@ PrefabSelector::PrefabSelector() :

// Update the controls right now, this also triggers a prefab rescan
onPrefabPathSelectionChanged();

Bind( wxEVT_DATAVIEW_ITEM_ACTIVATED, &PrefabSelector::_onItemActivated, this );
}

void PrefabSelector::_onItemActivated( wxDataViewEvent& ev ) {
if ( !getSelectedPath().empty() && !_treeView->GetIsFolderSelected() ) {
EndModal( wxID_OK );
}
}

void PrefabSelector::setupPathSelector(wxSizer* parentSizer)
Expand Down
1 change: 1 addition & 0 deletions radiant/ui/prefabselector/PrefabSelector.h
Expand Up @@ -107,6 +107,7 @@ class PrefabSelector :
void onFileViewTreePopulated();

void onMainFrameShuttingDown();
void _onItemActivated( wxDataViewEvent& ev );

public:
int ShowModal() override;
Expand Down

0 comments on commit 9cfda49

Please sign in to comment.