Esempio n. 1
0
  /** Set the program name attributes on the working copy based on the ICElement */
  protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
    boolean renamed = false;

    if (!(cElement instanceof IBinary)) {
      cElement = cElement.getCProject();
    }

    if (cElement instanceof ICProject) {
      IProject project = cElement.getCProject().getProject();
      String name = project.getName();
      ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
      if (projDes != null) {
        String buildConfigName = projDes.getActiveConfiguration().getName();
        name = name + " " + buildConfigName; // $NON-NLS-1$
      }
      name = getLaunchConfigurationDialog().generateName(name);
      config.rename(name);
      renamed = true;
    }

    IBinary binary = null;
    if (cElement instanceof ICProject) {
      IBinary[] bins = getBinaryFiles((ICProject) cElement);
      if (bins != null && bins.length == 1) {
        binary = bins[0];
      }
    } else if (cElement instanceof IBinary) {
      binary = (IBinary) cElement;
    }

    if (binary != null) {
      String path;
      path = binary.getResource().getProjectRelativePath().toOSString();
      config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, path);
      if (!renamed) {
        String name = binary.getElementName();
        int index = name.lastIndexOf('.');
        if (index > 0) {
          name = name.substring(0, index);
        }
        name = getLaunchConfigurationDialog().generateName(name);
        config.rename(name);
        renamed = true;
      }
    }

    if (!renamed) {
      String name =
          getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
      config.rename(name);
    }
  }
 protected IBinary[] getExecutables(IBinaryContainer container) throws CModelException {
   ICElement[] celements = container.getChildren();
   ArrayList<IBinary> list = new ArrayList<IBinary>(celements.length);
   for (int i = 0; i < celements.length; i++) {
     if (celements[i] instanceof IBinary) {
       IBinary bin = (IBinary) celements[i];
       if (bin.showInBinaryContainer()) {
         list.add(bin);
       }
     }
   }
   IBinary[] bins = new IBinary[list.size()];
   list.toArray(bins);
   return bins;
 }
Esempio n. 3
0
  /** Show a dialog that lists all main types */
  @Override
  protected void handleSearchButtonSelected() {
    if (getCProject() == null) {
      MessageDialog.openInformation(
          getShell(),
          LaunchMessages.getString("CMainTab.Project_required"), // $NON-NLS-1$
          LaunchMessages.getString(
              "CMainTab.Enter_project_before_searching_for_program")); //$NON-NLS-1$
      return;
    }

    ILabelProvider programLabelProvider =
        new CElementLabelProvider() {
          @Override
          public String getText(Object element) {
            if (element instanceof IBinary) {
              IBinary bin = (IBinary) element;
              StringBuffer name = new StringBuffer();
              name.append(bin.getPath().lastSegment());
              return name.toString();
            }
            return super.getText(element);
          }

          @Override
          public Image getImage(Object element) {
            if (!(element instanceof ICElement)) {
              return super.getImage(element);
            }
            ICElement celement = (ICElement) element;

            if (celement.getElementType() == ICElement.C_BINARY) {
              IBinary belement = (IBinary) celement;
              if (belement.isExecutable()) {
                return DebugUITools.getImage(IDebugUIConstants.IMG_ACT_RUN);
              }
            }

            return super.getImage(element);
          }
        };

    ILabelProvider qualifierLabelProvider =
        new CElementLabelProvider() {
          @Override
          public String getText(Object element) {
            if (element instanceof IBinary) {
              IBinary bin = (IBinary) element;
              StringBuffer name = new StringBuffer();
              name.append(
                  bin.getCPU() + (bin.isLittleEndian() ? "le" : "be")); // $NON-NLS-1$ //$NON-NLS-2$
              name.append(" - "); // $NON-NLS-1$
              name.append(bin.getPath().toString());
              return name.toString();
            }
            return super.getText(element);
          }
        };

    TwoPaneElementSelector dialog =
        new TwoPaneElementSelector(getShell(), programLabelProvider, qualifierLabelProvider);
    dialog.setElements(getBinaryFiles(getCProject()));
    dialog.setMessage(LaunchMessages.getString("CMainTab.Choose_program_to_run")); // $NON-NLS-1$
    dialog.setTitle(LaunchMessages.getString("CMainTab.Program_Selection")); // $NON-NLS-1$
    dialog.setUpperListLabel(
        LaunchMessages.getString("Launch.common.BinariesColon")); // $NON-NLS-1$
    dialog.setLowerListLabel(
        LaunchMessages.getString("Launch.common.QualifierColon")); // $NON-NLS-1$
    dialog.setMultipleSelection(false);
    // dialog.set
    if (dialog.open() == Window.OK) {
      IBinary binary = (IBinary) dialog.getFirstResult();
      fProgText.setText(binary.getResource().getProjectRelativePath().toString());
    }
  }