void BackCmd::Execute () { Clipboard* cb = GetClipboard(); Editor* ed = GetEditor(); if (cb == nil) { Selection* s = ed->GetSelection(); if (s->IsEmpty()) { return; } SetClipboard(cb = new Clipboard); GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); Iterator i; for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } } else { Clipboard* oldcb = cb; SetClipboard(cb = new Clipboard); Iterator i; for (oldcb->First(i); !oldcb->Done(i); oldcb->Next(i)) { oldcb->GetComp(i)->Interpret(this); } delete oldcb; } if (!cb->IsEmpty()) { ed->GetComponent()->Interpret(this); } }
/** * \brief Get the string that is currently selected when the action was called. * \param sValue the return value. * \param bQuote if we want to quote the text or not. * \return bool if we have a string selected or not. */ bool HelperApi::GetString (MYODD_STRING& sValue, const bool bQuote) const { try { const auto& clipBoard = GetClipboard( ); MYODD_STRING sClipBoard = _T(""); if( !clipBoard.GetText( sClipBoard, bQuote ) ) { // we have nothing. return false; } if( sClipBoard.length() == 0 ) { // we have something but the size is 0 return false; } // we do have something. sValue = sClipBoard; return true; } catch(... ) { return false; } }
void BackCmd::Unexecute () { GetEditor()->GetComponent()->Uninterpret(this); Clipboard* cb = GetClipboard(); Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { cb->GetComp(i)->Uninterpret(this); } }
void GroupCmd::Unexecute () { _group->Uninterpret(this); _executed = false; Clipboard* cb = GetClipboard(); Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { cb->GetComp(i)->Uninterpret(this); } }
void Command::Unexecute () { Clipboard* cb = GetClipboard(); if (cb != nil) { Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { cb->GetComp(i)->Uninterpret(this); } unidraw->Update(); } }
GraphicComp* AlignCmd::GetReference (GraphicComp* grcomp) { Clipboard* cb = GetClipboard(); Iterator i; cb->SetComp(grcomp, i); cb->Prev(i); if (cb->GetComp(i) == nil) { cb->First(i); } return cb->GetComp(i); }
void AlignToGridCmd::Unexecute () { Clipboard* cb = GetClipboard(); if (cb != nil) { Iterator i; for (cb->Last(i); !cb->Done(i); cb->Prev(i)) { Unmove(cb->GetComp(i)); } unidraw->Update(); } }
boolean Command::Reversible () { boolean reversible = true; Clipboard* cb = GetClipboard(); if (cb == nil) { Editor* ed = GetEditor(); Selection* s = (ed == nil) ? nil : ed->GetSelection(); reversible = (s == nil) || !s->IsEmpty(); } else { reversible = !cb->IsEmpty(); } return reversible; }
void JXExprEditor::EIPClipboardChanged() { const JFunction* f; if (GetClipboard(&f)) { const JString text = f->Print(); JXTextSelection* data = jnew JXTextSelection(GetDisplay(), text); assert( data != NULL ); GetSelectionManager()->SetData(kJXClipboardName, data); } }
GraphicComp* Command::GetGraphicComp () { Component* comp = _editor->GetComponent(); if (comp == nil) { Clipboard* cb = GetClipboard(); Iterator i; if (cb != nil && !cb->IsEmpty()) { cb->First(i); comp = cb->GetComp(i)->GetParent(); } } return ( comp != nil && comp->IsA(GRAPHIC_COMP) ) ? (GraphicComp*) comp : nil; }
void Command::Execute () { Selection* s = _editor->GetSelection(); Clipboard* cb = GetClipboard(); if (!s->IsEmpty() || (cb != nil && !cb->IsEmpty())) { Iterator i; if (cb == nil) { SetClipboard(cb = new Clipboard); cb->Init(s); } for (cb->First(i); !cb->Done(i); cb->Next(i)) { cb->GetComp(i)->Interpret(this); } unidraw->Update(); } }
void TimeEdit::PasteTime() { if (byFrame) { Paste(); return; } std::string text(GetClipboard()); if (text.empty()) return; AssTime tempTime(text); if (tempTime.GetAssFormated() == text) { SetTime(tempTime); SetSelection(0, GetValue().size()); wxCommandEvent evt(wxEVT_TEXT, GetId()); evt.SetEventObject(this); HandleWindowEvent(evt); } }
/** * \brief Get a currently selected file in the clipboard. * Used by plugins who want to behave a certain way for files. * \param idx the file number we are after * \param sValue the return value * \param bQuote if we want to quote or not. * \return bool success or not if there are no more files */ bool HelperApi::GetFile(const unsigned int idx, MYODD_STRING& sValue, const bool bQuote) const { try { const Clipboard& clipBoard = GetClipboard( ); MYODD_STRING sClipBoard = _T(""); if( !clipBoard.GetFile( sClipBoard, idx, bQuote ) ) { // could not find anything return false; } // we found one string. sValue = sClipBoard; return true; } catch( ... ) { return false; } }
void AlignToGridCmd::Execute () { Selection* s = _editor->GetSelection(); if (!s->IsEmpty()) { Clipboard* cb = GetClipboard(); Iterator i; if (cb == nil) { for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } SetClipboard(cb = new Clipboard); cb->Init(s); } else { for (cb->First(i); !cb->Done(i); cb->Next(i)) { Move(cb->GetComp(i)); } } unidraw->Update(); } }
void TextBox::mousePress(int x, int y, int button) { if (hasMouse() && button == MouseInput::LEFT) { mCaretRow = y / getFont()->getHeight(); if (mCaretRow >= (int)mTextRows.size()) { mCaretRow = mTextRows.size() - 1; } mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], x); } else if (hasMouse() && button == MouseInput::MIDDLE) { std::string str; if (GetClipboard(str) >= 0) { for (size_t i = 0; i < str.size(); ++i) { keyPress(Key(str[i])); } } } }
void GroupCmd::Execute () { Clipboard* cb = GetClipboard(); if (cb == nil) { SetClipboard(cb = new Clipboard); Editor* ed = GetEditor(); Selection* s = ed->GetSelection(); if (s->Number() > 1) { Iterator i; GraphicView* views = ed->GetViewer()->GetGraphicView(); s->Sort(views); for (s->First(i); !s->Done(i); s->Next(i)) { s->GetView(i)->Interpret(this); } } } else { Clipboard* oldcb = cb; SetClipboard(cb = new Clipboard); Iterator i; for (oldcb->First(i); !oldcb->Done(i); oldcb->Next(i)) { oldcb->GetComp(i)->Interpret(this); } delete oldcb; } if (!cb->IsEmpty()) { if (_group == nil) { SetGroup(new GraphicComps); } _group->Interpret(this); _executed = true; } }
/** * \brief Get the currently selected folder, (if any) * This is used when plugins want to behave a certain way depending * on the currently selected folder. * \param idx the folder number we are getting. * \param sValue the value we are after. * \param bQuote if we want to quote the string or not. * \return bool success or not, we return false when there are no more folders. */ bool HelperApi::GetFolder (const unsigned int idx, MYODD_STRING& sValue, const bool bQuote) const { try { const Clipboard& clipBoard = GetClipboard( ); MYODD_STRING sClipBoard = _T(""); if( !clipBoard.GetFolder( sClipBoard, idx, bQuote ) ) { // could not find anything return false; } // otherwise push the string sValue = sClipBoard; // we have one item return true; } catch( ... ) { return false; } }
void SetupClipboardContentTypes() { GtkTargetList* list = gtk_target_list_new(NULL, 0); // TODO: Support for images if (!this->text && !this->uris) return; if (this->text) gtk_target_list_add_text_targets(list, ClipboardPrivate::TEXT_DATA); if (this->uris) gtk_target_list_add_uri_targets(list, ClipboardPrivate::URI_LIST_DATA); int size = 0; GtkTargetEntry* table = gtk_target_table_new_from_list(list, &size); if (table) { // gtk_clipboard_set_with_data may try to clear our clipboard when we // call it, so we turn on a flag here which prevents our clipboard data // from being freed during this call. this->preserve = true; GtkClipboard* clipboard = GetClipboard(); if (gtk_clipboard_set_with_data(clipboard, table, size, GetClipboardData, ClearClipboardData, NULL)) { this->ownClipboard = true; gtk_clipboard_set_can_store(clipboard, NULL, 0); } this->preserve = false; gtk_target_table_free(table, size); } gtk_target_list_unref(list); }
UngroupCmd::~UngroupCmd () { if (_executed) { GetClipboard()->DeleteComps(); delete _kids; } }
boolean GroupCmd::Reversible () { Clipboard* cb = GetClipboard(); return cb == nil || !cb->IsEmpty(); }
Clipboard* Command::DeepCopyClipboard () { Clipboard* cb = GetClipboard(); return (cb == nil) ? nil : cb->DeepCopy(); }
bool TextBox::keyPress(const Key& key) { bool ret = false; if (key.getValue() == Key::K_LEFT) { mCaretColumn = UTF8GetPrev(mTextRows[mCaretRow], mCaretColumn); if (mCaretColumn < 0) { --mCaretRow; if (mCaretRow < 0) { mCaretRow = 0; mCaretColumn = 0; } else { mCaretColumn = mTextRows[mCaretRow].size(); } } ret = true; } else if (key.getValue() == Key::K_RIGHT) { mCaretColumn = UTF8GetNext(mTextRows[mCaretRow], mCaretColumn); if (mCaretColumn > (int)mTextRows[mCaretRow].size()) { ++mCaretRow; if (mCaretRow >= (int)mTextRows.size()) { mCaretRow = mTextRows.size() - 1; if (mCaretRow < 0) { mCaretRow = 0; } mCaretColumn = mTextRows[mCaretRow].size(); } else { mCaretColumn = 0; } } ret = true; } else if (key.getValue() == Key::K_DOWN) { setCaretRow(mCaretRow + 1); ret = true; } else if (key.getValue() == Key::K_UP) { setCaretRow(mCaretRow - 1); ret = true; } else if (key.getValue() == Key::K_HOME) { mCaretColumn = 0; ret = true; } else if (key.getValue() == Key::K_END) { mCaretColumn = mTextRows[mCaretRow].size(); ret = true; } else if (key.getValue() == Key::K_ENTER && mEditable) { mTextRows.insert(mTextRows.begin() + mCaretRow + 1, mTextRows[mCaretRow].substr(mCaretColumn, mTextRows[mCaretRow].size() - mCaretColumn)); mTextRows[mCaretRow].resize(mCaretColumn); ++mCaretRow; mCaretColumn = 0; ret = true; } else if (key.getValue() == Key::K_BACKSPACE && mCaretColumn != 0 && mEditable) { int newpos = UTF8GetPrev(mTextRows[mCaretRow], mCaretColumn); mTextRows[mCaretRow].erase(newpos, mCaretColumn - newpos); mCaretColumn = newpos; ret = true; } else if (key.getValue() == Key::K_BACKSPACE && mCaretColumn == 0 && mCaretRow != 0 && mEditable) { mCaretColumn = mTextRows[mCaretRow - 1].size(); mTextRows[mCaretRow - 1] += mTextRows[mCaretRow]; mTextRows.erase(mTextRows.begin() + mCaretRow); --mCaretRow; ret = true; } else if (key.getValue() == Key::K_DELETE && mCaretColumn < (int)mTextRows[mCaretRow].size() && mEditable) { int newpos = UTF8GetNext(mTextRows[mCaretRow], mCaretColumn); mTextRows[mCaretRow].erase(mCaretColumn, newpos - mCaretColumn); ret = true; } else if (key.getValue() == Key::K_DELETE && mCaretColumn == (int)mTextRows[mCaretRow].size() && mCaretRow < ((int)mTextRows.size() - 1) && mEditable) { mTextRows[mCaretRow] += mTextRows[mCaretRow + 1]; mTextRows.erase(mTextRows.begin() + mCaretRow + 1); ret = true; } else if(key.getValue() == Key::K_PAGE_UP) { int w, h, rowsPerPage; getParent()->getDrawSize(w, h, this); rowsPerPage = h / getFont()->getHeight(); mCaretRow -= rowsPerPage; if (mCaretRow < 0) { mCaretRow = 0; } ret = true; } else if(key.getValue() == Key::K_PAGE_DOWN) { int w, h, rowsPerPage; getParent()->getDrawSize(w, h, this); rowsPerPage = h / getFont()->getHeight(); mCaretRow += rowsPerPage; if (mCaretRow >= (int)mTextRows.size()) { mCaretRow = mTextRows.size() - 1; } ret = true; } else if(key.getValue() == Key::K_TAB && mEditable) { mTextRows[mCaretRow].insert(mCaretColumn,std::string(" ")); mCaretColumn += 4; ret = true; } else if (key.getValue() == 'v' - 'a' + 1 && mEditable) // ctrl-v { std::string str; if (GetClipboard(str) >= 0) { for (size_t i = 0; i < str.size(); ++i) { keyPress(Key(str[i])); } ret = true; } } else if (key.isCharacter() && mEditable) { mTextRows[mCaretRow].insert(mCaretColumn,key.toString()); mCaretColumn = UTF8GetNext(mTextRows[mCaretRow], mCaretColumn); ret = true; } adjustSize(); scrollToCaret(); return ret; }
void DrawImportPasteCmd::Execute () { if(!_executed) { Clipboard* cb = GetClipboard(); Iterator it; cb->First(it); GraphicComp* gcomp = cb->GetComp(it); cb->Next(it); if(cb->Done(it) && gcomp->IsA(DRAW_IDRAW_COMP) || gcomp->IsA(FRAME_IDRAW_COMP)) { gcomp->First(it); /* move to background frame */ DrawEditor* ed = (DrawEditor*)GetEditor(); FrameNumberState* fnumstate = ed->framenumstate(); int origfnum = fnumstate->framenumber(); int currfnum = 0; Append(new MoveFrameCmd(ed, -origfnum, true /* allowbg */)); /* paste contents of background frame */ FrameComp* fcomp = (FrameComp*) (gcomp->GetComp(it)->IsA(FRAME_COMP) ? gcomp->GetComp(it) : nil); if (fcomp) { while(!gcomp->Done(it)) { gcomp->Remove(it); Clipboard* newcb = new Clipboard(); Iterator jt; fcomp->First(jt); while(!fcomp->Done(jt)) { newcb->Append(fcomp->GetComp(jt)); fcomp->Remove(jt); } Append(new PasteCmd(ed, newcb)); delete fcomp; /* while more frames move to next frame and paste (create new frame if necessary) */ if(!gcomp->Done(it)) { currfnum++; fcomp = (FrameComp*) (gcomp->GetComp(it)->IsA(FRAME_COMP) ? gcomp->GetComp(it) : nil); if(currfnum>=ed->NumFrames()) Append(new CreateMoveFrameCmd(ed)); else Append(new MoveFrameCmd(ed, 1, true /* allowbg */)); } } } /* move to original frame */ Append(new MoveFrameCmd(ed, origfnum-currfnum, true /* allowbg */)); } else { Append(new PasteCmd(GetEditor(), cb->Copy())); Iterator i; for (cb->First(i); !cb->Done(i); cb->Next(i)) { GraphicComp* gcomp = cb->GetComp(i); if (gcomp->IsA(EDGE_COMP)) { EdgeComp* comp = (EdgeComp*)gcomp; NodeComp* start = node(cb, comp->GetStartNode()); NodeComp* end = node(cb, comp->GetEndNode()); EdgeConnectCmd* cmd = new EdgeConnectCmd(GetEditor(), comp, start, end); Append(cmd); } } } } MacroCmd::Execute(); _executed = 1; }