Esempio n. 1
0
ChoiceMenuEditorForm::ChoiceMenuEditorForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChoiceMenuEditorForm)
{
    ui->setupUi(this);
    connect(ui->pushButtonAddOption, SIGNAL(clicked()), this, SLOT(AddMenuItem()));
    connect(ui->pushButtonDelOption, SIGNAL(clicked()), this, SLOT(RemoveMenuItem()));
    connect(ui->pushButtonFinished, SIGNAL(clicked()), this, SLOT(Finished()));
    connect(ui->pushButtonCancel, SIGNAL(clicked()), this, SLOT(Cancel()));

    MenuItems.push_back("menu:");
    ui->listWidgetChoices->setWordWrap(true);
    items.clear();
}
Esempio n. 2
0
void BundlePane::OnTreeEndDrag(wxTreeEvent& event) {
	if (!m_draggedItem.IsOk()) return;

	const wxTreeItemId itemSrc = m_draggedItem;
	const wxTreeItemId itemDst = event.GetItem();
	m_draggedItem = wxTreeItemId();

	if (!itemDst.IsOk()) return; // Invalid destintion
	if (itemSrc == itemDst) return; // Can't drag to self
	if (IsTreeItemParentOf(itemSrc, itemDst)) return; // Can't drag to one of your own children

	wxLogDebug(wxT("Ending Drag over item: %s"), m_bundleTree->GetItemText(itemDst).c_str());

	const BundleItemData* srcData = (BundleItemData*)m_bundleTree->GetItemData(itemSrc);
	const BundleItemData* dstData = (BundleItemData*)m_bundleTree->GetItemData(itemDst);

	if (!dstData->IsMenuItem()) return; // You can only drag items to menu
	if (dstData->m_bundleId != srcData->m_bundleId) return; // Items can only be dragged within same bundle

	// We have to cache uuid of submenus
	const wxString subUuid = (srcData->m_type == BUNDLE_SUBDIR) ? srcData->m_uuid : wxString(wxEmptyString);

	const unsigned int bundleId = srcData->m_bundleId;
	PListDict infoDict = GetEditableMenuPlist(bundleId);
	
	// Insert the item
	Freeze();
	const wxString name = m_bundleTree->GetItemText(itemSrc);
	const wxTreeItemId insertedItem = InsertMenuItem(itemDst, name, new BundleItemData(*srcData), infoDict);

	if (srcData->m_type == BUNDLE_SUBDIR) {
		CopySubItems(itemSrc, insertedItem);
	}

	// Delete source ref
	if (srcData->IsMenuItem()) RemoveMenuItem(itemSrc, false, infoDict);
	Thaw();

	// Save the modified plist
	m_plistHandler.SaveBundle(bundleId);

	// Update menu in editorFrame
	m_syntaxHandler.ReParseBundles(true/*onlyMenu*/);
}
Esempio n. 3
0
void BundlePane::DeleteItem() {
	const wxTreeItemId selItem = m_bundleTree->GetSelection();
	if (!selItem.IsOk()) return; // Can't delete nothing

	const BundleItemData* data = (BundleItemData*)m_bundleTree->GetItemData(selItem);
	if (data->m_type == BUNDLE_MENU) return; // can't delete menu root
	const unsigned int bundleId = data->m_bundleId;

	if (data->IsMenuItem()) {
		PListDict infoDict = GetEditableMenuPlist(bundleId);
		RemoveMenuItem(selItem, true, infoDict);
		m_plistHandler.SaveBundle(bundleId);

		// Update menu in editorFrame
		m_syntaxHandler.ReParseBundles(true/*onlyMenu*/);
		return;
	}

	bool needFullReload = false;

	switch (data->m_type) {
	case BUNDLE_BUNDLE:
		{
			const wxString msg = _("Are you sure you wish to delete this Bundle?");

			if (wxMessageBox(msg, _("Deleting Bundle"), wxICON_EXCLAMATION|wxOK|wxCANCEL) == wxOK) {
				m_plistHandler.DeleteBundle(data->m_bundleId);
				needFullReload = true;
			}
			else return;
		}
		break;
	case BUNDLE_COMMAND:
	case BUNDLE_SNIPPET:
		{
			m_plistHandler.Delete(data->m_type, data->m_bundleId, data->m_itemId);

			// Check if it should also be removed from menu
			wxTreeItemId menuItem = FindMenuItem(data->m_type, data->m_bundleId, data->m_itemId);
			if (menuItem.IsOk()) {
				PListDict infoDict = GetEditableMenuPlist(bundleId);
				RemoveMenuItem(menuItem, true, infoDict);
				m_plistHandler.SaveBundle(bundleId);
			}
		}
		break;
	case BUNDLE_DRAGCMD:
		m_plistHandler.Delete(data->m_type, data->m_bundleId, data->m_itemId);
		break;
	case BUNDLE_PREF:
	case BUNDLE_LANGUAGE:
		m_plistHandler.Delete(data->m_type, data->m_bundleId, data->m_itemId);
		needFullReload = true;
		break;
	default:
		wxASSERT(false);
	}

	m_bundleTree->Delete(selItem);

	wxBusyCursor wait; // Show user that we are reloading
	if (needFullReload) {
		// if bundles are deleted or prefs or languages changed,
		// we have to call LoadBundles since all syntaxes will have to be reloaded
		m_syntaxHandler.LoadBundles(TmSyntaxHandler::cxRELOAD);
	}
	else m_syntaxHandler.ReParseBundles();
}