Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] How to get an open file's project in Eclipse
  • From: Ming Cheng <chengm349@xxxxxxxxxxx>
  • Date: Fri, 21 Feb 2020 04:47:56 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TFWO39TTHmhDKTya5eoXiZ4K2oJN8u3iIJWTdnbsSYw=; b=ZNWu67GpmSU0tQW9wD9iv7VSRh/Due5lxV+i2f0oz3MRxzfNwoF4Lig/QXK3UmzMBgrxumZnX8BQY1q1c1vrRe0eLKt/JjdcsuQ2fzZ69BR0yLzcwjbVzE1GozUI3fo/ZXHGjfFr4Ly6ILkyXeEbROlgP+qXrKI2eQfjPpEN0fiYnHXBMCKsllyC92GshH7V9eN497U1o3SQktkP9rLtk4+LLlTNxRS1+aRFcl7I+dr9l6HL52IcuDq2GCDp7aUkr7ol7XqYvLpphOm5Mi23KT1rErmW/L1qrmh6R2Ot5trL5+wjPz4xix92wru2LjkCROwh5m5fS+PKQvI/XkRGgg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dPBwmivHCpuLb0rLMAwJR00i1hG+aSe01kGQIBWf9Z7GXHmlAECsjvzkgxgi5/3eoGexiXwMksw1d3xfS2pQhluM2AUbnox5w3BBlUugYJL2TXo/zA41oF9mCGgjn2mMdxjblh1suHZLbd0trl/e4TlHhaG4WHfPyBNihsyHSMnuUyJ5jIOGu39c++/Y0j0HAk2l3LX/ubaGvvGV8DdJWFukkVQYzwuxyBCFRaJMEG/81Uvs/X2n4uxMH0B8jHZj3YvrITs1stQS/XwSqWv2QvjvOPHBG2YZRFUyngF+6Mwr04VsXxXXXbhLJ7Uhx03ADwlHLYV9gYdBYH3nYh569Q==
  • Delivered-to: cdt-dev@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/cdt-dev>
  • List-help: <mailto:cdt-dev-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/cdt-dev>, <mailto:cdt-dev-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHV58r3aa+aNQh9zUq4S+cZ0M2GH6gjyNMAgAFLnTI=
  • Thread-topic: [cdt-dev] How to get an open file's project in Eclipse

Hi Alexander

thanks! it works now.


From: cdt-dev-bounces@xxxxxxxxxxx <cdt-dev-bounces@xxxxxxxxxxx> on behalf of Alexander Fedorov <alexander.fedorov@xxxxxxxxxx>
Sent: Thursday, February 20, 2020 9:00 AM
To: cdt-dev@xxxxxxxxxxx <cdt-dev@xxxxxxxxxxx>
Subject: Re: [cdt-dev] How to get an open file's project in Eclipse
 
Remove the block regarding selection, you don't need it as far as I can see.
/*
                    ISelection iselection = window.getSelectionService().getSelection();
                    IStructuredSelection selection = (IStructuredSelection) iselection;
                    if (selection == null) {
                        log.error("null selection");
                        return;
                    }
*/
Regards,
AF

20.02.2020 11:56, Ming Cheng пишет:
I selected a tab in Eclipse Edit window.

my code to get the selected open file project like this:

public static void getCurrentProject() {
        Display.getDefault().asyncExec(new Runnable() {
            @Override
            public void run() {
                IWorkbenchWindow  window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

                if (window != null) {
                    ISelection iselection = window.getSelectionService().getSelection();
                    IStructuredSelection selection = (IStructuredSelection) iselection;
                    if (selection == null) {
                        log.error("null selection");
                        return;
                    }

                    IWorkbenchPage activePage = window.getActivePage();

                    IEditorPart activeEditor = activePage.getActiveEditor();

                    if (activeEditor != null) {
                       IEditorInput input = activeEditor.getEditorInput();

                       project = input.getAdapter(IProject.class);
                       if (project == null) {
                          IResource resource = input.getAdapter(IResource.class);
                          if (resource != null) {
                             project = resource.getProject();
                          }
                       }
                    } else {
                        log.error("null activeEditor");
                    }
                } else {
                    log.error("null window");
                }
            }
        });
    }

and window variable is not null but selection  is null.  Is my understanding wrong?

project  is a class static member variable.

Thanks.

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev


Back to the top