void CMainFrame::OnFileOpen(int id) {
  TextView   *view = getActiveTextView();
  if(view == NULL) {
    showWarning(_T("No active view"));
    return;
  }
  CFileDialog dlg(TRUE);
  dlg.m_ofn.lpstrFilter  = getFileDialogExtension().cstr();
  dlg.m_ofn.lpstrTitle   = _T("Open files");
  dlg.m_ofn.nFilterIndex = getOptions().m_defaultExtensionIndex;
  dlg.m_ofn.Flags |= OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST;
  TCHAR fileNames[1024];
  fileNames[0]           = 0;
  dlg.m_ofn.lpstrFile    = fileNames;
  dlg.m_ofn.nMaxFile     = ARRAYSIZE(fileNames);

  if((dlg.DoModal() != IDOK) || (_tcsclen(fileNames) == 0)) {
    return;
  }
  getOptions().m_defaultExtensionIndex = dlg.m_ofn.nFilterIndex;

  TCHAR *files[3];
  getFileNames(files,fileNames);

  CWinDiffDoc *doc = view->getDocument();

  if(_tcsclen(files[1]) == 0) { // only one selected
    doc->setDoc(id, DIFFDOC_FILE, files[0]);
  } else {
    const String f1 = FileNameSplitter::getChildName(files[0],files[1]);
    const String f2 = FileNameSplitter::getChildName(files[0],files[2]);
    doc->setDocs(f1, f2);
  }
  Invalidate(FALSE);
}
void CMainFrame::OnEditPaste() {
  TextView *view = getActiveTextView();
  if(view == NULL) {
    return;
  }
  const String t = getClipboardText();
  CWinDiffDoc *doc = view->getDocument();

  doc->setDoc(view->getId(),DIFFDOC_BUF,t);
  view->refreshBoth();
}
void CMainFrame::refreshDoc(bool recomp) {
  TextView *view = getActiveTextView();
  if(view == NULL) {
    return;
  }

  CWinDiffDoc *doc = view->getDocument();
  if(recomp) {
    doc->recompare();
  }
  view->savePositionState();
  view->refreshBoth();
}
void CMainFrame::OnViewTabSize() {
  TextView *view = getActiveTextView();
  if(view == NULL) {
    return;
  }
  CWinDiffDoc *doc = view->getDocument();

  const int tabSize = doc->m_diff.getTabSize();
  CTabSizeDlg dlg(tabSize);
  if(dlg.DoModal() == IDOK) {
    if(dlg.m_tabSize != doc->m_diff.getTabSize()) {
      view->setTabSize(dlg.m_tabSize, true);
    }
  }
}
void CMainFrame::onFileMruFile(int index) {
  TextView *view = getActiveTextView();
  if(view == NULL) return;
  try {
    const String fname = theApp.getRecentFile(index);

    if(ACCESS(fname, 4) < 0) {
      const int errorCode = errno;
      showWarning(getErrnoText());
      if(errorCode == ENOENT) {
        theApp.removeFromRecentFiles(index);
      }
      return;
    }
    CWinDiffDoc *doc = view->getDocument();
    doc->setDoc(view->getId(),DIFFDOC_FILE, fname);
    Invalidate(FALSE);
    //view->refreshBoth();
  } catch(Exception e) {
    showException(e);
  }
}