একটি উপস্থাপনায় আইটেম নির্বাচন করুন

সিলেকশন হলো একটি খোলা প্রেজেন্টেশন পৃষ্ঠার ফোকাসে থাকা বিষয়বস্তু, যেমন হাইলাইট করা টেক্সটের একটি অংশ বা একটি টেবিল। এই নির্দেশিকায় অ্যাপস স্ক্রিপ্ট ব্যবহার করে একটি সক্রিয় প্রেজেন্টেশনে কীভাবে সিলেকশন পেতে এবং সেট করতে হয় তা বর্ণনা করা হয়েছে।

একটি স্ক্রিপ্ট শুধুমাত্র স্ক্রিপ্টটি চালনাকারী ব্যবহারকারীর নির্বাচিত অংশগুলোই দেখতে পারে।

এই নির্বাচনটি হলো স্ক্রিপ্ট শুরু হওয়ার সময়ের একটি স্ন্যাপশট। স্ক্রিপ্ট চলার সময় যদি ব্যবহারকারী ক্লিক করেন এবং নির্বাচনটি পরিবর্তিত হয়, তবে সেই পরিবর্তনগুলো প্রতিফলিত হবে না।

নির্বাচন এবং নির্বাচনের ধরণ

Selection ক্লাস ব্যবহার করে নির্বাচনটি পড়ুন। নির্বাচিত অবজেক্টের ধরনের ওপর ভিত্তি করে সেগুলো পাওয়ার জন্য এই ক্লাসে বিভিন্ন মেথড রয়েছে।

SelectionType enum-টি নির্বাচিত অবজেক্টের নির্দিষ্ট ধরনকে বোঝায়। উদাহরণস্বরূপ, যদি ব্যবহারকারী কোনো শেপের মধ্যে কিছু টেক্সট নির্বাচন করে থাকেন, তাহলে নির্বাচনের ধরনটি হবে TEXT । এক্ষেত্রে, আপনি selection.getTextRange() মেথডটি ব্যবহার করে নির্বাচিত টেক্সটের পরিসরটি পেতে পারেন।

আপনি নির্বাচিত অংশ ধারণকারী অবজেক্টটিও পুনরুদ্ধার করতে পারেন। উদাহরণস্বরূপ, আপনি selection.getPageElementRange().getPageElements()[0] ব্যবহার করে নির্বাচিত লেখা ধারণকারী আকৃতিটি পুনরুদ্ধার করতে পারেন। একইভাবে, পরিবেষ্টনকারী আকৃতি ধারণকারী পৃষ্ঠাটিই বর্তমান সক্রিয় পৃষ্ঠা; সেই পৃষ্ঠাটি পুনরুদ্ধার করতে, selection.getCurrentPage() ব্যবহার করুন।

নির্বাচিত অংশটি পড়া

নির্বাচিত অংশটি পড়ার জন্য, নিচের উদাহরণে দেখানো অনুযায়ী Presentation.getSelection() মেথডটি ব্যবহার করুন:

slides/selection/selection.gs
const selection = SlidesApp.getActivePresentation().getSelection();

Read the current page

ব্যবহারকারী বর্তমানে যে পৃষ্ঠাটি দেখছেন তা পেতে, নিম্নলিখিতভাবে getSelection() এবং getCurrentPage() পদ্ধতিগুলি ব্যবহার করুন:

slides/selection/selection.gs
const currentPage = SlidesApp.getActivePresentation()
  .getSelection()
  .getCurrentPage();

উল্লেখ্য যে, বর্তমান পৃষ্ঠাটি নিম্নলিখিত প্রকারগুলির যেকোনো একটি হতে পারে:

বর্তমান পৃষ্ঠায় এক বা একাধিক অবজেক্ট নির্বাচিত থাকতে পারে এবং SelectionType নির্বাচনের ধরণ নির্ধারণ করে।

Read the selection based on the selection type

নিম্নলিখিত উদাহরণটি দেখায় যে কীভাবে আপনি সিলেকশন টাইপ ব্যবহার করে বর্তমান সিলেকশনটিকে টাইপ-উপযোগী উপায়ে পড়তে পারেন।

