mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 21:27:01 -04:00
Add Select All functionality, closes #19
This commit is contained in:
@@ -250,11 +250,13 @@ bool DataEditor::canCopy() const { return current_editor && current_ed
|
||||
bool DataEditor::canPaste() const { return current_editor && current_editor->canPaste(); }
|
||||
bool DataEditor::canFormat(int type) const { return current_editor && current_editor->canFormat(type); }
|
||||
bool DataEditor::hasFormat(int type) const { return current_editor && current_editor->hasFormat(type); }
|
||||
bool DataEditor::canSelectAll() const { return current_editor && current_editor->canSelectAll(); }
|
||||
|
||||
void DataEditor::doCut() { if (current_editor) current_editor->doCut(); }
|
||||
void DataEditor::doCopy() { if (current_editor) current_editor->doCopy(); }
|
||||
void DataEditor::doPaste() { if (current_editor) current_editor->doPaste(); }
|
||||
void DataEditor::doFormat(int type) { if (current_editor) current_editor->doFormat(type); }
|
||||
void DataEditor::doSelectAll() { if (current_editor) current_editor->doSelectAll(); }
|
||||
|
||||
|
||||
wxMenu* DataEditor::getMenu(int type) const {
|
||||
|
||||
@@ -65,7 +65,12 @@ class DataEditor : public CardViewer {
|
||||
wxMenu* getMenu(int type) const;
|
||||
/// A menu item from getMenu was selected
|
||||
void onCommand(int id);
|
||||
|
||||
|
||||
// --------------------------------------------------- : Text selection
|
||||
|
||||
bool canSelectAll() const;
|
||||
void doSelectAll();
|
||||
|
||||
// --------------------------------------------------- : Search/replace
|
||||
|
||||
/// Do a search or replace action for the given FindInfo
|
||||
|
||||
@@ -40,6 +40,9 @@ bool ItemList::canSelectPrevious() const {
|
||||
bool ItemList::canSelectNext() const {
|
||||
return selected_item_pos >= 0 && static_cast<size_t>(selected_item_pos + 1) < sorted_list.size();
|
||||
}
|
||||
bool ItemList::canSelectAll() const {
|
||||
return sorted_list.size() > 0 && !(GetWindowStyle() & wxLC_SINGLE_SEL);
|
||||
}
|
||||
void ItemList::selectPrevious() {
|
||||
assert(selected_item_pos >= 1);
|
||||
focusNone();
|
||||
@@ -54,6 +57,12 @@ void ItemList::selectFirst() {
|
||||
if (sorted_list.empty()) return;
|
||||
selectItemPos(0, true);
|
||||
}
|
||||
void ItemList::doSelectAll() {
|
||||
long count = GetItemCount();
|
||||
for (long pos = 0; pos < count; ++pos) {
|
||||
Select(pos,true);
|
||||
}
|
||||
}
|
||||
|
||||
bool ItemList::doCut() {
|
||||
// cut = copy + delete
|
||||
|
||||
@@ -32,12 +32,16 @@ class ItemList : public wxListView {
|
||||
bool canSelectPrevious() const;
|
||||
/// Is there a next item to select?
|
||||
bool canSelectNext() const;
|
||||
/// Can we select all?
|
||||
bool canSelectAll() const;
|
||||
/// Move the selection to the previous item (if possible)
|
||||
void selectPrevious();
|
||||
/// Move the selection to the next item (if possible)
|
||||
void selectNext();
|
||||
/// Move the selection to the first item (if possible)
|
||||
void selectFirst();
|
||||
/// Select all items
|
||||
void doSelectAll();
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
|
||||
@@ -399,6 +399,16 @@ void CardsPanel::doPaste() {
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Text selection
|
||||
|
||||
bool CardsPanel::canSelectAll() const {
|
||||
CUT_COPY_PASTE(canSelectAll, return)
|
||||
}
|
||||
|
||||
void CardsPanel::doSelectAll() {
|
||||
CUT_COPY_PASTE(doSelectAll, return (void))
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Searching
|
||||
|
||||
class CardsPanel::SearchFindInfo : public FindInfo {
|
||||
|
||||
@@ -49,6 +49,11 @@ class CardsPanel : public SetWindowPanel {
|
||||
virtual void doCopy();
|
||||
virtual void doPaste();
|
||||
|
||||
// --------------------------------------------------- : Text selection
|
||||
|
||||
bool canSelectAll() const override;
|
||||
void doSelectAll() override;
|
||||
|
||||
// --------------------------------------------------- : Searching (find/replace)
|
||||
|
||||
virtual bool canFind() const { return true; }
|
||||
|
||||
@@ -273,6 +273,16 @@ void KeywordsPanel::doCopy() { CUT_COPY_PASTE(doCopy, return (void), f
|
||||
void KeywordsPanel::doCut() { CUT_COPY_PASTE(doCut, return (void), !list->getKeyword() || list->getKeyword()->fixed) }
|
||||
void KeywordsPanel::doPaste() { CUT_COPY_PASTE(doPaste, return (void), !list->getKeyword() || list->getKeyword()->fixed) }
|
||||
|
||||
// ----------------------------------------------------------------------------- : Text selection
|
||||
|
||||
bool KeywordsPanel::canSelectAll() const {
|
||||
CUT_COPY_PASTE(canSelectAll, return, false)
|
||||
}
|
||||
|
||||
void KeywordsPanel::doSelectAll() {
|
||||
CUT_COPY_PASTE(doSelectAll, return (void), false)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
void KeywordsPanel::onChangeSet() {
|
||||
|
||||
@@ -43,7 +43,10 @@ class KeywordsPanel : public SetWindowPanel {
|
||||
virtual void doCut();
|
||||
virtual void doCopy();
|
||||
virtual void doPaste();
|
||||
|
||||
|
||||
virtual bool canSelectAll() const;
|
||||
virtual void doSelectAll();
|
||||
|
||||
private:
|
||||
DECLARE_EVENT_TABLE();
|
||||
|
||||
|
||||
@@ -60,7 +60,11 @@ class SetWindowPanel : public wxPanel, public SetView {
|
||||
virtual void doPaste() {} ///< Paste the contents of the clipboard
|
||||
virtual void doCopy() {} ///< Copy the selection to the clipboard
|
||||
virtual void doCut() {} ///< Cut the selection to the clipboard
|
||||
|
||||
|
||||
// --------------------------------------------------- : Selecting
|
||||
virtual bool canSelectAll() const { return false; }
|
||||
virtual void doSelectAll() {}
|
||||
|
||||
// --------------------------------------------------- : Searching (find/replace)
|
||||
virtual bool canFind() const { return false; } ///< Is finding possible?
|
||||
virtual bool canReplace() const { return false; } ///< Is replacing possible?
|
||||
|
||||
@@ -87,3 +87,5 @@ bool SetInfoPanel::canPaste() const { return editor->canPaste(); }
|
||||
void SetInfoPanel::doCut() { editor->doCut(); }
|
||||
void SetInfoPanel::doCopy() { editor->doCopy(); }
|
||||
void SetInfoPanel::doPaste() { editor->doPaste(); }
|
||||
bool SetInfoPanel::canSelectAll() const { return editor->canSelectAll(); }
|
||||
void SetInfoPanel::doSelectAll() { editor->doSelectAll(); }
|
||||
|
||||
@@ -28,12 +28,14 @@ class SetInfoPanel : public SetWindowPanel {
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
virtual bool canCut() const;
|
||||
virtual bool canCopy() const;
|
||||
virtual bool canCut() const;
|
||||
virtual bool canCopy() const;
|
||||
virtual bool canPaste() const;
|
||||
virtual bool canSelectAll() const;
|
||||
virtual void doCut();
|
||||
virtual void doCopy();
|
||||
virtual void doPaste();
|
||||
virtual void doSelectAll();
|
||||
|
||||
protected:
|
||||
virtual void onChangeSet();
|
||||
|
||||
@@ -156,6 +156,8 @@ bool StylePanel::canPaste() const { CUT_COPY_PASTE(canPaste, return) }
|
||||
void StylePanel::doCopy() { CUT_COPY_PASTE(doCopy, return (void)) }
|
||||
void StylePanel::doCut() { CUT_COPY_PASTE(doCut, return (void)) }
|
||||
void StylePanel::doPaste() { CUT_COPY_PASTE(doPaste, return (void)) }
|
||||
bool StylePanel::canSelectAll() const { CUT_COPY_PASTE(canSelectAll, return) }
|
||||
void StylePanel::doSelectAll() { CUT_COPY_PASTE(doSelectAll, return (void)) }
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
|
||||
@@ -33,9 +33,11 @@ class StylePanel : public SetWindowPanel {
|
||||
virtual bool canCut() const;
|
||||
virtual bool canCopy() const;
|
||||
virtual bool canPaste() const;
|
||||
virtual bool canSelectAll() const;
|
||||
virtual void doCut();
|
||||
virtual void doCopy();
|
||||
virtual void doPaste();
|
||||
virtual void doSelectAll();
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
virtual void selectCard(const CardP& card);
|
||||
|
||||
@@ -82,6 +82,8 @@ SetWindow::SetWindow(Window* parent, const SetP& set)
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_COPY, "copy", "copy");
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_PASTE, "paste", "paste");
|
||||
menuEdit->AppendSeparator();
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_SELECT_ALL, nullptr, "select_all");
|
||||
menuEdit->AppendSeparator();
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_FIND, "find", "find");
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_FIND_NEXT, nullptr, "find_next");
|
||||
add_menu_item_tr(menuEdit, ID_EDIT_REPLACE, nullptr, "replace");
|
||||
@@ -510,6 +512,7 @@ void SetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
case ID_EDIT_CUT : ev.Enable(current_panel->canCut()); break;
|
||||
case ID_EDIT_COPY : ev.Enable(current_panel->canCopy()); break;
|
||||
case ID_EDIT_PASTE : ev.Enable(current_panel->canPaste()); break;
|
||||
case ID_EDIT_SELECT_ALL: ev.Enable(current_panel->canSelectAll()); break;
|
||||
case ID_EDIT_FIND : ev.Enable(current_panel->canFind()); break;
|
||||
case ID_EDIT_FIND_NEXT : ev.Enable(current_panel->canFind()); break;
|
||||
case ID_EDIT_REPLACE : ev.Enable(current_panel->canReplace());break;
|
||||
@@ -736,6 +739,10 @@ void SetWindow::onEditPaste(wxCommandEvent&) {
|
||||
current_panel->doPaste();
|
||||
}
|
||||
|
||||
void SetWindow::onEditSelectAll(wxCommandEvent&) {
|
||||
current_panel->doSelectAll();
|
||||
}
|
||||
|
||||
void SetWindow::onEditFind(wxCommandEvent&) {
|
||||
find_dialog = make_unique<wxFindReplaceDialog>(this, &find_data, _("Find"));
|
||||
find_dialog->Show();
|
||||
@@ -849,6 +856,7 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame)
|
||||
EVT_MENU (ID_EDIT_CUT, SetWindow::onEditCut)
|
||||
EVT_MENU (ID_EDIT_COPY, SetWindow::onEditCopy)
|
||||
EVT_MENU (ID_EDIT_PASTE, SetWindow::onEditPaste)
|
||||
EVT_MENU (ID_EDIT_SELECT_ALL, SetWindow::onEditSelectAll)
|
||||
EVT_MENU (ID_EDIT_FIND, SetWindow::onEditFind)
|
||||
EVT_MENU (ID_EDIT_FIND_NEXT, SetWindow::onEditFindNext)
|
||||
EVT_MENU (ID_EDIT_REPLACE, SetWindow::onEditReplace)
|
||||
|
||||
@@ -141,6 +141,7 @@ private:
|
||||
void onEditCut (wxCommandEvent&);
|
||||
void onEditCopy (wxCommandEvent&);
|
||||
void onEditPaste (wxCommandEvent&);
|
||||
void onEditSelectAll (wxCommandEvent&);
|
||||
void onEditFind (wxCommandEvent&);
|
||||
void onEditFindNext (wxCommandEvent&);
|
||||
void onEditReplace (wxCommandEvent&);
|
||||
|
||||
@@ -91,6 +91,9 @@ class ValueEditor {
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
virtual bool canSelectAll() const { return false; }
|
||||
virtual void doSelectAll() {}
|
||||
|
||||
/// Select the specified range (if it makes sense)
|
||||
virtual void select(size_t start, size_t end) {}
|
||||
/// Determine the selected range
|
||||
|
||||
@@ -1165,6 +1165,15 @@ bool TextValueEditor::isWordBoundary(size_t pos_i) const {
|
||||
}
|
||||
}
|
||||
|
||||
void TextValueEditor::doSelectAll() {
|
||||
size_t old_selection_start_i = selection_start_i;
|
||||
size_t old_selection_end_i = selection_end_i;
|
||||
selection_start_i = 0;
|
||||
selection_end_i = value().value().size();
|
||||
fixSelection(TYPE_INDEX);
|
||||
redrawSelection(old_selection_start_i, old_selection_end_i, dropDownShown());
|
||||
}
|
||||
|
||||
void TextValueEditor::select(size_t start, size_t end) {
|
||||
selection_start = start;
|
||||
selection_end = end;
|
||||
|
||||
@@ -71,7 +71,9 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
|
||||
virtual void doFormat(int type);
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
|
||||
virtual bool canSelectAll() const { return true; }
|
||||
virtual void doSelectAll();
|
||||
virtual void select(size_t start, size_t end);
|
||||
virtual size_t selectionStart() const { return selection_start; }
|
||||
virtual size_t selectionEnd() const { return selection_end; }
|
||||
|
||||
Reference in New Issue
Block a user