Logo Search packages:      
Sourcecode: jedit version File versions  Download package

void org::gjt::sp::jedit::textarea::TextArea::rangeComment (  )  [inline]

Adds comment start and end strings to the beginning and end of the selection.

Since:
jEdit 3.2pre1

Definition at line 4073 of file TextArea.java.

References org::gjt::sp::jedit::buffer::JEditBuffer::beginCompoundEdit(), end(), org::gjt::sp::jedit::textarea::Selection::end, org::gjt::sp::jedit::buffer::JEditBuffer::endCompoundEdit(), org::gjt::sp::jedit::textarea::Selection::endLine, org::gjt::sp::jedit::buffer::JEditBuffer::getContextSensitiveProperty(), getSelection(), org::gjt::sp::jedit::buffer::JEditBuffer::insert(), org::gjt::sp::jedit::buffer::JEditBuffer::insertAtColumn(), org::gjt::sp::jedit::buffer::JEditBuffer::isEditable(), selectNone(), setCaretPosition(), org::gjt::sp::jedit::textarea::Selection::start, and org::gjt::sp::jedit::textarea::Selection::startLine.

      {
            String commentStart = buffer.getContextSensitiveProperty(caret,"commentStart");
            String commentEnd = buffer.getContextSensitiveProperty(caret,"commentEnd");
            if(!buffer.isEditable() || commentStart == null || commentEnd == null
                  || commentStart.length() == 0 || commentEnd.length() == 0)
            {
                  getToolkit().beep();
                  return;
            }

            commentStart += ' ';
            commentEnd = ' ' + commentEnd;

            try
            {
                  buffer.beginCompoundEdit();

                  Selection[] selection = getSelection();

                  if(selection.length == 0)
                  {
                        int oldCaret = caret;
                        buffer.insert(caret,commentStart);
                        buffer.insert(caret,commentEnd);
                        setCaretPosition(oldCaret + commentStart.length());
                  }

                  for(int i = 0; i < selection.length; i++)
                  {
                        Selection s = selection[i];
                        if(s instanceof Selection.Range)
                        {
                              buffer.insert(s.start,commentStart);
                              buffer.insert(s.end,commentEnd);
                        }
                        else if(s instanceof Selection.Rect)
                        {
                              Selection.Rect rect = (Selection.Rect)s;
                              int start = rect.getStartColumn(buffer);
                              int end = rect.getEndColumn(buffer);

                              for(int j = s.startLine; j <= s.endLine; j++)
                              {
                                    buffer.insertAtColumn(j,end,
                                          commentEnd);
                                    buffer.insertAtColumn(j,start,
                                          commentStart);
                              }
                        }
                  }

                  selectNone();
            }
            finally
            {
                  buffer.endCompoundEdit();
            }
      } //}}}


Generated by  Doxygen 1.6.0   Back to index