command palette: get rid of "extra actions" enum
This commit is contained in:
parent
66fbc1f2f1
commit
869e5d7be9
|
@ -19,39 +19,13 @@
|
|||
|
||||
#include "gui.h"
|
||||
#include "guiConst.h"
|
||||
#include "commandPalette.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
#include <fmt/printf.h>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include "../ta-log.h"
|
||||
|
||||
enum CommandPaletteType {
|
||||
CMDPAL_TYPE_MAIN = 0,
|
||||
CMDPAL_TYPE_RECENT,
|
||||
// TODO: are there more?
|
||||
|
||||
CMDPAL_TYPE_MAX,
|
||||
};
|
||||
|
||||
enum CommandPaletteExtraAction {
|
||||
CMDPAL_EXTRA_RECENT = 0,
|
||||
|
||||
CMDPAL_EXTRA_MAX,
|
||||
};
|
||||
|
||||
struct CommandPaletteExtraDef {
|
||||
const char* name;
|
||||
const char* friendlyName;
|
||||
CommandPaletteExtraDef(const char* n, const char* fn):
|
||||
name(n), friendlyName(fn) {}
|
||||
};
|
||||
|
||||
#define D CommandPaletteExtraDef
|
||||
const CommandPaletteExtraDef commandPaletteExtras[CMDPAL_EXTRA_MAX] = {
|
||||
D("CMDPAL_EXTRA_RECENT", "Recent files"),
|
||||
};
|
||||
#undef D
|
||||
|
||||
static inline bool matchFuzzy(const char* haystack,const char* needle) {
|
||||
size_t h_i=0; // haystack idx
|
||||
size_t n_i=0; // needle idx
|
||||
|
@ -90,11 +64,6 @@ void FurnaceGUI::drawPalette() {
|
|||
paletteSearchResults.push_back(i);
|
||||
}
|
||||
}
|
||||
for (int i=0; i<CMDPAL_EXTRA_MAX; i++) {
|
||||
if (matchFuzzy(commandPaletteExtras[i].friendlyName,paletteQuery.c_str())) {
|
||||
paletteSearchResults.push_back(GUI_ACTION_MAX+i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CMDPAL_TYPE_RECENT:
|
||||
|
@ -129,7 +98,7 @@ void FurnaceGUI::drawPalette() {
|
|||
const char *s="???";
|
||||
switch (curPaletteType) {
|
||||
case CMDPAL_TYPE_MAIN:
|
||||
s=(id<GUI_ACTION_MAX)?(guiActions[id].friendlyName):(commandPaletteExtras[id-GUI_ACTION_MAX].friendlyName);
|
||||
s=guiActions[id].friendlyName;
|
||||
break;
|
||||
case CMDPAL_TYPE_RECENT:
|
||||
s=recentFile[id].c_str();
|
||||
|
@ -139,7 +108,7 @@ void FurnaceGUI::drawPalette() {
|
|||
break;
|
||||
};
|
||||
|
||||
if (ImGui::Selectable(s, current)) {
|
||||
if (ImGui::Selectable(s,current)) {
|
||||
curPaletteChoice=i;
|
||||
accepted=true;
|
||||
}
|
||||
|
@ -167,23 +136,15 @@ void FurnaceGUI::drawPalette() {
|
|||
|
||||
switch (curPaletteType) {
|
||||
case CMDPAL_TYPE_MAIN:
|
||||
if (i<GUI_ACTION_MAX) {
|
||||
doAction(i);
|
||||
resetPalette(this);
|
||||
doAction(i);
|
||||
if (i<GUI_ACTION_CMDPAL_MIN || GUI_ACTION_CMDPAL_MAX<i) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
} else {
|
||||
switch (i-GUI_ACTION_MAX) {
|
||||
case CMDPAL_EXTRA_RECENT:
|
||||
resetPalette(this);
|
||||
curPaletteType=CMDPAL_TYPE_RECENT;
|
||||
break;
|
||||
default:
|
||||
// TODO: PANIC! DIE! PERISH!
|
||||
break;
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case CMDPAL_TYPE_RECENT:
|
||||
resetPalette(this);
|
||||
openRecentFile(recentFile[i]);
|
||||
ImGui::CloseCurrentPopup();
|
||||
break;
|
||||
|
|
26
src/gui/commandPalette.h
Normal file
26
src/gui/commandPalette.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2023 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
enum CommandPaletteType {
|
||||
CMDPAL_TYPE_MAIN = 0,
|
||||
CMDPAL_TYPE_RECENT,
|
||||
// TODO: are there more?
|
||||
|
||||
CMDPAL_TYPE_MAX,
|
||||
};
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "gui.h"
|
||||
#include "commandPalette.h"
|
||||
#include "../ta-log.h"
|
||||
#include <fmt/printf.h>
|
||||
#include <imgui.h>
|
||||
|
@ -187,6 +188,9 @@ void FurnaceGUI::doAction(int what) {
|
|||
case GUI_ACTION_COMMAND_PALETTE:
|
||||
displayPalette=true;
|
||||
break;
|
||||
case GUI_ACTION_CMDPAL_RECENT:
|
||||
curPaletteType=CMDPAL_TYPE_RECENT;
|
||||
break;
|
||||
case GUI_ACTION_WINDOW_EDIT_CONTROLS:
|
||||
nextWindow=GUI_WINDOW_EDIT_CONTROLS;
|
||||
break;
|
||||
|
|
|
@ -488,6 +488,10 @@ enum FurnaceGUIActions {
|
|||
GUI_ACTION_CLEAR,
|
||||
|
||||
GUI_ACTION_COMMAND_PALETTE,
|
||||
GUI_ACTION_CMDPAL_MIN,
|
||||
GUI_ACTION_CMDPAL_RECENT,
|
||||
GUI_ACTION_CMDPAL_MAX,
|
||||
|
||||
GUI_ACTION_WINDOW_EDIT_CONTROLS,
|
||||
GUI_ACTION_WINDOW_ORDERS,
|
||||
GUI_ACTION_WINDOW_INS_LIST,
|
||||
|
|
|
@ -493,6 +493,10 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={
|
|||
D("CLEAR", "Clear song data", 0),
|
||||
|
||||
D("COMMAND_PALETTE", "Command Palette", FURKMOD_CMD|SDLK_p),
|
||||
D("CMDPAL_MIN", "", NOT_AN_ACTION),
|
||||
D("CMDPAL_RECENT", "Recent files (Palette)", 0),
|
||||
D("CMDPAL_MAX", "", NOT_AN_ACTION),
|
||||
|
||||
D("WINDOW_EDIT_CONTROLS", "Edit Controls", 0),
|
||||
D("WINDOW_ORDERS", "Orders", 0),
|
||||
D("WINDOW_INS_LIST", "Instrument List", 0),
|
||||
|
|
Loading…
Reference in a new issue