bool ProjectManager::CloseWorkspace()
{
    bool result = false;
    m_IsClosingWorkspace = true;
    if (m_pWorkspace)
    {
        if (!m_ui->QueryCloseWorkspace())
        {
            m_IsClosingWorkspace = false;
            return false;
        }
        if (!CloseAllProjects(false))
        {
            m_IsClosingWorkspace = false;
            return false;
        }

        delete m_pWorkspace;
        m_pWorkspace = nullptr;

        m_ui->CloseWorkspace();
        result = true;
    }
    else
        result = CloseAllProjects(false);
    m_IsClosingWorkspace = false;
    WorkspaceChanged();
    return result;
}
bool ProjectManager::CloseAllProjects(bool dontsave)
{
    if (!dontsave)
    {
        if (!m_ui->QueryCloseAllProjects())
            return false;
    }

    m_ui->FreezeTree();
    m_IsClosingProject = true;
    while (m_pProjects->GetCount() != 0)
    {
// Commented it by Heromyth
//        if (!CloseActiveProject(true))
        if (!CloseProject(m_pProjects->Item(0), true, false))
        {
            m_ui->UnfreezeTree(true);
            m_IsClosingProject = false;
            return false;
        }
    }

    if (!Manager::IsAppShuttingDown())
        m_ui->RebuildTree();
    m_ui->UnfreezeTree(true);

    if (!m_InitialDir.IsEmpty())
        wxFileName::SetCwd(m_InitialDir);
    m_IsClosingProject = false;
    WorkspaceChanged();

    return true;
}
bool ProjectManager::CloseWorkspace()
{
    bool result = false;
    m_IsClosingWorkspace = true;
    if (m_pWorkspace)
    {
        if (!m_ui->QueryCloseWorkspace())
        {
            m_IsClosingWorkspace = false;
            return false;
        }
        // m_ui->QueryCloseWorkspace asked for saving workspace AND projects, no need to do again
        if (!CloseAllProjects(true))
        {
            m_IsClosingWorkspace = false;
            return false;
        }

        delete m_pWorkspace;
        m_pWorkspace = nullptr;

        m_ui->CloseWorkspace();
        result = true;
    }
    else
        result = CloseAllProjects(false);
    m_IsClosingWorkspace = false;
    WorkspaceChanged();
    return result;
}
bool ProjectManager::CloseProject(cbProject* project, bool dontsave, bool refresh)
{
    if (!project)
        return true;
    if (project->GetCurrentlyCompilingTarget())
        return false;
    if (!dontsave)
    {
         if (!m_ui->QueryCloseProject(project))
            return false;
    }

    bool wasActive = project == m_pActiveProject;
    if (wasActive)
        m_pActiveProject = nullptr;

    int index = m_pProjects->Index(project);
    if (index == wxNOT_FOUND)
        return false;

    // CloseProject is also called by CloseAllProjects, so we need to save
    // the state of m_IsClosingProject.
    bool isClosingOtherProjects = m_IsClosingProject;
    m_IsClosingProject = true;
    Manager::Get()->GetEditorManager()->UpdateProjectFiles(project);
    project->SaveLayout();

    if (m_pWorkspace)
        m_pWorkspace->SetModified(true);

    RemoveProjectFromAllDependencies(project);
    m_pProjects->Remove(project);

    // moved here from cbProject's destructor, because by then
    // the list of project files was already emptied...
    CodeBlocksEvent event(cbEVT_PROJECT_CLOSE);
    event.SetProject(project);
    Manager::Get()->GetPluginManager()->NotifyPlugins(event);

    project->CloseAllFiles(true);
    if (refresh)
        m_ui->RemoveProject(project);
    if (wasActive && m_pProjects->GetCount())
        SetProject(m_pProjects->Item(0), refresh);
    delete project;
    if (!m_InitialDir.IsEmpty()) // Restore the working directory
        wxFileName::SetCwd(m_InitialDir);
    m_IsClosingProject = isClosingOtherProjects;
    WorkspaceChanged();
    return true;
}
void ProjectManager::EndLoadingProject(cbProject* project)
{
    s_CanShutdown = true;
    if (!m_IsLoadingProject)
        return;

    if (project)
    {
        bool newAddition = m_pProjects->Index(project) == -1;
        if (newAddition)
        {
            m_pProjects->Add(project);
            project->LoadLayout();
        }

        if (!m_IsLoadingWorkspace)
            m_ui->FinishLoadingProject(project, newAddition, m_pFileGroups);

        if (m_pWorkspace)
            m_pWorkspace->SetModified(true);

        // if loading a workspace, avoid sending the event now
        // we 'll send them after all projects have been loaded
        // (look in LoadWorkspace)
        if (!m_IsLoadingWorkspace)
        {
            // notify plugins that the project is loaded
            // moved here from cbProject::Open() because code-completion
            // kicks in too early and the perceived loading time is long...
            CodeBlocksEvent event(cbEVT_PROJECT_OPEN);
            event.SetProject(project);
            Manager::Get()->ProcessEvent(event);

            // finally, display project notes (if appropriate)
            if (project->GetShowNotesOnLoad())
                project->ShowNotes(true);
        }
    }

    /* While loading the project layout, the ProjectManager is still working.
       Thus it should be set to Not Busy only at the end.*/
    m_IsLoadingProject = false;

    // sort out any global user vars that need to be defined now (in a batch) :)
    // but only if not loading workspace (else LoadWorkspace() will handle this)
    if (!m_IsLoadingWorkspace)
        Manager::Get()->GetUserVariableManager()->Arrogate();

    WorkspaceChanged();
}
void ProjectManager::EndLoadingWorkspace()
{
    if (!m_IsLoadingWorkspace)
        return;

    m_IsLoadingWorkspace = false;
    if (!m_pWorkspace)
        return;

    if (m_pWorkspace->IsOK())
    {
        if (m_pProjectToActivate)
        {
            SetProject(m_pProjectToActivate, true);
            m_pProjectToActivate = nullptr;
        }

        m_ui->FinishLoadingWorkspace(m_pActiveProject, m_pWorkspace->GetTitle());

        // sort out any global user vars that need to be defined now (in a batch) :)
        Manager::Get()->GetUserVariableManager()->Arrogate();

        int numNotes = 0;

        // and now send the project loaded events
        // since we were loading a workspace, these events were not sent before
        for (size_t i = 0; i < m_pProjects->GetCount(); ++i)
        {
            cbProject* project = m_pProjects->Item(i);

            // notify plugins that the project is loaded
            // moved here from cbProject::Open() because code-completion
            // kicks in too early and the perceived loading time is long...
            CodeBlocksEvent event(cbEVT_PROJECT_OPEN);
            event.SetProject(project);
            Manager::Get()->GetPluginManager()->NotifyPlugins(event);

            // since we 're iterating anyway, let's count the project notes that should be displayed
            if (project->GetShowNotesOnLoad() && !project->GetNotes().IsEmpty())
                ++numNotes;
        }

        // finally, display projects notes (if appropriate)
        if (numNotes)
        {
            if (numNotes == 1 || // if only one project has notes, don't bother asking
                cbMessageBox(wxString::Format(_("%d projects contain notes that should be displayed on-load.\n"
                                                "Do you want to display them now, one after the other?"),
                                                numNotes),
                                                _("Display project notes?"),
                                                wxICON_QUESTION | wxYES_NO) == wxID_YES)
            {
                for (size_t i = 0; i < m_pProjects->GetCount(); ++i)
                {
                    cbProject* project = m_pProjects->Item(i);
                    if (project->GetShowNotesOnLoad())
                        project->ShowNotes(true);
                }
            }
        }

        WorkspaceChanged();
    }
    else
        CloseWorkspace();
}
示例#7
0
//This function format taken directly from the Qt5.3 documentation
bool XCBEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *){
	if(stopping){ return false; } //don't do any parsing
	//qDebug() << "New Event";
	if(eventType=="xcb_generic_event_t"){
	  //qDebug() << " - XCB event";
	  //Convert to known event type (for X11 systems)
	   xcb_generic_event_t *ev = static_cast<xcb_generic_event_t *>(message);
	  //Now parse the event and emit signals as necessary
	  switch( ev->response_type & ~0x80){
//==============================
	    case XCB_PROPERTY_NOTIFY:
		//qDebug() << "Property Notify Event:";
	        //qDebug() << " - Root Window:" << QX11Info::appRootWindow();
		//qDebug() << " - Given Window:" << ((xcb_property_notify_event_t*)ev)->window;
		//System-specific proprty change
		if( ((xcb_property_notify_event_t*)ev)->window == QX11Info::appRootWindow() \
			&& ( ( ((xcb_property_notify_event_t*)ev)->atom == session->XCB->EWMH._NET_DESKTOP_GEOMETRY) \
			  ||  (((xcb_property_notify_event_t*)ev)->atom == session->XCB->EWMH._NET_WORKAREA) )){
		  session->RootSizeChange();
		}else if( ((xcb_property_notify_event_t*)ev)->window == QX11Info::appRootWindow() \
			&& ( ( ((xcb_property_notify_event_t*)ev)->atom == session->XCB->EWMH._NET_CURRENT_DESKTOP) )){
 		  //qDebug() << "Got Workspace Change";
		  session->emit WorkspaceChanged();
		}else if( SysNotifyAtoms.contains( ((xcb_property_notify_event_t*)ev)->atom ) ){
		  //Update the status/list of all running windows
		  session->WindowPropertyEvent();	
			
		//window-specific property change
		}else if( WinNotifyAtoms.contains( ((xcb_property_notify_event_t*)ev)->atom ) ){
		  //Ping only that window
		  //session->WindowPropertyEvent( ((xcb_property_notify_event_t*)ev)->window );
		  session->WindowPropertyEvent();
	        }
		break;
//==============================	    
	    case XCB_CLIENT_MESSAGE:
		//qDebug() << "Client Message Event";
		//qDebug() << " - Root Window:" << QX11Info::appRootWindow();
		//qDebug() << " - Given Window:" << ((xcb_client_message_event_t*)ev)->window;
		if( TrayDmgFlag!=0 &&  ((xcb_client_message_event_t*)ev)->type == _NET_SYSTEM_TRAY_OPCODE && ((xcb_client_message_event_t*)ev)->format == 32){
		  //data32[0] is timestamp, [1] is opcode, [2] is  window handle
		  if(SYSTEM_TRAY_REQUEST_DOCK == ((xcb_client_message_event_t*)ev)->data.data32[1]){
		      session->SysTrayDockRequest( ((xcb_client_message_event_t*)ev)->data.data32[2] );
		  }
		  //Ignore the System Tray messages at the moment (let the WM handle it)
		  
		//window-specific property changes
		/*}else if( ((xcb_client_message_event_t*)ev)->type == session->XCB->EWMH._NET_WM_STATE ){
		  if( session->XCB->WindowIsMaximized( ((xcb_client_message_event_t*)ev)->window ) ){
		    //Quick fix for maximized windows (since Fluxbox is not doing the STRUT detection properly)
		    session->adjustWindowGeom( ((xcb_client_message_event_t*)ev)->window );
		  }
		  session->WindowPropertyEvent( ((xcb_client_message_event_t*)ev)->window );*/
		}else if( WinNotifyAtoms.contains( ((xcb_client_message_event_t*)ev)->type ) ){
		  //Ping only that window
		  //session->WindowPropertyEvent( ((xcb_client_message_event_t*)ev)->window );
		  session->WindowPropertyEvent();
	        }
	        break;
//==============================	    
	    case XCB_DESTROY_NOTIFY:
		//qDebug() << "Window Closed Event";
		session->WindowClosedEvent( ( (xcb_destroy_notify_event_t*)ev )->window );
	        break;
//==============================	    
	    case XCB_CONFIGURE_NOTIFY:
		//qDebug() << "Configure Notify Event";
		session->WindowConfigureEvent( ((xcb_configure_notify_event_t*)ev)->window );
	        break;
//==============================	    
	    case XCB_SELECTION_CLEAR:
		//qDebug() << "Selection Clear Event";
		session->WindowSelectionClearEvent( ((xcb_selection_clear_event_t*)ev)->owner );  
	        break;
//==============================	    
	    default:
		if(TrayDmgFlag!=0){
		  //if( (ev->response_type & ~0x80)==TrayDmgFlag){
		    session->WindowDamageEvent( ((xcb_damage_notify_event_t*)ev)->drawable );
		  //}
		}/*else{
	          qDebug() << "Default Event:" << (ev->response_type & ~0x80);
	        }*/
//==============================
	  }
	}
	//qDebug() << " - finished event";
	return false; //make sure the handling keeps going (transparent watching of events)
}