Exemplo n.º 1
0
bool wxSTEditorNotebook::LoadFile( const wxFileName &fileName_,
                                   const wxString &extensions_,
                                   const wxString& encoding_ref)
{
    wxString encoding(encoding_ref);
    wxFileName fileName(fileName_);
    wxString extensions(extensions_.Length() ? extensions_ : GetOptions().GetDefaultFileExtensions());

    if (fileName.GetFullPath().IsEmpty())
    {
        wxSTEditorFileDialog fileDialog( this, _("Open file into new notebook page"),
                                 GetOptions().GetDefaultFilePath(),
                                 extensions,
                                 wxFD_OPEN | wxFD_FILE_MUST_EXIST);

        fileDialog.m_encoding = encoding;
        if (fileDialog.ShowModal() == wxID_OK)
        {
            fileName = fileDialog.GetPath();
            encoding = fileDialog.m_encoding;
        }
        else
            return false;
    }

    bool ok = fileName.FileExists();
    if (ok)
    {
        // load the file from disk and only load it once
        GetOptions().SetDefaultFilePath(fileName.GetPath());

        int page = FindEditorPageByFileName(fileName);
        if (page != wxNOT_FOUND)
        {
            ok = GetEditor(page)->LoadFile(fileName, wxEmptyString, true, encoding);
            SetSelection(page);
        }
        else if ( (GetEditor() == NULL) || GetEditor()->IsModified() || GetEditor()->IsFileFromDisk()) // non-empty editor?
        {
            // new splitter+editor
            wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY);
            wxCHECK_MSG(splitter, false, wxT("Invalid splitter"));
            ok = splitter->GetEditor()->LoadFile(fileName, wxEmptyString, true, encoding);
            if (ok)
            {
                ok = InsertEditorSplitter(-1, splitter, true);
            }
        }
        else // empty editor
        {
            // reuse editor
            ok = GetEditor()->LoadFile(fileName, wxEmptyString, true, encoding);
        }
    }
    return ok;
}
Exemplo n.º 2
0
void CInsertFunctionDialog::CreateWidgets()
{
	mFunctionCategories = new QComboBox;
	mFunctionList = new QListWidget;

	auto *widgets_l = CreateGroupBox( ELayoutType::Vertical,
	{
		new QLabel( "Select a Category" ), mFunctionCategories, new QLabel( "Select a Function" ), mFunctionList
	},
	"", nullptr, 2, 2, 2, 2, 2 );


    //... Help

    mHelpText = new CTextWidget;
	//mHelpText->setHelpProperties( "" , 6, Qt::AlignCenter );
    auto help_group = CreateGroupBox( ELayoutType::Vertical, { mHelpText }, "", nullptr, 6, 6, 6, 6, 6 );
    //help_group->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );

    //... Buttons

    mButtonBox = new QDialogButtonBox( this );
    mButtonBox->setObjectName( QString::fromUtf8( "mButtonBox" ) );
    mButtonBox->setOrientation( Qt::Horizontal );
    mButtonBox->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
    mButtonBox->button( QDialogButtonBox::Ok )->setDefault( true );


    //... All

	QSplitter *splitter = CreateSplitter( nullptr, Qt::Vertical, { widgets_l, help_group } );

    QBoxLayout *main_l = LayoutWidgets( Qt::Vertical,
                            {
								splitter,
                                mButtonBox

                            }, this, 6, 6, 6, 6, 6 );                       Q_UNUSED( main_l );


    setWindowTitle( "Insert Function");

    //	Wrap up dimensions

    adjustSize();
    setMinimumWidth( width() );

	Setup();
}
Exemplo n.º 3
0
wxSTEditorSplitter* wxSTEditorNotebook::InsertEditorSplitter(int nPage, wxWindowID win_id,
                                                             const wxString& title, bool bSelect)
{
    if (GetPageCount() >= GetMaxPageCount())
    {
        wxMessageBox(_("Maximum number of notebook pages exceeded,\nplease close one first."),
                     _("Too many pages opened"), wxOK|wxICON_ERROR, this);

        return NULL;
    }

    wxSTEditorSplitter *splitter = CreateSplitter(win_id);
    wxCHECK_MSG(splitter, NULL, wxT("Invalid splitter"));
    splitter->GetEditor()->NewFile(title);
    if (!InsertEditorSplitter(nPage, splitter, bSelect))
    {
       wxDELETE(splitter); // failed to insert it, delete it to not leak memory
    }
    return splitter;
}
Exemplo n.º 4
0
bool wxSTEditorNotebook::NewPage( const wxString& title_ )
{
    wxString title(title_);

    if (title.IsEmpty())
    {
        title = GetOptions().GetDefaultFileName();
                //wxGetTextFromUser(_("New file name"), _("New file"),
                //                  GetOptions().GetDefaultFileName(), this);
    }

    if (title.Length())
    {
        wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY);
        wxCHECK_MSG(splitter, true, wxT("Invalid splitter"));
        splitter->GetEditor()->NewFile(title);
        InsertEditorSplitter(-1, splitter, true);
        return true;
    }

    return false;
}
Exemplo n.º 5
0
bool wxSTEditorNotebook::LoadFiles( wxArrayString *filePaths_,
                                    const wxString &extensions_)
{
    wxString extensions(extensions_.Length() ? extensions_ : GetOptions().GetDefaultFileExtensions());
    wxArrayString filePaths;
    wxString encoding;

    if (filePaths_)
        filePaths = *filePaths_;

    if (filePaths.GetCount() < 1u)
    {
        wxSTEditorFileDialog fileDialog( this, _("Open file(s) into new notebook page"),
                                 GetOptions().GetDefaultFilePath(),
                                 extensions,
                                 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);

        fileDialog.m_encoding = encoding;
        if (fileDialog.ShowModal() == wxID_OK)
        {
            fileDialog.GetPaths(filePaths);
            encoding = fileDialog.m_encoding;
        }
        else
            return false;
    }

    if (!filePaths.GetCount())
        return false;

    size_t n, count = filePaths.GetCount();
    size_t max_filename_len = 80;
    //for (n = 0; n < count; n++) max_filename_len = wxMax(max_filename_len, filePaths[n].Length());

    wxProgressDialog progDlg(_("Loading files..."),
                             wxString(wxT('_'), max_filename_len + 10), // +10 for file count
                             (int)filePaths.GetCount(), this,
                             wxPD_CAN_ABORT|wxPD_ELAPSED_TIME|wxPD_APP_MODAL|wxPD_AUTO_HIDE);

    // block updating the pages while loading them
    if (m_editorTreeCtrl != NULL) m_editorTreeCtrl->Freeze();
    {
    wxSTERecursionGuard guard(m_rGuard_UpdatePageState);

    for (n = 0; n < count; n++)
    {
        wxString fileName(filePaths[n]);
        wxString progressFileName;
        // Ellipsize filename that are too long.
        if (fileName.Length() > max_filename_len)
            progressFileName = fileName.Mid(0, max_filename_len/2-2) + wxT(" ... ") + fileName.Mid(fileName.Length()-max_filename_len/2+2);
        else
            progressFileName = fileName;

        if (!progDlg.Update((int)n, wxString::Format(wxT("%d/%d : "), (int)n+1, (int)count) + progressFileName))
            break;

        if (fileName.IsEmpty() || !wxFileExists(fileName))
        {
            // when selecting multiple files with file selector you can easily
            // select the dir "..", throw it away
            wxString theFileName(fileName.AfterLast(wxFILE_SEP_PATH));
            if ((theFileName != wxT("..")) && (theFileName != wxT(".")))
            {
                wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY);
                wxCHECK_MSG(splitter, false, wxT("invalid splitter"));
                splitter->GetEditor()->NewFile(fileName);
                if (!InsertEditorSplitter(-1, splitter)) break; // checks overflow
            }
        }
        else
        {
            if (!LoadFile(fileName, wxEmptyString, encoding)) break;
        }
    }
    }

    UpdatePageState();
    if (m_editorTreeCtrl != NULL)
    {
        m_editorTreeCtrl->Thaw();
        m_editorTreeCtrl->UpdateFromNotebook();
    }

    return true;
}
Exemplo n.º 6
0
bool wxSTEditorNotebook::HandleMenuEvent(wxCommandEvent &event)
{
    wxSTERecursionGuard guard(m_rGuard_HandleMenuEvent);
    if (guard.IsInside()) return false;

    int n_page = (int)GetPageCount();
    int win_id = event.GetId();

    switch (win_id)
    {
        case wxID_NEW:
        {
            NewPage();
            return true;
        }
        case wxID_OPEN:
        {
            LoadFiles();
            return true;
        }
        case wxID_SAVEAS:
        {
            wxSTEditor *editor = GetEditor();
            if (!editor) return true; // event handled, but we couldn't do anything with it.

            if (!editor->IsFileFromDisk())
            {
                editor->SaveFile(true);
            }
            else
            {
                wxFileName selectedFileName;
                wxString   selectedFileEncoding;
                bool       selected_file_bom = false;

                bool ok = editor->SaveFileDialog(true, wxEmptyString, &selectedFileName, &selectedFileEncoding, &selected_file_bom);
                if (!ok) return true; // they probably canceled the dialog

                if (selectedFileName == editor->GetFileName())
                {
                    // They want to save to the same filename, update current editor.
                    editor->SaveFile(selectedFileName, selectedFileEncoding, selected_file_bom);
                    return true;
                }
                else
                {
                    // Make a new editor for the new filename, leave the original editor as is.
                    wxSTEditorSplitter *splitter = CreateSplitter(wxID_ANY);
                    wxCHECK_MSG(splitter, true, wxT("Invalid splitter"));
                    wxSTEditor *newEditor = splitter->GetEditor();
                    wxCHECK_MSG(newEditor, true, wxT("Invalid splitter editor"));

                    // Make this new editor identical to the original one
                    // these are probably not necessary
                    //splitter->GetEditor()->SetOptions(editor->GetOptions());
                    //splitter->GetEditor()->RegisterPrefs(editor->GetEditorPrefs());
                    //splitter->GetEditor()->RegisterStyles(editor->GetEditorStyles());
                    //splitter->GetEditor()->RegisterLangs(editor->GetEditorLangs());

                    newEditor->SetLanguage(editor->GetLanguageId());
                    newEditor->SetFileName(editor->GetFileName());
                    newEditor->SetFileEncoding(editor->GetFileEncoding());
                    newEditor->SetFileBOM(editor->GetFileBOM());

                    newEditor->SetText(editor->GetText());
                    newEditor->ColouriseDocument();
                    newEditor->GotoPos(editor->PositionFromLine(editor->LineFromPosition(editor->GetCurrentPos())));
                    newEditor->GotoPos(editor->GetCurrentPos());
                    newEditor->ScrollToLine(editor->GetFirstVisibleLine());

                    // if we can save it, then add it to the notebook
                    if (newEditor->SaveFile(selectedFileName, selectedFileEncoding, selected_file_bom))
                    {
                        if (!InsertEditorSplitter(-1, splitter, true))
                            splitter->Destroy();
                    }
                    else
                        splitter->Destroy(); // problem saving, delete new editor
                }
            }
            return true;
        }
        case ID_STN_SAVE_ALL:
        {
            SaveAllFiles();
            return true;
        }
        case ID_STN_CLOSE_PAGE:
        {
            if ((GetSelection() != -1) && GetEditor(GetSelection()))
            {
                ClosePage(GetSelection(), true);
            }
            return true;
        }
        case ID_STN_CLOSE_ALL:
        {
            if (wxYES == wxMessageBox(_("Close all pages?"), _("Confim closing all pages"),
                                   wxICON_QUESTION|wxYES_NO, this))
            {
                CloseAllPages(true, -1);
            }
            return true;
        }
        case ID_STN_CLOSE_ALL_OTHERS:
        {
            CloseAllPages(true, GetSelection());
            return true;
        }
        case ID_STN_WIN_PREVIOUS:
        {
            if ((GetPageCount() > 0) && (GetSelection() - 1 >= 0))
                SetSelection(GetSelection() - 1);
            else if (GetPageCount() > 0)
                SetSelection((int)GetPageCount() - 1);
            return true;
        }
        case ID_STN_WIN_NEXT:
        {
            if ((GetPageCount() > 0) && (GetSelection() + 1 < (int)GetPageCount()))
                SetSelection(GetSelection() + 1);
            else if (GetPageCount() > 0)
                SetSelection(0);
            return true;
        }
        case ID_STN_WINDOWS:
        {
            wxSTEditorWindowsDialog(this, _("Windows"));
            return true;
        }
        case ID_STE_PASTE_NEW:
        {
            wxString text;
            if (wxSTEditor::GetClipboardText(&text))
            {
                NewPage();
                wxSTEditor* editor = GetEditor();
                if (editor)
                {
                    editor->SetText(text);
                    editor->SetModified(false);
                }
            }
            return true;
        }
        default:
        {
            if ((win_id >= ID_STN_GOTO_PAGE_START) && (win_id < ID_STN_GOTO_PAGE_START+n_page))
            {
                SetSelection(win_id - ID_STN_GOTO_PAGE_START);
                return true;
            }
            else if ((win_id >= ID_STN_CLOSE_PAGE_START) && (win_id < ID_STN_CLOSE_PAGE_START+n_page))
            {
                ClosePage(win_id - ID_STN_CLOSE_PAGE_START);
                return true;
            }
            break;
        }
    }
    return false;
}
wyBool
FrameWindowSplitter::Create()
{
	CreateSplitter(m_hwndparent);
	return wyTrue;
}
Exemplo n.º 8
0
int main(int argc, char** argv)
{
  SplitterOption splitter_option;
  splitter_option.type = SplitterOption::SPLITTER_TYPE_LENGTH;
  splitter_option.length = 1;

  std::string join;
  bool join_given = false;

  while (true) {
    static struct option long_options[] = {
      { "length", required_argument, 0, 'n' },
      { "delim", required_argument, 0, 'd' },
      { "join", required_argument, 0, 'j' },
      { "help", no_argument, 0, 'h' },
      { "version", no_argument, 0, 'v' },
      { 0, 0, 0, 0 },
    };
    int c = getopt_long(argc, argv, "n:d:j:hv", long_options, NULL);
    if (c == -1) break;

    switch (c) {
    case 'n':
      splitter_option.type = SplitterOption::SPLITTER_TYPE_LENGTH;
      splitter_option.length = atoi(optarg);
      break;
    case 'd':
      splitter_option.type = SplitterOption::SPLITTER_TYPE_WORD;
      splitter_option.delims = optarg;
      if (!join_given) join = optarg[0];
      break;
    case 'j':
      join = optarg;
      join_given = true;
      break;
    case 'h':
      Usage(std::cout, argc, argv);
      return 0;
    case 'v':
      std::cout << PACKAGE_STRING << std::endl;
      return 0;
    default:
      Usage(std::cerr, argc, argv);
      return -1;
    }
  }

  Splitter* splitter = CreateSplitter(splitter_option);

  if (optind < argc) {
    std::string line;
    for (int i = optind; i < argc; ++i) {
      std::ifstream ifs(argv[i]);
      while(std::getline(ifs, line)) {
        std::cout << Reverse(splitter, join, line) << std::endl;
      }
    }
  } else {
    std::string line;
    while(std::getline(std::cin, line)) {
      std::cout << Reverse(splitter, join, line) << std::endl;
    }
  }

  delete splitter;
  return 0;
}