impr: Dock newly opened windows by default
This commit is contained in:
parent
e827ad4b8d
commit
c37c53369b
@ -44,6 +44,9 @@ namespace hex {
|
|||||||
[[nodiscard]] const std::string &getUnlocalizedName() const;
|
[[nodiscard]] const std::string &getUnlocalizedName() const;
|
||||||
[[nodiscard]] std::string getName() const;
|
[[nodiscard]] std::string getName() const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool didWindowJustOpen();
|
||||||
|
void setWindowJustOpened(bool state);
|
||||||
|
|
||||||
static void confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn);
|
static void confirmButtons(const std::string &textLeft, const std::string &textRight, const std::function<void()> &leftButtonFn, const std::function<void()> &rightButtonFn);
|
||||||
static void discardNavigationRequests();
|
static void discardNavigationRequests();
|
||||||
|
|
||||||
@ -61,6 +64,7 @@ namespace hex {
|
|||||||
std::string m_unlocalizedViewName;
|
std::string m_unlocalizedViewName;
|
||||||
bool m_windowOpen = false;
|
bool m_windowOpen = false;
|
||||||
std::map<Shortcut, std::function<void()>> m_shortcuts;
|
std::map<Shortcut, std::function<void()>> m_shortcuts;
|
||||||
|
bool m_windowJustOpened = false;
|
||||||
|
|
||||||
friend class ShortcutManager;
|
friend class ShortcutManager;
|
||||||
};
|
};
|
||||||
|
@ -50,6 +50,18 @@ namespace hex {
|
|||||||
return View::toWindowName(this->m_unlocalizedViewName);
|
return View::toWindowName(this->m_unlocalizedViewName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool View::didWindowJustOpen() {
|
||||||
|
bool result = this->m_windowJustOpened;
|
||||||
|
|
||||||
|
this->m_windowJustOpened = false;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void View::setWindowJustOpened(bool state) {
|
||||||
|
this->m_windowJustOpened = state;
|
||||||
|
}
|
||||||
|
|
||||||
void View::discardNavigationRequests() {
|
void View::discardNavigationRequests() {
|
||||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
|
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows))
|
||||||
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
ImGui::GetIO().ConfigFlags &= ~ImGuiConfigFlags_NavEnableKeyboard;
|
||||||
|
@ -727,17 +727,24 @@ namespace hex {
|
|||||||
view->drawContent();
|
view->drawContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle per-view shortcuts
|
|
||||||
if (view->getWindowOpenState() && !popupOpen) {
|
if (view->getWindowOpenState() && !popupOpen) {
|
||||||
auto window = ImGui::FindWindowByName(view->getName().c_str());
|
auto window = ImGui::FindWindowByName(view->getName().c_str());
|
||||||
bool hasWindow = window != nullptr;
|
bool hasWindow = window != nullptr;
|
||||||
bool focused = false;
|
bool focused = false;
|
||||||
|
|
||||||
// Get the currently focused view
|
// Get the currently focused view
|
||||||
if (hasWindow && !(window->Flags & ImGuiWindowFlags_Popup)) {
|
if (hasWindow && (window->Flags & ImGuiWindowFlags_Popup) != ImGuiWindowFlags_Popup) {
|
||||||
ImGui::Begin(View::toWindowName(name).c_str());
|
auto windowName = View::toWindowName(name);
|
||||||
|
ImGui::Begin(windowName.c_str());
|
||||||
|
|
||||||
|
// Detect if the window is focused
|
||||||
focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
focused = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows | ImGuiFocusedFlags_NoPopupHierarchy);
|
||||||
|
|
||||||
|
// Dock the window if it's not already docked
|
||||||
|
if (view->didWindowJustOpen() && !ImGui::IsWindowDocked()) {
|
||||||
|
ImGui::DockBuilderDockWindow(windowName.c_str(), ImHexApi::System::getMainDockSpaceId());
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,8 +434,12 @@ namespace hex::plugin::builtin {
|
|||||||
|
|
||||||
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.view" }, 1000, [] {
|
ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.view" }, 1000, [] {
|
||||||
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
|
for (auto &[name, view] : ContentRegistry::Views::impl::getEntries()) {
|
||||||
if (view->hasViewMenuItemEntry())
|
if (view->hasViewMenuItemEntry()) {
|
||||||
ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &view->getWindowOpenState());
|
auto &state = view->getWindowOpenState();
|
||||||
|
|
||||||
|
if (ImGui::MenuItem(LangEntry(view->getUnlocalizedName()), "", &state))
|
||||||
|
view->setWindowJustOpened(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
@ -14,7 +14,7 @@ namespace hex::plugin::builtin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ViewThemeManager::drawContent() {
|
void ViewThemeManager::drawContent() {
|
||||||
if (ImGui::Begin(View::toWindowName("hex.builtin.view.theme_manager.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse)) {
|
if (ImGui::Begin(View::toWindowName("hex.builtin.view.theme_manager.name").c_str(), &this->m_viewOpen, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoDocking)) {
|
||||||
ImGui::Header("hex.builtin.view.theme_manager.colors"_lang, true);
|
ImGui::Header("hex.builtin.view.theme_manager.colors"_lang, true);
|
||||||
|
|
||||||
// Draw theme handlers
|
// Draw theme handlers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user