/// Function name  : removeDocument
// Description     : Removes the destroys the specified document. Should not be called directly, except by 'closeDocumentByIndex'
// 
// DOCUMENTS_DATA*  pWindowData : [in] Documents window data
// DOCUMENT*        pDocument   : [in] Target document
// CONST UINT       iIndex      : [in] Index of target document
// 
VOID  removeDocument(DOCUMENTS_DATA*  pWindowData, DOCUMENT*  pDocument, CONST UINT  iIndex)
{
   UINT   iReplacementIndex;    // Index of document to display instead

   
   // [CHECK] Are we closing the ActiveDocument?
   if (pDocument == getActiveDocument())
   {
      // [CHECK] Is there a replacement for the ActiveDocument?
      if (getDocumentCount() > 1)
      {
         // [SUCCESS] Display document on the right, otherwise one on the left
         iReplacementIndex = (iIndex == getDocumentCount() - 1 ? (iIndex - 1) : (iIndex + 1));
         displayDocumentByIndex(pWindowData->hTabCtrl, iReplacementIndex);       /// [EVENT] Fires UM_DOCUMENT_SWITCHED
      }
      else
         // [FAILED] Reset active document
         setActiveDocument(pWindowData, NULL);     /// [EVENT] Fires UM_DOCUMENT_SWITCHED
   }

   /// Remove tab and Destroy Document
   TabCtrl_DeleteItem(pWindowData->hTabCtrl, iIndex);        // [WARNING] TabCtrl_DeleteItem causes document to be erased but not invalidated
   removeObjectFromListByValue(pWindowData->pDocumentList, (LPARAM)pDocument);
   deleteDocument(pDocument);

   // [CHECK] Is there an active document?
   if (getActiveDocument())
      // [ACTIVE DOCUMENT] Resize in case a row of tabs has been removed
      updateDocumentSize(pWindowData, getActiveDocument());
}
Example #2
0
void MainWindow::menuItemSelected (int menuItemID,
                                   int topLevelMenuIndex)
{
    if (menuItemID >= 100 && menuItemID < 200)
    {
        // open a file from the "recent files" menu
        JucerDocument* const newDoc
            = ObjectTypes::loadDocumentFromFile (StoredSettings::getInstance()->recentFiles.getFile (menuItemID - 100),
                                                 true);

        if (newDoc != 0)
            openDocument (newDoc);
    }
    else if (menuItemID == 200)
    {
        LookAndFeel::setDefaultLookAndFeel (oldLook);
    }
    else if (menuItemID == 201)
    {
        LookAndFeel::setDefaultLookAndFeel (nullptr);
    }
    else if (menuItemID >= 300 && menuItemID < 400)
    {
        if (getActiveDocument() != 0)
        {
            getActiveDocument()->setSnappingGrid (snapSizes [menuItemID - 300],
                                                  getActiveDocument()->isSnapActive (false),
                                                  getActiveDocument()->isSnapShown());
        }
    }
}
/// Function name  : displayDocumentByIndex
// Description     : Changes the active tab and displays the appropriate document
// 
// HWND        hTabCtrl : [in] Document control handle
// CONST UINT  iIndex   : [in] Zero based index of the document to display
// 
VOID  displayDocumentByIndex(HWND  hTabCtrl, CONST UINT  iIndex)
{
   DOCUMENTS_DATA*  pWindowData;    // Window data
   DOCUMENT*        pDocument;      // Target Document

   
   // Prepare
   pWindowData  = getDocumentsControlData(hTabCtrl);

   // Lookup document and ensure its not already active
   if (findDocumentByIndex(hTabCtrl, iIndex, pDocument) AND pDocument != getActiveDocument())
   {
      // [SUCCESS] Hide current active document (if any)
      if (getActiveDocument())
         ShowWindow(getActiveDocument()->hWnd, SW_HIDE);

      /// Ensure correct tab is selected
      TabCtrl_SetCurSel(pWindowData->hTabCtrl, iIndex);     // Already active if user has changed tab manually

      /// Display new document
      setActiveDocument(pWindowData, pDocument);
   }

}
Example #4
0
void FrostEdit::currentTabPageChanged(int id) {
	if(id == -1) {
		disableActions();
		return;
	}
	QWidget* wid = mCurrentTabWidget->widget(id);
	if(wid == nullptr) {
		disableActions();
		return;
	}
	TextEdit* e = toTextEdit(wid);
	if(e != nullptr &&  e->document() != getActiveDocument())
		emit documentChanged(toDocument(e->document()));
	//if there's no editor, let's disable some buttons.
	if(e == nullptr) {
		disableActions();
	} else { //there was editor, enable them
		enableActions();
	}
}
/// Function name  : closeAllDocuments
// Description     : Attempts to close/save all open documents
// 
// CONST BOOL  bExcludeActiveDocument : [in] Whether to leave the active document open 
// 
BOOL   closeAllDocuments(HWND  hTabCtrl, CONST BOOL  bExcludeActive)
{
   DOCUMENTS_DATA*    pWindowData;     // Documents data
   DOCUMENT*          pDocument;       // Document list iterator
   UINT               iDocumentCount;  // Document count

   // [TRACK]
   CONSOLE_COMMAND_BOLD();

   // Prepare  
   pWindowData = getDocumentsControlData(hTabCtrl);

   // [CHECK] Ensure there are documents to close
   if (iDocumentCount = getDocumentCount())
   {
      // Iterate through all open documents
      for (INT  iIndex = (iDocumentCount - 1); findDocumentByIndex(hTabCtrl, iIndex, pDocument); iIndex--)
      {
         // [CHECK] Skip the active document, if appropriate
         if (bExcludeActive AND pDocument == getActiveDocument())
            continue;
         
         /// [CHECK] Attempt to save or discard document
         if (!closeDocumentByIndex(hTabCtrl, iIndex))
            // [CANCELLED] Abort 
            break;
      }
   }

   // Recalculate document count
   iDocumentCount = getDocumentCount();

   // [CLOSING] Have all documents been closed?
   if (isAppClosing() AND !iDocumentCount)
      /// [EVENT] Fire UM_MAIN_WINDOW_CLOSING with state MWS_DOCUMENTS_CLOSED
      postAppClose(MWS_DOCUMENTS_CLOSED);

   // Return TRUE if all documents were closed
   return (iDocumentCount == 0);
}
Example #6
0
void FrostEdit::compile() {
	ui->consoleTabs->setCurrentIndex(ui->consoleTabs->indexOf(mCompileOutput));
	mCompileOutput->clear();
	mIssueList->clear();

	Document* doc = getActiveDocument();
	if(doc == nullptr)
		return;
	QFileInfo file;


	mCompiledFile = doc->getFullPath();
	if(doc->isActualFile()) {
		on_actionSave_triggered();
		file = doc->getFileInfo();
	} else {
		file = doc->saveTemporary();
		mTemporaryFiles.append(file);
	}

	mCompileFile = file;
	ui->actionCompile->setDisabled(true);
	ui->actionCompileAndRun->setDisabled(true);

	QProcessEnvironment procenv;
	QString env = Settings::getDefaultCompilerEnvironment();
	if(!env.isEmpty())
		procenv.insert("PATH", env);

	QString defaultCompilerPath = Settings::getDefaultCompilerPath();
	mFrostCompiler->setProgram(defaultCompilerPath+"CBCompiler.exe");
	mFrostCompiler->setArguments(QStringList() << file.absoluteFilePath());
	mFrostCompiler->setWorkingDirectory(defaultCompilerPath);
	mFrostCompiler->setProcessEnvironment(procenv);
	mFrostCompiler->setProcessChannelMode(QProcess::SeparateChannels);
	mFrostCompiler->start(QProcess::ReadOnly);


}
Example #7
0
PopupMenu MainWindow::getMenuForIndex (int topLevelMenuIndex,
                                       const String& menuName)
{
    PopupMenu menu;

    if (topLevelMenuIndex == 0)
    {
        // "File" menu

        for (int i = 0; i < ObjectTypes::numDocumentTypes; ++i)
            menu.addCommandItem (commandManager, CommandIDs::newDocumentBase + i);

        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::open);

        PopupMenu recentFiles;
        StoredSettings::getInstance()->recentFiles.createPopupMenuItems (recentFiles, 100, true, true);
        menu.addSubMenu ("Open recent file", recentFiles);

        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::close);
        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::save);
        menu.addCommandItem (commandManager, CommandIDs::saveAs);
        menu.addSeparator();

        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
    }
    else if (topLevelMenuIndex == 1)
    {
        // "Edit" menu

        menu.addCommandItem (commandManager, CommandIDs::undo);
        menu.addCommandItem (commandManager, CommandIDs::redo);
        menu.addSeparator();

        menu.addCommandItem (commandManager, CommandIDs::editCompLayout);
        menu.addCommandItem (commandManager, CommandIDs::editCompGraphics);
        menu.addSeparator();

        PopupMenu newComps;
        int i;
        for (i = 0; i < ObjectTypes::numComponentTypes; ++i)
            newComps.addCommandItem (commandManager, CommandIDs::newComponentBase + i);

        menu.addSubMenu ("Add new component", newComps);

        PopupMenu newElements;
        for (i = 0; i < ObjectTypes::numElementTypes; ++i)
            newElements.addCommandItem (commandManager, CommandIDs::newElementBase + i);

        menu.addSubMenu ("Add new graphic element", newElements);

        menu.addSeparator();
        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::cut);
        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::copy);
        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::paste);
        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::del);
        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::selectAll);
        menu.addCommandItem (commandManager, StandardApplicationCommandIDs::deselectAll);
        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::toFront);
        menu.addCommandItem (commandManager, CommandIDs::toBack);
        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::group);
        menu.addCommandItem (commandManager, CommandIDs::ungroup);
        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::bringBackLostItems);
    }
    else if (topLevelMenuIndex == 2)
    {
        // "View" menu

        menu.addCommandItem (commandManager, CommandIDs::test);

        PopupMenu lookAndFeels;
        lookAndFeels.addItem (201, "Default", true, (typeid (LookAndFeel) == typeid (LookAndFeel::getDefaultLookAndFeel())) != 0);
        lookAndFeels.addItem (200, "Old School", true, (typeid (OldSchoolLookAndFeel) == typeid (LookAndFeel::getDefaultLookAndFeel())) != 0);

        menu.addSeparator();
        menu.addSubMenu ("Look and Feel", lookAndFeels);

        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::showGrid);
        menu.addCommandItem (commandManager, CommandIDs::enableSnapToGrid);

        const int currentSnapSize = getActiveDocument() != 0 ? getActiveDocument()->getSnappingGridSize() : 0;

        PopupMenu m;
        for (int i = 0; i < numElementsInArray (snapSizes); ++i)
            m.addItem (300 + i, String (snapSizes[i]) + " pixels", true, snapSizes[i] == currentSnapSize);

        menu.addSubMenu ("Grid size", m, getActiveDocument() != 0);

        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::zoomIn);
        menu.addCommandItem (commandManager, CommandIDs::zoomOut);
        menu.addCommandItem (commandManager, CommandIDs::zoomNormal);

        menu.addSeparator();
        PopupMenu overlays;
        overlays.addCommandItem (commandManager, CommandIDs::compOverlay0);
        overlays.addCommandItem (commandManager, CommandIDs::compOverlay33);
        overlays.addCommandItem (commandManager, CommandIDs::compOverlay66);
        overlays.addCommandItem (commandManager, CommandIDs::compOverlay100);
        menu.addSubMenu ("Component Overlay", overlays,
                         getActiveDocument() != 0 && getActiveDocument()->getComponentLayout() != 0);

        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::useTabbedWindows);
        menu.addSeparator();
        menu.addCommandItem (commandManager, CommandIDs::showPrefs);
    }

    return menu;
}
/// Function name  : getActiveDocumentFileName
// Description     : Gets the filename of the active document, if any
// 
// Return Value   : Filename or NULL
// 
const TCHAR*   getActiveDocumentFileName()
{
   return getDocumentFileName(getActiveDocument());
}
Example #9
0
bool MultiDocumentPanel::closeDocument (Component* component,
                                        const bool checkItsOkToCloseFirst)
{
    if (components.contains (component))
    {
        if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
            return false;

        component->removeComponentListener (this);

        const bool shouldDelete = MultiDocHelpers::shouldDeleteComp (component);
        component->getProperties().remove ("mdiDocumentDelete_");
        component->getProperties().remove ("mdiDocumentBkg_");

        if (mode == FloatingWindows)
        {
            for (int i = getNumChildComponents(); --i >= 0;)
            {
                if (MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i)))
                {
                    if (dw->getContentComponent() == component)
                    {
                        ScopedPointer<MultiDocumentPanelWindow> (dw)->clearContentComponent();
                        break;
                    }
                }
            }

            if (shouldDelete)
                delete component;

            components.removeFirstMatchingValue (component);

            if (isFullscreenWhenOneDocument() && components.size() == 1)
            {
                for (int i = getNumChildComponents(); --i >= 0;)
                {
                    ScopedPointer<MultiDocumentPanelWindow> dw (dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i)));

                    if (dw != nullptr)
                        dw->clearContentComponent();
                }

                addAndMakeVisible (components.getFirst());
            }
        }
        else
        {
            jassert (components.indexOf (component) >= 0);

            if (tabComponent != nullptr)
            {
                for (int i = tabComponent->getNumTabs(); --i >= 0;)
                    if (tabComponent->getTabContentComponent (i) == component)
                        tabComponent->removeTab (i);
            }
            else
            {
                removeChildComponent (component);
            }

            if (shouldDelete)
                delete component;

            if (tabComponent != nullptr && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
                tabComponent = nullptr;

            components.removeFirstMatchingValue (component);

            if (components.size() > 0 && tabComponent == nullptr)
                addAndMakeVisible (components.getFirst());
        }

        resized();

        // This ensures that the active tab is painted properly when a tab is closed!
        if (Component* activeComponent = getActiveDocument())
            setActiveDocument (activeComponent);

        activeDocumentChanged();
    }
    else
    {
        jassertfalse;
    }

    return true;
}