Exemplo n.º 1
0
void MFolderFromProfile::SetFlags(int flags)
{
   int typeAndFlags = READ_CONFIG(m_profile, MP_FOLDER_TYPE);
   if ( (typeAndFlags & ~MF_TYPEMASK) == flags )
   {
      // flags unchanged
      return;
   }

   typeAndFlags = CombineFolderTypeAndFlags(GetFolderType(typeAndFlags),
                                            flags);
   m_profile->writeEntry(MP_FOLDER_TYPE, typeAndFlags);
}
Exemplo n.º 2
0
void CExtension::AddDefaultLibraryReferences (SDesignLoadCtx &Ctx)

//	AddDefaultLibraryReferences
//
//	Adds default references if we have no other libraries

	{
	if (GetLibraryCount() == 0)
		{
		//	Add compatibility library if we don't load anything else
		//	(This should only happen for older extensions. All official 
		//	extensions use either RPG or RTS libraries).

		if (GetAPIVersion() < 26 && GetFolderType() != folderBase)
			m_bUsesCompatibilityLibrary = true;
		}
	}
Exemplo n.º 3
0
afx_msg void
CProjectWindow::OnProjectGroupNew()
{
  HTREEITEM item = m_TreeControl.GetSelectedItem();

  if (!IsTreeItemFolder(m_TreeControl, item))
    return;

  switch (GetFolderType(m_TreeControl, item))
  {
    case tiMaps:         ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW_MAP,         0), 0); break;
    case tiSpritesets:   ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW_SPRITESET,   0), 0); break;
    case tiScripts:      ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW_SCRIPT,      0), 0); break;
    case tiFonts:        ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW_FONT,        0), 0); break;
    case tiWindowStyles: ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW_WINDOWSTYLE, 0), 0); break;
    case tiImages:       ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_FILE_NEW_IMAGE,       0), 0); break;
  }
}
Exemplo n.º 4
0
afx_msg void
CProjectWindow::OnProjectGroupInsert()
{
  HTREEITEM item = m_TreeControl.GetSelectedItem();
  if (!IsTreeItemFolder(m_TreeControl, item))
    return;

  switch (GetFolderType(m_TreeControl, item))
  {
    case tiMaps:         ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_MAP,         0), 0); break;
    case tiSpritesets:   ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_SPRITESET,   0), 0); break;
    case tiScripts:      ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_SCRIPT,      0), 0); break;
    case tiSounds:       ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_SOUND,       0), 0); break;
    case tiFonts:        ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_FONT,        0), 0); break;
    case tiWindowStyles: ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_WINDOWSTYLE, 0), 0); break;
    case tiImages:       ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_IMAGE,       0), 0); break;
    case tiAnimations:   ::PostMessage(m_MainWindow->m_hWnd, WM_COMMAND, MAKEWPARAM(ID_PROJECT_INSERT_ANIMATION,   0), 0); break;
  }
}
Exemplo n.º 5
0
MFolderType MFolderFromProfile::GetType() const
{
   return GetFolderType(READ_CONFIG(m_profile, MP_FOLDER_TYPE));
}
Exemplo n.º 6
0
bool MFolderFromProfile::Move(MFolder *newParent)
{
   CHECK( newParent, false, _T("no new parent in MFolder::Move()") );

   // This does not really 'move' the folder, but it creates a new one with the
   // correct parent and name, and copies all the profile information from the
   // old one to the new one. It then calls Delete on itself, so that the old
   // folder is removed from the tree. Last thing is to notify everyone that a
   // new folder has been created.

   // There are things that do not make sense at all
   CHECK( GetFolderType(GetType()) != MF_ILLEGAL, false,
            _T("How did you manage to try to move an MF_ILLEGAL folder ?") );
   CHECK( GetFolderType(GetType()) != MF_NEWS, false,
            _T("can't move News folders") );
   CHECK( GetFolderType(GetType()) != MF_INBOX, false,
            _T("can't move system Inbox") );
   CHECK( GetFolderType(GetType()) != MF_ROOT, false,
            _T("can't move the root pseudo-folder") );

   // And there are things we can't do yet.
   CHECK( GetSubfolderCount() == 0, false, _T("can't move a folder with sub-folders (yet)") );
   CHECK( GetFolderType(GetType()) != MF_IMAP, false, _T("can't move IMAP folders (yet)") );

   if ( GetFolderType(GetType()) == MF_IMAP )
   {
      // IMAP folders have one more check: we must make sure that they stay on
      // the same server, so that we can simply send it a RENAME command.
      CHECK( false, false, _T("Same server check not yet implemented") );
   }
   
   // Compute the name of the folder to create
   String path = newParent->GetFullName();
   String name = m_folderName.AfterLast('/');
   String newFullName = path;
   if ( !path.empty() )
      newFullName += _T('/');
   newFullName += name;

   // Create a new folder
   MFolder_obj newSubfolder(newParent->CreateSubfolder(name, MF_ILLEGAL));
   if ( !newSubfolder )
   {
      wxLogError(_("Could not create subfolder '%s' in '%s'."),
                   name.c_str(), path.c_str());
      return false;
   }

   wxString oldProfilePath, newProfilePath;
   oldProfilePath << Profile::GetProfilePath() << '/' << m_folderName;
   newProfilePath << Profile::GetProfilePath() << '/' << newFullName;
   if ( CopyEntries(mApplication->GetProfile()->GetConfig(), oldProfilePath, newProfilePath, false) == -1 )
   {
      wxLogError(_("Could not copy profile."));
      return false;
   }

   if ( GetFolderType(GetType()) == MF_IMAP )
   {
      // IMAP folders need one last specific thing: send a RENAME
      // command to the server, unless we are moving the root folder
      // for this server (in this case, nothing changes on the server
      // and no RENAME command should be issued).
      CHECK( false, false, _T("RENAME command to server not yet implemented") );
   }

   // We should update the cache, but I (XNO) did not find a way to do it correctly.
   //MFolderCache::Remove(this);
   //MFolderCache::Add(newSubfolder);
   
   // Iterate over all the filters to change the name of the folder where
   // it appears.
   wxArrayString allFilterNames = MFilter::GetAllFilters();
   for ( size_t i = 0; i < allFilterNames.GetCount(); ++i )
   {
      wxString filterName = allFilterNames[i];
      MFilter *filter = MFilter::CreateFromProfile(filterName);
      MFilterDesc filterDesc = filter->GetDesc();
      if ( filterDesc.IsSimple() )
      {
         MFDialogSettings *dialogSettings = filterDesc.GetSettings();
         wxString argument = dialogSettings->GetActionArgument();
         size_t nbReplacements = argument.Replace(m_folderName, newFullName);
         if ( nbReplacements > 0 )
         {
            dialogSettings->SetAction(dialogSettings->GetAction(), argument);
            filterDesc.Set(dialogSettings);
            filter->Set(filterDesc);
            wxLogStatus(_("Filter '%s' has been updated."), filterName.c_str());
         }
         else
         {
            dialogSettings->DecRef();
         }
      }
      else
      {
         // XNOTODO: Find out how to update this filter anyway
         wxLogError(_("Filter '%s' is not \"simple\" and has not been updated."), filterName.c_str());
      }
      filter->DecRef();
   }

   /*
   // notify everybody about the disappearance of the old folder
   MEventManager::Send(
      new MEventFolderTreeChangeData (m_folderName,
                                      MEventFolderTreeChangeData::Delete)
      );
      */
   // notify everybody about the creation of the new folder
   MEventManager::Send(
      new MEventFolderTreeChangeData(newFullName,
                                     MEventFolderTreeChangeData::Create)
      );

   // Now, we can delete the old folder from the hierarchy
   Delete();

   struct MailFolderStatus status;
   MfStatusCache* cache = MfStatusCache::Get();
   if ( cache->GetStatus(m_folderName, &status) )
      cache->UpdateStatus(newFullName, status);

   return true;
}
Exemplo n.º 7
0
void
CProjectWindow::__OnRightClick__()
{
  HTREEITEM item = m_TreeControl.GetSelectedItem();
  if (item == NULL)
    return;

  // if the user right clicked on a folder
  if (IsTreeItemFolder(m_TreeControl, item))
  {
    // if the user right-clicked on a group, open the "group" popup menu
    switch (GetFolderType(m_TreeControl, item))
    {
      case tiMaps:
      case tiSpritesets:
      case tiScripts:
      case tiSounds:
      case tiFonts:
      case tiWindowStyles:
      case tiImages:
      case tiAnimations:
      {
        CMenu menu;
        menu.LoadMenu(IDR_PROJECTGROUP);

        POINT Point;
        GetCursorPos(&Point);

        CMenu* sub_menu = menu.GetSubMenu(0);
        if (sub_menu) {
          TranslateMenu(sub_menu->GetSafeHmenu());
          sub_menu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, Point.x, Point.y, this);
        }
      
        menu.DestroyMenu();
        return;
      }
    }

    return;
  }

  if (IsTreeItemFile(m_TreeControl, item)) {
    CMenu menu;
    menu.LoadMenu(IDR_PROJECTITEM);

    int image = 0, selected = 0;
    m_TreeControl.GetItemImage(item, image, selected);
    if (image == IDI_FILETYPE_BASE - 1 && selected == IDI_FILETYPE_BASE - 1) {
      // this should work !! but doesn't
      menu.EnableMenuItem(ID_PROJECTITEM_OPEN, MF_BYCOMMAND | MF_DISABLED);
    }

    // get the mouse coordinates
    POINT Point;
    GetCursorPos(&Point);

    CMenu* sub_menu = menu.GetSubMenu(0);
    if (sub_menu) {
      TranslateMenu(sub_menu->GetSafeHmenu());
      sub_menu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, Point.x, Point.y, this);
    }

    menu.DestroyMenu();
  }
}
Exemplo n.º 8
0
ALERROR CExtension::Load (ELoadStates iDesiredState, IXMLParserController *pResolver, bool bNoResources, bool bKeepXML, CString *retsError)