slides/selection/selection.gs
const selection = SlidesApp.getActivePresentation().getSelection();
const selectionType = selection.getSelectionType();
let currentPage;
switch (selectionType) {
  case SlidesApp.SelectionType.NONE:
    console.log("Nothing selected");
    break;
  case SlidesApp.SelectionType.CURRENT_PAGE:
    currentPage = selection.getCurrentPage();
    console.log(`Selection is a page with ID: ${currentPage.getObjectId()}`);
    break;
  case SlidesApp.SelectionType.PAGE_ELEMENT: {
    const pageElements = selection.getPageElementRange().getPageElements();
    console.log(`There are ${pageElements.length} page elements selected.`);
    break;
  }
  case SlidesApp.SelectionType.TEXT: {
    const tableCellRange = selection.getTableCellRange();
    if (tableCellRange !== null) {
      const tableCell = tableCellRange.getTableCells()[0];
      console.log(
        `Selected text is in a table at row ${tableCell.getRowIndex()}, column ${tableCell.getColumnIndex()}`,
      );
    }
    const textRange = selection.getTextRange();
    if (textRange.getStartIndex() === textRange.getEndIndex()) {
      console.log(`Text cursor position: ${textRange.getStartIndex()}`);
    } else {
      console.log(
        `Selection is a text range from: ${textRange.getStartIndex()} to: ${textRange.getEndIndex()} is selected`,
      );
    }
    break;
  }
  case SlidesApp.SelectionType.TABLE_CELL: {
    const tableCells = selection.getTableCellRange().getTableCells();
    const table = tableCells[0].getParentTable();
    console.log(`There are ${tableCells.length} table cells selected.`);
    break;
  }
  case SlidesApp.SelectionType.PAGE: {
    const pages = selection.getPageRange().getPages();
    console.log(`There are ${pages.length} pages selected.`);
    break;
  }
  default:
    break;
}

Read text selections

Selection.getTextRange() মেথড ব্যবহার করে নির্বাচিত টেক্সটটি পড়ুন। টেক্সট সিলেকশন দুই প্রকারের হয়:

  • রেঞ্জ নির্বাচন : যদি কোনো শেপে "Hello" লেখাটি থাকে এবং "He" নির্বাচিত হয়, তাহলে ফেরত আসা রেঞ্জটির startIndex=0 এবং endIndex=2 হবে।
  • কার্সার নির্বাচন : যদি কোনো শেপে "Hello" লেখাটি থাকে এবং কার্সারটি "H"-এর পরে থাকে ("H|ello"), তাহলে ফেরত আসা রেঞ্জটি startIndex=1 এবং endIndex=1 সহ একটি খালি রেঞ্জ হবে।

নির্বাচন পরিবর্তন করা

স্ক্রিপ্টটি ব্যবহারকারীর নির্বাচন পরিবর্তন করতে পারে। স্ক্রিপ্টটি উপস্থাপনায় যে কোনো নির্বাচন পরিবর্তন করলে, স্ক্রিপ্টটি কার্যকর থাকা অবস্থায় পরবর্তী নির্বাচন প্রক্রিয়াগুলোতে তা প্রতিফলিত হয়।

স্ক্রিপ্ট নির্বাহ সম্পন্ন হওয়ার পর, অথবা Presentation.saveAndClose() কল করা হলেই ব্যবহারকারীর ব্রাউজারে নির্বাচনের পরিবর্তনগুলো প্রতিফলিত হয়।

বর্তমান পৃষ্ঠা নির্বাচন করা

A page in the active presentation can be selected as the current page by calling the selectAsCurrentPage() method. This method removes any previous page element, page, or text selection. So using this method on the current page lets you unselect any current selections on the page. For example:

slides/selection/selection.gs
// Select the first slide as the current page selection and remove any previous selection.
const selection = SlidesApp.getActivePresentation().getSelection();
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.selectAsCurrentPage();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.CURRENT_PAGE
// selection.getCurrentPage() = slide
//

পৃষ্ঠার একটি উপাদান নির্বাচন করুন

