use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class Model method isEditorTCActive.
private static boolean isEditorTCActive() {
boolean res = true;
TopComponent tc = TopComponent.getRegistry().getActivated();
if (null != tc) {
ModeImpl mode = (ModeImpl) WindowManagerImpl.getInstance().findMode(tc);
if (null != mode)
res = mode.getKind() == Constants.MODE_KIND_EDITOR;
}
return res;
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class SlideBar method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (e instanceof TabActionEvent) {
TabActionEvent tae = (TabActionEvent) e;
if (TabbedContainer.COMMAND_RESTORE_GROUP.equals(tae.getActionCommand())) {
String nameOfModeToRestore = tae.getGroupName();
WindowManagerImpl wm = WindowManagerImpl.getInstance();
ModeImpl modeToRestore = (ModeImpl) wm.findMode(nameOfModeToRestore);
if (null != modeToRestore) {
wm.userRestoredMode(tabbed.getSlidingMode(), modeToRestore);
}
}
}
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class GroupsManager method closeGroup.
boolean closeGroup(DocumentGroupImpl group) {
// NOI18N
TopComponent welcomeTc = WindowManager.getDefault().findTopComponent("Welcome");
boolean welcomeWasOpened = null != welcomeTc && welcomeTc.isOpened();
// save the window system first
Lookup.getDefault().lookup(WindowSystem.class).save();
// collect documents
WindowManagerImpl wmi = WindowManagerImpl.getInstance();
ArrayList<TopComponent> documents = new ArrayList<>(TopComponent.getRegistry().getOpened().size());
for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
if (wmi.isEditorTopComponent(tc)) {
documents.add(tc);
}
}
String name = group.getName();
File userDir = Places.getUserDirectory();
// NOI18N
File root = new File(new File(userDir, "config"), DOCUMENT_GROUPS);
File groupDir = new File(root, name);
// remove old data (if any)
deleteAll(groupDir);
groupDir.mkdirs();
FileObject groupFO = FileUtil.toFileObject(groupDir);
Preferences prefs = getPreferences().node(name);
try {
prefs.clear();
} catch (BackingStoreException ex) {
LOG.log(Level.INFO, null, ex);
}
prefs.put(DISPLAY_NAME, group.toString());
File configRoot = new File(new File(Places.getUserDirectory(), CONFIG), WINDOWS2_LOCAL);
File modesRoot = new File(configRoot, MODES);
for (ModeImpl mode : wmi.getModes()) {
if (mode.getKind() == Constants.MODE_KIND_EDITOR) {
String modeName = mode.getName();
// NOI18N //NOI18N
FileObject modeFO = FileUtil.toFileObject(new File(modesRoot, modeName + "." + WSMODE));
if (null == modeFO) {
continue;
}
try {
modeFO.copy(groupFO, modeName, WSMODE);
} catch (IOException ex) {
LOG.log(Level.INFO, null, ex);
continue;
}
StringBuilder sb = new StringBuilder();
for (String id : mode.getOpenedTopComponentsIDs()) {
sb.append(id);
sb.append(ID_SEPARATOR);
}
prefs.put(modeName, sb.toString());
}
}
// copy TopComponents
File componentRoot = new File(configRoot, COMPONENTS);
for (TopComponent tc : documents) {
String id = wmi.findTopComponentID(tc);
if (tc.equals(welcomeTc) && !welcomeWasOpened)
continue;
if (tc.getPersistenceType() == TopComponent.PERSISTENCE_NEVER) {
continue;
}
// NOI18N //NOI18N
FileObject tcFO = FileUtil.toFileObject(new File(componentRoot, id + "." + SETTINGS));
if (tcFO == null) {
continue;
}
try {
tcFO.copy(groupFO, id, SETTINGS);
} catch (IOException ex) {
LOG.log(Level.INFO, null, ex);
}
}
// TODO save recent view list
// NOI18N
getPreferences().put(SEL_GROUP, "");
return true;
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class CloseAllButThisAction method obtainTC.
private TopComponent obtainTC() {
TopComponent res = tc;
if (null == res) {
WindowManagerImpl wmi = WindowManagerImpl.getInstance();
String[] ids = wmi.getRecentViewIDList();
for (String tcId : ids) {
ModeImpl mode = wmi.findModeForOpenedID(tcId);
if (mode == null || mode.getKind() != Constants.MODE_KIND_EDITOR) {
continue;
}
res = wmi.findTopComponent(tcId);
break;
}
}
if (null == res)
res = TopComponent.getRegistry().getActivated();
return res;
}
use of org.netbeans.core.windows.ModeImpl in project netbeans-rcp-lite by outersky.
the class CloseAllButThisAction method run.
@Override
public void run() {
TopComponent tc = obtainTC();
WindowManagerImpl wmi = WindowManagerImpl.getInstance();
ModeImpl mode = (ModeImpl) wmi.findMode(tc);
boolean areOtherDocs;
if (isContext) {
areOtherDocs = mode.getOpenedTopComponents().size() > 1;
} else {
areOtherDocs = wmi.getEditorTopComponents().length > 1;
}
setEnabled(mode != null && mode.getKind() == Constants.MODE_KIND_EDITOR && areOtherDocs && Switches.isEditorTopComponentClosingEnabled());
}
Aggregations