//	Load
//
//	Makes sure that the extension is fully loaded.

	{
	ALERROR error;
	int i;

	switch (m_iLoadState)
		{
		case loadNone:
			{
			*retsError = CONSTLIT("Unable to load.");
			return ERR_FAIL;
			}

		case loadEntities:
		case loadAdventureDesc:
			{
			if (iDesiredState == loadNone || iDesiredState == loadEntities)
				return NOERROR;
			else if (iDesiredState == loadAdventureDesc && m_iLoadState == loadAdventureDesc)
				return NOERROR;

			//	Open the file

			CResourceDb ExtDb(m_sFilespec, true);
			if (error = ExtDb.Open(DFOPEN_FLAG_READ_ONLY, retsError))
				return ERR_FAIL;

			//	Setup

			SDesignLoadCtx Ctx;
			Ctx.sResDb = m_sFilespec;
			Ctx.pResDb = &ExtDb;
			Ctx.bNoVersionCheck = true;	//	Obsolete now
			Ctx.bNoResources = bNoResources;
			Ctx.bKeepXML = bKeepXML;
			Ctx.bLoadAdventureDesc = (iDesiredState == loadAdventureDesc && m_iType == extAdventure);
			Ctx.sErrorFilespec = m_sFilespec;

			//	If this is a registered extension then compute a digest for the
			//	file (so that we can compare against the cloud's digest).
			//	
			//	We need to do this even if we fail later because we don't want to
			//	have to recalc it later.

			if (m_Digest.IsEmpty() && GetFolderType() == folderCollection && IsRegistered())
				{
				if (error = fileCreateDigest(m_sFilespec, &m_Digest))
					{
					*retsError = strPatternSubst(CONSTLIT("Unable to compute digest for: %s."), m_sFilespec);
					return error;
					}
				}

			//	If we've already loaded a root element, then we need to clean up

			if (m_pRootXML)
				CleanUpXML();

			//	Parse the XML file into a structure

			if (error = ExtDb.LoadGameFile(&m_pRootXML, pResolver, retsError))
				{
				//	If we're in debug mode then this is a real error.

				if (g_pUniverse->InDebugMode()
						&& !ExtDb.IsTDB())
					{
					if (retsError) *retsError = strPatternSubst(CONSTLIT("Error parsing %s: %s"), m_sFilespec, *retsError);
					return ERR_FAIL;
					}

				//	Otherwise, we try to continue as if nothing bad had happened, but we
				//	disable the extension.

				else
					{
					SetDisabled((retsError ? *retsError : CONSTLIT("Unable to load")));
					return NOERROR;
					}
				}

			//	Set up context

			Ctx.pExtension = this;

			//	Load all the design elements

			for (i = 0; i < m_pRootXML->GetContentElementCount(); i++)
				{
				CXMLElement *pItem = m_pRootXML->GetContentElement(i);

				if (error = LoadDesignElement(Ctx, pItem))
					{
					if (!bKeepXML)
						{
						delete m_pRootXML;
						m_pRootXML = NULL;
						}

					if (g_pUniverse->InDebugMode()
							&& !ExtDb.IsTDB())
						return ComposeLoadError(Ctx, retsError);

					SetDisabled(Ctx.sError);
					return NOERROR;
					}
				}

			//	Restore

			Ctx.pExtension = NULL;

			//	Done

			m_iLoadState = (m_iType == extAdventure ? iDesiredState : loadComplete);
			if (!bKeepXML)
				{
				delete m_pRootXML;
				m_pRootXML = NULL;
				}

			//	If we get this far and we have no libraries, then include the 
			//	compatibility library.

			if (m_iLoadState == loadComplete)
				AddDefaultLibraryReferences(Ctx);

			//	Debug output

			switch (m_iType)
				{
				case extAdventure:
					if (m_iLoadState == loadAdventureDesc)
						kernelDebugLogMessage("Loaded adventure desc: %s", m_sFilespec);
					else
						kernelDebugLogMessage("Loaded adventure: %s", m_sFilespec);
					break;

				case extExtension:
					kernelDebugLogMessage("Loaded extension: %s", m_sFilespec);
					break;

				case extLibrary:
					kernelDebugLogMessage("Loaded library: %s", m_sFilespec);
					break;
				}

			return NOERROR;
			}

		case loadComplete:
			return NOERROR;

		default:
			ASSERT(false);
			return ERR_FAIL;
		}
	}