void AdvancedModeCommand::onExecute(Context* context) { // Switch advanced mode. MainWindow* mainWindow = App::instance()->getMainWindow(); bool advancedMode = !mainWindow->isAdvancedMode(); mainWindow->setAdvancedMode(advancedMode); if (advancedMode && get_config_bool("AdvancedMode", "Warning", true)) { Accelerator* accel = get_accel_to_execute_command(short_name()); if (accel != NULL) { char warning[1024]; char buf[1024]; UniquePtr<Window> window(app::load_widget<Window>("advanced_mode.xml", "advanced_mode_warning")); Widget* warning_label = app::find_widget<Widget>(window, "warning_label"); Widget* donot_show = app::find_widget<Widget>(window, "donot_show"); strcpy(warning, "You can back pressing the \"%s\" key."); std::sprintf(buf, warning, accel->toString().c_str()); warning_label->setText(buf); window->openWindowInForeground(); set_config_bool("AdvancedMode", "Warning", !donot_show->isSelected()); } } }
void ToolBar::openTipWindow(int group_index, Tool* tool) { if (m_tipWindow) closeTipWindow(); std::string tooltip; if (tool && group_index >= 0) { tooltip = tool->getText(); if (tool->getTips().size() > 0) { tooltip += ":\n"; tooltip += tool->getTips(); } // Tool shortcut Accelerator* accel = get_accel_to_change_tool(tool); if (accel) { tooltip += "\n\nShortcut: "; tooltip += accel->toString(); } } else if (group_index == ConfigureToolIndex) { tooltip = "Configure Tool"; } else if (group_index == MiniEditorVisibilityIndex) { if (App::instance()->getMainWindow()->getMiniEditor()->isMiniEditorEnabled()) tooltip = "Disable Mini-Editor"; else tooltip = "Enable Mini-Editor"; } else return; m_tipWindow = new TipWindow(tooltip.c_str()); m_tipWindow->setArrowAlign(JI_TOP | JI_RIGHT); m_tipWindow->remapWindow(); Rect toolrc = getToolGroupBounds(group_index); Point arrow = tool ? getToolPositionInGroup(group_index, tool): Point(0, 0); int w = m_tipWindow->getBounds().w; int h = m_tipWindow->getBounds().h; int x = toolrc.x - w + (tool && m_popupWindow && m_popupWindow->isVisible() ? arrow.x-m_popupWindow->getBounds().w: 0); int y = toolrc.y + toolrc.h; m_tipWindow->positionWindow(MID(0, x, ui::display_w()-w), MID(0, y, ui::display_h()-h)); if (m_tipOpened) m_tipWindow->openWindow(); else m_tipTimer.start(); }
bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { // We only expect Escape key. DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); Close(); return true; }
IEvent* findEvent(GdkEventKey* event) { // Retrieve the accelerators for this eventkey AcceleratorList accelList = findAccelerator(event); // Did we find any matching accelerators? if (!accelList.empty()) { // Take the first found accelerator Accelerator* accel = *accelList.begin(); return accel->getEvent(); } else { // No accelerators found return NULL; } }
void StatusBar::showTool(int msecs, tools::Tool* tool) { ASSERT(tool != NULL); // Tool name std::string text = tool->getText(); // Tool shortcut Accelerator* accel = get_accel_to_change_tool(tool); if (accel) { text += ", Shortcut: "; text += accel->toString(); } // Set text if (setStatusText(msecs, text.c_str())) { // Show tool m_state = SHOW_TOOL; m_tool = tool; } }
bool Accelerator::operator==(const Accelerator& other) const { // TODO improve this, avoid conversion to std::string return toString() == other.toString(); }