একটি পৃষ্ঠার কোনো উপাদান নির্বাচন করতে PageElement.select() পদ্ধতিটি ব্যবহার করুন। এটি পূর্বে নির্বাচিত যেকোনো উপাদানকে অনির্বাচিত করে দেয়।

select() এবং select(true) মেথড দুটি সমতুল্য।

উদাহরণস্বরূপ:

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const pageElement = slide.getPageElements()[0];
// Only select this page element and remove any previous selection.
pageElement.select();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.PAGE_ELEMENT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = pageElement
//

Select multiple page elements

নির্বাচিত অংশে অতিরিক্ত পেজ এলিমেন্ট যুক্ত করতে PageElement.select(false) মেথডটি ব্যবহার করুন। সকল পেজ এলিমেন্ট অবশ্যই বর্তমান পেজে থাকতে হবে।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
// First select the slide page, as the current page selection.
slide.selectAsCurrentPage();
// Then select all the page elements in the selected slide page.
const pageElements = slide.getPageElements();
for (let i = 0; i < pageElements.length; i++) {
  pageElements[i].select(false);
}
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.PAGE_ELEMENT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements() = pageElements
//

Transform the selection

আপনার স্ক্রিপ্ট দ্বারা সম্পাদিত সম্পাদনা বর্তমান নির্বাচনকে রূপান্তরিত করতে পারে, ফলে সম্পাদনার ফলস্বরূপ নির্বাচিত বিষয়বস্তু পরিবর্তিত হয়। উদাহরণস্বরূপ:

  1. ধরা যাক, আপনি A এবং B নামে দুটি আকৃতি নির্বাচন করেছেন।
  2. এরপর আপনার স্ক্রিপ্টটি A আকৃতিটি সরিয়ে দেয়।
  3. এর ফলে, সম্পাদনার সাপেক্ষে নির্বাচনটি এমনভাবে রূপান্তরিত হয় যাতে শুধুমাত্র আকৃতি B নির্বাচিত থাকে।

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে নির্বাচিত পৃষ্ঠার উপাদানগুলি পরিবর্তন করে নির্বাচনকে রূপান্তরিত করা যায়।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const shape1 = slide.getPageElements()[0].asShape();
const shape2 = slide.getPageElements()[1].asShape();
// Select both the shapes.
shape1.select();
shape2.select(false);
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.PAGE_ELEMENT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements() = [shape1, shape2]
//
// Remove one shape.
shape2.remove();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.PAGE_ELEMENT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements() = [shape1]
//

টেক্সট নির্বাচন করুন

TextRange.select() মেথড ব্যবহার করে কোনো শেপ বা টেবিল সেলের ভেতরের টেক্সট নির্বাচন করা যায়। যদি টেক্সটটি কোনো শেপের মধ্যে থাকে, তাহলে সেই শেপটিও নির্বাচিত হয়। আর যদি টেক্সটটি কোনো টেবিল সেলের মধ্যে থাকে, তাহলে সেই টেবিল সেল এবং তার ভেতরের টেবিল উভয়ই নির্বাচিত হয়।

এটি প্যারেন্ট পেজকে বর্তমান পেজ হিসেবেও সেট করে।

একটি আকৃতিতে পরিসর নির্বাচন

নিচের উদাহরণটিতে দেখানো হয়েছে, কীভাবে একটি শেপের মধ্যে থাকা টেক্সট থেকে রেঞ্জ সিলেকশন করতে হয়।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const shape = slide.getPageElements()[0].asShape();
shape.getText().setText("Hello");
// Range selection: Select the text range 'He'.
shape.getText().getRange(0, 2).select();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.TEXT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = shape
// selection.getTextRange().getStartIndex() = 0
// selection.getTextRange().getEndIndex() = 2
//

একটি আকৃতিতে কার্সার নির্বাচন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি শেপের মধ্যে থাকা টেক্সটের উপর কার্সার দিয়ে নির্বাচন করতে হয়।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const shape = slide.getPageElements()[0].asShape();
shape.getText().setText("Hello");
// Cursor selection: Place the cursor after 'H' like 'H|ello'.
shape.getText().getRange(1, 1).select();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.TEXT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = shape
// selection.getTextRange().getStartIndex() = 1
// selection.getTextRange().getEndIndex() = 1
//

