void CBSymbolTable::DisplaySelectedSymbols() const { itsKeyBuffer.Clear(); const JTableSelection& s = GetTableSelection(); if (s.HasSelection()) { JString missingFiles; JTableSelectionIterator iter(&s); JPoint cell; while (iter.Next(&cell)) { const JIndex symbolIndex = CellToSymbolIndex(cell); JIndex lineIndex; const JString& fileName = itsSymbolList->GetFile(symbolIndex, &lineIndex); CBTextDocument* doc; if ((CBGetDocumentManager())->OpenTextDocument(fileName, lineIndex, &doc)) { CBLanguage lang; CBSymbolList::Type type; itsSymbolList->GetSymbol(symbolIndex, &lang, &type); if (CBSymbolList::ShouldSmartScroll(type)) { (doc->GetTextEditor())->ScrollForDefinition(lang); } } else { missingFiles += fileName; missingFiles += "\n"; } } if (!missingFiles.IsEmpty()) { const JCharacter* map[] = { "list", missingFiles }; const JString msg = JGetString(kMissingFilesID, map, sizeof(map)); (JGetUserNotification())->ReportError(msg); } } }
void CBSearchTextDialog::SaveFileForSearch ( const JString& fullName, JPtrArray<JString>* fileList, JPtrArray<JString>* nameList ) const { JBoolean exists; const JIndex index = nameList->GetInsertionSortIndex(const_cast<JString*>(&fullName), &exists); if (!exists) { JString* file = jnew JString(fullName); assert( file != NULL ); JXFileDocument* doc; if ((CBGetDocumentManager())->FileDocumentIsOpen(*file, &doc) && doc->NeedsSave()) { CBTextDocument* textDoc = dynamic_cast<CBTextDocument*>(doc); if (textDoc != NULL && (JCreateTempFile(file)).OK()) { std::ofstream output(*file); ((textDoc->GetTextEditor())->GetText()).Print(output); } } if (!file->IsEmpty()) { JString* name = jnew JString(fullName); assert( name != NULL ); nameList->InsertAtIndex(index, name); fileList->InsertAtIndex(index, file); } else { jdelete file; } } }
JBoolean CBCClass::FindDefinition ( const JString& headerName, const JCharacter* searchStr, const JBoolean caseSensitive ) const { CBDocumentManager* docMgr = CBGetDocumentManager(); CBTextDocument* doc = NULL; // look for it in the source file JString sourceName; JIndex lineIndex; if (docMgr->GetComplementFile(headerName, kCBCHeaderFT, &sourceName, (GetTree())->GetProjectDoc()) && docMgr->SearchFile(sourceName, searchStr, caseSensitive, &lineIndex)) { docMgr->OpenTextDocument(sourceName, lineIndex, &doc); } // look for it in the header file (inline) else if (docMgr->SearchFile(headerName, searchStr, caseSensitive, &lineIndex)) { docMgr->OpenTextDocument(headerName, lineIndex, &doc); } if (doc != NULL) { (doc->GetTextEditor())->ScrollForDefinition(kCBCLang); return kJTrue; } else { return kJFalse; } }
void CBEditTextPrefsDialog::UpdateSettings() { CBTextEditor* te = itsDoc->GetTextEditor(); JString fontName; JSize fontSize; itsFontMenu->GetFont(&fontName, &fontSize); const JBoolean fontChanged = JI2B( fontName != te->GetDefaultFont().GetName() || fontSize != te->GetDefaultFont().GetSize() ); JFloat vScrollScale = 1.0; if (fontChanged) { const JFontManager* fontMgr = te->GetFontManager(); const JFloat h1 = te->GetDefaultFont().GetLineHeight(); const JFloat h2 = fontMgr->GetFont(fontName, fontSize).GetLineHeight(); vScrollScale = h2 / h1; } JInteger tabCharCount; JBoolean ok = itsTabCharCountInput->GetValue(&tabCharCount); assert( ok ); JInteger crmLineWidth; ok = itsCRMLineWidthInput->GetValue(&crmLineWidth); assert( ok ); JInteger undoDepth; ok = itsUndoDepthInput->GetValue(&undoDepth); assert( ok ); JInteger rightMargin; ok = itsRightMarginInput->GetValue(&rightMargin); assert( ok ); CBPrefsManager* prefsMgr = CBGetPrefsManager(); const JBoolean textColorChanged = JNegate( itsColor[ CBPrefsManager::kTextColorIndex-1 ] == prefsMgr->GetColor(CBPrefsManager::kTextColorIndex)); // set colors before RecalcStyles() so stylers update themselves prefsMgr->SetDefaultFont(fontName, fontSize); for (JIndex j=1; j<=CBPrefsManager::kColorCount; j++) { prefsMgr->SetColor(j, itsColor[j-1]); } JPtrArray<CBTextDocument>* docList = (CBGetDocumentManager())->GetTextDocList(); const JSize docCount = docList->GetElementCount(); JProgressDisplay* pg = JNewPG(); pg->FixedLengthProcessBeginning(docCount, "Updating preferences...", kJFalse, kJFalse); for (JIndex i=1; i<=docCount; i++) { CBTextDocument* doc = docList->NthElement(i); doc->ShouldMakeBackupFile(itsCreateBackupCB->IsChecked()); doc->ShouldMakeNewBackupEveryOpen(!itsOnlyBackupIfNoneCB->IsChecked()); doc->ShouldAllocateTitleSpace(itsExtraSpaceWindTitleCB->IsChecked()); doc->ShouldOpenComplFileOnTop(itsOpenComplFileOnTopCB->IsChecked()); te = doc->GetTextEditor(); if (itsEmulatorIndex != itsOrigEmulatorIndex) { JTEKeyHandler* handler; CBInstallEmulator(kMenuIndexToEmulator[ itsEmulatorIndex-1 ], te, &handler); } te->ShouldAutoIndent(itsAutoIndentCB->IsChecked()); te->CBShouldAllowDragAndDrop(itsUseDNDCB->IsChecked()); te->ShouldMoveToFrontOfText(itsLeftToFrontOfTextCB->IsChecked()); te->ShouldBalanceWhileTyping(itsBalanceWhileTypingCB->IsChecked()); te->ShouldScrollToBalance(itsScrollToBalanceCB->IsChecked()); te->ShouldBeepWhenTypeUnbalanced(itsBeepWhenTypeUnbalancedCB->IsChecked()); te->TabShouldBeSmart(itsSmartTabCB->IsChecked()); te->TabShouldInsertSpaces(itsTabToSpacesCB->IsChecked()); if (fontChanged) { JXScrollbar *hScrollbar, *vScrollbar; const JBoolean ok = te->GetScrollbars(&hScrollbar, &vScrollbar); assert( ok ); vScrollbar->PrepareForScaledMaxValue(vScrollScale); te->SetFont(fontName, fontSize, tabCharCount); } else { te->SetTabCharCount(tabCharCount); } te->SetCRMLineWidth(crmLineWidth); te->SetUndoDepth(undoDepth); te->SetRightMarginWidth(itsRightMarginCB->IsChecked(), rightMargin); te->SetDefaultFontStyle(itsColor [ CBPrefsManager::kTextColorIndex-1 ]); te->SetBackColor(itsColor [ CBPrefsManager::kBackColorIndex-1 ]); te->SetFocusColor(itsColor [ CBPrefsManager::kBackColorIndex-1 ]); te->SetCaretColor(itsColor [ CBPrefsManager::kCaretColorIndex-1 ]); te->SetSelectionColor(itsColor [ CBPrefsManager::kSelColorIndex-1 ]); te->SetSelectionOutlineColor(itsColor [ CBPrefsManager::kSelLineColorIndex-1 ]); te->SetRightMarginColor(itsColor [ CBPrefsManager::kRightMarginColorIndex-1 ]); if (textColorChanged) { te->RecalcStyles(); } // force update of insertion font JIndex caretIndex; if (te->GetCaretLocation(&caretIndex)) { te->SetCaretLocation(caretIndex); } pg->IncrementProgress(); } CBFnMenuUpdater* updater = CBGetFnMenuUpdater(); updater->ShouldSortFnNames(itsSortFnMenuCB->IsChecked()); updater->ShouldIncludeNamespace(itsNSInFnMenuCB->IsChecked()); updater->ShouldPackFnNames(itsPackFnMenuCB->IsChecked()); JXTEBase::SetPartialWordModifier( (JXTEBase::PartialWordModifier) itsPWModRG->GetSelectedItem()); JXTEBase::ShouldUseWindowsHomeEnd(itsHomeEndCB->IsChecked()); CBTextEditor::CaretShouldFollowScroll(itsScrollCaretCB->IsChecked()); JTextEditor::ShouldCopyWhenSelect(itsCopyWhenSelectCB->IsChecked()); JXTEBase::MiddleButtonShouldPaste(itsMiddleButtonPasteCB->IsChecked()); CBSearchTextDialog* dlog = CBGetSearchTextDialog(); dlog->SetFont(fontName, fontSize); itsDoc->JPrefObject::WritePrefs(); if (itsEmulatorIndex != itsOrigEmulatorIndex) { prefsMgr->SetEmulator(kMenuIndexToEmulator[ itsEmulatorIndex-1 ]); } CBMWriteSharedPrefs(kJTrue); pg->ProcessFinished(); jdelete pg; }
void CBFunctionMenu::UpdateMenu() { CBFnMenuUpdater* updater = CBMGetFnMenuUpdater(); const JXKeyModifiers& modifiers = GetDisplay()->GetLatestKeyModifiers(); JBoolean sort = updater->WillSortFnNames(); if (modifiers.meta()) { sort = !sort; } JBoolean includeNS = updater->WillIncludeNamespace(); if (modifiers.shift()) { includeNS = !includeNS; } const JBoolean pack = updater->WillPackFnNames(); if (itsNeedsUpdate || sort != itsSortFlag || includeNS != itsIncludeNSFlag || pack != itsPackFlag) { #if defined CODE_CRUSADER assert( itsDoc != NULL ); JString fileName; JBoolean deleteFile = kJFalse; if (itsDoc->NeedsSave()) { itsDoc->SafetySave(JXDocumentManager::kTimer); if (!itsDoc->GetSafetySaveFileName(&fileName) && (JCreateTempFile(&fileName)).OK()) { // directory may not be writable deleteFile = kJTrue; // itsDoc can't be CBTextDocument, because Code Medic uses us CBTextDocument* textDoc = dynamic_cast<CBTextDocument*>(itsDoc); assert( textDoc != NULL ); std::ofstream output(fileName); ((textDoc->GetTextEditor())->GetText()).Print(output); } } else { JBoolean onDisk; fileName = itsDoc->GetFullName(&onDisk); if (!onDisk) { fileName.Clear(); } } #elif defined CODE_MEDIC const JString& fileName = itsFileName; #endif if (!fileName.IsEmpty()) { itsLang = updater->UpdateMenu(fileName, itsFileType, sort, includeNS, pack, this, itsLineIndexList); } else { itsLang = kCBOtherLang; this->RemoveAllItems(); itsLineIndexList->RemoveAll(); } if (IsEmpty()) { SetEmptyMenuItems(); } itsNeedsUpdate = kJFalse; itsSortFlag = sort; itsIncludeNSFlag = includeNS; itsPackFlag = pack; itsCaretItemIndex = 0; // nothing to remove itsTE->DeactivateCurrentUndo(); // force another TextChanged #if defined CODE_CRUSADER if (deleteFile) { JRemoveFile(fileName); } #endif } // mark caret location if (!sort && !itsLineIndexList->IsEmpty()) { if (itsCaretItemIndex > 0) { ShowSeparatorAfter(itsCaretItemIndex, kJFalse); itsCaretItemIndex = 0; } const JIndex lineIndex = itsTE->VisualLineIndexToCRLineIndex( itsTE->GetLineForChar(itsTE->GetInsertionIndex())); const JSize count = GetItemCount(); assert( count == itsLineIndexList->GetElementCount() ); for (JIndex i=1; i<=count; i++) { if (itsLineIndexList->GetElement(i) > lineIndex) { itsCaretItemIndex = i-1; if (itsCaretItemIndex > 0) { ShowSeparatorAfter(itsCaretItemIndex, kJTrue); } break; } } } }