টেবিলের একটি সেলে রেঞ্জ নির্বাচন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি টেবিল সেলের মধ্যে থাকা টেক্সট নির্বাচন করতে হয়।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const table = slide.getPageElements()[0].asTable();
const tableCell = table.getCell(0, 1);
tableCell.getText().setText("Hello");
// Range selection: Select the text range 'He'.
tableCell.getText().getRange(0, 2).select();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.TEXT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = table
// selection.getTableCellRange().getTableCells()[0] = tableCell
// selection.getTextRange().getStartIndex() = 0
// selection.getTextRange().getEndIndex() = 2
//

টেবিলসেলে কার্সার নির্বাচন

নিম্নলিখিত উদাহরণে দেখানো হয়েছে কিভাবে একটি টেবিলের সেলের মধ্যে থাকা টেক্সটে কার্সার দিয়ে নির্বাচন করতে হয়।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const table = slide.getPageElements()[0].asTable();
const tableCell = table.getCell(0, 1);
tableCell.getText().setText("Hello");
// Cursor selection: Place the cursor after 'H' like 'H|ello'.
tableCell.getText().getRange(1, 1).select();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.TEXT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = table
// selection.getTableCellRange().getTableCells()[0] = tableCell
// selection.getTextRange().getStartIndex() = 1
// selection.getTextRange().getEndIndex() = 1
//

পাঠ্য সম্পাদনা সহ নির্বাচন রূপান্তর

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে নির্বাচিত টেক্সট সম্পাদনা করে নির্বাচনটিকে পরিবর্তন করা যায়।

slides/selection/selection.gs
const slide = SlidesApp.getActivePresentation().getSlides()[0];
const shape = slide.getPageElements()[0].asShape();
const textRange = shape.getText();
textRange.setText("World");
// Select all the text 'World'.
textRange.select();
// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.TEXT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = shape
// selection.getTextRange().getStartIndex() = 0
// selection.getTextRange().getEndIndex() = 6
//
// Add some text to the shape, and the selection will be transformed.
textRange.insertText(0, "Hello ");

// State of selection
//
// selection.getSelectionType() = SlidesApp.SelectionType.TEXT
// selection.getCurrentPage() = slide
// selection.getPageElementRange().getPageElements()[0] = shape
// selection.getTextRange().getStartIndex() = 0
// selection.getTextRange().getEndIndex() = 12
//

নির্বাচন বাতিল করুন

টেক্সট বা পেজ এলিমেন্ট আনসিলেক্ট করার জন্য কোনো সুস্পষ্ট মেথড নেই। তবে, Page.selectAsCurrentPage() অথবা pageElement.select() মেথড ব্যবহার করে এই কাজটি করা যায়।

বর্তমান পৃষ্ঠা নির্বাচন করুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি পৃষ্ঠাকে বর্তমান পৃষ্ঠা হিসাবে সেট করার মাধ্যমে সেই পৃষ্ঠার যেকোনো বর্তমান নির্বাচনকে অনির্বাচিত করা যায়।

slides/selection/selection.gs
// Unselect one or more page elements already selected.
//
// In case one or more page elements in the first slide are selected, setting the
// same (or any other) slide page as the current page would do the unselect.
//
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.selectAsCurrentPage();

পৃষ্ঠার একটি উপাদান নির্বাচন করুন

নিম্নলিখিত উদাহরণটি দেখায় কিভাবে একটি পৃষ্ঠার একটি উপাদান নির্বাচন করে বর্তমান নির্বাচনগুলি বাতিল করা যায়, যার ফলে নির্বাচন থেকে অন্য সমস্ত আইটেম মুছে যায়।

slides/selection/selection.gs
// Unselect one or more page elements already selected.
//
// In case one or more page elements in the first slide are selected,
// selecting any pageElement in the first slide (or any other pageElement) would
// do the unselect and select that pageElement.
//
const slide = SlidesApp.getActivePresentation().getSlides()[0];
slide.getPageElements()[0].select();